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: |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 26 | struct HoistedLayer { |
| 27 | const SkPicture* fPicture; |
| 28 | GrCachedLayer* fLayer; |
robertphillips | ed42059 | 2014-09-29 11:39:38 -0700 | [diff] [blame] | 29 | SkIPoint fOffset; |
| 30 | SkMatrix fCTM; |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 31 | }; |
| 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 |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 39 | @param recycled Out parameter storing layers that need hoisting but not rendering |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 40 | @param layerCache The source of new layers |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 41 | Return true if any layers are suitable for hoisting; false otherwise |
| 42 | */ |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 43 | static bool FindLayersToHoist(const SkPicture* topLevelPicture, |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 44 | const SkRect& query, |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 45 | SkTDArray<HoistedLayer>* altased, |
| 46 | SkTDArray<HoistedLayer>* nonAtlased, |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 47 | SkTDArray<HoistedLayer>* recycled, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 48 | GrLayerCache* layerCache); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 49 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 50 | /** Draw the specified layers into either the atlas or free floating textures. |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 51 | @param atlased The layers to be drawn into the atlas |
| 52 | @param nonAtlased The layers to be drawn into their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 53 | @param recycled Layers that don't need rendering but do need to go into the |
| 54 | replacements object |
| 55 | @param replacements The replacement structure to fill in with the rendered layer info |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 56 | */ |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 57 | static void DrawLayers(const SkTDArray<HoistedLayer>& atlased, |
| 58 | const SkTDArray<HoistedLayer>& nonAtlased, |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 59 | const SkTDArray<HoistedLayer>& recycled, |
robertphillips | 1c4c528 | 2014-09-18 12:03:15 -0700 | [diff] [blame] | 60 | GrReplacements* replacements); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 61 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 62 | /** Unlock unneeded layers in the layer cache. |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 63 | @param layerCache holder of the locked layers |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 64 | @param atlased Unneeded layers in the atlas |
| 65 | @param nonAtlased Unneeded layers in their own textures |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 66 | @param recycled Unneeded layers that did not require rendering |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 67 | */ |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 68 | static void UnlockLayers(GrLayerCache* layerCache, |
| 69 | const SkTDArray<HoistedLayer>& atlased, |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 70 | const SkTDArray<HoistedLayer>& nonAtlased, |
| 71 | const SkTDArray<HoistedLayer>& recycled); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #endif |