2014-02-13 17:14:46 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-02-13 17:14:46 +00:00
|
|
|
return SkString("peekpixels");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-04-14 15:02:19 +00:00
|
|
|
return SkISize::Make(360, 120);
|
2014-02-13 17:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-02-13 17:14:46 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
|
|
|
|
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
|
|
|
|
if (surface.get()) {
|
|
|
|
SkCanvas* surfCanvas = surface->getCanvas();
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
draw_content(surfCanvas);
|
|
|
|
SkBitmap bitmap;
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
// test peekPixels
|
|
|
|
{
|
|
|
|
SkImageInfo info;
|
|
|
|
size_t rowBytes;
|
|
|
|
const void* addr = surfCanvas->peekPixels(&info, &rowBytes);
|
2014-05-29 15:57:20 +00:00
|
|
|
if (addr && bitmap.installPixels(info, const_cast<void*>(addr), rowBytes)) {
|
2014-02-13 17:14:46 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
// test ROCanvasPixels
|
|
|
|
canvas->translate(120, 0);
|
|
|
|
SkAutoROCanvasPixels ropixels(surfCanvas);
|
|
|
|
if (ropixels.asROBitmap(&bitmap)) {
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0, NULL);
|
|
|
|
}
|
2014-02-14 03:02:05 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
// test Surface
|
|
|
|
canvas->translate(120, 0);
|
|
|
|
surface->draw(canvas, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new PeekPixelsGM;)
|