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, bool budg
eted, | 33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
bool 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 // In the case of mipmaps, do not use a scratch texture |
45 kNoCreate_ScratchTextureFlag; | 47 if (mipLevelCount < 2) { |
46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 48 const GrMipLevel& baseMipLevel = texels[0]; |
47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 49 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
48 srcData, rowBytes)) { | 50 kNoCreate_ScratchTextureFlag; |
49 if (!budgeted) { | 51 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
50 texture->resourcePriv().makeUnbudgeted(); | 52 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f
Config, |
| 53 baseMipLevel.fPixels, baseMipLevel.fRow
Bytes)) { |
| 54 if (!budgeted) { |
| 55 texture->resourcePriv().makeUnbudgeted(); |
| 56 } |
| 57 return texture; |
51 } | 58 } |
52 return texture; | 59 texture->unref(); |
53 } | 60 } |
54 texture->unref(); | |
55 } | 61 } |
56 } | 62 } |
57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 63 |
| 64 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); |
| 65 for (int i = 0; i < mipLevelCount; ++i) { |
| 66 texelsShallowCopy.push_back(texels[i]); |
| 67 } |
| 68 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); |
| 69 } |
| 70 |
| 71 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
| 72 const void* srcData, size_t rowBytes
) { |
| 73 const int mipLevelCount = 1; |
| 74 GrMipLevel texels[mipLevelCount]; |
| 75 texels[0].fPixels = srcData; |
| 76 texels[0].fRowBytes = rowBytes; |
| 77 |
| 78 return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); |
58 } | 79 } |
59 | 80 |
60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 81 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
61 ASSERT_SINGLE_OWNER | 82 ASSERT_SINGLE_OWNER |
62 return this->internalCreateApproxTexture(desc, 0); | 83 return this->internalCreateApproxTexture(desc, 0); |
63 } | 84 } |
64 | 85 |
65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 86 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
66 uint32_t scratchFlags)
{ | 87 uint32_t scratchFlags)
{ |
67 ASSERT_SINGLE_OWNER | 88 ASSERT_SINGLE_OWNER |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { | 180 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { |
160 ASSERT_SINGLE_OWNER | 181 ASSERT_SINGLE_OWNER |
161 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | 182 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
162 if (resource) { | 183 if (resource) { |
163 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | 184 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
164 SkASSERT(texture); | 185 SkASSERT(texture); |
165 return texture; | 186 return texture; |
166 } | 187 } |
167 return NULL; | 188 return NULL; |
168 } | 189 } |
OLD | NEW |