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" 12e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#include "SkCanvas.h" 134815fe5a0a497b676677fb4e4a0f05c511855490robertphillips#include "SkMatrix.h" 145ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein#include "SkRecord.h" 155ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein 163cb3840c9af6f70896cf5565a38d4ee03c02d767reedclass SkDrawable; 1782365915476caedc130d0e36012a1ce0c007c4aerobertphillipsclass SkLayerInfo; 1882365915476caedc130d0e36012a1ce0c007c4aerobertphillips 195ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein// Fill a BBH to be used by SkRecordDraw to accelerate playback. 204d52afef5cf90a2fed3bb69db71675c6450ab397robertphillipsvoid SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy*); 21e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org 224e8e3421aa919a82eb1dd287fecbd079f5a320b4robertphillipsvoid SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, 231bdfd3f4f09e47364f76d3f08177b1ce844ac786reed const SkPicture::SnapshotArray*, 2482365915476caedc130d0e36012a1ce0c007c4aerobertphillips SkBBoxHierarchy* bbh, SkLayerInfo* data); 254e8e3421aa919a82eb1dd287fecbd079f5a320b4robertphillips 2627f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. 271bdfd3f4f09e47364f76d3f08177b1ce844ac786reedvoid SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[], 283cb3840c9af6f70896cf5565a38d4ee03c02d767reed SkDrawable* const drawables[], int drawableCount, 29783fe16b8ed1cd1cff34eacc33296874a32f293brobertphillips const SkBBoxHierarchy*, SkPicture::AbortCallback*); 30e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org 318eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed// Draw a portion of an SkRecord into an SkCanvas. 324815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// When drawing a portion of an SkRecord the CTM on the passed in canvas must be 334815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the composition of the replay matrix with the record-time CTM (for the portion 344815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// of the record that is being replayed). For setMatrix calls to behave correctly 354815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the initialCTM parameter must set to just the replay matrix. 366be2aa9a251bf6022570a03140f956655b3ef1dareedvoid SkRecordPartialDraw(const SkRecord&, SkCanvas*, 376be2aa9a251bf6022570a03140f956655b3ef1dareed SkPicture const* const drawablePicts[], int drawableCount, 388eddfb50c0c9e4bcba6384a2ce39852b5fb5becbreed unsigned start, unsigned stop, const SkMatrix& initialCTM); 3900f30bdc9e34b013da54b4406f36556c5be8d041mtklein 4027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgnamespace SkRecords { 4127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 4227f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 4327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgclass Draw : SkNoncopyable { 4427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgpublic: 451bdfd3f4f09e47364f76d3f08177b1ce844ac786reed explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], 463cb3840c9af6f70896cf5565a38d4ee03c02d767reed SkDrawable* const drawables[], int drawableCount, 476be2aa9a251bf6022570a03140f956655b3ef1dareed const SkMatrix* initialCTM = NULL) 484815fe5a0a497b676677fb4e4a0f05c511855490robertphillips : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) 496be2aa9a251bf6022570a03140f956655b3ef1dareed , fCanvas(canvas) 506be2aa9a251bf6022570a03140f956655b3ef1dareed , fDrawablePicts(drawablePicts) 511bdfd3f4f09e47364f76d3f08177b1ce844ac786reed , fDrawables(drawables) 526be2aa9a251bf6022570a03140f956655b3ef1dareed , fDrawableCount(drawableCount) 536be2aa9a251bf6022570a03140f956655b3ef1dareed {} 5427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 55d239d425148e5c1445b6a99d9bc33348c41197bcdanakj // This operator calls methods on the |canvas|. The various draw() wrapper 56d239d425148e5c1445b6a99d9bc33348c41197bcdanakj // methods around SkCanvas are defined by the DRAW() macro in 57d239d425148e5c1445b6a99d9bc33348c41197bcdanakj // SkRecordDraw.cpp. 5827f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org template <typename T> void operator()(const T& r) { 59f4078ad1ec42f549369ac4f639aab18d00afae95mtklein this->draw(r); 6027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org } 6127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 626be2aa9a251bf6022570a03140f956655b3ef1dareedprotected: 636be2aa9a251bf6022570a03140f956655b3ef1dareed SkPicture const* const* drawablePicts() const { return fDrawablePicts; } 646be2aa9a251bf6022570a03140f956655b3ef1dareed int drawableCount() const { return fDrawableCount; } 656be2aa9a251bf6022570a03140f956655b3ef1dareed 6627f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgprivate: 6727f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org // No base case, so we'll be compile-time checked that we implement all possibilities. 6827f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org template <typename T> void draw(const T&); 6927f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 700a98d870448f66ea0df7c37a47b38cf2d3b734e5commit-bot@chromium.org const SkMatrix fInitialCTM; 7127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org SkCanvas* fCanvas; 726be2aa9a251bf6022570a03140f956655b3ef1dareed SkPicture const* const* fDrawablePicts; 733cb3840c9af6f70896cf5565a38d4ee03c02d767reed SkDrawable* const* fDrawables; 746be2aa9a251bf6022570a03140f956655b3ef1dareed int fDrawableCount; 7500f30bdc9e34b013da54b4406f36556c5be8d041mtklein}; 7600f30bdc9e34b013da54b4406f36556c5be8d041mtklein 7727f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org} // namespace SkRecords 7827f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 79e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#endif//SkRecordDraw_DEFINED 80