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

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

Issue 1357423009: gfx: Make conversions from Size to SizeF be explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sizefconvert-gfx: . Created 5 years, 2 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
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | ui/gfx/display.cc » ('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) 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 #include "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "third_party/skia/include/effects/SkGradientShader.h" 13 #include "third_party/skia/include/effects/SkGradientShader.h"
14 #include "ui/gfx/font_list.h" 14 #include "ui/gfx/font_list.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/rect_conversions.h" 16 #include "ui/gfx/geometry/rect_conversions.h"
17 #include "ui/gfx/geometry/safe_integer_conversions.h" 17 #include "ui/gfx/geometry/safe_integer_conversions.h"
18 #include "ui/gfx/geometry/size_conversions.h" 18 #include "ui/gfx/geometry/size_conversions.h"
19 #include "ui/gfx/scoped_canvas.h" 19 #include "ui/gfx/scoped_canvas.h"
20 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
21 #include "ui/gfx/transform.h" 21 #include "ui/gfx/transform.h"
22 22
23 namespace gfx { 23 namespace gfx {
24 24
25 Canvas::Canvas(const Size& size, float image_scale, bool is_opaque) 25 Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
26 : image_scale_(image_scale), 26 : image_scale_(image_scale),
27 canvas_(NULL) { 27 canvas_(NULL) {
28 Size pixel_size = ToCeiledSize(ScaleSize(size, image_scale)); 28 Size pixel_size = ScaleToCeiledSize(size, image_scale);
29 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), 29 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
30 pixel_size.height(), 30 pixel_size.height(),
31 is_opaque)); 31 is_opaque));
32 canvas_ = owned_canvas_.get(); 32 canvas_ = owned_canvas_.get();
33 #if defined(OS_WIN) || defined(OS_MACOSX) 33 #if defined(OS_WIN) || defined(OS_MACOSX)
34 // skia::PlatformCanvas instances are initialized to 0 by Cairo on Linux, but 34 // skia::PlatformCanvas instances are initialized to 0 by Cairo on Linux, but
35 // uninitialized on Win and Mac. 35 // uninitialized on Win and Mac.
36 if (!is_opaque) 36 if (!is_opaque)
37 owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); 37 owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
38 #endif 38 #endif
(...skipping 25 matching lines...) Expand all
64 DCHECK(canvas); 64 DCHECK(canvas);
65 } 65 }
66 66
67 Canvas::~Canvas() { 67 Canvas::~Canvas() {
68 } 68 }
69 69
70 void Canvas::RecreateBackingCanvas(const Size& size, 70 void Canvas::RecreateBackingCanvas(const Size& size,
71 float image_scale, 71 float image_scale,
72 bool is_opaque) { 72 bool is_opaque) {
73 image_scale_ = image_scale; 73 image_scale_ = image_scale;
74 Size pixel_size = ToFlooredSize(ScaleSize(size, image_scale)); 74 Size pixel_size = ScaleToFlooredSize(size, image_scale);
75 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), 75 owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(),
76 pixel_size.height(), 76 pixel_size.height(),
77 is_opaque)); 77 is_opaque));
78 canvas_ = owned_canvas_.get(); 78 canvas_ = owned_canvas_.get();
79 SkScalar scale_scalar = SkFloatToScalar(image_scale); 79 SkScalar scale_scalar = SkFloatToScalar(image_scale);
80 canvas_->scale(scale_scalar, scale_scalar); 80 canvas_->scale(scale_scalar, scale_scalar);
81 } 81 }
82 82
83 // static 83 // static
84 void Canvas::SizeStringInt(const base::string16& text, 84 void Canvas::SizeStringInt(const base::string16& text,
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // by the paint). 621 // by the paint).
622 SkPaint p(paint); 622 SkPaint p(paint);
623 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); 623 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
624 p.setShader(shader.get()); 624 p.setShader(shader.get());
625 625
626 // The rect will be filled by the bitmap. 626 // The rect will be filled by the bitmap.
627 canvas_->drawRect(dest_rect, p); 627 canvas_->drawRect(dest_rect, p);
628 } 628 }
629 629
630 } // namespace gfx 630 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | ui/gfx/display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698