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

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

Issue 2849953004: SV Test
Patch Set: Created 3 years, 7 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/gfx/canvas.h ('k') | ui/views/view.h » ('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 "cc/paint/paint_flags.h" 12 #include "cc/paint/paint_flags.h"
13 #include "cc/paint/paint_shader.h" 13 #include "cc/paint/paint_shader.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkPath.h" 15 #include "third_party/skia/include/core/SkPath.h"
16 #include "third_party/skia/include/core/SkRefCnt.h" 16 #include "third_party/skia/include/core/SkRefCnt.h"
17 #include "third_party/skia/include/effects/SkGradientShader.h" 17 #include "third_party/skia/include/effects/SkGradientShader.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/geometry/insets_f.h" 19 #include "ui/gfx/geometry/insets_f.h"
20 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/geometry/rect_conversions.h" 21 #include "ui/gfx/geometry/rect_conversions.h"
22 #include "ui/gfx/geometry/rect_f.h" 22 #include "ui/gfx/geometry/rect_f.h"
23 #include "ui/gfx/geometry/safe_integer_conversions.h" 23 #include "ui/gfx/geometry/safe_integer_conversions.h"
24 #include "ui/gfx/geometry/size_conversions.h" 24 #include "ui/gfx/geometry/size_conversions.h"
25 #include "ui/gfx/scoped_canvas.h" 25 #include "ui/gfx/scoped_canvas.h"
26 #include "ui/gfx/skia_paint_util.h" 26 #include "ui/gfx/skia_paint_util.h"
27 #include "ui/gfx/skia_util.h" 27 #include "ui/gfx/skia_util.h"
28 #include "ui/gfx/transform.h" 28 #include "ui/gfx/transform.h"
29 29
30 #include "base/debug/stack_trace.h"
31
30 namespace gfx { 32 namespace gfx {
31 33
32 Canvas::Canvas(const Size& size, float image_scale, bool is_opaque) 34 Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
33 : image_scale_(image_scale) { 35 : image_scale_(image_scale) {
34 Size pixel_size = ScaleToCeiledSize(size, image_scale); 36 Size pixel_size = ScaleToCeiledSize(size, image_scale);
35 canvas_ = CreateOwnedCanvas(pixel_size, is_opaque); 37 canvas_ = CreateOwnedCanvas(pixel_size, is_opaque);
38 LOG(ERROR) << "image scale:" << image_scale;
39
36 40
37 #if !defined(USE_CAIRO) 41 #if !defined(USE_CAIRO)
38 // skia::PlatformCanvas instances are initialized to 0 by Cairo, but 42 // skia::PlatformCanvas instances are initialized to 0 by Cairo, but
39 // uninitialized on other platforms. 43 // uninitialized on other platforms.
40 if (!is_opaque) 44 if (!is_opaque)
41 canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); 45 canvas_->clear(SkColorSetARGB(0, 0, 0, 0));
42 #endif 46 #endif
43 47
44 SkScalar scale_scalar = SkFloatToScalar(image_scale); 48 SkScalar scale_scalar = SkFloatToScalar(image_scale);
45 canvas_->scale(scale_scalar, scale_scalar); 49 canvas_->scale(scale_scalar, scale_scalar);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return true; 199 return true;
196 } 200 }
197 *bounds = gfx::Rect(); 201 *bounds = gfx::Rect();
198 return false; 202 return false;
199 } 203 }
200 204
201 void Canvas::Translate(const Vector2d& offset) { 205 void Canvas::Translate(const Vector2d& offset) {
202 canvas_->translate(SkIntToScalar(offset.x()), SkIntToScalar(offset.y())); 206 canvas_->translate(SkIntToScalar(offset.x()), SkIntToScalar(offset.y()));
203 } 207 }
204 208
205 void Canvas::Scale(int x_scale, int y_scale) { 209 void Canvas::Scale(float x_scale, float y_scale) {
206 canvas_->scale(SkIntToScalar(x_scale), SkIntToScalar(y_scale)); 210 canvas_->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
207 } 211 }
208 212
209 void Canvas::DrawColor(SkColor color) { 213 void Canvas::DrawColor(SkColor color) {
210 DrawColor(color, SkBlendMode::kSrcOver); 214 DrawColor(color, SkBlendMode::kSrcOver);
211 } 215 }
212 216
213 void Canvas::DrawColor(SkColor color, SkBlendMode mode) { 217 void Canvas::DrawColor(SkColor color, SkBlendMode mode) {
214 canvas_->drawColor(color, mode); 218 canvas_->drawColor(color, mode);
215 } 219 }
216 220
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 bitmap_.emplace(); 586 bitmap_.emplace();
583 bitmap_->allocPixels(info); 587 bitmap_->allocPixels(info);
584 // Ensure that the bitmap is zeroed, since the code expects that. 588 // Ensure that the bitmap is zeroed, since the code expects that.
585 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); 589 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize());
586 590
587 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); 591 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value());
588 return &owned_canvas_.value(); 592 return &owned_canvas_.value();
589 } 593 }
590 594
591 } // namespace gfx 595 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.h ('k') | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698