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