diff options
author | Mitsuru Oshima <oshima@chromium.org> | 2015-08-03 21:34:25 -0700 |
---|---|---|
committer | Mitsuru Oshima <oshima@chromium.org> | 2015-08-04 04:36:24 +0000 |
commit | 8cb079f8e1ce0efd8a7f0328c3bc6d33807f9470 (patch) | |
tree | 0c25f3e03be9fa6f92f5c80764fc39efa551ad98 /ui/gfx | |
parent | 48eea5f39c399af026543bfcafc63c9fe55ecfd8 (diff) | |
download | chromium_src-8cb079f8e1ce0efd8a7f0328c3bc6d33807f9470.zip chromium_src-8cb079f8e1ce0efd8a7f0328c3bc6d33807f9470.tar.gz chromium_src-8cb079f8e1ce0efd8a7f0328c3bc6d33807f9470.tar.bz2 |
Revert "Make it easier to test changes to a .icon file."
Reason for revert:
build errors on GN bots
LINUX:
FAILED: /mnt/data/b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/ui/views/examples/views_examples_lib/vector_example.o.d .....
../../ui/views/examples/vector_example.cc:112:14:error: no member named 'CreateVectorIconFromSource' in namespace 'gfx'
gfx::CreateVectorIconFromSource(contents, size_, color_));
~~~~~^
1 error generated.
WIN:
[472/771] LINK generate_barcode_video.exe
FAILED: ninja -t msvc -e environment.x64 -- E:\b\build\goma/gomacc.exe "E:\b\depot_tools\win_toolchain\vs2013_files\VC\bin\amd64/cl.exe" /nologo /showIncludes /FC @obj/ui/views/examples/views_examples_lib/vector_example.obj.rsp ....
e:\b\build\slave\win_x64_gn\build\src\ui\views\examples\vector_example.cc(112) :error C2039: 'CreateVectorIconFromSource' : is not a member of 'gfx'
e:\b\build\slave\win_x64_gn\build\src\ui\views\examples\vector_example.cc(112) :error C3861: 'CreateVectorIconFromSource': identifier not found
ninja: build stopped: subcommand failed.
> Make it easier to test changes to a .icon file.
> No need to recompile Chrome; views_examples_exe will read from a file. This would also be useful for the tool which will allow de
>
> Since this is potentially unsafe (could crash on the wrong inputs) and doesn't serve a purpose in Chrome itself, it's ifdef'd out
>
> BUG=505953
>
> Review URL: https://codereview.chromium.org/1268633002
>
> Cr-Commit-Position: refs/heads/master@{#341667}
TBR=estade@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1264343003 .
Cr-Commit-Position: refs/heads/master@{#341673}
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/paint_vector_icon.cc | 220 | ||||
-rw-r--r-- | ui/gfx/paint_vector_icon.h | 9 |
2 files changed, 75 insertions, 154 deletions
diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc index 0d178d8..fed63bdc 100644 --- a/ui/gfx/paint_vector_icon.cc +++ b/ui/gfx/paint_vector_icon.cc @@ -7,8 +7,6 @@ #include <map> #include "base/lazy_instance.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" #include "third_party/skia/include/core/SkPath.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/canvas_image_source.h" @@ -19,50 +17,84 @@ namespace gfx { namespace { -// Translates a string such as "MOVE_TO" into a command such as MOVE_TO. -CommandType CommandFromString(const std::string& source) { -#define RETURN_IF_IS(command) \ - if (source == #command) \ - return command; - - RETURN_IF_IS(MOVE_TO); - RETURN_IF_IS(R_MOVE_TO); - RETURN_IF_IS(R_LINE_TO); - RETURN_IF_IS(H_LINE_TO); - RETURN_IF_IS(R_H_LINE_TO); - RETURN_IF_IS(V_LINE_TO); - RETURN_IF_IS(R_V_LINE_TO); - RETURN_IF_IS(CUBIC_TO); - RETURN_IF_IS(R_CUBIC_TO); - RETURN_IF_IS(CIRCLE); - RETURN_IF_IS(CLOSE); - RETURN_IF_IS(END); -#undef RETURN_IF_IS - - NOTREACHED(); - return CLOSE; -} +class VectorIconSource : public CanvasImageSource { + public: + VectorIconSource(VectorIconId id, size_t dip_size, SkColor color) + : CanvasImageSource( + gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)), + false), + id_(id), + color_(color) {} + + ~VectorIconSource() override {} -std::vector<PathElement> PathFromSource(const std::string& source) { - std::vector<PathElement> path; - std::vector<std::string> pieces = base::SplitString( - source, "\n ,f", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); - for (const auto& piece : pieces) { - double value; - if (base::StringToDouble(piece, &value)) - path.push_back(PathElement(SkDoubleToScalar(value))); - else - path.push_back(PathElement(CommandFromString(piece))); + // CanvasImageSource: + void Draw(gfx::Canvas* canvas) override { + PaintVectorIcon(canvas, id_, size_.width(), color_); } - return path; -} -void PaintPath(Canvas* canvas, - const PathElement* path_elements, - size_t dip_size, - SkColor color) { - SkPath path; - path.setFillType(SkPath::kEvenOdd_FillType); + private: + const VectorIconId id_; + const SkColor color_; + + DISALLOW_COPY_AND_ASSIGN(VectorIconSource); +}; + +// This class caches vector icons (as ImageSkia) so they don't have to be drawn +// more than once. This also guarantees the backing data for the images returned +// by CreateVectorIcon will persist in memory until program termination. +class VectorIconCache { + public: + VectorIconCache() {} + ~VectorIconCache() {} + + ImageSkia GetOrCreateIcon(VectorIconId id, size_t dip_size, SkColor color) { + IconDescription description(id, dip_size, color); + auto iter = images_.find(description); + if (iter != images_.end()) + return iter->second; + + ImageSkia icon( + new VectorIconSource(id, dip_size, color), + gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); + images_.insert(std::make_pair(description, icon)); + return icon; + } + + private: + struct IconDescription { + IconDescription(VectorIconId id, size_t dip_size, SkColor color) + : id(id), dip_size(dip_size), color(color) {} + + bool operator<(const IconDescription& other) const { + if (id != other.id) + return id < other.id; + if (dip_size != other.dip_size) + return dip_size < other.dip_size; + return color < other.color; + } + + VectorIconId id; + size_t dip_size; + SkColor color; + }; + + std::map<IconDescription, ImageSkia> images_; + + DISALLOW_COPY_AND_ASSIGN(VectorIconCache); +}; + +static base::LazyInstance<VectorIconCache> g_icon_cache = + LAZY_INSTANCE_INITIALIZER; + +} // namespace + +void PaintVectorIcon(Canvas* canvas, + VectorIconId id, + size_t dip_size, + SkColor color) { + DCHECK(VectorIconId::VECTOR_ICON_NONE != id); + const PathElement* path_elements = GetPathForVectorIcon(id); std::vector<SkPath> paths; paths.push_back(SkPath()); @@ -195,110 +227,8 @@ void PaintPath(Canvas* canvas, canvas->DrawPath(path, paint); } -class VectorIconSource : public CanvasImageSource { - public: - VectorIconSource(VectorIconId id, size_t dip_size, SkColor color) - : CanvasImageSource( - gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)), - false), - id_(id), - color_(color) {} - - VectorIconSource(const std::string& definition, - size_t dip_size, - SkColor color) - : CanvasImageSource( - gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)), - false), - id_(VectorIconId::VECTOR_ICON_NONE), - path_(PathFromSource(definition)), - color_(color) {} - - ~VectorIconSource() override {} - - // CanvasImageSource: - void Draw(gfx::Canvas* canvas) override { - if (path_.empty()) - PaintVectorIcon(canvas, id_, size_.width(), color_); - else - PaintPath(canvas, path_.data(), size_.width(), color_); - } - - private: - const VectorIconId id_; - const std::vector<PathElement> path_; - const SkColor color_; - - DISALLOW_COPY_AND_ASSIGN(VectorIconSource); -}; - -// This class caches vector icons (as ImageSkia) so they don't have to be drawn -// more than once. This also guarantees the backing data for the images returned -// by CreateVectorIcon will persist in memory until program termination. -class VectorIconCache { - public: - VectorIconCache() {} - ~VectorIconCache() {} - - ImageSkia GetOrCreateIcon(VectorIconId id, size_t dip_size, SkColor color) { - IconDescription description(id, dip_size, color); - auto iter = images_.find(description); - if (iter != images_.end()) - return iter->second; - - ImageSkia icon( - new VectorIconSource(id, dip_size, color), - gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); - images_.insert(std::make_pair(description, icon)); - return icon; - } - - private: - struct IconDescription { - IconDescription(VectorIconId id, size_t dip_size, SkColor color) - : id(id), dip_size(dip_size), color(color) {} - - bool operator<(const IconDescription& other) const { - if (id != other.id) - return id < other.id; - if (dip_size != other.dip_size) - return dip_size < other.dip_size; - return color < other.color; - } - - VectorIconId id; - size_t dip_size; - SkColor color; - }; - - std::map<IconDescription, ImageSkia> images_; - - DISALLOW_COPY_AND_ASSIGN(VectorIconCache); -}; - -static base::LazyInstance<VectorIconCache> g_icon_cache = - LAZY_INSTANCE_INITIALIZER; - -} // namespace - -void PaintVectorIcon(Canvas* canvas, - VectorIconId id, - size_t dip_size, - SkColor color) { - DCHECK(VectorIconId::VECTOR_ICON_NONE != id); - PaintPath(canvas, GetPathForVectorIcon(id), dip_size, color); -} - ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color); } -ImageSkia CreateVectorIconFromSource(const std::string& source, - size_t dip_size, - SkColor color) { - return ImageSkia( - new VectorIconSource(source, dip_size, color), - gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size))); -} - } // namespace gfx diff --git a/ui/gfx/paint_vector_icon.h b/ui/gfx/paint_vector_icon.h index 51b2440..563d7cb 100644 --- a/ui/gfx/paint_vector_icon.h +++ b/ui/gfx/paint_vector_icon.h @@ -28,15 +28,6 @@ GFX_EXPORT ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color); -#if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(GFX_IMPLEMENTATION) -// Takes a string of the format expected of .icon files and renders onto -// a canvas. This should only be used as a debugging aid and should never be -// used in production code. -GFX_EXPORT ImageSkia CreateVectorIconFromSource(const std::string& source, - size_t dip_size, - SkColor color); -#endif - } // namespace gfx #endif // UI_GFX_PAINT_VECTOR_ICON_H_ |