summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorfmalita <fmalita@chromium.org>2015-06-12 08:14:53 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-12 15:15:29 +0000
commit36e307f1de9f9e12a03f9ab66302ed6521578882 (patch)
treee7ca5390e29226deaf371b61ec882474a9d28d0e /skia
parent5e0ab4d72e5edb4ac375783409a8567c5b05cc40 (diff)
downloadchromium_src-36e307f1de9f9e12a03f9ab66302ed6521578882.zip
chromium_src-36e307f1de9f9e12a03f9ab66302ed6521578882.tar.gz
chromium_src-36e307f1de9f9e12a03f9ab66302ed6521578882.tar.bz2
Use SkPaintFilterCanvas for paint filtering
SkDrawFilter is deprecated - convert its only Chromium client to SkPaintFilterCanvas. BUG=skia:3587 R=reed@google.com,robertphillips@google.com,enne@chromium.org CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1176393003 Cr-Commit-Position: refs/heads/master@{#334166}
Diffstat (limited to 'skia')
-rw-r--r--skia/BUILD.gn4
-rw-r--r--skia/ext/opacity_draw_filter.cc27
-rw-r--r--skia/ext/opacity_draw_filter.h33
-rw-r--r--skia/ext/opacity_filter_canvas.cc40
-rw-r--r--skia/ext/opacity_filter_canvas.h38
-rw-r--r--skia/skia_chrome.gypi4
6 files changed, 82 insertions, 64 deletions
diff --git a/skia/BUILD.gn b/skia/BUILD.gn
index 45916bf..bdde0c8 100644
--- a/skia/BUILD.gn
+++ b/skia/BUILD.gn
@@ -294,8 +294,8 @@ component("skia") {
"ext/google_logging.cc",
"ext/image_operations.cc",
"ext/image_operations.h",
- "ext/opacity_draw_filter.cc",
- "ext/opacity_draw_filter.h",
+ "ext/opacity_filter_canvas.cc",
+ "ext/opacity_filter_canvas.h",
"ext/pixel_ref_utils.cc",
"ext/pixel_ref_utils.h",
"ext/platform_canvas.cc",
diff --git a/skia/ext/opacity_draw_filter.cc b/skia/ext/opacity_draw_filter.cc
deleted file mode 100644
index 10ed9e8..0000000
--- a/skia/ext/opacity_draw_filter.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "skia/ext/opacity_draw_filter.h"
-#include "third_party/skia/include/core/SkPaint.h"
-
-namespace skia {
-
-OpacityDrawFilter::OpacityDrawFilter(float opacity,
- bool disable_image_filtering)
- : alpha_(SkScalarRoundToInt(opacity * 255)),
- disable_image_filtering_(disable_image_filtering) {}
-
-OpacityDrawFilter::~OpacityDrawFilter() {}
-
-bool OpacityDrawFilter::filter(SkPaint* paint, Type type) {
- if (alpha_ < 255)
- paint->setAlpha(alpha_);
- if (disable_image_filtering_)
- paint->setFilterQuality(kNone_SkFilterQuality);
- return true;
-}
-
-} // namespace skia
-
-
diff --git a/skia/ext/opacity_draw_filter.h b/skia/ext/opacity_draw_filter.h
deleted file mode 100644
index 7d11d68..0000000
--- a/skia/ext/opacity_draw_filter.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_OPACITY_DRAW_FILTER_H
-#define SKIA_EXT_OPACITY_DRAW_FILTER_H
-
-#include "base/values.h"
-#include "third_party/skia/include/core/SkDrawFilter.h"
-
-class SkPaint;
-
-namespace skia {
-
-// This filter allows setting an opacity on every draw call to a canvas, and to
-// disable image filtering. Note that the opacity setting is only correct in
-// very limited conditions: when there is only zero or one opaque, nonlayer
-// draw for every pixel in the surface.
-class SK_API OpacityDrawFilter : public SkDrawFilter {
- public:
- OpacityDrawFilter(float opacity, bool disable_image_filtering);
- ~OpacityDrawFilter() override;
- bool filter(SkPaint* paint, SkDrawFilter::Type type) override;
-
- private:
- int alpha_;
- bool disable_image_filtering_;
-};
-
-} // namespace skia
-
-#endif // SKIA_EXT_OPACITY_DRAW_FILTER_H
-
diff --git a/skia/ext/opacity_filter_canvas.cc b/skia/ext/opacity_filter_canvas.cc
new file mode 100644
index 0000000..11c8135
--- /dev/null
+++ b/skia/ext/opacity_filter_canvas.cc
@@ -0,0 +1,40 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "skia/ext/opacity_filter_canvas.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkTLazy.h"
+
+namespace skia {
+
+OpacityFilterCanvas::OpacityFilterCanvas(SkCanvas* canvas,
+ float opacity,
+ bool disable_image_filtering)
+ : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()),
+ alpha_(SkScalarRoundToInt(opacity * 255)),
+ disable_image_filtering_(disable_image_filtering) {
+ this->addCanvas(canvas);
+}
+
+void OpacityFilterCanvas::onFilterPaint(SkPaint* paint, Type) const {
+ if (alpha_ < 255)
+ paint->setAlpha(alpha_);
+
+ if (disable_image_filtering_)
+ paint->setFilterQuality(kNone_SkFilterQuality);
+}
+
+void OpacityFilterCanvas::onDrawPicture(const SkPicture* picture,
+ const SkMatrix* matrix,
+ const SkPaint* paint) {
+ SkTLazy<SkPaint> filteredPaint;
+ if (paint) {
+ this->onFilterPaint(filteredPaint.set(*paint), kPicture_Type);
+ }
+
+ // Unfurl pictures in order to filter nested paints.
+ this->SkCanvas::onDrawPicture(picture, matrix, filteredPaint.getMaybeNull());
+}
+
+} // namespace skia
diff --git a/skia/ext/opacity_filter_canvas.h b/skia/ext/opacity_filter_canvas.h
new file mode 100644
index 0000000..ee3eca6e
--- /dev/null
+++ b/skia/ext/opacity_filter_canvas.h
@@ -0,0 +1,38 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SKIA_EXT_OPACITY_FILTER_CANVAS_H
+#define SKIA_EXT_OPACITY_FILTER_CANVAS_H
+
+#include "third_party/skia/include/utils/SkPaintFilterCanvas.h"
+
+namespace skia {
+
+// This filter canvas allows setting an opacity on every draw call to a canvas,
+// and to disable image filtering. Note that the opacity setting is only
+// correct in very limited conditions: when there is only zero or one opaque,
+// nonlayer draw for every pixel in the surface.
+class SK_API OpacityFilterCanvas : public SkPaintFilterCanvas {
+ public:
+ OpacityFilterCanvas(SkCanvas* canvas,
+ float opacity,
+ bool disable_image_filtering);
+
+ protected:
+ void onFilterPaint(SkPaint* paint, Type type) const override;
+
+ void onDrawPicture(const SkPicture* picture,
+ const SkMatrix* matrix,
+ const SkPaint* paint) override;
+
+ private:
+ typedef SkPaintFilterCanvas INHERITED;
+
+ int alpha_;
+ bool disable_image_filtering_;
+};
+
+} // namespace skia
+
+#endif // SKIA_EXT_OPACITY_FILTER_CANVAS_H
diff --git a/skia/skia_chrome.gypi b/skia/skia_chrome.gypi
index eb3f7e2..0d10a43 100644
--- a/skia/skia_chrome.gypi
+++ b/skia/skia_chrome.gypi
@@ -51,8 +51,8 @@
'ext/google_logging.cc',
'ext/image_operations.cc',
'ext/image_operations.h',
- 'ext/opacity_draw_filter.cc',
- 'ext/opacity_draw_filter.h',
+ 'ext/opacity_filter_canvas.cc',
+ 'ext/opacity_filter_canvas.h',
'ext/pixel_ref_utils.cc',
'ext/pixel_ref_utils.h',
'ext/platform_canvas.cc',