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

Unified Diff: ui/gfx/canvas_skia.h

Issue 9562038: ui/gfx: Make gfx::Canvas inherit from gfx::CanvasSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
Index: ui/gfx/canvas_skia.h
diff --git a/ui/gfx/canvas_skia.h b/ui/gfx/canvas_skia.h
index aee77113f265591252b6f541a884dc76709933be..cbd8c8b04b83a8cf6b7d94806495ab16392145f7 100644
--- a/ui/gfx/canvas_skia.h
+++ b/ui/gfx/canvas_skia.h
@@ -7,18 +7,27 @@
#pragma once
#include "base/basictypes.h"
-#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "skia/ext/platform_canvas.h"
-#include "ui/gfx/canvas.h"
+#include "ui/gfx/native_widget_types.h"
class SkBitmap;
+namespace ui {
+class Transform;
+}
+
namespace gfx {
+class Brush;
+class Rect;
+class Font;
+class Point;
+class Size;
+
// CanvasSkia is a SkCanvas wrapper that provides a number of methods for
-// common operations used throughout an application built using base/gfx.
+// common operations used throughout an application built using ui/gfx.
//
// All methods that take integer arguments (as is used throughout views)
// end with Int. If you need to use methods provided by SkCanvas, you'll
@@ -30,7 +39,7 @@ namespace gfx {
// source and destination colors are combined. Unless otherwise specified,
// the variant that does not take a SkXfermode::Mode uses a transfer mode
// of kSrcOver_Mode.
-class UI_EXPORT CanvasSkia : public Canvas {
+class UI_EXPORT CanvasSkia {
public:
enum TruncateFadeMode {
TruncateFadeTail,
@@ -94,61 +103,150 @@ class UI_EXPORT CanvasSkia : public Canvas {
// Extracts a bitmap from the contents of this canvas.
SkBitmap ExtractBitmap() const;
- // Overridden from Canvas:
- virtual void Save() OVERRIDE;
- virtual void SaveLayerAlpha(uint8 alpha) OVERRIDE;
- virtual void SaveLayerAlpha(uint8 alpha,
- const gfx::Rect& layer_bounds) OVERRIDE;
- virtual void Restore() OVERRIDE;
- virtual bool ClipRect(const gfx::Rect& rect) OVERRIDE;
- virtual void Translate(const gfx::Point& point) OVERRIDE;
- virtual void Scale(int x_scale, int y_scale) OVERRIDE;
- virtual void FillRect(const gfx::Rect& rect, const SkColor& color) OVERRIDE;
- virtual void FillRect(const gfx::Rect& rect,
+ // Saves a copy of the drawing state onto a stack, operating on this copy
+ // until a balanced call to Restore() is made.
+ void Save();
+
+ // As with Save(), except draws to a layer that is blended with the canvas
+ // at the specified alpha once Restore() is called.
+ // |layer_bounds| are the bounds of the layer relative to the current
+ // transform.
+ void SaveLayerAlpha(uint8 alpha);
+ void SaveLayerAlpha(uint8 alpha,
+ const gfx::Rect& layer_bounds);
+
+ // Restores the drawing state after a call to Save*(). It is an error to
+ // call Restore() more times than Save*().
+ void Restore() ;
+
+ // Returns true if the clip is non-empty.
+ bool ClipRect(const gfx::Rect& rect) ;
+
+ void Translate(const gfx::Point& point) ;
+
+ void Scale(int x_scale, int y_scale) ;
+
+ // Fills |rect| with |color| using a transfer mode of
+ // SkXfermode::kSrcOver_Mode.
+ void FillRect(const gfx::Rect& rect, const SkColor& color) ;
+
+ // Fills |rect| with the specified |color| and |mode|.
+ void FillRect(const gfx::Rect& rect,
const SkColor& color,
- SkXfermode::Mode mode) OVERRIDE;
- virtual void FillRect(const gfx::Rect& rect,
- const gfx::Brush* brush) OVERRIDE;
- virtual void DrawRect(const gfx::Rect& rect, const SkColor& color) OVERRIDE;
- virtual void DrawRect(const gfx::Rect& rect,
+ SkXfermode::Mode mode) ;
+
+ // Fills |rect| with the specified |brush|.
+ void FillRect(const gfx::Rect& rect,
+ const gfx::Brush* brush) ;
+
+ // Draws a single pixel rect in the specified region with the specified
+ // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
+ //
+ // NOTE: if you need a single pixel line, use DrawLine.
+ void DrawRect(const gfx::Rect& rect, const SkColor& color) ;
+
+ // Draws a single pixel rect in the specified region with the specified
+ // color and transfer mode.
+ //
+ // NOTE: if you need a single pixel line, use DrawLine.
+ void DrawRect(const gfx::Rect& rect,
const SkColor& color,
- SkXfermode::Mode mode) OVERRIDE;
- virtual void DrawRect(const gfx::Rect& rect, const SkPaint& paint) OVERRIDE;
- virtual void DrawLine(const gfx::Point& p1,
+ SkXfermode::Mode mode) ;
+
+ // Draws the given rectangle with the given paint's parameters.
+ void DrawRect(const gfx::Rect& rect, const SkPaint& paint) ;
+
+ // Draws a single pixel line with the specified color.
+ void DrawLine(const gfx::Point& p1,
const gfx::Point& p2,
- const SkColor& color) OVERRIDE;
- virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) OVERRIDE;
- virtual void DrawBitmapInt(const SkBitmap& bitmap,
+ const SkColor& color) ;
+
+ // Draws a bitmap with the origin at the specified location. The upper left
+ // corner of the bitmap is rendered at the specified location.
+ void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) ;
+
+ // Draws a bitmap with the origin at the specified location, using the
+ // specified paint. The upper left corner of the bitmap is rendered at the
+ // specified location.
+ void DrawBitmapInt(const SkBitmap& bitmap,
int x, int y,
- const SkPaint& paint) OVERRIDE;
- virtual void DrawBitmapInt(const SkBitmap& bitmap,
+ const SkPaint& paint) ;
+
+ // Draws a portion of a bitmap in the specified location. The src parameters
+ // correspond to the region of the bitmap to draw in the region defined
+ // by the dest coordinates.
+ //
+ // If the width or height of the source differs from that of the destination,
+ // the bitmap will be scaled. When scaling down, it is highly recommended
+ // that you call buildMipMap(false) on your bitmap to ensure that it has
+ // a mipmap, which will result in much higher-quality output. Set |filter|
+ // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm
+ // is used for resampling.
+ //
+ // An optional custom SkPaint can be provided.
+ void DrawBitmapInt(const SkBitmap& bitmap,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h,
- bool filter) OVERRIDE;
- virtual void DrawBitmapInt(const SkBitmap& bitmap,
+ bool filter) ;
+ void DrawBitmapInt(const SkBitmap& bitmap,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h,
bool filter,
- const SkPaint& paint) OVERRIDE;
- virtual void DrawStringInt(const string16& text,
+ const SkPaint& paint) ;
+
+ // Draws text with the specified color, font and location. The text is
+ // aligned to the left, vertically centered, clipped to the region. If the
+ // text is too big, it is truncated and '...' is added to the end.
+ void DrawStringInt(const string16& text,
const gfx::Font& font,
const SkColor& color,
- int x, int y, int w, int h) OVERRIDE;
- virtual void DrawStringInt(const string16& text,
+ int x, int y, int w, int h) ;
+ void DrawStringInt(const string16& text,
const gfx::Font& font,
const SkColor& color,
- const gfx::Rect& display_rect) OVERRIDE;
- virtual void DrawStringInt(const string16& text,
+ const gfx::Rect& display_rect) ;
+
+ // Draws text with the specified color, font and location. The last argument
+ // specifies flags for how the text should be rendered. It can be one of
+ // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
+ void DrawStringInt(const string16& text,
const gfx::Font& font,
const SkColor& color,
int x, int y, int w, int h,
- int flags) OVERRIDE;
+ int flags) ;
+
+ // Draws a dotted gray rectangle used for focus purposes.
+ void DrawFocusRect(const gfx::Rect& rect) ;
+
+ // Tiles the image in the specified region.
+ void TileImageInt(const SkBitmap& bitmap,
+ int x, int y, int w, int h) ;
+ void TileImageInt(const SkBitmap& bitmap,
+ int src_x, int src_y,
+ int dest_x, int dest_y, int w, int h) ;
+
+ // Returns a native drawing context for platform specific drawing routines to
+ // use. Must be balanced by a call to EndPlatformPaint().
+ NativeDrawingContext BeginPlatformPaint() ;
+
+ // Signifies the end of platform drawing using the native drawing context
+ // returned by BeginPlatformPaint().
+ void EndPlatformPaint() ;
+
+ // Apply transformation on the canvas.
+ void Transform(const ui::Transform& transform) ;
+
+ CanvasSkia* AsCanvasSkia() ;
+ const CanvasSkia* AsCanvasSkia() const ;
+ SkCanvas* GetSkCanvas() ;
+ const SkCanvas* GetSkCanvas() const ;
+
#if defined(OS_WIN)
// Draws the given string with the beginning and/or the end using a fade
// gradient. When truncating the head
// |desired_characters_to_truncate_from_head| specifies the maximum number of
// characters that can be truncated.
- virtual void DrawFadeTruncatingString(
+ void DrawFadeTruncatingString(
const string16& text,
TruncateFadeMode truncate_mode,
size_t desired_characters_to_truncate_from_head,
@@ -156,19 +254,6 @@ class UI_EXPORT CanvasSkia : public Canvas {
const SkColor& color,
const gfx::Rect& display_rect);
#endif
- virtual void DrawFocusRect(const gfx::Rect& rect) OVERRIDE;
- virtual void TileImageInt(const SkBitmap& bitmap,
- int x, int y, int w, int h) OVERRIDE;
- virtual void TileImageInt(const SkBitmap& bitmap,
- int src_x, int src_y,
- int dest_x, int dest_y, int w, int h) OVERRIDE;
- virtual gfx::NativeDrawingContext BeginPlatformPaint() OVERRIDE;
- virtual void EndPlatformPaint() OVERRIDE;
- virtual void Transform(const ui::Transform& transform) OVERRIDE;
- virtual CanvasSkia* AsCanvasSkia() OVERRIDE;
- virtual const CanvasSkia* AsCanvasSkia() const OVERRIDE;
- virtual SkCanvas* GetSkCanvas() OVERRIDE;
- virtual const SkCanvas* GetSkCanvas() const OVERRIDE;
SkCanvas* sk_canvas() const { return canvas_; }
skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.cc ('k') | ui/gfx/canvas_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698