Home | History | Annotate | Download | only in core
      1 /*
      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"
     13 #include "SkTraceEvent.h"
     14 
     15 SkBigPicture::SkBigPicture(const SkRect& cull,
     16                            SkRecord* record,
     17                            SnapshotArray* drawablePicts,
     18                            SkBBoxHierarchy* bbh,
     19                            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.
     25 {}
     26 
     27 void 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     const bool useBBH = !canvas->getLocalClipBounds().contains(this->cullRect());
     32 
     33     SkRecordDraw(*fRecord,
     34                  canvas,
     35                  this->drawablePicts(),
     36                  nullptr,
     37                  this->drawableCount(),
     38                  useBBH ? fBBH.get() : nullptr,
     39                  callback);
     40 }
     41 
     42 void SkBigPicture::partialPlayback(SkCanvas* canvas,
     43                                    int start,
     44                                    int stop,
     45                                    const SkMatrix& initialCTM) const {
     46     SkASSERT(canvas);
     47     SkRecordPartialDraw(*fRecord,
     48                         canvas,
     49                         this->drawablePicts(),
     50                         this->drawableCount(),
     51                         start,
     52                         stop,
     53                         initialCTM);
     54 }
     55 
     56 const SkBigPicture::Analysis& SkBigPicture::analysis() const {
     57     fAnalysisOnce([this] { fAnalysis.init(*fRecord); });
     58     return fAnalysis;
     59 }
     60 
     61 SkRect SkBigPicture::cullRect()            const { return fCullRect; }
     62 bool   SkBigPicture::willPlayBackBitmaps() const { return this->analysis().fWillPlaybackBitmaps; }
     63 int    SkBigPicture::numSlowPaths() const { return this->analysis().fNumSlowPathsAndDashEffects; }
     64 int    SkBigPicture::approximateOpCount()   const { return fRecord->count(); }
     65 size_t SkBigPicture::approximateBytesUsed() const {
     66     size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures;
     67     if (fBBH) { bytes += fBBH->bytesUsed(); }
     68     return bytes;
     69 }
     70 
     71 int SkBigPicture::drawableCount() const {
     72     return fDrawablePicts ? fDrawablePicts->count() : 0;
     73 }
     74 
     75 SkPicture const* const* SkBigPicture::drawablePicts() const {
     76     return fDrawablePicts ? fDrawablePicts->begin() : nullptr;
     77 }
     78 
     79 void SkBigPicture::Analysis::init(const SkRecord& record) {
     80     TRACE_EVENT0("disabled-by-default-skia", "SkBigPicture::Analysis::init()");
     81     SkBitmapHunter bitmap;
     82     SkPathCounter  path;
     83 
     84     bool hasBitmap = false;
     85     for (int i = 0; i < record.count(); i++) {
     86         hasBitmap = hasBitmap || record.visit(i, bitmap);
     87         record.visit(i, path);
     88     }
     89 
     90     fWillPlaybackBitmaps        = hasBitmap;
     91     fNumSlowPathsAndDashEffects = SkTMin<int>(path.fNumSlowPathsAndDashEffects, 255);
     92 }
     93