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

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

Issue 1831883002: Use sk_sp-based shader creation APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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/skia_util.h ('k') | ui/native_theme/native_theme_base.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/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1))); 84 flattened->set(1, SkMScalarToScalar(transform.matrix().get(0, 1)));
85 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3))); 85 flattened->set(2, SkMScalarToScalar(transform.matrix().get(0, 3)));
86 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0))); 86 flattened->set(3, SkMScalarToScalar(transform.matrix().get(1, 0)));
87 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1))); 87 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1)));
88 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3))); 88 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3)));
89 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0))); 89 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0)));
90 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1))); 90 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1)));
91 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3))); 91 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3)));
92 } 92 }
93 93
94 skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, 94 sk_sp<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep,
95 SkShader::TileMode tile_mode, 95 SkShader::TileMode tile_mode,
96 const SkMatrix& local_matrix) { 96 const SkMatrix& local_matrix) {
97 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix, 97 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix,
98 image_rep.scale()); 98 image_rep.scale());
99 } 99 }
100 100
101 skia::RefPtr<SkShader> CreateImageRepShaderForScale( 101 sk_sp<SkShader> CreateImageRepShaderForScale(
102 const gfx::ImageSkiaRep& image_rep, 102 const gfx::ImageSkiaRep& image_rep,
103 SkShader::TileMode tile_mode, 103 SkShader::TileMode tile_mode,
104 const SkMatrix& local_matrix, 104 const SkMatrix& local_matrix,
105 SkScalar scale) { 105 SkScalar scale) {
106 // Unscale matrix by |scale| such that the bitmap is drawn at the 106 // Unscale matrix by |scale| such that the bitmap is drawn at the
107 // correct density. 107 // correct density.
108 // Convert skew and translation to pixel coordinates. 108 // Convert skew and translation to pixel coordinates.
109 // Thus, for |bitmap_scale| = 2: 109 // Thus, for |bitmap_scale| = 2:
110 // x scale = 2, x translation = 1 DIP, 110 // x scale = 2, x translation = 1 DIP,
111 // should be converted to 111 // should be converted to
112 // x scale = 1, x translation = 2 pixels. 112 // x scale = 1, x translation = 2 pixels.
113 SkMatrix shader_scale = local_matrix; 113 SkMatrix shader_scale = local_matrix;
114 shader_scale.preScale(scale, scale); 114 shader_scale.preScale(scale, scale);
115 shader_scale.setScaleX(local_matrix.getScaleX() / scale); 115 shader_scale.setScaleX(local_matrix.getScaleX() / scale);
116 shader_scale.setScaleY(local_matrix.getScaleY() / scale); 116 shader_scale.setScaleY(local_matrix.getScaleY() / scale);
117 117
118 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader( 118 return SkShader::MakeBitmapShader(
119 image_rep.sk_bitmap(), tile_mode, tile_mode, &shader_scale)); 119 image_rep.sk_bitmap(), tile_mode, tile_mode, &shader_scale);
120 return shader;
121 } 120 }
122 121
123 skia::RefPtr<SkShader> CreateGradientShader(int start_point, 122 sk_sp<SkShader> CreateGradientShader(int start_point,
124 int end_point, 123 int end_point,
125 SkColor start_color, 124 SkColor start_color,
126 SkColor end_color) { 125 SkColor end_color) {
127 SkColor grad_colors[2] = { start_color, end_color}; 126 SkColor grad_colors[2] = { start_color, end_color};
128 SkPoint grad_points[2]; 127 SkPoint grad_points[2];
129 grad_points[0].iset(0, start_point); 128 grad_points[0].iset(0, start_point);
130 grad_points[1].iset(0, end_point); 129 grad_points[1].iset(0, end_point);
131 130
132 return skia::AdoptRef(SkGradientShader::CreateLinear( 131 return SkGradientShader::MakeLinear(
133 grad_points, grad_colors, NULL, 2, SkShader::kClamp_TileMode)); 132 grad_points, grad_colors, NULL, 2, SkShader::kClamp_TileMode);
134 } 133 }
135 134
136 static SkScalar RadiusToSigma(double radius) { 135 static SkScalar RadiusToSigma(double radius) {
137 // This captures historically what skia did under the hood. Now skia accepts 136 // This captures historically what skia did under the hood. Now skia accepts
138 // sigma, not radius, so we perform the conversion. 137 // sigma, not radius, so we perform the conversion.
139 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0; 138 return radius > 0 ? SkDoubleToScalar(0.57735f * radius + 0.5) : 0;
140 } 139 }
141 140
142 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper( 141 skia::RefPtr<SkDrawLooper> CreateShadowDrawLooper(
143 const std::vector<ShadowValue>& shadows) { 142 const std::vector<ShadowValue>& shadows) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1; 236 static const SkScalar kSkToHbRatio = SK_Scalar1 / kHbUnit1;
238 return kSkToHbRatio * value; 237 return kSkToHbRatio * value;
239 } 238 }
240 239
241 float HarfBuzzUnitsToFloat(int value) { 240 float HarfBuzzUnitsToFloat(int value) {
242 static const float kFloatToHbRatio = 1.0f / kHbUnit1; 241 static const float kFloatToHbRatio = 1.0f / kHbUnit1;
243 return kFloatToHbRatio * value; 242 return kFloatToHbRatio * value;
244 } 243 }
245 244
246 } // namespace gfx 245 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/skia_util.h ('k') | ui/native_theme/native_theme_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698