Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: src/core/SkBitmapDevice.cpp

Issue 180113010: Add SkCanvas::writePixels that takes info+pixels directly (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/SkGpuDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapDevice.cpp
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 7ed8058c6a371b0f7e69221a8d786fe3f6927c27..098f0fc96ce95b9c12710cfb2f938a7e0e55cc40 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -199,6 +199,7 @@ bool SkBitmapDevice::onReadPixels(const SkBitmap& bitmap,
return true;
}
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
void SkBitmapDevice::writePixels(const SkBitmap& bitmap,
int x, int y,
SkCanvas::Config8888 config8888) {
@@ -265,6 +266,96 @@ void SkBitmapDevice::writePixels(const SkBitmap& bitmap,
draw.fMatrix = &SkMatrix::I();
this->drawSprite(draw, *sprite, x, y, paint);
}
+#endif
+
+static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow,
+ int rowCount) {
+ SkASSERT(bytesPerRow <= srcRB);
+ SkASSERT(bytesPerRow <= dstRB);
+ for (int i = 0; i < rowCount; ++i) {
+ memcpy(dst, src, bytesPerRow);
+ dst = (char*)dst + dstRB;
+ src = (const char*)src + srcRB;
+ }
+}
+
+static bool info2config8888(const SkImageInfo& info, SkCanvas::Config8888* config) {
+ bool pre;
+ switch (info.alphaType()) {
+ case kPremul_SkAlphaType:
+ case kOpaque_SkAlphaType:
+ pre = true;
+ break;
+ case kUnpremul_SkAlphaType:
+ pre = false;
+ break;
+ default:
+ return false;
+ }
+ switch (info.colorType()) {
+ case kRGBA_8888_SkColorType:
+ *config = pre ? SkCanvas::kRGBA_Premul_Config8888 : SkCanvas::kRGBA_Unpremul_Config8888;
+ return true;
+ case kBGRA_8888_SkColorType:
+ *config = pre ? SkCanvas::kBGRA_Premul_Config8888 : SkCanvas::kBGRA_Unpremul_Config8888;
+ return true;
+ default:
+ return false;
+ }
+}
+
+// TODO: make this guy real, and not rely on legacy config8888 utility
+#include "SkConfig8888.h"
+static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
+ const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes) {
+ if (srcInfo.dimensions() != dstInfo.dimensions()) {
+ return false;
+ }
+ if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) {
+ SkCanvas::Config8888 srcConfig, dstConfig;
+ if (!info2config8888(srcInfo, &srcConfig) || !info2config8888(dstInfo, &dstConfig)) {
+ return false;
+ }
+ SkConvertConfig8888Pixels((uint32_t*)dstPixels, dstRowBytes, dstConfig,
+ (const uint32_t*)srcPixels, srcRowBytes, srcConfig,
+ srcInfo.width(), srcInfo.height());
+ return true;
+ }
+ if (srcInfo.colorType() == dstInfo.colorType()) {
+ switch (srcInfo.colorType()) {
+ case kRGB_565_SkColorType:
+ case kAlpha_8_SkColorType:
+ break;
+ case kARGB_4444_SkColorType:
+ if (srcInfo.alphaType() != dstInfo.alphaType()) {
+ return false;
+ }
+ break;
+ default:
+ return false;
+ }
+ rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes,
+ srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height());
+ }
+ // TODO: add support for more conversions as needed
+ return false;
+}
+
+bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels,
+ size_t srcRowBytes, int x, int y) {
+ SkImageInfo dstInfo = fBitmap.info();
+ dstInfo.fWidth = srcInfo.width();
+ dstInfo.fHeight = srcInfo.height();
+
+ void* dstPixels = fBitmap.getAddr(x, y);
+ size_t dstRowBytes = fBitmap.rowBytes();
+
+ if (write_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) {
+ fBitmap.notifyPixelsChanged();
+ return true;
+ }
+ return false;
+}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « include/gpu/SkGpuDevice.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698