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

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

Issue 10783015: Add ability to store hidpi theme images in data pack (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/theme_provider.h ('k') | ui/gfx/image/image_skia_operations.h » ('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/image/image_skia.h" 5 #include "ui/gfx/image/image_skia.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 // Attempt to generate image reps for as many scale factors supported by 229 // Attempt to generate image reps for as many scale factors supported by
230 // this platform as possible. 230 // this platform as possible.
231 // Do not build return array here because the mapping from scale factor to 231 // Do not build return array here because the mapping from scale factor to
232 // image rep is one to many in some cases. 232 // image rep is one to many in some cases.
233 std::vector<ui::ScaleFactor> supported_scale_factors = 233 std::vector<ui::ScaleFactor> supported_scale_factors =
234 ui::GetSupportedScaleFactors(); 234 ui::GetSupportedScaleFactors();
235 for (size_t i = 0; i < supported_scale_factors.size(); ++i) 235 for (size_t i = 0; i < supported_scale_factors.size(); ++i)
236 storage_->FindRepresentation(supported_scale_factors[i], true); 236 storage_->FindRepresentation(supported_scale_factors[i], true);
237 237
238 ImageSkiaReps internal_image_reps = storage_->image_reps(); 238 return image_reps();
239 // Create list of image reps to return, skipping null image reps which were
240 // added for caching purposes only.
241 ImageSkiaReps image_reps;
242 for (ImageSkiaReps::iterator it = internal_image_reps.begin();
243 it != internal_image_reps.end(); ++it) {
244 if (!it->is_null())
245 image_reps.push_back(*it);
246 }
247
248 return image_reps;
249 } 239 }
250 240
251 #endif // OS_MACOSX 241 #endif // OS_MACOSX
252 242
253 bool ImageSkia::empty() const { 243 bool ImageSkia::empty() const {
254 return isNull() || storage_->size().IsEmpty(); 244 return isNull() || storage_->size().IsEmpty();
255 } 245 }
256 246
257 int ImageSkia::width() const { 247 int ImageSkia::width() const {
258 return isNull() ? 0 : storage_->size().width(); 248 return isNull() ? 0 : storage_->size().width();
(...skipping 10 matching lines...) Expand all
269 bool ImageSkia::extractSubset(ImageSkia* dst, const SkIRect& subset) const { 259 bool ImageSkia::extractSubset(ImageSkia* dst, const SkIRect& subset) const {
270 gfx::Rect rect(subset.x(), subset.y(), subset.width(), subset.height()); 260 gfx::Rect rect(subset.x(), subset.y(), subset.width(), subset.height());
271 *dst = ImageSkiaOperations::ExtractSubset(*this, rect); 261 *dst = ImageSkiaOperations::ExtractSubset(*this, rect);
272 return (!dst->isNull()); 262 return (!dst->isNull());
273 } 263 }
274 264
275 std::vector<ImageSkiaRep> ImageSkia::image_reps() const { 265 std::vector<ImageSkiaRep> ImageSkia::image_reps() const {
276 if (isNull()) 266 if (isNull())
277 return std::vector<ImageSkiaRep>(); 267 return std::vector<ImageSkiaRep>();
278 268
279 return storage_->image_reps(); 269 ImageSkiaReps internal_image_reps = storage_->image_reps();
270 // Create list of image reps to return, skipping null image reps which were
271 // added for caching purposes only.
272 ImageSkiaReps image_reps;
273 for (ImageSkiaReps::iterator it = internal_image_reps.begin();
274 it != internal_image_reps.end(); ++it) {
275 if (!it->is_null())
276 image_reps.push_back(*it);
277 }
278
279 return image_reps;
280 } 280 }
281 281
282 const SkBitmap* ImageSkia::bitmap() const { 282 const SkBitmap* ImageSkia::bitmap() const {
283 if (isNull()) { 283 if (isNull()) {
284 // Callers expect a ImageSkiaRep even if it is |isNull()|. 284 // Callers expect a ImageSkiaRep even if it is |isNull()|.
285 // TODO(pkotwicz): Fix this. 285 // TODO(pkotwicz): Fix this.
286 return &NullImageRep().sk_bitmap(); 286 return &NullImageRep().sk_bitmap();
287 } 287 }
288 288
289 ImageSkiaReps::iterator it = 289 ImageSkiaReps::iterator it =
290 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true); 290 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true);
291 return &it->sk_bitmap(); 291 return &it->sk_bitmap();
292 } 292 }
293 293
294 void ImageSkia::Init(const ImageSkiaRep& image_rep) { 294 void ImageSkia::Init(const ImageSkiaRep& image_rep) {
295 // TODO(pkotwicz): The image should be null whenever image rep is null. 295 // TODO(pkotwicz): The image should be null whenever image rep is null.
296 if (image_rep.sk_bitmap().empty()) { 296 if (image_rep.sk_bitmap().empty()) {
297 storage_ = NULL; 297 storage_ = NULL;
298 return; 298 return;
299 } 299 }
300 storage_ = new internal::ImageSkiaStorage( 300 storage_ = new internal::ImageSkiaStorage(
301 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); 301 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight()));
302 storage_->image_reps().push_back(image_rep); 302 storage_->image_reps().push_back(image_rep);
303 } 303 }
304 304
305 } // namespace gfx 305 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/base/theme_provider.h ('k') | ui/gfx/image/image_skia_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698