2014-08-21 20:12:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkMultiPictureDraw_DEFINED
|
|
|
|
#define SkMultiPictureDraw_DEFINED
|
|
|
|
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkTDArray.h"
|
2014-08-21 20:12:42 +00:00
|
|
|
#include "SkMatrix.h"
|
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
class SkPaint;
|
|
|
|
class SkPicture;
|
|
|
|
|
|
|
|
/** \class SkMultiPictureDraw
|
|
|
|
|
|
|
|
The MultiPictureDraw object accepts several picture/canvas pairs and
|
|
|
|
then attempts to optimally draw the pictures into the canvases, sharing
|
|
|
|
as many resources as possible.
|
|
|
|
*/
|
|
|
|
class SK_API SkMultiPictureDraw {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create an object to optimize the drawing of multiple pictures.
|
|
|
|
* @param reserve Hint for the number of add calls expected to be issued
|
|
|
|
*/
|
|
|
|
SkMultiPictureDraw(int reserve = 0);
|
|
|
|
~SkMultiPictureDraw() { this->reset(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a canvas/picture pair for later rendering.
|
|
|
|
* @param canvas the canvas in which to draw picture
|
|
|
|
* @param picture the picture to draw into canvas
|
|
|
|
* @param matrix if non-NULL, applied to the CTM when drawing
|
|
|
|
* @param paint if non-NULL, draw picture to a temporary buffer
|
|
|
|
* and then apply the paint when the result is drawn
|
|
|
|
*/
|
|
|
|
void add(SkCanvas* canvas,
|
|
|
|
const SkPicture* picture,
|
2017-08-28 14:34:05 +00:00
|
|
|
const SkMatrix* matrix = nullptr,
|
|
|
|
const SkPaint* paint = nullptr);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform all the previously added draws. This will reset the state
|
2015-01-28 19:01:06 +00:00
|
|
|
* of this object. If flush is true, all canvases are flushed after
|
|
|
|
* draw.
|
2014-08-21 20:12:42 +00:00
|
|
|
*/
|
2015-01-28 19:01:06 +00:00
|
|
|
void draw(bool flush = false);
|
2014-08-21 20:12:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abandon all buffered draws and reset to the initial state.
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct DrawData {
|
2016-11-12 14:06:55 +00:00
|
|
|
SkCanvas* fCanvas;
|
2014-10-29 19:36:45 +00:00
|
|
|
const SkPicture* fPicture; // reffed
|
|
|
|
SkMatrix fMatrix;
|
|
|
|
SkPaint* fPaint; // owned
|
|
|
|
|
|
|
|
void init(SkCanvas*, const SkPicture*, const SkMatrix*, const SkPaint*);
|
|
|
|
void draw();
|
|
|
|
|
|
|
|
static void Reset(SkTDArray<DrawData>&);
|
2014-08-21 20:12:42 +00:00
|
|
|
};
|
|
|
|
|
2014-10-29 19:36:45 +00:00
|
|
|
SkTDArray<DrawData> fThreadSafeDrawData;
|
|
|
|
SkTDArray<DrawData> fGPUDrawData;
|
2014-08-21 20:12:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|