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

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

Issue 11028064: Resize images for hi-dpi based on a custom PNG chunk added by GRIT r78, and roll GRIT r78 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: back out libpng/PNGCodec changes, scan for special chunks by hand (and rebase) Created 8 years, 2 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // information. 51 // information.
52 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage>, 52 class ImageSkiaStorage : public base::RefCounted<ImageSkiaStorage>,
53 public base::NonThreadSafe { 53 public base::NonThreadSafe {
54 public: 54 public:
55 ImageSkiaStorage(ImageSkiaSource* source, const gfx::Size& size) 55 ImageSkiaStorage(ImageSkiaSource* source, const gfx::Size& size)
56 : source_(source), 56 : source_(source),
57 size_(size), 57 size_(size),
58 read_only_(false) { 58 read_only_(false) {
59 } 59 }
60 60
61 ImageSkiaStorage(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
62 : source_(source),
63 read_only_(false) {
64 const ImageSkiaRep& image = *FindRepresentation(scale_factor, true);
65 if (image.is_null())
66 source_.reset();
67 else
68 size_.SetSize(image.GetWidth(), image.GetHeight());
69 }
70
61 bool has_source() const { return source_.get() != NULL; } 71 bool has_source() const { return source_.get() != NULL; }
62 72
63 std::vector<gfx::ImageSkiaRep>& image_reps() { return image_reps_; } 73 std::vector<gfx::ImageSkiaRep>& image_reps() { return image_reps_; }
64 74
65 const gfx::Size& size() const { return size_; } 75 const gfx::Size& size() const { return size_; }
66 76
67 bool read_only() const { return read_only_; } 77 bool read_only() const { return read_only_; }
68 78
69 void DeleteSource() { 79 void DeleteSource() {
70 source_.reset(); 80 source_.reset();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Don't blow up even if someone else deleted the ImageSkia. 165 // Don't blow up even if someone else deleted the ImageSkia.
156 DetachFromThread(); 166 DetachFromThread();
157 } 167 }
158 168
159 // Vector of bitmaps and their associated scale factor. 169 // Vector of bitmaps and their associated scale factor.
160 std::vector<gfx::ImageSkiaRep> image_reps_; 170 std::vector<gfx::ImageSkiaRep> image_reps_;
161 171
162 scoped_ptr<ImageSkiaSource> source_; 172 scoped_ptr<ImageSkiaSource> source_;
163 173
164 // Size of the image in DIP. 174 // Size of the image in DIP.
165 const gfx::Size size_; 175 gfx::Size size_;
166 176
167 bool read_only_; 177 bool read_only_;
168 178
169 friend class base::RefCounted<ImageSkiaStorage>; 179 friend class base::RefCounted<ImageSkiaStorage>;
170 }; 180 };
171 181
172 } // internal 182 } // internal
173 183
174 ImageSkia::ImageSkia() : storage_(NULL) { 184 ImageSkia::ImageSkia() : storage_(NULL) {
175 } 185 }
176 186
177 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) 187 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size)
178 : storage_(new internal::ImageSkiaStorage(source, size)) { 188 : storage_(new internal::ImageSkiaStorage(source, size)) {
179 DCHECK(source); 189 DCHECK(source);
180 // No other thread has reference to this, so it's safe to detach the thread. 190 // No other thread has reference to this, so it's safe to detach the thread.
181 DetachStorageFromThread(); 191 DetachStorageFromThread();
182 } 192 }
183 193
194 ImageSkia::ImageSkia(ImageSkiaSource* source, ui::ScaleFactor scale_factor)
195 : storage_(new internal::ImageSkiaStorage(source, scale_factor)) {
196 DCHECK(source);
197 if (!storage_->has_source())
198 storage_ = NULL;
199 // No other thread has reference to this, so it's safe to detach the thread.
200 DetachStorageFromThread();
201 }
202
184 ImageSkia::ImageSkia(const SkBitmap& bitmap) { 203 ImageSkia::ImageSkia(const SkBitmap& bitmap) {
185 Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); 204 Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P));
186 // No other thread has reference to this, so it's safe to detach the thread. 205 // No other thread has reference to this, so it's safe to detach the thread.
187 DetachStorageFromThread(); 206 DetachStorageFromThread();
188 } 207 }
189 208
190 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { 209 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) {
191 Init(image_rep); 210 Init(image_rep);
192 // No other thread has reference to this, so it's safe to detach the thread. 211 // No other thread has reference to this, so it's safe to detach the thread.
193 DetachStorageFromThread(); 212 DetachStorageFromThread();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 bool ImageSkia::CanModify() const { 401 bool ImageSkia::CanModify() const {
383 return !storage_ || storage_->CanModify(); 402 return !storage_ || storage_->CanModify();
384 } 403 }
385 404
386 void ImageSkia::DetachStorageFromThread() { 405 void ImageSkia::DetachStorageFromThread() {
387 if (storage_) 406 if (storage_)
388 storage_->DetachFromThread(); 407 storage_->DetachFromThread();
389 } 408 }
390 409
391 } // namespace gfx 410 } // namespace gfx
OLDNEW
« ui/base/resource/resource_bundle.cc ('K') | « ui/gfx/image/image_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698