blob: 0780c1e801283316dc62bf64964f6289be1c91c8 [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
robertphillipsa63f32e2014-11-10 08:10:42 -080044 @param numSamples The number if MSAA samples required
robertphillipsfd61ed02014-10-28 07:21:44 -070045 */
46 static void FindLayersToAtlas(GrContext* context,
47 const SkPicture* topLevelPicture,
48 const SkRect& query,
49 SkTDArray<GrHoistedLayer>* atlasedNeedRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080050 SkTDArray<GrHoistedLayer>* recycled,
51 int numSamples);
robertphillipsfd61ed02014-10-28 07:21:44 -070052
robertphillips30d2cc62014-09-24 08:52:18 -070053 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
54 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070055 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070056 @param topLevelPicture The top-level picture that is about to be rendered
57 @param query The rectangle that is about to be drawn.
robertphillipsfd61ed02014-10-28 07:21:44 -070058 @param needRendering Out parameter storing the layers that need rendering.
59 This should never include atlased layers.
robertphillipsb5a97152014-09-30 11:33:02 -070060 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillipsa63f32e2014-11-10 08:10:42 -080061 @param numSamples The number if MSAA samples required
robertphillips98d709b2014-09-02 10:20:50 -070062 */
robertphillipsfd61ed02014-10-28 07:21:44 -070063 static void FindLayersToHoist(GrContext* context,
robertphillipsd61ef012014-10-08 05:17:02 -070064 const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070065 const SkRect& query,
robertphillipsfd61ed02014-10-28 07:21:44 -070066 SkTDArray<GrHoistedLayer>* needRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080067 SkTDArray<GrHoistedLayer>* recycled,
68 int numSamples);
robertphillips98d709b2014-09-02 10:20:50 -070069
robertphillipsfd61ed02014-10-28 07:21:44 -070070 /** Draw the specified layers into the atlas.
robertphillips9e6835d2014-10-22 05:33:52 -070071 @param context Owner of the layer cache (and thus the layers)
robertphillipsfd61ed02014-10-28 07:21:44 -070072 @param layers The layers to be drawn into the atlas
robertphillips98d709b2014-09-02 10:20:50 -070073 */
robertphillipsfd61ed02014-10-28 07:21:44 -070074 static void DrawLayersToAtlas(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips98d709b2014-09-02 10:20:50 -070075
robertphillipsfd61ed02014-10-28 07:21:44 -070076 /** Draw the specified layers into their own individual textures.
77 @param context Owner of the layer cache (and thus the layers)
78 @param layers The layers to be drawn
robertphillips98d709b2014-09-02 10:20:50 -070079 */
robertphillipsfd61ed02014-10-28 07:21:44 -070080 static void DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
81
82 /** Convert all the layers in 'layers' into replacement objects in 'replacements'.
83 @param layers The hoisted layers
84 @param replacements Replacement object that will be used for a replacement draw
85 */
86 static void ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>& layers,
87 GrReplacements* replacements);
88
89 /** Unlock a group of layers in the layer cache.
90 @param context Owner of the layer cache (and thus the layers)
91 @param layers Unneeded layers in the atlas
92 */
93 static void UnlockLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips4ab5a902014-10-29 13:56:02 -070094
95 /** Forceably remove all cached layers and release the atlas. Useful for debugging and timing.
96 This is only functional when GR_CACHE_HOISTED_LAYERS is set to 1 in GrLayerCache.h
97 @param context Owner of the layer cache (and thus the layers)
98 */
99 static void PurgeCache(GrContext* context);
robertphillips98d709b2014-09-02 10:20:50 -0700100};
101
102#endif