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

Unified Diff: src/utils/SkDeferredCanvas.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/gpu/SkGpuDevice.cpp ('k') | src/utils/SkGatherPixelRefsAndRects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkDeferredCanvas.cpp
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 09494c9aaa04428a437a88c83c878ede07a8c3bd..b81d64c57dc1c0c89c7fe04c4ff4bcf2c47fd949 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -30,8 +30,7 @@ enum PlaybackMode {
kSilent_PlaybackMode,
};
-namespace {
-bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint,
+static bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint,
size_t bitmapSizeThreshold) {
if (bitmap && ((bitmap->getTexture() && !bitmap->isImmutable()) ||
(bitmap->getSize() > bitmapSizeThreshold))) {
@@ -54,7 +53,6 @@ bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint,
}
return false;
}
-}
//-----------------------------------------------------------------------------
// DeferredPipeController
@@ -170,9 +168,10 @@ public:
virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE;
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
-
+#endif
virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
protected:
@@ -180,6 +179,7 @@ protected:
virtual bool onReadPixels(const SkBitmap& bitmap,
int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE;
+ virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y) SK_OVERRIDE;
// The following methods are no-ops on a deferred device
virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE {
@@ -478,8 +478,9 @@ void DeferredDevice::prepareForImmediatePixelWrite() {
fImmediateCanvas->flush();
}
-void DeferredDevice::writePixels(const SkBitmap& bitmap,
- int x, int y, SkCanvas::Config8888 config8888) {
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
+void DeferredDevice::writePixels(const SkBitmap& bitmap, int x, int y,
+ SkCanvas::Config8888 config8888) {
if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() &&
(y + bitmap.height()) >= height()) {
@@ -506,6 +507,24 @@ void DeferredDevice::writePixels(const SkBitmap& bitmap,
}
}
+#endif
+
+bool DeferredDevice::onWritePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes,
+ int x, int y) {
+ SkASSERT(x >= 0 && y >= 0);
+ SkASSERT(x + info.width() <= width());
+ SkASSERT(y + info.height() <= height());
+
+ this->flushPendingCommands(kNormal_PlaybackMode);
+
+ const SkImageInfo deviceInfo = this->imageInfo();
+ if (info.width() == deviceInfo.width() && info.height() == deviceInfo.height()) {
+ this->skipPendingCommands();
+ }
+
+ this->prepareForImmediatePixelWrite();
+ return immediateDevice()->onWritePixels(info, pixels, rowBytes, x, y);
+}
const SkBitmap& DeferredDevice::onAccessBitmap() {
this->flushPendingCommands(kNormal_PlaybackMode);
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/utils/SkGatherPixelRefsAndRects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698