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" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 if (this->isAbandoned()) { | 22 if (this->isAbandoned()) { |
23 return NULL; | 23 return NULL; |
24 } | 24 } |
25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
27 return NULL; | 27 return NULL; |
28 } | 28 } |
29 if (!GrPixelConfigIsCompressed(desc.fConfig)) { | 29 if (!GrPixelConfigIsCompressed(desc.fConfig)) { |
30 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 30 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
31 kNoCreate_ScratchTextureFlag; | 31 kNoCreate_ScratchTextureFlag; |
32 if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) { | 32 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
33 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, |
34 srcData, rowBytes)) { | 34 srcData, rowBytes)) { |
35 if (!budgeted) { | 35 if (!budgeted) { |
36 texture->resourcePriv().makeUnbudgeted(); | 36 texture->resourcePriv().makeUnbudgeted(); |
37 } | 37 } |
38 return texture; | 38 return texture; |
39 } | 39 } |
40 texture->unref(); | 40 texture->unref(); |
41 } | 41 } |
42 } | 42 } |
43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); |
44 } | 44 } |
45 | 45 |
46 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& desc, Scrat chTexMatch match, | 46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
47 bool calledDuringFlush) { | 47 return this->internalCreateApproxTexture(desc, 0); |
48 } | |
49 | |
50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d esc, | |
51 uint32_t scratchFlags) { | |
48 if (this->isAbandoned()) { | 52 if (this->isAbandoned()) { |
49 return NULL; | 53 return NULL; |
50 } | 54 } |
51 // Currently we don't recycle compressed textures as scratch. | 55 // Currently we don't recycle compressed textures as scratch. |
52 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 56 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
53 return NULL; | 57 return NULL; |
54 } else { | 58 } else { |
55 uint32_t flags = 0; | 59 return this->refScratchTexture(desc, scratchFlags); |
56 if (kExact_ScratchTexMatch == match) { | |
57 flags |= kExact_ScratchTextureFlag; | |
58 } | |
59 if (calledDuringFlush) { | |
60 flags |= kNoPendingIO_ScratchTextureFlag; | |
61 } | |
62 return this->internalRefScratchTexture(desc, flags); | |
63 } | 60 } |
64 } | 61 } |
65 | 62 |
66 GrTexture* GrTextureProvider::internalRefScratchTexture(const GrSurfaceDesc& inD esc, | 63 GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& inDesc, |
67 uint32_t flags) { | 64 uint32_t scratchFlags) { |
68 SkASSERT(!this->isAbandoned()); | 65 SkASSERT(!this->isAbandoned()); |
69 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); | 66 SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig)); |
70 | 67 |
71 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); | 68 SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc); |
72 | 69 |
73 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) { | 70 if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_Gr SurfaceFlag)) { |
74 if (!(kExact_ScratchTextureFlag & flags)) { | 71 if (!(kExact_ScratchTextureFlag & scratchFlags)) { |
75 // bin by pow2 with a reasonable min | 72 // bin by pow2 with a reasonable min |
76 const int minSize = SkTMin(16, fGpu->caps()->minTextureSize()); | 73 const int minSize = SkTMin(16, fGpu->caps()->minTextureSize()); |
77 GrSurfaceDesc* wdesc = desc.writable(); | 74 GrSurfaceDesc* wdesc = desc.writable(); |
78 wdesc->fWidth = SkTMax(minSize, GrNextPow2(desc->fWidth)); | 75 wdesc->fWidth = SkTMax(minSize, GrNextPow2(desc->fWidth)); |
79 wdesc->fHeight = SkTMax(minSize, GrNextPow2(desc->fHeight)); | 76 wdesc->fHeight = SkTMax(minSize, GrNextPow2(desc->fHeight)); |
80 } | 77 } |
81 | 78 |
82 GrScratchKey key; | 79 GrScratchKey key; |
83 GrTexturePriv::ComputeScratchKey(*desc, &key); | 80 GrTexturePriv::ComputeScratchKey(*desc, &key); |
84 uint32_t scratchFlags = 0; | 81 uint32_t scratchFlags = 0; |
85 if (kNoPendingIO_ScratchTextureFlag & flags) { | 82 if (kNoPendingIO_ScratchTextureFlag & scratchFlags) { |
brucedawson
2015/08/05 17:41:19
This use of scratchFlags now refers to the local v
| |
86 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; | 83 scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag; |
87 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { | 84 } else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) { |
88 // If it is not a render target then it will most likely be populate d by | 85 // If it is not a render target then it will most likely be populate d by |
89 // writePixels() which will trigger a flush if the texture has pendi ng IO. | 86 // writePixels() which will trigger a flush if the texture has pendi ng IO. |
90 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 87 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
91 } | 88 } |
92 GrGpuResource* resource = fCache->findAndRefScratchResource(key, scratch Flags); | 89 GrGpuResource* resource = fCache->findAndRefScratchResource(key, scratch Flags); |
93 if (resource) { | 90 if (resource) { |
94 GrSurface* surface = static_cast<GrSurface*>(resource); | 91 GrSurface* surface = static_cast<GrSurface*>(resource); |
95 GrRenderTarget* rt = surface->asRenderTarget(); | 92 GrRenderTarget* rt = surface->asRenderTarget(); |
96 if (rt && fGpu->caps()->discardRenderTargetSupport()) { | 93 if (rt && fGpu->caps()->discardRenderTargetSupport()) { |
97 rt->discard(); | 94 rt->discard(); |
98 } | 95 } |
99 return surface->asTexture(); | 96 return surface->asTexture(); |
100 } | 97 } |
101 } | 98 } |
102 | 99 |
103 if (!(kNoCreate_ScratchTextureFlag & flags)) { | 100 if (!(kNoCreate_ScratchTextureFlag & scratchFlags)) { |
104 return fGpu->createTexture(*desc, true, NULL, 0); | 101 return fGpu->createTexture(*desc, true, NULL, 0); |
105 } | 102 } |
106 | 103 |
107 return NULL; | 104 return NULL; |
108 } | 105 } |
109 | 106 |
110 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c, | 107 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des c, |
111 GrWrapOwnership ownership) { | 108 GrWrapOwnership ownership) { |
112 if (this->isAbandoned()) { | 109 if (this->isAbandoned()) { |
113 return NULL; | 110 return NULL; |
(...skipping 13 matching lines...) Expand all Loading... | |
127 resource->resourcePriv().setUniqueKey(key); | 124 resource->resourcePriv().setUniqueKey(key); |
128 } | 125 } |
129 | 126 |
130 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t { | 127 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons t { |
131 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); | 128 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); |
132 } | 129 } |
133 | 130 |
134 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) { | 131 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe y& key) { |
135 return this->isAbandoned() ? NULL : fCache->findAndRefUniqueResource(key); | 132 return this->isAbandoned() ? NULL : fCache->findAndRefUniqueResource(key); |
136 } | 133 } |
OLD | NEW |