Update InfoBarUtil to use TouchCommon over TestTouchUtils.
[chromium-blink-merge.git] / cc / test / skia_common.cc
blobd8d61a85b9b1d4f8a6ee27acf486f5c1f2fe8417
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(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) {
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(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) {
43 return pixels_.get();
46 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) {
47 return true;
50 bool TestLazyPixelRef::MaybeDecoded() {
51 return true;
54 SkPixelRef* TestLazyPixelRef::deepCopy(
55 SkBitmap::Config config,
56 const SkIRect* subset) {
57 this->ref();
58 return this;
61 void DrawPicture(unsigned char* buffer,
62 gfx::Rect layer_rect,
63 scoped_refptr<Picture> picture) {
64 SkBitmap bitmap;
65 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
66 layer_rect.width(),
67 layer_rect.height());
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) {
76 SkImageInfo info = {
77 size.width(),
78 size.height(),
79 kPMColor_SkColorType,
80 kPremul_SkAlphaType
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());
92 } // namespace cc