1 /* 2 * Copyright 2023 Google LLC 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 SkWindowContext_DEFINED 8 #define SkWindowContext_DEFINED 9 10 #include "include/core/SkRefCnt.h" 11 #include "include/core/SkSurfaceProps.h" 12 #include "include/gpu/GrTypes.h" 13 #include "tools/window/SkDisplayParams.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 class SkWindowContext { 25 public: 26 SkWindowContext(const SkDisplayParams&); 27 28 virtual ~SkWindowContext(); 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 activate(bool isActive)38 virtual void activate(bool isActive) {} 39 getDisplayParams()40 const SkDisplayParams& getDisplayParams() { return fDisplayParams; } 41 virtual void setDisplayParams(const SkDisplayParams& params) = 0; 42 directContext()43 GrDirectContext* directContext() const { return fContext.get(); } 44 #if defined(SK_GRAPHITE) graphiteContext()45 skgpu::graphite::Context* graphiteContext() const { return fGraphiteContext.get(); } graphiteRecorder()46 skgpu::graphite::Recorder* graphiteRecorder() const { return fGraphiteRecorder.get(); } 47 #endif 48 width()49 int width() const { return fWidth; } height()50 int height() const { return fHeight; } dimensions()51 SkISize dimensions() const { return {fWidth, fHeight}; } sampleCount()52 int sampleCount() const { return fSampleCount; } stencilBits()53 int stencilBits() const { return fStencilBits; } 54 55 protected: isGpuContext()56 virtual bool isGpuContext() { return true; } 57 58 sk_sp<GrDirectContext> fContext; 59 #if defined(SK_GRAPHITE) 60 std::unique_ptr<skgpu::graphite::Context> fGraphiteContext; 61 std::unique_ptr<skgpu::graphite::Recorder> fGraphiteRecorder; 62 #endif 63 64 int fWidth; 65 int fHeight; 66 SkDisplayParams fDisplayParams; 67 68 // parameters obtained from the native window 69 // Note that the platform .cpp file is responsible for 70 // initializing fSampleCount and fStencilBits! 71 int fSampleCount = 1; 72 int fStencilBits = 0; 73 }; 74 75 #endif 76