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

Side by Side Diff: ui/wm/core/image_grid.cc

Issue 1845283005: Makes ImageGrid work again (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « no previous file | 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/wm/core/image_grid.h" 5 #include "ui/wm/core/image_grid.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "third_party/skia/include/core/SkXfermode.h" 10 #include "third_party/skia/include/core/SkXfermode.h"
(...skipping 11 matching lines...) Expand all
22 using std::max; 22 using std::max;
23 using std::min; 23 using std::min;
24 24
25 namespace wm { 25 namespace wm {
26 namespace { 26 namespace {
27 27
28 // Sets the scaling for the transform applied to a layer. The left, top, 28 // Sets the scaling for the transform applied to a layer. The left, top,
29 // right and bottom layers are stretched to the height or width of the 29 // right and bottom layers are stretched to the height or width of the
30 // center image. 30 // center image.
31 31
32 void ScaleWidth(gfx::Size center, ui::Layer* layer, gfx::Transform& transform) { 32 void ScaleWidth(const gfx::Size& center,
33 ui::Layer* layer,
34 gfx::Transform* transform) {
33 float layer_width = layer->bounds().width() * layer->device_scale_factor(); 35 float layer_width = layer->bounds().width() * layer->device_scale_factor();
34 float scale = static_cast<float>(center.width()) / layer_width; 36 float scale = static_cast<float>(center.width()) / layer_width;
35 transform.Scale(scale, 1.0); 37 transform->Scale(scale, 1.0);
36 } 38 }
37 39
38 void ScaleHeight(gfx::Size center, 40 void ScaleHeight(const gfx::Size& center,
39 ui::Layer* layer, 41 ui::Layer* layer,
40 gfx::Transform& transform) { 42 gfx::Transform* transform) {
41 float layer_height = layer->bounds().height() * layer->device_scale_factor(); 43 float layer_height = layer->bounds().height() * layer->device_scale_factor();
42 float scale = static_cast<float>(center.height()) / layer_height; 44 float scale = static_cast<float>(center.height()) / layer_height;
43 transform.Scale(1.0, scale); 45 transform->Scale(1.0, scale);
44 } 46 }
45 47
46 // Returns the dimensions of |image| if non-NULL or gfx::Size(0, 0) otherwise. 48 // Returns the dimensions of |image| if non-NULL or gfx::Size(0, 0) otherwise.
47 gfx::Size GetImageSize(const gfx::Image* image) { 49 gfx::Size GetImageSize(const gfx::Image* image) {
48 return image ? gfx::Size(image->ToImageSkia()->width(), 50 return image ? gfx::Size(image->ToImageSkia()->width(),
49 image->ToImageSkia()->height()) 51 image->ToImageSkia()->height())
50 : gfx::Size(); 52 : gfx::Size();
51 } 53 }
52 54
53 // Returns true if |layer|'s bounds don't fit within |size|. 55 // Returns true if |layer|'s bounds don't fit within |size|.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // At non-integer scale factors, the ratio of dimensions in DIP is not 148 // At non-integer scale factors, the ratio of dimensions in DIP is not
147 // necessarily the same as the ratio in physical pixels due to rounding. Set 149 // necessarily the same as the ratio in physical pixels due to rounding. Set
148 // the transform on each of the layers based on dimensions in pixels. 150 // the transform on each of the layers based on dimensions in pixels.
149 gfx::Size center_size_in_pixels = gfx::ScaleToFlooredSize( 151 gfx::Size center_size_in_pixels = gfx::ScaleToFlooredSize(
150 gfx::Size(center_width, center_height), layer_->device_scale_factor()); 152 gfx::Size(center_width, center_height), layer_->device_scale_factor());
151 153
152 if (top_layer_.get()) { 154 if (top_layer_.get()) {
153 if (center_width > 0) { 155 if (center_width > 0) {
154 gfx::Transform transform; 156 gfx::Transform transform;
155 transform.Translate(left, 0); 157 transform.Translate(left, 0);
156 ScaleWidth(center_size_in_pixels, top_layer_.get(), transform); 158 ScaleWidth(center_size_in_pixels, top_layer_.get(), &transform);
157 top_layer_->SetTransform(transform); 159 top_layer_->SetTransform(transform);
158 } 160 }
159 top_layer_->SetVisible(center_width > 0); 161 top_layer_->SetVisible(center_width > 0);
160 } 162 }
161 if (bottom_layer_.get()) { 163 if (bottom_layer_.get()) {
162 if (center_width > 0) { 164 if (center_width > 0) {
163 gfx::Transform transform; 165 gfx::Transform transform;
164 transform.Translate( 166 transform.Translate(
165 left, size.height() - bottom_layer_->bounds().height()); 167 left, size.height() - bottom_layer_->bounds().height());
166 ScaleWidth(center_size_in_pixels, bottom_layer_.get(), transform); 168 ScaleWidth(center_size_in_pixels, bottom_layer_.get(), &transform);
167 bottom_layer_->SetTransform(transform); 169 bottom_layer_->SetTransform(transform);
168 } 170 }
169 bottom_layer_->SetVisible(center_width > 0); 171 bottom_layer_->SetVisible(center_width > 0);
170 } 172 }
171 if (left_layer_.get()) { 173 if (left_layer_.get()) {
172 if (center_height > 0) { 174 if (center_height > 0) {
173 gfx::Transform transform; 175 gfx::Transform transform;
174 transform.Translate(0, top); 176 transform.Translate(0, top);
175 ScaleHeight(center_size_in_pixels, left_layer_.get(), transform); 177 ScaleHeight(center_size_in_pixels, left_layer_.get(), &transform);
176 left_layer_->SetTransform(transform); 178 left_layer_->SetTransform(transform);
177 } 179 }
178 left_layer_->SetVisible(center_height > 0); 180 left_layer_->SetVisible(center_height > 0);
179 } 181 }
180 if (right_layer_.get()) { 182 if (right_layer_.get()) {
181 if (center_height > 0) { 183 if (center_height > 0) {
182 gfx::Transform transform; 184 gfx::Transform transform;
183 transform.Translate( 185 transform.Translate(
184 size.width() - right_layer_->bounds().width(), top); 186 size.width() - right_layer_->bounds().width(), top);
185 ScaleHeight(center_size_in_pixels, right_layer_.get(), transform); 187 ScaleHeight(center_size_in_pixels, right_layer_.get(), &transform);
186 right_layer_->SetTransform(transform); 188 right_layer_->SetTransform(transform);
187 } 189 }
188 right_layer_->SetVisible(center_height > 0); 190 right_layer_->SetVisible(center_height > 0);
189 } 191 }
190 192
191 if (top_left_layer_.get()) { 193 if (top_left_layer_.get()) {
192 // No transformation needed; it should be at (0, 0) and unscaled. 194 // No transformation needed; it should be at (0, 0) and unscaled.
193 top_left_painter_->SetClipRect( 195 top_left_painter_->SetClipRect(
194 LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ? 196 LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ?
195 gfx::Rect(gfx::Rect(0, 0, left, top)) : 197 gfx::Rect(gfx::Rect(0, 0, left, top)) :
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 263
262 void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect, 264 void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect,
263 ui::Layer* layer) { 265 ui::Layer* layer) {
264 if (clip_rect != clip_rect_) { 266 if (clip_rect != clip_rect_) {
265 clip_rect_ = clip_rect; 267 clip_rect_ = clip_rect;
266 layer->SchedulePaint(layer->bounds()); 268 layer->SchedulePaint(layer->bounds());
267 } 269 }
268 } 270 }
269 271
270 void ImageGrid::ImagePainter::OnPaintLayer(const ui::PaintContext& context) { 272 void ImageGrid::ImagePainter::OnPaintLayer(const ui::PaintContext& context) {
271 gfx::Size bounding_size(clip_rect_.right(), clip_rect_.bottom()); 273 gfx::Size bounding_size(image_.width(), image_.height());
sky 2016/04/01 23:11:56 This is the important change. The rest are just ra
272 ui::PaintRecorder recorder(context, bounding_size); 274 ui::PaintRecorder recorder(context, bounding_size);
273 if (!clip_rect_.IsEmpty()) 275 if (!clip_rect_.IsEmpty())
274 recorder.canvas()->ClipRect(clip_rect_); 276 recorder.canvas()->ClipRect(clip_rect_);
275 recorder.canvas()->DrawImageInt(image_, 0, 0); 277 recorder.canvas()->DrawImageInt(image_, 0, 0);
276 } 278 }
277 279
278 void ImageGrid::ImagePainter::OnDelegatedFrameDamage( 280 void ImageGrid::ImagePainter::OnDelegatedFrameDamage(
279 const gfx::Rect& damage_rect_in_dip) { 281 const gfx::Rect& damage_rect_in_dip) {
280 } 282 }
281 283
282 void ImageGrid::ImagePainter::OnDeviceScaleFactorChanged( 284 void ImageGrid::ImagePainter::OnDeviceScaleFactorChanged(
283 float device_scale_factor) { 285 float device_scale_factor) {
284 // Redrawing will take care of scale factor change. 286 // Redrawing will take care of scale factor change.
285 } 287 }
286 288
287 base::Closure ImageGrid::ImagePainter::PrepareForLayerBoundsChange() { 289 base::Closure ImageGrid::ImagePainter::PrepareForLayerBoundsChange() {
288 return base::Closure(); 290 return base::Closure();
289 } 291 }
290 292
291 void ImageGrid::SetImage(const gfx::Image* image, 293 void ImageGrid::SetImage(const gfx::Image* image,
292 scoped_ptr<ui::Layer>* layer_ptr, 294 scoped_ptr<ui::Layer>* layer_ptr,
293 scoped_ptr<ImagePainter>* painter_ptr, 295 scoped_ptr<ImagePainter>* painter_ptr,
294 ImageType type) { 296 ImageType type) {
295 // Minimum width (for HORIZONTAL) or height (for VERTICAL) of the 297 // Minimum width (for HORIZONTAL) or height (for VERTICAL) of the
296 // |image| so that layers are scaled property if the device scale 298 // |image| so that layers are scaled property if the device scale
297 // factor is non integral. 299 // factor is non integral.
298 const int kMinimumSize = 20; 300 const int kMinimumSize = 20;
299 301
300 // Clean out old layers and painters. 302 // Clean out old layers and painters.
301 if (layer_ptr->get())
302 layer_->Remove(layer_ptr->get());
303 layer_ptr->reset(); 303 layer_ptr->reset();
304 painter_ptr->reset(); 304 painter_ptr->reset();
305 305
306 // If we're not using an image, we're done. 306 // If we're not using an image, we're done.
307 if (!image) 307 if (!image)
308 return; 308 return;
309 309
310 gfx::ImageSkia image_skia = image->AsImageSkia(); 310 gfx::ImageSkia image_skia = image->AsImageSkia();
311 switch (type) { 311 switch (type) {
312 case HORIZONTAL: 312 case HORIZONTAL:
(...skipping 23 matching lines...) Expand all
336 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); 336 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height()));
337 337
338 painter_ptr->reset(new ImagePainter(image_skia)); 338 painter_ptr->reset(new ImagePainter(image_skia));
339 layer_ptr->get()->set_delegate(painter_ptr->get()); 339 layer_ptr->get()->set_delegate(painter_ptr->get());
340 layer_ptr->get()->SetFillsBoundsOpaquely(false); 340 layer_ptr->get()->SetFillsBoundsOpaquely(false);
341 layer_ptr->get()->SetVisible(true); 341 layer_ptr->get()->SetVisible(true);
342 layer_->Add(layer_ptr->get()); 342 layer_->Add(layer_ptr->get());
343 } 343 }
344 344
345 } // namespace wm 345 } // namespace wm
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698