WindowContext.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef WindowContext_DEFINED
  8. #define WindowContext_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/core/SkSurfaceProps.h"
  11. #include "include/gpu/GrContext.h"
  12. #include "include/gpu/GrTypes.h"
  13. #include "tools/sk_app/DisplayParams.h"
  14. class SkSurface;
  15. class GrRenderTarget;
  16. namespace sk_app {
  17. class WindowContext {
  18. public:
  19. WindowContext(const DisplayParams& params)
  20. : fContext(nullptr)
  21. , fDisplayParams(params)
  22. , fSampleCount(1)
  23. , fStencilBits(0) {}
  24. virtual ~WindowContext() {}
  25. virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
  26. virtual void swapBuffers() = 0;
  27. virtual bool isValid() = 0;
  28. virtual void resize(int w, int h) = 0;
  29. const DisplayParams& getDisplayParams() { return fDisplayParams; }
  30. virtual void setDisplayParams(const DisplayParams& params) = 0;
  31. GrContext* getGrContext() const { return fContext.get(); }
  32. int width() const { return fWidth; }
  33. int height() const { return fHeight; }
  34. int sampleCount() const { return fSampleCount; }
  35. int stencilBits() const { return fStencilBits; }
  36. protected:
  37. virtual bool isGpuContext() { return true; }
  38. sk_sp<GrContext> fContext;
  39. int fWidth;
  40. int fHeight;
  41. DisplayParams fDisplayParams;
  42. // parameters obtained from the native window
  43. // Note that the platform .cpp file is responsible for
  44. // initializing fSampleCount and fStencilBits!
  45. int fSampleCount;
  46. int fStencilBits;
  47. };
  48. } // namespace sk_app
  49. #endif