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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ImageSkia& ImageSkia::operator=(const ImageSkia& other) { | 158 ImageSkia& ImageSkia::operator=(const ImageSkia& other) { |
159 storage_ = other.storage_; | 159 storage_ = other.storage_; |
160 return *this; | 160 return *this; |
161 } | 161 } |
162 | 162 |
163 ImageSkia& ImageSkia::operator=(const SkBitmap& other) { | 163 ImageSkia& ImageSkia::operator=(const SkBitmap& other) { |
164 Init(ImageSkiaRep(other, ui::SCALE_FACTOR_100P)); | 164 Init(ImageSkiaRep(other, ui::SCALE_FACTOR_100P)); |
165 return *this; | 165 return *this; |
166 } | 166 } |
167 | 167 |
168 ImageSkia::operator SkBitmap&() const { | |
169 if (isNull()) | |
170 return const_cast<SkBitmap&>(NullImageRep().sk_bitmap()); | |
171 | |
172 return const_cast<SkBitmap&>(storage_->image_reps()[0].sk_bitmap()); | |
173 } | |
174 | |
175 ImageSkia::~ImageSkia() { | 168 ImageSkia::~ImageSkia() { |
176 } | 169 } |
177 | 170 |
178 void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) { | 171 void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) { |
179 DCHECK(!image_rep.is_null()); | 172 DCHECK(!image_rep.is_null()); |
180 | 173 |
181 if (isNull()) | 174 if (isNull()) |
182 Init(image_rep); | 175 Init(image_rep); |
183 else | 176 else |
184 storage_->image_reps().push_back(image_rep); | 177 storage_->image_reps().push_back(image_rep); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 ImageSkiaReps image_reps; | 265 ImageSkiaReps image_reps; |
273 for (ImageSkiaReps::iterator it = internal_image_reps.begin(); | 266 for (ImageSkiaReps::iterator it = internal_image_reps.begin(); |
274 it != internal_image_reps.end(); ++it) { | 267 it != internal_image_reps.end(); ++it) { |
275 if (!it->is_null()) | 268 if (!it->is_null()) |
276 image_reps.push_back(*it); | 269 image_reps.push_back(*it); |
277 } | 270 } |
278 | 271 |
279 return image_reps; | 272 return image_reps; |
280 } | 273 } |
281 | 274 |
282 const SkBitmap* ImageSkia::bitmap() const { | 275 ImageSkia::operator SkBitmap&() const { |
283 if (isNull()) { | 276 if (isNull()) { |
284 // Callers expect a ImageSkiaRep even if it is |isNull()|. | 277 // Callers expect a ImageSkiaRep even if it is |isNull()|. |
285 // TODO(pkotwicz): Fix this. | 278 // TODO(pkotwicz): Fix this. |
286 return &NullImageRep().sk_bitmap(); | 279 return NullImageRep().mutable_sk_bitmap(); |
287 } | 280 } |
288 | 281 |
289 ImageSkiaReps::iterator it = | 282 ImageSkiaReps::iterator it = |
290 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true); | 283 storage_->FindRepresentation(ui::SCALE_FACTOR_100P, true); |
291 return &it->sk_bitmap(); | 284 if (it != storage_->image_reps().end()) |
| 285 return it->mutable_sk_bitmap(); |
| 286 return NullImageRep().mutable_sk_bitmap(); |
292 } | 287 } |
293 | 288 |
294 void ImageSkia::Init(const ImageSkiaRep& image_rep) { | 289 void ImageSkia::Init(const ImageSkiaRep& image_rep) { |
295 // TODO(pkotwicz): The image should be null whenever image rep is null. | 290 // TODO(pkotwicz): The image should be null whenever image rep is null. |
296 if (image_rep.sk_bitmap().empty()) { | 291 if (image_rep.sk_bitmap().empty()) { |
297 storage_ = NULL; | 292 storage_ = NULL; |
298 return; | 293 return; |
299 } | 294 } |
300 storage_ = new internal::ImageSkiaStorage( | 295 storage_ = new internal::ImageSkiaStorage( |
301 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); | 296 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); |
302 storage_->image_reps().push_back(image_rep); | 297 storage_->image_reps().push_back(image_rep); |
303 } | 298 } |
304 | 299 |
305 } // namespace gfx | 300 } // namespace gfx |
OLD | NEW |