зеркало из https://github.com/mozilla/moz-skia.git
remove SkShape (unused)
Review URL: https://codereview.appspot.com/6461069 git-svn-id: http://skia.googlecode.com/svn/trunk@5033 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
af73091b56
Коммит
d74e710c00
|
@ -6,9 +6,6 @@
|
|||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "gm.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkRectShape.h"
|
||||
#include "SkGroupShape.h"
|
||||
|
||||
typedef SkScalar (*MakePathProc)(SkPath*);
|
||||
|
||||
|
|
124
gm/shapes.cpp
124
gm/shapes.cpp
|
@ -1,124 +0,0 @@
|
|||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "gm.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkRectShape.h"
|
||||
#include "SkGroupShape.h"
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
static SkRect make_rect(int l, int t, int r, int b) {
|
||||
SkRect rect;
|
||||
rect.set(SkIntToScalar(l), SkIntToScalar(t),
|
||||
SkIntToScalar(r), SkIntToScalar(b));
|
||||
return rect;
|
||||
}
|
||||
|
||||
static SkShape* make_shape0(bool red) {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setRect(make_rect(10, 10, 90, 90));
|
||||
if (red) {
|
||||
s->paint().setColor(SK_ColorRED);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static SkShape* make_shape1() {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setOval(make_rect(10, 10, 90, 90));
|
||||
s->paint().setColor(SK_ColorBLUE);
|
||||
return s;
|
||||
}
|
||||
|
||||
static SkShape* make_shape2() {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setRRect(make_rect(10, 10, 90, 90),
|
||||
SkIntToScalar(20), SkIntToScalar(20));
|
||||
s->paint().setColor(SK_ColorGREEN);
|
||||
return s;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ShapesGM : public GM {
|
||||
SkGroupShape fGroup;
|
||||
SkMatrixRef* fMatrixRefs[4];
|
||||
public:
|
||||
ShapesGM() {
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
|
||||
SkMatrix m;
|
||||
fGroup.appendShape(make_shape0(false))->unref();
|
||||
m.setRotate(SkIntToScalar(30), SkIntToScalar(50), SkIntToScalar(50));
|
||||
m.postTranslate(0, SkIntToScalar(120));
|
||||
fGroup.appendShape(make_shape0(true), m)->unref();
|
||||
|
||||
m.setTranslate(SkIntToScalar(120), 0);
|
||||
fGroup.appendShape(make_shape1(), m)->unref();
|
||||
m.postTranslate(0, SkIntToScalar(120));
|
||||
fGroup.appendShape(make_shape2(), m)->unref();
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i));
|
||||
}
|
||||
SkScalar c = SkIntToScalar(50);
|
||||
fMatrixRefs[3]->preRotate(SkIntToScalar(30), c, c);
|
||||
}
|
||||
|
||||
virtual ~ShapesGM() {
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeUnref(fMatrixRefs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() {
|
||||
return SkString("shapes");
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
return make_isize(380, 480);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
SkMatrix matrix;
|
||||
|
||||
SkGroupShape* gs = new SkGroupShape;
|
||||
SkAutoUnref aur(gs);
|
||||
gs->appendShape(&fGroup);
|
||||
matrix.setScale(-SK_Scalar1, SK_Scalar1);
|
||||
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
|
||||
gs->appendShape(&fGroup, matrix);
|
||||
matrix.setTranslate(SkIntToScalar(240), 0);
|
||||
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
|
||||
gs->appendShape(&fGroup, matrix);
|
||||
|
||||
#if 1
|
||||
SkPicture* pict = new SkPicture;
|
||||
SkCanvas* cv = pict->beginRecording(1000, 1000);
|
||||
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
|
||||
gs->draw(cv);
|
||||
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
|
||||
cv->scale(-SK_Scalar1, SK_Scalar1);
|
||||
gs->draw(cv);
|
||||
pict->endRecording();
|
||||
canvas->drawPicture(*pict);
|
||||
pict->unref();
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GM* MyFactory(void*) { return new ShapesGM; }
|
||||
static GMRegistry reg(MyFactory);
|
||||
|
||||
}
|
|
@ -85,7 +85,6 @@
|
|||
'../samplecode/SampleRepeatTile.cpp',
|
||||
'../samplecode/SampleShaders.cpp',
|
||||
'../samplecode/SampleShaderText.cpp',
|
||||
'../samplecode/SampleShapes.cpp',
|
||||
'../samplecode/SampleSkLayer.cpp',
|
||||
'../samplecode/SampleSlides.cpp',
|
||||
'../samplecode/SampleStrokePath.cpp',
|
||||
|
|
|
@ -134,7 +134,6 @@
|
|||
'<(skia_src_path)/core/SkScan_Hairline.cpp',
|
||||
'<(skia_src_path)/core/SkScan_Path.cpp',
|
||||
'<(skia_src_path)/core/SkShader.cpp',
|
||||
'<(skia_src_path)/core/SkShape.cpp',
|
||||
'<(skia_src_path)/core/SkSpriteBlitter_ARGB32.cpp',
|
||||
'<(skia_src_path)/core/SkSpriteBlitter_RGB16.cpp',
|
||||
'<(skia_src_path)/core/SkSinTable.h',
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
'../include/effects/SkDrawExtraPathEffect.h',
|
||||
'../include/effects/SkEmbossMaskFilter.h',
|
||||
'../include/effects/SkGradientShader.h',
|
||||
'../include/effects/SkGroupShape.h',
|
||||
'../include/effects/SkKernel33MaskFilter.h',
|
||||
'../include/effects/SkLayerDrawLooper.h',
|
||||
'../include/effects/SkLayerRasterizer.h',
|
||||
|
@ -32,7 +31,6 @@
|
|||
'../include/effects/SkPaintFlagsDrawFilter.h',
|
||||
'../include/effects/SkPixelXorXfermode.h',
|
||||
'../include/effects/SkPorterDuff.h',
|
||||
'../include/effects/SkRectShape.h',
|
||||
'../include/effects/SkStippleMaskFilter.h',
|
||||
'../include/effects/SkTableColorFilter.h',
|
||||
'../include/effects/SkTableMaskFilter.h',
|
||||
|
@ -57,7 +55,6 @@
|
|||
'../src/effects/SkEmbossMask.h',
|
||||
'../src/effects/SkEmbossMask_Table.h',
|
||||
'../src/effects/SkEmbossMaskFilter.cpp',
|
||||
'../src/effects/SkGroupShape.cpp',
|
||||
'../src/effects/SkKernel33MaskFilter.cpp',
|
||||
'../src/effects/SkLayerDrawLooper.cpp',
|
||||
'../src/effects/SkLayerRasterizer.cpp',
|
||||
|
@ -66,7 +63,6 @@
|
|||
'../src/effects/SkPaintFlagsDrawFilter.cpp',
|
||||
'../src/effects/SkPixelXorXfermode.cpp',
|
||||
'../src/effects/SkPorterDuff.cpp',
|
||||
'../src/effects/SkRectShape.cpp',
|
||||
'../src/effects/SkStippleMaskFilter.cpp',
|
||||
'../src/effects/SkTableColorFilter.cpp',
|
||||
'../src/effects/SkTableMaskFilter.cpp',
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
'../gm/shaderbounds.cpp',
|
||||
'../gm/shadertext.cpp',
|
||||
'../gm/shadows.cpp',
|
||||
'../gm/shapes.cpp',
|
||||
'../gm/simpleaaclip.cpp',
|
||||
'../gm/strokefill.cpp',
|
||||
'../gm/strokerects.cpp',
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
'../gm/poly2poly.cpp',
|
||||
'../gm/shadertext.cpp',
|
||||
'../gm/shadows.cpp',
|
||||
'../gm/shapes.cpp',
|
||||
'../gm/tilemodes.cpp',
|
||||
'../gm/xfermodes.cpp',
|
||||
|
||||
|
@ -93,7 +92,6 @@
|
|||
'../samplecode/SampleRepeatTile.cpp',
|
||||
'../samplecode/SampleShaders.cpp',
|
||||
'../samplecode/SampleShaderText.cpp',
|
||||
'../samplecode/SampleShapes.cpp',
|
||||
'../samplecode/SampleSkLayer.cpp',
|
||||
'../samplecode/SampleSlides.cpp',
|
||||
'../samplecode/SampleStrokePath.cpp',
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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 SkShape_DEFINED
|
||||
#define SkShape_DEFINED
|
||||
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkMatrix;
|
||||
class SkWStream;
|
||||
|
||||
class SkShape : public SkFlattenable {
|
||||
public:
|
||||
SK_DECLARE_INST_COUNT(SkShape)
|
||||
|
||||
SkShape();
|
||||
virtual ~SkShape();
|
||||
|
||||
void draw(SkCanvas*);
|
||||
|
||||
/** Draw the shape translated by (dx,dy), which is applied before the
|
||||
shape's matrix (if any).
|
||||
*/
|
||||
void drawXY(SkCanvas*, SkScalar dx, SkScalar dy);
|
||||
|
||||
/** Draw the shape with the specified matrix, applied before the shape's
|
||||
matrix (if any).
|
||||
*/
|
||||
void drawMatrix(SkCanvas*, const SkMatrix&);
|
||||
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkShape)
|
||||
|
||||
protected:
|
||||
virtual void onDraw(SkCanvas*);
|
||||
|
||||
SkShape(SkFlattenableReadBuffer&);
|
||||
|
||||
private:
|
||||
|
||||
typedef SkFlattenable INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,153 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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 SkGroupShape_DEFINED
|
||||
#define SkGroupShape_DEFINED
|
||||
|
||||
#include "SkMatrix.h"
|
||||
#include "SkShape.h"
|
||||
#include "SkTDArray.h"
|
||||
#include "SkThread.h"
|
||||
|
||||
template <typename T> class SkTRefCnt : public T {
|
||||
public:
|
||||
SkTRefCnt() : fRefCnt(1) {}
|
||||
~SkTRefCnt() { SkASSERT(1 == fRefCnt); }
|
||||
|
||||
int32_t getRefCnt() const { return fRefCnt; }
|
||||
|
||||
/** Increment the reference count. Must be balanced by a call to unref().
|
||||
*/
|
||||
void ref() const {
|
||||
SkASSERT(fRefCnt > 0);
|
||||
sk_atomic_inc(&fRefCnt);
|
||||
}
|
||||
|
||||
/** Decrement the reference count. If the reference count is 1 before the
|
||||
decrement, then call delete on the object. Note that if this is the
|
||||
case, then the object needs to have been allocated via new, and not on
|
||||
the stack.
|
||||
*/
|
||||
void unref() const {
|
||||
SkASSERT(fRefCnt > 0);
|
||||
if (sk_atomic_dec(&fRefCnt) == 1) {
|
||||
fRefCnt = 1; // so our destructor won't complain
|
||||
SkDELETE(this);
|
||||
}
|
||||
}
|
||||
|
||||
static void SafeRef(const SkTRefCnt* obj) {
|
||||
if (obj) {
|
||||
obj->ref();
|
||||
}
|
||||
}
|
||||
|
||||
static void SafeUnref(const SkTRefCnt* obj) {
|
||||
if (obj) {
|
||||
obj->unref();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable int32_t fRefCnt;
|
||||
};
|
||||
|
||||
class SkMatrixRef : public SkTRefCnt<SkMatrix> {
|
||||
public:
|
||||
SkMatrixRef() { this->reset(); }
|
||||
explicit SkMatrixRef(const SkMatrix& matrix) {
|
||||
SkMatrix& m = *this;
|
||||
m = matrix;
|
||||
}
|
||||
|
||||
SkMatrix& operator=(const SkMatrix& matrix) {
|
||||
SkMatrix& m = *this;
|
||||
m = matrix;
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
class SkGroupShape : public SkShape {
|
||||
public:
|
||||
SkGroupShape();
|
||||
virtual ~SkGroupShape();
|
||||
|
||||
/** Return the number of child shapes in this group
|
||||
*/
|
||||
int countShapes() const;
|
||||
|
||||
/** Return the shape at the specified index. Note this does not affect the
|
||||
owner count of the index'd shape. If index is out of range, returns NULL
|
||||
*/
|
||||
SkShape* getShape(int index, SkMatrixRef** = NULL) const;
|
||||
|
||||
/** Helper function to return the matrixref of the specified shape.
|
||||
*/
|
||||
SkMatrixRef* getShapeMatrixRef(int index) const {
|
||||
SkMatrixRef* mr = NULL;
|
||||
(void)this->getShape(index, &mr);
|
||||
return mr;
|
||||
}
|
||||
|
||||
/** Ref the specified shape, and insert it into the child list at the
|
||||
specified index. If index == countShapes(), then the shape will be
|
||||
appended to the child list, otherwise if index is out of range, the
|
||||
shape is not added. Either way, the shape parameter is returned.
|
||||
|
||||
Child shapes are drawn in order, after the parent, so the shape at index
|
||||
0 will be drawn first, and the shape at index countShapes() - 1 will be
|
||||
drawn last.
|
||||
*/
|
||||
void addShape(int index, SkShape*, SkMatrixRef* = NULL);
|
||||
|
||||
void addShape(int index, SkShape* shape, const SkMatrix& matrix) {
|
||||
SkMatrixRef* mr = SkNEW_ARGS(SkMatrixRef, (matrix));
|
||||
this->addShape(index, shape, mr);
|
||||
mr->unref();
|
||||
}
|
||||
|
||||
/** Helper method to append a shape, passing countShapes() for the index
|
||||
*/
|
||||
SkShape* appendShape(SkShape* shape, SkMatrixRef* mr = NULL) {
|
||||
this->addShape(this->countShapes(), shape, mr);
|
||||
return shape;
|
||||
}
|
||||
|
||||
SkShape* appendShape(SkShape* shape, const SkMatrix& matrix) {
|
||||
this->addShape(this->countShapes(), shape, matrix);
|
||||
return shape;
|
||||
}
|
||||
|
||||
/** Unref the specified index, and remove it from the child list. If index
|
||||
is out of range, does nothing.
|
||||
*/
|
||||
void removeShape(int index);
|
||||
|
||||
/** Unrefs and removes all of the child shapes
|
||||
*/
|
||||
void removeAllShapes();
|
||||
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkGroupShape)
|
||||
|
||||
protected:
|
||||
// overrides
|
||||
virtual void onDraw(SkCanvas*);
|
||||
|
||||
SkGroupShape(SkFlattenableReadBuffer&);
|
||||
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
struct Rec {
|
||||
SkShape* fShape;
|
||||
SkMatrixRef* fMatrixRef;
|
||||
};
|
||||
SkTDArray<Rec> fList;
|
||||
|
||||
typedef SkShape INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
|
||||
/*
|
||||
* 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 SkRectShape_DEFINED
|
||||
#define SkRectShape_DEFINED
|
||||
|
||||
#include "SkShape.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkSize.h"
|
||||
|
||||
class SkPaintShape : public SkShape {
|
||||
public:
|
||||
SkPaintShape();
|
||||
|
||||
SkPaint& paint() { return fPaint; }
|
||||
const SkPaint& paint() const { return fPaint; }
|
||||
|
||||
protected:
|
||||
SkPaintShape(SkFlattenableReadBuffer& buffer);
|
||||
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
||||
|
||||
private:
|
||||
SkPaint fPaint;
|
||||
|
||||
typedef SkShape INHERITED;
|
||||
};
|
||||
|
||||
class SkRectShape : public SkPaintShape {
|
||||
public:
|
||||
SkRectShape();
|
||||
|
||||
void setRect(const SkRect&);
|
||||
void setOval(const SkRect&);
|
||||
void setCircle(SkScalar x, SkScalar y, SkScalar radius);
|
||||
void setRRect(const SkRect&, SkScalar rx, SkScalar ry);
|
||||
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRectShape)
|
||||
|
||||
protected:
|
||||
SkRectShape(SkFlattenableReadBuffer&);
|
||||
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
||||
|
||||
// overrides
|
||||
virtual void onDraw(SkCanvas*);
|
||||
|
||||
private:
|
||||
SkRect fBounds;
|
||||
SkSize fRadii;
|
||||
|
||||
typedef SkPaintShape INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,165 +0,0 @@
|
|||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "SampleCode.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkView.h"
|
||||
|
||||
#define DO_AA true
|
||||
|
||||
#include "SkRectShape.h"
|
||||
#include "SkGroupShape.h"
|
||||
|
||||
static SkRect make_rect(int l, int t, int r, int b) {
|
||||
SkRect rect;
|
||||
rect.set(SkIntToScalar(l), SkIntToScalar(t),
|
||||
SkIntToScalar(r), SkIntToScalar(b));
|
||||
return rect;
|
||||
}
|
||||
|
||||
static SkShape* make_shape0(bool red) {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setRect(make_rect(10, 10, 90, 90));
|
||||
if (red) {
|
||||
s->paint().setColor(SK_ColorRED);
|
||||
}
|
||||
s->paint().setAntiAlias(DO_AA);
|
||||
return s;
|
||||
}
|
||||
|
||||
static SkShape* make_shape1() {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setOval(make_rect(10, 10, 90, 90));
|
||||
s->paint().setColor(SK_ColorBLUE);
|
||||
s->paint().setAntiAlias(DO_AA);
|
||||
return s;
|
||||
}
|
||||
|
||||
static SkShape* make_shape2() {
|
||||
SkRectShape* s = new SkRectShape;
|
||||
s->setRRect(make_rect(10, 10, 90, 90),
|
||||
SkIntToScalar(20), SkIntToScalar(20));
|
||||
s->paint().setColor(SK_ColorGREEN);
|
||||
s->paint().setAntiAlias(DO_AA);
|
||||
return s;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ShapesView : public SampleView {
|
||||
SkGroupShape fGroup;
|
||||
SkMatrixRef* fMatrixRefs[4];
|
||||
public:
|
||||
ShapesView() {
|
||||
SkMatrix m;
|
||||
fGroup.appendShape(make_shape0(false))->unref();
|
||||
m.setRotate(SkIntToScalar(30), SkIntToScalar(50), SkIntToScalar(50));
|
||||
m.postTranslate(0, SkIntToScalar(120));
|
||||
fGroup.appendShape(make_shape0(true), m)->unref();
|
||||
|
||||
m.setTranslate(SkIntToScalar(120), 0);
|
||||
fGroup.appendShape(make_shape1(), m)->unref();
|
||||
m.postTranslate(0, SkIntToScalar(120));
|
||||
fGroup.appendShape(make_shape2(), m)->unref();
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeRef(fMatrixRefs[i] = fGroup.getShapeMatrixRef(i));
|
||||
}
|
||||
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
virtual ~ShapesView() {
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrixRefs); i++) {
|
||||
SkSafeUnref(fMatrixRefs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
// overrides from SkEventSink
|
||||
virtual bool onQuery(SkEvent* evt) {
|
||||
if (SampleCode::TitleQ(*evt)) {
|
||||
SampleCode::TitleR(evt, "Shapes");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
void drawpicture(SkCanvas* canvas, SkPicture& pict) {
|
||||
#if 0
|
||||
SkDynamicMemoryWStream ostream;
|
||||
pict.serialize(&ostream);
|
||||
|
||||
SkMemoryStream istream(ostream.getStream(), ostream.getOffset());
|
||||
SkPicture* newPict = new SkPicture(&istream);
|
||||
canvas->drawPicture(*newPict);
|
||||
newPict->unref();
|
||||
#else
|
||||
canvas->drawPicture(pict);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
SkScalar angle = SampleCode::GetAnimScalar(SkIntToScalar(180),
|
||||
SkIntToScalar(360));
|
||||
|
||||
SkMatrix saveM = *fMatrixRefs[3];
|
||||
SkScalar c = SkIntToScalar(50);
|
||||
fMatrixRefs[3]->preRotate(angle, c, c);
|
||||
|
||||
const SkScalar dx = 350;
|
||||
const SkScalar dy = 500;
|
||||
const int N = 1;
|
||||
for (int v = -N; v <= N; v++) {
|
||||
for (int h = -N; h <= N; h++) {
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->translate(h * dx, v * dy);
|
||||
|
||||
SkMatrix matrix;
|
||||
|
||||
SkGroupShape* gs = new SkGroupShape;
|
||||
SkAutoUnref aur(gs);
|
||||
gs->appendShape(&fGroup);
|
||||
matrix.setScale(-SK_Scalar1, SK_Scalar1);
|
||||
matrix.postTranslate(SkIntToScalar(220), SkIntToScalar(240));
|
||||
gs->appendShape(&fGroup, matrix);
|
||||
matrix.setTranslate(SkIntToScalar(240), 0);
|
||||
matrix.preScale(SK_Scalar1*2, SK_Scalar1*2);
|
||||
gs->appendShape(&fGroup, matrix);
|
||||
|
||||
#if 1
|
||||
SkPicture* pict = new SkPicture;
|
||||
SkCanvas* cv = pict->beginRecording(1000, 1000);
|
||||
cv->scale(SK_ScalarHalf, SK_ScalarHalf);
|
||||
gs->draw(cv);
|
||||
cv->translate(SkIntToScalar(680), SkIntToScalar(480));
|
||||
cv->scale(-SK_Scalar1, SK_Scalar1);
|
||||
gs->draw(cv);
|
||||
pict->endRecording();
|
||||
|
||||
drawpicture(canvas, *pict);
|
||||
pict->unref();
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
*fMatrixRefs[3] = saveM;
|
||||
this->inval(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef SampleView INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkView* MyFactory() { return new ShapesView; }
|
||||
static SkViewRegister reg(MyFactory);
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "SkCanvas.h"
|
||||
#include "SkShape.h"
|
||||
#include "SkMatrix.h"
|
||||
|
||||
SK_DEFINE_INST_COUNT(SkShape)
|
||||
|
||||
#if 0
|
||||
static int gShapeCounter;
|
||||
static void inc_shape(const SkShape* s) {
|
||||
SkDebugf("inc %d\n", gShapeCounter);
|
||||
gShapeCounter += 1;
|
||||
}
|
||||
static void dec_shape(const SkShape* s) {
|
||||
--gShapeCounter;
|
||||
SkDebugf("dec %d\n", gShapeCounter);
|
||||
}
|
||||
#else
|
||||
#define inc_shape(s)
|
||||
#define dec_shape(s)
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkShape::draw(SkCanvas* canvas) {
|
||||
int saveCount = canvas->getSaveCount();
|
||||
this->onDraw(canvas);
|
||||
canvas->restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
void SkShape::drawXY(SkCanvas* canvas, SkScalar dx, SkScalar dy) {
|
||||
int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag);
|
||||
canvas->translate(dx, dy);
|
||||
this->onDraw(canvas);
|
||||
canvas->restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
void SkShape::drawMatrix(SkCanvas* canvas, const SkMatrix& matrix) {
|
||||
int saveCount = canvas->save(SkCanvas::kMatrix_SaveFlag);
|
||||
canvas->concat(matrix);
|
||||
this->onDraw(canvas);
|
||||
canvas->restoreToCount(saveCount);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkShape::SkShape() {
|
||||
inc_shape(this);
|
||||
}
|
||||
|
||||
SkShape::~SkShape() {
|
||||
dec_shape(this);
|
||||
}
|
||||
|
||||
SkShape::SkShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
|
||||
inc_shape(this);
|
||||
}
|
||||
|
||||
void SkShape::onDraw(SkCanvas*) {}
|
||||
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR(SkShape)
|
|
@ -1,121 +0,0 @@
|
|||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "SkGroupShape.h"
|
||||
#include "SkFlattenableBuffers.h"
|
||||
|
||||
SkGroupShape::SkGroupShape() {}
|
||||
|
||||
SkGroupShape::~SkGroupShape() {
|
||||
this->removeAllShapes();
|
||||
}
|
||||
|
||||
int SkGroupShape::countShapes() const {
|
||||
return fList.count();
|
||||
}
|
||||
|
||||
SkShape* SkGroupShape::getShape(int index, SkMatrixRef** mr) const {
|
||||
if ((unsigned)index < (unsigned)fList.count()) {
|
||||
const Rec& rec = fList[index];
|
||||
if (mr) {
|
||||
*mr = rec.fMatrixRef;
|
||||
}
|
||||
return rec.fShape;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SkGroupShape::addShape(int index, SkShape* shape, SkMatrixRef* mr) {
|
||||
int count = fList.count();
|
||||
if (NULL == shape || index < 0 || index > count) {
|
||||
return;
|
||||
}
|
||||
|
||||
shape->ref();
|
||||
SkMatrixRef::SafeRef(mr);
|
||||
|
||||
Rec* rec;
|
||||
if (index == count) {
|
||||
rec = fList.append();
|
||||
} else {
|
||||
rec = fList.insert(index);
|
||||
}
|
||||
rec->fShape = shape;
|
||||
rec->fMatrixRef = mr;
|
||||
}
|
||||
|
||||
void SkGroupShape::removeShape(int index) {
|
||||
if ((unsigned)index < (unsigned)fList.count()) {
|
||||
Rec& rec = fList[index];
|
||||
rec.fShape->unref();
|
||||
SkMatrixRef::SafeUnref(rec.fMatrixRef);
|
||||
fList.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
void SkGroupShape::removeAllShapes() {
|
||||
Rec* rec = fList.begin();
|
||||
Rec* stop = fList.end();
|
||||
while (rec < stop) {
|
||||
rec->fShape->unref();
|
||||
SkMatrixRef::SafeUnref(rec->fMatrixRef);
|
||||
rec++;
|
||||
}
|
||||
fList.reset();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkGroupShape::onDraw(SkCanvas* canvas) {
|
||||
const Rec* rec = fList.begin();
|
||||
const Rec* stop = fList.end();
|
||||
while (rec < stop) {
|
||||
SkShape* shape = rec->fShape;
|
||||
if (rec->fMatrixRef) {
|
||||
shape->drawMatrix(canvas, *rec->fMatrixRef);
|
||||
} else {
|
||||
shape->draw(canvas);
|
||||
}
|
||||
rec++;
|
||||
}
|
||||
}
|
||||
|
||||
void SkGroupShape::flatten(SkFlattenableWriteBuffer& buffer) const {
|
||||
this->INHERITED::flatten(buffer);
|
||||
|
||||
buffer.writeInt(fList.count());
|
||||
const Rec* rec = fList.begin();
|
||||
const Rec* stop = fList.end();
|
||||
while (rec < stop) {
|
||||
buffer.writeFlattenable(rec->fShape);
|
||||
buffer.writeBool(NULL != rec->fMatrixRef);
|
||||
if (rec->fMatrixRef) {
|
||||
buffer.writeMatrix(*rec->fMatrixRef);
|
||||
}
|
||||
rec += 1;
|
||||
}
|
||||
}
|
||||
|
||||
SkGroupShape::SkGroupShape(SkFlattenableReadBuffer& buffer) : INHERITED(buffer){
|
||||
int count = buffer.readInt();
|
||||
for (int i = 0; i < count; i++) {
|
||||
SkShape* shape = buffer.readFlattenableT<SkShape>();
|
||||
SkMatrixRef* mr = NULL;
|
||||
bool hasMatrix = buffer.readBool();
|
||||
if (hasMatrix) {
|
||||
mr = SkNEW(SkMatrixRef);
|
||||
buffer.readMatrix(mr);
|
||||
}
|
||||
if (shape) {
|
||||
this->appendShape(shape, mr)->unref();
|
||||
}
|
||||
SkSafeUnref(mr);
|
||||
}
|
||||
}
|
||||
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR(SkGroupShape)
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
#include "SkMallocPixelRef.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkPixelRef.h"
|
||||
#include "SkShape.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
#include "Sk1DPathEffect.h"
|
||||
|
@ -37,14 +36,12 @@
|
|||
#include "SkEmbossMaskFilter.h"
|
||||
#include "SkFlattenable.h"
|
||||
#include "SkGradientShader.h"
|
||||
#include "SkGroupShape.h"
|
||||
#include "SkLayerDrawLooper.h"
|
||||
#include "SkLayerRasterizer.h"
|
||||
#include "SkLightingImageFilter.h"
|
||||
#include "SkMorphologyImageFilter.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkPixelXorXfermode.h"
|
||||
#include "SkRectShape.h"
|
||||
#include "SkStippleMaskFilter.h"
|
||||
#include "SkTableColorFilter.h"
|
||||
#include "SkTestImageFilters.h"
|
||||
|
@ -67,16 +64,13 @@ void SkFlattenable::InitializeFlattenables() {
|
|||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkEmbossMaskFilter)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkEmptyShader)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkErodeImageFilter)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkGroupShape)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerDrawLooper)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLayerRasterizer)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath1DPathEffect)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPath2DPathEffect)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRectShape)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkStippleMaskFilter)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShape)
|
||||
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkOffsetImageFilter)
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposeImageFilter)
|
||||
|
|
Загрузка…
Ссылка в новой задаче