blob: 37ec32fa745d7ecfbce6f43c2cd017dc9a3347e7 [file] [log] [blame]
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkPath.h"
11#include "SkSurface.h"
12#include "SkPicture.h"
13
14static void draw_content(SkCanvas* canvas) {
15 SkImageInfo info = canvas->imageInfo();
16 SkPaint paint;
17 paint.setAntiAlias(true);
18 canvas->drawCircle(SkScalarHalf(info.width()), SkScalarHalf(info.height()),
19 SkScalarHalf(info.width()), paint);
20}
21
22class PeekPixelsGM : public skiagm::GM {
23public:
24 PeekPixelsGM() {}
25
26protected:
mtklein36352bf2015-03-25 18:17:31 -070027 SkString onShortName() override {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000028 return SkString("peekpixels");
29 }
30
mtklein36352bf2015-03-25 18:17:31 -070031 SkISize onISize() override {
commit-bot@chromium.org5d0b1502014-04-14 15:02:19 +000032 return SkISize::Make(360, 120);
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000033 }
34
mtklein36352bf2015-03-25 18:17:31 -070035 void onDraw(SkCanvas* canvas) override {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000036 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
37 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
38 if (surface.get()) {
39 SkCanvas* surfCanvas = surface->getCanvas();
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +000040
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000041 draw_content(surfCanvas);
42 SkBitmap bitmap;
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +000043
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000044 // test peekPixels
45 {
46 SkImageInfo info;
47 size_t rowBytes;
48 const void* addr = surfCanvas->peekPixels(&info, &rowBytes);
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +000049 if (addr && bitmap.installPixels(info, const_cast<void*>(addr), rowBytes)) {
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000050 canvas->drawBitmap(bitmap, 0, 0, NULL);
51 }
52 }
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +000053
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000054 // test ROCanvasPixels
55 canvas->translate(120, 0);
56 SkAutoROCanvasPixels ropixels(surfCanvas);
57 if (ropixels.asROBitmap(&bitmap)) {
58 canvas->drawBitmap(bitmap, 0, 0, NULL);
59 }
skia.committer@gmail.com02d6f542014-02-14 03:02:05 +000060
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000061 // test Surface
62 canvas->translate(120, 0);
63 surface->draw(canvas, 0, 0, NULL);
64 }
65 }
66
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +000067private:
68 typedef skiagm::GM INHERITED;
69};
70
71DEF_GM( return SkNEW(PeekPixelsGM); )