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 #if defined(SK_GRAPHITE) 18 namespace skgpu::graphite { 19 class Context; 20 class Recorder; 21 } 22 #endif 23 24 namespace sk_app { 25 26 class WindowContext { 27 public: 28 WindowContext(const DisplayParams&); 29 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 activate(bool isActive)40 virtual void activate(bool isActive) {} 41 getDisplayParams()42 const DisplayParams& getDisplayParams() { return fDisplayParams; } 43 virtual void setDisplayParams(const DisplayParams& params) = 0; 44 directContext()45 GrDirectContext* directContext() const { return fContext.get(); } 46 #if defined(SK_GRAPHITE) graphiteContext()47 skgpu::graphite::Context* graphiteContext() const { return fGraphiteContext.get(); } graphiteRecorder()48 skgpu::graphite::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); } 49 #endif 50 width()51 int width() const { return fWidth; } height()52 int height() const { return fHeight; } dimensions()53 SkISize dimensions() const { return {fWidth, fHeight}; } sampleCount()54 int sampleCount() const { return fSampleCount; } stencilBits()55 int stencilBits() const { return fStencilBits; } 56 57 protected: isGpuContext()58 virtual bool isGpuContext() { return true; } 59 60 sk_sp<GrDirectContext> fContext; 61 #if defined(SK_GRAPHITE) 62 std::unique_ptr<skgpu::graphite::Context> fGraphiteContext; 63 std::unique_ptr<skgpu::graphite::Recorder> fGraphiteRecorder; 64 #endif 65 66 int fWidth; 67 int fHeight; 68 DisplayParams fDisplayParams; 69 70 // parameters obtained from the native window 71 // Note that the platform .cpp file is responsible for 72 // initializing fSampleCount and fStencilBits! 73 int fSampleCount = 1; 74 int fStencilBits = 0; 75 }; 76 77 } // namespace sk_app 78 79 #endif 80