• 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 "GrContext.h"
12 #include "GrTypes.h"
13 #include "SkRefCnt.h"
14 #include "SkSurfaceProps.h"
15 
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             , fSampleCount(1)
27             , fStencilBits(0) {}
28 
~WindowContext()29     virtual ~WindowContext() {}
30 
31     virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
32 
33     virtual void swapBuffers() = 0;
34 
35     virtual bool isValid() = 0;
36 
37     virtual void resize(int w, int h) = 0;
38 
getDisplayParams()39     const DisplayParams& getDisplayParams() { return fDisplayParams; }
40     virtual void setDisplayParams(const DisplayParams& params) = 0;
41 
getGrContext()42     GrContext* getGrContext() const { return fContext.get(); }
43 
width()44     int width() const { return fWidth; }
height()45     int height() const { return fHeight; }
sampleCount()46     int sampleCount() const { return fSampleCount; }
stencilBits()47     int stencilBits() const { return fStencilBits; }
48 
49 protected:
isGpuContext()50     virtual bool isGpuContext() { return true;  }
51 
52     sk_sp<GrContext>        fContext;
53 
54     int               fWidth;
55     int               fHeight;
56     DisplayParams     fDisplayParams;
57 
58     // parameters obtained from the native window
59     // Note that the platform .cpp file is responsible for
60     // initializing fSampleCount and fStencilBits!
61     int               fSampleCount;
62     int               fStencilBits;
63 };
64 
65 }   // namespace sk_app
66 
67 #endif
68