diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-25 15:51:06 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-25 15:51:06 +0000 |
commit | fea37b5e532dfe776269253afb9951e763c3b205 (patch) | |
tree | 276a520d1cdfad17bdda4ca608bf4192138efdb7 /src | |
parent | 9875dd14af6d768da8d1a4be58b98fc91ceca0dd (diff) |
Add lockKeylessTexture() for caching texture without a content key.
Review URL: http://codereview.appspot.com/4440065/
git-svn-id: http://skia.googlecode.com/svn/trunk@1172 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 118 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 10 |
2 files changed, 59 insertions, 69 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 1c797c3b95..036d9b5ae9 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -192,8 +192,7 @@ SkGpuDevice::~SkGpuDevice() { if (fCache) { GrAssert(NULL != fTexture); GrAssert(fRenderTarget == fTexture->asRenderTarget()); - // IMPORTANT: reattach the rendertarget/tex back to the cache. - fContext->reattachAndUnlockCachedTexture((GrTextureEntry*)fCache); + fContext->unlockTexture((GrTextureEntry*)fCache); } else if (NULL != fTexture) { GrAssert(!CACHE_LAYER_TEXTURES); GrAssert(fRenderTarget == fTexture->asRenderTarget()); @@ -655,34 +654,34 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) { - CHECK_SHOULD_DRAW(draw);
-
- bool doStroke = paint.getStyle() == SkPaint::kStroke_Style;
- SkScalar width = paint.getStrokeWidth();
-
- /*
- We have special code for hairline strokes, miter-strokes, and fills.
- Anything else we just call our path code.
- */
- bool usePath = doStroke && width > 0 &&
- paint.getStrokeJoin() != SkPaint::kMiter_Join;
- // another reason we might need to call drawPath...
- if (paint.getMaskFilter()) {
- usePath = true;
- }
-
- if (usePath) {
- SkPath path;
- path.addRect(rect);
- this->drawPath(draw, path, paint, NULL, true);
- return;
- }
-
- GrPaint grPaint;
- SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
- return;
- }
+ CHECK_SHOULD_DRAW(draw); + + bool doStroke = paint.getStyle() == SkPaint::kStroke_Style; + SkScalar width = paint.getStrokeWidth(); + + /* + We have special code for hairline strokes, miter-strokes, and fills. + Anything else we just call our path code. + */ + bool usePath = doStroke && width > 0 && + paint.getStrokeJoin() != SkPaint::kMiter_Join; + // another reason we might need to call drawPath... + if (paint.getMaskFilter()) { + usePath = true; + } + + if (usePath) { + SkPath path; + path.addRect(rect); + this->drawPath(draw, path, paint, NULL, true); + return; + } + + GrPaint grPaint; + SkAutoCachedTexture act; + if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) { + return; + } fContext->drawRect(grPaint, Sk2Gr(rect), doStroke ? width : -1); } @@ -720,9 +719,9 @@ static bool drawWithMaskFilter(GrContext* context, const SkPath& path, GrAutoMatrix avm(context, GrMatrix::I()); - const GrGpu::TextureDesc desc = { - 0, - GrGpu::kNone_AALevel, + const GrTextureDesc desc = { + kNone_GrTextureFlags, + kNone_GrAALevel, dstM.fBounds.width(), dstM.fBounds.height(), kAlpha_8_GrPixelConfig @@ -1242,40 +1241,36 @@ bool SkGpuDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) { /////////////////////////////////////////////////////////////////////////////// SkGpuDevice::TexCache* SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap, - const GrSamplerState& sampler, - GrTexture** texture, - bool forDeviceRenderTarget) { + const GrSamplerState& sampler, + GrTexture** texture, + bool forDeviceRenderTarget) { + GrTexture* newTexture = NULL; + GrTextureEntry* entry = NULL; GrContext* ctx = this->context(); - uint32_t p0, p1; + if (forDeviceRenderTarget) { - p0 = p1 = -1; + const GrTextureDesc desc = { + kRenderTarget_GrTextureFlagBit, + kNone_GrAALevel, + bitmap.width(), + bitmap.height(), + SkGr::Bitmap2PixelConfig(bitmap) + }; + entry = ctx->lockKeylessTexture(desc, sampler); } else { + uint32_t p0, p1; p0 = bitmap.getGenerationID(); p1 = bitmap.pixelRefOffset(); - } - - GrTexture* newTexture = NULL; - GrTextureKey key(p0, p1, bitmap.width(), bitmap.height()); - GrTextureEntry* entry = ctx->findAndLockTexture(&key, sampler); - if (NULL == entry) { + GrTextureKey key(p0, p1, bitmap.width(), bitmap.height()); + entry = ctx->findAndLockTexture(&key, sampler); - if (forDeviceRenderTarget) { - const GrGpu::TextureDesc desc = { - GrGpu::kRenderTarget_TextureFlag, - GrGpu::kNone_AALevel, - bitmap.width(), - bitmap.height(), - SkGr::Bitmap2PixelConfig(bitmap) - }; - entry = ctx->createAndLockTexture(&key, sampler, desc, NULL, 0); - - } else { - entry = sk_gr_create_bitmap_texture(ctx, &key, sampler, bitmap); - } if (NULL == entry) { - GrPrintf("---- failed to create texture for cache [%d %d]\n", - bitmap.width(), bitmap.height()); + entry = sk_gr_create_bitmap_texture(ctx, &key, sampler, bitmap); + if (NULL == entry) { + GrPrintf("---- failed to create texture for cache [%d %d]\n", + bitmap.width(), bitmap.height()); + } } } @@ -1284,11 +1279,6 @@ SkGpuDevice::TexCache* SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap, if (texture) { *texture = newTexture; } - // IMPORTANT: We can't allow another SkGpuDevice to get this - // cache entry until this one is destroyed! - if (forDeviceRenderTarget) { - ctx->detachCachedTexture(entry); - } } return (TexCache*)entry; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index e7e2365da1..f6e1425e24 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -44,7 +44,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { ctable->unlockColors(false); // always skip a full 256 number of entries, even if we memcpy'd fewer - dst += GrGpu::kColorTableSize; + dst += kGrColorTableSize; if (bitmap.width() == bitmap.rowBytes()) { memcpy(dst, bitmap.getPixels(), bitmap.getSize()); @@ -76,9 +76,9 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx, const SkBitmap* bitmap = &origBitmap; - GrGpu::TextureDesc desc = { - 0, - GrGpu::kNone_AALevel, + GrTextureDesc desc = { + kNone_GrTextureFlags, + kNone_GrAALevel, bitmap->width(), bitmap->height(), SkGr::Bitmap2PixelConfig(*bitmap) @@ -90,7 +90,7 @@ GrTextureEntry* sk_gr_create_bitmap_texture(GrContext* ctx, if (ctx->supportsIndex8PixelConfig(sampler, bitmap->width(), bitmap->height())) { size_t imagesize = bitmap->width() * bitmap->height() + - GrGpu::kColorTableSize; + kGrColorTableSize; SkAutoMalloc storage(imagesize); build_compressed_data(storage.get(), origBitmap); |