| 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 | |
| 49 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 40 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
| 50 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 41 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 51 return nullptr; | 42 return nullptr; |
| 52 } | 43 } |
| 53 if (!GrPixelConfigIsCompressed(desc.fConfig) && | 44 if (!GrPixelConfigIsCompressed(desc.fConfig) && |
| 54 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { | 45 !desc.fTextureStorageAllocator.fAllocateTextureStorage) { |
| 55 if (mipLevelCount < 2) { | 46 if (mipLevelCount < 2) { |
| 56 const GrMipLevel& baseMipLevel = texels[0]; | 47 const GrMipLevel& baseMipLevel = texels[0]; |
| 57 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 48 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
| 58 kNoCreate_ScratchTextureFlag; | 49 kNoCreate_ScratchTextureFlag; |
| 59 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 50 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
| 60 if (!texels || texture->writePixels(0, 0, desc.fWidth, desc.fHei
ght, desc.fConfig, | 51 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.f
Config, |
| 61 baseMipLevel.fPixels, baseMi
pLevel.fRowBytes)) { | 52 baseMipLevel.fPixels, baseMipLevel.fRow
Bytes)) { |
| 62 if (SkBudgeted::kNo == budgeted) { | 53 if (SkBudgeted::kNo == budgeted) { |
| 63 texture->resourcePriv().makeUnbudgeted(); | 54 texture->resourcePriv().makeUnbudgeted(); |
| 64 } | 55 } |
| 65 return texture; | 56 return texture; |
| 66 } | 57 } |
| 67 texture->unref(); | 58 texture->unref(); |
| 68 } | 59 } |
| 69 } | 60 } |
| 70 } | 61 } |
| 71 | 62 |
| 72 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); | 63 SkTArray<GrMipLevel> texelsShallowCopy(mipLevelCount); |
| 73 for (int i = 0; i < mipLevelCount; ++i) { | 64 for (int i = 0; i < mipLevelCount; ++i) { |
| 74 texelsShallowCopy.push_back(texels[i]); | 65 texelsShallowCopy.push_back(texels[i]); |
| 75 } | 66 } |
| 76 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); | 67 return fGpu->createTexture(desc, budgeted, texelsShallowCopy); |
| 77 } | 68 } |
| 78 | 69 |
| 79 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, | 70 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgete
d budgeted, |
| 80 const void* srcData, size_t rowBytes
) { | 71 const void* srcData, size_t rowBytes
) { |
| 81 GrMipLevel tempTexels; | 72 const int mipLevelCount = 1; |
| 82 GrMipLevel* texels = nullptr; | 73 GrMipLevel texels[mipLevelCount]; |
| 83 int levelCount = 0; | 74 texels[0].fPixels = srcData; |
| 84 if (srcData) { | 75 texels[0].fRowBytes = rowBytes; |
| 85 tempTexels.fPixels = srcData; | 76 |
| 86 tempTexels.fRowBytes = rowBytes; | 77 return this->createMipMappedTexture(desc, budgeted, texels, mipLevelCount); |
| 87 texels = &tempTexels; | |
| 88 levelCount = 1; | |
| 89 } | |
| 90 return this->createMipMappedTexture(desc, budgeted, texels, levelCount); | |
| 91 } | 78 } |
| 92 | 79 |
| 93 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 80 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
| 94 ASSERT_SINGLE_OWNER | 81 ASSERT_SINGLE_OWNER |
| 95 return this->internalCreateApproxTexture(desc, 0); | 82 return this->internalCreateApproxTexture(desc, 0); |
| 96 } | 83 } |
| 97 | 84 |
| 98 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 85 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
| 99 uint32_t scratchFlags)
{ | 86 uint32_t scratchFlags)
{ |
| 100 ASSERT_SINGLE_OWNER | 87 ASSERT_SINGLE_OWNER |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 GrSurface* surface = static_cast<GrSurface*>(resource); | 130 GrSurface* surface = static_cast<GrSurface*>(resource); |
| 144 GrRenderTarget* rt = surface->asRenderTarget(); | 131 GrRenderTarget* rt = surface->asRenderTarget(); |
| 145 if (rt && fGpu->caps()->discardRenderTargetSupport()) { | 132 if (rt && fGpu->caps()->discardRenderTargetSupport()) { |
| 146 rt->discard(); | 133 rt->discard(); |
| 147 } | 134 } |
| 148 return surface->asTexture(); | 135 return surface->asTexture(); |
| 149 } | 136 } |
| 150 } | 137 } |
| 151 | 138 |
| 152 if (!(kNoCreate_ScratchTextureFlag & flags)) { | 139 if (!(kNoCreate_ScratchTextureFlag & flags)) { |
| 153 return fGpu->createTexture(*desc, SkBudgeted::kYes); | 140 return fGpu->createTexture(*desc, SkBudgeted::kYes, nullptr, 0); |
| 154 } | 141 } |
| 155 | 142 |
| 156 return nullptr; | 143 return nullptr; |
| 157 } | 144 } |
| 158 | 145 |
| 159 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des
c, | 146 GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& des
c, |
| 160 GrWrapOwnership ownership) { | 147 GrWrapOwnership ownership) { |
| 161 ASSERT_SINGLE_OWNER | 148 ASSERT_SINGLE_OWNER |
| 162 if (this->isAbandoned()) { | 149 if (this->isAbandoned()) { |
| 163 return nullptr; | 150 return nullptr; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 192 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { | 179 GrTexture* GrTextureProvider::findAndRefTextureByUniqueKey(const GrUniqueKey& ke
y) { |
| 193 ASSERT_SINGLE_OWNER | 180 ASSERT_SINGLE_OWNER |
| 194 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | 181 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
| 195 if (resource) { | 182 if (resource) { |
| 196 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | 183 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
| 197 SkASSERT(texture); | 184 SkASSERT(texture); |
| 198 return texture; | 185 return texture; |
| 199 } | 186 } |
| 200 return NULL; | 187 return NULL; |
| 201 } | 188 } |
| OLD | NEW |