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

Unified Diff: ui/gfx/image/canvas_image_source.h

Issue 2373633002: Improve ergonomics of CanvasImageSource -> gfx::ImageSkia. (Closed)
Patch Set: review comments Created 4 years, 3 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 | « no previous file | ui/gfx/image/canvas_image_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/canvas_image_source.h
diff --git a/ui/gfx/image/canvas_image_source.h b/ui/gfx/image/canvas_image_source.h
index f41c2814c0a81a59b86cf07da949a5b0d0c80284..1108f0d7c6d4870401f5b544db0d9c1ee9058c3d 100644
--- a/ui/gfx/image/canvas_image_source.h
+++ b/ui/gfx/image/canvas_image_source.h
@@ -7,8 +7,10 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_source.h"
namespace gfx {
@@ -21,7 +23,18 @@ class ImageSkiaRep;
// completed.
class GFX_EXPORT CanvasImageSource : public gfx::ImageSkiaSource {
public:
+ // Factory function to create an ImageSkia from a CanvasImageSource. Example:
+ // gfx::ImageSkia my_image =
+ // CanvasImageSource::MakeImageSkia<MySource>(param1, param2);
+ template <typename T, typename... Args>
+ static ImageSkia MakeImageSkia(Args&&... args) {
+ auto source = base::MakeUnique<T>(std::forward<Args>(args)...);
+ gfx::Size size = source->size();
+ return gfx::ImageSkia(source.release(), size);
+ }
+
CanvasImageSource(const gfx::Size& size, bool is_opaque);
+ ~CanvasImageSource() override {}
// Called when a new image needs to be drawn for a scale factor.
virtual void Draw(gfx::Canvas* canvas) = 0;
@@ -33,8 +46,6 @@ class GFX_EXPORT CanvasImageSource : public gfx::ImageSkiaSource {
gfx::ImageSkiaRep GetImageForScale(float scale) override;
protected:
- ~CanvasImageSource() override {}
-
const gfx::Size size_;
const bool is_opaque_;
DISALLOW_COPY_AND_ASSIGN(CanvasImageSource);
« no previous file with comments | « no previous file | ui/gfx/image/canvas_image_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698