Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrSurface.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 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
8#ifndef GrSurface_DEFINED
9#define GrSurface_DEFINED
10
12#include "include/core/SkRect.h"
16
17class GrBackendFormat;
18class GrDirectContext;
19class GrRenderTarget;
20class GrTexture;
21
22class GrSurface : public GrGpuResource {
23public:
24 /**
25 * Retrieves the dimensions of the surface.
26 */
27 SkISize dimensions() const { return fDimensions; }
28
29 /**
30 * Retrieves the width of the surface.
31 */
32 int width() const { return fDimensions.width(); }
33
34 /**
35 * Retrieves the height of the surface.
36 */
37 int height() const { return fDimensions.height(); }
38
39 /**
40 * Helper that gets the width and height of the surface as a bounding rectangle.
41 */
42 SkRect getBoundsRect() const { return SkRect::Make(this->dimensions()); }
43
44 virtual GrBackendFormat backendFormat() const = 0;
45
47
48 // These match the definitions in SkImage, from whence they came.
49 // TODO: Remove Chrome's need to call this on a GrTexture
50 typedef void* ReleaseCtx;
51 typedef void (*ReleaseProc)(ReleaseCtx);
54 }
55
56 /**
57 * @return the texture associated with the surface, may be null.
58 */
59 virtual GrTexture* asTexture() { return nullptr; }
60 virtual const GrTexture* asTexture() const { return nullptr; }
61
62 /**
63 * @return the render target underlying this surface, may be null.
64 */
65 virtual GrRenderTarget* asRenderTarget() { return nullptr; }
66 virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
67
68 GrInternalSurfaceFlags flags() const { return fSurfaceFlags; }
69
70 static size_t ComputeSize(const GrBackendFormat&,
72 int colorSamplesPerPixel,
74 bool binSize = false);
75
76 /**
77 * The pixel values of this surface cannot be modified (e.g. doesn't support write pixels or
78 * MIP map level regen).
79 */
80 bool readOnly() const { return fSurfaceFlags & GrInternalSurfaceFlags::kReadOnly; }
81
82 bool framebufferOnly() const {
83 return fSurfaceFlags & GrInternalSurfaceFlags::kFramebufferOnly;
84 }
85
86 // Returns true if we are working with protected content.
87 bool isProtected() const { return fIsProtected == skgpu::Protected::kYes; }
88
93
94 class RefCntedReleaseProc : public SkNVRefCnt<RefCntedReleaseProc> {
95 public:
97 sk_sp<GrDirectContext> directContext);
98
100
101 private:
103 sk_sp<GrDirectContext> fDirectContext;
104 };
105
106#if defined(GR_TEST_UTILS)
107 const GrSurface* asSurface() const override { return this; }
108#endif
109
110protected:
113 SkASSERT(!this->asTexture());
114 SkASSERT(this->asRenderTarget());
116 }
117 bool glRTFBOIDis0() const {
118 return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
119 }
120
129
130 void setReadOnly() {
131 SkASSERT(!this->asRenderTarget());
132 fSurfaceFlags |= GrInternalSurfaceFlags::kReadOnly;
133 }
134
139
141 const SkISize& dimensions,
143 std::string_view label)
144 : INHERITED(gpu, label)
145 , fDimensions(dimensions)
146 , fSurfaceFlags(GrInternalSurfaceFlags::kNone)
147 , fIsProtected(isProtected) {}
148
149 ~GrSurface() override {
150 // check that invokeReleaseProc has been called (if needed)
151 SkASSERT(!fReleaseHelper);
152 }
153
154 void onRelease() override;
155 void onAbandon() override;
156
157private:
158 const char* getResourceType() const override { return "Surface"; }
159
160 // Unmanaged backends (e.g. Vulkan) may want to specially handle the release proc in order to
161 // ensure it isn't called until GPU work related to the resource is completed.
162
163 // NOLINTNEXTLINE(performance-unnecessary-value-param)
165
166 void invokeReleaseProc() {
167 // Depending on the ref count of fReleaseHelper this may or may not actually trigger the
168 // ReleaseProc to be called.
169 fReleaseHelper.reset();
170 }
171
172 SkISize fDimensions;
173 GrInternalSurfaceFlags fSurfaceFlags;
174 skgpu::Protected fIsProtected;
175 sk_sp<RefCntedReleaseProc> fReleaseHelper;
176
177 using INHERITED = GrGpuResource;
178};
179
180#endif
GrInternalSurfaceFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
Definition GrGpu.h:62
virtual GrBackendFormat backendFormat() const =0
bool readOnly() const
Definition GrSurface.h:80
void * ReleaseCtx
Definition GrSurface.h:50
void setRelease(sk_sp< skgpu::RefCntedCallback > releaseHelper)
Definition GrSurface.cpp:60
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
bool glRTFBOIDis0() const
Definition GrSurface.h:117
int height() const
Definition GrSurface.h:37
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition GrSurface.cpp:21
void setGLRTFBOIDIs0()
Definition GrSurface.h:111
bool framebufferOnly() const
Definition GrSurface.h:82
virtual void onSetRelease(sk_sp< RefCntedReleaseProc >)
Definition GrSurface.h:164
void setRequiresManualMSAAResolve()
Definition GrSurface.h:121
GrSurface(GrGpu *gpu, const SkISize &dimensions, skgpu::Protected isProtected, std::string_view label)
Definition GrSurface.h:140
~GrSurface() override
Definition GrSurface.h:149
virtual const GrTexture * asTexture() const
Definition GrSurface.h:60
void setReadOnly()
Definition GrSurface.h:130
void onAbandon() override
Definition GrSurface.cpp:86
void setVkRTSupportsInputAttachment()
Definition GrSurface.h:135
virtual const GrRenderTarget * asRenderTarget() const
Definition GrSurface.h:66
virtual GrTexture * asTexture()
Definition GrSurface.h:59
bool requiresManualMSAAResolve() const
Definition GrSurface.h:126
virtual GrRenderTarget * asRenderTarget()
Definition GrSurface.h:65
void setFramebufferOnly()
Definition GrSurface.h:89
SkRect getBoundsRect() const
Definition GrSurface.h:42
int width() const
Definition GrSurface.h:32
void setRelease(ReleaseProc proc, ReleaseCtx ctx)
Definition GrSurface.h:52
void onRelease() override
Definition GrSurface.cpp:81
GrInternalSurfaceFlags flags() const
Definition GrSurface.h:68
void(* ReleaseProc)(ReleaseCtx)
Definition GrSurface.h:51
const char * getResourceType() const override
Definition GrSurface.h:158
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
static SkRect Make(const SkISize &size)
Definition SkRect.h:669