| Index: ui/gfx/paint_vector_icon.cc
|
| diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc
|
| index 90feddf4629a0466bbde9dc68bfabfbafa0763ed..9544615218999217506cbfa5f9ab534a1b0eedb9 100644
|
| --- a/ui/gfx/paint_vector_icon.cc
|
| +++ b/ui/gfx/paint_vector_icon.cc
|
| @@ -20,7 +20,6 @@
|
| #include "ui/gfx/image/canvas_image_source.h"
|
| #include "ui/gfx/scoped_canvas.h"
|
| #include "ui/gfx/vector_icon_types.h"
|
| -#include "ui/gfx/vector_icons_public.h"
|
|
|
| namespace gfx {
|
|
|
| @@ -361,71 +360,37 @@ class VectorIconSource : public CanvasImageSource {
|
| icon_(icon),
|
| badge_(badge_icon) {}
|
|
|
| - ~VectorIconSource() override {}
|
| -
|
| - // CanvasImageSource:
|
| - bool HasRepresentationAtAllScales() const override {
|
| - return !icon_.is_empty();
|
| - }
|
| -
|
| - void Draw(gfx::Canvas* canvas) override {
|
| - PaintVectorIcon(canvas, icon_, size_.width(), color_);
|
| - if (!badge_.is_empty())
|
| - PaintVectorIcon(canvas, badge_, size_.width(), color_);
|
| - }
|
| -
|
| - private:
|
| - const SkColor color_;
|
| - const VectorIcon& icon_;
|
| - const VectorIcon& badge_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(VectorIconSource);
|
| -};
|
| -
|
| -class VectorIconSourceLegacy : public CanvasImageSource {
|
| - public:
|
| - VectorIconSourceLegacy(VectorIconId id,
|
| - int dip_size,
|
| - SkColor color,
|
| - VectorIconId badge_id)
|
| + VectorIconSource(const std::string& definition, int dip_size, SkColor color)
|
| : CanvasImageSource(gfx::Size(dip_size, dip_size), false),
|
| - id_(id),
|
| color_(color),
|
| - badge_id_(badge_id) {}
|
| + icon_(kNoneIcon),
|
| + badge_(kNoneIcon),
|
| + path_(PathFromSource(definition)) {}
|
|
|
| - VectorIconSourceLegacy(const std::string& definition,
|
| - int dip_size,
|
| - SkColor color)
|
| - : CanvasImageSource(gfx::Size(dip_size, dip_size), false),
|
| - id_(VectorIconId::VECTOR_ICON_NONE),
|
| - path_(PathFromSource(definition)),
|
| - color_(color),
|
| - badge_id_(VectorIconId::VECTOR_ICON_NONE) {}
|
| -
|
| - ~VectorIconSourceLegacy() override {}
|
| + ~VectorIconSource() override {}
|
|
|
| // CanvasImageSource:
|
| bool HasRepresentationAtAllScales() const override {
|
| - return id_ != VectorIconId::VECTOR_ICON_NONE;
|
| + return !icon_.is_empty();
|
| }
|
|
|
| void Draw(gfx::Canvas* canvas) override {
|
| if (path_.empty()) {
|
| - PaintVectorIcon(canvas, id_, size_.width(), color_);
|
| - if (badge_id_ != VectorIconId::VECTOR_ICON_NONE)
|
| - PaintVectorIcon(canvas, badge_id_, size_.width(), color_);
|
| + PaintVectorIcon(canvas, icon_, size_.width(), color_);
|
| + if (!badge_.is_empty())
|
| + PaintVectorIcon(canvas, badge_, size_.width(), color_);
|
| } else {
|
| PaintPath(canvas, path_.data(), size_.width(), color_);
|
| }
|
| }
|
|
|
| private:
|
| - const VectorIconId id_;
|
| - const std::vector<PathElement> path_;
|
| const SkColor color_;
|
| - const VectorIconId badge_id_;
|
| + const VectorIcon& icon_;
|
| + const VectorIcon& badge_;
|
| + const std::vector<PathElement> path_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(VectorIconSourceLegacy);
|
| + DISALLOW_COPY_AND_ASSIGN(VectorIconSource);
|
| };
|
|
|
| // This class caches vector icons (as ImageSkia) so they don't have to be drawn
|
| @@ -483,69 +448,11 @@ class VectorIconCache {
|
| static base::LazyInstance<VectorIconCache>::DestructorAtExit g_icon_cache =
|
| LAZY_INSTANCE_INITIALIZER;
|
|
|
| -class VectorIconCacheLegacy {
|
| - public:
|
| - VectorIconCacheLegacy() {}
|
| - ~VectorIconCacheLegacy() {}
|
| -
|
| - ImageSkia GetOrCreateIcon(VectorIconId id,
|
| - int dip_size,
|
| - SkColor color,
|
| - VectorIconId badge_id) {
|
| - IconDescription description(id, dip_size, color, badge_id);
|
| - auto iter = images_.find(description);
|
| - if (iter != images_.end())
|
| - return iter->second;
|
| -
|
| - ImageSkia icon(new VectorIconSourceLegacy(id, dip_size, color, badge_id),
|
| - gfx::Size(dip_size, dip_size));
|
| - images_.insert(std::make_pair(description, icon));
|
| - return icon;
|
| - }
|
| -
|
| - private:
|
| - struct IconDescription {
|
| - IconDescription(VectorIconId id,
|
| - int dip_size,
|
| - SkColor color,
|
| - VectorIconId badge_id)
|
| - : id(id), dip_size(dip_size), color(color), badge_id(badge_id) {}
|
| -
|
| - bool operator<(const IconDescription& other) const {
|
| - return std::tie(id, dip_size, color, badge_id) <
|
| - std::tie(other.id, other.dip_size, other.color, other.badge_id);
|
| - }
|
| -
|
| - VectorIconId id;
|
| - int dip_size;
|
| - SkColor color;
|
| - VectorIconId badge_id;
|
| - };
|
| -
|
| - std::map<IconDescription, ImageSkia> images_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(VectorIconCacheLegacy);
|
| -};
|
| -
|
| -static base::LazyInstance<VectorIconCacheLegacy>::DestructorAtExit
|
| - g_icon_cache_legacy = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| } // namespace
|
|
|
| const VectorIcon kNoneIcon = {};
|
|
|
| void PaintVectorIcon(Canvas* canvas,
|
| - VectorIconId id,
|
| - int dip_size,
|
| - SkColor color) {
|
| - DCHECK(VectorIconId::VECTOR_ICON_NONE != id);
|
| - const PathElement* path = canvas->image_scale() == 1.f
|
| - ? GetPathForVectorIconAt1xScale(id)
|
| - : GetPathForVectorIcon(id);
|
| - PaintPath(canvas, path, dip_size, color);
|
| -}
|
| -
|
| -void PaintVectorIcon(Canvas* canvas,
|
| const VectorIcon& icon,
|
| int dip_size,
|
| SkColor color) {
|
| @@ -556,14 +463,6 @@ void PaintVectorIcon(Canvas* canvas,
|
| PaintPath(canvas, path, dip_size, color);
|
| }
|
|
|
| -ImageSkia CreateVectorIcon(VectorIconId id, SkColor color) {
|
| - const PathElement* one_x_path = GetPathForVectorIconAt1xScale(id);
|
| - int size = (one_x_path[0].type == CANVAS_DIMENSIONS)
|
| - ? SkScalarTruncToInt(one_x_path[1].arg)
|
| - : kReferenceSizeDip;
|
| - return CreateVectorIcon(id, size, color);
|
| -}
|
| -
|
| ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) {
|
| const PathElement* one_x_path = icon.path_1x_ ? icon.path_1x_ : icon.path_;
|
| int size = one_x_path[0].type == CANVAS_DIMENSIONS ? one_x_path[1].arg
|
| @@ -571,27 +470,12 @@ ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) {
|
| return CreateVectorIcon(icon, size, color);
|
| }
|
|
|
| -ImageSkia CreateVectorIcon(VectorIconId id, int dip_size, SkColor color) {
|
| - return CreateVectorIconWithBadge(id, dip_size, color,
|
| - VectorIconId::VECTOR_ICON_NONE);
|
| -}
|
| -
|
| ImageSkia CreateVectorIcon(const VectorIcon& icon,
|
| int dip_size,
|
| SkColor color) {
|
| return CreateVectorIconWithBadge(icon, dip_size, color, kNoneIcon);
|
| }
|
|
|
| -ImageSkia CreateVectorIconWithBadge(VectorIconId id,
|
| - int dip_size,
|
| - SkColor color,
|
| - VectorIconId badge_id) {
|
| - return (id == VectorIconId::VECTOR_ICON_NONE)
|
| - ? gfx::ImageSkia()
|
| - : g_icon_cache_legacy.Get().GetOrCreateIcon(id, dip_size, color,
|
| - badge_id);
|
| -}
|
| -
|
| ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
|
| int dip_size,
|
| SkColor color,
|
| @@ -604,8 +488,8 @@ ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
|
| ImageSkia CreateVectorIconFromSource(const std::string& source,
|
| int dip_size,
|
| SkColor color) {
|
| - return CanvasImageSource::MakeImageSkia<VectorIconSourceLegacy>(
|
| - source, dip_size, color);
|
| + return CanvasImageSource::MakeImageSkia<VectorIconSource>(source, dip_size,
|
| + color);
|
| }
|
|
|
| } // namespace gfx
|
|
|