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
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 07a946e..e4c1537 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -200,7 +200,10 @@
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 @@
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 @@
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 @@
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 @@
}
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;
}