• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gl/GrGLInterface.h"
13 
14 #include "SkRefCnt.h"
15 #include "SkSurface.h"
16 
17 #include "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 
getBackendContext()34     GrBackendContext getBackendContext() override {
35         return (GrBackendContext) fBackendContext.get();
36     }
37 
38 protected:
39     GLWindowContext(const DisplayParams&);
40     // This should be called by subclass constructor. It is also called when window/display
41     // parameters change. This will in turn call onInitializeContext().
42     void initializeContext();
43     virtual void onInitializeContext() = 0;
44 
45     // This should be called by subclass destructor. It is also called when window/display
46     // parameters change prior to initializing a new GL context. This will in turn call
47     // onDestroyContext().
48     void destroyContext();
49     virtual void onDestroyContext() = 0;
50 
51     virtual void onSwapBuffers() = 0;
52 
53     sk_sp<const GrGLInterface> fBackendContext;
54     sk_sp<SkSurface>           fSurface;
55 };
56 
57 }   // namespace sk_app
58 
59 #endif
60