commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | static 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 | |
| 22 | class PeekPixelsGM : public skiagm::GM { |
| 23 | public: |
| 24 | PeekPixelsGM() {} |
| 25 | |
| 26 | protected: |
| 27 | virtual SkString onShortName() SK_OVERRIDE { |
| 28 | return SkString("peekpixels"); |
| 29 | } |
| 30 | |
| 31 | virtual SkISize onISize() SK_OVERRIDE { |
commit-bot@chromium.org | 5d0b150 | 2014-04-14 15:02:19 +0000 | [diff] [blame] | 32 | return SkISize::Make(360, 120); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 36 | 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.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 40 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 41 | draw_content(surfCanvas); |
| 42 | SkBitmap bitmap; |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 43 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 44 | // test peekPixels |
| 45 | { |
| 46 | SkImageInfo info; |
| 47 | size_t rowBytes; |
| 48 | const void* addr = surfCanvas->peekPixels(&info, &rowBytes); |
| 49 | if (addr && bitmap.installPixels(info, const_cast<void*>(addr), |
| 50 | rowBytes, NULL, NULL)) { |
| 51 | canvas->drawBitmap(bitmap, 0, 0, NULL); |
| 52 | } |
| 53 | } |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 54 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 55 | // test ROCanvasPixels |
| 56 | canvas->translate(120, 0); |
| 57 | SkAutoROCanvasPixels ropixels(surfCanvas); |
| 58 | if (ropixels.asROBitmap(&bitmap)) { |
| 59 | canvas->drawBitmap(bitmap, 0, 0, NULL); |
| 60 | } |
skia.committer@gmail.com | 02d6f54 | 2014-02-14 03:02:05 +0000 | [diff] [blame] | 61 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 62 | // test Surface |
| 63 | canvas->translate(120, 0); |
| 64 | surface->draw(canvas, 0, 0, NULL); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | virtual uint32_t onGetFlags() const { |
| 69 | // we explicitly test peekPixels and readPixels, neither of which |
| 70 | // return something for a picture-backed canvas, so we skip that test. |
| 71 | return kSkipPicture_Flag; |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | typedef skiagm::GM INHERITED; |
| 76 | }; |
| 77 | |
| 78 | DEF_GM( return SkNEW(PeekPixelsGM); ) |