GLWindowContext.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 GLWindowContext_DEFINED
  8. #define GLWindowContext_DEFINED
  9. #include "include/gpu/gl/GrGLInterface.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/core/SkSurface.h"
  12. #include "tools/sk_app/WindowContext.h"
  13. class GrContext;
  14. namespace sk_app {
  15. class GLWindowContext : public WindowContext {
  16. public:
  17. sk_sp<SkSurface> getBackbufferSurface() override;
  18. bool isValid() override { return SkToBool(fBackendContext.get()); }
  19. void resize(int w, int h) override;
  20. void swapBuffers() override;
  21. void setDisplayParams(const DisplayParams& params) override;
  22. protected:
  23. GLWindowContext(const DisplayParams&);
  24. // This should be called by subclass constructor. It is also called when window/display
  25. // parameters change. This will in turn call onInitializeContext().
  26. void initializeContext();
  27. virtual sk_sp<const GrGLInterface> onInitializeContext() = 0;
  28. // This should be called by subclass destructor. It is also called when window/display
  29. // parameters change prior to initializing a new GL context. This will in turn call
  30. // onDestroyContext().
  31. void destroyContext();
  32. virtual void onDestroyContext() = 0;
  33. virtual void onSwapBuffers() = 0;
  34. sk_sp<const GrGLInterface> fBackendContext;
  35. sk_sp<SkSurface> fSurface;
  36. };
  37. } // namespace sk_app
  38. #endif