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 "include/core/SkRefCnt.h" 11 #include "include/core/SkSurfaceProps.h" 12 #include "include/gpu/GrTypes.h" 13 #include "tools/sk_app/DisplayParams.h" 14 15 class GrDirectContext; 16 class SkSurface; 17 #ifdef SK_GRAPHITE_ENABLED 18 namespace skgpu { 19 class Context; 20 } 21 #endif 22 23 namespace sk_app { 24 25 class WindowContext { 26 public: 27 WindowContext(const DisplayParams&); 28 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 activate(bool isActive)39 virtual void activate(bool isActive) {} 40 getDisplayParams()41 const DisplayParams& getDisplayParams() { return fDisplayParams; } 42 virtual void setDisplayParams(const DisplayParams& params) = 0; 43 directContext()44 GrDirectContext* directContext() const { return fContext.get(); } 45 #ifdef SK_GRAPHITE_ENABLED graphiteContext()46 skgpu::Context* graphiteContext() const { return fGraphiteContext.get(); } 47 #endif 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 sk_sp<GrDirectContext> fContext; 58 #if SK_GRAPHITE_ENABLED 59 sk_sp<skgpu::Context> fGraphiteContext; 60 #endif 61 62 int fWidth; 63 int fHeight; 64 DisplayParams fDisplayParams; 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 = 1; 70 int fStencilBits = 0; 71 }; 72 73 } // namespace sk_app 74 75 #endif 76