From 15877b6eae33a9282458bdb904a6d00440eca0ec Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 18 May 2015 13:47:17 -0700 Subject: Sketch splitting SkPicture into an interface and SkBigPicture. Adds small pictures for drawRect(), drawTextBlob(), and drawPath(). These cover about 89% of draw calls from Blink SKPs, and about 25% of draw calls from our GMs. SkPicture handles: - serialization and deserialization - unique IDs Everything else is left to the subclasses: - playback(), cullRect() - hasBitmap(), hasText(), suitableForGPU(), etc. - LayerInfo / AccelData if applicable. The time to record a 1-op picture improves a good chunk (2 mallocs to 1), and the time to record a 0-op picture greatly improves (2 mallocs to none): picture_overhead_draw: 450ns -> 350ns picture_overhead_nodraw: 300ns -> 90ns BUG=skia: Committed: https://skia.googlesource.com/skia/+/c92c129ff85b05a714bd1bf921c02d5e14651f8b Latest blink_linux_rel: http://build.chromium.org/p/tryserver.blink/builders/linux_blink_rel/builds/61248 Review URL: https://codereview.chromium.org/1112523006 --- src/core/SkMiniRecorder.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/core/SkMiniRecorder.h (limited to 'src/core/SkMiniRecorder.h') diff --git a/src/core/SkMiniRecorder.h b/src/core/SkMiniRecorder.h new file mode 100644 index 0000000000..d01aedacea --- /dev/null +++ b/src/core/SkMiniRecorder.h @@ -0,0 +1,44 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkMiniRecorder_DEFINED +#define SkMiniRecorder_DEFINED + +#include "SkRecords.h" +#include "SkScalar.h" +#include "SkTypes.h" +class SkCanvas; + +// Records small pictures, but only a limited subset of the canvas API, and may fail. +class SkMiniRecorder : SkNoncopyable { +public: + SkMiniRecorder(); + ~SkMiniRecorder(); + + // Try to record an op. Returns false on failure. + bool drawPath(const SkPath&, const SkPaint&); + bool drawRect(const SkRect&, const SkPaint&); + bool drawTextBlob(const SkTextBlob*, SkScalar x, SkScalar y, const SkPaint&); + + // Detach anything we've recorded as a picture, resetting this SkMiniRecorder. + SkPicture* detachAsPicture(const SkRect& cull); + +private: + enum class State { kEmpty, kDrawPath, kDrawRect, kDrawTextBlob }; + + State fState; + + template + struct Max { static const size_t val = A > B ? A : B; }; + + static const size_t kInlineStorage = Max::val>::val; + SkAlignedSStorage fBuffer; +}; + +#endif//SkMiniRecorder_DEFINED -- cgit v1.2.3