1c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org/*
2c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * Copyright 2014 Google Inc.
3c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org *
4c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
5c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org * found in the LICENSE file.
6c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org */
7c4b21e6c03a6cdb03e116b9f510eb10cf8daedb1commit-bot@chromium.org
8e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#ifndef SkRecordDraw_DEFINED
9e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#define SkRecordDraw_DEFINED
10e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org
115ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein#include "SkBBoxHierarchy.h"
129db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein#include "SkBigPicture.h"
13e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#include "SkCanvas.h"
144815fe5a0a497b676677fb4e4a0f05c511855490robertphillips#include "SkMatrix.h"
155ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein#include "SkRecord.h"
165ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein
173cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable;
1882365915476caedc130d0e36012a1ce0c007c4aerobertphillipsclass SkLayerInfo;
1982365915476caedc130d0e36012a1ce0c007c4aerobertphillips
202880df2609eba09b555ca37be04b6ad89290c765Tom Hudson// Calculate conservative identity space bounds for each op in the record.
212880df2609eba09b555ca37be04b6ad89290c765Tom Hudsonvoid SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkRect bounds[]);
22e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org
232880df2609eba09b555ca37be04b6ad89290c765Tom Hudson// SkRecordFillBounds(), and gathers information about saveLayers and stores it for later
242880df2609eba09b555ca37be04b6ad89290c765Tom Hudson// use (e.g., layer hoisting). The gathered information is sufficient to determine
252880df2609eba09b555ca37be04b6ad89290c765Tom Hudson// where each saveLayer will land and which ops in the picture it represents.
262880df2609eba09b555ca37be04b6ad89290c765Tom Hudsonvoid SkRecordComputeLayers(const SkRect& cullRect, const SkRecord&, SkRect bounds[],
272880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                           const SkBigPicture::SnapshotArray*, SkLayerInfo* data);
284e8e3421aa919a82eb1dd287fecbd079f5a320b4robertphillips
2927f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// Draw an SkRecord into an SkCanvas.  A convenience wrapper around SkRecords::Draw.
301bdfd3f4f09e47364f76d3f08177b1ce844ac786reedvoid SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[],
313cb3840c9af6f70896cf5565a38d4ee03c02d767reed                  SkDrawable* const drawables[], int drawableCount,
32783fe16b8ed1cd1cff34eacc33296874a32f293brobertphillips                  const SkBBoxHierarchy*, SkPicture::AbortCallback*);
33e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org
348eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed// Draw a portion of an SkRecord into an SkCanvas.
354815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
364815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the composition of the replay matrix with the record-time CTM (for the portion
374815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// of the record that is being replayed). For setMatrix calls to behave correctly
384815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the initialCTM parameter must set to just the replay matrix.
396be2aa9a251bf6022570a03140f956655b3ef1dareedvoid SkRecordPartialDraw(const SkRecord&, SkCanvas*,
406be2aa9a251bf6022570a03140f956655b3ef1dareed                         SkPicture const* const drawablePicts[], int drawableCount,
412880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                         int start, int stop, const SkMatrix& initialCTM);
4200f30bdc9e34b013da54b4406f36556c5be8d041mtklein
4327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgnamespace SkRecords {
4427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org
4527f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
4627f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgclass Draw : SkNoncopyable {
4727f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgpublic:
481bdfd3f4f09e47364f76d3f08177b1ce844ac786reed    explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
493cb3840c9af6f70896cf5565a38d4ee03c02d767reed                  SkDrawable* const drawables[], int drawableCount,
502880df2609eba09b555ca37be04b6ad89290c765Tom Hudson                  const SkMatrix* initialCTM = nullptr)
514815fe5a0a497b676677fb4e4a0f05c511855490robertphillips        : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
526be2aa9a251bf6022570a03140f956655b3ef1dareed        , fCanvas(canvas)
536be2aa9a251bf6022570a03140f956655b3ef1dareed        , fDrawablePicts(drawablePicts)
541bdfd3f4f09e47364f76d3f08177b1ce844ac786reed        , fDrawables(drawables)
556be2aa9a251bf6022570a03140f956655b3ef1dareed        , fDrawableCount(drawableCount)
566be2aa9a251bf6022570a03140f956655b3ef1dareed    {}
5727f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org
58d239d425148e5c1445b6a99d9bc33348c41197bcdanakj    // This operator calls methods on the |canvas|. The various draw() wrapper
59d239d425148e5c1445b6a99d9bc33348c41197bcdanakj    // methods around SkCanvas are defined by the DRAW() macro in
60d239d425148e5c1445b6a99d9bc33348c41197bcdanakj    // SkRecordDraw.cpp.
6127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org    template <typename T> void operator()(const T& r) {
62f4078ad1ec42f549369ac4f639aab18d00afae95mtklein        this->draw(r);
6327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org    }
6427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org
656be2aa9a251bf6022570a03140f956655b3ef1dareedprotected:
666be2aa9a251bf6022570a03140f956655b3ef1dareed    SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
676be2aa9a251bf6022570a03140f956655b3ef1dareed    int drawableCount() const { return fDrawableCount; }
686be2aa9a251bf6022570a03140f956655b3ef1dareed
6927f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgprivate:
7027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org    // No base case, so we'll be compile-time checked that we implement all possibilities.
7127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org    template <typename T> void draw(const T&);
7227f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org
730a98d870448f66ea0df7c37a47b38cf2d3b734e5commit-bot@chromium.org    const SkMatrix fInitialCTM;
7427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org    SkCanvas* fCanvas;
756be2aa9a251bf6022570a03140f956655b3ef1dareed    SkPicture const* const* fDrawablePicts;
763cb3840c9af6f70896cf5565a38d4ee03c02d767reed    SkDrawable* const* fDrawables;
776be2aa9a251bf6022570a03140f956655b3ef1dareed    int fDrawableCount;
7800f30bdc9e34b013da54b4406f36556c5be8d041mtklein};
7900f30bdc9e34b013da54b4406f36556c5be8d041mtklein
8027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org}  // namespace SkRecords
8127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org
82e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#endif//SkRecordDraw_DEFINED
83