remove drawShape from canvas api

git-svn-id: http://skia.googlecode.com/svn/trunk@1723 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-06-27 14:42:15 +00:00
parent 0f1c95cd67
commit 5667afc5cb
23 changed files with 26 additions and 215 deletions

View File

@ -351,14 +351,6 @@ void SkDumpCanvasM::drawTextOnPath(const void* text, size_t byteLength,
str.c_str(), byteLength);
}
void SkDumpCanvasM::drawShape(SkShape* shape) {
this->dump(kDrawShape_Verb, NULL, "drawShape(%p)", shape);
fNestLevel += 1;
this->INHERITED::drawShape(shape);
fNestLevel -= 1;
this->dump(kDrawShape_Verb, NULL, "endShape(%p)", shape);
}
void SkDumpCanvasM::drawPicture(SkPicture& picture) {
this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", &picture,
picture.width(), picture.height());

View File

@ -33,7 +33,6 @@ public:
kDrawBitmap_Verb,
kDrawText_Verb,
kDrawPicture_Verb,
kDrawShape_Verb,
kDrawVertices_Verb,
kDrawData_Verb
};
@ -97,7 +96,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
virtual void drawPicture(SkPicture&);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,

View File

@ -95,16 +95,14 @@ protected:
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 0
canvas->drawShape(gs);
#else
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
cv->drawShape(gs);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
cv->drawShape(gs);
gs->draw(cv);
pict->endRecording();
canvas->drawPicture(*pict);
pict->unref();

View File

@ -34,7 +34,6 @@ class SkDeviceFactory;
class SkDraw;
class SkDrawFilter;
class SkPicture;
class SkShape;
/** \class SkCanvas
@ -63,7 +62,7 @@ public:
*/
explicit SkCanvas(SkDeviceFactory* factory = NULL);
/** Construct a canvas with the specified device to draw into. The device
/** Construct a canvas with the specified device to draw into. The device
factory will be retrieved from the passed device.
@param device Specifies a device for the canvas to draw into.
@ -677,10 +676,6 @@ public:
*/
virtual void drawPicture(SkPicture& picture);
/** Draws the specified shape
*/
virtual void drawShape(SkShape*);
enum VertexMode {
kTriangles_VertexMode,
kTriangleStrip_VertexMode,

View File

@ -137,9 +137,15 @@ public:
/** Returns a SkStream with the page contents. The caller is responsible
for a reference to the returned value.
DEPRECATED: use copyContentToData()
*/
SK_API SkStream* content() const;
/** Returns a SkStream with the page contents. The caller is responsible
* for calling data->unref() when it is finished.
*/
SK_API SkData* copyContentToData() const;
SK_API const SkMatrix& initialTransform() const {
return fInitialTransform;
}

View File

@ -33,7 +33,6 @@ public:
kDrawBitmap_Verb,
kDrawText_Verb,
kDrawPicture_Verb,
kDrawShape_Verb,
kDrawVertices_Verb,
kDrawData_Verb
};
@ -97,7 +96,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
virtual void drawPicture(SkPicture&);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,

View File

@ -57,7 +57,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
virtual void drawPicture(SkPicture&);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,

View File

@ -64,7 +64,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
virtual void drawPicture(SkPicture&);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,

View File

