Remove DEPRECATED_beginRecording().

This removes:
  1) ability to record old pictures with SkPictureRecorder;
  2) a couple tests specific to the old backend.

The functionality of DEPRECATED_beginRecording() now lives in
(private) SkPicture::Backport(), which is the only place we
need it now.

BUG=skia:
TBR=reed@google.com

Review URL: https://codereview.chromium.org/618303002
This commit is contained in:
mtklein 2014-10-01 09:29:35 -07:00 коммит произвёл Commit bot
Родитель 23cd4d2d1a
Коммит 8e12656096
8 изменённых файлов: 77 добавлений и 191 удалений

Просмотреть файл

@ -53,14 +53,14 @@ public:
protected:
virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE {
SkPictureRecorder recorder;
SkCanvas* canvas = NULL;
SkCanvas* canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
const SkPoint translateDelta = getTranslateDelta(loops);
for (int i = 0; i < loops; i++) {
if (0 == i % kMaxLoopsPerCanvas) {
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, NULL, 0);
canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
}
SkColor color = SK_ColorYELLOW + (i % 255);
@ -98,6 +98,7 @@ protected:
canvas->restore();
canvas->translate(translateDelta.fX, translateDelta.fY);
}
SkAutoTUnref<SkPicture> cleanup(recorder.endRecording());
}
SkPoint getTranslateDelta(int M) {
@ -122,15 +123,16 @@ protected:
SkRandom rand;
SkPaint paint;
SkPictureRecorder recorder;
SkCanvas* canvas = NULL;
SkCanvas* canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
for (int i = 0; i < loops; i++) {
if (0 == i % kMaxLoopsPerCanvas) {
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT, NULL, 0);
canvas = recorder.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT);
}
paint.setColor(rand.nextU());
canvas->drawPaint(paint);
}
SkAutoTUnref<SkPicture> cleanup(recorder.endRecording());
}
private:

Просмотреть файл

@ -272,7 +272,7 @@ private:
void createHeader(SkPictInfo* info) const;
static bool IsValidPictInfo(const SkPictInfo& info);
friend class SkPictureRecorder; // just for SkPicture-based constructor
friend class SkPictureRecorder; // SkRecord-based constructor.
friend class SkGpuDevice; // for fData access
friend class GrLayerHoister; // access to fRecord
friend class CollectLayers; // access to fRecord
@ -285,6 +285,8 @@ private:
SkPicture(SkScalar width, SkScalar height, SkRecord*, SkBBoxHierarchy*);
// Return as a new SkPicture that's backed by SkRecord.
static SkPicture* Forwardport(const SkPicture&);
// Return as a new SkPicture that's backed by the old backend.
static SkPicture* Backport(const SkRecord& src, const SkRect& cullRect);
SkAutoTDelete<SkRecord> fRecord;
SkAutoTUnref<SkBBoxHierarchy> fBBH;

Просмотреть файл

@ -48,18 +48,6 @@ public:
SkBBHFactory* bbhFactory = NULL,
uint32_t recordFlags = 0);
// As usual, we have a deprecated old version and a maybe almost working
// new version. We currently point beginRecording() to EXPERIMENTAL_beginRecording().
// Old slower backend.
SkCanvas* DEPRECATED_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory = NULL,
uint32_t recordFlags = 0);
// New faster backend.
SkCanvas* EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory = NULL);
/** Returns the recording canvas if one is active, or NULL if recording is
not active. This does not alter the refcnt on the canvas (if present).
*/
@ -87,13 +75,8 @@ private:
SkScalar fCullWidth;
SkScalar fCullHeight;
SkAutoTUnref<SkBBoxHierarchy> fBBH;
// One of these two canvases will be non-NULL.
SkAutoTUnref<SkPictureRecord> fPictureRecord; // beginRecording()
SkAutoTUnref<SkRecorder> fRecorder; // EXPERIMENTAL_beginRecording()
// Used by EXPERIMENTAL_beginRecording().
SkAutoTDelete<SkRecord> fRecord;
SkAutoTUnref<SkRecorder> fRecorder;
SkAutoTDelete<SkRecord> fRecord;
typedef SkNoncopyable INHERITED;
};

