blob: 6299264e21f065d491030ed900d151e69a3154be [file] [log] [blame]
bsalomoned0bcad2015-05-04 10:36:42 -07001/*
2 * Copyright 2015 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#include "GrResourceProvider.h"
9
cdalton397536c2016-03-25 12:15:03 -070010#include "GrBuffer.h"
robertphillips5fa7f302016-07-21 09:21:04 -070011#include "GrCaps.h"
Robert Phillips26c90e02017-03-14 14:39:29 -040012#include "GrContext.h"
Robert Phillipse78b7252017-04-06 07:59:41 -040013#include "GrContextPriv.h"
bsalomoned0bcad2015-05-04 10:36:42 -070014#include "GrGpu.h"
kkinnunencabe20c2015-06-01 01:37:26 -070015#include "GrPathRendering.h"
egdanielec00d942015-09-14 12:56:10 -070016#include "GrRenderTarget.h"
17#include "GrRenderTargetPriv.h"
bsalomoned0bcad2015-05-04 10:36:42 -070018#include "GrResourceCache.h"
19#include "GrResourceKey.h"
Greg Danield85f97d2017-03-07 13:37:21 -050020#include "GrSemaphore.h"
egdanielec00d942015-09-14 12:56:10 -070021#include "GrStencilAttachment.h"
Robert Phillipsb66b42f2017-03-14 08:53:02 -040022#include "GrSurfaceProxyPriv.h"
Brian Osman32342f02017-03-04 08:12:46 -050023#include "GrTexturePriv.h"
24#include "../private/GrSingleOwner.h"
Robert Phillips45fdae12017-04-17 12:57:27 -040025#include "SkGr.h"
halcanary4dbbd042016-06-07 17:21:10 -070026#include "SkMathPriv.h"
bsalomoned0bcad2015-05-04 10:36:42 -070027
28GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
29
Brian Osman32342f02017-03-04 08:12:46 -050030const int GrResourceProvider::kMinScratchTextureSize = 16;
31
32#define ASSERT_SINGLE_OWNER \
33 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
34
joshualitt6d0872d2016-01-11 08:27:48 -080035GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner)
Brian Osman32342f02017-03-04 08:12:46 -050036 : fCache(cache)
37 , fGpu(gpu)
38#ifdef SK_DEBUG
39 , fSingleOwner(owner)
40#endif
41 {
Robert Phillips26c90e02017-03-14 14:39:29 -040042 fCaps = sk_ref_sp(fGpu->caps());
43
bsalomoned0bcad2015-05-04 10:36:42 -070044 GR_DEFINE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey);
45 fQuadIndexBufferKey = gQuadIndexBufferKey;
46}
47
Robert Phillipsf7a72612017-03-31 10:03:45 -040048bool GrResourceProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) {
Robert Phillipsb66b42f2017-03-14 08:53:02 -040049 return proxy->priv().isExact() || (SkIsPow2(proxy->width()) && SkIsPow2(proxy->height()));
50}
Brian Osman32342f02017-03-04 08:12:46 -050051
Robert Phillipse78b7252017-04-06 07:59:41 -040052// MDB TODO: this should probably be a factory on GrSurfaceProxy
53sk_sp<GrTextureProxy> GrResourceProvider::createMipMappedTexture(
54 const GrSurfaceDesc& desc,
55 SkBudgeted budgeted,
56 const GrMipLevel* texels,
57 int mipLevelCount,
Robert Phillipsa4c41b32017-03-15 13:02:45 -040058 SkDestinationSurfaceColorMode mipColorMode) {
Brian Osman32342f02017-03-04 08:12:46 -050059 ASSERT_SINGLE_OWNER
60
Robert Phillips1119dc32017-04-11 12:54:57 -040061 if (!mipLevelCount) {
62 if (texels) {
63 return nullptr;
64 }
65 return GrSurfaceProxy::MakeDeferred(this, desc, budgeted, nullptr, 0);
Robert Phillips45fdae12017-04-17 12:57:27 -040066 } else if (1 == mipLevelCount) {
67 if (!texels) {
68 return nullptr;
69 }
70 return this->createTextureProxy(desc, budgeted, texels[0]);
Robert Phillips1119dc32017-04-11 12:54:57 -040071 }
72
Brian Osman32342f02017-03-04 08:12:46 -050073 if (this->isAbandoned()) {
74 return nullptr;
75 }
Robert Phillips1119dc32017-04-11 12:54:57 -040076
Brian Osman32342f02017-03-04 08:12:46 -050077 if (mipLevelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
78 return nullptr;
79 }
80 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
81 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
82 return nullptr;
83 }
Brian Osman32342f02017-03-04 08:12:46 -050084
85 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount);
86 for (int i = 0; i < mipLevelCount; ++i) {
Robert Phillips45fdae12017-04-17 12:57:27 -040087 if (!texels[i].fPixels) {
88 return nullptr;
89 }
90
Brian Osman32342f02017-03-04 08:12:46 -050091 texelsShallowCopy.push_back(texels[i]);
92 }
Robert Phillipse78b7252017-04-06 07:59:41 -040093 sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted, texelsShallowCopy));
94 if (tex) {
95 tex->texturePriv().setMipColorMode(mipColorMode);
Robert Phillipsa4c41b32017-03-15 13:02:45 -040096 }
Robert Phillipse78b7252017-04-06 07:59:41 -040097
98 return GrSurfaceProxy::MakeWrapped(std::move(tex));
Brian Osman32342f02017-03-04 08:12:46 -050099}
100
Robert Phillips45fdae12017-04-17 12:57:27 -0400101sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc,
102 SkBudgeted budgeted, uint32_t flags) {
103
104 flags |= kExact_Flag | kNoCreate_Flag;
105 sk_sp<GrTexture> tex(this->refScratchTexture(desc, flags));
106 if (tex && SkBudgeted::kNo == budgeted) {
107 tex->resourcePriv().makeUnbudgeted();
108 }
109
110 return tex;
111}
112
113static bool make_info(int w, int h, GrPixelConfig config, SkImageInfo* ii) {
114 SkColorType colorType;
115 if (!GrPixelConfigToColorType(config, &colorType)) {
116 return false;
117 }
118
119 *ii = SkImageInfo::Make(w, h, colorType, kUnknown_SkAlphaType, nullptr);
120 return true;
121}
122
123sk_sp<GrTextureProxy> GrResourceProvider::createTextureProxy(const GrSurfaceDesc& desc,
124 SkBudgeted budgeted,
125 const GrMipLevel& mipLevel) {
126 if (!mipLevel.fPixels) {
127 return nullptr;
128 }
129
130 GrContext* context = fGpu->getContext();
131
132 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
133 SkImageInfo srcInfo;
134
135 if (make_info(desc.fWidth, desc.fHeight, desc.fConfig, &srcInfo)) {
136 sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, 0);
137 sk_sp<GrSurfaceContext> sContext =
138 context->contextPriv().makeWrappedSurfaceContext(std::move(tex));
139 if (sContext) {
140 if (sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0)) {
141 return sContext->asTextureProxyRef();
142 }
143 }
144 }
145 }
146
147 SkTArray<GrMipLevel> texels(1);
148 texels.push_back(mipLevel);
149
150 sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted, texels));
151 return GrSurfaceProxy::MakeWrapped(std::move(tex));
152}
153
154
Robert Phillipse78b7252017-04-06 07:59:41 -0400155sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
156 uint32_t flags) {
157 ASSERT_SINGLE_OWNER
158
159 if (this->isAbandoned()) {
160 return nullptr;
Brian Osman32342f02017-03-04 08:12:46 -0500161 }
Robert Phillipse78b7252017-04-06 07:59:41 -0400162
163 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
164 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
165 return nullptr;
166 }
167
168 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
Robert Phillips45fdae12017-04-17 12:57:27 -0400169 sk_sp<GrTexture> tex = this->getExactScratch(desc, budgeted, flags);
Robert Phillipse78b7252017-04-06 07:59:41 -0400170 if (tex) {
Robert Phillipse78b7252017-04-06 07:59:41 -0400171 return tex;
172 }
173 }
174
175 sk_sp<GrTexture> tex(fGpu->createTexture(desc, budgeted));
176 return tex;
Brian Osman32342f02017-03-04 08:12:46 -0500177}
178
179GrTexture* GrResourceProvider::createApproxTexture(const GrSurfaceDesc& desc, uint32_t flags) {
180 ASSERT_SINGLE_OWNER
181 SkASSERT(0 == flags || kNoPendingIO_Flag == flags);
Brian Osman32342f02017-03-04 08:12:46 -0500182
Brian Osman32342f02017-03-04 08:12:46 -0500183 if (this->isAbandoned()) {
184 return nullptr;
185 }
Robert Phillips1119dc32017-04-11 12:54:57 -0400186
Brian Osman32342f02017-03-04 08:12:46 -0500187 // Currently we don't recycle compressed textures as scratch.
188 if (GrPixelConfigIsCompressed(desc.fConfig)) {
189 return nullptr;
Brian Osman32342f02017-03-04 08:12:46 -0500190 }
Robert Phillips1119dc32017-04-11 12:54:57 -0400191
192 return this->refScratchTexture(desc, flags);
Brian Osman32342f02017-03-04 08:12:46 -0500193}
194
195GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
196 uint32_t flags) {
197 ASSERT_SINGLE_OWNER
198 SkASSERT(!this->isAbandoned());
199 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
200
201 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
202
203 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
204 if (!(kExact_Flag & flags)) {
205 // bin by pow2 with a reasonable min
206 GrSurfaceDesc* wdesc = desc.writable();
207 wdesc->fWidth = SkTMax(kMinScratchTextureSize, GrNextPow2(desc->fWidth));
208 wdesc->fHeight = SkTMax(kMinScratchTextureSize, GrNextPow2(desc->fHeight));
209 }
210
211 GrScratchKey key;
212 GrTexturePriv::ComputeScratchKey(*desc, &key);
213 uint32_t scratchFlags = 0;
214 if (kNoPendingIO_Flag & flags) {
215 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
216 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
217 // If it is not a render target then it will most likely be populated by
218 // writePixels() which will trigger a flush if the texture has pending IO.
219 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
220 }
221 GrGpuResource* resource = fCache->findAndRefScratchResource(key,
222 GrSurface::WorstCaseSize(*desc),
223 scratchFlags);
224 if (resource) {
225 GrSurface* surface = static_cast<GrSurface*>(resource);
Brian Osman32342f02017-03-04 08:12:46 -0500226 return surface->asTexture();
227 }
228 }
229
230 if (!(kNoCreate_Flag & flags)) {
231 return fGpu->createTexture(*desc, SkBudgeted::kYes);
232 }
233
234 return nullptr;
235}
236
237sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTextureDesc& desc,
238 GrWrapOwnership ownership) {
239 ASSERT_SINGLE_OWNER
240 if (this->isAbandoned()) {
241 return nullptr;
242 }
243 return fGpu->wrapBackendTexture(desc, ownership);
244}
245
246sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
247 const GrBackendRenderTargetDesc& desc)
248{
249 ASSERT_SINGLE_OWNER
Brian Osman0b791f52017-03-10 08:30:22 -0500250 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc);
Brian Osman32342f02017-03-04 08:12:46 -0500251}
252
253void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key,
254 GrGpuResource* resource) {
255 ASSERT_SINGLE_OWNER
256 if (this->isAbandoned() || !resource) {
257 return;
258 }
259 resource->resourcePriv().setUniqueKey(key);
260}
261
262GrGpuResource* GrResourceProvider::findAndRefResourceByUniqueKey(const GrUniqueKey& key) {
263 ASSERT_SINGLE_OWNER
264 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key);
265}
266
267GrTexture* GrResourceProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& key) {
268 ASSERT_SINGLE_OWNER
269 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
270 if (resource) {
271 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
272 SkASSERT(texture);
273 return texture;
274 }
275 return NULL;
276}
277
Robert Phillipsd3749482017-03-14 09:17:43 -0400278// MDB TODO (caching): this side-steps the issue of texture proxies with unique IDs
279void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
280 ASSERT_SINGLE_OWNER
281 SkASSERT(key.isValid());
282 if (this->isAbandoned() || !proxy) {
283 return;
284 }
285
286 GrTexture* texture = proxy->instantiate(this);
287 if (!texture) {
288 return;
289 }
290
291 this->assignUniqueKeyToResource(key, texture);
292}
293
294// MDB TODO (caching): this side-steps the issue of texture proxies with unique IDs
295sk_sp<GrTextureProxy> GrResourceProvider::findProxyByUniqueKey(const GrUniqueKey& key) {
296 ASSERT_SINGLE_OWNER
297
298 sk_sp<GrTexture> texture(this->findAndRefTextureByUniqueKey(key));
299 if (!texture) {
300 return nullptr;
301 }
302
303 return GrSurfaceProxy::MakeWrapped(std::move(texture));
304}
305
cdalton397536c2016-03-25 12:15:03 -0700306const GrBuffer* GrResourceProvider::createInstancedIndexBuffer(const uint16_t* pattern,
307 int patternSize,
308 int reps,
309 int vertCount,
310 const GrUniqueKey& key) {
bsalomoned0bcad2015-05-04 10:36:42 -0700311 size_t bufferSize = patternSize * reps * sizeof(uint16_t);
312
Brian Salomon09d994e2016-12-21 11:14:46 -0500313 // This is typically used in GrMeshDrawOps, so we assume kNoPendingIO.
cdaltone2e71c22016-04-07 18:13:29 -0700314 GrBuffer* buffer = this->createBuffer(bufferSize, kIndex_GrBufferType, kStatic_GrAccessPattern,
cdalton397536c2016-03-25 12:15:03 -0700315 kNoPendingIO_Flag);
bsalomoned0bcad2015-05-04 10:36:42 -0700316 if (!buffer) {
halcanary96fcdcc2015-08-27 07:41:13 -0700317 return nullptr;
bsalomoned0bcad2015-05-04 10:36:42 -0700318 }
319 uint16_t* data = (uint16_t*) buffer->map();
halcanary96fcdcc2015-08-27 07:41:13 -0700320 bool useTempData = (nullptr == data);
bsalomoned0bcad2015-05-04 10:36:42 -0700321 if (useTempData) {
halcanary385fe4d2015-08-26 13:07:48 -0700322 data = new uint16_t[reps * patternSize];
bsalomoned0bcad2015-05-04 10:36:42 -0700323 }
324 for (int i = 0; i < reps; ++i) {
325 int baseIdx = i * patternSize;
326 uint16_t baseVert = (uint16_t)(i * vertCount);
327 for (int j = 0; j < patternSize; ++j) {
328 data[baseIdx+j] = baseVert + pattern[j];
329 }
330 }
331 if (useTempData) {
332 if (!buffer->updateData(data, bufferSize)) {
333 buffer->unref();
halcanary96fcdcc2015-08-27 07:41:13 -0700334 return nullptr;
bsalomoned0bcad2015-05-04 10:36:42 -0700335 }
halcanary385fe4d2015-08-26 13:07:48 -0700336 delete[] data;
bsalomoned0bcad2015-05-04 10:36:42 -0700337 } else {
338 buffer->unmap();
339 }
340 this->assignUniqueKeyToResource(key, buffer);
341 return buffer;
342}
343
cdalton397536c2016-03-25 12:15:03 -0700344const GrBuffer* GrResourceProvider::createQuadIndexBuffer() {
bsalomoned0bcad2015-05-04 10:36:42 -0700345 static const int kMaxQuads = 1 << 12; // max possible: (1 << 14) - 1;
346 GR_STATIC_ASSERT(4 * kMaxQuads <= 65535);
347 static const uint16_t kPattern[] = { 0, 1, 2, 0, 2, 3 };
348
349 return this->createInstancedIndexBuffer(kPattern, 6, kMaxQuads, 4, fQuadIndexBufferKey);
350}
351
bsalomon6663acf2016-05-10 09:14:17 -0700352GrPath* GrResourceProvider::createPath(const SkPath& path, const GrStyle& style) {
bsalomon706f08f2015-05-22 07:35:58 -0700353 SkASSERT(this->gpu()->pathRendering());
bsalomon6663acf2016-05-10 09:14:17 -0700354 return this->gpu()->pathRendering()->createPath(path, style);
bsalomon706f08f2015-05-22 07:35:58 -0700355}
356
357GrPathRange* GrResourceProvider::createPathRange(GrPathRange::PathGenerator* gen,
bsalomon6663acf2016-05-10 09:14:17 -0700358 const GrStyle& style) {
bsalomon706f08f2015-05-22 07:35:58 -0700359 SkASSERT(this->gpu()->pathRendering());
bsalomon6663acf2016-05-10 09:14:17 -0700360 return this->gpu()->pathRendering()->createPathRange(gen, style);
bsalomon706f08f2015-05-22 07:35:58 -0700361}
362
reeda9322c22016-04-12 06:47:05 -0700363GrPathRange* GrResourceProvider::createGlyphs(const SkTypeface* tf,
364 const SkScalerContextEffects& effects,
365 const SkDescriptor* desc,
bsalomon6663acf2016-05-10 09:14:17 -0700366 const GrStyle& style) {
bsalomon706f08f2015-05-22 07:35:58 -0700367
368 SkASSERT(this->gpu()->pathRendering());
bsalomon6663acf2016-05-10 09:14:17 -0700369 return this->gpu()->pathRendering()->createGlyphs(tf, effects, desc, style);
bsalomon706f08f2015-05-22 07:35:58 -0700370}
371
cdaltone2e71c22016-04-07 18:13:29 -0700372GrBuffer* GrResourceProvider::createBuffer(size_t size, GrBufferType intendedType,
cdalton1bf3e712016-04-19 10:00:02 -0700373 GrAccessPattern accessPattern, uint32_t flags,
374 const void* data) {
robertphillips1b8e1b52015-06-24 06:54:10 -0700375 if (this->isAbandoned()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700376 return nullptr;
robertphillips1b8e1b52015-06-24 06:54:10 -0700377 }
cdaltond37fe762016-04-21 07:41:50 -0700378 if (kDynamic_GrAccessPattern != accessPattern) {
379 return this->gpu()->createBuffer(size, intendedType, accessPattern, data);
380 }
csmartdalton485a1202016-07-13 10:16:32 -0700381 if (!(flags & kRequireGpuMemory_Flag) &&
382 this->gpu()->caps()->preferClientSideDynamicBuffers() &&
383 GrBufferTypeIsVertexOrIndex(intendedType) &&
384 kDynamic_GrAccessPattern == accessPattern) {
385 return GrBuffer::CreateCPUBacked(this->gpu(), size, intendedType, data);
386 }
robertphillips1b8e1b52015-06-24 06:54:10 -0700387
cdaltond37fe762016-04-21 07:41:50 -0700388 // bin by pow2 with a reasonable min
Robert Phillips9e380472016-10-28 12:15:03 -0400389 static const size_t MIN_SIZE = 1 << 12;
390 size_t allocSize = SkTMax(MIN_SIZE, GrNextSizePow2(size));
robertphillips1b8e1b52015-06-24 06:54:10 -0700391
cdaltond37fe762016-04-21 07:41:50 -0700392 GrScratchKey key;
csmartdalton485a1202016-07-13 10:16:32 -0700393 GrBuffer::ComputeScratchKeyForDynamicVBO(allocSize, intendedType, &key);
cdaltond37fe762016-04-21 07:41:50 -0700394 uint32_t scratchFlags = 0;
395 if (flags & kNoPendingIO_Flag) {
396 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
397 } else {
398 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
399 }
400 GrBuffer* buffer = static_cast<GrBuffer*>(
401 this->cache()->findAndRefScratchResource(key, allocSize, scratchFlags));
402 if (!buffer) {
403 buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrAccessPattern);
404 if (!buffer) {
405 return nullptr;
robertphillips1b8e1b52015-06-24 06:54:10 -0700406 }
407 }
cdaltond37fe762016-04-21 07:41:50 -0700408 if (data) {
409 buffer->updateData(data, size);
410 }
csmartdalton485a1202016-07-13 10:16:32 -0700411 SkASSERT(!buffer->isCPUBacked()); // We should only cache real VBOs.
cdaltond37fe762016-04-21 07:41:50 -0700412 return buffer;
jvanverth17aa0472016-01-05 10:41:27 -0800413}
414
egdanielec00d942015-09-14 12:56:10 -0700415GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt) {
416 SkASSERT(rt);
417 if (rt->renderTargetPriv().getStencilAttachment()) {
418 return rt->renderTargetPriv().getStencilAttachment();
419 }
420
421 if (!rt->wasDestroyed() && rt->canAttemptStencilAttachment()) {
422 GrUniqueKey sbKey;
423
424 int width = rt->width();
425 int height = rt->height();
426#if 0
427 if (this->caps()->oversizedStencilSupport()) {
428 width = SkNextPow2(width);
429 height = SkNextPow2(height);
430 }
431#endif
432 bool newStencil = false;
433 GrStencilAttachment::ComputeSharedStencilAttachmentKey(width, height,
434 rt->numStencilSamples(), &sbKey);
435 GrStencilAttachment* stencil = static_cast<GrStencilAttachment*>(
436 this->findAndRefResourceByUniqueKey(sbKey));
437 if (!stencil) {
438 // Need to try and create a new stencil
439 stencil = this->gpu()->createStencilAttachmentForRenderTarget(rt, width, height);
440 if (stencil) {
Robert Phillipsf7cf81a2017-03-02 10:23:52 -0500441 this->assignUniqueKeyToResource(sbKey, stencil);
egdanielec00d942015-09-14 12:56:10 -0700442 newStencil = true;
443 }
444 }
445 if (rt->renderTargetPriv().attachStencilAttachment(stencil)) {
446 if (newStencil) {
447 // Right now we're clearing the stencil attachment here after it is
bsalomon7ea33f52015-11-22 14:51:00 -0800448 // attached to a RT for the first time. When we start matching
egdanielec00d942015-09-14 12:56:10 -0700449 // stencil buffers with smaller color targets this will no longer
450 // be correct because it won't be guaranteed to clear the entire
451 // sb.
452 // We used to clear down in the GL subclass using a special purpose
453 // FBO. But iOS doesn't allow a stencil-only FBO. It reports unsupported
454 // FBO status.
455 this->gpu()->clearStencil(rt);
456 }
457 }
458 }
459 return rt->renderTargetPriv().getStencilAttachment();
460}
461
bungeman6bd52842016-10-27 09:30:08 -0700462sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
463 const GrBackendTextureDesc& desc)
464{
ericrkf7b8b8a2016-02-24 14:49:51 -0800465 if (this->isAbandoned()) {
466 return nullptr;
467 }
kkinnunen49c4c222016-04-01 04:50:37 -0700468 return this->gpu()->wrapBackendTextureAsRenderTarget(desc);
ericrkf7b8b8a2016-02-24 14:49:51 -0800469}
Greg Danield85f97d2017-03-07 13:37:21 -0500470
471sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore() {
472 return fGpu->makeSemaphore();
473}
474
475void GrResourceProvider::takeOwnershipOfSemaphore(sk_sp<GrSemaphore> semaphore) {
476 semaphore->resetGpu(fGpu);
477}
478
479void GrResourceProvider::releaseOwnershipOfSemaphore(sk_sp<GrSemaphore> semaphore) {
480 semaphore->resetGpu(nullptr);
481}