blob: c3a451df572583fcb8db4d60c4b9a1b77dd2c62f [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;
robertphillips9e6835d2014-10-22 05:33:52 -070024 SkMatrix fPreMat;
25 SkMatrix fLocalMat;
robertphillipsd61ef012014-10-08 05:17:02 -070026};
27
robertphillips98d709b2014-09-02 10:20:50 -070028// This class collects the layer hoisting functionality in one place.
29// For each picture rendering:
30// FindLayersToHoist should be called once to collect the required layers
31// DrawLayers should be called once to render them
32// UnlockLayers should be called once to allow the texture resources to be recycled
33class GrLayerHoister {
34public:
robertphillips30d2cc62014-09-24 08:52:18 -070035
robertphillipsfd61ed02014-10-28 07:21:44 -070036 /** Find the layers in 'topLevelPicture' that can be atlased. Note that the discovered
37 layers can be inside nested sub-pictures.
38 @param context Owner of the layer cache (the source of new layers)
39 @param topLevelPicture The top-level picture that is about to be rendered
40 @param query The rectangle that is about to be drawn.
41 @param atlasedNeedRendering Out parameter storing the layers that
42 should be hoisted to the atlas
43 @param recycled Out parameter storing layers that are atlased but do not need rendering
44 */
45 static void FindLayersToAtlas(GrContext* context,
46 const SkPicture* topLevelPicture,
47 const SkRect& query,
48 SkTDArray<GrHoistedLayer>* atlasedNeedRendering,
49 SkTDArray<GrHoistedLayer>* recycled);
50
robertphillips30d2cc62014-09-24 08:52:18 -070051 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
52 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070053 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070054 @param topLevelPicture The top-level picture that is about to be rendered
55 @param query The rectangle that is about to be drawn.
robertphillipsfd61ed02014-10-28 07:21:44 -070056 @param needRendering Out parameter storing the layers that need rendering.
57 This should never include atlased layers.
robertphillipsb5a97152014-09-30 11:33:02 -070058 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillips98d709b2014-09-02 10:20:50 -070059 */
robertphillipsfd61ed02014-10-28 07:21:44 -070060 static void FindLayersToHoist(GrContext* context,
robertphillipsd61ef012014-10-08 05:17:02 -070061 const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070062 const SkRect& query,
robertphillipsfd61ed02014-10-28 07:21:44 -070063 SkTDArray<GrHoistedLayer>* needRendering,
robertphillipsd61ef012014-10-08 05:17:02 -070064 SkTDArray<GrHoistedLayer>* recycled);
robertphillips98d709b2014-09-02 10:20:50 -070065
robertphillipsfd61ed02014-10-28 07:21:44 -070066 /** Draw the specified layers into the atlas.
robertphillips9e6835d2014-10-22 05:33:52 -070067 @param context Owner of the layer cache (and thus the layers)
robertphillipsfd61ed02014-10-28 07:21:44 -070068 @param layers The layers to be drawn into the atlas
robertphillips98d709b2014-09-02 10:20:50 -070069 */
robertphillipsfd61ed02014-10-28 07:21:44 -070070 static void DrawLayersToAtlas(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips98d709b2014-09-02 10:20:50 -070071
robertphillipsfd61ed02014-10-28 07:21:44 -070072 /** Draw the specified layers into their own individual textures.
73 @param context Owner of the layer cache (and thus the layers)
74 @param layers The layers to be drawn
robertphillips98d709b2014-09-02 10:20:50 -070075 */
robertphillipsfd61ed02014-10-28 07:21:44 -070076 static void DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
77
78 /** Convert all the layers in 'layers' into replacement objects in 'replacements'.
79 @param layers The hoisted layers
80 @param replacements Replacement object that will be used for a replacement draw
81 */
82 static void ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>& layers,
83 GrReplacements* replacements);
84
85 /** Unlock a group of layers in the layer cache.
86 @param context Owner of the layer cache (and thus the layers)
87 @param layers Unneeded layers in the atlas
88 */
89 static void UnlockLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips4ab5a902014-10-29 13:56:02 -070090
91 /** Forceably remove all cached layers and release the atlas. Useful for debugging and timing.
92 This is only functional when GR_CACHE_HOISTED_LAYERS is set to 1 in GrLayerCache.h
93 @param context Owner of the layer cache (and thus the layers)
94 */
95 static void PurgeCache(GrContext* context);
robertphillips98d709b2014-09-02 10:20:50 -070096};
97
98#endif