OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "GrTextureProvider.h" | 8 #include "GrTextureProvider.h" |
10 #include "GrTexturePriv.h" | 9 #include "GrTexturePriv.h" |
11 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
12 #include "GrGpu.h" | 11 #include "GrGpu.h" |
13 | 12 |
14 enum ScratchTextureFlags { | 13 enum ScratchTextureFlags { |
15 kExact_ScratchTextureFlag = 0x1, | 14 kExact_ScratchTextureFlag = 0x1, |
16 kNoPendingIO_ScratchTextureFlag = 0x2, | 15 kNoPendingIO_ScratchTextureFlag = 0x2, |
17 kNoCreate_ScratchTextureFlag = 0x4, | 16 kNoCreate_ScratchTextureFlag = 0x4, |
18 }; | 17 }; |
19 | 18 |
20 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, | 19 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
21 const void* srcData, size_t rowBytes
) { | 20 const SkTArray<SkMipMapLevel>& texel
s) { |
22 if (this->isAbandoned()) { | 21 if (this->isAbandoned()) { |
23 return nullptr; | 22 return nullptr; |
24 } | 23 } |
25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 24 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 25 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
27 return nullptr; | 26 return nullptr; |
28 } | 27 } |
29 if (!GrPixelConfigIsCompressed(desc.fConfig)) { | 28 if (!GrPixelConfigIsCompressed(desc.fConfig)) { |
30 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 29 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
31 kNoCreate_ScratchTextureFlag; | 30 kNoCreate_ScratchTextureFlag; |
32 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 31 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
33 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 32 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConf
ig, |
34 srcData, rowBytes)) { | 33 texels)) { |
35 if (!budgeted) { | 34 if (!budgeted) { |
36 texture->resourcePriv().makeUnbudgeted(); | 35 texture->resourcePriv().makeUnbudgeted(); |
37 } | 36 } |
38 return texture; | 37 return texture; |
39 } | 38 } |
40 texture->unref(); | 39 texture->unref(); |
41 } | 40 } |
42 } | 41 } |
43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 42 return fGpu->createTexture(desc, budgeted, texels); |
| 43 } |
| 44 |
| 45 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
| 46 const void* srcData, size_t rowBytes
) { |
| 47 const int height = desc.fHeight; |
| 48 const int width = desc.fWidth; |
| 49 if (height < 0 || width < 0) { |
| 50 return nullptr; |
| 51 } |
| 52 const uint32_t baseLevelHeight = height; |
| 53 const uint32_t baseLevelWidth = width; |
| 54 |
| 55 SkMipMapLevel level(srcData, rowBytes, baseLevelWidth, baseLevelHeight); |
| 56 const int mipLevelCount = 1; |
| 57 SkTArray<SkMipMapLevel> texels(mipLevelCount); |
| 58 texels.push_back(level); |
| 59 |
| 60 return this->createTexture(desc, budgeted, texels); |
44 } | 61 } |
45 | 62 |
46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 63 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
47 return this->internalCreateApproxTexture(desc, 0); | 64 return this->internalCreateApproxTexture(desc, 0); |
48 } | 65 } |
49 | 66 |
50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 67 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
51 uint32_t scratchFlags)
{ | 68 uint32_t scratchFlags)
{ |
52 if (this->isAbandoned()) { | 69 if (this->isAbandoned()) { |
53 return nullptr; | 70 return nullptr; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 resource->resourcePriv().setUniqueKey(key); | 143 resource->resourcePriv().setUniqueKey(key); |
127 } | 144 } |
128 | 145 |
129 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { | 146 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { |
130 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); | 147 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); |
131 } | 148 } |
132 | 149 |
133 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe
y& key) { | 150 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe
y& key) { |
134 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; | 151 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; |
135 } | 152 } |
OLD | NEW |