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

Side by Side Diff: ui/gfx/image/image_family.cc

Issue 2707993005: Avoid returning a shallow copy of gfx::Image from gfx::ImageFamily::CreateExact (Closed)
Patch Set: fix Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/image/image_family.h" 5 #include "ui/gfx/image/image_family.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "skia/ext/image_operations.h" 9 #include "skia/ext/image_operations.h"
10 #include "ui/gfx/geometry/size.h" 10 #include "ui/gfx/geometry/size.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 gfx::Image ImageFamily::CreateExact(int width, int height) const { 111 gfx::Image ImageFamily::CreateExact(int width, int height) const {
112 // Resize crashes if width or height is 0, so just return an empty image. 112 // Resize crashes if width or height is 0, so just return an empty image.
113 if (width == 0 || height == 0) 113 if (width == 0 || height == 0)
114 return gfx::Image(); 114 return gfx::Image();
115 115
116 const gfx::Image* image = GetBest(width, height); 116 const gfx::Image* image = GetBest(width, height);
117 if (!image) 117 if (!image)
118 return gfx::Image(); 118 return gfx::Image();
119 119
120 if (image->Width() == width && image->Height() == height) 120 if (image->Width() == width && image->Height() == height) {
121 return gfx::Image(*image); 121 std::unique_ptr<gfx::ImageSkia> image_skia(image->CopyImageSkia());
Robert Sesek 2017/02/22 18:44:46 I'd leave a comment here as to why this is done.
tzik 2017/02/22 22:01:16 Done.
122 return gfx::Image(*image_skia);
123 }
122 124
123 SkBitmap bitmap = image->AsBitmap(); 125 SkBitmap bitmap = image->AsBitmap();
124 SkBitmap resized_bitmap = skia::ImageOperations::Resize( 126 SkBitmap resized_bitmap = skia::ImageOperations::Resize(
125 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, width, height); 127 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, width, height);
126 return gfx::Image::CreateFrom1xBitmap(resized_bitmap); 128 return gfx::Image::CreateFrom1xBitmap(resized_bitmap);
127 } 129 }
128 130
129 gfx::Image ImageFamily::CreateExact(const gfx::Size& size) const { 131 gfx::Image ImageFamily::CreateExact(const gfx::Size& size) const {
130 return CreateExact(size.width(), size.height()); 132 return CreateExact(size.width(), size.height());
131 } 133 }
(...skipping 12 matching lines...) Expand all
144 DCHECK(greater_or_equal != map_.begin()); 146 DCHECK(greater_or_equal != map_.begin());
145 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal; 147 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal;
146 --less_than; 148 --less_than;
147 // This must be true because there must be at least one image with |aspect|. 149 // This must be true because there must be at least one image with |aspect|.
148 DCHECK_EQ(less_than->first.aspect(), aspect); 150 DCHECK_EQ(less_than->first.aspect(), aspect);
149 // We have found the largest image smaller than desired. 151 // We have found the largest image smaller than desired.
150 return &less_than->second; 152 return &less_than->second;
151 } 153 }
152 154
153 } // namespace gfx 155 } // namespace gfx
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