@ -14,7 +14,6 @@
#include "SkUtils.h"
#include "SkColorPriv.h"
#include "SkColorFilter.h"
#include "SkShape.h"
#include "SkTime.h"
#include "SkTypeface.h"
#include "SkXfermode.h"
@ -22,67 +21,6 @@
#include "SkStream.h"
#include "SkXMLParser.h"
class SignalShape : public SkShape {
public:
SignalShape() : fSignal(0) {}
SkShape* setSignal(int n) {
fSignal = n;
return this;
}
protected:
virtual void onDraw(SkCanvas* canvas) {
// SkDebugf("---- sc %d\n", canvas->getSaveCount() - 1);
}
private:
int fSignal;
};
static SkPMColor SignalProc(SkPMColor src, SkPMColor dst) {
return dst;
}
/* Picture playback will skip blocks of draw calls that follow a clip() call
that returns empty, and jump down to the corresponding restore() call.
This is a great preformance win for drawing very large/tall pictures with
a small visible window (think scrolling a long document). These tests make
sure that (a) we are performing the culling, and (b) we don't get confused
by nested save() calls, nor by calls to restoreToCount().
*/
static void test_saveRestoreCulling() {
SkPaint signalPaint;
SignalShape signalShape;
SkPicture pic;
SkRect r = SkRect::MakeWH(0, 0);
int n;
SkCanvas* canvas = pic.beginRecording(100, 100);
int startN = canvas->getSaveCount();
SkDebugf("---- start sc %d\n", startN);
canvas->drawShape(signalShape.setSignal(1));
canvas->save();
canvas->drawShape(signalShape.setSignal(2));
n = canvas->save();
canvas->drawShape(signalShape.setSignal(3));
canvas->save();
canvas->clipRect(r);
canvas->drawShape(signalShape.setSignal(4));
canvas->restoreToCount(n);
canvas->drawShape(signalShape.setSignal(5));
canvas->restore();
canvas->drawShape(signalShape.setSignal(6));
SkASSERT(canvas->getSaveCount() == startN);
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
bm.allocPixels();
SkCanvas c(bm);
c.drawPicture(pic);
}
///////////////////////////////////////////////////////////////////////////////
#include "SkImageRef_GlobalPool.h"
@ -137,8 +75,6 @@ public:
// unref fPicture in our destructor, and it will in turn take care of
// the other references to fSubPicture
fSubPicture->unref();
test_saveRestoreCulling();
}
virtual ~PictureView() {

View File

@ -127,16 +127,14 @@ protected:
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
gs->appendShape(&fGroup, matrix);
#if 0
canvas->drawShape(gs);
#else
#if 1
SkPicture* pict = new SkPicture;
SkCanvas* cv = pict->beginRecording(1000, 1000);
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
cv->drawShape(gs);
gs->draw(cv);
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
cv->scale(-SK_Scalar1, SK_Scalar1);
cv->drawShape(gs);
gs->draw(cv);
pict->endRecording();
drawpicture(canvas, *pict);

View File

@ -22,7 +22,6 @@
#include "SkDrawLooper.h"
#include "SkPicture.h"
#include "SkScalarCompare.h"
#include "SkShape.h"
#include "SkTemplates.h"
#include "SkTLazy.h"
#include "SkUtils.h"
@ -1646,11 +1645,6 @@ void SkCanvas::drawPicture(SkPicture& picture) {
restoreToCount(saveCount);
}
void SkCanvas::drawShape(SkShape* shape) {
// shape baseclass takes care of save/restore
shape->draw(this);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

View File

@ -28,7 +28,6 @@ enum DrawType {
DRAW_POS_TEXT_H,
DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H
DRAW_RECT,
DRAW_SHAPE,
DRAW_SPRITE,
DRAW_TEXT,
DRAW_TEXT_ON_PATH,

View File

@ -120,17 +120,6 @@ SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record) {
}
}
const SkTDArray<SkShape* >& shapes = record.getShapes();
fShapeCount = shapes.count();
if (fShapeCount > 0) {
fShapes = SkNEW_ARRAY(SkShape*, fShapeCount);
for (int i = 0; i < fShapeCount; i++) {
SkShape* s = shapes[i];
SkSafeRef(s);
fShapes[i] = s;
}
}
const SkTDArray<const SkFlatRegion* >& regions = record.getRegions();
fRegionCount = regions.count();
if (fRegionCount > 0) {
@ -203,14 +192,6 @@ SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src) {
fPictureRefs[i]->ref();
}
fShapeCount = src.fShapeCount;
fShapes = SkNEW_ARRAY(SkShape*, fShapeCount);
for (int i = 0; i < fShapeCount; i++) {
SkShape* s = src.fShapes[i];
SkSafeRef(s);
fShapes[i] = s;
}
fRegionCount = src.fRegionCount;
fRegions = SkNEW_ARRAY(SkRegion, fRegionCount);
for (i = 0; i < fRegionCount; i++) {
@ -224,10 +205,9 @@ void SkPicturePlayback::init() {
fPaints = NULL;
fPathHeap = NULL;
fPictureRefs = NULL;
fShapes = NULL;
fRegions = NULL;
fBitmapCount = fMatrixCount = fPaintCount = fPictureCount =
fRegionCount = fShapeCount = 0;
fRegionCount = 0;
fFactoryPlayback = NULL;
}
@ -247,11 +227,6 @@ SkPicturePlayback::~SkPicturePlayback() {
}
SkDELETE_ARRAY(fPictureRefs);
for (int i = 0; i < fShapeCount; i++) {
SkSafeUnref(fShapes[i]);
}
SkDELETE_ARRAY(fShapes);
SkDELETE(fFactoryPlayback);
}
@ -281,7 +256,6 @@ void SkPicturePlayback::dumpSize() const {
#define PICT_PAINT_TAG SkSetFourByteTag('p', 'n', 't', ' ')
#define PICT_PATH_TAG SkSetFourByteTag('p', 't', 'h', ' ')
#define PICT_REGION_TAG SkSetFourByteTag('r', 'g', 'n', ' ')
#define PICT_SHAPE_TAG SkSetFourByteTag('s', 'h', 'p', ' ')
#include "SkStream.h"
@ -378,11 +352,6 @@ void SkPicturePlayback::serialize(SkWStream* stream) const {
buffer.writePad(storage.get(), size);
}
writeTagSize(buffer, PICT_SHAPE_TAG, fShapeCount);
for (i = 0; i < fShapeCount; i++) {
buffer.writeFlattenable(fShapes[i]);
}
// now we can write to the stream again
writeFactories(stream, factSet);
@ -491,12 +460,6 @@ SkPicturePlayback::SkPicturePlayback(SkStream* stream) {
SkDEBUGCODE(uint32_t bytes =) fRegions[i].unflatten(buffer.skip(size));
SkASSERT(size == bytes);
}
fShapeCount = readTagSize(buffer, PICT_SHAPE_TAG);
fShapes = SkNEW_ARRAY(SkShape*, fShapeCount);
for (i = 0; i < fShapeCount; i++) {
fShapes[i] = reinterpret_cast<SkShape*>(buffer.readFlattenable());
}
}
///////////////////////////////////////////////////////////////////////////////
@ -651,12 +614,6 @@ void SkPicturePlayback::draw(SkCanvas& canvas) {
const SkPaint& paint = *getPaint();
canvas.drawRect(*fReader.skipRect(), paint);
} break;
case DRAW_SHAPE: {
SkShape* shape = getShape();
if (shape) {
canvas.drawShape(shape);
}
} break;
case DRAW_SPRITE: {
const SkPaint* paint = getPaint();
const SkBitmap& bitmap = getBitmap();

View File

@ -11,7 +11,6 @@
#include "SkPathHeap.h"
#include "SkRegion.h"
#include "SkPictureFlat.h"
#include "SkShape.h"
#ifdef ANDROID
#include "SkThread.h"
@ -78,12 +77,6 @@ private:
return *fPictureRefs[index - 1];
}
SkShape* getShape() {
int index = getInt();
SkASSERT(index > 0 && index <= fShapeCount);
return fShapes[index - 1];
}
const SkPaint* getPaint() {
int index = getInt();
if (index == 0) {
@ -170,8 +163,6 @@ private:
SkPicture** fPictureRefs;
int fPictureCount;
SkShape** fShapes;
int fShapeCount;
SkRefCntPlayback fRCPlayback;
SkTypefacePlayback fTFPlayback;

View File

@ -1,5 +1,4 @@
#include "SkPictureRecord.h"
#include "SkShape.h"
#include "SkTSearch.h"
#define MIN_WRITER_SIZE 16384
@ -368,20 +367,6 @@ void SkPictureRecord::drawPicture(SkPicture& picture) {
validate();
}
void SkPictureRecord::drawShape(SkShape* shape) {
addDraw(DRAW_SHAPE);
int index = fShapes.find(shape);
if (index < 0) { // not found
index = fShapes.count();
*fShapes.append() = shape;
shape->ref();
}
// follow the convention of recording a 1-based index
addInt(index + 1);
validate();
}
void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode*,
@ -433,7 +418,6 @@ void SkPictureRecord::reset() {
fPaints.reset();
fPictureRefs.unrefAll();
fRegions.reset();
fShapes.safeUnrefAll();
fWriter.reset();
fHeap.reset();

View File

@ -51,7 +51,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint&);
virtual void drawPicture(SkPicture& picture);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode*,
@ -73,9 +72,6 @@ public:
const SkTDArray<SkPicture* >& getPictureRefs() const {
return fPictureRefs;
}
const SkTDArray<SkShape* >& getShapes() const {
return fShapes;
}
const SkTDArray<const SkFlatRegion* >& getRegions() const {
return fRegions;
}
@ -173,7 +169,6 @@ private:
// we ref each item in these arrays
SkTDArray<SkPicture*> fPictureRefs;
SkTDArray<SkShape*> fShapes;
SkRefCntSet fRCSet;
SkRefCntSet fTFSet;

View File

@ -1081,10 +1081,13 @@ SkRefPtr<SkPDFArray> SkPDFDevice::getMediaBox() const {
return mediaBox;
}
/**
* Can this return SkData instead of SkStream?
*/
SkStream* SkPDFDevice::content() const {
SkMemoryStream* result = new SkMemoryStream;
result->setData(this->copyContentToData())->unref();
return result;
}
SkData* SkPDFDevice::copyContentToData() const {
SkDynamicMemoryWStream data;
if (fInitialTransform.getType() != SkMatrix::kIdentity_Mask) {
SkPDFUtils::AppendTransform(fInitialTransform, &data);
@ -1097,11 +1100,11 @@ SkStream* SkPDFDevice::content() const {
SkRect r = SkRect::MakeWH(this->width(), this->height());
emit_clip(NULL, &r, &data);
}
GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, &data);
for (ContentEntry* entry = fContentEntries.get();
entry != NULL;
entry = entry->fNext.get()) {
entry != NULL;
entry = entry->fNext.get()) {
SkIPoint translation = this->getOrigin();
translation.negate();
gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion,
@ -1114,9 +1117,9 @@ SkStream* SkPDFDevice::content() const {
}
gsState.drainStack();
SkMemoryStream* result = new SkMemoryStream;
result->setData(data.copyToData())->unref();
return result;
// potentially we could cache this SkData, and only rebuild it if we
// see that our state has changed.
return data.copyToData();
}
void SkPDFDevice::createFormXObjectFromDevice(

View File

@ -56,7 +56,6 @@ enum DrawOps {
kDrawPosText_DrawOp,
kDrawPosTextH_DrawOp,
kDrawRect_DrawOp,
kDrawShape_DrawOp,
kDrawSprite_DrawOp,
kDrawText_DrawOp,
kDrawTextOnPath_DrawOp,

View File

@ -364,11 +364,6 @@ static void drawData_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
canvas->drawData(data, size);
}
static void drawShape_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
UNIMPLEMENTED
}
static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
UNIMPLEMENTED
@ -463,7 +458,6 @@ static const ReadProc gReadTable[] = {
drawPosText_rp,
drawPosTextH_rp,
drawRect_rp,
drawShape_rp,
drawSprite_rp,
drawText_rp,
drawTextOnPath_rp,

View File

@ -127,7 +127,6 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint&);
virtual void drawPicture(SkPicture& picture);
virtual void drawShape(SkShape*);
virtual void drawVertices(VertexMode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode*,
@ -591,10 +590,6 @@ void SkGPipeCanvas::drawPicture(SkPicture& picture) {
this->INHERITED::drawPicture(picture);
}
void SkGPipeCanvas::drawShape(SkShape* shape) {
UNIMPLEMENTED
}
void SkGPipeCanvas::drawVertices(VertexMode mode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode*,

View File

@ -351,14 +351,6 @@ void SkDumpCanvas::drawTextOnPath(const void* text, size_t byteLength,
str.c_str(), byteLength);
}
void SkDumpCanvas::drawShape(SkShape* shape) {
this->dump(kDrawShape_Verb, NULL, "drawShape(%p)", shape);
fNestLevel += 1;
this->INHERITED::drawShape(shape);
fNestLevel -= 1;
this->dump(kDrawShape_Verb, NULL, "endShape(%p)", shape);
}
void SkDumpCanvas::drawPicture(SkPicture& picture) {
this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", &picture,
picture.width(), picture.height());

View File

@ -248,13 +248,6 @@ void SkNWayCanvas::drawPicture(SkPicture& picture) {
}
}
void SkNWayCanvas::drawShape(SkShape* shape) {
Iter iter(fList);
while (iter.next()) {
iter->drawShape(shape);
}
}
void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,

View File

@ -126,10 +126,6 @@ void SkProxyCanvas::drawPicture(SkPicture& picture) {
fProxy->drawPicture(picture);
}
void SkProxyCanvas::drawShape(SkShape* shape) {
fProxy->drawShape(shape);
}
void SkProxyCanvas::drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,