blob: 58b3f4870ba2f809a1a3554a1b50216eebd22b5f [file] [log] [blame]
robertphillips98d709b2014-09-02 10:20:50 -07001/*
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 GrLayerHoister_DEFINED
9#define GrLayerHoister_DEFINED
10
11#include "SkPicture.h"
12#include "SkTDArray.h"
13
14class GrAccelData;
15struct GrCachedLayer;
robertphillips1c4c5282014-09-18 12:03:15 -070016class GrReplacements;
robertphillips98d709b2014-09-02 10:20:50 -070017struct SkRect;
18
19// This class collects the layer hoisting functionality in one place.
20// For each picture rendering:
21// FindLayersToHoist should be called once to collect the required layers
22// DrawLayers should be called once to render them
23// UnlockLayers should be called once to allow the texture resources to be recycled
24class GrLayerHoister {
25public:
robertphillips30d2cc62014-09-24 08:52:18 -070026 struct HoistedLayer {
27 const SkPicture* fPicture;
28 GrCachedLayer* fLayer;
robertphillipsed420592014-09-29 11:39:38 -070029 SkIPoint fOffset;
30 SkMatrix fCTM;
robertphillips30d2cc62014-09-24 08:52:18 -070031 };
32
33 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
34 layers can be inside nested sub-pictures.
35 @param topLevelPicture The top-level picture that is about to be rendered
36 @param query The rectangle that is about to be drawn.
37 @param atlased Out parameter storing the layers that should be hoisted to the atlas
38 @param nonAtlased Out parameter storing the layers that should be hoisted stand alone
robertphillipsb5a97152014-09-30 11:33:02 -070039 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillips1c4c5282014-09-18 12:03:15 -070040 @param layerCache The source of new layers
robertphillips98d709b2014-09-02 10:20:50 -070041 Return true if any layers are suitable for hoisting; false otherwise
42 */
robertphillips30d2cc62014-09-24 08:52:18 -070043 static bool FindLayersToHoist(const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070044 const SkRect& query,
robertphillips30d2cc62014-09-24 08:52:18 -070045 SkTDArray<HoistedLayer>* altased,
46 SkTDArray<HoistedLayer>* nonAtlased,
robertphillipsb5a97152014-09-30 11:33:02 -070047 SkTDArray<HoistedLayer>* recycled,
robertphillips1c4c5282014-09-18 12:03:15 -070048 GrLayerCache* layerCache);
robertphillips98d709b2014-09-02 10:20:50 -070049
robertphillips30d2cc62014-09-24 08:52:18 -070050 /** Draw the specified layers into either the atlas or free floating textures.
robertphillips1c4c5282014-09-18 12:03:15 -070051 @param atlased The layers to be drawn into the atlas
52 @param nonAtlased The layers to be drawn into their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070053 @param recycled Layers that don't need rendering but do need to go into the
54 replacements object
55 @param replacements The replacement structure to fill in with the rendered layer info
robertphillips98d709b2014-09-02 10:20:50 -070056 */
robertphillips30d2cc62014-09-24 08:52:18 -070057 static void DrawLayers(const SkTDArray<HoistedLayer>& atlased,
58 const SkTDArray<HoistedLayer>& nonAtlased,
robertphillipsb5a97152014-09-30 11:33:02 -070059 const SkTDArray<HoistedLayer>& recycled,
robertphillips1c4c5282014-09-18 12:03:15 -070060 GrReplacements* replacements);
robertphillips98d709b2014-09-02 10:20:50 -070061
robertphillips30d2cc62014-09-24 08:52:18 -070062 /** Unlock unneeded layers in the layer cache.
robertphillips98d709b2014-09-02 10:20:50 -070063 @param layerCache holder of the locked layers
robertphillips30d2cc62014-09-24 08:52:18 -070064 @param atlased Unneeded layers in the atlas
65 @param nonAtlased Unneeded layers in their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070066 @param recycled Unneeded layers that did not require rendering
robertphillips98d709b2014-09-02 10:20:50 -070067 */
robertphillips30d2cc62014-09-24 08:52:18 -070068 static void UnlockLayers(GrLayerCache* layerCache,
69 const SkTDArray<HoistedLayer>& atlased,
robertphillipsb5a97152014-09-30 11:33:02 -070070 const SkTDArray<HoistedLayer>& nonAtlased,
71 const SkTDArray<HoistedLayer>& recycled);
robertphillips98d709b2014-09-02 10:20:50 -070072};
73
74#endif