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" 13c11530ea73b2a2fcb431df0f5c1887d08ac9113cMike Klein#include "SkDrawPictureCallback.h" 144815fe5a0a497b676677fb4e4a0f05c511855490robertphillips#include "SkMatrix.h" 155ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein#include "SkRecord.h" 165ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein 175ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtklein// Fill a BBH to be used by SkRecordDraw to accelerate playback. 185ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtkleinvoid SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); 19e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org 2027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. 215ad6ee1b2ce54f8e59b9f5a337c688a98a4b0f2amtkleinvoid SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*); 22e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org 2300f30bdc9e34b013da54b4406f36556c5be8d041mtklein// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects. 244815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// When drawing a portion of an SkRecord the CTM on the passed in canvas must be 254815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the composition of the replay matrix with the record-time CTM (for the portion 264815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// of the record that is being replayed). For setMatrix calls to behave correctly 274815fe5a0a497b676677fb4e4a0f05c511855490robertphillips// the initialCTM parameter must set to just the replay matrix. 284815fe5a0a497b676677fb4e4a0f05c511855490robertphillipsvoid SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop, 294815fe5a0a497b676677fb4e4a0f05c511855490robertphillips const SkMatrix& initialCTM); 3000f30bdc9e34b013da54b4406f36556c5be8d041mtklein 3127f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgnamespace SkRecords { 3227f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 3327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 3427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgclass Draw : SkNoncopyable { 3527f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgpublic: 364815fe5a0a497b676677fb4e4a0f05c511855490robertphillips explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL) 374815fe5a0a497b676677fb4e4a0f05c511855490robertphillips : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) 384815fe5a0a497b676677fb4e4a0f05c511855490robertphillips , fCanvas(canvas) {} 3927f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 4027f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org template <typename T> void operator()(const T& r) { 41f4078ad1ec42f549369ac4f639aab18d00afae95mtklein this->draw(r); 4227f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org } 4327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 4427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.orgprivate: 4527f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org // No base case, so we'll be compile-time checked that we implement all possibilities. 4627f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org template <typename T> void draw(const T&); 4727f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 480a98d870448f66ea0df7c37a47b38cf2d3b734e5commit-bot@chromium.org const SkMatrix fInitialCTM; 4927f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org SkCanvas* fCanvas; 5000f30bdc9e34b013da54b4406f36556c5be8d041mtklein}; 5100f30bdc9e34b013da54b4406f36556c5be8d041mtklein 5200f30bdc9e34b013da54b4406f36556c5be8d041mtklein// Used by SkRecordPartialDraw. 5300f30bdc9e34b013da54b4406f36556c5be8d041mtkleinclass PartialDraw : public Draw { 5400f30bdc9e34b013da54b4406f36556c5be8d041mtkleinpublic: 554815fe5a0a497b676677fb4e4a0f05c511855490robertphillips PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM) 564815fe5a0a497b676677fb4e4a0f05c511855490robertphillips : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {} 5700f30bdc9e34b013da54b4406f36556c5be8d041mtklein 5800f30bdc9e34b013da54b4406f36556c5be8d041mtklein // Same as Draw for all ops except Clear. 5900f30bdc9e34b013da54b4406f36556c5be8d041mtklein template <typename T> void operator()(const T& r) { 6000f30bdc9e34b013da54b4406f36556c5be8d041mtklein this->INHERITED::operator()(r); 6100f30bdc9e34b013da54b4406f36556c5be8d041mtklein } 6200f30bdc9e34b013da54b4406f36556c5be8d041mtklein void operator()(const Clear& c) { 6300f30bdc9e34b013da54b4406f36556c5be8d041mtklein SkPaint p; 6400f30bdc9e34b013da54b4406f36556c5be8d041mtklein p.setColor(c.color); 6500f30bdc9e34b013da54b4406f36556c5be8d041mtklein DrawRect drawRect(p, fClearRect); 6600f30bdc9e34b013da54b4406f36556c5be8d041mtklein this->INHERITED::operator()(drawRect); 6700f30bdc9e34b013da54b4406f36556c5be8d041mtklein } 6800f30bdc9e34b013da54b4406f36556c5be8d041mtklein 6900f30bdc9e34b013da54b4406f36556c5be8d041mtkleinprivate: 7000f30bdc9e34b013da54b4406f36556c5be8d041mtklein const SkRect fClearRect; 7100f30bdc9e34b013da54b4406f36556c5be8d041mtklein typedef Draw INHERITED; 7227f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org}; 7327f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 7427f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org} // namespace SkRecords 7527f6b0d013572184dc980462cce8d0f3caec1c8ecommit-bot@chromium.org 76e3ff558a4baf4cb924e7513a81c8073ddae385fccommit-bot@chromium.org#endif//SkRecordDraw_DEFINED 77