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

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

Issue 11377068: ui: Make gfx::Size::Scale() mutate the class. Add gfx::ScaleSize() similar to Rect/Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseTOGO Created 8 years, 1 month 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 | « ui/compositor/layer.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 <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"
(...skipping 11 matching lines...) Expand all
22 #endif 22 #endif
23 23
24 namespace gfx { 24 namespace gfx {
25 25
26 Canvas::Canvas(const gfx::Size& size, 26 Canvas::Canvas(const gfx::Size& size,
27 ui::ScaleFactor scale_factor, 27 ui::ScaleFactor scale_factor,
28 bool is_opaque) 28 bool is_opaque)
29 : scale_factor_(scale_factor), 29 : scale_factor_(scale_factor),
30 owned_canvas_(NULL), 30 owned_canvas_(NULL),
31 canvas_(NULL) { 31 canvas_(NULL) {
32 gfx::Size pixel_size = gfx::ToFlooredSize(size.Scale( 32 gfx::Size pixel_size = gfx::ToFlooredSize(
33 ui::GetScaleFactorScale(scale_factor))); 33 gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
34 owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(), 34 owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(),
35 pixel_size.height(), 35 pixel_size.height(),
36 is_opaque)); 36 is_opaque));
37 canvas_ = owned_canvas_.get(); 37 canvas_ = owned_canvas_.get();
38 #if defined(OS_WIN) || defined(OS_MACOSX) 38 #if defined(OS_WIN) || defined(OS_MACOSX)
39 // skia::PlatformCanvas instances are initialized to 0 by Cairo on Linux, but 39 // skia::PlatformCanvas instances are initialized to 0 by Cairo on Linux, but
40 // uninitialized on Win and Mac. 40 // uninitialized on Win and Mac.
41 if (!is_opaque) 41 if (!is_opaque)
42 owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); 42 owned_canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
43 #endif 43 #endif
(...skipping 26 matching lines...) Expand all
70 Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas, 70 Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas,
71 ui::ScaleFactor scale_factor) { 71 ui::ScaleFactor scale_factor) {
72 return new Canvas(canvas, scale_factor); 72 return new Canvas(canvas, scale_factor);
73 } 73 }
74 74
75 void Canvas::RecreateBackingCanvas(const gfx::Size& size, 75 void Canvas::RecreateBackingCanvas(const gfx::Size& size,
76 ui::ScaleFactor scale_factor, 76 ui::ScaleFactor scale_factor,
77 bool is_opaque) { 77 bool is_opaque) {
78 scale_factor_ = scale_factor; 78 scale_factor_ = scale_factor;
79 gfx::Size pixel_size = gfx::ToFlooredSize( 79 gfx::Size pixel_size = gfx::ToFlooredSize(
80 size.Scale(ui::GetScaleFactorScale(scale_factor))); 80 gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
81 owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(), 81 owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(),
82 pixel_size.height(), 82 pixel_size.height(),
83 is_opaque)); 83 is_opaque));
84 canvas_ = owned_canvas_.get(); 84 canvas_ = owned_canvas_.get();
85 SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); 85 SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_));
86 canvas_->scale(scale, scale); 86 canvas_->scale(scale, scale);
87 } 87 }
88 88
89 // static 89 // static
90 int Canvas::GetStringWidth(const string16& text, const gfx::Font& font) { 90 int Canvas::GetStringWidth(const string16& text, const gfx::Font& font) {
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 532
533 float bitmap_scale = image_rep.GetScale(); 533 float bitmap_scale = image_rep.GetScale();
534 if (scale_x < bitmap_scale || scale_y < bitmap_scale) 534 if (scale_x < bitmap_scale || scale_y < bitmap_scale)
535 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); 535 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap();
536 } 536 }
537 537
538 return image_rep; 538 return image_rep;
539 } 539 }
540 540
541 } // namespace gfx 541 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/compositor/layer.cc ('k') | ui/gfx/display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698