2014-08-21 20:12:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkMultiPictureDraw.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kRoot3Over2 = 0.86602545f; // sin(60)
|
|
|
|
constexpr SkScalar kRoot3 = 1.73205081f;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kHexSide = 30;
|
|
|
|
constexpr int kNumHexX = 6;
|
|
|
|
constexpr int kNumHexY = 6;
|
|
|
|
constexpr int kPicWidth = kNumHexX * kHexSide;
|
|
|
|
constexpr int kPicHeight = (int)((kNumHexY - 0.5f) * 2 * kHexSide * kRoot3Over2 + 0.5f);
|
|
|
|
constexpr SkScalar kInset = 20.0f;
|
|
|
|
constexpr int kNumPictures = 4;
|
2014-09-19 15:56:09 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kTriSide = 40;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
// Create a hexagon centered at (originX, originY)
|
|
|
|
static SkPath make_hex_path(SkScalar originX, SkScalar originY) {
|
|
|
|
SkPath hex;
|
|
|
|
hex.moveTo(originX-kHexSide, originY);
|
|
|
|
hex.rLineTo(SkScalarHalf(kHexSide), kRoot3Over2 * kHexSide);
|
|
|
|
hex.rLineTo(SkIntToScalar(kHexSide), 0);
|
|
|
|
hex.rLineTo(SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2);
|
|
|
|
hex.rLineTo(-SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2);
|
|
|
|
hex.rLineTo(-SkIntToScalar(kHexSide), 0);
|
|
|
|
hex.close();
|
|
|
|
return hex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a picture that is a tiling of the plane with stroked hexagons where
|
|
|
|
// each hexagon is in its own layer. The layers are to exercise Ganesh's
|
|
|
|
// layer hoisting.
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_hex_plane_picture(SkColor fillColor) {
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
// Create a hexagon with its center at the origin
|
|
|
|
SkPath hex = make_hex_path(0, 0);
|
|
|
|
|
|
|
|
SkPaint fill;
|
|
|
|
fill.setStyle(SkPaint::kFill_Style);
|
|
|
|
fill.setColor(fillColor);
|
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(3);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2014-09-24 20:03:30 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(kPicHeight),
|
2016-07-13 20:27:16 +00:00
|
|
|
&bbhFactory);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
SkScalar xPos, yPos = 0;
|
|
|
|
|
|
|
|
for (int y = 0; y < kNumHexY; ++y) {
|
|
|
|
xPos = 0;
|
|
|
|
|
|
|
|
for (int x = 0; x < kNumHexX; ++x) {
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0));
|
|
|
|
canvas->drawPath(hex, fill);
|
|
|
|
canvas->drawPath(hex, stroke);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
xPos += 1.5f * kHexSide;
|
|
|
|
}
|
|
|
|
|
|
|
|
yPos += 2 * kHexSide * kRoot3Over2;
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 15:32:43 +00:00
|
|
|
// Create a picture that consists of a single large layer that is tiled
|
|
|
|
// with hexagons.
|
|
|
|
// This is intended to exercise the layer hoisting code's clip handling (in
|
|
|
|
// tile mode).
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_single_layer_hex_plane_picture() {
|
2014-10-02 15:32:43 +00:00
|
|
|
|
|
|
|
// Create a hexagon with its center at the origin
|
|
|
|
SkPath hex = make_hex_path(0, 0);
|
|
|
|
|
|
|
|
SkPaint whiteFill;
|
|
|
|
whiteFill.setStyle(SkPaint::kFill_Style);
|
|
|
|
whiteFill.setColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint greyFill;
|
|
|
|
greyFill.setStyle(SkPaint::kFill_Style);
|
2015-07-28 17:37:53 +00:00
|
|
|
greyFill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
|
2014-10-02 15:32:43 +00:00
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(3);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-10-02 15:32:43 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kBig = 10000.0f;
|
2016-07-13 20:27:16 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory);
|
2014-10-02 15:32:43 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2014-10-06 18:50:31 +00:00
|
|
|
|
2014-10-02 15:32:43 +00:00
|
|
|
SkScalar xPos = 0.0f, yPos = 0.0f;
|
|
|
|
|
|
|
|
for (int y = 0; yPos < kBig; ++y) {
|
|
|
|
xPos = 0;
|
|
|
|
|
|
|
|
for (int x = 0; xPos < kBig; ++x) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0));
|
|
|
|
// The color of the filled hex is swapped to yield a different
|
|
|
|
// pattern in each tile. This allows an error in layer hoisting (e.g.,
|
|
|
|
// the clip isn't blocking cache reuse) to cause a visual discrepancy.
|
|
|
|
canvas->drawPath(hex, ((x+y) % 3) ? whiteFill : greyFill);
|
|
|
|
canvas->drawPath(hex, stroke);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
xPos += 1.5f * kHexSide;
|
|
|
|
}
|
|
|
|
|
|
|
|
yPos += 2 * kHexSide * kRoot3Over2;
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:50:31 +00:00
|
|
|
canvas->restore();
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2014-10-02 15:32:43 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 15:56:09 +00:00
|
|
|
// Make an equilateral triangle path with its top corner at (originX, originY)
|
|
|
|
static SkPath make_tri_path(SkScalar originX, SkScalar originY) {
|
|
|
|
SkPath tri;
|
|
|
|
tri.moveTo(originX, originY);
|
|
|
|
tri.rLineTo(SkScalarHalf(kTriSide), 1.5f * kTriSide / kRoot3);
|
|
|
|
tri.rLineTo(-kTriSide, 0);
|
|
|
|
tri.close();
|
|
|
|
return tri;
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_tri_picture() {
|
2014-09-29 12:07:39 +00:00
|
|
|
SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0);
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkPaint fill;
|
|
|
|
fill.setStyle(SkPaint::kFill_Style);
|
2015-07-28 17:37:53 +00:00
|
|
|
fill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(3);
|
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(kPicHeight),
|
2016-07-13 20:27:16 +00:00
|
|
|
&bbhFactory);
|
2014-10-03 14:29:20 +00:00
|
|
|
SkRect r = tri.getBounds();
|
|
|
|
r.outset(2.0f, 2.0f); // outset for stroke
|
|
|
|
canvas->clipRect(r);
|
2014-09-19 15:56:09 +00:00
|
|
|
// The saveLayer/restore block is to exercise layer hoisting
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2014-09-19 15:56:09 +00:00
|
|
|
canvas->drawPath(tri, fill);
|
|
|
|
canvas->drawPath(tri, stroke);
|
|
|
|
canvas->restore();
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2014-09-19 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_sub_picture(const SkPicture* tri) {
|
2014-09-19 15:56:09 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(kPicHeight),
|
2016-07-13 20:27:16 +00:00
|
|
|
&bbhFactory);
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
canvas->scale(1.0f/2.0f, 1.0f/2.0f);
|
|
|
|
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkScalarHalf(kTriSide), 0);
|
2014-09-19 15:56:09 +00:00
|
|
|
canvas->drawPicture(tri);
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->restore();
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
canvas->save();
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->translate(SkIntToScalar(kTriSide), 1.5f * kTriSide / kRoot3);
|
2014-09-19 15:56:09 +00:00
|
|
|
canvas->drawPicture(tri);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->translate(0, 1.5f * kTriSide / kRoot3);
|
2014-09-19 15:56:09 +00:00
|
|
|
canvas->drawPicture(tri);
|
|
|
|
canvas->restore();
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2014-09-19 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a Sierpinkski-like picture that starts with a top row with a picture
|
2014-09-24 20:03:30 +00:00
|
|
|
// that just contains a triangle. Subsequent rows take the prior row's picture,
|
2014-09-19 15:56:09 +00:00
|
|
|
// shrinks it and replicates it 3 times then draws and appropriate number of
|
|
|
|
// copies of it.
|
2016-03-18 14:25:55 +00:00
|
|
|
static sk_sp<SkPicture> make_sierpinski_picture() {
|
|
|
|
sk_sp<SkPicture> pic(make_tri_picture());
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(kPicHeight),
|
2016-07-13 20:27:16 +00:00
|
|
|
&bbhFactory);
|
2014-09-19 15:56:09 +00:00
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kNumLevels = 4;
|
2014-09-19 15:56:09 +00:00
|
|
|
for (int i = 0; i < kNumLevels; ++i) {
|
|
|
|
canvas->save();
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f);
|
2014-09-19 15:56:09 +00:00
|
|
|
for (int j = 0; j < i+1; ++j) {
|
|
|
|
canvas->drawPicture(pic);
|
|
|
|
canvas->translate(SkIntToScalar(kTriSide), 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
pic = make_sub_picture(pic.get());
|
2014-09-19 15:56:09 +00:00
|
|
|
|
|
|
|
canvas->translate(0, 1.5f * kTriSide / kRoot3);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
return recorder.finishRecordingAsPicture();
|
2014-09-19 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
static sk_sp<SkSurface> create_compat_surface(SkCanvas* canvas, int width, int height) {
|
2014-08-21 20:12:42 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
|
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface = canvas->makeSurface(info);
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == surface) {
|
|
|
|
// picture canvas returns nullptr so fall back to raster
|
2016-03-24 01:59:25 +00:00
|
|
|
surface = SkSurface::MakeRaster(info);
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This class stores the information required to compose all the result
|
|
|
|
// fragments potentially generated by the MultiPictureDraw object
|
|
|
|
class ComposeStep {
|
|
|
|
public:
|
2016-03-24 01:59:25 +00:00
|
|
|
ComposeStep() : fX(0.0f), fY(0.0f), fPaint(nullptr) { }
|
2015-08-26 20:07:48 +00:00
|
|
|
~ComposeStep() {
|
|
|
|
delete fPaint;
|
|
|
|
}
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2016-03-24 01:59:25 +00:00
|
|
|
sk_sp<SkSurface> fSurf;
|
2014-08-21 20:12:42 +00:00
|
|
|
SkScalar fX;
|
|
|
|
SkScalar fY;
|
|
|
|
SkPaint* fPaint;
|
|
|
|
};
|
|
|
|
|
2014-09-19 15:56:09 +00:00
|
|
|
typedef void (*PFContentMtd)(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
// Just a single picture with no clip
|
2014-09-19 15:56:09 +00:00
|
|
|
static void no_clip(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->drawPicture(pictures[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two pictures with a rect clip on the second one
|
2014-09-19 15:56:09 +00:00
|
|
|
static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->drawPicture(pictures[0]);
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
SkRect rect = pictures[0]->cullRect();
|
2014-08-21 20:12:42 +00:00
|
|
|
rect.inset(kInset, kInset);
|
|
|
|
|
|
|
|
canvas->clipRect(rect);
|
|
|
|
|
|
|
|
canvas->drawPicture(pictures[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two pictures with a round rect clip on the second one
|
2014-09-19 15:56:09 +00:00
|
|
|
static void rrect_clip(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->drawPicture(pictures[0]);
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
SkRect rect = pictures[0]->cullRect();
|
2014-08-21 20:12:42 +00:00
|
|
|
rect.inset(kInset, kInset);
|
2014-09-24 20:03:30 +00:00
|
|
|
|
2014-08-21 20:12:42 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
rrect.setRectXY(rect, kInset, kInset);
|
|
|
|
|
|
|
|
canvas->clipRRect(rrect);
|
|
|
|
|
|
|
|
canvas->drawPicture(pictures[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two pictures with a clip path on the second one
|
2014-09-19 15:56:09 +00:00
|
|
|
static void path_clip(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->drawPicture(pictures[0]);
|
|
|
|
|
|
|
|
// Create a hexagon centered on the middle of the hex grid
|
|
|
|
SkPath hex = make_hex_path((kNumHexX / 2.0f) * kHexSide, kNumHexY * kHexSide * kRoot3Over2);
|
|
|
|
|
|
|
|
canvas->clipPath(hex);
|
|
|
|
|
|
|
|
canvas->drawPicture(pictures[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two pictures with an inverse clip path on the second one
|
2014-09-19 15:56:09 +00:00
|
|
|
static void invpath_clip(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
2014-08-21 20:12:42 +00:00
|
|
|
canvas->drawPicture(pictures[0]);
|
|
|
|
|
|
|
|
// Create a hexagon centered on the middle of the hex grid
|
|
|
|
SkPath hex = make_hex_path((kNumHexX / 2.0f) * kHexSide, kNumHexY * kHexSide * kRoot3Over2);
|
|
|
|
hex.setFillType(SkPath::kInverseEvenOdd_FillType);
|
|
|
|
|
|
|
|
canvas->clipPath(hex);
|
|
|
|
|
|
|
|
canvas->drawPicture(pictures[1]);
|
|
|
|
}
|
|
|
|
|
2014-09-19 15:56:09 +00:00
|
|
|
// Reuse a single base (triangular) picture a _lot_ (rotated, scaled and translated).
|
|
|
|
static void sierpinski(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->drawPicture(pictures[2]);
|
|
|
|
|
|
|
|
canvas->rotate(180.0f);
|
2014-09-29 12:07:39 +00:00
|
|
|
canvas->translate(-SkIntToScalar(kPicWidth), -SkIntToScalar(kPicHeight));
|
2014-09-19 15:56:09 +00:00
|
|
|
canvas->drawPicture(pictures[2]);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2014-10-02 15:32:43 +00:00
|
|
|
static void big_layer(SkCanvas* canvas, const SkPicture* pictures[kNumPictures]) {
|
|
|
|
canvas->drawPicture(pictures[3]);
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr PFContentMtd gContentMthds[] = {
|
2014-08-21 20:12:42 +00:00
|
|
|
no_clip,
|
|
|
|
rect_clip,
|
|
|
|
rrect_clip,
|
|
|
|
path_clip,
|
2014-09-19 15:56:09 +00:00
|
|
|
invpath_clip,
|
2014-10-02 15:32:43 +00:00
|
|
|
sierpinski,
|
|
|
|
big_layer,
|
2014-08-21 20:12:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen,
|
2014-09-19 15:56:09 +00:00
|
|
|
const SkPicture* pictures[kNumPictures],
|
2014-08-21 20:12:42 +00:00
|
|
|
SkCanvas* dest, const SkMatrix& xform) {
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> composite;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkPictureRecorder recorder;
|
2014-11-11 12:54:49 +00:00
|
|
|
SkRTreeFactory bbhFactory;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2014-09-24 20:03:30 +00:00
|
|
|
SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidth),
|
2014-11-11 12:54:49 +00:00
|
|
|
SkIntToScalar(kPicHeight),
|
2016-07-13 20:27:16 +00:00
|
|
|
&bbhFactory);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
(*pfGen)(pictureCanvas, pictures);
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
composite = recorder.finishRecordingAsPicture();
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 14:25:55 +00:00
|
|
|
mpd->add(dest, composite.get(), &xform);
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 20:03:30 +00:00
|
|
|
typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
|
2014-09-19 15:56:09 +00:00
|
|
|
PFContentMtd pfGen, const SkPicture* pictures[kNumPictures],
|
2014-08-21 20:12:42 +00:00
|
|
|
SkTArray<ComposeStep>* composeSteps);
|
|
|
|
|
|
|
|
// Draw the content into a single canvas
|
2014-09-24 20:03:30 +00:00
|
|
|
static void simple(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
|
|
|
|
PFContentMtd pfGen,
|
2014-09-19 15:56:09 +00:00
|
|
|
const SkPicture* pictures[kNumPictures],
|
2014-08-21 20:12:42 +00:00
|
|
|
SkTArray<ComposeStep> *composeSteps) {
|
|
|
|
|
|
|
|
ComposeStep& step = composeSteps->push_back();
|
|
|
|
|
2014-08-21 21:40:36 +00:00
|
|
|
step.fSurf = create_compat_surface(finalCanvas, kPicWidth, kPicHeight);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
SkCanvas* subCanvas = step.fSurf->getCanvas();
|
|
|
|
|
|
|
|
create_content(mpd, pfGen, pictures, subCanvas, SkMatrix::I());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the content into multiple canvases/tiles
|
|
|
|
static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
|
2014-09-24 20:03:30 +00:00
|
|
|
PFContentMtd pfGen,
|
2014-09-19 15:56:09 +00:00
|
|
|
const SkPicture* pictures[kNumPictures],
|
2014-08-21 20:12:42 +00:00
|
|
|
SkTArray<ComposeStep> *composeSteps) {
|
2016-09-01 18:24:54 +00:00
|
|
|
const int kNumTilesX = 2;
|
|
|
|
const int kNumTilesY = 2;
|
|
|
|
const int kTileWidth = kPicWidth / kNumTilesX;
|
|
|
|
const int kTileHeight = kPicHeight / kNumTilesY;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
SkASSERT(kPicWidth == kNumTilesX * kTileWidth);
|
|
|
|
SkASSERT(kPicHeight == kNumTilesY * kTileHeight);
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
const SkColor colors[kNumTilesX][kNumTilesY] = {
|
2014-09-24 20:03:30 +00:00
|
|
|
{ SK_ColorCYAN, SK_ColorMAGENTA },
|
2014-08-21 20:12:42 +00:00
|
|
|
{ SK_ColorYELLOW, SK_ColorGREEN }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int y = 0; y < kNumTilesY; ++y) {
|
|
|
|
for (int x = 0; x < kNumTilesX; ++x) {
|
|
|
|
ComposeStep& step = composeSteps->push_back();
|
|
|
|
|
|
|
|
step.fX = SkIntToScalar(x*kTileWidth);
|
|
|
|
step.fY = SkIntToScalar(y*kTileHeight);
|
2015-08-26 20:07:48 +00:00
|
|
|
step.fPaint = new SkPaint;
|
2014-08-21 20:12:42 +00:00
|
|
|
step.fPaint->setColorFilter(
|
2016-10-28 19:42:34 +00:00
|
|
|
SkColorFilter::MakeModeFilter(colors[x][y], SkBlendMode::kModulate));
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2014-08-21 21:40:36 +00:00
|
|
|
step.fSurf = create_compat_surface(finalCanvas, kTileWidth, kTileHeight);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
SkCanvas* subCanvas = step.fSurf->getCanvas();
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
const SkMatrix trans = SkMatrix::MakeTrans(-SkIntToScalar(x*kTileWidth),
|
2015-03-27 02:57:08 +00:00
|
|
|
-SkIntToScalar(y*kTileHeight));
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
create_content(mpd, pfGen, pictures, subCanvas, trans);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr PFLayoutMtd gLayoutMthds[] = { simple, tiled };
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
/**
|
|
|
|
* This GM exercises the SkMultiPictureDraw object. It tests the
|
|
|
|
* cross product of:
|
|
|
|
* tiled vs. all-at-once rendering (e.g., into many or just 1 canvas)
|
|
|
|
* different clips (e.g., none, rect, rrect)
|
|
|
|
* single vs. multiple pictures (e.g., normal vs. picture-pile-style content)
|
|
|
|
*/
|
|
|
|
class MultiPictureDraw : public GM {
|
|
|
|
public:
|
|
|
|
enum Content {
|
|
|
|
kNoClipSingle_Content,
|
|
|
|
kRectClipMulti_Content,
|
|
|
|
kRRectClipMulti_Content,
|
|
|
|
kPathClipMulti_Content,
|
|
|
|
kInvPathClipMulti_Content,
|
2014-09-19 15:56:09 +00:00
|
|
|
kSierpinski_Content,
|
2014-10-02 15:32:43 +00:00
|
|
|
kBigLayer_Content,
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2014-10-02 15:32:43 +00:00
|
|
|
kLast_Content = kBigLayer_Content
|
2014-08-21 20:12:42 +00:00
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
const int kContentCnt = kLast_Content + 1;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
enum Layout {
|
|
|
|
kSimple_Layout,
|
|
|
|
kTiled_Layout,
|
|
|
|
|
|
|
|
kLast_Layout = kTiled_Layout
|
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
const int kLayoutCnt = kLast_Layout + 1;
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
MultiPictureDraw(Content content, Layout layout) : fContent(content), fLayout(layout) {
|
|
|
|
SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt);
|
|
|
|
SkASSERT(SK_ARRAY_COUNT(gContentMthds) == kContentCnt);
|
|
|
|
|
2014-09-19 15:56:09 +00:00
|
|
|
for (int i = 0; i < kNumPictures; ++i) {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPictures[i] = nullptr;
|
2014-09-19 15:56:09 +00:00
|
|
|
}
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~MultiPictureDraw() override {
|
2014-09-19 15:56:09 +00:00
|
|
|
for (int i = 0; i < kNumPictures; ++i) {
|
|
|
|
SkSafeUnref(fPictures[i]);
|
|
|
|
}
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Content fContent;
|
|
|
|
Layout fLayout;
|
2014-09-19 15:56:09 +00:00
|
|
|
const SkPicture* fPictures[kNumPictures];
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-03-18 14:25:55 +00:00
|
|
|
fPictures[0] = make_hex_plane_picture(SK_ColorWHITE).release();
|
|
|
|
fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK_ColorGRAY)).release();
|
|
|
|
fPictures[2] = make_sierpinski_picture().release();
|
|
|
|
fPictures[3] = make_single_layer_hex_plane_picture().release();
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-08-21 20:12:42 +00:00
|
|
|
SkMultiPictureDraw mpd;
|
|
|
|
SkTArray<ComposeStep> composeSteps;
|
|
|
|
|
|
|
|
// Fill up the MultiPictureDraw
|
2014-09-24 20:03:30 +00:00
|
|
|
(*gLayoutMthds[fLayout])(canvas, &mpd,
|
|
|
|
gContentMthds[fContent],
|
2014-08-21 20:12:42 +00:00
|
|
|
fPictures, &composeSteps);
|
|
|
|
|
|
|
|
mpd.draw();
|
|
|
|
|
|
|
|
// Compose all the drawn canvases into the final canvas
|
|
|
|
for (int i = 0; i < composeSteps.count(); ++i) {
|
|
|
|
const ComposeStep& step = composeSteps[i];
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
canvas->drawImage(step.fSurf->makeImageSnapshot().get(),
|
|
|
|
step.fX, step.fY, step.fPaint);
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(kPicWidth, kPicHeight); }
|
2014-08-21 20:12:42 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2016-09-01 18:24:54 +00:00
|
|
|
const char* gContentNames[] = {
|
2016-03-29 16:03:52 +00:00
|
|
|
"noclip", "rectclip", "rrectclip", "pathclip",
|
2014-10-02 15:32:43 +00:00
|
|
|
"invpathclip", "sierpinski", "biglayer"
|
2014-08-21 20:12:42 +00:00
|
|
|
};
|
2016-09-01 18:24:54 +00:00
|
|
|
const char* gLayoutNames[] = { "simple", "tiled" };
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
SkASSERT(SK_ARRAY_COUNT(gLayoutNames) == kLayoutCnt);
|
|
|
|
SkASSERT(SK_ARRAY_COUNT(gContentNames) == kContentCnt);
|
|
|
|
|
|
|
|
SkString name("multipicturedraw_");
|
|
|
|
|
|
|
|
name.append(gContentNames[fContent]);
|
|
|
|
name.append("_");
|
|
|
|
name.append(gLayoutNames[fLayout]);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kNoClipSingle_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kRectClipMulti_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kRRectClipMulti_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content,
|
|
|
|
MultiPictureDraw::kSimple_Layout);)
|
|
|
|
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kNoClipSingle_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kRectClipMulti_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kRRectClipMulti_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
|
|
|
DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content,
|
|
|
|
MultiPictureDraw::kTiled_Layout);)
|
2014-08-21 20:12:42 +00:00
|
|
|
}
|