Update V8 to version 4.7.21.
[chromium-blink-merge.git] / cc / test / skia_common.cc
bloba25df8d4ffb36d9523df5a4127e743a0e5b680ab
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/playback/display_item_list.h"
8 #include "cc/playback/picture.h"
9 #include "skia/ext/refptr.h"
10 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/core/SkImageGenerator.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/skia_util.h"
15 namespace cc {
17 namespace {
19 class TestImageGenerator : public SkImageGenerator {
20 public:
21 explicit TestImageGenerator(const SkImageInfo& info)
22 : SkImageGenerator(info) {}
25 } // anonymous namespace
27 void DrawPicture(unsigned char* buffer,
28 const gfx::Rect& layer_rect,
29 scoped_refptr<Picture> picture) {
30 SkImageInfo info =
31 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
32 SkBitmap bitmap;
33 bitmap.installPixels(info, buffer, info.minRowBytes());
34 SkCanvas canvas(bitmap);
35 canvas.clipRect(gfx::RectToSkRect(layer_rect));
36 // We're drawing the entire canvas, so the negated content region is empty.
37 gfx::Rect negated_content_region;
38 picture->Raster(&canvas, NULL, negated_content_region, 1.0f);
41 void DrawDisplayList(unsigned char* buffer,
42 const gfx::Rect& layer_rect,
43 scoped_refptr<DisplayItemList> list) {
44 SkImageInfo info =
45 SkImageInfo::MakeN32Premul(layer_rect.width(), layer_rect.height());
46 SkBitmap bitmap;
47 bitmap.installPixels(info, buffer, info.minRowBytes());
48 SkCanvas canvas(bitmap);
49 canvas.clipRect(gfx::RectToSkRect(layer_rect));
50 list->Raster(&canvas, NULL, gfx::Rect(), 1.0f);
53 void CreateDiscardableBitmap(const gfx::Size& size, SkBitmap* bitmap) {
54 const SkImageInfo info =
55 SkImageInfo::MakeN32Premul(size.width(), size.height());
56 SkInstallDiscardablePixelRef(new TestImageGenerator(info), bitmap);
59 } // namespace cc