aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-13 19:09:42 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-04-13 19:09:42 +0000
commit84b18c7e3e042bf206e1ace3d1b6ea5bb929fe51 (patch)
tree7b46e74e6212283d9efe62a7b6feaad2c009972b /gm
parentc202ea7cc69476a20ad898d6c76bcdbcb18adf74 (diff)
split SkPictureRecorder out of SkPicture
Diffstat (limited to 'gm')
-rw-r--r--gm/distantclip.cpp13
-rw-r--r--gm/gmmain.cpp14
-rw-r--r--gm/optimizations.cpp26
-rw-r--r--gm/pathopsskpclip.cpp7
-rw-r--r--gm/pictureimagefilter.cpp13
-rw-r--r--gm/pictureshader.cpp8
6 files changed, 36 insertions, 45 deletions
diff --git a/gm/distantclip.cpp b/gm/distantclip.cpp
index 6fd14206c4..0f78dbd3ee 100644
--- a/gm/distantclip.cpp
+++ b/gm/distantclip.cpp
@@ -29,11 +29,11 @@ protected:
int offset = 35000;
int extents = 1000;
+ SkPictureRecorder recorder;
// We record a picture of huge vertical extents in which we clear the canvas to red, create
// a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw
// green into that.
- SkPicture pict;
- SkCanvas* rec = pict.beginRecording(100, offset + extents);
+ SkCanvas* rec = recorder.beginRecording(100, offset + extents);
rec->drawColor(0xffff0000);
rec->save();
SkRect r = {
@@ -47,18 +47,17 @@ protected:
rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(0xff00ff00);
rec->restore();
- pict.endRecording();
+ SkAutoTUnref<SkPicture> pict(recorder.endRecording());
// Next we play that picture into another picture of the same size.
- SkPicture pict2;
- pict.draw(pict2.beginRecording(100, offset + extents));
- pict2.endRecording();
+ pict->draw(recorder.beginRecording(100, offset + extents));
+ SkAutoTUnref<SkPicture> pict2(recorder.endRecording());
// Finally we play the part of that second picture that should be green into the canvas.
canvas->save();
canvas->translate(SkIntToScalar(extents / 2),
SkIntToScalar(-(offset - extents / 2)));
- pict2.draw(canvas);
+ pict2->draw(canvas);
canvas->restore();
// If the image is red, we erroneously decided the clipPath was empty and didn't record
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 03556e70e9..4d5866a3d2 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -1008,29 +1008,25 @@ public:
static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags,
SkScalar scale = SK_Scalar1) {
- // Pictures are refcounted so must be on heap
- SkPicture* pict;
int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale));
int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale));
+ SkAutoTUnref<SkPictureFactory> factory;
if (kTileGrid_BbhType == bbhType) {
SkTileGridPicture::TileGridInfo info;
info.fMargin.setEmpty();
info.fOffset.setZero();
info.fTileInterval.set(16, 16);
- pict = new SkTileGridPicture(width, height, info);
- } else {
- pict = new SkPicture;
+ factory.reset(SkNEW_ARGS(SkTileGridPictureFactory, (info)));
}
if (kNone_BbhType != bbhType) {
recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag;
}
- SkCanvas* cv = pict->beginRecording(width, height, recordFlags);
+ SkPictureRecorder recorder(factory);
+ SkCanvas* cv = recorder.beginRecording(width, height, recordFlags);
cv->scale(scale, scale);
invokeGM(gm, cv, false, false);
- pict->endRecording();
-
- return pict;
+ return recorder.endRecording();
}
static SkPicture* stream_to_new_picture(const SkPicture& src) {
diff --git a/gm/optimizations.cpp b/gm/optimizations.cpp
index ff88e3d1f0..1e6ddfa1d6 100644
--- a/gm/optimizations.cpp
+++ b/gm/optimizations.cpp
@@ -79,11 +79,11 @@ static SkPicture* create_save_layer_opt_1(SkTDArray<DrawType>* preOptPattern,
(*postOptPattern)[6] = RESTORE;
}
- SkPicture* result = new SkPicture;
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100, 100);
// have to disable the optimizations while generating the picture
- SkCanvas* canvas = result->beginRecording(100, 100);
- result->internalOnly_EnableOpts(false);
+ recorder.internalOnly_EnableOpts(false);
SkPaint saveLayerPaint;
saveLayerPaint.setColor(0xCC000000);
@@ -112,9 +112,7 @@ static SkPicture* create_save_layer_opt_1(SkTDArray<DrawType>* preOptPattern,
}
canvas->restore();
- result->endRecording();
-
- return result;
+ return recorder.endRecording();
}
// straight-ahead version that is seen in the skps
@@ -215,11 +213,11 @@ static SkPicture* create_save_layer_opt_2(SkTDArray<DrawType>* preOptPattern,
(*postOptPattern)[9] = RESTORE;
}
- SkPicture* result = new SkPicture;
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100, 100);
// have to disable the optimizations while generating the picture
- SkCanvas* canvas = result->beginRecording(100, 100);
- result->internalOnly_EnableOpts(false);
+ recorder.internalOnly_EnableOpts(false);
SkPaint saveLayerPaint;
saveLayerPaint.setColor(0xCC000000);
@@ -252,9 +250,7 @@ static SkPicture* create_save_layer_opt_2(SkTDArray<DrawType>* preOptPattern,
canvas->restore();
canvas->restore();
- result->endRecording();
-
- return result;
+ return recorder.endRecording();
}
// straight-ahead version that is seen in the skps
@@ -360,13 +356,13 @@ protected:
canvas->restore();
// re-render the 'pre' picture and thus 'apply' the optimization
- SkAutoTUnref<SkPicture> post(new SkPicture);
+ SkPictureRecorder recorder;
- SkCanvas* recordCanvas = post->beginRecording(pre->width(), pre->height());
+ SkCanvas* recordCanvas = recorder.beginRecording(pre->width(), pre->height());
pre->draw(recordCanvas);
- post->endRecording();
+ SkAutoTUnref<SkPicture> post(recorder.endRecording());
if (!(check_pattern(*post, postPattern))) {
WARN("Post optimization pattern mismatch");
diff --git a/gm/pathopsskpclip.cpp b/gm/pathopsskpclip.cpp
index b85b294fef..0d936983b9 100644
--- a/gm/pathopsskpclip.cpp
+++ b/gm/pathopsskpclip.cpp
@@ -32,8 +32,8 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
- SkPicture* pict = SkNEW(SkPicture);
- SkCanvas* rec = pict->beginRecording(1200, 900);
+ SkPictureRecorder recorder;
+ SkCanvas* rec = recorder.beginRecording(1200, 900);
SkPath p;
SkRect r = {
SkIntToScalar(100),
@@ -46,7 +46,7 @@ protected:
rec->translate(SkIntToScalar(250), SkIntToScalar(250));
rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(0xffff0000);
- pict->endRecording();
+ SkAutoTUnref<SkPicture> pict(recorder.endRecording());
canvas->setAllowSimplifyClip(true);
canvas->save();
@@ -58,7 +58,6 @@ protected:
canvas->translate(SkIntToScalar(1200 / 2), 0);
canvas->drawPicture(*pict);
canvas->restore();
- SkSafeUnref(pict);
}
private:
diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp
index 2b3cd14ea2..12806618b3 100644
--- a/gm/pictureimagefilter.cpp
+++ b/gm/pictureimagefilter.cpp
@@ -22,7 +22,8 @@ protected:
}
void makePicture() {
- SkCanvas* canvas = fPicture.beginRecording(100, 100);
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
@@ -30,7 +31,7 @@ protected:
paint.setTextSize(SkIntToScalar(96));
const char* str = "e";
canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
- fPicture.endRecording();
+ fPicture.reset(recorder.endRecording());
}
virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(500, 150); }
@@ -54,9 +55,9 @@ protected:
SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
- SkAutoTUnref<SkImageFilter> pictureSource(SkPictureImageFilter::Create(&fPicture));
- SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilter::Create(&fPicture, srcRect));
- SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFilter::Create(&fPicture, emptyRect));
+ SkAutoTUnref<SkImageFilter> pictureSource(SkPictureImageFilter::Create(fPicture));
+ SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilter::Create(fPicture, srcRect));
+ SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFilter::Create(fPicture, emptyRect));
// Draw the picture unscaled.
fillRectFiltered(canvas, bounds, pictureSource);
@@ -82,7 +83,7 @@ protected:
}
private:
- SkPicture fPicture;
+ SkAutoTUnref<SkPicture> fPicture;
typedef GM INHERITED;
};
diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp
index 5d37c907ac..51ce0b1bcd 100644
--- a/gm/pictureshader.cpp
+++ b/gm/pictureshader.cpp
@@ -31,11 +31,11 @@ public:
, fSceneSize(sceneSize) {
// Build the picture.
- SkAutoTUnref<SkPicture> p(SkNEW(SkPicture));
- SkCanvas* pictureCanvas = p->beginRecording(SkScalarRoundToInt(tileSize),
- SkScalarRoundToInt(tileSize));
+ SkPictureRecorder recorder;
+ SkCanvas* pictureCanvas = recorder.beginRecording(SkScalarRoundToInt(tileSize),
+ SkScalarRoundToInt(tileSize));
this->drawTile(pictureCanvas);
- p->endRecording();
+ SkAutoTUnref<SkPicture> p(recorder.endRecording());
// Build a reference bitmap.
SkBitmap bm;