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