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

Side by Side Diff: gfx/canvas_skia.cc

Issue 3058012: Add support for Radial Gradient Brush and Bitmap Brush to gfx::Canvas.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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 | « gfx/canvas_skia.h ('k') | gfx/gfx.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "gfx/canvas_skia.h" 5 #include "gfx/canvas_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "gfx/font.h" 11 #include "gfx/font.h"
12 #include "gfx/rect.h" 12 #include "gfx/rect.h"
13 #include "third_party/skia/include/effects/SkGradientShader.h" 13 #include "third_party/skia/include/effects/SkGradientShader.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include "gfx/canvas_skia_paint.h" 16 #include "gfx/canvas_skia_paint.h"
17 #endif 17 #endif
18 18
19 namespace { 19 namespace {
20 20
21 SkPoint PointToSkPoint(const gfx::Point point) {
22 SkPoint sk_point;
23 sk_point.set(SkIntToScalar(point.x()), SkIntToScalar(point.y()));
24 return sk_point;
25 }
26
21 SkShader::TileMode TileModeToSkShaderTileMode(gfx::Canvas::TileMode tile_mode) { 27 SkShader::TileMode TileModeToSkShaderTileMode(gfx::Canvas::TileMode tile_mode) {
22 switch (tile_mode) { 28 switch (tile_mode) {
23 case gfx::Canvas::TileMode_Clamp: 29 case gfx::Canvas::TileMode_Clamp:
24 return SkShader::kClamp_TileMode; 30 return SkShader::kClamp_TileMode;
25 case gfx::Canvas::TileMode_Mirror: 31 case gfx::Canvas::TileMode_Mirror:
26 return SkShader::kMirror_TileMode; 32 return SkShader::kMirror_TileMode;
27 case gfx::Canvas::TileMode_Repeat: 33 case gfx::Canvas::TileMode_Repeat:
28 return SkShader::kRepeat_TileMode; 34 return SkShader::kRepeat_TileMode;
29 default: 35 default:
30 NOTREACHED() << "Invalid TileMode"; 36 NOTREACHED() << "Invalid TileMode";
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 SkIntToScalar(start_point.y())); 363 SkIntToScalar(start_point.y()));
358 SkShader* shader = SkGradientShader::CreateLinear( 364 SkShader* shader = SkGradientShader::CreateLinear(
359 boundary_points, 365 boundary_points,
360 colors, 366 colors,
361 positions, 367 positions,
362 position_count, 368 position_count,
363 TileModeToSkShaderTileMode(tile_mode)); 369 TileModeToSkShaderTileMode(tile_mode));
364 return new SkiaShader(shader); 370 return new SkiaShader(shader);
365 } 371 }
366 372
373 Brush* CanvasSkia::CreateRadialGradientBrush(
374 const gfx::Point& center_point,
375 float radius,
376 const SkColor colors[],
377 const float positions[],
378 size_t position_count,
379 TileMode tile_mode) {
380 SkShader* shader = SkGradientShader::CreateRadial(
381 PointToSkPoint(center_point),
382 radius,
383 colors,
384 positions,
385 position_count,
386 TileModeToSkShaderTileMode(tile_mode));
387 return new SkiaShader(shader);
388 }
389
390 Brush* CanvasSkia::CreateBitmapBrush(
391 const SkBitmap& bitmap,
392 TileMode tile_mode_x,
393 TileMode tile_mode_y) {
394 SkShader* shader = SkShader::CreateBitmapShader(
395 bitmap,
396 TileModeToSkShaderTileMode(tile_mode_x),
397 TileModeToSkShaderTileMode(tile_mode_y));
398 return new SkiaShader(shader);
399 }
400
367 CanvasSkia* CanvasSkia::AsCanvasSkia() { 401 CanvasSkia* CanvasSkia::AsCanvasSkia() {
368 return this; 402 return this;
369 } 403 }
370 404
371 const CanvasSkia* CanvasSkia::AsCanvasSkia() const { 405 const CanvasSkia* CanvasSkia::AsCanvasSkia() const {
372 return this; 406 return this;
373 } 407 }
374 408
375 //////////////////////////////////////////////////////////////////////////////// 409 ////////////////////////////////////////////////////////////////////////////////
376 // CanvasSkia, private: 410 // CanvasSkia, private:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 450
417 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { 451 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) {
418 #if defined(OS_WIN) 452 #if defined(OS_WIN)
419 return new CanvasPaintWin(view); 453 return new CanvasPaintWin(view);
420 #else 454 #else
421 return NULL; 455 return NULL;
422 #endif 456 #endif
423 } 457 }
424 458
425 } // namespace gfx 459 } // namespace gfx
OLDNEW
« no previous file with comments | « gfx/canvas_skia.h ('k') | gfx/gfx.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698