Ejemplo n.º 1
0
// Test the kReturnNullForEmpty_FinishFlag option when recording
//
DEF_TEST(Picture_RecordEmpty, r) {
    const SkRect cull = SkRect::MakeWH(100, 100);

    CanvasProc procs[] { empty_ops, clip_ops, matrix_ops, matrixclip_ops };

    for (auto proc : procs) {
        {
            SkPictureRecorder rec;
            proc(rec.beginRecording(cull));
            sk_sp<SkPicture> pic = rec.finishRecordingAsPicture(0);
            REPORTER_ASSERT(r, pic.get());
            REPORTER_ASSERT(r, pic->approximateOpCount() == 0);
        }
        {
            SkPictureRecorder rec;
            proc(rec.beginRecording(cull));
            sk_sp<SkPicture> pic = rec.finishRecordingAsPicture(
                                                 SkPictureRecorder::kReturnNullForEmpty_FinishFlag);
            REPORTER_ASSERT(r, !pic.get());
        }
        {
            SkPictureRecorder rec;
            proc(rec.beginRecording(cull));
            sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable(0);
            REPORTER_ASSERT(r, dr.get());
        }
        {
            SkPictureRecorder rec;
            proc(rec.beginRecording(cull));
            sk_sp<SkDrawable> dr = rec.finishRecordingAsDrawable(
                                                 SkPictureRecorder::kReturnNullForEmpty_FinishFlag);
            REPORTER_ASSERT(r, !dr.get());
        }
    }
}
Ejemplo n.º 2
0
    HTView() {
        SkRandom rand;

        SkPictureRecorder recorder;
        SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H));
        for (int i = 0; i < N; ++i) {
            fArray[i].fDrawable = new HTDrawable(rand);
            canvas->drawDrawable(fArray[i].fDrawable);
            fArray[i].fDrawable->unref();
        }
        fRoot = recorder.finishRecordingAsDrawable();
    }
Ejemplo n.º 3
0
sk_sp<SkFlattenable> SkRecordedDrawable::CreateProc(SkReadBuffer& buffer) {
    // Read the bounds.
    SkRect bounds;
    buffer.readRect(&bounds);

    // Unflatten into a SkPictureData.
    SkPictInfo info;
    info.fCullRect = bounds;
    SkAutoTDelete<SkPictureData> pictureData(SkPictureData::CreateFromBuffer(buffer, info));
    if (!pictureData) {
        return nullptr;
    }

    // Create a drawable.
    SkPicturePlayback playback(pictureData);
    SkPictureRecorder recorder;
    playback.draw(recorder.beginRecording(bounds), nullptr, &buffer);
    return recorder.finishRecordingAsDrawable();
}
DEF_TEST(FlattenRecordedDrawable, r) {
    // Record a set of canvas draw commands
    SkPictureRecorder recorder;
    SkCanvas* canvas = recorder.beginRecording(1000.0f, 1000.0f);
    SkPaint paint;
    paint.setColor(SK_ColorGREEN);
    canvas->drawPoint(42.0f, 17.0f, paint);
    paint.setColor(SK_ColorRED);
    canvas->drawPaint(paint);
    SkPaint textPaint;
    textPaint.setColor(SK_ColorBLUE);
    canvas->drawString("TEXT", 467.0f, 100.0f, textPaint);

    // Draw some drawables as well
    sk_sp<SkDrawable> drawable(new IntDrawable(1, 2, 3, 4));
    sk_sp<RootDrawable> root(new RootDrawable(5, 6, 7, 8, paint, 9, 10, 11, 12, drawable.get()));
    canvas->drawDrawable(root.get(), 747.0f, 242.0f);
    sk_sp<PaintDrawable> paintDrawable(new PaintDrawable(paint));
    canvas->drawDrawable(paintDrawable.get(), 500.0, 500.0f);
    sk_sp<CompoundDrawable> comDrawable(new CompoundDrawable(13, 14, 15, 16, textPaint));
    canvas->drawDrawable(comDrawable.get(), 10.0f, 10.0f);

    // Serialize the recorded drawable
    sk_sp<SkDrawable> recordedDrawable = recorder.finishRecordingAsDrawable();
    SkBinaryWriteBuffer writeBuffer;
    writeBuffer.writeFlattenable(recordedDrawable.get());

    // Copy the contents of the write buffer into a read buffer
    sk_sp<SkData> data = SkData::MakeUninitialized(writeBuffer.bytesWritten());
    writeBuffer.writeToMemory(data->writable_data());
    SkReadBuffer readBuffer(data->data(), data->size());
    register_test_drawables(readBuffer);

    // Deserialize and verify the drawable
    sk_sp<SkDrawable> out((SkDrawable*)readBuffer.readFlattenable(SkFlattenable::kSkDrawable_Type));
    REPORTER_ASSERT(r, out);
    REPORTER_ASSERT(r, !strcmp("SkRecordedDrawable", out->getTypeName()));
}