Просмотреть файл

@ -264,12 +264,12 @@ SkPicture::SkPicture(SkScalar width, SkScalar height,
// Create an SkPictureData-backed SkPicture from an SkRecord.
// This for compatibility with serialization code only. This is not cheap.
static SkPicture* backport(const SkRecord& src, const SkRect& cullRect) {
SkPictureRecorder recorder;
SkRecordDraw(src,
recorder.DEPRECATED_beginRecording(cullRect.width(), cullRect.height()),
NULL/*bbh*/, NULL/*callback*/);
return recorder.endRecording();
SkPicture* SkPicture::Backport(const SkRecord& src, const SkRect& cullRect) {
SkPictureRecord rec(SkISize::Make(cullRect.width(), cullRect.height()), 0/*flags*/);
rec.beginRecording();
SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/);
rec.endRecording();
return SkNEW_ARGS(SkPicture, (cullRect.width(), cullRect.height(), rec, false/*deepCopyOps*/));
}
// fRecord OK
@ -510,7 +510,7 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
// If we're a new-format picture, backport to old format for serialization.
SkAutoTDelete<SkPicture> oldFormat;
if (NULL == data && fRecord.get()) {
oldFormat.reset(backport(*fRecord, this->cullRect()));
oldFormat.reset(Backport(*fRecord, this->cullRect()));
data = oldFormat->fData.get();
SkASSERT(data);
}
@ -535,7 +535,7 @@ void SkPicture::flatten(SkWriteBuffer& buffer) const {
// If we're a new-format picture, backport to old format for serialization.
SkAutoTDelete<SkPicture> oldFormat;
if (NULL == data && fRecord.get()) {
oldFormat.reset(backport(*fRecord, this->cullRect()));
oldFormat.reset(Backport(*fRecord, this->cullRect()));
data = oldFormat->fData.get();
SkASSERT(data);
}

Просмотреть файл

@ -24,8 +24,10 @@ enum {
static int const kUInt32Size = 4;
static const uint32_t kSaveSize = kUInt32Size;
#ifdef SK_DEBUG
static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size;
static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect);
#endif//SK_DEBUG
SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags)
: INHERITED(dimensions.width(), dimensions.height())
@ -49,10 +51,11 @@ SkPictureRecord::~SkPictureRecord() {
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
// Return the offset of the paint inside a given op's byte stream. A zero
// return value means there is no paint (and you really shouldn't be calling
// this method)
static inline size_t getPaintOffset(DrawType op, size_t opSize) {
static inline size_t get_paint_offset(DrawType op, size_t opSize) {
// These offsets are where the paint would be if the op size doesn't overflow
static const uint8_t gPaintOffsets[] = {
0, // UNUSED - no paint
@ -129,6 +132,7 @@ static inline size_t getPaintOffset(DrawType op, size_t opSize) {
SkASSERT(0 != gPaintOffsets[op]); // really shouldn't be calling this method
return gPaintOffsets[op] * sizeof(uint32_t) + overflow;
}
#endif//SK_DEBUG
void SkPictureRecord::willSave() {
// record the offset to us, making it non-positive to distinguish a save
@ -184,7 +188,7 @@ void SkPictureRecord::recordSaveLayer(const SkRect* bounds, const SkPaint* paint
size_t initialOffset = this->addDraw(SAVE_LAYER, &size);
this->addRectPtr(bounds);
SkASSERT(initialOffset+getPaintOffset(SAVE_LAYER, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(SAVE_LAYER, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addInt(flags);
@ -476,7 +480,7 @@ void SkPictureRecord::drawPaint(const SkPaint& paint) {
// op + paint index
size_t size = 2 * kUInt32Size;
size_t initialOffset = this->addDraw(DRAW_PAINT, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_PAINT, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_PAINT, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->validate(initialOffset, size);
}
@ -488,7 +492,7 @@ void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
// op + paint index + mode + count + point data
size_t size = 4 * kUInt32Size + count * sizeof(SkPoint);
size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_POINTS, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addInt(mode);
@ -501,7 +505,7 @@ void SkPictureRecord::drawOval(const SkRect& oval, const SkPaint& paint) {
// op + paint index + rect
size_t size = 2 * kUInt32Size + sizeof(oval);
size_t initialOffset = this->addDraw(DRAW_OVAL, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_OVAL, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_OVAL, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addRect(oval);
this->validate(initialOffset, size);
@ -511,7 +515,7 @@ void SkPictureRecord::drawRect(const SkRect& rect, const SkPaint& paint) {
// op + paint index + rect
size_t size = 2 * kUInt32Size + sizeof(rect);
size_t initialOffset = this->addDraw(DRAW_RECT, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_RECT, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_RECT, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addRect(rect);
this->validate(initialOffset, size);
@ -521,7 +525,7 @@ void SkPictureRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
// op + paint index + rrect
size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory;
size_t initialOffset = this->addDraw(DRAW_RRECT, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_RRECT, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_RRECT, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addRRect(rrect);
this->validate(initialOffset, size);
@ -532,7 +536,7 @@ void SkPictureRecord::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
// op + paint index + rrects
size_t size = 2 * kUInt32Size + SkRRect::kSizeInMemory * 2;
size_t initialOffset = this->addDraw(DRAW_DRRECT, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_DRRECT, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_DRRECT, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addRRect(outer);
this->addRRect(inner);
@ -545,7 +549,7 @@ void SkPictureRecord::drawPath(const SkPath& path, const SkPaint& paint) {
// op + paint index + path index
size_t size = 3 * kUInt32Size;
size_t initialOffset = this->addDraw(DRAW_PATH, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_PATH, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_PATH, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addPath(path);
this->validate(initialOffset, size);
@ -556,7 +560,7 @@ void SkPictureRecord::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
// op + paint index + bitmap index + left + top
size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addBitmap(bitmap);
this->addScalar(left);
@ -575,7 +579,7 @@ void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
size += sizeof(dst); // + rect
size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size)
SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_RECT_TO_RECT, size)
== fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addBitmap(bitmap);
@ -590,7 +594,7 @@ void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
// id + paint index + bitmap index + matrix
size_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_MATRIX, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addBitmap(bitmap);
this->addMatrix(matrix);
@ -602,7 +606,7 @@ void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
// op + paint index + bitmap id + center + dst rect
size_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_BITMAP_NINE, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addBitmap(bitmap);
this->addIRect(center);
@ -615,7 +619,7 @@ void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
// op + paint index + bitmap index + left + top
size_t size = 5 * kUInt32Size;
size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_SPRITE, size) == fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addBitmap(bitmap);
this->addInt(left);
@ -630,7 +634,7 @@ void SkPictureRecord::onDrawText(const void* text, size_t byteLength, SkScalar x
DrawType op = DRAW_TEXT;
size_t initialOffset = this->addDraw(op, &size);
SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addText(text, byteLength);
this->addScalar(x);
@ -648,7 +652,7 @@ void SkPictureRecord::onDrawPosText(const void* text, size_t byteLength, const S
DrawType op = DRAW_POS_TEXT;
size_t initialOffset = this->addDraw(op, &size);
SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(op, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addText(text, byteLength);
this->addInt(points);
@ -680,7 +684,7 @@ void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons
const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.writeToMemory(NULL);
size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addText(text, byteLength);
this->addPath(path);
@ -694,7 +698,7 @@ void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScala
// op + paint index + blob index + x/y
size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size);
SkASSERT(initialOffset + getPaintOffset(DRAW_TEXT_BLOB, size) == fWriter.bytesWritten());
SkASSERT(initialOffset + get_paint_offset(DRAW_TEXT_BLOB, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addTextBlob(blob);
@ -717,7 +721,7 @@ void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma
const SkMatrix& m = matrix ? *matrix : SkMatrix::I();
size += m.writeToMemory(NULL) + kUInt32Size; // matrix + paint
initialOffset = this->addDraw(DRAW_PICTURE_MATRIX_PAINT, &size);
SkASSERT(initialOffset + getPaintOffset(DRAW_PICTURE_MATRIX_PAINT, size)
SkASSERT(initialOffset + get_paint_offset(DRAW_PICTURE_MATRIX_PAINT, size)
== fWriter.bytesWritten());
this->addPaintPtr(paint);
this->addMatrix(m);
@ -765,7 +769,7 @@ void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount,
}
size_t initialOffset = this->addDraw(DRAW_VERTICES, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_VERTICES, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_VERTICES, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addInt(flags);
this->addInt(vmode);
@ -812,7 +816,7 @@ void SkPictureRecord::onDrawPatch(const SkPoint cubics[12], const SkColor colors
}
size_t initialOffset = this->addDraw(DRAW_PATCH, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_PATCH, size) == fWriter.bytesWritten());
SkASSERT(initialOffset+get_paint_offset(DRAW_PATCH, size) == fWriter.bytesWritten());
this->addPaint(paint);
this->addPatch(cubics);
this->addInt(flag);

Просмотреть файл

@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
#include "SkPictureRecord.h"
#include "SkPictureRecorder.h"
#include "SkRecord.h"
#include "SkRecordDraw.h"
@ -19,24 +18,6 @@ SkPictureRecorder::~SkPictureRecorder() {}
SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */,
uint32_t recordFlags /* = 0 */) {
return EXPERIMENTAL_beginRecording(width, height, bbhFactory);
}
SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */,
uint32_t recordFlags /* = 0 */) {
SkASSERT(!bbhFactory); // No longer suppported with this backend.
fCullWidth = width;
fCullHeight = height;
fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (SkISize::Make(width, height), recordFlags)));
fPictureRecord->beginRecording();
return this->getRecordingCanvas();
}
SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
SkBBHFactory* bbhFactory /* = NULL */) {
fCullWidth = width;
fCullHeight = height;
@ -51,43 +32,16 @@ SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(SkScalar width, SkScala
}
SkCanvas* SkPictureRecorder::getRecordingCanvas() {
if (fRecorder.get()) {
return fRecorder.get();
}
return fPictureRecord.get();
return fRecorder.get();
}
SkPicture* SkPictureRecorder::endRecording() {
SkPicture* picture = NULL;
if (fRecord.get()) {
picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
fRecord.detach(), fBBH.get()));
}
if (fPictureRecord.get()) {
fPictureRecord->endRecording();
const bool deepCopyOps = false;
picture = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight,
*fPictureRecord.get(), deepCopyOps));
}
return picture;
return SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.detach(), fBBH.get()));
}
void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
if (NULL == canvas) {
return;
}
if (fRecord.get()) {
SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/);
}
if (fPictureRecord.get()) {
const bool deepCopyOps = true;
SkPicture picture(fCullWidth, fCullHeight,
*fPictureRecord.get(), deepCopyOps);
picture.playback(canvas);
}
SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/);
}

Просмотреть файл

@ -121,10 +121,6 @@ static const int kHeight = 2;
static const char* const kDefaultAssertMessageFormat = "%s";
static const char* const kCanvasDrawAssertMessageFormat =
"Drawing test step %s with SkCanvas";
static const char* const kPictureDrawAssertMessageFormat =
"Drawing test step %s with SkPicture";
static const char* const kPictureSecondDrawAssertMessageFormat =
"Duplicate draw of test step %s with SkPicture";
static const char* const kDeferredDrawAssertMessageFormat =
"Drawing test step %s with SkDeferredCanvas";
static const char* const kProxyDrawAssertMessageFormat =
@ -137,8 +133,6 @@ static const char* const kDeferredPostFlushPlaybackAssertMessageFormat =
"test step %s, SkDeferredCanvas playback canvas state consistency after flush";
static const char* const kDeferredPostSilentFlushPlaybackAssertMessageFormat =
"test step %s, SkDeferredCanvas playback canvas state consistency after silent flush";
static const char* const kPictureResourceReuseMessageFormat =
"test step %s, SkPicture duplicate flattened object test";
static const char* const kProxyStateAssertMessageFormat =
"test step %s, SkProxyCanvas state consistency";
static const char* const kProxyIndirectStateAssertMessageFormat =
@ -463,7 +457,7 @@ static void DrawPictureTestStep(SkCanvas* canvas,
skiatest::Reporter*,
CanvasTestStep*) {
SkPictureRecorder recorder;
SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
NULL, 0);
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
testCanvas->clipRect(kTestRect);
@ -678,37 +672,6 @@ private:
*/
}
public:
static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter,
CanvasTestStep* testStep,
uint32_t recordFlags) {
// Verify that when a test step is executed twice, no extra resources
// are flattened during the second execution
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
SkPictureRecorder referenceRecorder;
SkCanvas* referenceCanvas =
referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
SkIntToScalar(kHeight),
NULL, recordFlags);
testStep->draw(referenceCanvas, reporter);
SkPictureRecorder testRecorder;
SkCanvas* testCanvas =
testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
SkIntToScalar(kHeight),
NULL, recordFlags);
testStep->draw(testCanvas, reporter);
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
testStep->draw(testCanvas, reporter);
SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(referenceCanvas);
SkPictureRecord* testRecord = static_cast<SkPictureRecord*>(testCanvas);
testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat);
AssertFlattenedObjectsEqual(referenceRecord, testRecord,
reporter, testStep);
}
};
static void TestPdfDevice(skiatest::Reporter* reporter,
@ -908,8 +871,6 @@ DEF_TEST(Canvas, reporter) {
for (int testStep = 0; testStep < testStepArray().count(); testStep++) {
TestOverrideStateConsistency(reporter, testStepArray()[testStep]);
SkPictureTester::TestPictureFlattenedObjectReuse(reporter,
testStepArray()[testStep], 0);
if (testStepArray()[testStep]->enablePdfTesting()) {
TestPdfDevice(reporter, testStepArray()[testStep]);
}

Просмотреть файл

@ -579,22 +579,18 @@ static void test_gatherpixelrefs(skiatest::Reporter* reporter) {
}
}
#define GENERATE_CANVAS(recorder, x) \
(x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
: recorder. DEPRECATED_beginRecording(100,100);
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */
static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) {
static void test_analysis(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
SkCanvas* canvas = recorder.beginRecording(100, 100);
{
canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
}
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
canvas = GENERATE_CANVAS(recorder, useNewPath);
canvas = recorder.beginRecording(100, 100);
{
SkPaint paint;
// CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader
@ -745,12 +741,10 @@ static void rand_op(SkCanvas* canvas, SkRandom& rand) {
#if SK_SUPPORT_GPU
static void test_gpu_veto(skiatest::Reporter* reporter,
bool useNewPath) {
static void test_gpu_veto(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
SkCanvas* canvas = recorder.beginRecording(100, 100);
{
SkPath path;
path.moveTo(0, 0);
@ -772,7 +766,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reason));
REPORTER_ASSERT(reporter, reason);
canvas = GENERATE_CANVAS(recorder, useNewPath);
canvas = recorder.beginRecording(100, 100);
{
SkPath path;
@ -794,7 +788,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter,
// A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
canvas = GENERATE_CANVAS(recorder, useNewPath);
canvas = recorder.beginRecording(100, 100);
{
SkPath path;
@ -818,7 +812,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter,
// hairline stroked AA concave paths are fine for GPU rendering
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
canvas = GENERATE_CANVAS(recorder, useNewPath);
canvas = recorder.beginRecording(100, 100);
{
SkPaint paint;
SkScalar intervals [] = { 10, 20 };
@ -832,7 +826,7 @@ static void test_gpu_veto(skiatest::Reporter* reporter,
// fast-path dashed effects are fine for GPU rendering ...
REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
canvas = GENERATE_CANVAS(recorder, useNewPath);
canvas = recorder.beginRecording(100, 100);
{
SkPaint paint;
SkScalar intervals [] = { 10, 20 };
@ -846,19 +840,14 @@ static void test_gpu_veto(skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
// Nest the previous picture inside a new one.
// This doesn't work in the old backend.
if (useNewPath) {
canvas = GENERATE_CANVAS(recorder, useNewPath);
{
canvas->drawPicture(picture.get());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
canvas = recorder.beginRecording(100, 100);
{
canvas->drawPicture(picture.get());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
}
#undef GENERATE_CANVAS
static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
GrContextFactory* factory) {
for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
@ -1072,12 +1061,10 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
#endif
static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
static void test_has_text(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
#define BEGIN_RECORDING useNewPath ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
: recorder. DEPRECATED_beginRecording(100, 100)
SkCanvas* canvas = BEGIN_RECORDING;
SkCanvas* canvas = recorder.beginRecording(100,100);
{
canvas->drawRect(SkRect::MakeWH(20, 20), SkPaint());
}
@ -1085,28 +1072,28 @@ static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
REPORTER_ASSERT(reporter, !picture->hasText());
SkPoint point = SkPoint::Make(10, 10);
canvas = BEGIN_RECORDING;
canvas = recorder.beginRecording(100,100);
{
canvas->drawText("Q", 1, point.fX, point.fY, SkPaint());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
canvas = BEGIN_RECORDING;
canvas = recorder.beginRecording(100,100);
{
canvas->drawPosText("Q", 1, &point, SkPaint());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
canvas = BEGIN_RECORDING;
canvas = recorder.beginRecording(100,100);
{
canvas->drawPosTextH("Q", 1, &point.fX, point.fY, SkPaint());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
canvas = BEGIN_RECORDING;
canvas = recorder.beginRecording(100,100);
{
SkPath path;
path.moveTo(0, 0);
@ -1117,7 +1104,7 @@ static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
canvas = BEGIN_RECORDING;
canvas = recorder.beginRecording(100,100);
{
SkPath path;
path.moveTo(0, 0);
@ -1129,16 +1116,12 @@ static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
REPORTER_ASSERT(reporter, picture->hasText());
// Nest the previous picture inside a new one.
// This doesn't work in the old backend.
if (useNewPath) {
canvas = BEGIN_RECORDING;
{
canvas->drawPicture(picture.get());
}
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
canvas = recorder.beginRecording(100,100);
{
canvas->drawPicture(picture.get());
}
#undef BEGIN_RECORDING
picture.reset(recorder.endRecording());
REPORTER_ASSERT(reporter, picture->hasText());
}
static void set_canvas_to_save_count_4(SkCanvas* canvas) {
@ -1775,13 +1758,10 @@ DEF_TEST(Picture, reporter) {
test_unbalanced_save_restores(reporter);
test_peephole();
#if SK_SUPPORT_GPU
test_gpu_veto(reporter, false);
test_gpu_veto(reporter, true);
test_gpu_veto(reporter);
#endif
test_has_text(reporter, false);
test_has_text(reporter, true);
test_analysis(reporter, false);
test_analysis(reporter, true);
test_has_text(reporter);
test_analysis(reporter);
test_gatherpixelrefs(reporter);
test_gatherpixelrefsandrects(reporter);
test_bitmap_with_encoded_data(reporter);