LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/core - SkRecordedDrawable.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 44 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2016 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 "SkMatrix.h"
       9             : #include "SkPictureData.h"
      10             : #include "SkPicturePlayback.h"
      11             : #include "SkPictureRecord.h"
      12             : #include "SkPictureRecorder.h"
      13             : #include "SkRecordedDrawable.h"
      14             : #include "SkRecordDraw.h"
      15             : 
      16           0 : void SkRecordedDrawable::onDraw(SkCanvas* canvas) {
      17           0 :     SkDrawable* const* drawables = nullptr;
      18           0 :     int drawableCount = 0;
      19           0 :     if (fDrawableList) {
      20           0 :         drawables = fDrawableList->begin();
      21           0 :         drawableCount = fDrawableList->count();
      22             :     }
      23           0 :     SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, fBBH.get(), nullptr);
      24           0 : }
      25             : 
      26           0 : SkPicture* SkRecordedDrawable::onNewPictureSnapshot() {
      27           0 :     SkBigPicture::SnapshotArray* pictList = nullptr;
      28           0 :     if (fDrawableList) {
      29             :         // TODO: should we plumb-down the BBHFactory and recordFlags from our host
      30             :         //       PictureRecorder?
      31           0 :         pictList = fDrawableList->newDrawableSnapshot();
      32             :     }
      33             : 
      34           0 :     size_t subPictureBytes = 0;
      35           0 :     for (int i = 0; pictList && i < pictList->count(); i++) {
      36           0 :         subPictureBytes += pictList->begin()[i]->approximateBytesUsed();
      37             :     }
      38             :     // SkBigPicture will take ownership of a ref on both fRecord and fBBH.
      39             :     // We're not willing to give up our ownership, so we must ref them for SkPicture.
      40           0 :     return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()),
      41           0 :                             subPictureBytes);
      42             : }
      43             : 
      44           0 : void SkRecordedDrawable::flatten(SkWriteBuffer& buffer) const {
      45             :     // Write the bounds.
      46           0 :     buffer.writeRect(fBounds);
      47             : 
      48             :     // Create an SkPictureRecord to record the draw commands.
      49           0 :     SkPictInfo info;
      50           0 :     SkPictureRecord pictureRecord(SkISize::Make(fBounds.width(), fBounds.height()), 0);
      51             : 
      52             :     // If the query contains the whole picture, don't bother with the bounding box hierarchy.
      53             :     SkBBoxHierarchy* bbh;
      54           0 :     if (pictureRecord.getLocalClipBounds().contains(fBounds)) {
      55           0 :         bbh = nullptr;
      56             :     } else {
      57           0 :         bbh = fBBH.get();
      58             :     }
      59             : 
      60             :     // Record the draw commands.
      61           0 :     pictureRecord.beginRecording();
      62           0 :     SkRecordDraw(*fRecord, &pictureRecord, nullptr, fDrawableList->begin(), fDrawableList->count(),
      63           0 :                 bbh, nullptr);
      64           0 :     pictureRecord.endRecording();
      65             : 
      66             :     // Flatten the recorded commands and drawables.
      67           0 :     SkPictureData pictureData(pictureRecord, info);
      68           0 :     pictureData.flatten(buffer);
      69           0 : }
      70             : 
      71           0 : sk_sp<SkFlattenable> SkRecordedDrawable::CreateProc(SkReadBuffer& buffer) {
      72             :     // Read the bounds.
      73             :     SkRect bounds;
      74           0 :     buffer.readRect(&bounds);
      75             : 
      76             :     // Unflatten into a SkPictureData.
      77           0 :     SkPictInfo info;
      78           0 :     info.setVersion(buffer.getVersion());
      79           0 :     info.fCullRect = bounds;
      80           0 :     info.fFlags = 0;    // ???
      81           0 :     std::unique_ptr<SkPictureData> pictureData(SkPictureData::CreateFromBuffer(buffer, info));
      82           0 :     if (!pictureData) {
      83           0 :         return nullptr;
      84             :     }
      85             : 
      86             :     // Create a drawable.
      87           0 :     SkPicturePlayback playback(pictureData.get());
      88           0 :     SkPictureRecorder recorder;
      89           0 :     playback.draw(recorder.beginRecording(bounds), nullptr, &buffer);
      90           0 :     return recorder.finishRecordingAsDrawable();
      91             : }

Generated by: LCOV version 1.13