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 namespace sk_app {
20 
21 class GLWindowContext : public WindowContext {
22 public:
23     sk_sp<SkSurface> getBackbufferSurface() override;
24 
isValid()25     bool isValid() override { return SkToBool(fBackendContext.get()); }
26 
27     void resize(int w, int h) override;
28     void swapBuffers() override;
29 
30     void setDisplayParams(const DisplayParams& params) override;
31 
32 protected:
33     GLWindowContext(const DisplayParams&);
34     // This should be called by subclass constructor. It is also called when window/display
35     // parameters change. This will in turn call onInitializeContext().
36     void initializeContext();
37     virtual sk_sp<const GrGLInterface> onInitializeContext() = 0;
38 
39     // This should be called by subclass destructor. It is also called when window/display
40     // parameters change prior to initializing a new GL context. This will in turn call
41     // onDestroyContext().
42     void destroyContext();
43     virtual void onDestroyContext() = 0;
44 
45     virtual void onSwapBuffers() = 0;
46 
47     sk_sp<const GrGLInterface> fBackendContext;
48     sk_sp<SkSurface>           fSurface;
49 };
50 
51 }   // namespace sk_app
52 
53 #endif
54