本文整理汇总了C++中SkPictureRecorder::finishRecordingAsPicture方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPictureRecorder::finishRecordingAsPicture方法的具体用法?C++ SkPictureRecorder::finishRecordingAsPicture怎么用?C++ SkPictureRecorder::finishRecordingAsPicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPictureRecorder
的用法示例。
在下文中一共展示了SkPictureRecorder::finishRecordingAsPicture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_analysis
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */
static void test_analysis(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(100, 100);
{
canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
}
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
canvas = recorder.beginRecording(100, 100);
{
SkPaint paint;
// CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader
// gets optimized into a non-bitmap form, so we create a 2x2 bitmap here.
SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
bitmap.eraseColor(SK_ColorBLUE);
*(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode));
REPORTER_ASSERT(reporter, paint.getShader()->isABitmap());
canvas->drawRect(SkRect::MakeWH(10, 10), paint);
}
REPORTER_ASSERT(reporter, recorder.finishRecordingAsPicture()->willPlayBackBitmaps());
}
示例2: proc
// 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());
}
}
}
示例3: onDraw
virtual void onDraw(SkCanvas* canvas) {
constexpr SkScalar kOffset = 35000.0f;
constexpr SkScalar kExtents = 1000.0f;
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.
SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents, nullptr, 0);
rec->drawColor(SK_ColorRED);
rec->save();
SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents);
SkPath p;
p.addRoundRect(r, 5, 5);
rec->clipPath(p, true);
rec->drawColor(SK_ColorGREEN);
rec->restore();
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
// Next we play that picture into another picture of the same size.
pict->playback(recorder.beginRecording(pict->cullRect().width(),
pict->cullRect().height(),
nullptr, 0));
sk_sp<SkPicture> pict2(recorder.finishRecordingAsPicture());
// Finally we play the part of that second picture that should be green into the canvas.
canvas->save();
canvas->translate(kExtents / 2, -(kOffset - kExtents / 2));
pict2->playback(canvas);
canvas->restore();
// If the image is red, we erroneously decided the clipPath was empty and didn't record
// the green drawColor, if it's green we're all good.
}
示例4: test_unbalanced_save_restores
static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
SkCanvas testCanvas(100, 100);
set_canvas_to_save_count_4(&testCanvas);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
SkPaint paint;
SkRect rect = SkRect::MakeLTRB(-10000000, -10000000, 10000000, 10000000);
SkPictureRecorder recorder;
{
// Create picture with 2 unbalanced saves
SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->save();
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
canvas->save();
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
sk_sp<SkPicture> extraSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraSavePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
}
set_canvas_to_save_count_4(&testCanvas);
{
// Create picture with 2 unbalanced restores
SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->save();
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
canvas->save();
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
canvas->restore();
canvas->restore();
canvas->restore();
canvas->restore();
sk_sp<SkPicture> extraRestorePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(extraRestorePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
}
set_canvas_to_save_count_4(&testCanvas);
{
SkCanvas* canvas = recorder.beginRecording(100, 100);
canvas->translate(10, 10);
canvas->drawRect(rect, paint);
sk_sp<SkPicture> noSavePicture(recorder.finishRecordingAsPicture());
testCanvas.drawPicture(noSavePicture);
REPORTER_ASSERT(reporter, 4 == testCanvas.getSaveCount());
REPORTER_ASSERT(reporter, testCanvas.getTotalMatrix().isIdentity());
}
}
示例5: test_peephole
static void test_peephole() {
SkRandom rand;
SkPictureRecorder recorder;
for (int j = 0; j < 100; j++) {
SkRandom rand2(rand); // remember the seed
SkCanvas* canvas = recorder.beginRecording(100, 100);
for (int i = 0; i < 1000; ++i) {
rand_op(canvas, rand);
}
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
rand = rand2;
}
{
SkCanvas* canvas = recorder.beginRecording(100, 100);
SkRect rect = SkRect::MakeWH(50, 50);
for (int i = 0; i < 100; ++i) {
canvas->save();
}
while (canvas->getSaveCount() > 1) {
canvas->clipRect(rect);
canvas->restore();
}
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
}
}
示例6: tool_main
int tool_main(int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv);
for (int i = 0; i < FLAGS_skps.count(); i++) {
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
continue;
}
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
if (!stream) {
SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
return 1;
}
sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream));
if (!src) {
SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
return 1;
}
if (FLAGS_defer) {
SkPictureRecorder recorder;
SkDeferredCanvas deferred(recorder.beginRecording(src->cullRect()));
src->playback(&deferred);
src = recorder.finishRecordingAsPicture();
}
const int w = SkScalarCeilToInt(src->cullRect().width());
const int h = SkScalarCeilToInt(src->cullRect().height());
SkRecord record;
SkRecorder canvas(&record, w, h);
src->playback(&canvas);
if (FLAGS_optimize) {
SkRecordOptimize(&record);
}
if (FLAGS_optimize2) {
SkRecordOptimize2(&record);
}
dump(FLAGS_skps[i], w, h, record);
if (FLAGS_write.count() > 0) {
SkPictureRecorder r;
SkRecordDraw(record,
r.beginRecording(SkRect::MakeIWH(w, h)),
nullptr,
nullptr,
0,
nullptr,
nullptr);
sk_sp<SkPicture> dst(r.finishRecordingAsPicture());
SkFILEWStream ostream(FLAGS_write[0]);
dst->serialize(&ostream);
}
}
return 0;
}
示例7: test_serializing_empty_picture
// Ensure that serializing an empty picture does not assert. Likewise only runs in debug mode.
static void test_serializing_empty_picture() {
SkPictureRecorder recorder;
recorder.beginRecording(0, 0);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkDynamicMemoryWStream stream;
picture->serialize(&stream);
}
示例8: stream
PassRefPtr<PictureSnapshot> PictureSnapshot::load(const Vector<RefPtr<TilePictureStream>>& tiles)
{
ASSERT(!tiles.isEmpty());
Vector<sk_sp<SkPicture>> pictures;
pictures.reserveCapacity(tiles.size());
FloatRect unionRect;
for (const auto& tileStream : tiles) {
SkMemoryStream stream(tileStream->data.begin(), tileStream->data.size());
sk_sp<SkPicture> picture = SkPicture::MakeFromStream(&stream, decodeBitmap);
if (!picture)
return nullptr;
FloatRect cullRect(picture->cullRect());
cullRect.moveBy(tileStream->layerOffset);
unionRect.unite(cullRect);
pictures.append(std::move(picture));
}
if (tiles.size() == 1)
return adoptRef(new PictureSnapshot(fromSkSp(std::move(pictures[0]))));
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(unionRect.width(), unionRect.height(), 0, 0);
for (size_t i = 0; i < pictures.size(); ++i) {
canvas->save();
canvas->translate(tiles[i]->layerOffset.x() - unionRect.x(), tiles[i]->layerOffset.y() - unionRect.y());
pictures[i]->playback(canvas, 0);
canvas->restore();
}
return adoptRef(new PictureSnapshot(fromSkSp(recorder.finishRecordingAsPicture())));
}
示例9: onDraw
void onDraw(SkCanvas* canvas) override {
SkPictureRecorder recorder;
SkCanvas* rec = recorder.beginRecording(1200, 900, nullptr, 0);
SkPath p;
SkRect r = {
SkIntToScalar(100),
SkIntToScalar(200),
SkIntToScalar(400),
SkIntToScalar(700)
};
p.addRoundRect(r, SkIntToScalar(50), SkIntToScalar(50));
rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->translate(SkIntToScalar(250), SkIntToScalar(250));
rec->clipPath(p, SkRegion::kIntersect_Op, true);
rec->drawColor(0xffff0000);
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
canvas->setAllowSimplifyClip(true);
canvas->save();
canvas->drawPicture(pict);
canvas->restore();
canvas->setAllowSimplifyClip(false);
canvas->save();
canvas->translate(SkIntToScalar(1200 / 2), 0);
canvas->drawPicture(pict);
canvas->restore();
}
示例10: fName
PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
// Flatten the source picture in case it's trivially nested (useless for timing).
SkPictureRecorder rec;
pic->playback(rec.beginRecording(pic->cullRect(), nullptr,
SkPictureRecorder::kPlaybackDrawPicture_RecordFlag));
fSrc = rec.finishRecordingAsPicture();
}
示例11: SkASSERT
DEF_TEST(Picture_BitmapLeak, r) {
SkBitmap mut, immut;
mut.allocN32Pixels(300, 200);
immut.allocN32Pixels(300, 200);
immut.setImmutable();
SkASSERT(!mut.isImmutable());
SkASSERT(immut.isImmutable());
// No one can hold a ref on our pixels yet.
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique());
sk_sp<SkPicture> pic;
{
// we want the recorder to go out of scope before our subsequent checks, so we
// place it inside local braces.
SkPictureRecorder rec;
SkCanvas* canvas = rec.beginRecording(1920, 1200);
canvas->drawBitmap(mut, 0, 0);
canvas->drawBitmap(immut, 800, 600);
pic = rec.finishRecordingAsPicture();
}
// The picture shares the immutable pixels but copies the mutable ones.
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, !immut.pixelRef()->unique());
// When the picture goes away, it's just our bitmaps holding the refs.
pic = nullptr;
REPORTER_ASSERT(r, mut.pixelRef()->unique());
REPORTER_ASSERT(r, immut.pixelRef()->unique());
}
示例12: onOnceBeforeDraw
void onOnceBeforeDraw() override {
const SkRect rect = SkRect::MakeWH(kPictureWidth, kPictureHeight);
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(rect);
draw_vector_logo(canvas, rect);
fPicture = recorder.finishRecordingAsPicture();
}
示例13: onDrawContent
void GMSampleView::onDrawContent(SkCanvas* canvas) {
SkPictureRecorder recorder;
SkCanvas* origCanvas = canvas;
if (false) {
SkISize size = fGM->getISize();
canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.height()));
}
{
SkAutoCanvasRestore acr(canvas, fShowSize);
fGM->drawContent(canvas);
}
if (origCanvas != canvas) {
sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
if (false) {
pic = round_trip_serialize(pic.get());
}
origCanvas->drawPicture(pic);
canvas = origCanvas;
}
if (fShowSize) {
SkISize size = fGM->getISize();
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
SkIntToScalar(size.height()));
SkPaint paint;
paint.setColor(0x40FF8833);
canvas->drawRect(r, paint);
}
}
示例14: serialize_and_compare_typeface
static void serialize_and_compare_typeface(sk_sp<SkTypeface> typeface, const char* text,
skiatest::Reporter* reporter)
{
// Create a paint with the typeface.
SkPaint paint;
paint.setColor(SK_ColorGRAY);
paint.setTextSize(SkIntToScalar(30));
paint.setTypeface(std::move(typeface));
// Paint some text.
SkPictureRecorder recorder;
SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize);
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()),
SkIntToScalar(canvasRect.height()),
nullptr, 0);
canvas->drawColor(SK_ColorWHITE);
canvas->drawText(text, 2, 24, 32, paint);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
// Serlialize picture and create its clone from stream.
SkDynamicMemoryWStream stream;
picture->serialize(&stream);
std::unique_ptr<SkStream> inputStream(stream.detachAsStream());
sk_sp<SkPicture> loadedPicture(SkPicture::MakeFromStream(inputStream.get()));
// Draw both original and clone picture and compare bitmaps -- they should be identical.
SkBitmap origBitmap = draw_picture(*picture);
SkBitmap destBitmap = draw_picture(*loadedPicture);
compare_bitmaps(reporter, origBitmap, destBitmap);
}
示例15: canvas
/*
* Test the 3 annotation types by recording them into a picture, serializing, and then playing
* them back into another canvas.
*/
DEF_TEST(Annotations, reporter) {
SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100));
const char* str0 = "rect-with-url";
const SkRect r0 = SkRect::MakeWH(10, 10);
sk_sp<SkData> d0(SkData::MakeWithCString(str0));
SkAnnotateRectWithURL(recordingCanvas, r0, d0.get());
const char* str1 = "named-destination";
const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point
sk_sp<SkData> d1(SkData::MakeWithCString(str1));
SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1.get());
const char* str2 = "link-to-destination";
const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6);
sk_sp<SkData> d2(SkData::MakeWithCString(str2));
SkAnnotateLinkToDestination(recordingCanvas, r2, d2.get());
const AnnotationRec recs[] = {
{ r0, SkAnnotationKeys::URL_Key(), std::move(d0) },
{ r1, SkAnnotationKeys::Define_Named_Dest_Key(), std::move(d1) },
{ r2, SkAnnotationKeys::Link_Named_Dest_Key(), std::move(d2) },
};
sk_sp<SkPicture> pict0(recorder.finishRecordingAsPicture());
sk_sp<SkPicture> pict1(copy_picture_via_serialization(pict0.get()));
TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
canvas.drawPicture(pict1);
}