| 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" |
| 12 #include "GrGpu.h" | 11 #include "GrGpu.h" |
| 13 | 12 |
| 14 enum ScratchTextureFlags { | 13 enum ScratchTextureFlags { |
| 15 kExact_ScratchTextureFlag = 0x1, | 14 kExact_ScratchTextureFlag = 0x1, |
| 16 kNoPendingIO_ScratchTextureFlag = 0x2, | 15 kNoPendingIO_ScratchTextureFlag = 0x2, |
| 17 kNoCreate_ScratchTextureFlag = 0x4, | 16 kNoCreate_ScratchTextureFlag = 0x4, |
| 18 }; | 17 }; |
| 19 | 18 |
| 20 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, | 19 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
| 21 const void* srcData, size_t rowBytes
) { | 20 const SkTArray<SkMipMapLevel>& texel
s) { |
| 22 if (this->isAbandoned()) { | 21 if (this->isAbandoned()) { |
| 23 return nullptr; | 22 return nullptr; |
| 24 } | 23 } |
| 25 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && | 24 if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) && |
| 26 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { | 25 !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { |
| 27 return nullptr; | 26 return nullptr; |
| 28 } | 27 } |
| 29 if (!GrPixelConfigIsCompressed(desc.fConfig)) { | 28 if (!GrPixelConfigIsCompressed(desc.fConfig)) { |
| 30 static const uint32_t kFlags = kExact_ScratchTextureFlag | | 29 static const uint32_t kFlags = kExact_ScratchTextureFlag | |
| 31 kNoCreate_ScratchTextureFlag; | 30 kNoCreate_ScratchTextureFlag; |
| 32 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { | 31 if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) { |
| 33 if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight
, desc.fConfig, | 32 if (texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConf
ig, |
| 34 srcData, rowBytes)) { | 33 texels)) { |
| 35 if (!budgeted) { | 34 if (!budgeted) { |
| 36 texture->resourcePriv().makeUnbudgeted(); | 35 texture->resourcePriv().makeUnbudgeted(); |
| 37 } | 36 } |
| 38 return texture; | 37 return texture; |
| 39 } | 38 } |
| 40 texture->unref(); | 39 texture->unref(); |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 return fGpu->createTexture(desc, budgeted, srcData, rowBytes); | 42 return fGpu->createTexture(desc, budgeted, texels); |
| 43 } |
| 44 |
| 45 GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budg
eted, |
| 46 const void* srcData, size_t rowBytes
) { |
| 47 SkMipMapLevel level(srcData, rowBytes); |
| 48 const int mipLevelCount = 1; |
| 49 SkTArray<SkMipMapLevel> texels(mipLevelCount); |
| 50 texels.push_back(level); |
| 51 return this->createTexture(desc, budgeted, texels); |
| 44 } | 52 } |
| 45 | 53 |
| 46 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { | 54 GrTexture* GrTextureProvider::createApproxTexture(const GrSurfaceDesc& desc) { |
| 47 return this->internalCreateApproxTexture(desc, 0); | 55 return this->internalCreateApproxTexture(desc, 0); |
| 48 } | 56 } |
| 49 | 57 |
| 50 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, | 58 GrTexture* GrTextureProvider::internalCreateApproxTexture(const GrSurfaceDesc& d
esc, |
| 51 uint32_t scratchFlags)
{ | 59 uint32_t scratchFlags)
{ |
| 52 if (this->isAbandoned()) { | 60 if (this->isAbandoned()) { |
| 53 return nullptr; | 61 return nullptr; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 resource->resourcePriv().setUniqueKey(key); | 134 resource->resourcePriv().setUniqueKey(key); |
| 127 } | 135 } |
| 128 | 136 |
| 129 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { | 137 bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) cons
t { |
| 130 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); | 138 return this->isAbandoned() ? false : fCache->hasUniqueKey(key); |
| 131 } | 139 } |
| 132 | 140 |
| 133 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe
y& key) { | 141 GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKe
y& key) { |
| 134 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; | 142 return this->isAbandoned() ? nullptr : fCache->findAndRefUniqueResource(key)
; |
| 135 } | 143 } |
| OLD | NEW |