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