aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-09-25 09:15:55 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-25 09:15:55 -0700
commit2f5891ea6460675b3c8d08684e1fa8b239bc0a14 (patch)
treeb67a41b8f44935eb74ec797388e4021951b00bfc /src
parentd114645d931d4e95a938597a45a270f211273c17 (diff)
Remove SkBitmapSource
To avoid breaking existing SKPs, add a deserialization stub which unflattens SkBitmapSource records to SkImageSources. R=reed@google.com,mtklein@google.com,robertphillips@google.com Review URL: https://codereview.chromium.org/1363913002
Diffstat (limited to 'src')
-rw-r--r--src/effects/SkBitmapSource.cpp110
-rw-r--r--src/ports/SkGlobalInitialization_chromium.cpp4
-rw-r--r--src/ports/SkGlobalInitialization_default.cpp4
-rw-r--r--src/utils/SkBitmapSourceDeserializer.cpp34
-rw-r--r--src/utils/SkBitmapSourceDeserializer.h21
5 files changed, 59 insertions, 114 deletions
diff --git a/src/effects/SkBitmapSource.cpp b/src/effects/SkBitmapSource.cpp
deleted file mode 100644
index 5b1934f68a..0000000000
--- a/src/effects/SkBitmapSource.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2012 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmapSource.h"
-#include "SkDevice.h"
-#include "SkCanvas.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
-#include "SkValidationUtils.h"
-
-SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap)
- : INHERITED(0, 0)
- , fBitmap(bitmap)
- , fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()),
- SkIntToScalar(bitmap.height())))
- , fDstRect(fSrcRect)
- , fFilterQuality(kHigh_SkFilterQuality) {
-}
-
-SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap,
- const SkRect& srcRect, const SkRect& dstRect,
- SkFilterQuality filterQuality)
- : INHERITED(0, 0)
- , fBitmap(bitmap)
- , fSrcRect(srcRect)
- , fDstRect(dstRect)
- , fFilterQuality(filterQuality) {
-}
-
-SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) {
- SkFilterQuality filterQuality;
- if (buffer.isVersionLT(SkReadBuffer::kBitmapSourceFilterQuality_Version)) {
- filterQuality = kHigh_SkFilterQuality;
- } else {
- filterQuality = (SkFilterQuality)buffer.readInt();
- }
- SkRect src, dst;
- buffer.readRect(&src);
- buffer.readRect(&dst);
- SkBitmap bitmap;
- if (!buffer.readBitmap(&bitmap)) {
- return nullptr;
- }
- return SkBitmapSource::Create(bitmap, src, dst, filterQuality);
-}
-
-void SkBitmapSource::flatten(SkWriteBuffer& buffer) const {
- buffer.writeInt(fFilterQuality);
- buffer.writeRect(fSrcRect);
- buffer.writeRect(fDstRect);
- buffer.writeBitmap(fBitmap);
-}
-
-bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
- SkRect bounds, dstRect;
- fBitmap.getBounds(&bounds);
- ctx.ctm().mapRect(&dstRect, fDstRect);
- if (fSrcRect == bounds && dstRect == bounds) {
- // No regions cropped out or resized; return entire bitmap.
- *result = fBitmap;
- offset->fX = offset->fY = 0;
- return true;
- }
-
- const SkIRect dstIRect = dstRect.roundOut();
- SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstIRect.height()));
- if (nullptr == device.get()) {
- return false;
- }
-
- SkCanvas canvas(device.get());
- SkPaint paint;
-
- // Subtract off the integer component of the translation (will be applied in loc, below).
- dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop));
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- // FIXME: this probably shouldn't be necessary, but drawBitmapRect asserts
- // None filtering when it's translate-only
- paint.setFilterQuality(
- fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
- kNone_SkFilterQuality : fFilterQuality);
- canvas.drawBitmapRect(fBitmap, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
-
- *result = device.get()->accessBitmap(false);
- offset->fX = dstIRect.fLeft;
- offset->fY = dstIRect.fTop;
-
- return true;
-}
-
-void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const {
- *dst = fDstRect;
-}
-
-#ifndef SK_IGNORE_TO_STRING
-void SkBitmapSource::toString(SkString* str) const {
- str->appendf("SkBitmapSource: (");
- str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ",
- fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
- fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBottom);
- str->appendf("bitmap: (%d,%d)",
- fBitmap.width(), fBitmap.height());
- str->append(")");
-}
-#endif
diff --git a/src/ports/SkGlobalInitialization_chromium.cpp b/src/ports/SkGlobalInitialization_chromium.cpp
index e0c7d191b3..8ff43f78e8 100644
--- a/src/ports/SkGlobalInitialization_chromium.cpp
+++ b/src/ports/SkGlobalInitialization_chromium.cpp
@@ -17,7 +17,7 @@
#include "Sk2DPathEffect.h"
#include "SkArithmeticMode.h"
#include "SkArcToPathEffect.h"
-#include "SkBitmapSource.h"
+#include "SkBitmapSourceDeserializer.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurImageFilter.h"
#include "SkBlurMaskFilter.h"
@@ -85,7 +85,7 @@ public:
static void Init() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArcToPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader)
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapSource)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapSourceDeserializer)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurDrawLooper)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorCubeFilter)
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index 73e4f5a902..3038e25c5d 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -13,7 +13,7 @@
#include "Sk2DPathEffect.h"
#include "SkArithmeticMode.h"
#include "SkArcToPathEffect.h"
-#include "SkBitmapSource.h"
+#include "SkBitmapSourceDeserializer.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurImageFilter.h"
#include "SkBlurMaskFilter.h"
@@ -64,7 +64,7 @@ public:
static void Init() {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArcToPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader)
- SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapSource)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapSourceDeserializer)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurDrawLooper)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkColorCubeFilter)
diff --git a/src/utils/SkBitmapSourceDeserializer.cpp b/src/utils/SkBitmapSourceDeserializer.cpp
new file mode 100644
index 0000000000..bb783bfeef
--- /dev/null
+++ b/src/utils/SkBitmapSourceDeserializer.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapSourceDeserializer.h"
+
+#include "SkBitmap.h"
+#include "SkFilterQuality.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
+#include "SkReadBuffer.h"
+
+SkFlattenable* SkBitmapSourceDeserializer::CreateProc(SkReadBuffer& buffer) {
+ SkFilterQuality filterQuality;
+ if (buffer.isVersionLT(SkReadBuffer::kBitmapSourceFilterQuality_Version)) {
+ filterQuality = kHigh_SkFilterQuality;
+ } else {
+ filterQuality = (SkFilterQuality)buffer.readInt();
+ }
+ SkRect src, dst;
+ buffer.readRect(&src);
+ buffer.readRect(&dst);
+ SkBitmap bitmap;
+ if (!buffer.readBitmap(&bitmap)) {
+ return nullptr;
+ }
+ bitmap.setImmutable();
+
+ SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap));
+ return SkImageSource::Create(image, src, dst, filterQuality);
+}
diff --git a/src/utils/SkBitmapSourceDeserializer.h b/src/utils/SkBitmapSourceDeserializer.h
new file mode 100644
index 0000000000..e017599918
--- /dev/null
+++ b/src/utils/SkBitmapSourceDeserializer.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapSourceDeserializer_DEFINED
+#define SkBitmapSourceDeserializer_DEFINED
+
+#include "SkFlattenable.h"
+
+// A temporary utility class to support deserializing legacy SkBitmapSource as SkImageSource.
+// Should be removed when SKP versions which may contain SkBitmapSource records are phased out.
+class SkBitmapSourceDeserializer : public SkFlattenable {
+public:
+ SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapSource)
+};
+
+#endif