diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-06 18:41:33 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-06 18:41:33 +0000 |
commit | 3e89524e747b513986abfeeea00b6fac79593f26 (patch) | |
tree | 2ccdbfb082b488e8a60749a07d778d9f82fac33c /src/gpu | |
parent | 332999eabf8738d3b34e91b4a2e92daf5c7d7573 (diff) |
PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is to refactor bitmap later to remove redundancy, and more interestingly, remove the chance for a disconnect between the actual (pixelref) rowbytes and config, and the one claimed by the bitmap.
R=mtklein@google.com, scroggo@google.com
Review URL: https://codereview.chromium.org/68973005
git-svn-id: http://skia.googlecode.com/svn/trunk@12537 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrSurface.cpp | 10 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 28 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 30 | ||||
-rw-r--r-- | src/gpu/SkGrPixelRef.cpp | 32 |
4 files changed, 84 insertions, 16 deletions
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index fed95f232f..1fcc4ff18b 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -8,9 +8,19 @@ #include "GrSurface.h" #include "SkBitmap.h" +#include "SkGr.h" #include "SkImageEncoder.h" #include <stdio.h> +void GrSurface::asImageInfo(SkImageInfo* info) const { + if (!GrPixelConfig2ColorType(this->config(), &info->fColorType)) { + sk_throw(); + } + info->fWidth = this->width(); + info->fHeight = this->height(); + info->fAlphaType = kPremul_SkAlphaType; +} + bool GrSurface::savePixels(const char* filename) { SkBitmap bm; bm.setConfig(SkBitmap::kARGB_8888_Config, this->width(), this->height()); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 07a946ef94..e4c153783b 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -200,7 +200,10 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context, if (NULL == surface) { surface = fRenderTarget; } - SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); + + SkImageInfo info; + surface->asImageInfo(&info); + SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, cached)); this->setPixelRef(pr, 0)->unref(); } @@ -210,8 +213,8 @@ SkGpuDevice::SkGpuDevice(GrContext* context, int width, int height, int sampleCount) - : SkBitmapDevice(config, width, height, false /*isOpaque*/) { - + : SkBitmapDevice(config, width, height, false /*isOpaque*/) +{ fDrawProcs = NULL; fContext = context; @@ -231,6 +234,14 @@ SkGpuDevice::SkGpuDevice(GrContext* context, desc.fConfig = SkBitmapConfig2GrPixelConfig(config); desc.fSampleCnt = sampleCount; + SkImageInfo info; + if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { + sk_throw(); + } + info.fWidth = width; + info.fHeight = height; + info.fAlphaType = kPremul_SkAlphaType; + SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL, 0)); if (NULL != texture) { @@ -240,7 +251,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context, SkASSERT(NULL != fRenderTarget); // wrap the bitmap with a pixelref to expose our texture - SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (texture)); + SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); this->setPixelRef(pr, 0)->unref(); } else { GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", @@ -826,11 +837,12 @@ bool create_mask_GPU(GrContext* context, } SkBitmap wrap_texture(GrTexture* texture) { + SkImageInfo info; + texture->asImageInfo(&info); + SkBitmap result; - bool dummy; - SkBitmap::Config config = grConfig2skConfig(texture->config(), &dummy); - result.setConfig(config, texture->width(), texture->height()); - result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); + result.setConfig(info); + result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); return result; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index c7ae0c8f36..b55256e78e 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -258,3 +258,33 @@ GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) { return kUnknown_GrPixelConfig; } } + +bool GrPixelConfig2ColorType(GrPixelConfig config, SkColorType* ctOut) { + SkColorType ct; + switch (config) { + case kAlpha_8_GrPixelConfig: + ct = kAlpha_8_SkColorType; + break; + case kIndex_8_GrPixelConfig: + ct = kIndex8_SkColorType; + break; + case kRGB_565_GrPixelConfig: + ct = kRGB_565_SkColorType; + break; + case kRGBA_4444_GrPixelConfig: + ct = kARGB_4444_SkColorType; + break; + case kRGBA_8888_GrPixelConfig: + ct = kRGBA_8888_SkColorType; + break; + case kBGRA_8888_GrPixelConfig: + ct = kBGRA_8888_SkColorType; + break; + default: + return false; + } + if (ctOut) { + *ctOut = ct; + } + return true; +} diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index dc5d7558f0..882995e088 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp @@ -18,16 +18,14 @@ // to avoid deadlock with the default one provided by SkPixelRef. SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex); -SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixelRefMutex) { +SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) + : INHERITED(info, &gROLockPixelsPixelRefMutex) { } SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() { } -void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) { - if (ctable) { - *ctable = NULL; - } +bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { fBitmap.reset(); // SkDebugf("---------- calling readpixels in support of lockpixels\n"); if (!this->onReadPixels(&fBitmap, NULL)) { @@ -35,7 +33,14 @@ void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) { return NULL; } fBitmap.lockPixels(); - return fBitmap.getPixels(); + if (NULL == fBitmap.getPixels()) { + return false; + } + + rec->fPixels = fBitmap.getPixels(); + rec->fColorTable = NULL; + rec->fRowBytes = fBitmap.rowBytes(); + return true; } void SkROLockPixelsPixelRef::onUnlockPixels() { @@ -76,6 +81,14 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); + SkImageInfo info; + if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { + return NULL; + } + info.fWidth = desc.fWidth; + info.fHeight = desc.fHeight; + info.fAlphaType = kPremul_SkAlphaType; + GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); if (NULL == dst) { return NULL; @@ -93,14 +106,17 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config dst->releaseRenderTarget(); #endif - SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (dst)); + SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); SkSafeUnref(dst); return pixelRef; } /////////////////////////////////////////////////////////////////////////////// -SkGrPixelRef::SkGrPixelRef(GrSurface* surface, bool transferCacheLock) { +SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, + bool transferCacheLock) + : INHERITED(info) +{ // TODO: figure out if this is responsible for Chrome canvas errors #if 0 // The GrTexture has a ref to the GrRenderTarget but not vice versa. |