blob: 2d68a94a889831cc2158f682d9190583e55d58dc [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
robertphillips98d709b2014-09-02 10:20:50 -070014struct GrCachedLayer;
robertphillips1c4c5282014-09-18 12:03:15 -070015class GrReplacements;
robertphillips98d709b2014-09-02 10:20:50 -070016struct SkRect;
17
robertphillipsd61ef012014-10-08 05:17:02 -070018class GrHoistedLayer {
19public:
robertphillips01d6e5f2014-12-01 09:09:27 -080020 const SkPicture* fPicture; // the picture that actually contains the layer
21 // (not necessarily the top-most picture)
robertphillipsd61ef012014-10-08 05:17:02 -070022 GrCachedLayer* fLayer;
robertphillips01d6e5f2014-12-01 09:09:27 -080023 SkMatrix fInitialMat;
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
robertphillips30d78412014-11-24 09:49:17 -080040 @param initialMat The CTM of the canvas into which the layers will be drawn
robertphillipsfd61ed02014-10-28 07:21:44 -070041 @param query The rectangle that is about to be drawn.
42 @param atlasedNeedRendering Out parameter storing the layers that
43 should be hoisted to the atlas
44 @param recycled Out parameter storing layers that are atlased but do not need rendering
robertphillipsa63f32e2014-11-10 08:10:42 -080045 @param numSamples The number if MSAA samples required
robertphillipsfd61ed02014-10-28 07:21:44 -070046 */
47 static void FindLayersToAtlas(GrContext* context,
48 const SkPicture* topLevelPicture,
robertphillips30d78412014-11-24 09:49:17 -080049 const SkMatrix& initialMat,
robertphillipsfd61ed02014-10-28 07:21:44 -070050 const SkRect& query,
51 SkTDArray<GrHoistedLayer>* atlasedNeedRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080052 SkTDArray<GrHoistedLayer>* recycled,
53 int numSamples);
robertphillipsfd61ed02014-10-28 07:21:44 -070054
robertphillips30d2cc62014-09-24 08:52:18 -070055 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
56 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070057 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070058 @param topLevelPicture The top-level picture that is about to be rendered
robertphillips30d78412014-11-24 09:49:17 -080059 @param initialMat The CTM of the canvas into which the layers will be drawn
robertphillips30d2cc62014-09-24 08:52:18 -070060 @param query The rectangle that is about to be drawn.
robertphillipsfd61ed02014-10-28 07:21:44 -070061 @param needRendering Out parameter storing the layers that need rendering.
62 This should never include atlased layers.
robertphillipsb5a97152014-09-30 11:33:02 -070063 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillipsa63f32e2014-11-10 08:10:42 -080064 @param numSamples The number if MSAA samples required
robertphillips98d709b2014-09-02 10:20:50 -070065 */
robertphillipsfd61ed02014-10-28 07:21:44 -070066 static void FindLayersToHoist(GrContext* context,
robertphillipsd61ef012014-10-08 05:17:02 -070067 const SkPicture* topLevelPicture,
robertphillips30d78412014-11-24 09:49:17 -080068 const SkMatrix& initialMat,
robertphillips98d709b2014-09-02 10:20:50 -070069 const SkRect& query,
robertphillipsfd61ed02014-10-28 07:21:44 -070070 SkTDArray<GrHoistedLayer>* needRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080071 SkTDArray<GrHoistedLayer>* recycled,
72 int numSamples);
robertphillips98d709b2014-09-02 10:20:50 -070073
robertphillipsfd61ed02014-10-28 07:21:44 -070074 /** Draw the specified layers into the atlas.
robertphillips9e6835d2014-10-22 05:33:52 -070075 @param context Owner of the layer cache (and thus the layers)
robertphillipsfd61ed02014-10-28 07:21:44 -070076 @param layers The layers to be drawn into the atlas
robertphillips98d709b2014-09-02 10:20:50 -070077 */
robertphillipsfd61ed02014-10-28 07:21:44 -070078 static void DrawLayersToAtlas(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips98d709b2014-09-02 10:20:50 -070079
robertphillipsfd61ed02014-10-28 07:21:44 -070080 /** Draw the specified layers into their own individual textures.
81 @param context Owner of the layer cache (and thus the layers)
82 @param layers The layers to be drawn
robertphillips98d709b2014-09-02 10:20:50 -070083 */
robertphillipsfd61ed02014-10-28 07:21:44 -070084 static void DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
85
86 /** Convert all the layers in 'layers' into replacement objects in 'replacements'.
87 @param layers The hoisted layers
88 @param replacements Replacement object that will be used for a replacement draw
89 */
robertphillips01d6e5f2014-12-01 09:09:27 -080090 static void ConvertLayersToReplacements(const SkPicture* topLevelPicture,
91 const SkTDArray<GrHoistedLayer>& layers,
robertphillipsfd61ed02014-10-28 07:21:44 -070092 GrReplacements* replacements);
93
94 /** Unlock a group of layers in the layer cache.
95 @param context Owner of the layer cache (and thus the layers)
96 @param layers Unneeded layers in the atlas
97 */
98 static void UnlockLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips4ab5a902014-10-29 13:56:02 -070099
100 /** Forceably remove all cached layers and release the atlas. Useful for debugging and timing.
101 This is only functional when GR_CACHE_HOISTED_LAYERS is set to 1 in GrLayerCache.h
102 @param context Owner of the layer cache (and thus the layers)
103 */
104 static void PurgeCache(GrContext* context);
robertphillips98d709b2014-09-02 10:20:50 -0700105};
106
107#endif