17eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips/* 27eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Copyright 2014 Google Inc. 37eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * 47eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Use of this source code is governed by a BSD-style license that can be 57eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * found in the LICENSE file. 67eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips */ 77eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 87eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips#ifndef SkMultiPictureDraw_DEFINED 97eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips#define SkMultiPictureDraw_DEFINED 107eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 117eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips#include "SkMatrix.h" 127eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips#include "SkTDArray.h" 137eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 147eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipsclass SkCanvas; 157eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipsclass SkPaint; 167eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipsclass SkPicture; 177eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 187eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips/** \class SkMultiPictureDraw 197eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 207eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips The MultiPictureDraw object accepts several picture/canvas pairs and 217eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips then attempts to optimally draw the pictures into the canvases, sharing 227eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips as many resources as possible. 237eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips*/ 247eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipsclass SK_API SkMultiPictureDraw { 257eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipspublic: 267eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips /** 277eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Create an object to optimize the drawing of multiple pictures. 287eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * @param reserve Hint for the number of add calls expected to be issued 297eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips */ 307eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips SkMultiPictureDraw(int reserve = 0); 317eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips ~SkMultiPictureDraw() { this->reset(); } 327eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 337eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips /** 347eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Add a canvas/picture pair for later rendering. 357eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * @param canvas the canvas in which to draw picture 367eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * @param picture the picture to draw into canvas 377eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * @param matrix if non-NULL, applied to the CTM when drawing 387eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * @param paint if non-NULL, draw picture to a temporary buffer 397eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * and then apply the paint when the result is drawn 407eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips */ 417eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips void add(SkCanvas* canvas, 427eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips const SkPicture* picture, 437eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips const SkMatrix* matrix = NULL, 447eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips const SkPaint* paint = NULL); 457eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 467eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips /** 477eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Perform all the previously added draws. This will reset the state 487eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * of this object. 497eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips */ 507eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips void draw(); 517eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 527eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips /** 537eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips * Abandon all buffered draws and reset to the initial state. 547eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips */ 557eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips void reset(); 567eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 577eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillipsprivate: 587eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips struct DrawData { 597eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips SkCanvas* canvas; // reffed 607eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips const SkPicture* picture; // reffed 617eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips SkMatrix matrix; 627eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips SkPaint* paint; // owned 637eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips }; 647eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 657eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips SkTDArray<DrawData> fDrawData; 667eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips}; 677eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips 687eacd77ce63abec6c5a0e7be9bf9f40ea4145d11robertphillips#endif 69