blob: 2a2e438fd6a3af02067904e4d2a2b8c0630029d9 [file] [log] [blame]
mtklein9db912c2015-05-19 11:11:26 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkBBoxHierarchy.h"
9#include "SkBigPicture.h"
10#include "SkPictureCommon.h"
11#include "SkRecord.h"
12#include "SkRecordDraw.h"
mtkleine01008f2015-08-27 10:39:07 -070013#include "SkTraceEvent.h"
mtklein9db912c2015-05-19 11:11:26 -070014
15SkBigPicture::SkBigPicture(const SkRect& cull,
16 SkRecord* record,
17 SnapshotArray* drawablePicts,
18 SkBBoxHierarchy* bbh,
mtklein9db912c2015-05-19 11:11:26 -070019 size_t approxBytesUsedBySubPictures)
20 : fCullRect(cull)
21 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures)
22 , fRecord(record) // Take ownership of caller's ref.
23 , fDrawablePicts(drawablePicts) // Take ownership.
24 , fBBH(bbh) // Take ownership of caller's ref.
mtklein9db912c2015-05-19 11:11:26 -070025{}
26
27void SkBigPicture::playback(SkCanvas* canvas, AbortCallback* callback) const {
28 SkASSERT(canvas);
29
30 // If the query contains the whole picture, don't bother with the BBH.
31 SkRect clipBounds = { 0, 0, 0, 0 };
32 (void)canvas->getClipBounds(&clipBounds);
33 const bool useBBH = !clipBounds.contains(this->cullRect());
34
35 SkRecordDraw(*fRecord,
36 canvas,
37 this->drawablePicts(),
38 nullptr,
39 this->drawableCount(),
40 useBBH ? fBBH.get() : nullptr,
41 callback);
42}
43
44void SkBigPicture::partialPlayback(SkCanvas* canvas,
mtkleinc6ad06a2015-08-19 09:51:00 -070045 int start,
46 int stop,
mtklein9db912c2015-05-19 11:11:26 -070047 const SkMatrix& initialCTM) const {
48 SkASSERT(canvas);
49 SkRecordPartialDraw(*fRecord,
50 canvas,
51 this->drawablePicts(),
52 this->drawableCount(),
53 start,
54 stop,
55 initialCTM);
56}
57
58const SkBigPicture::Analysis& SkBigPicture::analysis() const {
mtklein59c12e32016-05-02 07:19:41 -070059 fAnalysisOnce([this] { fAnalysis.init(*fRecord); });
60 return fAnalysis;
mtklein9db912c2015-05-19 11:11:26 -070061}
62
63SkRect SkBigPicture::cullRect() const { return fCullRect; }
mtklein9db912c2015-05-19 11:11:26 -070064bool SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; }
65int SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; }
66int SkBigPicture::approximateOpCount() const { return fRecord->count(); }
67size_t SkBigPicture::approximateBytesUsed() const {
68 size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
69 if (fBBH) { bytes += fBBH->bytesUsed(); }
70 return bytes;
71}
72
73int SkBigPicture::drawableCount() const {
74 return fDrawablePicts ? fDrawablePicts->count() : 0;
75}
76
77SkPicture const* const* SkBigPicture::drawablePicts() const {
78 return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
79}
80
mtklein59c12e32016-05-02 07:19:41 -070081void SkBigPicture::Analysis::init(const SkRecord& record) {
82 TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::init()");
mtklein9db912c2015-05-19 11:11:26 -070083 SkBitmapHunter bitmap;
84 SkPathCounter path;
85
fmalita1e2e33a2016-05-12 10:53:49 -070086 bool hasBitmap = false;
mtkleinc6ad06a2015-08-19 09:51:00 -070087 for (int i = 0; i < record.count(); i++) {
mtklein343a63d2016-03-22 11:46:53 -070088 hasBitmap = hasBitmap || record.visit(i, bitmap);
89 record.visit(i, path);
mtklein9db912c2015-05-19 11:11:26 -070090 }
91
mtklein9db912c2015-05-19 11:11:26 -070092 fWillPlaybackBitmaps = hasBitmap;
93 fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255);
94}