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_rep.h" | 5 #include "ui/gfx/image/image_skia_rep.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace gfx { | 9 namespace gfx { |
10 | 10 |
11 ImageSkiaRep::ImageSkiaRep() : scale_(0.0f) { | 11 ImageSkiaRep::ImageSkiaRep() : scale_(0.0f) { |
12 } | 12 } |
13 | 13 |
14 ImageSkiaRep::~ImageSkiaRep() { | 14 ImageSkiaRep::~ImageSkiaRep() { |
15 } | 15 } |
16 | 16 |
17 ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) { | 17 ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) { |
18 bitmap_.setConfig(SkBitmap::kARGB_8888_Config, | 18 bitmap_.allocN32Pixels(static_cast<int>(size.width() * this->scale()), |
19 static_cast<int>(size.width() * this->scale()), | 19 static_cast<int>(size.height() * this->scale())); |
20 static_cast<int>(size.height() * this->scale())); | |
21 bitmap_.allocPixels(); | |
22 bitmap_.eraseColor(SK_ColorRED); | 20 bitmap_.eraseColor(SK_ColorRED); |
23 } | 21 } |
24 | 22 |
25 ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale) | 23 ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale) |
26 : bitmap_(src), | 24 : bitmap_(src), |
27 scale_(scale) { | 25 scale_(scale) { |
28 } | 26 } |
29 | 27 |
30 int ImageSkiaRep::GetWidth() const { | 28 int ImageSkiaRep::GetWidth() const { |
31 return static_cast<int>(bitmap_.width() / scale()); | 29 return static_cast<int>(bitmap_.width() / scale()); |
32 } | 30 } |
33 | 31 |
34 int ImageSkiaRep::GetHeight() const { | 32 int ImageSkiaRep::GetHeight() const { |
35 return static_cast<int>(bitmap_.height() / scale()); | 33 return static_cast<int>(bitmap_.height() / scale()); |
36 } | 34 } |
37 | 35 |
38 void ImageSkiaRep::SetScaled() { | 36 void ImageSkiaRep::SetScaled() { |
39 DCHECK_EQ(0.0f, scale_); | 37 DCHECK_EQ(0.0f, scale_); |
40 if (scale_ == 0.0f) | 38 if (scale_ == 0.0f) |
41 scale_ = 1.0f; | 39 scale_ = 1.0f; |
42 } | 40 } |
43 | 41 |
44 } // namespace gfx | 42 } // namespace gfx |
OLD | NEW |