[SkDebugger] Flatten drawPicture ops
Add two drawPicture bracketing ops (BeginDrawPicture, EndDrawPicture) to replace the current DrawPicture op, and flatten picture contents. Review URL: https://codereview.chromium.org/1048383002
This commit is contained in:
parent
82973dbf4f
commit
160ebb2bfa
@ -783,7 +783,10 @@ void SkDebuggerGUI::setupListWidget() {
|
|||||||
SkDrawCommand::GetCommandString(SkDrawCommand::kBeginCommentGroup_OpType)));
|
SkDrawCommand::GetCommandString(SkDrawCommand::kBeginCommentGroup_OpType)));
|
||||||
SkASSERT(!strcmp("EndCommentGroup",
|
SkASSERT(!strcmp("EndCommentGroup",
|
||||||
SkDrawCommand::GetCommandString(SkDrawCommand::kEndCommentGroup_OpType)));
|
SkDrawCommand::GetCommandString(SkDrawCommand::kEndCommentGroup_OpType)));
|
||||||
|
SkASSERT(!strcmp("BeginDrawPicture",
|
||||||
|
SkDrawCommand::GetCommandString(SkDrawCommand::kBeginDrawPicture_OpType)));
|
||||||
|
SkASSERT(!strcmp("EndDrawPicture",
|
||||||
|
SkDrawCommand::GetCommandString(SkDrawCommand::kEndDrawPicture_OpType)));
|
||||||
|
|
||||||
fListWidget.clear();
|
fListWidget.clear();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
@ -796,7 +799,8 @@ void SkDebuggerGUI::setupListWidget() {
|
|||||||
item->setData(Qt::UserRole + 1, counter++);
|
item->setData(Qt::UserRole + 1, counter++);
|
||||||
|
|
||||||
if (0 == strcmp("Restore", commandString.c_str()) ||
|
if (0 == strcmp("Restore", commandString.c_str()) ||
|
||||||
0 == strcmp("EndCommentGroup", commandString.c_str())) {
|
0 == strcmp("EndCommentGroup", commandString.c_str()) ||
|
||||||
|
0 == strcmp("EndDrawPicture", commandString.c_str())) {
|
||||||
indent -= 10;
|
indent -= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,7 +808,8 @@ void SkDebuggerGUI::setupListWidget() {
|
|||||||
|
|
||||||
if (0 == strcmp("Save", commandString.c_str()) ||
|
if (0 == strcmp("Save", commandString.c_str()) ||
|
||||||
0 == strcmp("SaveLayer", commandString.c_str()) ||
|
0 == strcmp("SaveLayer", commandString.c_str()) ||
|
||||||
0 == strcmp("BeginCommentGroup", commandString.c_str())) {
|
0 == strcmp("BeginCommentGroup", commandString.c_str()) ||
|
||||||
|
0 == strcmp("BeginDrawPicture", commandString.c_str())) {
|
||||||
indent += 10;
|
indent += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +459,9 @@ void SkDebugCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
|
|||||||
void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
|
void SkDebugCanvas::onDrawPicture(const SkPicture* picture,
|
||||||
const SkMatrix* matrix,
|
const SkMatrix* matrix,
|
||||||
const SkPaint* paint) {
|
const SkPaint* paint) {
|
||||||
this->addDrawCommand(new SkDrawPictureCommand(picture, matrix, paint));
|
this->addDrawCommand(new SkBeginDrawPictureCommand(picture, matrix, paint));
|
||||||
|
this->INHERITED::onDrawPicture(picture, matrix, paint);
|
||||||
|
this->addDrawCommand(new SkEndDrawPictureCommand(SkToBool(matrix) || SkToBool(paint)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
|
void SkDebugCanvas::onDrawPoints(PointMode mode, size_t count,
|
||||||
|
@ -26,6 +26,7 @@ SkDrawCommand::~SkDrawCommand() {
|
|||||||
const char* SkDrawCommand::GetCommandString(OpType type) {
|
const char* SkDrawCommand::GetCommandString(OpType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case kBeginCommentGroup_OpType: return "BeginCommentGroup";
|
case kBeginCommentGroup_OpType: return "BeginCommentGroup";
|
||||||
|
case kBeginDrawPicture_OpType: return "BeginDrawPicture";
|
||||||
case kClipPath_OpType: return "ClipPath";
|
case kClipPath_OpType: return "ClipPath";
|
||||||
case kClipRegion_OpType: return "ClipRegion";
|
case kClipRegion_OpType: return "ClipRegion";
|
||||||
case kClipRect_OpType: return "ClipRect";
|
case kClipRect_OpType: return "ClipRect";
|
||||||
@ -41,7 +42,6 @@ const char* SkDrawCommand::GetCommandString(OpType type) {
|
|||||||
case kDrawPaint_OpType: return "DrawPaint";
|
case kDrawPaint_OpType: return "DrawPaint";
|
||||||
case kDrawPatch_OpType: return "DrawPatch";
|
case kDrawPatch_OpType: return "DrawPatch";
|
||||||
case kDrawPath_OpType: return "DrawPath";
|
case kDrawPath_OpType: return "DrawPath";
|
||||||
case kDrawPicture_OpType: return "DrawPicture";
|
|
||||||
case kDrawPoints_OpType: return "DrawPoints";
|
case kDrawPoints_OpType: return "DrawPoints";
|
||||||
case kDrawPosText_OpType: return "DrawPosText";
|
case kDrawPosText_OpType: return "DrawPosText";
|
||||||
case kDrawPosTextH_OpType: return "DrawPosTextH";
|
case kDrawPosTextH_OpType: return "DrawPosTextH";
|
||||||
@ -53,6 +53,7 @@ const char* SkDrawCommand::GetCommandString(OpType type) {
|
|||||||
case kDrawTextOnPath_OpType: return "DrawTextOnPath";
|
case kDrawTextOnPath_OpType: return "DrawTextOnPath";
|
||||||
case kDrawVertices_OpType: return "DrawVertices";
|
case kDrawVertices_OpType: return "DrawVertices";
|
||||||
case kEndCommentGroup_OpType: return "EndCommentGroup";
|
case kEndCommentGroup_OpType: return "EndCommentGroup";
|
||||||
|
case kEndDrawPicture_OpType: return "EndDrawPicture";
|
||||||
case kRestore_OpType: return "Restore";
|
case kRestore_OpType: return "Restore";
|
||||||
case kSave_OpType: return "Save";
|
case kSave_OpType: return "Save";
|
||||||
case kSaveLayer_OpType: return "SaveLayer";
|
case kSaveLayer_OpType: return "SaveLayer";
|
||||||
@ -445,41 +446,48 @@ bool SkDrawPathCommand::render(SkCanvas* canvas) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDrawPictureCommand::SkDrawPictureCommand(const SkPicture* picture,
|
SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
|
||||||
const SkMatrix* matrix,
|
const SkMatrix* matrix,
|
||||||
const SkPaint* paint)
|
const SkPaint* paint)
|
||||||
: INHERITED(kDrawPicture_OpType)
|
: INHERITED(kBeginDrawPicture_OpType)
|
||||||
, fPicture(SkRef(picture))
|
, fPicture(SkRef(picture)) {
|
||||||
, fMatrixPtr(NULL)
|
|
||||||
, fPaintPtr(NULL) {
|
SkString* str = new SkString;
|
||||||
|
str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
|
||||||
|
picture->cullRect().fLeft, picture->cullRect().fTop,
|
||||||
|
picture->cullRect().fRight, picture->cullRect().fBottom);
|
||||||
|
fInfo.push(str);
|
||||||
|
|
||||||
if (matrix) {
|
if (matrix) {
|
||||||
fMatrix = *matrix;
|
fMatrix.set(*matrix);
|
||||||
fMatrixPtr = &fMatrix;
|
|
||||||
}
|
|
||||||
if (paint) {
|
|
||||||
fPaint = *paint;
|
|
||||||
fPaintPtr = &fPaint;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkString* temp = new SkString;
|
|
||||||
temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
|
|
||||||
picture->cullRect().fLeft, picture->cullRect().fTop,
|
|
||||||
picture->cullRect().fRight, picture->cullRect().fBottom);
|
|
||||||
fInfo.push(temp);
|
|
||||||
if (matrix) {
|
|
||||||
fInfo.push(SkObjectParser::MatrixToString(*matrix));
|
fInfo.push(SkObjectParser::MatrixToString(*matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paint) {
|
if (paint) {
|
||||||
|
fPaint.set(*paint);
|
||||||
fInfo.push(SkObjectParser::PaintToString(*paint));
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
|
||||||
|
if (fPaint.isValid()) {
|
||||||
|
SkRect bounds = fPicture->cullRect();
|
||||||
|
if (fMatrix.isValid()) {
|
||||||
|
fMatrix.get()->mapRect(&bounds);
|
||||||
|
}
|
||||||
|
canvas->saveLayer(&bounds, fPaint.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fMatrix.isValid()) {
|
||||||
|
if (!fPaint.isValid()) {
|
||||||
|
canvas->save();
|
||||||
|
}
|
||||||
|
canvas->concat(*fMatrix.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkDrawPictureCommand::execute(SkCanvas* canvas) const {
|
bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
|
||||||
canvas->drawPicture(fPicture, fMatrixPtr, fPaintPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
|
|
||||||
canvas->clear(0xFFFFFFFF);
|
canvas->clear(0xFFFFFFFF);
|
||||||
canvas->save();
|
canvas->save();
|
||||||
|
|
||||||
@ -492,6 +500,15 @@ bool SkDrawPictureCommand::render(SkCanvas* canvas) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
|
||||||
|
: INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
|
||||||
|
|
||||||
|
void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
|
||||||
|
if (fRestore) {
|
||||||
|
canvas->restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
|
SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
|
||||||
const SkPoint pts[], const SkPaint& paint)
|
const SkPoint pts[], const SkPaint& paint)
|
||||||
: INHERITED(kDrawPoints_OpType) {
|
: INHERITED(kDrawPoints_OpType) {
|
||||||
|
@ -16,6 +16,7 @@ class SK_API SkDrawCommand {
|
|||||||
public:
|
public:
|
||||||
enum OpType {
|
enum OpType {
|
||||||
kBeginCommentGroup_OpType,
|
kBeginCommentGroup_OpType,
|
||||||
|
kBeginDrawPicture_OpType,
|
||||||
kClipPath_OpType,
|
kClipPath_OpType,
|
||||||
kClipRegion_OpType,
|
kClipRegion_OpType,
|
||||||
kClipRect_OpType,
|
kClipRect_OpType,
|
||||||
@ -31,7 +32,6 @@ public:
|
|||||||
kDrawPaint_OpType,
|
kDrawPaint_OpType,
|
||||||
kDrawPatch_OpType,
|
kDrawPatch_OpType,
|
||||||
kDrawPath_OpType,
|
kDrawPath_OpType,
|
||||||
kDrawPicture_OpType,
|
|
||||||
kDrawPoints_OpType,
|
kDrawPoints_OpType,
|
||||||
kDrawPosText_OpType,
|
kDrawPosText_OpType,
|
||||||
kDrawPosTextH_OpType,
|
kDrawPosTextH_OpType,
|
||||||
@ -43,6 +43,7 @@ public:
|
|||||||
kDrawTextOnPath_OpType,
|
kDrawTextOnPath_OpType,
|
||||||
kDrawVertices_OpType,
|
kDrawVertices_OpType,
|
||||||
kEndCommentGroup_OpType,
|
kEndCommentGroup_OpType,
|
||||||
|
kEndDrawPicture_OpType,
|
||||||
kRestore_OpType,
|
kRestore_OpType,
|
||||||
kSave_OpType,
|
kSave_OpType,
|
||||||
kSaveLayer_OpType,
|
kSaveLayer_OpType,
|
||||||
@ -337,18 +338,31 @@ private:
|
|||||||
typedef SkDrawCommand INHERITED;
|
typedef SkDrawCommand INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkDrawPictureCommand : public SkDrawCommand {
|
class SkBeginDrawPictureCommand : public SkDrawCommand {
|
||||||
public:
|
public:
|
||||||
SkDrawPictureCommand(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint);
|
SkBeginDrawPictureCommand(const SkPicture* picture,
|
||||||
|
const SkMatrix* matrix,
|
||||||
|
const SkPaint* paint);
|
||||||
|
|
||||||
void execute(SkCanvas* canvas) const override;
|
void execute(SkCanvas* canvas) const override;
|
||||||
bool render(SkCanvas* canvas) const override;
|
bool render(SkCanvas* canvas) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SkAutoTUnref<const SkPicture> fPicture;
|
SkAutoTUnref<const SkPicture> fPicture;
|
||||||
SkMatrix fMatrix;
|
SkTLazy<SkMatrix> fMatrix;
|
||||||
SkMatrix* fMatrixPtr;
|
SkTLazy<SkPaint> fPaint;
|
||||||
SkPaint fPaint;
|
|
||||||
SkPaint* fPaintPtr;
|
typedef SkDrawCommand INHERITED;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SkEndDrawPictureCommand : public SkDrawCommand {
|
||||||
|
public:
|
||||||
|
SkEndDrawPictureCommand(bool restore);
|
||||||
|
|
||||||
|
void execute(SkCanvas* canvas) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool fRestore;
|
||||||
|
|
||||||
typedef SkDrawCommand INHERITED;
|
typedef SkDrawCommand INHERITED;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user