Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / gfx / image / image_png_rep.cc
blob253a5291afde3d49da42e9cc138efdb48317f5b1
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_png_rep.h"
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "ui/gfx/codec/png_codec.h"
9 #include "ui/gfx/size.h"
11 namespace gfx {
13 ImagePNGRep::ImagePNGRep()
14 : raw_data(NULL),
15 scale_factor(ui::SCALE_FACTOR_NONE) {
18 ImagePNGRep::ImagePNGRep(const scoped_refptr<base::RefCountedMemory>& data,
19 ui::ScaleFactor data_scale_factor)
20 : raw_data(data),
21 scale_factor(data_scale_factor) {
24 ImagePNGRep::~ImagePNGRep() {
27 gfx::Size ImagePNGRep::Size() const {
28 // The only way to get the width and height of a raw PNG stream, at least
29 // using the gfx::PNGCodec API, is to decode the whole thing.
30 CHECK(raw_data.get());
31 SkBitmap bitmap;
32 if (!gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
33 &bitmap)) {
34 LOG(ERROR) << "Unable to decode PNG.";
35 return gfx::Size(0, 0);
37 return gfx::Size(bitmap.width(), bitmap.height());
40 } // namespace gfx