1 // Copyright 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 "cc/test/skia_common.h"
7 #include "cc/resources/picture.h"
8 #include "skia/ext/refptr.h"
9 #include "third_party/skia/include/core/SkBitmapDevice.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/skia_util.h"
15 TestPixelRef::TestPixelRef(int width, int height)
16 : pixels_(new char[4 * width * height]) {}
18 TestPixelRef::~TestPixelRef() {}
20 SkFlattenable::Factory TestPixelRef::getFactory() const { return NULL; }
22 void* TestPixelRef::onLockPixels(SkColorTable** color_table) {
26 SkPixelRef* TestPixelRef::deepCopy(
27 SkBitmap::Config config,
28 const SkIRect* subset) {
34 TestLazyPixelRef::TestLazyPixelRef(int width, int height)
35 : pixels_(new char[4 * width * height]) {}
37 TestLazyPixelRef::~TestLazyPixelRef() {}
39 SkFlattenable::Factory TestLazyPixelRef::getFactory() const { return NULL; }
41 void* TestLazyPixelRef::onLockPixels(SkColorTable** color_table) {
45 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) {
49 bool TestLazyPixelRef::MaybeDecoded() {
53 SkPixelRef* TestLazyPixelRef::deepCopy(
54 SkBitmap::Config config,
55 const SkIRect* subset) {
60 void DrawPicture(unsigned char* buffer,
62 scoped_refptr<Picture> picture) {
64 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
67 bitmap.setPixels(buffer);
68 SkBitmapDevice device(bitmap);
69 SkCanvas canvas(&device);
70 canvas.clipRect(gfx::RectToSkRect(layer_rect));
71 picture->Raster(&canvas, NULL, layer_rect, 1.0f);
74 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) {
75 skia::RefPtr<TestLazyPixelRef> lazy_pixel_ref =
76 skia::AdoptRef(new TestLazyPixelRef(size.width(), size.height()));
77 lazy_pixel_ref->setURI(uri);
79 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
82 bitmap->setPixelRef(lazy_pixel_ref.get());