1 /* 2 * Copyright 2023 Google LLC 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 SkGLWindowContext_DEFINED 8 #define SkGLWindowContext_DEFINED 9 10 11 #include "include/gpu/gl/GrGLInterface.h" 12 13 #include "include/core/SkRefCnt.h" 14 #include "include/core/SkSurface.h" 15 16 #include "tools/window/SkWindowContext.h" 17 18 class SkGLWindowContext : public SkWindowContext { 19 public: 20 sk_sp<SkSurface> getBackbufferSurface() override; 21 isValid()22 bool isValid() override { return SkToBool(fBackendContext.get()); } 23 24 void resize(int w, int h) override; 25 void swapBuffers() override; 26 27 void setDisplayParams(const SkDisplayParams& params) override; 28 29 protected: 30 SkGLWindowContext(const SkDisplayParams&); 31 // This should be called by subclass constructor. It is also called when window/display 32 // parameters change. This will in turn call onInitializeContext(). 33 void initializeContext(); 34 virtual sk_sp<const GrGLInterface> onInitializeContext() = 0; 35 36 // This should be called by subclass destructor. It is also called when window/display 37 // parameters change prior to initializing a new GL context. This will in turn call 38 // onDestroyContext(). 39 void destroyContext(); 40 virtual void onDestroyContext() = 0; 41 42 virtual void onSwapBuffers() = 0; 43 44 sk_sp<const GrGLInterface> fBackendContext; 45 sk_sp<SkSurface> fSurface; 46 }; 47 48 #endif 49