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; |
| 24 | SkMatrix fCTM; |
| 25 | }; |
| 26 | |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 27 | // 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 |
| 32 | class GrLayerHoister { |
| 33 | public: |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 34 | |
| 35 | /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered |
| 36 | layers can be inside nested sub-pictures. |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 37 | @param context Owner of the layer cache (the source of new layers) |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 38 | @param topLevelPicture The top-level picture that is about to be rendered |
| 39 | @param query The rectangle that is about to be drawn. |
| 40 | @param atlased Out parameter storing the layers that should be hoisted to the atlas |
| 41 | @param nonAtlased Out parameter storing the layers that should be hoisted stand alone |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 42 | @param recycled Out parameter storing layers that need hoisting but not rendering |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 43 | Return true if any layers are suitable for hoisting; false otherwise |
| 44 | */ |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 45 | static bool FindLayersToHoist(GrContext* context, |
| 46 | const SkPicture* topLevelPicture, |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 47 | const SkRect& query, |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 48 | SkTDArray<GrHoistedLayer>* atlased, |
| 49 | SkTDArray<GrHoistedLayer>* nonAtlased, |
| 50 | SkTDArray<GrHoistedLayer>* recycled); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 51 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 52 | /** Draw the specified layers into either the atlas or free floating textures. |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 53 | @param atlased The layers to be drawn into the atlas |
| 54 | @param nonAtlased The layers to be drawn into their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 55 | @param recycled Layers that don't need rendering but do need to go into the |
| 56 | replacements object |
| 57 | @param replacements The replacement structure to fill in with the rendered layer info |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 58 | */ |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 59 | static void DrawLayers(const SkTDArray<GrHoistedLayer>& atlased, |
| 60 | const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 61 | const SkTDArray<GrHoistedLayer>& recycled, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 62 | GrReplacements* replacements); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 63 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 64 | /** Unlock unneeded layers in the layer cache. |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 65 | @param context Owner of the layer cache (and thus the layers) |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 66 | @param atlased Unneeded layers in the atlas |
| 67 | @param nonAtlased Unneeded layers in their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 68 | @param recycled Unneeded layers that did not require rendering |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 69 | */ |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame^] | 70 | static void UnlockLayers(GrContext* context, |
| 71 | const SkTDArray<GrHoistedLayer>& atlased, |
| 72 | const SkTDArray<GrHoistedLayer>& nonAtlased, |
| 73 | const SkTDArray<GrHoistedLayer>& recycled); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #endif |