robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 14 | class GrAccelData; |
| 15 | struct GrCachedLayer; |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 16 | class GrReplacements; |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 17 | struct 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 |
| 24 | class GrLayerHoister { |
| 25 | public: |
| 26 | /** Find the layers in 'gpuData' that need hoisting. |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 27 | @param gpuData Acceleration structure containing layer information for a picture |
| 28 | @param query The rectangle that is about to be drawn. |
| 29 | @param atlased Out parameter storing the layers that should be hoisted to the atlas |
| 30 | @param nonAtlased Out parameter storing the layers that should be hoisted stand alone |
| 31 | @param layerCache The source of new layers |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 32 | Return true if any layers are suitable for hoisting; false otherwise |
| 33 | */ |
| 34 | static bool FindLayersToHoist(const GrAccelData *gpuData, |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 35 | const SkRect& query, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 36 | SkTDArray<GrCachedLayer*>* altased, |
| 37 | SkTDArray<GrCachedLayer*>* nonAtlased, |
| 38 | GrLayerCache* layerCache); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 39 | |
| 40 | /** Draw the specified layers of 'picture' into either the atlas or free |
| 41 | floating textures. |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 42 | @param picture The picture containing the layers |
| 43 | @param atlased The layers to be drawn into the atlas |
| 44 | @param nonAtlased The layers to be drawn into their own textures |
| 45 | @oaram replacements The replacement structure to fill in with the rendered layer info |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 46 | */ |
| 47 | static void DrawLayers(const SkPicture* picture, |
| 48 | const SkTDArray<GrCachedLayer*>& atlased, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 49 | const SkTDArray<GrCachedLayer*>& nonAtlased, |
| 50 | GrReplacements* replacements); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 51 | |
| 52 | /** Unlock all the layers associated with picture in the layer cache. |
| 53 | @param layerCache holder of the locked layers |
| 54 | @pmara picture the source of the locked layers |
| 55 | */ |
| 56 | static void UnlockLayers(GrLayerCache* layerCache, const SkPicture* picture); |
| 57 | }; |
| 58 | |
| 59 | #endif |