• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WindowContext_DEFINED
8 #define WindowContext_DEFINED
9 
10 #include "DisplayParams.h"
11 #include "GrTypes.h"
12 #include "SkRefCnt.h"
13 #include "SkSurfaceProps.h"
14 
15 class GrContext;
16 class SkSurface;
17 class GrRenderTarget;
18 
19 namespace sk_app {
20 
21 class WindowContext {
22 public:
WindowContext(const DisplayParams & params)23     WindowContext(const DisplayParams& params)
24         : fContext(nullptr)
25         , fDisplayParams(params)
26         , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
27         , fSampleCount(0)
28         , fStencilBits(0) {}
29 
~WindowContext()30     virtual ~WindowContext() {}
31 
32     virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
33 
34     virtual void swapBuffers() = 0;
35 
36     virtual bool isValid() = 0;
37 
38     virtual void resize(int w, int h) = 0;
39 
getDisplayParams()40     const DisplayParams& getDisplayParams() { return fDisplayParams; }
41     virtual void setDisplayParams(const DisplayParams& params) = 0;
42 
getSurfaceProps()43     SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
setSurfaceProps(const SkSurfaceProps & props)44     void setSurfaceProps(const SkSurfaceProps& props) {
45         fSurfaceProps = props;
46     }
47 
48     virtual GrBackendContext getBackendContext() = 0;
getGrContext()49     GrContext* getGrContext() const { return fContext; }
50 
width()51     int width() const { return fWidth; }
height()52     int height() const { return fHeight; }
sampleCount()53     int sampleCount() const { return fSampleCount; }
stencilBits()54     int stencilBits() const { return fStencilBits; }
55 
56 protected:
isGpuContext()57     virtual bool isGpuContext() { return true;  }
58 
59     GrContext*        fContext;
60 
61     int               fWidth;
62     int               fHeight;
63     DisplayParams     fDisplayParams;
64     GrPixelConfig     fPixelConfig;
65     SkSurfaceProps    fSurfaceProps;
66 
67     // parameters obtained from the native window
68     // Note that the platform .cpp file is responsible for
69     // initializing fSampleCount and fStencilBits!
70     int               fSampleCount;
71     int               fStencilBits;
72 };
73 
74 }   // namespace sk_app
75 
76 #endif
77