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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SKDEBUGCANVAS_H_
|
|
|
|
#define SKDEBUGCANVAS_H_
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkDrawCommand.h"
|
|
|
|
#include "SkPicture.h"
|
2012-11-19 20:44:29 +00:00
|
|
|
#include "SkTArray.h"
|
2012-08-07 20:41:37 +00:00
|
|
|
#include "SkString.h"
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-10-17 17:56:10 +00:00
|
|
|
class SkTexOverrideFilter;
|
|
|
|
|
2013-06-13 20:59:14 +00:00
|
|
|
class SK_API SkDebugCanvas : public SkCanvas {
|
2012-06-29 14:21:22 +00:00
|
|
|
public:
|
2012-07-30 18:54:07 +00:00
|
|
|
SkDebugCanvas(int width, int height);
|
2013-02-06 20:13:54 +00:00
|
|
|
virtual ~SkDebugCanvas();
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
void toggleFilter(bool toggle);
|
|
|
|
|
2013-02-06 20:13:54 +00:00
|
|
|
/**
|
|
|
|
* Enable or disable overdraw visualization
|
|
|
|
*/
|
|
|
|
void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
|
|
|
|
|
2013-10-17 17:56:10 +00:00
|
|
|
/**
|
|
|
|
* Enable or disable texure filtering override
|
|
|
|
*/
|
2013-10-18 07:01:59 +00:00
|
|
|
void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level);
|
2013-10-17 17:56:10 +00:00
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Executes all draw calls to the canvas.
|
|
|
|
@param canvas The canvas being drawn to
|
|
|
|
*/
|
|
|
|
void draw(SkCanvas* canvas);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Executes the draw calls up to the specified index.
|
|
|
|
@param canvas The canvas being drawn to
|
|
|
|
@param index The index of the final command being executed
|
|
|
|
*/
|
2012-07-31 19:55:32 +00:00
|
|
|
void drawTo(SkCanvas* canvas, int index);
|
|
|
|
|
2012-08-03 17:32:05 +00:00
|
|
|
/**
|
|
|
|
Returns the most recently calculated transformation matrix
|
|
|
|
*/
|
|
|
|
const SkMatrix& getCurrentMatrix() {
|
|
|
|
return fMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the most recently calculated clip
|
|
|
|
*/
|
|
|
|
const SkIRect& getCurrentClip() {
|
|
|
|
return fClip;
|
|
|
|
}
|
|
|
|
|
2012-07-31 19:55:32 +00:00
|
|
|
/**
|
|
|
|
Returns the index of the last draw command to write to the pixel at (x,y)
|
|
|
|
*/
|
2012-08-01 15:57:52 +00:00
|
|
|
int getCommandAtPoint(int x, int y, int index);
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
/**
|
|
|
|
Removes the command at the specified index
|
|
|
|
@param index The index of the command to delete
|
|
|
|
*/
|
|
|
|
void deleteDrawCommandAt(int index);
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Returns the draw command at the given index.
|
|
|
|
@param index The index of the command
|
|
|
|
*/
|
|
|
|
SkDrawCommand* getDrawCommandAt(int index);
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
/**
|
|
|
|
Sets the draw command for a given index.
|
|
|
|
@param index The index to overwrite
|
|
|
|
@param command The new command
|
|
|
|
*/
|
|
|
|
void setDrawCommandAt(int index, SkDrawCommand* command);
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Returns information about the command at the given index.
|
|
|
|
@param index The index of the command
|
|
|
|
*/
|
2012-08-07 20:41:37 +00:00
|
|
|
SkTDArray<SkString*>* getCommandInfo(int index);
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-17 15:40:51 +00:00
|
|
|
/**
|
|
|
|
Returns the visibility of the command at the given index.
|
|
|
|
@param index The index of the command
|
|
|
|
*/
|
|
|
|
bool getDrawCommandVisibilityAt(int index);
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Returns the vector of draw commands
|
|
|
|
*/
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("please use getDrawCommandAt and getSize instead")
|
2012-11-19 20:44:29 +00:00
|
|
|
const SkTDArray<SkDrawCommand*>& getDrawCommands() const;
|
2013-03-12 07:12:32 +00:00
|
|
|
|
2013-03-11 22:53:11 +00:00
|
|
|
/**
|
|
|
|
Returns the vector of draw commands. Do not use this entry
|
|
|
|
point - it is going away!
|
|
|
|
*/
|
|
|
|
SkTDArray<SkDrawCommand*>& getDrawCommands();
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the string vector of draw commands
|
|
|
|
*/
|
2012-11-19 20:44:29 +00:00
|
|
|
SkTArray<SkString>* getDrawCommandsAsStrings() const;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2012-07-03 20:28:14 +00:00
|
|
|
/**
|
|
|
|
Returns length of draw command vector.
|
|
|
|
*/
|
2013-07-15 22:47:14 +00:00
|
|
|
int getSize() const {
|
2013-01-02 20:20:31 +00:00
|
|
|
return fCommandVector.count();
|
2012-07-03 20:28:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Toggles the visibility / execution of the draw command at index i with
|
|
|
|
the value of toggle.
|
|
|
|
*/
|
|
|
|
void toggleCommand(int index, bool toggle);
|
|
|
|
|
2012-07-10 14:14:50 +00:00
|
|
|
void setBounds(int width, int height) {
|
|
|
|
fWidth = width;
|
|
|
|
fHeight = height;
|
|
|
|
}
|
|
|
|
|
2013-01-17 16:30:56 +00:00
|
|
|
void setUserMatrix(SkMatrix matrix) {
|
|
|
|
fUserMatrix = matrix;
|
2012-08-01 15:57:52 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Inherited from SkCanvas
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
virtual void clear(SkColor) SK_OVERRIDE;
|
|
|
|
|
2014-02-28 15:28:02 +00:00
|
|
|
virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool clipRRect(const SkRRect& rrect,
|
|
|
|
SkRegion::Op op = SkRegion::kIntersect_Op,
|
|
|
|
bool doAntiAlias = false) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
|
|
|
|
const SkPaint*) SK_OVERRIDE;
|
|
|
|
|
2012-09-18 15:14:33 +00:00
|
|
|
virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkRect& dst, const SkPaint* paint,
|
|
|
|
DrawBitmapRectFlags flags) SK_OVERRIDE;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
|
|
|
virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
|
|
|
|
const SkPaint*) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
|
|
|
|
const SkRect& dst, const SkPaint*) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawData(const void*, size_t) SK_OVERRIDE;
|
|
|
|
|
2013-05-29 13:24:23 +00:00
|
|
|
virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void endCommentGroup() SK_OVERRIDE;
|
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
|
|
|
|
|
2013-10-22 16:54:15 +00:00
|
|
|
virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
|
|
|
|
const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawPosText(const void* text, size_t byteLength,
|
|
|
|
const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawPosTextH(const void* text, size_t byteLength,
|
2013-01-03 02:01:32 +00:00
|
|
|
const SkScalar xpos[], SkScalar constY,
|
2013-01-02 20:20:31 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-10-22 16:54:15 +00:00
|
|
|
virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
2013-01-02 20:20:31 +00:00
|
|
|
virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
virtual void drawSprite(const SkBitmap&, int left, int top,
|
|
|
|
const SkPaint*) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawText(const void* text, size_t byteLength, SkScalar x,
|
|
|
|
SkScalar y, const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawTextOnPath(const void* text, size_t byteLength,
|
2013-01-02 20:20:31 +00:00
|
|
|
const SkPath& path, const SkMatrix* matrix,
|
2012-06-29 14:21:22 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void drawVertices(VertexMode, int vertexCount,
|
2013-01-02 20:20:31 +00:00
|
|
|
const SkPoint vertices[], const SkPoint texs[],
|
|
|
|
const SkColor colors[], SkXfermode*,
|
|
|
|
const uint16_t indices[], int indexCount,
|
2012-06-29 14:21:22 +00:00
|
|
|
const SkPaint&) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void restore() SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual int save(SaveFlags) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
static const int kVizImageHeight = 256;
|
|
|
|
static const int kVizImageWidth = 256;
|
|
|
|
|
2014-02-21 12:20:45 +00:00
|
|
|
protected:
|
|
|
|
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
|
2014-02-27 17:40:13 +00:00
|
|
|
virtual void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
|
|
|
|
virtual void onPopCull() SK_OVERRIDE;
|
2014-02-21 12:20:45 +00:00
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
private:
|
2013-01-02 20:20:31 +00:00
|
|
|
SkTDArray<SkDrawCommand*> fCommandVector;
|
2012-07-10 14:14:50 +00:00
|
|
|
int fWidth;
|
2013-12-04 13:42:46 +00:00
|
|
|
int fHeight;
|
2012-07-17 15:40:51 +00:00
|
|
|
bool fFilter;
|
2012-08-01 15:57:52 +00:00
|
|
|
int fIndex;
|
2013-01-17 16:30:56 +00:00
|
|
|
SkMatrix fUserMatrix;
|
2012-08-03 17:32:05 +00:00
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkIRect fClip;
|
2013-10-17 17:56:10 +00:00
|
|
|
|
2013-02-06 20:13:54 +00:00
|
|
|
bool fOverdrawViz;
|
|
|
|
SkDrawFilter* fOverdrawFilter;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-10-17 17:56:10 +00:00
|
|
|
bool fOverrideTexFiltering;
|
|
|
|
SkTexOverrideFilter* fTexOverrideFilter;
|
|
|
|
|
2012-11-27 16:09:42 +00:00
|
|
|
/**
|
|
|
|
Number of unmatched save() calls at any point during a draw.
|
|
|
|
If there are any saveLayer() calls outstanding, we need to resolve
|
|
|
|
all of them, which in practice means resolving all save() calls,
|
|
|
|
to avoid corruption of our canvas.
|
|
|
|
*/
|
|
|
|
int fOutstandingSaveCount;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
/**
|
|
|
|
Adds the command to the classes vector of commands.
|
|
|
|
@param command The draw command for execution
|
|
|
|
*/
|
|
|
|
void addDrawCommand(SkDrawCommand* command);
|
2012-08-01 15:57:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Applies any panning and zooming the user has specified before
|
|
|
|
drawing anything else into the canvas.
|
|
|
|
*/
|
|
|
|
void applyUserTransform(SkCanvas* canvas);
|
2013-01-31 15:56:22 +00:00
|
|
|
|
|
|
|
typedef SkCanvas INHERITED;
|
2012-06-29 14:21:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|