OLD | NEW |
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 <limits> | 7 #include <limits> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ImageSkia::~ImageSkia() { | 84 ImageSkia::~ImageSkia() { |
85 } | 85 } |
86 | 86 |
87 void ImageSkia::AddBitmapForScale(const SkBitmap& bitmap, | 87 void ImageSkia::AddBitmapForScale(const SkBitmap& bitmap, |
88 float dip_scale_factor) { | 88 float dip_scale_factor) { |
89 DCHECK(!bitmap.isNull()); | 89 DCHECK(!bitmap.isNull()); |
90 | 90 |
91 if (isNull()) { | 91 if (isNull()) { |
92 Init(bitmap, dip_scale_factor); | 92 Init(bitmap, dip_scale_factor); |
93 } else { | 93 } else { |
94 // Currently data packs include 1x scale images whenever a different scale | 94 // We currently assume that the bitmap size = 1x size * |dip_scale_factor|. |
95 // image is unavailable. As |dip_scale_factor| is derived from the data | 95 // TODO(pkotwicz): Do something better because of rounding errors when |
96 // pack, sometimes |dip_scale_factor| is incorrect. | 96 // |dip_scale_factor| is not an int. |
97 // TODO(pkotwicz): Fix this and add DCHECK. | 97 // TODO(pkotwicz): Remove DCHECK for dip_scale_factor == 1.0f once |
| 98 // image_loading_tracker correctly handles multiple sized images. |
| 99 DCHECK(dip_scale_factor == 1.0f || |
| 100 static_cast<int>(width() * dip_scale_factor) == bitmap.width()); |
| 101 DCHECK(dip_scale_factor == 1.0f || |
| 102 static_cast<int>(height() * dip_scale_factor) == bitmap.height()); |
98 storage_->AddBitmap(bitmap); | 103 storage_->AddBitmap(bitmap); |
99 } | 104 } |
100 } | 105 } |
101 | 106 |
102 const SkBitmap& ImageSkia::GetBitmapForScale(float x_scale_factor, | 107 const SkBitmap& ImageSkia::GetBitmapForScale(float x_scale_factor, |
103 float y_scale_factor, | 108 float y_scale_factor, |
104 float* bitmap_scale_factor) const { | 109 float* bitmap_scale_factor) const { |
105 | 110 |
106 if (empty()) | 111 if (empty()) |
107 return *null_bitmap_; | 112 return *null_bitmap_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 storage_ = NULL; | 183 storage_ = NULL; |
179 return; | 184 return; |
180 } | 185 } |
181 storage_ = new internal::ImageSkiaStorage(); | 186 storage_ = new internal::ImageSkiaStorage(); |
182 storage_->set_size(gfx::Size(static_cast<int>(bitmap.width() / scale_factor), | 187 storage_->set_size(gfx::Size(static_cast<int>(bitmap.width() / scale_factor), |
183 static_cast<int>(bitmap.height() / scale_factor))); | 188 static_cast<int>(bitmap.height() / scale_factor))); |
184 storage_->AddBitmap(bitmap); | 189 storage_->AddBitmap(bitmap); |
185 } | 190 } |
186 | 191 |
187 } // namespace gfx | 192 } // namespace gfx |
OLD | NEW |