2012-06-29 14:21:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-02-12 15:15:45 +00:00
|
|
|
#include "SkCanvasPriv.h"
|
2015-08-05 20:57:49 +00:00
|
|
|
#include "SkClipStack.h"
|
2012-06-29 14:21:22 +00:00
|
|
|
#include "SkDebugCanvas.h"
|
|
|
|
#include "SkDrawCommand.h"
|
2016-09-13 17:00:23 +00:00
|
|
|
#include "SkPaintFilterCanvas.h"
|
|
|
|
#include "SkTextBlob.h"
|
2015-03-26 14:24:48 +00:00
|
|
|
|
2016-02-29 19:15:06 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrAuditTrail.h"
|
|
|
|
#include "GrContext.h"
|
|
|
|
#include "GrRenderTarget.h"
|
2016-03-01 15:15:52 +00:00
|
|
|
#include "SkGpuDevice.h"
|
2016-02-29 19:15:06 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-04 18:45:05 +00:00
|
|
|
#define SKDEBUGCANVAS_VERSION 1
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail"
|
2016-02-10 20:57:30 +00:00
|
|
|
|
2015-03-26 14:24:48 +00:00
|
|
|
class DebugPaintFilterCanvas : public SkPaintFilterCanvas {
|
|
|
|
public:
|
2016-10-17 19:20:02 +00:00
|
|
|
DebugPaintFilterCanvas(SkCanvas* canvas,
|
2015-08-26 20:07:48 +00:00
|
|
|
bool overdrawViz,
|
|
|
|
bool overrideFilterQuality,
|
2015-03-26 14:24:48 +00:00
|
|
|
SkFilterQuality quality)
|
2016-10-17 19:20:02 +00:00
|
|
|
: INHERITED(canvas)
|
|
|
|
, fOverdrawViz(overdrawViz)
|
2015-03-26 14:24:48 +00:00
|
|
|
, fOverrideFilterQuality(overrideFilterQuality)
|
2015-08-26 20:07:48 +00:00
|
|
|
, fFilterQuality(quality) {}
|
2015-03-26 14:24:48 +00:00
|
|
|
|
|
|
|
protected:
|
2016-01-12 15:21:11 +00:00
|
|
|
bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override {
|
|
|
|
if (*paint) {
|
2016-10-17 19:20:02 +00:00
|
|
|
if (fOverdrawViz) {
|
|
|
|
paint->writable()->setColor(SK_ColorRED);
|
|
|
|
paint->writable()->setAlpha(0x08);
|
|
|
|
paint->writable()->setBlendMode(SkBlendMode::kSrcOver);
|
2016-01-11 21:58:29 +00:00
|
|
|
}
|
2015-03-26 14:24:48 +00:00
|
|
|
|
2016-01-11 21:58:29 +00:00
|
|
|
if (fOverrideFilterQuality) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setFilterQuality(fFilterQuality);
|
2016-01-11 21:58:29 +00:00
|
|
|
}
|
2015-03-26 14:24:48 +00:00
|
|
|
}
|
2016-01-11 21:58:29 +00:00
|
|
|
return true;
|
2015-03-26 14:24:48 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawPicture(const SkPicture* picture,
|
|
|
|
const SkMatrix* matrix,
|
|
|
|
const SkPaint* paint) override {
|
2015-03-26 14:24:48 +00:00
|
|
|
// We need to replay the picture onto this canvas in order to filter its internal paints.
|
|
|
|
this->SkCanvas::onDrawPicture(picture, matrix, paint);
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
void onDrawShadowedPicture(const SkPicture* picture,
|
|
|
|
const SkMatrix* matrix,
|
2016-08-25 13:30:23 +00:00
|
|
|
const SkPaint* paint,
|
|
|
|
const SkShadowParams& params) {
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
2016-08-25 13:30:23 +00:00
|
|
|
this->SkCanvas::onDrawShadowedPicture(picture, matrix, paint, params);
|
2016-07-21 17:25:54 +00:00
|
|
|
#else
|
|
|
|
this->SkCanvas::onDrawPicture(picture, matrix, paint);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-26 14:24:48 +00:00
|
|
|
private:
|
2016-10-17 19:20:02 +00:00
|
|
|
bool fOverdrawViz;
|
2015-03-26 14:24:48 +00:00
|
|
|
bool fOverrideFilterQuality;
|
|
|
|
SkFilterQuality fFilterQuality;
|
|
|
|
|
|
|
|
typedef SkPaintFilterCanvas INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-01-05 20:58:56 +00:00
|
|
|
SkDebugCanvas::SkDebugCanvas(int width, int height)
|
|
|
|
: INHERITED(width, height)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fPicture(nullptr)
|
2013-12-04 13:42:46 +00:00
|
|
|
, fFilter(false)
|
2014-03-03 16:32:17 +00:00
|
|
|
, fMegaVizMode(false)
|
2013-02-06 20:13:54 +00:00
|
|
|
, fOverdrawViz(false)
|
2015-03-26 14:24:48 +00:00
|
|
|
, fOverrideFilterQuality(false)
|
2016-02-12 20:06:53 +00:00
|
|
|
, fFilterQuality(kNone_SkFilterQuality)
|
2016-02-29 19:15:06 +00:00
|
|
|
, fClipVizColor(SK_ColorTRANSPARENT)
|
2016-02-29 20:46:04 +00:00
|
|
|
, fDrawGpuBatchBounds(false) {
|
2013-01-17 16:30:56 +00:00
|
|
|
fUserMatrix.reset();
|
2013-11-07 22:20:31 +00:00
|
|
|
|
|
|
|
// SkPicturePlayback uses the base-class' quickReject calls to cull clipped
|
|
|
|
// operations. This can lead to problems in the debugger which expects all
|
|
|
|
// the operations in the captured skp to appear in the debug canvas. To
|
|
|
|
// circumvent this we create a wide open clip here (an empty clip rect
|
|
|
|
// is not sufficient).
|
|
|
|
// Internally, the SkRect passed to clipRect is converted to an SkIRect and
|
|
|
|
// rounded out. The following code creates a nearly maximal rect that will
|
|
|
|
// not get collapsed by the coming conversions (Due to precision loss the
|
|
|
|
// inset has to be surprisingly large).
|
|
|
|
SkIRect largeIRect = SkIRect::MakeLargest();
|
|
|
|
largeIRect.inset(1024, 1024);
|
2013-11-10 15:08:45 +00:00
|
|
|
SkRect large = SkRect::Make(largeIRect);
|
2013-11-07 22:20:31 +00:00
|
|
|
#ifdef SK_DEBUG
|
2014-11-19 13:03:18 +00:00
|
|
|
SkASSERT(!large.roundOut().isEmpty());
|
2013-11-07 22:20:31 +00:00
|
|
|
#endif
|
2014-02-28 18:19:39 +00:00
|
|
|
// call the base class' version to avoid adding a draw command
|
2016-12-09 14:00:50 +00:00
|
|
|
this->INHERITED::onClipRect(large, kReplace_SkClipOp, kHard_ClipEdgeStyle);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 15:08:33 +00:00
|
|
|
SkDebugCanvas::~SkDebugCanvas() {
|
2013-01-02 20:20:31 +00:00
|
|
|
fCommandVector.deleteAll();
|
2012-08-07 15:08:33 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) {
|
2013-01-02 20:20:31 +00:00
|
|
|
fCommandVector.push(command);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::draw(SkCanvas* canvas) {
|
2013-12-04 13:42:46 +00:00
|
|
|
if (!fCommandVector.isEmpty()) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->drawTo(canvas, fCommandVector.count() - 1);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 15:57:52 +00:00
|
|
|
void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) {
|
2013-01-17 16:30:56 +00:00
|
|
|
canvas->concat(fUserMatrix);
|
2012-08-01 15:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) {
|
2012-07-31 19:55:32 +00:00
|
|
|
SkBitmap bitmap;
|
2014-01-24 18:53:42 +00:00
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1));
|
2012-07-31 19:55:32 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(bitmap);
|
2012-09-06 18:43:21 +00:00
|
|
|
canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
|
2014-08-29 15:03:56 +00:00
|
|
|
this->applyUserTransform(&canvas);
|
2012-07-31 19:55:32 +00:00
|
|
|
|
|
|
|
int layer = 0;
|
2012-07-31 20:07:42 +00:00
|
|
|
SkColor prev = bitmap.getColor(0,0);
|
2012-07-31 19:55:32 +00:00
|
|
|
for (int i = 0; i < index; i++) {
|
2013-01-02 20:20:31 +00:00
|
|
|
if (fCommandVector[i]->isVisible()) {
|
2014-10-16 21:28:28 +00:00
|
|
|
fCommandVector[i]->setUserMatrix(fUserMatrix);
|
2013-01-02 20:20:31 +00:00
|
|
|
fCommandVector[i]->execute(&canvas);
|
2012-07-31 19:55:32 +00:00
|
|
|
}
|
|
|
|
if (prev != bitmap.getColor(0,0)) {
|
|
|
|
layer = i;
|
|
|
|
}
|
|
|
|
prev = bitmap.getColor(0,0);
|
|
|
|
}
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2014-03-03 16:32:17 +00:00
|
|
|
class SkDebugClipVisitor : public SkCanvas::ClipVisitor {
|
|
|
|
public:
|
|
|
|
SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipRect(const SkRect& r, SkClipOp, bool doAA) override {
|
2014-03-03 16:32:17 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setAntiAlias(doAA);
|
|
|
|
fCanvas->drawRect(r, p);
|
|
|
|
}
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipRRect(const SkRRect& rr, SkClipOp, bool doAA) override {
|
2014-03-03 16:32:17 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorGREEN);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setAntiAlias(doAA);
|
|
|
|
fCanvas->drawRRect(rr, p);
|
|
|
|
}
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipPath(const SkPath& path, SkClipOp, bool doAA) override {
|
2014-03-03 16:32:17 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLUE);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setAntiAlias(doAA);
|
|
|
|
fCanvas->drawPath(path, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkCanvas* fCanvas;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkCanvas::ClipVisitor INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
// set up the saveLayer commands so that the active ones
|
|
|
|
// return true in their 'active' method
|
2014-03-03 23:25:41 +00:00
|
|
|
void SkDebugCanvas::markActiveCommands(int index) {
|
|
|
|
fActiveLayers.rewind();
|
2014-03-03 16:32:17 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < fCommandVector.count(); ++i) {
|
|
|
|
fCommandVector[i]->setActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < index; ++i) {
|
|
|
|
SkDrawCommand::Action result = fCommandVector[i]->action();
|
2014-03-03 23:25:41 +00:00
|
|
|
if (SkDrawCommand::kPushLayer_Action == result) {
|
|
|
|
fActiveLayers.push(fCommandVector[i]);
|
|
|
|
} else if (SkDrawCommand::kPopLayer_Action == result) {
|
|
|
|
fActiveLayers.pop();
|
2014-03-03 16:32:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:25:41 +00:00
|
|
|
for (int i = 0; i < fActiveLayers.count(); ++i) {
|
|
|
|
fActiveLayers[i]->setActive(true);
|
|
|
|
}
|
|
|
|
|
2014-03-03 16:32:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 16:32:37 +00:00
|
|
|
void SkDebugCanvas::drawTo(SkCanvas* canvas, int index, int m) {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(!fCommandVector.isEmpty());
|
|
|
|
SkASSERT(index < fCommandVector.count());
|
2015-01-14 07:09:19 +00:00
|
|
|
|
|
|
|
int saveCount = canvas->save();
|
|
|
|
|
2015-01-05 20:58:56 +00:00
|
|
|
SkRect windowRect = SkRect::MakeWH(SkIntToScalar(canvas->getBaseLayerSize().width()),
|
|
|
|
SkIntToScalar(canvas->getBaseLayerSize().height()));
|
2012-08-01 15:57:52 +00:00
|
|
|
|
2014-05-19 13:53:10 +00:00
|
|
|
bool pathOpsMode = getAllowSimplifyClip();
|
|
|
|
canvas->setAllowSimplifyClip(pathOpsMode);
|
2016-02-17 19:49:43 +00:00
|
|
|
canvas->clear(SK_ColorWHITE);
|
2015-01-14 07:09:19 +00:00
|
|
|
canvas->resetMatrix();
|
|
|
|
if (!windowRect.isEmpty()) {
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipRect(windowRect, kReplace_SkClipOp);
|
2013-08-05 16:31:27 +00:00
|
|
|
}
|
2015-01-14 07:09:19 +00:00
|
|
|
this->applyUserTransform(canvas);
|
2013-02-06 20:13:54 +00:00
|
|
|
|
2016-10-17 19:20:02 +00:00
|
|
|
DebugPaintFilterCanvas fPaintFilterCanvas(canvas, fOverdrawViz,
|
|
|
|
fOverrideFilterQuality, fFilterQuality);
|
|
|
|
canvas = &fPaintFilterCanvas;
|
2012-08-01 15:57:52 +00:00
|
|
|
|
2014-03-03 16:32:17 +00:00
|
|
|
if (fMegaVizMode) {
|
2014-03-03 23:25:41 +00:00
|
|
|
this->markActiveCommands(index);
|
2014-03-03 16:32:17 +00:00
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-03-11 19:45:53 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-02-29 19:15:06 +00:00
|
|
|
// If we have a GPU backend we can also visualize the batching information
|
|
|
|
GrAuditTrail* at = nullptr;
|
2016-03-10 21:29:36 +00:00
|
|
|
if (fDrawGpuBatchBounds || m != -1) {
|
|
|
|
at = this->getAuditTrail(canvas);
|
2016-02-29 19:15:06 +00:00
|
|
|
}
|
2016-03-11 19:45:53 +00:00
|
|
|
#endif
|
2014-03-03 16:32:17 +00:00
|
|
|
|
2015-01-14 07:09:19 +00:00
|
|
|
for (int i = 0; i <= index; i++) {
|
2012-07-31 19:55:32 +00:00
|
|
|
if (i == index && fFilter) {
|
2014-08-29 15:03:56 +00:00
|
|
|
canvas->clear(0xAAFFFFFF);
|
2012-07-31 19:55:32 +00:00
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-02-29 19:15:06 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-04-15 18:00:51 +00:00
|
|
|
// We need to flush any pending operations, or they might batch with commands below.
|
|
|
|
// Previous operations were not registered with the audit trail when they were
|
|
|
|
// created, so if we allow them to combine, the audit trail will fail to find them.
|
|
|
|
canvas->flush();
|
|
|
|
|
2016-02-29 19:15:06 +00:00
|
|
|
GrAuditTrail::AutoCollectBatches* acb = nullptr;
|
|
|
|
if (at) {
|
|
|
|
acb = new GrAuditTrail::AutoCollectBatches(at, i);
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
if (fCommandVector[i]->isVisible()) {
|
2014-03-03 16:32:17 +00:00
|
|
|
if (fMegaVizMode && fCommandVector[i]->active()) {
|
2014-03-03 23:25:41 +00:00
|
|
|
// "active" commands execute their visualization behaviors:
|
|
|
|
// All active saveLayers get replaced with saves so all draws go to the
|
|
|
|
// visible canvas.
|
|
|
|
// All active culls draw their cull box
|
|
|
|
fCommandVector[i]->vizExecute(canvas);
|
2014-03-03 16:32:17 +00:00
|
|
|
} else {
|
2014-10-16 21:28:28 +00:00
|
|
|
fCommandVector[i]->setUserMatrix(fUserMatrix);
|
2014-03-03 16:32:17 +00:00
|
|
|
fCommandVector[i]->execute(canvas);
|
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
2016-02-29 19:15:06 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (at && acb) {
|
|
|
|
delete acb;
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
2014-03-03 16:32:17 +00:00
|
|
|
|
2016-02-12 20:06:53 +00:00
|
|
|
if (SkColorGetA(fClipVizColor) != 0) {
|
|
|
|
canvas->save();
|
|
|
|
#define LARGE_COORD 1000000000
|
|
|
|
canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD),
|
2016-12-09 14:00:50 +00:00
|
|
|
kReverseDifference_SkClipOp);
|
2016-02-12 20:06:53 +00:00
|
|
|
SkPaint clipPaint;
|
|
|
|
clipPaint.setColor(fClipVizColor);
|
|
|
|
canvas->drawPaint(clipPaint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2014-03-03 16:32:17 +00:00
|
|
|
if (fMegaVizMode) {
|
|
|
|
canvas->save();
|
|
|
|
// nuke the CTM
|
2014-08-29 15:03:56 +00:00
|
|
|
canvas->resetMatrix();
|
2014-03-03 16:32:17 +00:00
|
|
|
// turn off clipping
|
2015-01-05 20:58:56 +00:00
|
|
|
if (!windowRect.isEmpty()) {
|
|
|
|
SkRect r = windowRect;
|
|
|
|
r.outset(SK_Scalar1, SK_Scalar1);
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipRect(r, kReplace_SkClipOp);
|
2015-01-05 20:58:56 +00:00
|
|
|
}
|
2014-03-03 16:32:17 +00:00
|
|
|
// visualize existing clips
|
|
|
|
SkDebugClipVisitor visitor(canvas);
|
|
|
|
|
|
|
|
canvas->replayClips(&visitor);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2014-05-19 13:53:10 +00:00
|
|
|
if (pathOpsMode) {
|
|
|
|
this->resetClipStackData();
|
|
|
|
const SkClipStack* clipStack = canvas->getClipStack();
|
|
|
|
SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart);
|
|
|
|
const SkClipStack::Element* element;
|
|
|
|
SkPath devPath;
|
|
|
|
while ((element = iter.next())) {
|
|
|
|
SkClipStack::Element::Type type = element->getType();
|
|
|
|
SkPath operand;
|
|
|
|
if (type != SkClipStack::Element::kEmpty_Type) {
|
|
|
|
element->asPath(&operand);
|
|
|
|
}
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp elementOp = element->getOp();
|
2014-05-19 13:53:10 +00:00
|
|
|
this->addClipStackData(devPath, operand, elementOp);
|
2016-12-09 14:00:50 +00:00
|
|
|
if (elementOp == kReplace_SkClipOp) {
|
2014-05-19 13:53:10 +00:00
|
|
|
devPath = operand;
|
|
|
|
} else {
|
|
|
|
Op(devPath, operand, (SkPathOp) elementOp, &devPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->lastClipStackData(devPath);
|
|
|
|
}
|
2012-08-03 17:32:05 +00:00
|
|
|
fMatrix = canvas->getTotalMatrix();
|
2014-03-08 03:57:19 +00:00
|
|
|
if (!canvas->getClipDeviceBounds(&fClip)) {
|
|
|
|
fClip.setEmpty();
|
|
|
|
}
|
2015-01-14 07:09:19 +00:00
|
|
|
|
|
|
|
canvas->restoreToCount(saveCount);
|
2015-03-26 14:24:48 +00:00
|
|
|
|
2016-02-29 19:15:06 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
// draw any batches if required and issue a full reset onto GrAuditTrail
|
|
|
|
if (at) {
|
2016-03-04 18:45:05 +00:00
|
|
|
// just in case there is global reordering, we flush the canvas before querying
|
|
|
|
// GrAuditTrail
|
2016-03-08 18:43:41 +00:00
|
|
|
GrAuditTrail::AutoEnable ae(at);
|
2016-03-04 18:45:05 +00:00
|
|
|
canvas->flush();
|
|
|
|
|
2016-03-01 22:22:02 +00:00
|
|
|
// we pick three colorblind-safe colors, 75% alpha
|
|
|
|
static const SkColor kTotalBounds = SkColorSetARGB(0xC0, 0x6A, 0x3D, 0x9A);
|
|
|
|
static const SkColor kOpBatchBounds = SkColorSetARGB(0xC0, 0xE3, 0x1A, 0x1C);
|
|
|
|
static const SkColor kOtherBatchBounds = SkColorSetARGB(0xC0, 0xFF, 0x7F, 0x00);
|
|
|
|
|
2016-03-01 15:15:52 +00:00
|
|
|
// get the render target of the top device so we can ignore batches drawn offscreen
|
|
|
|
SkBaseDevice* bd = canvas->getDevice_just_for_deprecated_compatibility_testing();
|
|
|
|
SkGpuDevice* gbd = reinterpret_cast<SkGpuDevice*>(bd);
|
2016-11-11 17:38:40 +00:00
|
|
|
GrGpuResource::UniqueID rtID =
|
|
|
|
gbd->accessRenderTargetContext()->accessRenderTarget()->uniqueID();
|
2016-03-01 15:15:52 +00:00
|
|
|
|
|
|
|
// get the bounding boxes to draw
|
2016-02-29 19:15:06 +00:00
|
|
|
SkTArray<GrAuditTrail::BatchInfo> childrenBounds;
|
2016-03-02 16:32:37 +00:00
|
|
|
if (m == -1) {
|
|
|
|
at->getBoundsByClientID(&childrenBounds, index);
|
|
|
|
} else {
|
|
|
|
// the client wants us to draw the mth batch
|
|
|
|
at->getBoundsByBatchListID(&childrenBounds.push_back(), m);
|
|
|
|
}
|
2016-02-29 19:15:06 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
for (int i = 0; i < childrenBounds.count(); i++) {
|
2016-03-01 15:15:52 +00:00
|
|
|
if (childrenBounds[i].fRenderTargetUniqueID != rtID) {
|
|
|
|
// offscreen draw, ignore for now
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-01 22:22:02 +00:00
|
|
|
paint.setColor(kTotalBounds);
|
2016-02-29 19:15:06 +00:00
|
|
|
canvas->drawRect(childrenBounds[i].fBounds, paint);
|
|
|
|
for (int j = 0; j < childrenBounds[i].fBatches.count(); j++) {
|
|
|
|
const GrAuditTrail::BatchInfo::Batch& batch = childrenBounds[i].fBatches[j];
|
|
|
|
if (batch.fClientID != index) {
|
2016-03-01 22:22:02 +00:00
|
|
|
paint.setColor(kOtherBatchBounds);
|
2016-02-29 19:15:06 +00:00
|
|
|
} else {
|
2016-03-01 22:22:02 +00:00
|
|
|
paint.setColor(kOpBatchBounds);
|
2016-02-29 19:15:06 +00:00
|
|
|
}
|
|
|
|
canvas->drawRect(batch.fBounds, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-10 21:29:36 +00:00
|
|
|
this->cleanupAuditTrail(canvas);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
void SkDebugCanvas::deleteDrawCommandAt(int index) {
|
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
delete fCommandVector[index];
|
|
|
|
fCommandVector.remove(index);
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
return fCommandVector[index];
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) {
|
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
delete fCommandVector[index];
|
|
|
|
fCommandVector[index] = command;
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
const SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) const {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
return fCommandVector[index]->Info();
|
2012-07-17 15:40:51 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-17 15:40:51 +00:00
|
|
|
bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
return fCommandVector[index]->isVisible();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 20:44:29 +00:00
|
|
|
const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const {
|
2013-01-02 20:20:31 +00:00
|
|
|
return fCommandVector;
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 22:53:11 +00:00
|
|
|
SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() {
|
|
|
|
return fCommandVector;
|
|
|
|
}
|
|
|
|
|
2016-03-10 21:29:36 +00:00
|
|
|
GrAuditTrail* SkDebugCanvas::getAuditTrail(SkCanvas* canvas) {
|
|
|
|
GrAuditTrail* at = nullptr;
|
2016-03-04 18:45:05 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-04-28 21:32:04 +00:00
|
|
|
GrContext* ctx = canvas->getGrContext();
|
|
|
|
if (ctx) {
|
|
|
|
at = ctx->getAuditTrail();
|
2016-03-10 21:29:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return at;
|
|
|
|
}
|
2016-03-04 18:45:05 +00:00
|
|
|
|
2016-03-10 21:29:36 +00:00
|
|
|
void SkDebugCanvas::drawAndCollectBatches(int n, SkCanvas* canvas) {
|
2016-03-11 19:45:53 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-03-10 21:29:36 +00:00
|
|
|
GrAuditTrail* at = this->getAuditTrail(canvas);
|
|
|
|
if (at) {
|
|
|
|
// loop over all of the commands and draw them, this is to collect reordering
|
|
|
|
// information
|
|
|
|
for (int i = 0; i < this->getSize() && i <= n; i++) {
|
|
|
|
GrAuditTrail::AutoCollectBatches enable(at, i);
|
|
|
|
fCommandVector[i]->execute(canvas);
|
|
|
|
}
|
2016-03-04 18:45:05 +00:00
|
|
|
|
2016-03-10 21:29:36 +00:00
|
|
|
// in case there is some kind of global reordering
|
|
|
|
{
|
|
|
|
GrAuditTrail::AutoEnable ae(at);
|
|
|
|
canvas->flush();
|
2016-03-04 18:45:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-11 19:45:53 +00:00
|
|
|
#endif
|
2016-03-10 21:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::cleanupAuditTrail(SkCanvas* canvas) {
|
|
|
|
GrAuditTrail* at = this->getAuditTrail(canvas);
|
|
|
|
if (at) {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrAuditTrail::AutoEnable ae(at);
|
|
|
|
at->fullReset();
|
2016-03-04 18:45:05 +00:00
|
|
|
#endif
|
2016-03-10 21:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) {
|
|
|
|
this->drawAndCollectBatches(n, canvas);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-03-04 18:45:05 +00:00
|
|
|
// now collect json
|
2016-03-11 19:45:53 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-03-10 21:29:36 +00:00
|
|
|
GrAuditTrail* at = this->getAuditTrail(canvas);
|
2016-03-11 19:45:53 +00:00
|
|
|
#endif
|
2016-02-10 20:57:30 +00:00
|
|
|
Json::Value result = Json::Value(Json::objectValue);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION);
|
|
|
|
Json::Value commands = Json::Value(Json::arrayValue);
|
2016-02-12 20:06:53 +00:00
|
|
|
for (int i = 0; i < this->getSize() && i <= n; i++) {
|
2016-03-04 18:45:05 +00:00
|
|
|
commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager);
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (at) {
|
|
|
|
// TODO if this is inefficient we could add a method to GrAuditTrail which takes
|
|
|
|
// a Json::Value and is only compiled in this file
|
|
|
|
Json::Value parsedFromString;
|
|
|
|
Json::Reader reader;
|
|
|
|
SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString));
|
|
|
|
|
|
|
|
commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2016-03-10 21:29:36 +00:00
|
|
|
this->cleanupAuditTrail(canvas);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Value SkDebugCanvas::toJSONBatchList(int n, SkCanvas* canvas) {
|
|
|
|
this->drawAndCollectBatches(n, canvas);
|
|
|
|
|
|
|
|
Json::Value parsedFromString;
|
2016-03-04 18:45:05 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-03-11 19:45:53 +00:00
|
|
|
GrAuditTrail* at = this->getAuditTrail(canvas);
|
2016-03-04 18:45:05 +00:00
|
|
|
if (at) {
|
2016-03-10 21:29:36 +00:00
|
|
|
GrAuditTrail::AutoManageBatchList enable(at);
|
|
|
|
Json::Reader reader;
|
|
|
|
SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString));
|
2016-02-10 20:57:30 +00:00
|
|
|
}
|
2016-03-04 18:45:05 +00:00
|
|
|
#endif
|
2016-03-10 21:29:36 +00:00
|
|
|
this->cleanupAuditTrail(canvas);
|
|
|
|
return parsedFromString;
|
2016-02-10 20:57:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 14:24:48 +00:00
|
|
|
void SkDebugCanvas::setOverdrawViz(bool overdrawViz) {
|
|
|
|
fOverdrawViz = overdrawViz;
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkFilterQuality quality) {
|
2015-03-26 14:24:48 +00:00
|
|
|
fOverrideFilterQuality = overrideTexFiltering;
|
|
|
|
fFilterQuality = quality;
|
2013-10-17 17:56:10 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
void SkDebugCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
|
2014-02-28 18:19:39 +00:00
|
|
|
this->addDrawCommand(new SkClipPathCommand(path, op, kSoft_ClipEdgeStyle == edgeStyle));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
void SkDebugCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
|
2014-02-28 18:19:39 +00:00
|
|
|
this->addDrawCommand(new SkClipRectCommand(rect, op, kSoft_ClipEdgeStyle == edgeStyle));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
void SkDebugCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
|
2014-02-28 18:19:39 +00:00
|
|
|
this->addDrawCommand(new SkClipRRectCommand(rrect, op, kSoft_ClipEdgeStyle == edgeStyle));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
void SkDebugCanvas::onClipRegion(const SkRegion& region, SkClipOp op) {
|
2014-02-28 18:19:39 +00:00
|
|
|
this->addDrawCommand(new SkClipRegionCommand(region, op));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 20:03:58 +00:00
|
|
|
void SkDebugCanvas::didConcat(const SkMatrix& matrix) {
|
2015-02-13 19:13:00 +00:00
|
|
|
this->addDrawCommand(new SkConcatCommand(matrix));
|
2014-03-13 20:03:58 +00:00
|
|
|
this->INHERITED::didConcat(matrix);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 01:54:19 +00:00
|
|
|
void SkDebugCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
|
|
|
|
this->addDrawCommand(new SkDrawAnnotationCommand(rect, key, sk_ref_sp(value)));
|
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar left,
|
|
|
|
SkScalar top, const SkPaint* paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
|
2015-07-28 14:35:14 +00:00
|
|
|
const SkPaint* paint, SrcRectConstraint constraint) {
|
2015-07-14 17:54:12 +00:00
|
|
|
this->addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint,
|
|
|
|
(SrcRectConstraint)constraint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
|
|
|
const SkRect& dst, const SkPaint* paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
|
|
|
|
const SkPaint* paint) {
|
2015-07-22 17:23:01 +00:00
|
|
|
this->addDrawCommand(new SkDrawImageCommand(image, left, top, paint));
|
2015-01-05 15:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
|
2015-07-28 14:35:14 +00:00
|
|
|
const SkPaint* paint, SrcRectConstraint constraint) {
|
2015-07-22 17:23:01 +00:00
|
|
|
this->addDrawCommand(new SkDrawImageRectCommand(image, src, dst, paint, constraint));
|
2015-01-05 15:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 18:25:19 +00:00
|
|
|
void SkDebugCanvas::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
|
|
|
|
bool useCenter, const SkPaint& paint) {
|
|
|
|
this->addDrawCommand(new SkDrawArcCommand(oval, startAngle, sweepAngle, useCenter, paint));
|
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawPaint(const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawPaintCommand(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawPathCommand(path, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 16:46:25 +00:00
|
|
|
void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
|
|
|
|
const SkMatrix* matrix,
|
2014-08-13 17:46:23 +00:00
|
|
|
const SkPaint* paint) {
|
2015-04-02 03:58:37 +00:00
|
|
|
this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint));
|
2016-02-12 15:15:45 +00:00
|
|
|
SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
|
|
|
|
picture->playback(this);
|
2015-04-02 03:58:37 +00:00
|
|
|
this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint)));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
void SkDebugCanvas::onDrawShadowedPicture(const SkPicture* picture,
|
|
|
|
const SkMatrix* matrix,
|
2016-08-25 13:30:23 +00:00
|
|
|
const SkPaint* paint,
|
|
|
|
const SkShadowParams& params) {
|
|
|
|
this->addDrawCommand(new SkBeginDrawShadowedPictureCommand(picture, matrix, paint, params));
|
2016-07-21 17:25:54 +00:00
|
|
|
SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
|
|
|
|
picture->playback(this);
|
|
|
|
this->addDrawCommand(new SkEndDrawShadowedPictureCommand(SkToBool(matrix) || SkToBool(paint)));
|
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
|
|
|
|
const SkPoint pts[], const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
void SkDebugCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
|
|
|
|
const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
void SkDebugCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
|
|
|
|
SkScalar constY, const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(
|
2013-06-18 20:20:55 +00:00
|
|
|
new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
|
2012-06-29 14:21:22 +00:00
|
|
|
// NOTE(chudy): Messing up when renamed to DrawRect... Why?
|
2013-06-18 20:20:55 +00:00
|
|
|
addDrawCommand(new SkDrawRectCommand(rect, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawRRectCommand(rrect, paint));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 12:20:45 +00:00
|
|
|
void SkDebugCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
|
|
|
|
const SkPaint& paint) {
|
2014-02-24 17:28:55 +00:00
|
|
|
this->addDrawCommand(new SkDrawDRRectCommand(outer, inner, paint));
|
2014-02-21 12:20:45 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
void SkDebugCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
void SkDebugCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
|
|
|
|
const SkMatrix* matrix, const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(
|
2013-06-18 20:20:55 +00:00
|
|
|
new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 19:47:17 +00:00
|
|
|
void SkDebugCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
|
|
|
|
const SkRect* cull, const SkPaint& paint) {
|
|
|
|
this->addDrawCommand(new SkDrawTextRSXformCommand(text, byteLength, xform, cull, paint));
|
|
|
|
}
|
|
|
|
|
2014-08-26 14:56:44 +00:00
|
|
|
void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint) {
|
2016-09-13 17:00:23 +00:00
|
|
|
this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)),
|
|
|
|
x, y, paint));
|
2014-08-26 14:56:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 19:13:00 +00:00
|
|
|
void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
2016-11-03 18:45:31 +00:00
|
|
|
const SkPoint texCoords[4], SkBlendMode bmode,
|
2015-02-13 19:13:00 +00:00
|
|
|
const SkPaint& paint) {
|
2016-10-28 19:42:34 +00:00
|
|
|
this->addDrawCommand(new SkDrawPatchCommand(cubics, colors, texCoords, bmode, paint));
|
2015-02-13 19:13:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
void SkDebugCanvas::onDrawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[],
|
|
|
|
const SkPoint texs[], const SkColor colors[],
|
2016-11-03 18:45:31 +00:00
|
|
|
SkBlendMode bmode, const uint16_t indices[], int indexCount,
|
2015-01-05 15:49:08 +00:00
|
|
|
const SkPaint& paint) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices,
|
2016-10-28 19:42:34 +00:00
|
|
|
texs, colors, bmode, indices, indexCount, paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 20:21:48 +00:00
|
|
|
void SkDebugCanvas::willRestore() {
|
|
|
|
this->addDrawCommand(new SkRestoreCommand());
|
|
|
|
this->INHERITED::willRestore();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 14:13:28 +00:00
|
|
|
void SkDebugCanvas::willSave() {
|
|
|
|
this->addDrawCommand(new SkSaveCommand());
|
|
|
|
this->INHERITED::willSave();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
SkCanvas::SaveLayerStrategy SkDebugCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
|
|
|
|
this->addDrawCommand(new SkSaveLayerCommand(rec));
|
|
|
|
(void)this->INHERITED::getSaveLayerStrategy(rec);
|
2014-03-12 20:21:48 +00:00
|
|
|
// No need for a full layer.
|
|
|
|
return kNoLayer_SaveLayerStrategy;
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 20:03:58 +00:00
|
|
|
void SkDebugCanvas::didSetMatrix(const SkMatrix& matrix) {
|
2014-03-25 23:31:33 +00:00
|
|
|
this->addDrawCommand(new SkSetMatrixCommand(matrix));
|
2014-03-13 20:03:58 +00:00
|
|
|
this->INHERITED::didSetMatrix(matrix);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 21:05:28 +00:00
|
|
|
void SkDebugCanvas::didTranslateZ(SkScalar z) {
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
2016-07-13 21:05:28 +00:00
|
|
|
this->addDrawCommand(new SkTranslateZCommand(z));
|
|
|
|
this->INHERITED::didTranslateZ(z);
|
2016-07-21 17:25:54 +00:00
|
|
|
#endif
|
2016-07-13 21:05:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
void SkDebugCanvas::toggleCommand(int index, bool toggle) {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(index < fCommandVector.count());
|
|
|
|
fCommandVector[index]->setVisible(toggle);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
2014-05-19 13:53:10 +00:00
|
|
|
|
|
|
|
static const char* gFillTypeStrs[] = {
|
|
|
|
"kWinding_FillType",
|
|
|
|
"kEvenOdd_FillType",
|
|
|
|
"kInverseWinding_FillType",
|
|
|
|
"kInverseEvenOdd_FillType"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* gOpStrs[] = {
|
2015-04-07 13:53:21 +00:00
|
|
|
"kDifference_PathOp",
|
|
|
|
"kIntersect_PathOp",
|
|
|
|
"kUnion_PathOp",
|
2014-05-19 13:53:10 +00:00
|
|
|
"kXor_PathOp",
|
2015-04-07 13:53:21 +00:00
|
|
|
"kReverseDifference_PathOp",
|
2014-05-19 13:53:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char kHTML4SpaceIndent[] = " ";
|
|
|
|
|
|
|
|
void SkDebugCanvas::outputScalar(SkScalar num) {
|
|
|
|
if (num == (int) num) {
|
|
|
|
fClipStackData.appendf("%d", (int) num);
|
|
|
|
} else {
|
|
|
|
SkString str;
|
|
|
|
str.printf("%1.9g", num);
|
|
|
|
int width = (int) str.size();
|
|
|
|
const char* cStr = str.c_str();
|
|
|
|
while (cStr[width - 1] == '0') {
|
|
|
|
--width;
|
|
|
|
}
|
|
|
|
str.resize(width);
|
|
|
|
fClipStackData.appendf("%sf", str.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::outputPointsCommon(const SkPoint* pts, int count) {
|
|
|
|
for (int index = 0; index < count; ++index) {
|
|
|
|
this->outputScalar(pts[index].fX);
|
|
|
|
fClipStackData.appendf(", ");
|
|
|
|
this->outputScalar(pts[index].fY);
|
|
|
|
if (index + 1 < count) {
|
|
|
|
fClipStackData.appendf(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::outputPoints(const SkPoint* pts, int count) {
|
|
|
|
this->outputPointsCommon(pts, count);
|
|
|
|
fClipStackData.appendf(");<br>");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::outputConicPoints(const SkPoint* pts, SkScalar weight) {
|
|
|
|
this->outputPointsCommon(pts, 2);
|
|
|
|
fClipStackData.appendf(", ");
|
|
|
|
this->outputScalar(weight);
|
|
|
|
fClipStackData.appendf(");<br>");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::addPathData(const SkPath& path, const char* pathName) {
|
|
|
|
SkPath::RawIter iter(path);
|
|
|
|
SkPath::FillType fillType = path.getFillType();
|
|
|
|
fClipStackData.appendf("%sSkPath %s;<br>", kHTML4SpaceIndent, pathName);
|
|
|
|
fClipStackData.appendf("%s%s.setFillType(SkPath::%s);<br>", kHTML4SpaceIndent, pathName,
|
|
|
|
gFillTypeStrs[fillType]);
|
|
|
|
iter.setPath(path);
|
|
|
|
uint8_t verb;
|
|
|
|
SkPoint pts[4];
|
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kMove_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.moveTo(", kHTML4SpaceIndent, pathName);
|
|
|
|
this->outputPoints(&pts[0], 1);
|
|
|
|
continue;
|
|
|
|
case SkPath::kLine_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.lineTo(", kHTML4SpaceIndent, pathName);
|
|
|
|
this->outputPoints(&pts[1], 1);
|
|
|
|
break;
|
|
|
|
case SkPath::kQuad_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.quadTo(", kHTML4SpaceIndent, pathName);
|
|
|
|
this->outputPoints(&pts[1], 2);
|
|
|
|
break;
|
|
|
|
case SkPath::kConic_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.conicTo(", kHTML4SpaceIndent, pathName);
|
|
|
|
this->outputConicPoints(&pts[1], iter.conicWeight());
|
|
|
|
break;
|
|
|
|
case SkPath::kCubic_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.cubicTo(", kHTML4SpaceIndent, pathName);
|
|
|
|
this->outputPoints(&pts[1], 3);
|
|
|
|
break;
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
fClipStackData.appendf("%s%s.close();<br>", kHTML4SpaceIndent, pathName);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("bad verb");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::addClipStackData(const SkPath& devPath, const SkPath& operand,
|
2016-12-09 14:00:50 +00:00
|
|
|
SkClipOp elementOp) {
|
|
|
|
if (elementOp == kReplace_SkClipOp) {
|
2014-05-19 13:53:10 +00:00
|
|
|
if (!lastClipStackData(devPath)) {
|
|
|
|
fSaveDevPath = operand;
|
|
|
|
}
|
|
|
|
fCalledAddStackData = false;
|
|
|
|
} else {
|
|
|
|
fClipStackData.appendf("<br>static void test(skiatest::Reporter* reporter,"
|
|
|
|
" const char* filename) {<br>");
|
|
|
|
addPathData(fCalledAddStackData ? devPath : fSaveDevPath, "path");
|
|
|
|
addPathData(operand, "pathB");
|
|
|
|
fClipStackData.appendf("%stestPathOp(reporter, path, pathB, %s, filename);<br>",
|
|
|
|
kHTML4SpaceIndent, gOpStrs[elementOp]);
|
|
|
|
fClipStackData.appendf("}<br>");
|
|
|
|
fCalledAddStackData = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::lastClipStackData(const SkPath& devPath) {
|
|
|
|
if (fCalledAddStackData) {
|
|
|
|
fClipStackData.appendf("<br>");
|
|
|
|
addPathData(devPath, "pathOut");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|