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

Side by Side Diff: ui/gfx/canvas.h

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/gfx/canvas.cc » ('j') | ui/gfx/canvas.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_CANVAS_H_ 5 #ifndef UI_GFX_CANVAS_H_
6 #define UI_GFX_CANVAS_H_ 6 #define UI_GFX_CANVAS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "skia/ext/platform_canvas.h" 14 #include "skia/ext/platform_canvas.h"
15 #include "ui/gfx/image/image_skia.h"
15 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
16 17
17 class SkBitmap; 18 class SkBitmap;
18 19
19 namespace ui { 20 namespace ui {
20 class Transform; 21 class Transform;
21 } 22 }
22 23
23 namespace gfx { 24 namespace gfx {
24 25
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 int radius, 234 int radius,
234 const SkPaint& paint); 235 const SkPaint& paint);
235 236
236 // Draws the given rectangle with rounded corners of |radius| using the 237 // Draws the given rectangle with rounded corners of |radius| using the
237 // given |paint| parameters. 238 // given |paint| parameters.
238 void DrawRoundRect(const gfx::Rect& rect, int radius, const SkPaint& paint); 239 void DrawRoundRect(const gfx::Rect& rect, int radius, const SkPaint& paint);
239 240
240 // Draws the given path using the given |paint| parameters. 241 // Draws the given path using the given |paint| parameters.
241 void DrawPath(const SkPath& path, const SkPaint& paint); 242 void DrawPath(const SkPath& path, const SkPaint& paint);
242 243
243 // Draws a bitmap with the origin at the specified location. The upper left 244 // Draws an image with the origin at the specified location. The upper left
244 // corner of the bitmap is rendered at the specified location. 245 // corner of the bitmap is rendered at the specified location.
245 void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); 246 // Parameters are specified relative to current canvas scale not pixels.
247 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
248 void DrawBitmapInt(const gfx::ImageSkia&, int x, int y);
246 249
247 // Draws a bitmap with the origin at the specified location, using the 250 // Draws an image with the origin at the specified location, using the
248 // specified paint. The upper left corner of the bitmap is rendered at the 251 // specified paint. The upper left corner of the bitmap is rendered at the
249 // specified location. 252 // specified location.
250 void DrawBitmapInt(const SkBitmap& bitmap, 253 // Parameters are specified relative to current canvas scale not pixels.
254 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
255 void DrawBitmapInt(const gfx::ImageSkia& image,
251 int x, int y, 256 int x, int y,
252 const SkPaint& paint); 257 const SkPaint& paint);
253 258
254 // Draws a portion of a bitmap in the specified location. The src parameters 259 // Draws a portion of an image in the specified location. The src parameters
255 // correspond to the region of the bitmap to draw in the region defined 260 // correspond to the region of the bitmap to draw in the region defined
256 // by the dest coordinates. 261 // by the dest coordinates.
257 // 262 //
258 // If the width or height of the source differs from that of the destination, 263 // If the width or height of the source differs from that of the destination,
259 // the bitmap will be scaled. When scaling down, it is highly recommended 264 // the bitmap will be scaled. When scaling down, it is highly recommended
260 // that you call buildMipMap(false) on your bitmap to ensure that it has 265 // that you call BuildMipMap() on your image to ensure that it has
261 // a mipmap, which will result in much higher-quality output. Set |filter| 266 // a mipmap, which will result in much higher-quality output. Set |filter|
262 // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm 267 // to use filtering for images, otherwise the nearest-neighbor algorithm
263 // is used for resampling. 268 // is used for resampling.
264 // 269 //
265 // An optional custom SkPaint can be provided. 270 // An optional custom SkPaint can be provided.
266 void DrawBitmapInt(const SkBitmap& bitmap, 271 // Parameters are specified relative to current canvas scale not pixels.
272 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
273 void DrawBitmapInt(const gfx::ImageSkia& image,
267 int src_x, int src_y, int src_w, int src_h, 274 int src_x, int src_y, int src_w, int src_h,
268 int dest_x, int dest_y, int dest_w, int dest_h, 275 int dest_x, int dest_y, int dest_w, int dest_h,
269 bool filter); 276 bool filter);
270 void DrawBitmapInt(const SkBitmap& bitmap, 277 void DrawBitmapInt(const gfx::ImageSkia& image,
271 int src_x, int src_y, int src_w, int src_h, 278 int src_x, int src_y, int src_w, int src_h,
272 int dest_x, int dest_y, int dest_w, int dest_h, 279 int dest_x, int dest_y, int dest_w, int dest_h,
273 bool filter, 280 bool filter,
274 const SkPaint& paint); 281 const SkPaint& paint);
275 282
276 // TODO(pkotwicz): make this function private once gfx::ImageSkia stops
277 // calling this method.
278 void DrawBitmapFloat(const SkBitmap& bitmap,
279 float src_x, float src_y, float src_w, float src_h,
280 float dest_x, float dest_y, float dest_w, float dest_h,
281 bool filter,
282 const SkPaint& paint);
283
284 // Draws text with the specified color, font and location. The text is 283 // Draws text with the specified color, font and location. The text is
285 // aligned to the left, vertically centered, clipped to the region. If the 284 // aligned to the left, vertically centered, clipped to the region. If the
286 // text is too big, it is truncated and '...' is added to the end. 285 // text is too big, it is truncated and '...' is added to the end.
287 void DrawStringInt(const string16& text, 286 void DrawStringInt(const string16& text,
288 const gfx::Font& font, 287 const gfx::Font& font,
289 SkColor color, 288 SkColor color,
290 int x, int y, int w, int h); 289 int x, int y, int w, int h);
291 void DrawStringInt(const string16& text, 290 void DrawStringInt(const string16& text,
292 const gfx::Font& font, 291 const gfx::Font& font,
293 SkColor color, 292 SkColor color,
(...skipping 14 matching lines...) Expand all
308 const gfx::Font& font, 307 const gfx::Font& font,
309 SkColor color, 308 SkColor color,
310 const gfx::Rect& text_bounds, 309 const gfx::Rect& text_bounds,
311 int flags, 310 int flags,
312 const std::vector<ShadowValue>& shadows); 311 const std::vector<ShadowValue>& shadows);
313 312
314 // Draws a dotted gray rectangle used for focus purposes. 313 // Draws a dotted gray rectangle used for focus purposes.
315 void DrawFocusRect(const gfx::Rect& rect); 314 void DrawFocusRect(const gfx::Rect& rect);
316 315
317 // Tiles the image in the specified region. 316 // Tiles the image in the specified region.
318 void TileImageInt(const SkBitmap& bitmap, 317 // Parameters are specified relative to current canvas scale not pixels.
318 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
319 void TileImageInt(const gfx::ImageSkia& image,
319 int x, int y, int w, int h); 320 int x, int y, int w, int h);
320 void TileImageInt(const SkBitmap& bitmap, 321 void TileImageInt(const gfx::ImageSkia& image,
321 int src_x, int src_y, 322 int src_x, int src_y,
322 int dest_x, int dest_y, int w, int h); 323 int dest_x, int dest_y, int w, int h);
323 324
324 // Returns a native drawing context for platform specific drawing routines to 325 // Returns a native drawing context for platform specific drawing routines to
325 // use. Must be balanced by a call to EndPlatformPaint(). 326 // use. Must be balanced by a call to EndPlatformPaint().
326 NativeDrawingContext BeginPlatformPaint(); 327 NativeDrawingContext BeginPlatformPaint();
327 328
328 // Signifies the end of platform drawing using the native drawing context 329 // Signifies the end of platform drawing using the native drawing context
329 // returned by BeginPlatformPaint(). 330 // returned by BeginPlatformPaint().
330 void EndPlatformPaint(); 331 void EndPlatformPaint();
(...skipping 16 matching lines...) Expand all
347 #endif 348 #endif
348 349
349 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } 350 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
350 SkCanvas* sk_canvas() const { return canvas_; } 351 SkCanvas* sk_canvas() const { return canvas_; }
351 352
352 private: 353 private:
353 // Test whether the provided rectangle intersects the current clip rect. 354 // Test whether the provided rectangle intersects the current clip rect.
354 bool IntersectsClipRectInt(int x, int y, int w, int h); 355 bool IntersectsClipRectInt(int x, int y, int w, int h);
355 bool IntersectsClipRect(const gfx::Rect& rect); 356 bool IntersectsClipRect(const gfx::Rect& rect);
356 357
358 // Returns bitmap whose density best matches the current canvas scale.
359 const SkBitmap* GetBitmapToPaint(const gfx::ImageSkia& image) const;
360
357 #if defined(OS_WIN) 361 #if defined(OS_WIN)
358 // Draws text with the specified color, font and location. The text is 362 // Draws text with the specified color, font and location. The text is
359 // aligned to the left, vertically centered, clipped to the region. If the 363 // aligned to the left, vertically centered, clipped to the region. If the
360 // text is too big, it is truncated and '...' is added to the end. 364 // text is too big, it is truncated and '...' is added to the end.
361 void DrawStringInt(const string16& text, 365 void DrawStringInt(const string16& text,
362 HFONT font, 366 HFONT font,
363 SkColor color, 367 SkColor color,
364 const gfx::Rect& text_bounds, 368 const gfx::Rect& text_bounds,
365 int flags); 369 int flags);
366 #endif 370 #endif
367 371
368 scoped_ptr<skia::PlatformCanvas> owned_canvas_; 372 scoped_ptr<skia::PlatformCanvas> owned_canvas_;
369 SkCanvas* canvas_; 373 SkCanvas* canvas_;
370 374
371 DISALLOW_COPY_AND_ASSIGN(Canvas); 375 DISALLOW_COPY_AND_ASSIGN(Canvas);
372 }; 376 };
373 377
374 } // namespace gfx 378 } // namespace gfx
375 379
376 #endif // UI_GFX_CANVAS_H_ 380 #endif // UI_GFX_CANVAS_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/canvas.cc » ('j') | ui/gfx/canvas.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698