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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase Created 3 years, 11 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
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/skia_util.h" 5 #include "ui/gfx/skia_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1))); 97 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1)));
98 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3))); 98 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3)));
99 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0))); 99 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0)));
100 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1))); 100 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1)));
101 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3))); 101 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3)));
102 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0))); 102 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0)));
103 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1))); 103 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1)));
104 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3))); 104 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3)));
105 } 105 }
106 106
107 sk_sp<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, 107 sk_sp<cc::PaintShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep,
108 SkShader::TileMode tile_mode, 108 cc::PaintShader::TileMode tile_mode,
109 const SkMatrix& local_matrix) { 109 const SkMatrix& local_matrix) {
110 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix, 110 return cc::WrapSkShader(CreateImageRepShaderForScale(
111 image_rep.scale()); 111 image_rep, tile_mode, local_matrix, image_rep.scale()));
112 } 112 }
113 113
114 sk_sp<SkShader> CreateImageRepShaderForScale( 114 sk_sp<cc::PaintShader> CreateImageRepShaderForScale(
115 const gfx::ImageSkiaRep& image_rep, 115 const gfx::ImageSkiaRep& image_rep,
116 SkShader::TileMode tile_mode, 116 cc::PaintShader::TileMode tile_mode,
117 const SkMatrix& local_matrix, 117 const SkMatrix& local_matrix,
118 SkScalar scale) { 118 SkScalar scale) {
119 // Unscale matrix by |scale| such that the bitmap is drawn at the 119 // Unscale matrix by |scale| such that the bitmap is drawn at the
120 // correct density. 120 // correct density.
121 // Convert skew and translation to pixel coordinates. 121 // Convert skew and translation to pixel coordinates.
122 // Thus, for |bitmap_scale| = 2: 122 // Thus, for |bitmap_scale| = 2:
123 // x scale = 2, x translation = 1 DIP, 123 // x scale = 2, x translation = 1 DIP,
124 // should be converted to 124 // should be converted to
125 // x scale = 1, x translation = 2 pixels. 125 // x scale = 1, x translation = 2 pixels.
126 SkMatrix shader_scale = local_matrix; 126 SkMatrix shader_scale = local_matrix;
127 shader_scale.preScale(scale, scale); 127 shader_scale.preScale(scale, scale);
128 shader_scale.setScaleX(local_matrix.getScaleX() / scale); 128 shader_scale.setScaleX(local_matrix.getScaleX() / scale);
129 shader_scale.setScaleY(local_matrix.getScaleY() / scale); 129 shader_scale.setScaleY(local_matrix.getScaleY() / scale);
130 130
131 return SkShader::MakeBitmapShader( 131 return cc::WrapSkShader(cc::PaintShader::MakeBitmapShader(
132 image_rep.sk_bitmap(), tile_mode, tile_mode, &shader_scale); 132 image_rep.sk_bitmap(), tile_mode, tile_mode, &shader_scale));
133 } 133 }
134 134
135 sk_sp<SkShader> CreateGradientShader(int start_point, 135 sk_sp<cc::PaintShader> CreateGradientShader(int start_point,
136 int end_point, 136 int end_point,
137 SkColor start_color, 137 SkColor start_color,
138 SkColor end_color) { 138 SkColor end_color) {
139 SkColor grad_colors[2] = { start_color, end_color}; 139 SkColor grad_colors[2] = { start_color, end_color};
140 SkPoint grad_points[2]; 140 SkPoint grad_points[2];
141 grad_points[0].iset(0, start_point); 141 grad_points[0].iset(0, start_point);
142 grad_points[1].iset(0, end_point); 142 grad_points[1].iset(0, end_point);
143 143
144 return SkGradientShader::MakeLinear( 144 return cc::WrapSkShader(SkGradientShader::MakeLinear(
145 grad_points, grad_colors, NULL, 2, SkShader::kClamp_TileMode); 145 grad_points, grad_colors, NULL, 2, cc::PaintShader::kClamp_TileMode));
146 } 146 }
147 147
148 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper. 148 // TODO(estade): remove. Only exists to support legacy CreateShadowDrawLooper.
149 static SkScalar DeprecatedRadiusToSigma(double radius) { 149 static SkScalar DeprecatedRadiusToSigma(double radius) {
150 // This captures historically what skia did under the hood. Now skia accepts 150 // This captures historically what skia did under the hood. Now skia accepts
151 // sigma, not radius, so we perform the conversion. 151 // sigma, not radius, so we perform the conversion.
152 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; 152 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
153 } 153 }
154 154
155 // This is copied from 155 // This is copied from
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; 287 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1;
288 return kSkToHbRatio * value; 288 return kSkToHbRatio * value;
289 } 289 }
290 290
291 float HarfBuzzUnitsToFloat(int value) { 291 float HarfBuzzUnitsToFloat(int value) {
292 static const float kFloatToHbRatio = 1.0f / kHbUnit1; 292 static const float kFloatToHbRatio = 1.0f / kHbUnit1;
293 return kFloatToHbRatio * value; 293 return kFloatToHbRatio * value;
294 } 294 }
295 295
296 } // namespace gfx 296 } // namespace gfx
OLDNEW
« ui/gfx/canvas_paint_mac.mm ('K') | « ui/gfx/skia_util.h ('k') | ui/native_theme/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698