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

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

Issue 1565313003: Revert 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);)
17 13
18 enum ScratchTextureFlags { 14 enum ScratchTextureFlags {
19 kExact_ScratchTextureFlag = 0x1, 15 kExact_ScratchTextureFlag = 0x1,
20 kNoPendingIO_ScratchTextureFlag = 0x2, 16 kNoPendingIO_ScratchTextureFlag = 0x2,
21 kNoCreate_ScratchTextureFlag = 0x4, 17 kNoCreate_ScratchTextureFlag = 0x4,
22 }; 18 };
23 19
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
33 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted, 20 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg eted,
34 const void* srcData, size_t rowBytes ) { 21 const void* srcData, size_t rowBytes ) {
35 ASSERT_SINGLE_OWNER
36 if (this->isAbandoned()) { 22 if (this->isAbandoned()) {
37 return nullptr; 23 return nullptr;
38 } 24 }
39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && 25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { 26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
41 return nullptr; 27 return nullptr;
42 } 28 }
43 if (!GrPixelConfigIsCompressed(desc.fConfig)) { 29 if (!GrPixelConfigIsCompressed(desc.fConfig)) {
44 static const uint32_t kFlags = kExact_ScratchTextureFlag | 30 static const uint32_t kFlags = kExact_ScratchTextureFlag |
45 kNoCreate_ScratchTextureFlag; 31 kNoCreate_ScratchTextureFlag;
46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { 32 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig, 33 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight , desc.fConfig,
48 srcData, rowBytes)) { 34 srcData, rowBytes)) {
49 if (!budgeted) { 35 if (!budgeted) {
50 texture->resourcePriv().makeUnbudgeted(); 36 texture->resourcePriv().makeUnbudgeted();
51 } 37 }
52 return texture; 38 return texture;
53 } 39 }
54 texture->unref(); 40 texture->unref();
55 } 41 }
56 } 42 }
57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); 43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes);
58 } 44 }
59 45
60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { 46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) {
61 ASSERT_SINGLE_OWNER
62 return this->internalCreateApproxTexture(desc, 0); 47 return this->internalCreateApproxTexture(desc, 0);
63 } 48 }
64 49
65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc, 50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc,
66 uint32_t scratchFlags) { 51 uint32_t scratchFlags) {
67 ASSERT_SINGLE_OWNER
68 if (this->isAbandoned()) { 52 if (this->isAbandoned()) {
69 return nullptr; 53 return nullptr;
70 } 54 }
71 // Currently we don't recycle compressed textures as scratch. 55 // Currently we don't recycle compressed textures as scratch.
72 if (GrPixelConfigIsCompressed(desc.fConfig)) { 56 if (GrPixelConfigIsCompressed(desc.fConfig)) {
73 return nullptr; 57 return nullptr;
74 } else { 58 } else {
75 return this->refScratchTexture(desc, scratchFlags); 59 return this->refScratchTexture(desc, scratchFlags);
76 } 60 }
77 } 61 }
78 62
79 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc, 63 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
80 uint32_t flags) { 64 uint32_t flags) {
81 ASSERT_SINGLE_OWNER
82 SkASSERT(!this->isAbandoned()); 65 SkASSERT(!this->isAbandoned());
83 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); 66 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
84 67
85 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); 68 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
86 69
87 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) { 70 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) {
88 if (!(kExact_ScratchTextureFlag & flags)) { 71 if (!(kExact_ScratchTextureFlag & flags)) {
89 // bin by pow2 with a reasonable min 72 // bin by pow2 with a reasonable min
90 const int kMinSize = 16; 73 const int kMinSize = 16;
91 GrSurfaceDesc* wdesc = desc.writable(); 74 GrSurfaceDesc* wdesc = desc.writable();
(...skipping 26 matching lines...) Expand all
118 101
119 if (!(kNoCreate_ScratchTextureFlag & flags)) { 102 if (!(kNoCreate_ScratchTextureFlag & flags)) {
120 return fGpu->createTexture(*desc, true, nullptr, 0); 103 return fGpu->createTexture(*desc, true, nullptr, 0);
121 } 104 }
122 105
123 return nullptr; 106 return nullptr;
124 } 107 }
125 108
126 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c, 109 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c,
127 GrWrapOwnership ownership) { 110 GrWrapOwnership ownership) {
128 ASSERT_SINGLE_OWNER
129 if (this->isAbandoned()) { 111 if (this->isAbandoned()) {
130 return nullptr; 112 return nullptr;
131 } 113 }
132 return fGpu->wrapBackendTexture(desc, ownership); 114 return fGpu->wrapBackendTexture(desc, ownership);
133 } 115 }
134 116
135 GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRender TargetDesc& desc) { 117 GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRender TargetDesc& desc) {
136 ASSERT_SINGLE_OWNER
137 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc, 118 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc,
138 kBorrow _GrWrapOwnership); 119 kBorrow_Gr WrapOwnership);
139 } 120 }
140 121
141 void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuR esource* resource) { 122 void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuR esource* resource) {
142 ASSERT_SINGLE_OWNER
143 if (this->isAbandoned() || !resource) { 123 if (this->isAbandoned() || !resource) {
144 return; 124 return;
145 } 125 }
146 resource->resourcePriv().setUniqueKey(key); 126 resource->resourcePriv().setUniqueKey(key);
147 } 127 }
148 128
149 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t { 129 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t {
150 ASSERT_SINGLE_OWNER
151 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); 130 return this->isAbandoned() ? false : fCache->hasUniqueKey(key);
152 } 131 }
153 132
154 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) { 133 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) {
155 ASSERT_SINGLE_OWNER
156 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key) ; 134 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key) ;
157 } 135 }
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