blob: da3d3a841808da5339ff82a64d04d08b705d984d [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,
19 AccelData* accelData,
20 size_t approxBytesUsedBySubPictures)
21 : fCullRect(cull)
22 , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures)
23 , fRecord(record) // Take ownership of caller's ref.
24 , fDrawablePicts(drawablePicts) // Take ownership.
25 , fBBH(bbh) // Take ownership of caller's ref.
26 , fAccelData(accelData) // Take ownership of caller's ref.
27{}
28
29void SkBigPicture::playback(SkCanvas* canvas, AbortCallback* callback) const {
30 SkASSERT(canvas);
31
32 // If the query contains the whole picture, don't bother with the BBH.
33 SkRect clipBounds = { 0, 0, 0, 0 };
34 (void)canvas->getClipBounds(&clipBounds);
35 const bool useBBH = !clipBounds.contains(this->cullRect());
36
37 SkRecordDraw(*fRecord,
38 canvas,
39 this->drawablePicts(),
40 nullptr,
41 this->drawableCount(),
42 useBBH ? fBBH.get() : nullptr,
43 callback);
44}
45
46void SkBigPicture::partialPlayback(SkCanvas* canvas,
mtkleinc6ad06a2015-08-19 09:51:00 -070047 int start,
48 int stop,
mtklein9db912c2015-05-19 11:11:26 -070049 const SkMatrix& initialCTM) const {
50 SkASSERT(canvas);
51 SkRecordPartialDraw(*fRecord,
52 canvas,
53 this->drawablePicts(),
54 this->drawableCount(),
55 start,
56 stop,
57 initialCTM);
58}
59
60const SkBigPicture::Analysis& SkBigPicture::analysis() const {
mtklein59c12e32016-05-02 07:19:41 -070061 fAnalysisOnce([this] { fAnalysis.init(*fRecord); });
62 return fAnalysis;
mtklein9db912c2015-05-19 11:11:26 -070063}
64
65SkRect SkBigPicture::cullRect() const { return fCullRect; }
66bool SkBigPicture::hasText() const { return this->analysis().fHasText; }
67bool SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; }
68int SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; }
69int SkBigPicture::approximateOpCount() const { return fRecord->count(); }
70size_t SkBigPicture::approximateBytesUsed() const {
71 size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
72 if (fBBH) { bytes += fBBH->bytesUsed(); }
73 return bytes;
74}
75
76int SkBigPicture::drawableCount() const {
77 return fDrawablePicts ? fDrawablePicts->count() : 0;
78}
79
80SkPicture const* const* SkBigPicture::drawablePicts() const {
81 return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
82}
83
mtklein59c12e32016-05-02 07:19:41 -070084void SkBigPicture::Analysis::init(const SkRecord& record) {
85 TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::init()");
mtklein9db912c2015-05-19 11:11:26 -070086 SkTextHunter text;
87 SkBitmapHunter bitmap;
88 SkPathCounter path;
89
90 bool hasText = false, hasBitmap = false;
mtkleinc6ad06a2015-08-19 09:51:00 -070091 for (int i = 0; i < record.count(); i++) {
mtklein343a63d2016-03-22 11:46:53 -070092 hasText = hasText || record.visit(i, text);
93 hasBitmap = hasBitmap || record.visit(i, bitmap);
94 record.visit(i, path);
mtklein9db912c2015-05-19 11:11:26 -070095 }
96
97 fHasText = hasText;
98 fWillPlaybackBitmaps = hasBitmap;
99 fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255);
100}