SkRecordDraw.h revision 8eddfb50c0c9e4bcba6384a2ce39852b5fb5becb
1/* 2 * Copyright 2014 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#ifndef SkRecordDraw_DEFINED 9#define SkRecordDraw_DEFINED 10 11#include "SkBBoxHierarchy.h" 12#include "SkCanvas.h" 13#include "SkDrawPictureCallback.h" 14#include "SkMatrix.h" 15#include "SkRecord.h" 16 17class SkCanvasDrawable; 18class SkLayerInfo; 19 20// Fill a BBH to be used by SkRecordDraw to accelerate playback. 21void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy*); 22 23void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, 24 const SkPicture::SnapshotArray*, 25 SkBBoxHierarchy* bbh, SkLayerInfo* data); 26 27// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. 28void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[], 29 SkCanvasDrawable* const drawables[], int drawableCount, 30 const SkBBoxHierarchy*, SkDrawPictureCallback*); 31 32// Draw a portion of an SkRecord into an SkCanvas. 33// When drawing a portion of an SkRecord the CTM on the passed in canvas must be 34// the composition of the replay matrix with the record-time CTM (for the portion 35// of the record that is being replayed). For setMatrix calls to behave correctly 36// the initialCTM parameter must set to just the replay matrix. 37void SkRecordPartialDraw(const SkRecord&, SkCanvas*, 38 SkPicture const* const drawablePicts[], int drawableCount, 39 unsigned start, unsigned stop, const SkMatrix& initialCTM); 40 41namespace SkRecords { 42 43// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 44class Draw : SkNoncopyable { 45public: 46 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], 47 SkCanvasDrawable* const drawables[], int drawableCount, 48 const SkMatrix* initialCTM = NULL) 49 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) 50 , fCanvas(canvas) 51 , fDrawablePicts(drawablePicts) 52 , fDrawables(drawables) 53 , fDrawableCount(drawableCount) 54 {} 55 56 // This operator calls methods on the |canvas|. The various draw() wrapper 57 // methods around SkCanvas are defined by the DRAW() macro in 58 // SkRecordDraw.cpp. 59 template <typename T> void operator()(const T& r) { 60 this->draw(r); 61 } 62 63protected: 64 SkPicture const* const* drawablePicts() const { return fDrawablePicts; } 65 int drawableCount() const { return fDrawableCount; } 66 67private: 68 // No base case, so we'll be compile-time checked that we implement all possibilities. 69 template <typename T> void draw(const T&); 70 71 const SkMatrix fInitialCTM; 72 SkCanvas* fCanvas; 73 SkPicture const* const* fDrawablePicts; 74 SkCanvasDrawable* const* fDrawables; 75 int fDrawableCount; 76}; 77 78} // namespace SkRecords 79 80#endif//SkRecordDraw_DEFINED 81