diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-13 15:11:11 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-02-13 15:11:11 +0000 |
commit | b2d93a91222dac2edb3c19128fd58fa2e74272aa (patch) | |
tree | 542e5234ce9408bb85fe36ae131746376eb3ae53 /gm/peekpixels.cpp | |
parent | deee496cd30070e52556dcb538c2e5eb39b66b81 (diff) |
add peekPixels to SkCanvas and SkSurface
clone of https://codereview.chromium.org/159723006/
Review URL: https://codereview.chromium.org/161733002
git-svn-id: http://skia.googlecode.com/svn/trunk@13427 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/peekpixels.cpp')
-rw-r--r-- | gm/peekpixels.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/gm/peekpixels.cpp b/gm/peekpixels.cpp new file mode 100644 index 0000000000..c6744d3abe --- /dev/null +++ b/gm/peekpixels.cpp @@ -0,0 +1,78 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkCanvas.h" +#include "SkPath.h" +#include "SkSurface.h" +#include "SkPicture.h" + +static void draw_content(SkCanvas* canvas) { + SkImageInfo info = canvas->imageInfo(); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawCircle(SkScalarHalf(info.width()), SkScalarHalf(info.height()), + SkScalarHalf(info.width()), paint); +} + +class PeekPixelsGM : public skiagm::GM { +public: + PeekPixelsGM() {} + +protected: + virtual SkString onShortName() SK_OVERRIDE { + return SkString("peekpixels"); + } + + virtual SkISize onISize() SK_OVERRIDE { + return SkISize::Make(640, 480); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); + SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); + if (surface.get()) { + SkCanvas* surfCanvas = surface->getCanvas(); + + draw_content(surfCanvas); + SkBitmap bitmap; + + // test peekPixels + { + SkImageInfo info; + size_t rowBytes; + const void* addr = surfCanvas->peekPixels(&info, &rowBytes); + if (addr && bitmap.installPixels(info, const_cast<void*>(addr), + rowBytes, NULL, NULL)) { + canvas->drawBitmap(bitmap, 0, 0, NULL); + } + } + + // test ROCanvasPixels + canvas->translate(120, 0); + SkAutoROCanvasPixels ropixels(surfCanvas); + if (ropixels.asROBitmap(&bitmap)) { + canvas->drawBitmap(bitmap, 0, 0, NULL); + } + + // test Surface + canvas->translate(120, 0); + surface->draw(canvas, 0, 0, NULL); + } + } + + virtual uint32_t onGetFlags() const { + // we explicitly test peekPixels and readPixels, neither of which + // return something for a picture-backed canvas, so we skip that test. + return kSkipPicture_Flag; + } + +private: + typedef skiagm::GM INHERITED; +}; + +DEF_GM( return SkNEW(PeekPixelsGM); ) |