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 12 matching lines...) Expand all Loading... |
23 return nullptr; | 23 return nullptr; |
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 nullptr; | 27 return nullptr; |
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->refScratchTexture(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(NULL, 0, 0, desc.fWidth, desc.f
Height, 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 if (srcData) { |
| 39 texture->setFromRawPixels(true); |
| 40 } |
38 return texture; | 41 return texture; |
39 } | 42 } |
40 texture->unref(); | 43 texture->unref(); |
41 } | 44 } |
42 } | 45 } |
43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 46 GrTexture* tmp = fGpu->createTexture(desc, budgeted, srcData, rowBytes); |
| 47 if (tmp && srcData) { |
| 48 tmp->setFromRawPixels(true); |
| 49 } |
| 50 return tmp; |
44 } | 51 } |
45 | 52 |
46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 53 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
47 return this->internalCreateApproxTexture(desc, 0); | 54 GrTexture* texture = this->internalCreateApproxTexture(desc, 0); |
| 55 if (texture) { |
| 56 SkASSERT(!texture->fromRawPixels2()); |
| 57 } |
| 58 return texture; |
48 } | 59 } |
49 | 60 |
50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 61 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
51 uint32_t scratchFlags)
{ | 62 uint32_t scratchFlags)
{ |
52 if (this->isAbandoned()) { | 63 if (this->isAbandoned()) { |
53 return nullptr; | 64 return nullptr; |
54 } | 65 } |
55 // Currently we don't recycle compressed textures as scratch. | 66 // Currently we don't recycle compressed textures as scratch. |
56 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 67 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
57 return nullptr; | 68 return nullptr; |
(...skipping 28 matching lines...) Expand all Loading... |
86 // writePixels() which will trigger a flush if the texture has pendi
ng IO. | 97 // writePixels() which will trigger a flush if the texture has pendi
ng IO. |
87 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; | 98 scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag; |
88 } | 99 } |
89 GrGpuResource* resource = fCache->findAndRefScratchResource(key, | 100 GrGpuResource* resource = fCache->findAndRefScratchResource(key, |
90 GrSurface::Wo
rseCaseSize(*desc), | 101 GrSurface::Wo
rseCaseSize(*desc), |
91 scratchFlags)
; | 102 scratchFlags)
; |
92 if (resource) { | 103 if (resource) { |
93 GrSurface* surface = static_cast<GrSurface*>(resource); | 104 GrSurface* surface = static_cast<GrSurface*>(resource); |
94 GrRenderTarget* rt = surface->asRenderTarget(); | 105 GrRenderTarget* rt = surface->asRenderTarget(); |
95 if (rt && fGpu->caps()->discardRenderTargetSupport()) { | 106 if (rt && fGpu->caps()->discardRenderTargetSupport()) { |
| 107 // trash the existing DC in this case |
96 rt->discard(); | 108 rt->discard(); |
97 } | 109 } |
98 return surface->asTexture(); | 110 return surface->asTexture(); |
99 } | 111 } |
100 } | 112 } |
101 | 113 |
102 if (!(kNoCreate_ScratchTextureFlag & flags)) { | 114 if (!(kNoCreate_ScratchTextureFlag & flags)) { |
103 return fGpu->createTexture(*desc, true, nullptr, 0); | 115 return fGpu->createTexture(*desc, true, nullptr, 0); |
104 } | 116 } |
105 | 117 |
(...skipping 20 matching lines...) Expand all Loading... |
126 resource->resourcePriv().setUniqueKey(key); | 138 resource->resourcePriv().setUniqueKey(key); |
127 } | 139 } |
128 | 140 |
129 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { | 141 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { |
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) { |
134 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; | 146 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; |
135 } | 147 } |
OLD | NEW |