Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / gfx / image / image_skia_rep.cc
bloba3f9b472d0444dad011d929095246a1e5ff27833
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
3 // found in the LICENSE file.
5 #include "ui/gfx/image/image_skia_rep.h"
7 #include "base/logging.h"
9 namespace gfx {
11 ImageSkiaRep::ImageSkiaRep() : scale_(0.0f) {
14 ImageSkiaRep::~ImageSkiaRep() {
17 ImageSkiaRep::ImageSkiaRep(const gfx::Size& size, float scale) : scale_(scale) {
18 bitmap_.allocN32Pixels(static_cast<int>(size.width() * this->scale()),
19 static_cast<int>(size.height() * this->scale()));
20 bitmap_.eraseColor(SK_ColorRED);
21 bitmap_.setImmutable();
24 ImageSkiaRep::ImageSkiaRep(const SkBitmap& src, float scale)
25 : bitmap_(src),
26 scale_(scale) {
27 bitmap_.setImmutable();
30 int ImageSkiaRep::GetWidth() const {
31 return static_cast<int>(bitmap_.width() / scale());
34 int ImageSkiaRep::GetHeight() const {
35 return static_cast<int>(bitmap_.height() / scale());
38 void ImageSkiaRep::SetScaled() {
39 DCHECK_EQ(0.0f, scale_);
40 if (scale_ == 0.0f)
41 scale_ = 1.0f;
44 } // namespace gfx