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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-02-06 20:13:54 +00:00
|
|
|
#include "SkColorPriv.h"
|
2012-06-29 14:21:22 +00:00
|
|
|
#include "SkDebugCanvas.h"
|
|
|
|
#include "SkDrawCommand.h"
|
2013-02-06 20:13:54 +00:00
|
|
|
#include "SkDrawFilter.h"
|
2012-11-21 17:11:02 +00:00
|
|
|
#include "SkDevice.h"
|
2013-02-06 20:13:54 +00:00
|
|
|
#include "SkXfermode.h"
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-01-08 20:31:53 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
// iostream includes xlocale which generates warning 4530 because we're compiling without
|
|
|
|
// exceptions
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4530)
|
|
|
|
#endif
|
|
|
|
#include <iostream>
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2012-09-26 13:44:13 +00:00
|
|
|
static SkBitmap make_noconfig_bm(int width, int height) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.setConfig(SkBitmap::kNo_Config, width, height);
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugCanvas::SkDebugCanvas(int width, int height)
|
2012-11-27 16:09:42 +00:00
|
|
|
: INHERITED(make_noconfig_bm(width, height))
|
2013-02-06 20:13:54 +00:00
|
|
|
, fOverdrawViz(false)
|
2013-02-08 21:16:19 +00:00
|
|
|
, fOverdrawFilter(NULL)
|
|
|
|
, fOutstandingSaveCount(0) {
|
2012-06-29 14:21:22 +00:00
|
|
|
// TODO(chudy): Free up memory from all draw commands in destructor.
|
2012-07-30 18:54:07 +00:00
|
|
|
fWidth = width;
|
|
|
|
fHeight = height;
|
2012-09-26 13:44:13 +00:00
|
|
|
// do we need fBm anywhere?
|
2012-07-10 14:14:50 +00:00
|
|
|
fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight);
|
2012-06-29 14:21:22 +00:00
|
|
|
fFilter = false;
|
2012-08-01 15:57:52 +00:00
|
|
|
fIndex = 0;
|
2013-01-17 16:30:56 +00:00
|
|
|
fUserMatrix.reset();
|
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();
|
2013-02-06 20:13:54 +00:00
|
|
|
SkSafeUnref(fOverdrawFilter);
|
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-01-02 20:20:31 +00:00
|
|
|
if(!fCommandVector.isEmpty()) {
|
|
|
|
for (int i = 0; i < fCommandVector.count(); i++) {
|
|
|
|
if (fCommandVector[i]->isVisible()) {
|
|
|
|
fCommandVector[i]->execute(canvas);
|
2012-07-28 20:16:11 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-02 20:20:31 +00:00
|
|
|
fIndex = 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;
|
|
|
|
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
|
|
|
|
bitmap.allocPixels();
|
|
|
|
|
|
|
|
SkCanvas canvas(bitmap);
|
2012-09-06 18:43:21 +00:00
|
|
|
canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
|
2012-08-01 15:57:52 +00:00
|
|
|
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()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-06 21:44:21 +00:00
|
|
|
static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) {
|
2013-02-06 20:13:54 +00:00
|
|
|
// This table encodes the color progression of the overdraw visualization
|
|
|
|
static const SkPMColor gTable[] = {
|
|
|
|
SkPackARGB32(0x00, 0x00, 0x00, 0x00),
|
|
|
|
SkPackARGB32(0xFF, 128, 158, 255),
|
|
|
|
SkPackARGB32(0xFF, 170, 185, 212),
|
|
|
|
SkPackARGB32(0xFF, 213, 195, 170),
|
|
|
|
SkPackARGB32(0xFF, 255, 192, 127),
|
|
|
|
SkPackARGB32(0xFF, 255, 185, 85),
|
|
|
|
SkPackARGB32(0xFF, 255, 165, 42),
|
|
|
|
SkPackARGB32(0xFF, 255, 135, 0),
|
|
|
|
SkPackARGB32(0xFF, 255, 95, 0),
|
|
|
|
SkPackARGB32(0xFF, 255, 50, 0),
|
|
|
|
SkPackARGB32(0xFF, 255, 0, 0)
|
|
|
|
};
|
|
|
|
|
2013-02-06 20:42:14 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) {
|
2013-02-06 20:13:54 +00:00
|
|
|
if (gTable[i] == dst) {
|
|
|
|
return gTable[i+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gTable[SK_ARRAY_COUNT(gTable)-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The OverdrawFilter modifies every paint to use an SkProcXfermode which
|
|
|
|
// in turn invokes OverdrawXferModeProc
|
|
|
|
class OverdrawFilter : public SkDrawFilter {
|
|
|
|
public:
|
|
|
|
OverdrawFilter() {
|
|
|
|
fXferMode = new SkProcXfermode(OverdrawXferModeProc);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~OverdrawFilter() {
|
|
|
|
delete fXferMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
|
|
|
|
p->setXfermode(fXferMode);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkXfermode* fXferMode;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkDrawFilter INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-07-31 19:55:32 +00:00
|
|
|
void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkASSERT(!fCommandVector.isEmpty());
|
|
|
|
SkASSERT(index < fCommandVector.count());
|
2012-08-01 15:57:52 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
// This only works assuming the canvas and device are the same ones that
|
|
|
|
// were previously drawn into because they need to preserve all saves
|
|
|
|
// and restores.
|
|
|
|
if (fIndex < index) {
|
|
|
|
i = fIndex + 1;
|
|
|
|
} else {
|
2012-11-27 16:09:42 +00:00
|
|
|
for (int j = 0; j < fOutstandingSaveCount; j++) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-08-01 15:57:52 +00:00
|
|
|
i = 0;
|
2012-12-06 21:47:40 +00:00
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
2012-08-01 15:57:52 +00:00
|
|
|
canvas->resetMatrix();
|
2012-09-07 02:01:30 +00:00
|
|
|
SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
|
2012-09-06 18:43:21 +00:00
|
|
|
SkIntToScalar(fHeight));
|
2012-08-14 19:38:31 +00:00
|
|
|
canvas->clipRect(rect, SkRegion::kReplace_Op );
|
2012-08-01 15:57:52 +00:00
|
|
|
applyUserTransform(canvas);
|
2012-11-27 16:09:42 +00:00
|
|
|
fOutstandingSaveCount = 0;
|
2013-02-06 20:13:54 +00:00
|
|
|
|
|
|
|
// The setting of the draw filter has to go here (rather than in
|
|
|
|
// SkRasterWidget) due to the canvas restores this class performs.
|
|
|
|
// Since the draw filter is stored in the layer stack if we
|
|
|
|
// call setDrawFilter on anything but the root layer odd things happen
|
|
|
|
if (fOverdrawViz) {
|
|
|
|
if (NULL == fOverdrawFilter) {
|
|
|
|
fOverdrawFilter = new OverdrawFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fOverdrawFilter != canvas->getDrawFilter()) {
|
|
|
|
canvas->setDrawFilter(fOverdrawFilter);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
canvas->setDrawFilter(NULL);
|
|
|
|
}
|
2012-08-01 15:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (; i <= index; i++) {
|
2012-07-31 19:55:32 +00:00
|
|
|
if (i == index && fFilter) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(0xAAFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
canvas->resetMatrix();
|
|
|
|
SkRect mask;
|
|
|
|
mask.set(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(fWidth), SkIntToScalar(fHeight));
|
|
|
|
canvas->clipRect(mask, SkRegion::kReplace_Op, false);
|
|
|
|
canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
if (fCommandVector[i]->isVisible()) {
|
|
|
|
fCommandVector[i]->execute(canvas);
|
|
|
|
fCommandVector[i]->trackSaveState(&fOutstandingSaveCount);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-03 17:32:05 +00:00
|
|
|
fMatrix = canvas->getTotalMatrix();
|
|
|
|
fClip = canvas->getTotalClip().getBounds();
|
2012-08-01 15:57:52 +00:00
|
|
|
fIndex = 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
|
|
|
}
|
|
|
|
|
2012-08-07 20:41:37 +00:00
|
|
|
SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(chudy): Free command string memory.
|
2012-11-19 20:44:29 +00:00
|
|
|
SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const {
|
2013-01-02 20:20:31 +00:00
|
|
|
SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count());
|
|
|
|
if (!fCommandVector.isEmpty()) {
|
|
|
|
for (int i = 0; i < fCommandVector.count(); i ++) {
|
|
|
|
commandString->push_back() = fCommandVector[i]->toString();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return commandString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::toggleFilter(bool toggle) {
|
|
|
|
fFilter = toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::clear(SkColor color) {
|
|
|
|
addDrawCommand(new Clear(color));
|
|
|
|
}
|
|
|
|
|
2012-11-21 17:11:02 +00:00
|
|
|
static SkBitmap createBitmap(const SkPath& path) {
|
|
|
|
SkBitmap bitmap;
|
2012-11-22 02:02:41 +00:00
|
|
|
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
2013-01-31 15:56:22 +00:00
|
|
|
SkDebugCanvas::kVizImageWidth,
|
|
|
|
SkDebugCanvas::kVizImageHeight);
|
2012-11-21 17:11:02 +00:00
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorWHITE);
|
|
|
|
SkDevice* device = new SkDevice(bitmap);
|
|
|
|
|
|
|
|
SkCanvas canvas(device);
|
|
|
|
device->unref();
|
|
|
|
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
|
|
|
|
if (bounds.width() > bounds.height()) {
|
2013-01-31 15:56:22 +00:00
|
|
|
canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.width()),
|
|
|
|
SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.width()));
|
2012-11-21 17:11:02 +00:00
|
|
|
} else {
|
2013-01-31 15:56:22 +00:00
|
|
|
canvas.scale(SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageWidth)/bounds.height()),
|
|
|
|
SkDoubleToScalar((0.9*SkDebugCanvas::kVizImageHeight)/bounds.height()));
|
2012-11-21 17:11:02 +00:00
|
|
|
}
|
|
|
|
canvas.translate(-bounds.fLeft+2, -bounds.fTop+2);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas.drawPath(path, p);
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2012-11-26 13:09:17 +00:00
|
|
|
static SkBitmap createBitmap(const SkBitmap& input, const SkRect* srcRect) {
|
|
|
|
SkBitmap bitmap;
|
2012-11-27 02:01:19 +00:00
|
|
|
bitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
2013-01-31 15:56:22 +00:00
|
|
|
SkDebugCanvas::kVizImageWidth,
|
|
|
|
SkDebugCanvas::kVizImageHeight);
|
2012-11-26 13:09:17 +00:00
|
|
|
bitmap.allocPixels();
|
|
|
|
bitmap.eraseColor(SK_ColorLTGRAY);
|
|
|
|
SkDevice* device = new SkDevice(bitmap);
|
|
|
|
|
|
|
|
SkCanvas canvas(device);
|
|
|
|
device->unref();
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
SkScalar xScale = SkIntToScalar(SkDebugCanvas::kVizImageWidth-2) / input.width();
|
|
|
|
SkScalar yScale = SkIntToScalar(SkDebugCanvas::kVizImageHeight-2) / input.height();
|
2012-11-26 13:09:17 +00:00
|
|
|
|
|
|
|
if (input.width() > input.height()) {
|
|
|
|
yScale *= input.height() / (float) input.width();
|
|
|
|
} else {
|
|
|
|
xScale *= input.width() / (float) input.height();
|
|
|
|
}
|
|
|
|
|
2012-11-27 02:01:19 +00:00
|
|
|
SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
|
2012-11-26 13:09:17 +00:00
|
|
|
xScale * input.width(),
|
|
|
|
yScale * input.height());
|
|
|
|
|
|
|
|
canvas.drawBitmapRect(input, NULL, dst);
|
|
|
|
|
|
|
|
if (NULL != srcRect) {
|
|
|
|
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
|
|
|
|
srcRect->fTop * yScale + SK_Scalar1,
|
|
|
|
srcRect->fRight * xScale + SK_Scalar1,
|
|
|
|
srcRect->fBottom * yScale + SK_Scalar1);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas.drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
|
2012-11-21 18:37:58 +00:00
|
|
|
SkBitmap bitmap = createBitmap(path);
|
|
|
|
addDrawCommand(new ClipPath(path, op, doAA, bitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
|
|
|
|
addDrawCommand(new ClipRect(rect, op, doAA));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
|
|
|
|
addDrawCommand(new ClipRRect(rrect, op, doAA));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) {
|
|
|
|
addDrawCommand(new ClipRegion(region, op));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::concat(const SkMatrix& matrix) {
|
|
|
|
addDrawCommand(new Concat(matrix));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
|
|
|
|
SkScalar top, const SkPaint* paint = NULL) {
|
2012-11-26 13:09:17 +00:00
|
|
|
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
|
|
|
addDrawCommand(new DrawBitmap(bitmap, left, top, paint, resizedBitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 15:14:33 +00:00
|
|
|
void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap,
|
|
|
|
const SkRect* src, const SkRect& dst, const SkPaint* paint) {
|
2012-11-26 13:09:17 +00:00
|
|
|
SkBitmap resizedBitmap = createBitmap(bitmap, src);
|
|
|
|
addDrawCommand(new DrawBitmapRect(bitmap, src, dst, paint, resizedBitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
|
|
|
|
const SkMatrix& matrix, const SkPaint* paint) {
|
2012-11-26 13:09:17 +00:00
|
|
|
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
|
|
|
addDrawCommand(new DrawBitmapMatrix(bitmap, matrix, paint, resizedBitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap,
|
|
|
|
const SkIRect& center, const SkRect& dst, const SkPaint* paint) {
|
2012-11-26 13:09:17 +00:00
|
|
|
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
|
|
|
addDrawCommand(new DrawBitmapNine(bitmap, center, dst, paint, resizedBitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawData(const void* data, size_t length) {
|
|
|
|
addDrawCommand(new DrawData(data, length));
|
|
|
|
}
|
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawOval(oval, paint));
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
void SkDebugCanvas::drawPaint(const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawPaint(paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
|
2012-11-21 18:37:58 +00:00
|
|
|
SkBitmap bitmap = createBitmap(path);
|
|
|
|
addDrawCommand(new DrawPath(path, paint, bitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawPicture(SkPicture& picture) {
|
|
|
|
addDrawCommand(new DrawPicture(picture));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawPoints(PointMode mode, size_t count,
|
|
|
|
const SkPoint pts[], const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawPoints(mode, count, pts, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawPosText(const void* text, size_t byteLength,
|
|
|
|
const SkPoint pos[], const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawPosText(text, byteLength, pos, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength,
|
|
|
|
const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawPosTextH(text, byteLength, xpos, constY, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
|
|
|
|
// NOTE(chudy): Messing up when renamed to DrawRect... Why?
|
|
|
|
addDrawCommand(new DrawRectC(rect, paint));
|
|
|
|
}
|
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawRRect(rrect, paint));
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
|
|
|
|
const SkPaint* paint = NULL) {
|
2012-11-26 13:09:17 +00:00
|
|
|
SkBitmap resizedBitmap = createBitmap(bitmap, NULL);
|
|
|
|
addDrawCommand(new DrawSprite(bitmap, left, top, paint, resizedBitmap));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
|
|
|
|
SkScalar y, const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawTextC(text, byteLength, x, y, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength,
|
|
|
|
const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawTextOnPath(text, byteLength, path, matrix, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount,
|
|
|
|
const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
|
|
|
|
SkXfermode*, const uint16_t indices[], int indexCount,
|
|
|
|
const SkPaint& paint) {
|
|
|
|
addDrawCommand(new DrawVertices(vmode, vertexCount, vertices, texs, colors,
|
|
|
|
NULL, indices, indexCount, paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::restore() {
|
|
|
|
addDrawCommand(new Restore());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::rotate(SkScalar degrees) {
|
|
|
|
addDrawCommand(new Rotate(degrees));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SkDebugCanvas::save(SaveFlags flags) {
|
|
|
|
addDrawCommand(new Save(flags));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
|
|
|
|
SaveFlags flags) {
|
|
|
|
addDrawCommand(new SaveLayer(bounds, paint, flags));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) {
|
|
|
|
addDrawCommand(new Scale(sx, sy));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDebugCanvas::setMatrix(const SkMatrix& matrix) {
|
|
|
|
addDrawCommand(new SetMatrix(matrix));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::skew(SkScalar sx, SkScalar sy) {
|
|
|
|
addDrawCommand(new Skew(sx, sy));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) {
|
|
|
|
addDrawCommand(new Translate(dx, dy));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|