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 | |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 19 | class GrHoistedLayer { |
| 20 | public: |
| 21 | const SkPicture* fPicture; |
| 22 | GrCachedLayer* fLayer; |
| 23 | SkIPoint fOffset; |
robertphillips | 9e6835d | 2014-10-22 05:33:52 -0700 | [diff] [blame] | 24 | SkMatrix fPreMat; |
| 25 | SkMatrix fLocalMat; |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 28 | // 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 |
| 33 | class GrLayerHoister { |
| 34 | public: |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 35 | |
| 36 | /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered |
| 37 | layers can be inside nested sub-pictures. |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 38 | @param context Owner of the layer cache (the source of new layers) |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 39 | @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 |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 43 | @param recycled Out parameter storing layers that need hoisting but not rendering |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 44 | Return true if any layers are suitable for hoisting; false otherwise |
| 45 | */ |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 46 | static bool FindLayersToHoist(GrContext* context, |
| 47 | const SkPicture* topLevelPicture, |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 48 | const SkRect& query, |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 49 | SkTDArray<GrHoistedLayer>* atlased, |
| 50 | SkTDArray<GrHoistedLayer>* nonAtlased, |
| 51 | SkTDArray<GrHoistedLayer>* recycled); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 52 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 53 | /** Draw the specified layers into either the atlas or free floating textures. |
robertphillips | 9e6835d | 2014-10-22 05:33:52 -0700 | [diff] [blame] | 54 | @param context Owner of the layer cache (and thus the layers) |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 55 | @param atlased The layers to be drawn into the atlas |
| 56 | @param nonAtlased The layers to be drawn into their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 57 | @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 |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 60 | */ |
robertphillips | 9e6835d | 2014-10-22 05:33:52 -0700 | [diff] [blame] | 61 | static void DrawLayers(GrContext* context, |
| 62 | const SkTDArray<GrHoistedLayer>& atlased, |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 63 | const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 64 | const SkTDArray<GrHoistedLayer>& recycled, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 65 | GrReplacements* replacements); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 66 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 67 | /** Unlock unneeded layers in the layer cache. |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 68 | @param context Owner of the layer cache (and thus the layers) |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 69 | @param atlased Unneeded layers in the atlas |
| 70 | @param nonAtlased Unneeded layers in their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 71 | @param recycled Unneeded layers that did not require rendering |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 72 | */ |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 73 | static void UnlockLayers(GrContext* context, |
| 74 | const SkTDArray<GrHoistedLayer>& atlased, |
| 75 | const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 76 | const SkTDArray<GrHoistedLayer>& recycled); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | #endif |