aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-07 03:25:16 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-07 03:25:16 +0000
commit4cd9e2169e35cd67ee7358acea6541245e1d1744 (patch)
tree6e78d84ef91181b41f5c45a73bab003c63780f10 /src/utils
parenta5572e5bb2a2bbeeb59de0741c2527869d365a0c (diff)
Add SkCanvas::writePixels that takes info+pixels directly
add corresponding methods to device (w/ diff name to avoid colliding with exising virtuals) BUG=skia: R=bsalomon@google.com, robertphillips@google.com, junov@google.com, junov@chromium.org Author: reed@google.com Review URL: https://codereview.chromium.org/180113010 git-svn-id: http://skia.googlecode.com/svn/trunk@13697 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkDeferredCanvas.cpp31
-rw-r--r--src/utils/SkGatherPixelRefsAndRects.h2
-rw-r--r--src/utils/SkPictureUtils.cpp3
3 files changed, 30 insertions, 6 deletions
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 09494c9aaa..b81d64c57d 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);
diff --git a/src/utils/SkGatherPixelRefsAndRects.h b/src/utils/SkGatherPixelRefsAndRects.h
index 90ab0f6cff..4b5bb6f9e5 100644
--- a/src/utils/SkGatherPixelRefsAndRects.h
+++ b/src/utils/SkGatherPixelRefsAndRects.h
@@ -49,10 +49,12 @@ public:
return fEmptyBitmap.info();
}
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE {
NotSupported();
}
+#endif
virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; }
protected:
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp
index cda64052c3..e41bfecfb4 100644
--- a/src/utils/SkPictureUtils.cpp
+++ b/src/utils/SkPictureUtils.cpp
@@ -85,10 +85,13 @@ public:
virtual void clear(SkColor color) SK_OVERRIDE {
nothing_to_do();
}
+
+#ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
virtual void writePixels(const SkBitmap& bitmap, int x, int y,
SkCanvas::Config8888 config8888) SK_OVERRIDE {
not_supported();
}
+#endif
virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE {
this->addBitmapFromPaint(paint);