| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 { | 30 { |
| 31 } | 31 } |
| 32 | 32 |
| 33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
SkBudgeted budgeted, | 33 GrTexture* GrTextureProvider::createMipMappedTexture(const GrSurfaceDesc& desc,
SkBudgeted budgeted, |
| 34 const GrMipLevel* texels, i
nt mipLevelCount) { | 34 const GrMipLevel* texels, i
nt mipLevelCount) { |
| 35 ASSERT_SINGLE_OWNER | 35 ASSERT_SINGLE_OWNER |
| 36 | 36 |
| 37 if (this->isAbandoned()) { | 37 if (this->isAbandoned()) { |
| 38 return nullptr; | 38 return nullptr; |
| 39 } | 39 } |
| 40 if (mipLevelCount && !texels) { |
| 41 return nullptr; |
| 42 } |
| 43 for (int i = 0; i < mipLevelCount; ++i) { |
| 44 if (!texels[i].fPixels) { |
| 45 return nullptr; |
| 46 } |
| 47 } |
| 48 |
| 40 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 49 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
| 41 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 50 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 42 return nullptr; | 51 return nullptr; |
| 43 } | 52 } |
| 44 if (!GrPixelConfigIsCompressed(desc.fConfig) && | 53 if (!GrPixelConfigIsCompressed(desc.fConfig) && |
| 45 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { | 54 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { |
| 46 if (mipLevelCount < 2) { | 55 if (mipLevelCount < 2) { |
| 47 const GrMipLevel& baseMipLevel = texels[0]; | 56 const GrMipLevel& baseMipLevel = texels[0]; |
| 48 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 57 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
| 49 kNoCreate_ScratchTextureFlag; | 58 kNoCreate_ScratchTextureFlag; |
| 50 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 59 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
| 51 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f
Config, | 60 if (!texels || texture->writePixels(0, 0, desc.fWidth, desc.fHei
ght, desc.fConfig, |
| 52 baseMipLevel.fPixels, baseMipLevel.fRow
Bytes)) { | 61 baseMipLevel.fPixels, baseMi
pLevel.fRowBytes)) { |
| 53 if (SkBudgeted::kNo == budgeted) { | 62 if (SkBudgeted::kNo == budgeted) { |
| 54 texture->resourcePriv().makeUnbudgeted(); | 63 texture->resourcePriv().makeUnbudgeted(); |
| 55 } | 64 } |
| 56 return texture; | 65 return texture; |
| 57 } | 66 } |
| 58 texture->unref(); | 67 texture->unref(); |
| 59 } | 68 } |
| 60 } | 69 } |
| 61 } | 70 } |
| 62 | 71 |
| 63 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); | 72 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); |
| 64 for (int i = 0; i < mipLevelCount; ++i) { | 73 for (int i = 0; i < mipLevelCount; ++i) { |
| 65 texelsShallowCopy.push_back(texels[i]); | 74 texelsShallowCopy.push_back(texels[i]); |
| 66 } | 75 } |
| 67 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); | 76 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); |
| 68 } | 77 } |
| 69 | 78 |
| 70 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, | 79 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, |
| 71 const void* srcData, size_t rowBytes
) { | 80 const void* srcData, size_t rowBytes
) { |
| 72 const int mipLevelCount = 1; | 81 if (srcData) { |
| 73 GrMipLevel texels[mipLevelCount]; | 82 GrMipLevel texels; |
| 74 texels[0].fPixels = srcData; | 83 texels.fPixels = srcData; |
| 75 texels[0].fRowBytes = rowBytes; | 84 texels.fRowBytes = rowBytes; |
| 76 | 85 return this->createMipMappedTexture(desc, budgeted, &texels, 1); |
| 77 return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); | 86 } |
| 87 return this->createMipMappedTexture(desc, budgeted, nullptr, 0); |
| 78 } | 88 } |
| 79 | 89 |
| 80 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 90 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
| 81 ASSERT_SINGLE_OWNER | 91 ASSERT_SINGLE_OWNER |
| 82 return this->internalCreateApproxTexture(desc, 0); | 92 return this->internalCreateApproxTexture(desc, 0); |
| 83 } | 93 } |
| 84 | 94 |
| 85 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 95 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
| 86 uint32_t scratchFlags)
{ | 96 uint32_t scratchFlags)
{ |
| 87 ASSERT_SINGLE_OWNER | 97 ASSERT_SINGLE_OWNER |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { | 189 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { |
| 180 ASSERT_SINGLE_OWNER | 190 ASSERT_SINGLE_OWNER |
| 181 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | 191 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
| 182 if (resource) { | 192 if (resource) { |
| 183 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | 193 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
| 184 SkASSERT(texture); | 194 SkASSERT(texture); |
| 185 return texture; | 195 return texture; |
| 186 } | 196 } |
| 187 return NULL; | 197 return NULL; |
| 188 } | 198 } |
| OLD | NEW |