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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 ImageSkia::ImageSkia() : storage_(NULL) { | 174 ImageSkia::ImageSkia() : storage_(NULL) { |
175 } | 175 } |
176 | 176 |
177 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) | 177 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) |
178 : storage_(new internal::ImageSkiaStorage(source, size)) { | 178 : storage_(new internal::ImageSkiaStorage(source, size)) { |
179 DCHECK(source); | 179 DCHECK(source); |
180 // No other thread has reference to this, so it's safe to detach the thread. | 180 // No other thread has reference to this, so it's safe to detach the thread. |
181 DetachStorageFromThread(); | 181 DetachStorageFromThread(); |
182 } | 182 } |
183 | 183 |
184 ImageSkia::ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor) { | |
185 DCHECK(source); | |
186 ImageSkiaRep image = source->GetImageForScale(scale_factor); | |
187 if (image.is_null()) { | |
188 storage_ = NULL; | |
189 delete source; | |
190 return; | |
191 } | |
192 Size size_in_dip(image.GetWidth(), image.GetHeight()); | |
193 storage_ = new internal::ImageSkiaStorage(source, size_in_dip); | |
oshima
2012/10/10 21:43:29
Can you add new constructor ImageSkiaStorage(sourc
benrg
2012/10/11 01:22:02
Like this? It's a bit awkward because of the failu
| |
194 // No other thread has reference to this, so it's safe to detach the thread. | |
195 DetachStorageFromThread(); | |
oshima
2012/10/10 21:43:29
DetachStorageFromThread should be called after Add
| |
196 AddRepresentation(image); | |
197 } | |
198 | |
184 ImageSkia::ImageSkia(const SkBitmap& bitmap) { | 199 ImageSkia::ImageSkia(const SkBitmap& bitmap) { |
185 Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); | 200 Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
186 // No other thread has reference to this, so it's safe to detach the thread. | 201 // No other thread has reference to this, so it's safe to detach the thread. |
187 DetachStorageFromThread(); | 202 DetachStorageFromThread(); |
188 } | 203 } |
189 | 204 |
190 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { | 205 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { |
191 Init(image_rep); | 206 Init(image_rep); |
192 // No other thread has reference to this, so it's safe to detach the thread. | 207 // No other thread has reference to this, so it's safe to detach the thread. |
193 DetachStorageFromThread(); | 208 DetachStorageFromThread(); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 bool ImageSkia::CanModify() const { | 397 bool ImageSkia::CanModify() const { |
383 return !storage_ || storage_->CanModify(); | 398 return !storage_ || storage_->CanModify(); |
384 } | 399 } |
385 | 400 |
386 void ImageSkia::DetachStorageFromThread() { | 401 void ImageSkia::DetachStorageFromThread() { |
387 if (storage_) | 402 if (storage_) |
388 storage_->DetachFromThread(); | 403 storage_->DetachFromThread(); |
389 } | 404 } |
390 | 405 |
391 } // namespace gfx | 406 } // namespace gfx |
OLD | NEW |