skia2/include/private/SkMiniRecorder.h
Mike Klein 26eb16f1e3 calculate cull rects for SkMiniPictures
This is the other half of https://skia-review.googlesource.com/c/7874/,
adding the cull-shrinking feature of SkBigPictures to SkMiniPictures.

Like SkBigPictures, shrink only when we're asked to build an R-tree.
(We don't actually build a tree for one rect, of course.)

We could do unconditionally, but SkPictureImageFilter uses the cull rect
as its crop.  It's unclear to me what this image filter unit test I've
changed here was intending... had it had two draws we would have shrunk
its cull, but because it was hitting the 1-draw SkMiniPicture path it
kept the larger user-supplied cull.

As the test doesn't appear to have been written with cull shrinking in
mind, I've removed its SkRTreeFactory to keep that feature explicitly
disabled there.

BUG=skia:5974

Change-Id: I4118d2e85f2a69adef2e7a7fa9b9b8c17607a94f
Reviewed-on: https://skia-review.googlesource.com/12624
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
2017-04-20 15:02:19 +00:00

58 lines
1.6 KiB
C++

/*
* 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.
// If cull is nullptr we'll calculate it.
sk_sp<SkPicture> detachAsPicture(const SkRect* cull);
// Flush anything we've recorded to the canvas, resetting this SkMiniRecorder.
// This is logically the same as but rather more efficient than:
// sk_sp<SkPicture> pic(this->detachAsPicture(nullptr));
// pic->playback(canvas);
void flushAndReset(SkCanvas*);
private:
enum class State {
kEmpty,
kDrawPath,
kDrawRect,
kDrawTextBlob,
};
State fState;
template <size_t A, size_t B>
struct Max { static const size_t val = A > B ? A : B; };
static const size_t kInlineStorage =
Max<sizeof(SkRecords::DrawPath),
Max<sizeof(SkRecords::DrawRect),
sizeof(SkRecords::DrawTextBlob)>::val>::val;
SkAlignedSStorage<kInlineStorage> fBuffer;
};
#endif//SkMiniRecorder_DEFINED