blob: 70f68db337d0c2a7db931da6ec57d7b5d9e946aa [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 {
mtklein6c59d802015-09-09 09:09:53 -070061 return *fAnalysis.get([&]{ return new Analysis(*fRecord); });
mtklein9db912c2015-05-19 11:11:26 -070062}
63
64SkRect SkBigPicture::cullRect() const { return fCullRect; }
65bool SkBigPicture::hasText() const { return this->analysis().fHasText; }
66bool SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; }
67int SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; }
68int SkBigPicture::approximateOpCount() const { return fRecord->count(); }
69size_t SkBigPicture::approximateBytesUsed() const {
70 size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
71 if (fBBH) { bytes += fBBH->bytesUsed(); }
72 return bytes;
73}
74
75int SkBigPicture::drawableCount() const {
76 return fDrawablePicts ? fDrawablePicts->count() : 0;
77}
78
79SkPicture const* const* SkBigPicture::drawablePicts() const {
80 return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
81}
82
83SkBigPicture::Analysis::Analysis(const SkRecord& record) {
mtkleine01008f2015-08-27 10:39:07 -070084 TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::Analysis()");
mtklein9db912c2015-05-19 11:11:26 -070085 SkTextHunter text;
86 SkBitmapHunter bitmap;
87 SkPathCounter path;
88
89 bool hasText = false, hasBitmap = false;
mtkleinc6ad06a2015-08-19 09:51:00 -070090 for (int i = 0; i < record.count(); i++) {
mtklein343a63d2016-03-22 11:46:53 -070091 hasText = hasText || record.visit(i, text);
92 hasBitmap = hasBitmap || record.visit(i, bitmap);
93 record.visit(i, path);
mtklein9db912c2015-05-19 11:11:26 -070094 }
95
96 fHasText = hasText;
97 fWillPlaybackBitmaps = hasBitmap;
98 fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255);
99}