blob: 6aff2ea32abe45965a49e298b12165e84edf75fa [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
19// This class collects the layer hoisting functionality in one place.
20// For each picture rendering:
21// FindLayersToHoist should be called once to collect the required layers
22// DrawLayers should be called once to render them
23// UnlockLayers should be called once to allow the texture resources to be recycled
24class GrLayerHoister {
25public:
robertphillips30d2cc62014-09-24 08:52:18 -070026 struct HoistedLayer {
27 const SkPicture* fPicture;
28 GrCachedLayer* fLayer;
robertphillipsed420592014-09-29 11:39:38 -070029 SkIPoint fOffset;
30 SkMatrix fCTM;
robertphillips30d2cc62014-09-24 08:52:18 -070031 };
32
33 /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
34 layers can be inside nested sub-pictures.
35 @param topLevelPicture The top-level picture that is about to be rendered
36 @param query The rectangle that is about to be drawn.
37 @param atlased Out parameter storing the layers that should be hoisted to the atlas
38 @param nonAtlased Out parameter storing the layers that should be hoisted stand alone
robertphillips1c4c5282014-09-18 12:03:15 -070039 @param layerCache The source of new layers
robertphillips98d709b2014-09-02 10:20:50 -070040 Return true if any layers are suitable for hoisting; false otherwise
41 */
robertphillips30d2cc62014-09-24 08:52:18 -070042 static bool FindLayersToHoist(const SkPicture* topLevelPicture,
robertphillips98d709b2014-09-02 10:20:50 -070043 const SkRect& query,
robertphillips30d2cc62014-09-24 08:52:18 -070044 SkTDArray<HoistedLayer>* altased,
45 SkTDArray<HoistedLayer>* nonAtlased,
robertphillips1c4c5282014-09-18 12:03:15 -070046 GrLayerCache* layerCache);
robertphillips98d709b2014-09-02 10:20:50 -070047
robertphillips30d2cc62014-09-24 08:52:18 -070048 /** Draw the specified layers into either the atlas or free floating textures.
robertphillips1c4c5282014-09-18 12:03:15 -070049 @param atlased The layers to be drawn into the atlas
50 @param nonAtlased The layers to be drawn into their own textures
51 @oaram replacements The replacement structure to fill in with the rendered layer info
robertphillips98d709b2014-09-02 10:20:50 -070052 */
robertphillips30d2cc62014-09-24 08:52:18 -070053 static void DrawLayers(const SkTDArray<HoistedLayer>& atlased,
54 const SkTDArray<HoistedLayer>& nonAtlased,
robertphillips1c4c5282014-09-18 12:03:15 -070055 GrReplacements* replacements);
robertphillips98d709b2014-09-02 10:20:50 -070056
robertphillips30d2cc62014-09-24 08:52:18 -070057 /** Unlock unneeded layers in the layer cache.
robertphillips98d709b2014-09-02 10:20:50 -070058 @param layerCache holder of the locked layers
robertphillips30d2cc62014-09-24 08:52:18 -070059 @param atlased Unneeded layers in the atlas
60 @param nonAtlased Unneeded layers in their own textures
robertphillips98d709b2014-09-02 10:20:50 -070061 */
robertphillips30d2cc62014-09-24 08:52:18 -070062 static void UnlockLayers(GrLayerCache* layerCache,
63 const SkTDArray<HoistedLayer>& atlased,
64 const SkTDArray<HoistedLayer>& nonAtlased);
robertphillips98d709b2014-09-02 10:20:50 -070065};
66
67#endif