diff options
author | 2012-06-07 12:08:45 +0000 | |
---|---|---|
committer | 2012-06-07 12:08:45 +0000 | |
commit | 75b3c9633cb9a594dab0ccf51dab1e694c149a18 (patch) | |
tree | ec4669cda6d54e286bf9b92f6495d733cfd58033 /src/gpu | |
parent | 93b4375fd4d87d3502d14d5e6a98383993b2600c (diff) |
Move clientID into texture desc
http://codereview.appspot.com/6305044/
git-svn-id: http://skia.googlecode.com/svn/trunk@4201 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrAtlas.cpp | 13 | ||||
-rw-r--r-- | src/gpu/GrClipMaskManager.cpp | 24 | ||||
-rw-r--r-- | src/gpu/GrClipMaskManager.h | 3 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 60 | ||||
-rw-r--r-- | src/gpu/GrSoftwarePathRenderer.cpp | 11 | ||||
-rw-r--r-- | src/gpu/GrTexture.cpp | 9 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 84 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 22 | ||||
-rw-r--r-- | src/gpu/SkGrTexturePixelRef.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 2 |
10 files changed, 100 insertions, 129 deletions
diff --git a/src/gpu/GrAtlas.cpp b/src/gpu/GrAtlas.cpp index f8586fa0e3..fb127194a5 100644 --- a/src/gpu/GrAtlas.cpp +++ b/src/gpu/GrAtlas.cpp @@ -177,13 +177,12 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas, GrAssert(0 == kA8_GrMaskFormat); GrAssert(1 == kA565_GrMaskFormat); if (NULL == fTexture[format]) { - GrTextureDesc desc = { - kDynamicUpdate_GrTextureFlagBit, - GR_ATLAS_TEXTURE_WIDTH, - GR_ATLAS_TEXTURE_HEIGHT, - maskformat2pixelconfig(format), - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kDynamicUpdate_GrTextureFlagBit; + desc.fWidth = GR_ATLAS_TEXTURE_WIDTH; + desc.fHeight = GR_ATLAS_TEXTURE_HEIGHT; + desc.fConfig = maskformat2pixelconfig(format); + fTexture[format] = fGpu->createTexture(desc, NULL, 0); if (NULL == fTexture[format]) { return NULL; diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp index c0272bbd5d..28ce46d27e 100644 --- a/src/gpu/GrClipMaskManager.cpp +++ b/src/gpu/GrClipMaskManager.cpp @@ -481,13 +481,11 @@ void GrClipMaskManager::getTemp(const GrIRect& bounds, return; } - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit, - bounds.width(), - bounds.height(), - kAlpha_8_GrPixelConfig, - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit; + desc.fWidth = bounds.width(); + desc.fHeight = bounds.height(); + desc.fConfig = kAlpha_8_GrPixelConfig; temp->set(this->getContext(), desc); } @@ -499,13 +497,11 @@ void GrClipMaskManager::setupCache(const GrClip& clipIn, // Free up the currently cached mask so it can be reused fAACache.reset(); - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit, - bounds.width(), - bounds.height(), - kAlpha_8_GrPixelConfig, - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit; + desc.fWidth = bounds.width(); + desc.fHeight = bounds.height(); + desc.fConfig = kAlpha_8_GrPixelConfig; fAACache.acquireMask(clipIn, desc, bounds); } diff --git a/src/gpu/GrClipMaskManager.h b/src/gpu/GrClipMaskManager.h index 2f4d8c7aa7..1acdba5c46 100644 --- a/src/gpu/GrClipMaskManager.h +++ b/src/gpu/GrClipMaskManager.h @@ -251,8 +251,7 @@ private: void reset () { fLastClip.setEmpty(); - const GrTextureDesc desc = { kNone_GrTextureFlags, 0, 0, - kUnknown_GrPixelConfig, 0 }; + GrTextureDesc desc; fLastMask.set(NULL, desc); fLastBound.setEmpty(); diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 1c55ecf627..3708993674 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -252,18 +252,16 @@ void convolve_gaussian(GrGpu* gpu, } GrContext::TextureCacheEntry GrContext::findAndLockTexture( - GrTexture::TextureKey key, const GrTextureDesc& desc, const GrSamplerState* sampler) { - GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key, desc, false); + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, desc, false); return TextureCacheEntry(fTextureCache->findAndLock(resourceKey, GrResourceCache::kNested_LockType)); } -bool GrContext::isTextureInCache(GrTexture::TextureKey key, - const GrTextureDesc& desc, +bool GrContext::isTextureInCache(const GrTextureDesc& desc, const GrSamplerState* sampler) const { - GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key, desc, false); + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, desc, false); return fTextureCache->hasKey(resourceKey); } @@ -323,7 +321,6 @@ static void stretchImage(void* dst, } GrContext::TextureCacheEntry GrContext::createAndLockTexture( - GrTexture::TextureKey key, const GrSamplerState* sampler, const GrTextureDesc& desc, void* srcData, @@ -336,19 +333,18 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture( TextureCacheEntry entry; - GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, key, + GrResourceKey resourceKey = GrTexture::ComputeKey(fGpu, sampler, desc, false); if (GrTexture::NeedsResizing(resourceKey)) { // The desired texture is NPOT and tiled but that isn't supported by // the current hardware. Resize the texture to be a POT GrAssert(NULL != sampler); - TextureCacheEntry clampEntry = this->findAndLockTexture(key, - desc, + TextureCacheEntry clampEntry = this->findAndLockTexture(desc, NULL); if (NULL == clampEntry.texture()) { - clampEntry = this->createAndLockTexture(key, NULL, desc, + clampEntry = this->createAndLockTexture(NULL, desc, srcData, rowBytes); GrAssert(NULL != clampEntry.texture()); if (NULL == clampEntry.texture()) { @@ -438,8 +434,9 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture( GrContext::TextureCacheEntry GrContext::lockScratchTexture( const GrTextureDesc& inDesc, ScratchTexMatch match) { - GrTextureDesc desc = inDesc; + desc.fClientCacheID = kScratch_CacheID; + if (kExact_ScratchTexMatch != match) { // bin by pow2 with a reasonable min static const int MIN_SIZE = 256; @@ -454,7 +451,7 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture( bool doubledH = false; do { - GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, 0, desc, true); + GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, desc, true); entry = fTextureCache->findAndLock(key, GrResourceCache::kNested_LockType); // if we miss, relax the fit of the flags... @@ -487,7 +484,7 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture( desc.fHeight = origHeight; GrTexture* texture = fGpu->createTexture(desc, NULL, 0); if (NULL != texture) { - GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, 0, + GrResourceKey key = GrTexture::ComputeKey(fGpu, NULL, texture->desc(), true); entry = fTextureCache->createAndLock(key, texture); @@ -515,10 +512,12 @@ void GrContext::unlockTexture(TextureCacheEntry entry) { } } -GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& desc, +GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn, void* srcData, size_t rowBytes) { - return fGpu->createTexture(desc, srcData, rowBytes); + GrTextureDesc descCopy = descIn; + descCopy.fClientCacheID = kUncached_CacheID; + return fGpu->createTexture(descCopy, srcData, rowBytes); } void GrContext::getTextureCacheLimits(int* maxTextures, @@ -1547,12 +1546,11 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target, } // Make the scratch a render target because we don't have a robust // readTexturePixels as of yet (it calls this function). - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit, - width, height, - config, - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; // When a full readback is faster than a partial we could always make // the scratch exactly match the passed rect. However, if we see many @@ -1705,9 +1703,11 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target, config = GrPixelConfigSwapRAndB(config); } - const GrTextureDesc desc = { - kNone_GrTextureFlags, width, height, config, 0 - }; + GrTextureDesc desc; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; + GrAutoScratchTexture ast(this, desc); GrTexture* texture = ast.texture(); if (NULL == texture) { @@ -1992,13 +1992,11 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture, kRGBA_8888_PM_GrPixelConfig == srcTexture->config() || kAlpha_8_GrPixelConfig == srcTexture->config()); - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit, - SkScalarFloorToInt(srcRect.width()), - SkScalarFloorToInt(srcRect.height()), - srcTexture->config(), - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; + desc.fWidth = SkScalarFloorToInt(srcRect.width()); + desc.fHeight = SkScalarFloorToInt(srcRect.height()); + desc.fConfig = srcTexture->config(); temp1->set(this, desc); if (temp2) { diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index 99209c6395..1213c41a7f 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -201,13 +201,10 @@ bool GrSWMaskHelper::init(const GrIRect& pathDevBounds, * Get a texture (from the texture cache) of the correct size & format */ bool GrSWMaskHelper::getTexture(GrAutoScratchTexture* tex) { - const GrTextureDesc desc = { - kNone_GrTextureFlags, - fBM.width(), - fBM.height(), - kAlpha_8_GrPixelConfig, - 0 // samples - }; + GrTextureDesc desc; + desc.fWidth = fBM.width(); + desc.fHeight = fBM.height(); + desc.fConfig = kAlpha_8_GrPixelConfig; tex->set(fContext, desc); GrTexture* texture = tex->texture(); diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp index 8dd0b0bcb7..4f4c5f5850 100644 --- a/src/gpu/GrTexture.cpp +++ b/src/gpu/GrTexture.cpp @@ -107,16 +107,16 @@ enum TextureBits { namespace { void gen_texture_key_values(const GrGpu* gpu, const GrSamplerState* sampler, - GrTexture::TextureKey clientKey, const GrTextureDesc& desc, bool scratch, uint32_t v[4]) { - GR_STATIC_ASSERT(sizeof(GrTexture::TextureKey) == sizeof(uint64_t)); + + uint64_t clientKey = desc.fClientCacheID; if (scratch) { // Instead of a client-provided key of the texture contents // we create a key of from the descriptor. - GrAssert(0 == clientKey); + GrAssert(kScratch_CacheID == clientKey); clientKey = (desc.fFlags << 8) | ((uint64_t) desc.fConfig << 32); } @@ -156,11 +156,10 @@ void gen_texture_key_values(const GrGpu* gpu, GrResourceKey GrTexture::ComputeKey(const GrGpu* gpu, const GrSamplerState* sampler, - TextureKey clientKey, const GrTextureDesc& desc, bool scratch) { uint32_t v[4]; - gen_texture_key_values(gpu, sampler, clientKey, desc, scratch, v); + gen_texture_key_values(gpu, sampler, desc, scratch, v); return GrResourceKey(v); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index b0ff43a545..b62e5be39a 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -226,13 +226,11 @@ SkGpuDevice::SkGpuDevice(GrContext* context, SkBitmap bm; bm.setConfig(config, width, height); - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit, - width, - height, - SkGr::BitmapConfig2PixelConfig(bm.config()), - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = SkGr::BitmapConfig2PixelConfig(bm.config()); fTexture = fContext->createUncachedTexture(desc, NULL, 0); @@ -792,15 +790,13 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path, } GrPoint offset = GrPoint::Make(-srcRect.fLeft, -srcRect.fTop); srcRect.offset(offset); - GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit, - SkScalarCeilToInt(srcRect.width()), - SkScalarCeilToInt(srcRect.height()), - // We actually only need A8, but it often isn't supported as a - // render target so default to RGBA_8888 - kRGBA_8888_PM_GrPixelConfig, - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit; + desc.fWidth = SkScalarCeilToInt(srcRect.width()); + desc.fHeight = SkScalarCeilToInt(srcRect.height()); + // We actually only need A8, but it often isn't supported as a + // render target so default to RGBA_8888 + desc.fConfig = kRGBA_8888_PM_GrPixelConfig; if (context->isConfigRenderable(kAlpha_8_GrPixelConfig)) { desc.fConfig = kAlpha_8_GrPixelConfig; @@ -930,13 +926,10 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& path, GrAutoMatrix avm(context, GrMatrix::I()); - const GrTextureDesc desc = { - kNone_GrTextureFlags, - dstM.fBounds.width(), - dstM.fBounds.height(), - kAlpha_8_GrPixelConfig, - 0, // samples - }; + GrTextureDesc desc; + desc.fWidth = dstM.fBounds.width(); + desc.fHeight = dstM.fBounds.height(); + desc.fConfig = kAlpha_8_GrPixelConfig; GrAutoScratchTexture ast(context, desc); GrTexture* texture = ast.texture(); @@ -1436,13 +1429,11 @@ static GrTexture* filter_texture(GrContext* context, GrTexture* texture, SkSize blurSize; SkISize radius; - const GrTextureDesc desc = { - kRenderTarget_GrTextureFlagBit, - SkScalarCeilToInt(rect.width()), - SkScalarCeilToInt(rect.height()), - kRGBA_8888_PM_GrPixelConfig, - 0 // samples - }; + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit, + desc.fWidth = SkScalarCeilToInt(rect.width()); + desc.fHeight = SkScalarCeilToInt(rect.height()); + desc.fConfig = kRGBA_8888_PM_GrPixelConfig; if (filter->asABlur(&blurSize)) { GrAutoScratchTexture temp1, temp2; @@ -1833,24 +1824,21 @@ SkGpuDevice::TexCache SkGpuDevice::lockCachedTexture( GrContext* ctx = this->context(); if (!bitmap.isVolatile()) { - GrTexture::TextureKey key = bitmap.getGenerationID(); + uint64_t key = bitmap.getGenerationID(); key |= ((uint64_t) bitmap.pixelRefOffset()) << 32; - GrTextureDesc desc = { - kNone_GrTextureFlags, - bitmap.width(), - bitmap.height(), - SkGr::BitmapConfig2PixelConfig(bitmap.config()), - 0 // samples - }; + GrTextureDesc desc; + desc.fWidth = bitmap.width(); + desc.fHeight = bitmap.height(); + desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config()); - entry = ctx->findAndLockTexture(key, desc, sampler); + entry = ctx->findAndLockTexture(desc, sampler); if (NULL == entry.texture()) { entry = sk_gr_create_bitmap_texture(ctx, key, sampler, bitmap); } } else { - entry = sk_gr_create_bitmap_texture(ctx, gUNCACHED_KEY, + entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID, sampler, bitmap); } if (NULL == entry.texture()) { @@ -1866,18 +1854,16 @@ void SkGpuDevice::unlockCachedTexture(TexCache cache) { bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap, const GrSamplerState& sampler) const { - GrTexture::TextureKey key = bitmap.getGenerationID(); + uint64_t key = bitmap.getGenerationID(); key |= ((uint64_t) bitmap.pixelRefOffset()) << 32; - GrTextureDesc desc = { - kNone_GrTextureFlags, - bitmap.width(), - bitmap.height(), - SkGr::BitmapConfig2PixelConfig(bitmap.config()), - 0 // samples - }; + GrTextureDesc desc; + desc.fWidth = bitmap.width(); + desc.fHeight = bitmap.height(); + desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config()); + desc.fClientCacheID = key; - return this->context()->isTextureInCache(key, desc, &sampler); + return this->context()->isTextureInCache(desc, &sampler); } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 00a0282887..6fc851a683 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -57,7 +57,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { //////////////////////////////////////////////////////////////////////////////// GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, - GrTexture::TextureKey key, + uint64_t key, const GrSamplerState* sampler, const SkBitmap& origBitmap) { SkAutoLockPixels alp(origBitmap); @@ -71,13 +71,11 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, const SkBitmap* bitmap = &origBitmap; - GrTextureDesc desc = { - kNone_GrTextureFlags, - bitmap->width(), - bitmap->height(), - SkGr::BitmapConfig2PixelConfig(bitmap->config()), - 0 // samples - }; + GrTextureDesc desc; + desc.fWidth = bitmap->width(); + desc.fHeight = bitmap->height(); + desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config()); + desc.fClientCacheID = key; if (SkBitmap::kIndex8_Config == bitmap->config()) { // build_compressed_data doesn't do npot->pot expansion @@ -93,8 +91,8 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, // our compressed data will be trimmed, so pass width() for its // "rowBytes", since they are the same now. - if (gUNCACHED_KEY != key) { - return ctx->createAndLockTexture(key, sampler, desc, storage.get(), + if (kUncached_CacheID != key) { + return ctx->createAndLockTexture(sampler, desc, storage.get(), bitmap->width()); } else { entry = ctx->lockScratchTexture(desc, @@ -113,8 +111,8 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, } desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config()); - if (gUNCACHED_KEY != key) { - return ctx->createAndLockTexture(key, sampler, desc, + if (kUncached_CacheID != key) { + return ctx->createAndLockTexture(sampler, desc, bitmap->getPixels(), bitmap->rowBytes()); } else { diff --git a/src/gpu/SkGrTexturePixelRef.cpp b/src/gpu/SkGrTexturePixelRef.cpp index 485d572c0b..0caf0b40ae 100644 --- a/src/gpu/SkGrTexturePixelRef.cpp +++ b/src/gpu/SkGrTexturePixelRef.cpp @@ -63,7 +63,6 @@ static SkGrTexturePixelRef* copyToTexturePixelRef(GrTexture* texture, desc.fHeight = texture->height(); desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig); - desc.fSampleCnt = 0; GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); if (NULL == dst) { diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index d5c0bd2ed6..da168cda13 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -375,7 +375,6 @@ bool GrGpuGL::canPreserveReadWriteUnpremulPixels() { dstDesc.fWidth = 256; dstDesc.fHeight = 256; dstDesc.fConfig = kRGBA_8888_PM_GrPixelConfig; - dstDesc.fSampleCnt = 0; SkAutoTUnref<GrTexture> dstTex(this->createTexture(dstDesc, NULL, 0)); if (!dstTex.get()) { @@ -1015,6 +1014,7 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc, glTexDesc.fHeight = desc.fHeight; glTexDesc.fConfig = desc.fConfig; glTexDesc.fSampleCnt = desc.fSampleCnt; + glTexDesc.fClientCacheID = desc.fClientCacheID; glTexDesc.fOwnsID = true; |