BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / cc / test / skia_common.cc
blobbcb5f1a2500c41e062a248431f66069f2550718b
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 skia::RefPtr<SkImage> CreateDiscardableImage(const gfx::Size& size) {
54 const SkImageInfo info =
55 SkImageInfo::MakeN32Premul(size.width(), size.height());
56 return skia::AdoptRef(
57 SkImage::NewFromGenerator(new TestImageGenerator(info)));
60 } // namespace cc