OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrTextureProvider.h" | 8 #include "GrTextureProvider.h" |
9 #include "GrTexturePriv.h" | 9 #include "GrTexturePriv.h" |
10 #include "GrResourceCache.h" | 10 #include "GrResourceCache.h" |
11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
12 #include "../private/GrSingleOwner.h" | 12 #include "../private/GrSingleOwner.h" |
| 13 #include "SkTArray.h" |
13 | 14 |
14 #define ASSERT_SINGLE_OWNER \ | 15 #define ASSERT_SINGLE_OWNER \ |
15 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) | 16 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fSingleOwner);) |
16 | 17 |
17 enum ScratchTextureFlags { | 18 enum ScratchTextureFlags { |
18 kExact_ScratchTextureFlag = 0x1, | 19 kExact_ScratchTextureFlag = 0x1, |
19 kNoPendingIO_ScratchTextureFlag = 0x2, | 20 kNoPendingIO_ScratchTextureFlag = 0x2, |
20 kNoCreate_ScratchTextureFlag = 0x4, | 21 kNoCreate_ScratchTextureFlag = 0x4, |
21 }; | 22 }; |
22 | 23 |
23 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl
eOwner* singleOwner) | 24 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl
eOwner* singleOwner) |
24 : fCache(cache) | 25 : fCache(cache) |
25 , fGpu(gpu) | 26 , fGpu(gpu) |
26 #ifdef SK_DEBUG | 27 #ifdef SK_DEBUG |
27 , fSingleOwner(singleOwner) | 28 , fSingleOwner(singleOwner) |
28 #endif | 29 #endif |
29 { | 30 { |
30 } | 31 } |
31 | 32 |
32 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, | 33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
SkBudgeted budgeted, |
33 const void* srcData, size_t rowBytes
) { | 34 const GrMipLevel* texels, i
nt mipLevelCount) { |
34 ASSERT_SINGLE_OWNER | 35 ASSERT_SINGLE_OWNER |
| 36 |
35 if (this->isAbandoned()) { | 37 if (this->isAbandoned()) { |
36 return nullptr; | 38 return nullptr; |
37 } | 39 } |
38 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 40 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
39 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 41 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
40 return nullptr; | 42 return nullptr; |
41 } | 43 } |
42 if (!GrPixelConfigIsCompressed(desc.fConfig) && | 44 if (!GrPixelConfigIsCompressed(desc.fConfig) && |
43 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { | 45 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { |
44 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 46 if (mipLevelCount < 2) { |
45 kNoCreate_ScratchTextureFlag; | 47 const GrMipLevel& baseMipLevel = texels[0]; |
46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 48 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 49 kNoCreate_ScratchTextureFlag; |
48 srcData, rowBytes)) { | 50 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
49 if (SkBudgeted::kNo == budgeted) { | 51 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f
Config, |
50 texture->resourcePriv().makeUnbudgeted(); | 52 baseMipLevel.fPixels, baseMipLevel.fRow
Bytes)) { |
| 53 if (SkBudgeted::kNo == budgeted) { |
| 54 texture->resourcePriv().makeUnbudgeted(); |
| 55 } |
| 56 return texture; |
51 } | 57 } |
52 return texture; | 58 texture->unref(); |
53 } | 59 } |
54 texture->unref(); | |
55 } | 60 } |
56 } | 61 } |
57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 62 |
| 63 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); |
| 64 for (int i = 0; i < mipLevelCount; ++i) { |
| 65 texelsShallowCopy.push_back(texels[i]); |
| 66 } |
| 67 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); |
| 68 } |
| 69 |
| 70 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, |
| 71 const void* srcData, size_t rowBytes
) { |
| 72 const int mipLevelCount = 1; |
| 73 GrMipLevel texels[mipLevelCount]; |
| 74 texels[0].fPixels = srcData; |
| 75 texels[0].fRowBytes = rowBytes; |
| 76 |
| 77 return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); |
58 } | 78 } |
59 | 79 |
60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 80 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
61 ASSERT_SINGLE_OWNER | 81 ASSERT_SINGLE_OWNER |
62 return this->internalCreateApproxTexture(desc, 0); | 82 return this->internalCreateApproxTexture(desc, 0); |
63 } | 83 } |
64 | 84 |
65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 85 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
66 uint32_t scratchFlags)
{ | 86 uint32_t scratchFlags)
{ |
67 ASSERT_SINGLE_OWNER | 87 ASSERT_SINGLE_OWNER |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { | 179 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { |
160 ASSERT_SINGLE_OWNER | 180 ASSERT_SINGLE_OWNER |
161 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | 181 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
162 if (resource) { | 182 if (resource) { |
163 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | 183 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
164 SkASSERT(texture); | 184 SkASSERT(texture); |
165 return texture; | 185 return texture; |
166 } | 186 } |
167 return NULL; | 187 return NULL; |
168 } | 188 } |
OLD | NEW |