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" |
(...skipping 12 matching lines...) Expand all Loading... |
24 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl
eOwner* singleOwner) | 23 GrTextureProvider::GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingl
eOwner* singleOwner) |
25 : fCache(cache) | 24 : fCache(cache) |
26 , fGpu(gpu) | 25 , fGpu(gpu) |
27 #ifdef SK_DEBUG | 26 #ifdef SK_DEBUG |
28 , fSingleOwner(singleOwner) | 27 , fSingleOwner(singleOwner) |
29 #endif | 28 #endif |
30 { | 29 { |
31 } | 30 } |
32 | 31 |
33 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, | 32 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
34 const void* srcData, size_t rowBytes
) { | 33 const SkTArray<SkMipMapLevel>& texel
s) { |
35 ASSERT_SINGLE_OWNER | 34 ASSERT_SINGLE_OWNER |
| 35 |
36 if (this->isAbandoned()) { | 36 if (this->isAbandoned()) { |
37 return nullptr; | 37 return nullptr; |
38 } | 38 } |
39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 39 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 40 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
41 return nullptr; | 41 return nullptr; |
42 } | 42 } |
43 if (!GrPixelConfigIsCompressed(desc.fConfig)) { | 43 if (!GrPixelConfigIsCompressed(desc.fConfig)) { |
44 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 44 // In the case of mipmaps, do not use a scratch texture |
45 kNoCreate_ScratchTextureFlag; | 45 if (texels.count() < 2) { |
46 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 46 const SkMipMapLevel& baseMipLevel = texels[0]; |
47 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 47 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
48 srcData, rowBytes)) { | 48 kNoCreate_ScratchTextureFlag; |
49 if (!budgeted) { | 49 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
50 texture->resourcePriv().makeUnbudgeted(); | 50 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f
Config, |
| 51 baseMipLevel.fTexelsOrOffset, baseMipLe
vel.fRowBytes)) { |
| 52 if (!budgeted) { |
| 53 texture->resourcePriv().makeUnbudgeted(); |
| 54 } |
| 55 return texture; |
51 } | 56 } |
52 return texture; | 57 texture->unref(); |
53 } | 58 } |
54 texture->unref(); | |
55 } | 59 } |
56 } | 60 } |
57 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 61 return fGpu->createTexture(desc, budgeted, texels); |
| 62 } |
| 63 |
| 64 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
| 65 const void* srcData, size_t rowBytes
) { |
| 66 SkMipMapLevel level(srcData, rowBytes, desc.fWidth, desc.fHeight); |
| 67 SkSTArray<1, SkMipMapLevel> texels; |
| 68 texels.push_back(level); |
| 69 |
| 70 return this->createTexture(desc, budgeted, texels); |
58 } | 71 } |
59 | 72 |
60 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 73 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
61 ASSERT_SINGLE_OWNER | 74 ASSERT_SINGLE_OWNER |
62 return this->internalCreateApproxTexture(desc, 0); | 75 return this->internalCreateApproxTexture(desc, 0); |
63 } | 76 } |
64 | 77 |
65 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 78 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
66 uint32_t scratchFlags)
{ | 79 uint32_t scratchFlags)
{ |
67 ASSERT_SINGLE_OWNER | 80 ASSERT_SINGLE_OWNER |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { | 172 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { |
160 ASSERT_SINGLE_OWNER | 173 ASSERT_SINGLE_OWNER |
161 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | 174 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
162 if (resource) { | 175 if (resource) { |
163 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | 176 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
164 SkASSERT(texture); | 177 SkASSERT(texture); |
165 return texture; | 178 return texture; |
166 } | 179 } |
167 return NULL; | 180 return NULL; |
168 } | 181 } |
OLD | NEW |