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

Unified Diff: src/core/SkCanvas.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 | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkConfig8888.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index dfc3f93789d643cabd95dd75ec12ee190bb7f8ac..c5a49bd89f010c7130140abb36994499ab2aad01 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -698,6 +698,7 @@ bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
}
}
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y,
Config8888 config8888) {
SkBaseDevice* device = this->getDevice();
@@ -709,6 +710,62 @@ void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y,
}
}
}
+#endif
+
+bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
+ if (bitmap.getTexture()) {
+ return false;
+ }
+ SkBitmap bm(bitmap);
+ bm.lockPixels();
+ if (bm.getPixels()) {
+ return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y);
+ }
+ return false;
+}
+
+bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size_t rowBytes,
+ int x, int y) {
+ switch (origInfo.colorType()) {
+ case kUnknown_SkColorType:
+ case kIndex_8_SkColorType:
+ return false;
+ default:
+ break;
+ }
+ if (NULL == pixels || rowBytes < origInfo.minRowBytes()) {
+ return false;
+ }
+
+ const SkISize size = this->getBaseLayerSize();
+ SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height());
+ if (!target.intersect(0, 0, size.width(), size.height())) {
+ return false;
+ }
+
+ SkBaseDevice* device = this->getDevice();
+ if (!device) {
+ return false;
+ }
+
+ SkImageInfo info = origInfo;
+ // the intersect may have shrunk info's logical size
+ info.fWidth = target.width();
+ info.fHeight = target.height();
+
+ // if x or y are negative, then we have to adjust pixels
+ if (x > 0) {
+ x = 0;
+ }
+ if (y > 0) {
+ y = 0;
+ }
+ // here x,y are either 0 or negative
+ pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel());
+
+ // The device can assert that the requested area is always contained in its bounds
+ return device->writePixelsDirect(info, pixels, rowBytes, target.x(), target.y());
+}
SkCanvas* SkCanvas::canvasForDrawIter() {
return this;
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkConfig8888.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698