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

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

Issue 262773010: Fix images drawn with the NineImagePainter class in high DPI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to tip Created 6 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
« ui/gfx/canvas.cc ('K') | « ui/gfx/skia_util.h ('k') | no next file » | 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 "third_party/skia/include/core/SkBitmap.h" 7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "third_party/skia/include/core/SkColorFilter.h" 8 #include "third_party/skia/include/core/SkColorFilter.h"
9 #include "third_party/skia/include/core/SkColorPriv.h" 9 #include "third_party/skia/include/core/SkColorPriv.h"
10 #include "third_party/skia/include/core/SkUnPreMultiply.h" 10 #include "third_party/skia/include/core/SkUnPreMultiply.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1))); 57 flattened->set(4, SkMScalarToScalar(transform.matrix().get(1, 1)));
58 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3))); 58 flattened->set(5, SkMScalarToScalar(transform.matrix().get(1, 3)));
59 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0))); 59 flattened->set(6, SkMScalarToScalar(transform.matrix().get(3, 0)));
60 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1))); 60 flattened->set(7, SkMScalarToScalar(transform.matrix().get(3, 1)));
61 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3))); 61 flattened->set(8, SkMScalarToScalar(transform.matrix().get(3, 3)));
62 } 62 }
63 63
64 skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep, 64 skia::RefPtr<SkShader> CreateImageRepShader(const gfx::ImageSkiaRep& image_rep,
65 SkShader::TileMode tile_mode, 65 SkShader::TileMode tile_mode,
66 const SkMatrix& local_matrix) { 66 const SkMatrix& local_matrix) {
67 return CreateImageRepShaderForScale(image_rep, tile_mode, local_matrix,
68 image_rep.scale());
69 }
70
71 skia::RefPtr<SkShader> CreateImageRepShaderForScale(
72 const gfx::ImageSkiaRep& image_rep,
73 SkShader::TileMode tile_mode,
74 const SkMatrix& local_matrix,
75 SkScalar scale) {
67 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader( 76 skia::RefPtr<SkShader> shader = skia::AdoptRef(SkShader::CreateBitmapShader(
68 image_rep.sk_bitmap(), tile_mode, tile_mode)); 77 image_rep.sk_bitmap(), tile_mode, tile_mode));
69 SkScalar scale_x = local_matrix.getScaleX(); 78 SkScalar scale_x = local_matrix.getScaleX();
70 SkScalar scale_y = local_matrix.getScaleY(); 79 SkScalar scale_y = local_matrix.getScaleY();
71 SkScalar bitmap_scale = SkFloatToScalar(image_rep.scale());
72 80
73 // Unscale matrix by |bitmap_scale| such that the bitmap is drawn at the 81 // Unscale matrix by |scale| such that the bitmap is drawn at the
74 // correct density. 82 // correct density.
75 // Convert skew and translation to pixel coordinates. 83 // Convert skew and translation to pixel coordinates.
76 // Thus, for |bitmap_scale| = 2: 84 // Thus, for |bitmap_scale| = 2:
77 // x scale = 2, x translation = 1 DIP, 85 // x scale = 2, x translation = 1 DIP,
78 // should be converted to 86 // should be converted to
79 // x scale = 1, x translation = 2 pixels. 87 // x scale = 1, x translation = 2 pixels.
80 SkMatrix shader_scale = local_matrix; 88 SkMatrix shader_scale = local_matrix;
81 shader_scale.preScale(bitmap_scale, bitmap_scale); 89 shader_scale.preScale(scale, scale);
82 shader_scale.setScaleX(SkScalarDiv(scale_x, bitmap_scale)); 90 shader_scale.setScaleX(SkScalarDiv(scale_x, scale));
83 shader_scale.setScaleY(SkScalarDiv(scale_y, bitmap_scale)); 91 shader_scale.setScaleY(SkScalarDiv(scale_y, scale));
84 92
85 shader->setLocalMatrix(shader_scale); 93 shader->setLocalMatrix(shader_scale);
86 return shader; 94 return shader;
87 } 95 }
88 96
89 skia::RefPtr<SkShader> CreateGradientShader(int start_point, 97 skia::RefPtr<SkShader> CreateGradientShader(int start_point,
90 int end_point, 98 int end_point,
91 SkColor start_color, 99 SkColor start_color,
92 SkColor end_color) { 100 SkColor end_color) {
93 SkColor grad_colors[2] = { start_color, end_color}; 101 SkColor grad_colors[2] = { start_color, end_color};
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } else { 188 } else {
181 rgba[i + 0] = SkGetPackedR32(pixel_in); 189 rgba[i + 0] = SkGetPackedR32(pixel_in);
182 rgba[i + 1] = SkGetPackedG32(pixel_in); 190 rgba[i + 1] = SkGetPackedG32(pixel_in);
183 rgba[i + 2] = SkGetPackedB32(pixel_in); 191 rgba[i + 2] = SkGetPackedB32(pixel_in);
184 rgba[i + 3] = alpha; 192 rgba[i + 3] = alpha;
185 } 193 }
186 } 194 }
187 } 195 }
188 196
189 } // namespace gfx 197 } // namespace gfx
OLDNEW
« ui/gfx/canvas.cc ('K') | « ui/gfx/skia_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698