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(const SkImageInfo
& info
)
16 : SkPixelRef(info
), pixels_(new char[4 * info
.fWidth
* info
.fHeight
]) {}
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(const SkImageInfo
& info
)
35 : skia::LazyPixelRef(info
),
36 pixels_(new char[4 * info
.fWidth
* info
.fHeight
]) {}
38 TestLazyPixelRef::~TestLazyPixelRef() {}
40 SkFlattenable::Factory
TestLazyPixelRef::getFactory() const { return NULL
; }
42 void* TestLazyPixelRef::onLockPixels(SkColorTable
** color_table
) {
46 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams
& params
) {
50 bool TestLazyPixelRef::MaybeDecoded() {
54 SkPixelRef
* TestLazyPixelRef::deepCopy(
55 SkBitmap::Config config
,
56 const SkIRect
* subset
) {
61 void DrawPicture(unsigned char* buffer
,
63 scoped_refptr
<Picture
> picture
) {
65 bitmap
.setConfig(SkBitmap::kARGB_8888_Config
,
68 bitmap
.setPixels(buffer
);
69 SkBitmapDevice
device(bitmap
);
70 SkCanvas
canvas(&device
);
71 canvas
.clipRect(gfx::RectToSkRect(layer_rect
));
72 picture
->Raster(&canvas
, NULL
, layer_rect
, 1.0f
);
75 void CreateBitmap(gfx::Size size
, const char* uri
, SkBitmap
* bitmap
) {
83 skia::RefPtr
<TestLazyPixelRef
> lazy_pixel_ref
=
84 skia::AdoptRef(new TestLazyPixelRef(info
));
85 lazy_pixel_ref
->setURI(uri
);
87 bitmap
->setConfig(info
);
88 bitmap
->setPixelRef(lazy_pixel_ref
.get());