Flutter Engine
The Flutter Engine
GrContextThreadSafeProxy.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
9
19
20#include <memory>
21
22static uint32_t next_id() {
23 static std::atomic<uint32_t> nextID{1};
24 uint32_t id;
25 do {
26 id = nextID.fetch_add(1, std::memory_order_relaxed);
27 } while (id == SK_InvalidGenID);
28 return id;
29}
30
33 : fBackend(backend), fOptions(options), fContextID(next_id()) {
34}
35
37
38void GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
39 sk_sp<GrThreadSafePipelineBuilder> pipelineBuilder) {
40 fCaps = std::move(caps);
41 fTextBlobRedrawCoordinator =
42 std::make_unique<sktext::gpu::TextBlobRedrawCoordinator>(fContextID);
43 fThreadSafeCache = std::make_unique<GrThreadSafeCache>();
44 fPipelineBuilder = std::move(pipelineBuilder);
45}
46
48 size_t cacheMaxResourceBytes,
49 const SkImageInfo& ii,
50 const GrBackendFormat& backendFormat,
51 int sampleCnt,
52 GrSurfaceOrigin origin,
53 const SkSurfaceProps& surfaceProps,
54 skgpu::Mipmapped isMipmapped,
55 bool willUseGLFBO0,
56 bool isTextureable,
57 skgpu::Protected isProtected,
58 bool vkRTSupportsInputAttachment,
59 bool forVulkanSecondaryCommandBuffer) {
60 SkASSERT(fCaps);
61 if (!backendFormat.isValid()) {
62 return {};
63 }
64
65 SkASSERT(isTextureable || isMipmapped == skgpu::Mipmapped::kNo);
66
67 if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
68 // The willUseGLFBO0 flags can only be used for a GL backend.
69 return {};
70 }
71
72 if (GrBackendApi::kVulkan != backendFormat.backend() &&
73 (vkRTSupportsInputAttachment || forVulkanSecondaryCommandBuffer)) {
74 // The vkRTSupportsInputAttachment and forVulkanSecondaryCommandBuffer flags can only be
75 // used for a Vulkan backend.
76 return {};
77 }
78
79 if (!fCaps->mipmapSupport()) {
80 isMipmapped = skgpu::Mipmapped::kNo;
81 }
82
83 if (ii.width() < 1 || ii.width() > fCaps->maxRenderTargetSize() ||
84 ii.height() < 1 || ii.height() > fCaps->maxRenderTargetSize()) {
85 return {};
86 }
87
89
90 if (!fCaps->areColorTypeAndFormatCompatible(grColorType, backendFormat)) {
91 return {};
92 }
93
94 if (!fCaps->isFormatAsColorTypeRenderable(grColorType, backendFormat, sampleCnt)) {
95 return {};
96 }
97
98 sampleCnt = fCaps->getRenderTargetSampleCount(sampleCnt, backendFormat);
99 SkASSERT(sampleCnt);
100
101 if (willUseGLFBO0 && isTextureable) {
102 return {};
103 }
104
105 if (isTextureable && !fCaps->isFormatTexturable(backendFormat, backendFormat.textureType())) {
106 // Skia doesn't agree that this is textureable.
107 return {};
108 }
109
110 if (GrBackendApi::kVulkan == backendFormat.backend()) {
112 isTextureable,
113 isMipmapped,
114 isProtected,
115 vkRTSupportsInputAttachment,
116 forVulkanSecondaryCommandBuffer)) {
117 return {};
118 }
119 }
120
122 sk_ref_sp<GrContextThreadSafeProxy>(this),
123 cacheMaxResourceBytes,
124 ii,
125 backendFormat,
126 origin,
127 sampleCnt,
129 isMipmapped,
132 GrSurfaceCharacterization::VulkanSecondaryCBCompatible(forVulkanSecondaryCommandBuffer),
133 isProtected,
134 surfaceProps);
135}
136
139 bool isTextureable,
140 skgpu::Mipmapped isMipmapped,
141 skgpu::Protected isProtected,
142 bool vkRTSupportsInputAttachment,
143 bool forVulkanSecondaryCommandBuffer) {
144 return false; // handled by a subclass
145}
146
148 GrRenderable renderable) const {
149 SkASSERT(fCaps);
150 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
151
152 GrBackendFormat format = fCaps->getDefaultBackendFormat(grColorType, renderable);
153 if (!format.isValid()) {
154 return GrBackendFormat();
155 }
156
157 SkASSERT(renderable == GrRenderable::kNo ||
158 fCaps->isFormatAsColorTypeRenderable(grColorType, format));
159
160 return format;
161}
162
164 SkASSERT(fCaps);
165
167
169 return format;
170}
171
173 SkASSERT(fCaps);
174
177 return fCaps->maxRenderTargetSampleCount(format);
178}
179
180void GrContextThreadSafeProxy::abandonContext() {
181 if (!fAbandoned.exchange(true)) {
182 fTextBlobRedrawCoordinator->freeAll();
183 }
184}
185
186bool GrContextThreadSafeProxy::abandoned() const {
187 return fAbandoned;
188}
189
190////////////////////////////////////////////////////////////////////////////////
193 const GrContextOptions& options) {
195}
196
199 fProxy->init(std::move(caps), std::move(builder));
200}
const char * options
const char * backend
static uint32_t next_id()
GrColorType
Definition: GrTypesPriv.h:540
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
GrSurfaceOrigin
Definition: GrTypes.h:147
GrBackendApi
Definition: GrTypes.h:95
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorType
Definition: SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkTextureCompressionType
static constexpr uint32_t SK_InvalidGenID
Definition: SkTypes.h:192
GrBackendApi backend() const
bool isValid() const
GrTextureType textureType() const
bool mipmapSupport() const
Definition: GrCaps.h:72
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
virtual int maxRenderTargetSampleCount(const GrBackendFormat &) const =0
virtual GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const =0
int maxRenderTargetSize() const
Definition: GrCaps.h:223
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition: GrCaps.cpp:428
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
virtual bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const =0
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
const GrContextOptions & options() const
static sk_sp< GrContextThreadSafeProxy > Make(GrBackendApi, const GrContextOptions &)
void init(sk_sp< const GrCaps >, sk_sp< GrThreadSafePipelineBuilder >) const
virtual ~GrContextThreadSafeProxy()
virtual bool isValidCharacterizationForVulkan(sk_sp< const GrCaps >, bool isTextureable, skgpu::Mipmapped isMipmapped, skgpu::Protected isProtected, bool vkRTSupportsInputAttachment, bool forVulkanSecondaryCommandBuffer)
int maxSurfaceSampleCountForColorType(SkColorType colorType) const
GrBackendFormat compressedBackendFormat(SkTextureCompressionType c) const
GrSurfaceCharacterization createCharacterization(size_t cacheMaxResourceBytes, const SkImageInfo &ii, const GrBackendFormat &backendFormat, int sampleCount, GrSurfaceOrigin origin, const SkSurfaceProps &surfaceProps, skgpu::Mipmapped isMipmapped, bool willUseGLFBO0=false, bool isTextureable=true, skgpu::Protected isProtected=GrProtected::kNo, bool vkRTSupportsInputAttachment=false, bool forVulkanSecondaryCommandBuffer=false)
GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const
GrContextThreadSafeProxy(GrBackendApi, const GrContextOptions &)
uint32_t uint32_t * format
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
int width() const
Definition: SkImageInfo.h:365
SkColorType colorType() const
Definition: SkImageInfo.h:373
int height() const
Definition: SkImageInfo.h:371
const uintptr_t id