skia2/include/utils/SkDumpCanvas.h
Mike Reed 1eb3fef136 Revert "More SkVertices implementation work"
This reverts commit 14583e11fd.

Reason for revert: leaking

Direct leak of 499104 byte(s) in 2112 object(s) allocated from:
    #0 0x1e195f0 in operator new(unsigned long) (/b/swarm_slave/w/irazbR79/out/Debug/dm+0x1e195f0)
    #1 0x3142b0a in SkVertices::Builder::init(SkCanvas::VertexMode, int, int, SkVertices::Sizes const&) (/b/swarm_slave/w/irazbR79/out/Debug/dm+0x3142b0a)


Original change's description:
> More SkVertices implementation work
> 
> - change virtuals to take const SkVertices*, as we do for TextBobs and Images
> - override onDrawVerticesObject in recording canvases
> - deserialize raw-vertices into SkVertices object
> 
> Possibly a follow-on would intercept the raw-form directly in canvas,
> and remove the virtual, and only support the object form.
> 
> BUG=skia:6366
> 
> Change-Id: I57a932667ccb3b3b004beb802ac3ae6898e3c6e0
> Reviewed-on: https://skia-review.googlesource.com/9633
> Commit-Queue: Mike Reed <reed@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> 

TBR=bsalomon@google.com,reed@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:6366

Change-Id: I40bb7a20698ef6aa0a9ef71a3d6ac4c1473e081c
Reviewed-on: https://skia-review.googlesource.com/9825
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-03-17 13:09:52 +00:00

174 lines
6.2 KiB
C++

/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkDumpCanvas_DEFINED
#define SkDumpCanvas_DEFINED
#include "SkCanvas.h"
#include "SkVertices.h"
/** This class overrides all the draw methods on SkCanvas, and formats them
as text, and then sends that to a Dumper helper object.
Typical use might be to dump a display list to a log file to see what is
being drawn.
*/
class SkDumpCanvas : public SkCanvas {
public:
class Dumper;
explicit SkDumpCanvas(Dumper* = 0);
virtual ~SkDumpCanvas();
enum Verb {
kNULL_Verb,
kSave_Verb,
kRestore_Verb,
kMatrix_Verb,
kClip_Verb,
kDrawPaint_Verb,
kDrawPoints_Verb,
kDrawOval_Verb,
kDrawArc_Verb,
kDrawRect_Verb,
kDrawRRect_Verb,
kDrawDRRect_Verb,
kDrawPath_Verb,
kDrawBitmap_Verb,
kDrawText_Verb,
kDrawPicture_Verb,
kDrawVertices_Verb,
kDrawPatch_Verb,
kDrawData_Verb, // obsolete
kDrawAnnotation_Verb,
kCull_Verb
};
/** Subclasses of this are installed on the DumpCanvas, and then called for
each drawing command.
*/
class Dumper : public SkRefCnt {
public:
virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
const SkPaint*) = 0;
private:
typedef SkRefCnt INHERITED;
};
Dumper* getDumper() const { return fDumper; }
void setDumper(Dumper*);
int getNestLevel() const { return fNestLevel; }
protected:
void willSave() override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;
void didSetMatrix(const SkMatrix&) override;
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint&) override;
virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
const SkPaint&) override;
virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
SkScalar constY, const SkPaint&) override;
virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
const SkMatrix* matrix, const SkPaint&) override;
void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
const SkRect* cull, const SkPaint& paint) override;
virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) override;
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], SkBlendMode,
const SkPaint& paint) override;
void onDrawPaint(const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;
void onDrawPath(const SkPath&, const SkPaint&) override;
void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
SrcRectConstraint) override;
void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint*, SrcRectConstraint) override;
void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
const SkPaint*) override;
void onDrawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkBlendMode,
const uint16_t indices[], int indexCount,
const SkPaint&) override;
void onDrawVerticesObject(sk_sp<SkVertices> vertices, SkBlendMode mode, const SkPaint& paint,
uint32_t flags) override {
this->onDrawVerticesObjectFallback(std::move(vertices), mode, paint, flags);
}
void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
void onClipRegion(const SkRegion&, SkClipOp) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
private:
Dumper* fDumper;
int fNestLevel; // for nesting recursive elements like pictures
void dump(Verb, const SkPaint*, const char format[], ...);
typedef SkCanvas INHERITED;
};
/** Formats the draw commands, and send them to a function-pointer provided
by the caller.
*/
class SkFormatDumper : public SkDumpCanvas::Dumper {
public:
SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
// override from baseclass that does the formatting, and in turn calls
// the function pointer that was passed to the constructor
virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
const SkPaint*) override;
private:
void (*fProc)(const char*, void*);
void* fRefcon;
typedef SkDumpCanvas::Dumper INHERITED;
};
/** Subclass of Dumper that dumps the drawing command to SkDebugf
*/
class SkDebugfDumper : public SkFormatDumper {
public:
SkDebugfDumper();
private:
typedef SkFormatDumper INHERITED;
};
#endif