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 , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) 27 , fSampleCount(1) 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.get(); } 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 sk_sp<GrContext> fContext; 60 61 int fWidth; 62 int fHeight; 63 DisplayParams fDisplayParams; 64 SkSurfaceProps fSurfaceProps; 65 66 // parameters obtained from the native window 67 // Note that the platform .cpp file is responsible for 68 // initializing fSampleCount and fStencilBits! 69 int fSampleCount; 70 int fStencilBits; 71 }; 72 73 } // namespace sk_app 74 75 #endif 76