blob: 84c7896abec2b1778a0bd7061f70d5f6bdb10c12 [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:
20 const SkPicture* fPicture;
21 GrCachedLayer* fLayer;
22 SkIPoint fOffset;
robertphillips9e6835d2014-10-22 05:33:52 -070023 SkMatrix fPreMat;
24 SkMatrix fLocalMat;
robertphillipsd61ef012014-10-08 05:17:02 -070025};
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
robertphillipsfd61ed02014-10-28 07:21:44 -070035 /** Find the layers in 'topLevelPicture' that can be atlased. Note that the discovered
36 layers can be inside nested sub-pictures.
37 @param context Owner of the layer cache (the source of new layers)
38 @param topLevelPicture The top-level picture that is about to be rendered
robertphillips30d78412014-11-24 09:49:17 -080039 @param initialMat The CTM of the canvas into which the layers will be drawn
robertphillipsfd61ed02014-10-28 07:21:44 -070040 @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,
robertphillips30d78412014-11-24 09:49:17 -080048 const SkMatrix& initialMat,
robertphillipsfd61ed02014-10-28 07:21:44 -070049 const SkRect& query,
50 SkTDArray<GrHoistedLayer>* atlasedNeedRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080051 SkTDArray<GrHoistedLayer>* recycled,
52 int numSamples);
robertphillipsfd61ed02014-10-28 07:21:44 -070053
robertphillips30d2cc62014-09-24 08:52:18 -070054 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
55 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070056 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070057 @param topLevelPicture The top-level picture that is about to be rendered
robertphillips30d78412014-11-24 09:49:17 -080058 @param initialMat The CTM of the canvas into which the layers will be drawn
robertphillips30d2cc62014-09-24 08:52:18 -070059 @param query The rectangle that is about to be drawn.
robertphillipsfd61ed02014-10-28 07:21:44 -070060 @param needRendering Out parameter storing the layers that need rendering.
61 This should never include atlased layers.
robertphillipsb5a97152014-09-30 11:33:02 -070062 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillipsa63f32e2014-11-10 08:10:42 -080063 @param numSamples The number if MSAA samples required
robertphillips98d709b2014-09-02 10:20:50 -070064 */
robertphillipsfd61ed02014-10-28 07:21:44 -070065 static void FindLayersToHoist(GrContext* context,
robertphillipsd61ef012014-10-08 05:17:02 -070066 const SkPicture* topLevelPicture,
robertphillips30d78412014-11-24 09:49:17 -080067 const SkMatrix& initialMat,
robertphillips98d709b2014-09-02 10:20:50 -070068 const SkRect& query,
robertphillipsfd61ed02014-10-28 07:21:44 -070069 SkTDArray<GrHoistedLayer>* needRendering,
robertphillipsa63f32e2014-11-10 08:10:42 -080070 SkTDArray<GrHoistedLayer>* recycled,
71 int numSamples);
robertphillips98d709b2014-09-02 10:20:50 -070072
robertphillipsfd61ed02014-10-28 07:21:44 -070073 /** Draw the specified layers into the atlas.
robertphillips9e6835d2014-10-22 05:33:52 -070074 @param context Owner of the layer cache (and thus the layers)
robertphillipsfd61ed02014-10-28 07:21:44 -070075 @param layers The layers to be drawn into the atlas
robertphillips98d709b2014-09-02 10:20:50 -070076 */
robertphillipsfd61ed02014-10-28 07:21:44 -070077 static void DrawLayersToAtlas(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips98d709b2014-09-02 10:20:50 -070078
robertphillipsfd61ed02014-10-28 07:21:44 -070079 /** Draw the specified layers into their own individual textures.
80 @param context Owner of the layer cache (and thus the layers)
81 @param layers The layers to be drawn
robertphillips98d709b2014-09-02 10:20:50 -070082 */
robertphillipsfd61ed02014-10-28 07:21:44 -070083 static void DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
84
85 /** Convert all the layers in 'layers' into replacement objects in 'replacements'.
86 @param layers The hoisted layers
87 @param replacements Replacement object that will be used for a replacement draw
88 */
89 static void ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>& layers,
90 GrReplacements* replacements);
91
92 /** Unlock a group of layers in the layer cache.
93 @param context Owner of the layer cache (and thus the layers)
94 @param layers Unneeded layers in the atlas
95 */
96 static void UnlockLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers);
robertphillips4ab5a902014-10-29 13:56:02 -070097
98 /** Forceably remove all cached layers and release the atlas. Useful for debugging and timing.
99 This is only functional when GR_CACHE_HOISTED_LAYERS is set to 1 in GrLayerCache.h
100 @param context Owner of the layer cache (and thus the layers)
101 */
102 static void PurgeCache(GrContext* context);
robertphillips98d709b2014-09-02 10:20:50 -0700103};
104
105#endif