blob: 2b2eb0914bd1bd2cdbfd30f7d3d315a9084eaa45 [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
36 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
37 layers can be inside nested sub-pictures.
robertphillipsd61ef012014-10-08 05:17:02 -070038 @param context Owner of the layer cache (the source of new layers)
robertphillips30d2cc62014-09-24 08:52:18 -070039 @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 atlased Out parameter storing the layers that should be hoisted to the atlas
42 @param nonAtlased Out parameter storing the layers that should be hoisted stand alone
robertphillipsb5a97152014-09-30 11:33:02 -070043 @param recycled Out parameter storing layers that need hoisting but not rendering
robertphillips98d709b2014-09-02 10:20:50 -070044 Return true if any layers are suitable for hoisting; false otherwise
45 */
robertphillipsd61ef012014-10-08 05:17:02 -070046 static bool FindLayersToHoist(GrContext* context,
47 const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070048 const SkRect& query,
robertphillipsd61ef012014-10-08 05:17:02 -070049 SkTDArray<GrHoistedLayer>* atlased,
50 SkTDArray<GrHoistedLayer>* nonAtlased,
51 SkTDArray<GrHoistedLayer>* recycled);
robertphillips98d709b2014-09-02 10:20:50 -070052
robertphillips30d2cc62014-09-24 08:52:18 -070053 /** Draw the specified layers into either the atlas or free floating textures.
robertphillips9e6835d2014-10-22 05:33:52 -070054 @param context Owner of the layer cache (and thus the layers)
robertphillips1c4c5282014-09-18 12:03:15 -070055 @param atlased The layers to be drawn into the atlas
56 @param nonAtlased The layers to be drawn into their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070057 @param recycled Layers that don't need rendering but do need to go into the
58 replacements object
59 @param replacements The replacement structure to fill in with the rendered layer info
robertphillips98d709b2014-09-02 10:20:50 -070060 */
robertphillips9e6835d2014-10-22 05:33:52 -070061 static void DrawLayers(GrContext* context,
62 const SkTDArray<GrHoistedLayer>& atlased,
robertphillipsd61ef012014-10-08 05:17:02 -070063 const SkTDArray<GrHoistedLayer>& nonAtlased,
64 const SkTDArray<GrHoistedLayer>& recycled,
robertphillips1c4c5282014-09-18 12:03:15 -070065 GrReplacements* replacements);
robertphillips98d709b2014-09-02 10:20:50 -070066
robertphillips30d2cc62014-09-24 08:52:18 -070067 /** Unlock unneeded layers in the layer cache.
robertphillipsd61ef012014-10-08 05:17:02 -070068 @param context Owner of the layer cache (and thus the layers)
robertphillips30d2cc62014-09-24 08:52:18 -070069 @param atlased Unneeded layers in the atlas
70 @param nonAtlased Unneeded layers in their own textures
robertphillipsb5a97152014-09-30 11:33:02 -070071 @param recycled Unneeded layers that did not require rendering
robertphillips98d709b2014-09-02 10:20:50 -070072 */
robertphillipsd61ef012014-10-08 05:17:02 -070073 static void UnlockLayers(GrContext* context,
74 const SkTDArray<GrHoistedLayer>& atlased,
75 const SkTDArray<GrHoistedLayer>& nonAtlased,
76 const SkTDArray<GrHoistedLayer>& recycled);
robertphillips98d709b2014-09-02 10:20:50 -070077};
78
79#endif