Add config8888 support to writePixels
Review URL: http://codereview.appspot.com/5374052/
git-svn-id: http://skia.googlecode.com/svn/trunk@2662 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 64d74ee..7230516 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -299,20 +299,48 @@
bitmap.rowBytes());
}
-void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y) {
+// This can be removed when temporary code in writePixels is removed
+#include "SkConfig8888.h"
+
+void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y,
+ SkCanvas::Config8888 config8888) {
SkAutoLockPixels alp(bitmap);
if (!bitmap.readyToDraw()) {
return;
}
- GrPixelConfig config = SkGr::BitmapConfig2PixelConfig(bitmap.config(),
- bitmap.isOpaque());
+
+ GrPixelConfig config;
+ if (SkBitmap::kARGB_8888_Config == bitmap.config()) {
+ config = config8888_to_gr_config(config8888);
+ } else {
+ config= SkGr::BitmapConfig2PixelConfig(bitmap.config(),
+ bitmap.isOpaque());
+ }
+
+ // Temporary until we add support for drawing from an unpremul config in
+ // GrContext
+ const SkBitmap* src = &bitmap;
+ SkBitmap tmp;
+ if (GrPixelConfigIsUnpremultiplied(config)) {
+ config = kSkia8888_PM_GrPixelConfig;
+ tmp.setConfig(SkBitmap::kARGB_8888_Config,
+ bitmap.width(), bitmap.height());
+ if (!tmp.allocPixels()) {
+ return;
+ }
+ SkAutoLockPixels alp(bitmap);
+ uint32_t* pixels = reinterpret_cast<uint32_t*>(bitmap.getPixels());
+ SkCopyConfig8888ToBitmap(tmp, pixels, bitmap.rowBytes(), config8888);
+ src = &tmp;
+ }
+
fContext->setRenderTarget(fRenderTarget);
// we aren't setting the clip or matrix, so mark as dirty
// we don't need to set them for this call and don't have them anyway
fNeedPrepareRenderTarget = true;
- fContext->writePixels(x, y, bitmap.width(), bitmap.height(),
- config, bitmap.getPixels(), bitmap.rowBytes());
+ fContext->writePixels(x, y, src->width(), src->height(),
+ config, src->getPixels(), src->rowBytes());
}
///////////////////////////////////////////////////////////////////////////////