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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 ImageSkia::ImageSkia() : storage_(NULL) { | 135 ImageSkia::ImageSkia() : storage_(NULL) { |
136 } | 136 } |
137 | 137 |
138 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) | 138 ImageSkia::ImageSkia(ImageSkiaSource* source, const gfx::Size& size) |
139 : storage_(new internal::ImageSkiaStorage(source, size)) { | 139 : storage_(new internal::ImageSkiaStorage(source, size)) { |
140 DCHECK(source); | 140 DCHECK(source); |
141 } | 141 } |
142 | 142 |
143 ImageSkia::ImageSkia(const SkBitmap& bitmap) { | 143 ImageSkia::ImageSkia(const SkBitmap& bitmap) { |
144 Init(ImageSkiaRep(bitmap)); | 144 Init(ImageSkiaRep(bitmap, ui::SCALE_FACTOR_100P)); |
145 } | 145 } |
146 | 146 |
147 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { | 147 ImageSkia::ImageSkia(const ImageSkiaRep& image_rep) { |
148 Init(image_rep); | 148 Init(image_rep); |
149 } | 149 } |
150 | 150 |
151 ImageSkia::ImageSkia(const ImageSkia& other) : storage_(other.storage_) { | 151 ImageSkia::ImageSkia(const ImageSkia& other) : storage_(other.storage_) { |
152 } | 152 } |
153 | 153 |
154 ImageSkia& ImageSkia::operator=(const ImageSkia& other) { | 154 ImageSkia& ImageSkia::operator=(const ImageSkia& other) { |
155 storage_ = other.storage_; | 155 storage_ = other.storage_; |
156 return *this; | 156 return *this; |
157 } | 157 } |
158 | 158 |
159 ImageSkia& ImageSkia::operator=(const SkBitmap& other) { | 159 ImageSkia& ImageSkia::operator=(const SkBitmap& other) { |
160 Init(ImageSkiaRep(other)); | 160 Init(ImageSkiaRep(other, ui::SCALE_FACTOR_100P)); |
161 return *this; | 161 return *this; |
162 } | 162 } |
163 | 163 |
164 ImageSkia& ImageSkia::operator=(const ImageSkiaRep& other) { | |
165 Init(other); | |
166 return *this; | |
167 } | |
168 | |
169 ImageSkia::operator SkBitmap&() const { | 164 ImageSkia::operator SkBitmap&() const { |
170 if (isNull()) | 165 if (isNull()) |
171 return const_cast<SkBitmap&>(NullImageRep().sk_bitmap()); | 166 return const_cast<SkBitmap&>(NullImageRep().sk_bitmap()); |
172 | 167 |
173 return const_cast<SkBitmap&>(storage_->image_reps()[0].sk_bitmap()); | 168 return const_cast<SkBitmap&>(storage_->image_reps()[0].sk_bitmap()); |
174 } | 169 } |
175 | 170 |
176 ImageSkia::operator ImageSkiaRep&() const { | |
177 if (isNull()) | |
178 return NullImageRep(); | |
179 | |
180 return storage_->image_reps()[0]; | |
181 } | |
182 | |
183 ImageSkia::~ImageSkia() { | 171 ImageSkia::~ImageSkia() { |
184 } | 172 } |
185 | 173 |
186 void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) { | 174 void ImageSkia::AddRepresentation(const ImageSkiaRep& image_rep) { |
187 DCHECK(!image_rep.is_null()); | 175 DCHECK(!image_rep.is_null()); |
188 | 176 |
189 if (isNull()) | 177 if (isNull()) |
190 Init(image_rep); | 178 Init(image_rep); |
191 else | 179 else |
192 storage_->image_reps().push_back(image_rep); | 180 storage_->image_reps().push_back(image_rep); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 if (image_rep.sk_bitmap().empty()) { | 278 if (image_rep.sk_bitmap().empty()) { |
291 storage_ = NULL; | 279 storage_ = NULL; |
292 return; | 280 return; |
293 } | 281 } |
294 storage_ = new internal::ImageSkiaStorage( | 282 storage_ = new internal::ImageSkiaStorage( |
295 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); | 283 NULL, gfx::Size(image_rep.GetWidth(), image_rep.GetHeight())); |
296 storage_->image_reps().push_back(image_rep); | 284 storage_->image_reps().push_back(image_rep); |
297 } | 285 } |
298 | 286 |
299 } // namespace gfx | 287 } // namespace gfx |
OLD | NEW |