blob: 7f49881e21d66194a7f199cb32f9a54a8e9d3cb6 [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
robertphillipsd61ef012014-10-08 05:17:02 -070019class GrHoistedLayer {
20public:
21 const SkPicture* fPicture;
22 GrCachedLayer* fLayer;
23 SkIPoint fOffset;
24 SkMatrix fCTM;
25};
26
robertphillips98d709b2014-09-02 10:20:50 -070027// This class collects the layer hoisting functionality in one place.
28// For each picture rendering:
29// FindLayersToHoist should be called once to collect the required layers
30// DrawLayers should be called once to render them
31// UnlockLayers should be called once to allow the texture resources to be recycled
32class GrLayerHoister {
33public:
robertphillips30d2cc62014-09-24 08:52:18 -070034
35 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
36 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070037 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070038 @param topLevelPicture The top-level picture that is about to be rendered
39 @param query The rectangle that is about to be drawn.
40 @param atlased Out parameter storing the layers that should be hoisted to the atlas
41 @param nonAtlased Out parameter storing the layers that should be hoisted stand alone
robertphillipsb5a97152014-09-30 11:33:02 -070042 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillips98d709b2014-09-02 10:20:50 -070043 Return true if any layers are suitable for hoisting; false otherwise
44 */
robertphillipsd61ef012014-10-08 05:17:02 -070045 static bool FindLayersToHoist(GrContext* context,
46 const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070047 const SkRect& query,
robertphillipsd61ef012014-10-08 05:17:02 -070048 SkTDArray<GrHoistedLayer>* atlased,
49 SkTDArray<GrHoistedLayer>* nonAtlased,
50 SkTDArray<GrHoistedLayer>* recycled);
robertphillips98d709b2014-09-02 10:20:50 -070051
robertphillips30d2cc62014-09-24 08:52:18 -070052 /** Draw the specified layers into either the atlas or free floating textures.
robertphillips1c4c5282014-09-18 12:03:15 -070053 @param atlased The layers to be drawn into the atlas
54 @param nonAtlased The layers to be drawn into their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070055 @param recycled Layers that don't need rendering but do need to go into the
56 replacements object
57 @param replacements The replacement structure to fill in with the rendered layer info
robertphillips98d709b2014-09-02 10:20:50 -070058 */
robertphillipsd61ef012014-10-08 05:17:02 -070059 static void DrawLayers(const SkTDArray<GrHoistedLayer>& atlased,
60 const SkTDArray<GrHoistedLayer>& nonAtlased,
61 const SkTDArray<GrHoistedLayer>& recycled,
robertphillips1c4c5282014-09-18 12:03:15 -070062 GrReplacements* replacements);
robertphillips98d709b2014-09-02 10:20:50 -070063
robertphillips30d2cc62014-09-24 08:52:18 -070064 /** Unlock unneeded layers in the layer cache.
robertphillipsd61ef012014-10-08 05:17:02 -070065 @param context Owner of the layer cache (and thus the layers)
robertphillips30d2cc62014-09-24 08:52:18 -070066 @param atlased Unneeded layers in the atlas
67 @param nonAtlased Unneeded layers in their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070068 @param recycled Unneeded layers that did not require rendering
robertphillips98d709b2014-09-02 10:20:50 -070069 */
robertphillipsd61ef012014-10-08 05:17:02 -070070 static void UnlockLayers(GrContext* context,
71 const SkTDArray<GrHoistedLayer>& atlased,
72 const SkTDArray<GrHoistedLayer>& nonAtlased,
73 const SkTDArray<GrHoistedLayer>& recycled);
robertphillips98d709b2014-09-02 10:20:50 -070074};
75
76#endif