cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / cc / test / skia_common.cc
blob67c72f47c3bce4ec58ebadf6f849715120bee198
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"
13 namespace cc {
15 TestPixelRef::TestPixelRef(int width, int height)
16 : pixels_(new char[4 * width * height]) {}
18 TestPixelRef::~TestPixelRef() {}
20 SkFlattenable::Factory TestPixelRef::getFactory() { return NULL; }
22 void* TestPixelRef::onLockPixels(SkColorTable** color_table) {
23 return pixels_.get();
26 SkPixelRef* TestPixelRef::deepCopy(
27 SkBitmap::Config config,
28 const SkIRect* subset) {
29 this->ref();
30 return this;
34 TestLazyPixelRef::TestLazyPixelRef(int width, int height)
35 : pixels_(new char[4 * width * height]) {}
37 TestLazyPixelRef::~TestLazyPixelRef() {}
39 SkFlattenable::Factory TestLazyPixelRef::getFactory() { return NULL; }
41 void* TestLazyPixelRef::onLockPixels(SkColorTable** color_table) {
42 return pixels_.get();
45 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) {
46 return true;
49 bool TestLazyPixelRef::MaybeDecoded() {
50 return true;
53 SkPixelRef* TestLazyPixelRef::deepCopy(
54 SkBitmap::Config config,
55 const SkIRect* subset) {
56 this->ref();
57 return this;
60 void DrawPicture(unsigned char* buffer,
61 gfx::Rect layer_rect,
62 scoped_refptr<Picture> picture) {
63 SkBitmap bitmap;
64 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
65 layer_rect.width(),
66 layer_rect.height());
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,
80 size.width(),
81 size.height());
82 bitmap->setPixelRef(lazy_pixel_ref.get());
86 } // namespace cc