Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: src/gpu/GrTextureProvider.cpp

Issue 1575093002: Reland of Add guards to GrTextureProvider (Closed) Base URL: https://skia.googlesource.com/skia.git@gpudeviceguards
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrResourceProvider.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrTextureProvider.h" 9 #include "GrTextureProvider.h"
10 #include "GrTexturePriv.h" 10 #include "GrTexturePriv.h"
11 #include "GrResourceCache.h" 11 #include "GrResourceCache.h"
12 #include "GrGpu.h" 12 #include "GrGpu.h"
13 #include "../private/GrSingleOwner.h"
14
15 #define ASSERT_SINGLE_OWNER \
16 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);)
13 17
14 enum ScratchTextureFlags { 18 enum ScratchTextureFlags {
15 kExact_ScratchTextureFlag = 0x1, 19 kExact_ScratchTextureFlag = 0x1,
16 kNoPendingIO_ScratchTextureFlag = 0x2, 20 kNoPendingIO_ScratchTextureFlag = 0x2,
17 kNoCreate_ScratchTextureFlag = 0x4, 21 kNoCreate_ScratchTextureFlag = 0x4,
18 }; 22 };
19 23
24 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl eOwner* singleOwner)
25 : fCache(cache)
26 , fGpu(gpu)
27 #ifdef SK_DEBUG
28 , fSingleOwner(singleOwner)
29 #endif
30 {
31 }
32
20 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted, 33 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted,
21 const void* srcData, size_t rowBytes ) { 34 const void* srcData, size_t rowBytes ) {
35 ASSERT_SINGLE_OWNER
22 if (this->isAbandoned()) { 36 if (this->isAbandoned()) {
23 return nullptr; 37 return nullptr;
24 } 38 }
25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && 39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
27 return nullptr; 41 return nullptr;
28 } 42 }
29 if (!GrPixelConfigIsCompressed(desc.fConfig)) { 43 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
30 static const uint32_t kFlags = kExact_ScratchTextureFlag | 44 static const uint32_t kFlags = kExact_ScratchTextureFlag |
31 kNoCreate_ScratchTextureFlag; 45 kNoCreate_ScratchTextureFlag;
32 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { 46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
33 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig, 47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig,
34 srcData, rowBytes)) { 48 srcData, rowBytes)) {
35 if (!budgeted) { 49 if (!budgeted) {
36 texture->resourcePriv().makeUnbudgeted(); 50 texture->resourcePriv().makeUnbudgeted();
37 } 51 }
38 return texture; 52 return texture;
39 } 53 }
40 texture->unref(); 54 texture->unref();
41 } 55 }
42 } 56 }
43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); 57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes);
44 } 58 }
45 59
46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { 60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
61 ASSERT_SINGLE_OWNER
47 return this->internalCreateApproxTexture(desc, 0); 62 return this->internalCreateApproxTexture(desc, 0);
48 } 63 }
49 64
50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc, 65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc,
51 uint32_t scratchFlags) { 66 uint32_t scratchFlags) {
67 ASSERT_SINGLE_OWNER
52 if (this->isAbandoned()) { 68 if (this->isAbandoned()) {
53 return nullptr; 69 return nullptr;
54 } 70 }
55 // Currently we don't recycle compressed textures as scratch. 71 // Currently we don't recycle compressed textures as scratch.
56 if (GrPixelConfigIsCompressed(desc.fConfig)) { 72 if (GrPixelConfigIsCompressed(desc.fConfig)) {
57 return nullptr; 73 return nullptr;
58 } else { 74 } else {
59 return this->refScratchTexture(desc, scratchFlags); 75 return this->refScratchTexture(desc, scratchFlags);
60 } 76 }
61 } 77 }
62 78
63 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc, 79 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
64 uint32_t flags) { 80 uint32_t flags) {
81 ASSERT_SINGLE_OWNER
65 SkASSERT(!this->isAbandoned()); 82 SkASSERT(!this->isAbandoned());
66 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); 83 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
67 84
68 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); 85 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
69 86
70 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) { 87 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) {
71 if (!(kExact_ScratchTextureFlag & flags)) { 88 if (!(kExact_ScratchTextureFlag & flags)) {
72 // bin by pow2 with a reasonable min 89 // bin by pow2 with a reasonable min
73 const int kMinSize = 16; 90 const int kMinSize = 16;
74 GrSurfaceDesc* wdesc = desc.writable(); 91 GrSurfaceDesc* wdesc = desc.writable();
(...skipping 26 matching lines...) Expand all
101 118
102 if (!(kNoCreate_ScratchTextureFlag & flags)) { 119 if (!(kNoCreate_ScratchTextureFlag & flags)) {
103 return fGpu->createTexture(*desc, true, nullptr, 0); 120 return fGpu->createTexture(*desc, true, nullptr, 0);
104 } 121 }
105 122
106 return nullptr; 123 return nullptr;
107 } 124 }
108 125
109 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c, 126 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c,
110 GrWrapOwnership ownership) { 127 GrWrapOwnership ownership) {
128 ASSERT_SINGLE_OWNER
111 if (this->isAbandoned()) { 129 if (this->isAbandoned()) {
112 return nullptr; 130 return nullptr;
113 } 131 }
114 return fGpu->wrapBackendTexture(desc, ownership); 132 return fGpu->wrapBackendTexture(desc, ownership);
115 } 133 }
116 134
117 GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRender TargetDesc& desc) { 135 GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRender TargetDesc& desc) {
136 ASSERT_SINGLE_OWNER
118 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc, 137 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc,
119 kBorrow_Gr WrapOwnership); 138 kBorrow _GrWrapOwnership);
120 } 139 }
121 140
122 void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuR esource* resource) { 141 void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuR esource* resource) {
142 ASSERT_SINGLE_OWNER
123 if (this->isAbandoned() || !resource) { 143 if (this->isAbandoned() || !resource) {
124 return; 144 return;
125 } 145 }
126 resource->resourcePriv().setUniqueKey(key); 146 resource->resourcePriv().setUniqueKey(key);
127 } 147 }
128 148
129 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t { 149 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t {
150 ASSERT_SINGLE_OWNER
130 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); 151 return this->isAbandoned() ? false : fCache->hasUniqueKey(key);
131 } 152 }
132 153
133 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) { 154 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) {
155 ASSERT_SINGLE_OWNER
134 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key) ; 156 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key) ;
135 } 157 }
158
159 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke y) {
160 ASSERT_SINGLE_OWNER
161 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
162 if (resource) {
163 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
164 SkASSERT(texture);
165 return texture;
166 }
167 return NULL;
168 }
OLDNEW
« no previous file with comments | « src/gpu/GrResourceProvider.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698