2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkSurface.h"
12 #include "SkPicture.h"
14 static void draw_content(SkCanvas* canvas) {
15 SkImageInfo info = canvas->imageInfo();
17 paint.setAntiAlias(true);
18 canvas->drawCircle(SkScalarHalf(info.width()), SkScalarHalf(info.height()),
19 SkScalarHalf(info.width()), paint);
22 class PeekPixelsGM : public skiagm::GM {
27 SkString onShortName() override {
28 return SkString("peekpixels");
31 SkISize onISize() override {
32 return SkISize::Make(360, 120);
35 void onDraw(SkCanvas* canvas) override {
36 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
37 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
39 SkCanvas* surfCanvas = surface->getCanvas();
41 draw_content(surfCanvas);
48 const void* addr = surfCanvas->peekPixels(&info, &rowBytes);
49 if (addr && bitmap.installPixels(info, const_cast<void*>(addr), rowBytes)) {
50 canvas->drawBitmap(bitmap, 0, 0, NULL);
54 // test ROCanvasPixels
55 canvas->translate(120, 0);
56 SkAutoROCanvasPixels ropixels(surfCanvas);
57 if (ropixels.asROBitmap(&bitmap)) {
58 canvas->drawBitmap(bitmap, 0, 0, NULL);
62 canvas->translate(120, 0);
63 surface->draw(canvas, 0, 0, NULL);
68 typedef skiagm::GM INHERITED;
71 DEF_GM( return SkNEW(PeekPixelsGM); )