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

Unified Diff: ui/gfx/image/image_skia_operations.cc

Issue 2443983003: Refactor ShadowImageSource into ui/gfx/skia_util for better reuse (Closed)
Patch Set: remove changes Created 4 years, 2 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 | « ui/gfx/image/image_skia_operations.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image_skia_operations.cc
diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc
index 0dc4c80327abbfb1d698b8ace05eaa9233080f5b..383623515779eeec0d85494df9ad7216c27f2f4c 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "skia/ext/image_operations.h"
+#include "third_party/skia/include/core/SkDrawLooper.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
@@ -397,6 +398,40 @@ class DropShadowSource : public ImageSkiaSource {
DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
};
+// An image source that is 1dp wide, suitable for tiling horizontally.
+class HorizontalShadowSource : public CanvasImageSource {
+ public:
+ HorizontalShadowSource(const std::vector<ShadowValue>& shadows,
+ bool fades_down)
+ : CanvasImageSource(Size(1, GetHeightForShadows(shadows)), false),
+ shadows_(shadows),
+ fades_down_(fades_down) {}
+ ~HorizontalShadowSource() override {}
+
+ // CanvasImageSource overrides:
+ void Draw(Canvas* canvas) override {
+ SkPaint paint;
+ paint.setLooper(CreateShadowDrawLooperCorrectBlur(shadows_));
+ canvas->DrawRect(RectF(0, fades_down_ ? -1 : size().height(), 1, 1), paint);
+ }
+
+ private:
+ static int GetHeightForShadows(const std::vector<ShadowValue>& shadows) {
+ int height = 0;
+ for (const auto& shadow : shadows) {
+ height = std::max(height, shadow.y() + ToCeiledInt(shadow.blur() / 2));
+ }
+ return height;
+ }
+
+ const std::vector<ShadowValue> shadows_;
+
+ // The orientation of the shadow (true for shadows that emanate downwards).
+ bool fades_down_;
+
+ DISALLOW_COPY_AND_ASSIGN(HorizontalShadowSource);
+};
+
// RotatedSource generates image reps that are rotations of those in
// |source| that represent requested scale factors.
class RotatedSource : public ImageSkiaSource {
@@ -557,6 +592,15 @@ ImageSkia ImageSkiaOperations::CreateImageWithDropShadow(
}
// static
+ImageSkia ImageSkiaOperations::CreateHorizontalShadow(
+ const std::vector<ShadowValue>& shadows,
+ bool fades_down) {
+ HorizontalShadowSource* source =
+ new HorizontalShadowSource(shadows, fades_down);
+ return ImageSkia(source, source->size());
+}
+
+// static
ImageSkia ImageSkiaOperations::CreateRotatedImage(
const ImageSkia& source,
SkBitmapOperations::RotationAmount rotation) {
« no previous file with comments | « ui/gfx/image/image_skia_operations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698