1 2 /* 3 * Copyright 2016 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #ifndef GLWindowContext_DEFINED 9 #define GLWindowContext_DEFINED 10 11 12 #include "include/gpu/gl/GrGLInterface.h" 13 14 #include "include/core/SkRefCnt.h" 15 #include "include/core/SkSurface.h" 16 17 #include "tools/sk_app/WindowContext.h" 18 19 class GrContext; 20 21 namespace sk_app { 22 23 class GLWindowContext : public WindowContext { 24 public: 25 sk_sp<SkSurface> getBackbufferSurface() override; 26 isValid()27 bool isValid() override { return SkToBool(fBackendContext.get()); } 28 29 void resize(int w, int h) override; 30 void swapBuffers() override; 31 32 void setDisplayParams(const DisplayParams& params) override; 33 34 protected: 35 GLWindowContext(const DisplayParams&); 36 // This should be called by subclass constructor. It is also called when window/display 37 // parameters change. This will in turn call onInitializeContext(). 38 void initializeContext(); 39 virtual sk_sp<const GrGLInterface> onInitializeContext() = 0; 40 41 // This should be called by subclass destructor. It is also called when window/display 42 // parameters change prior to initializing a new GL context. This will in turn call 43 // onDestroyContext(). 44 void destroyContext(); 45 virtual void onDestroyContext() = 0; 46 47 virtual void onSwapBuffers() = 0; 48 49 sk_sp<const GrGLInterface> fBackendContext; 50 sk_sp<SkSurface> fSurface; 51 }; 52 53 } // namespace sk_app 54 55 #endif 56