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 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 36 | /** Find the layers in 'topLevelPicture' that can be atlased. Note that the discovered |
| 37 | layers can be inside nested sub-pictures. |
| 38 | @param context Owner of the layer cache (the source of new layers) |
| 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 atlasedNeedRendering Out parameter storing the layers that |
| 42 | should be hoisted to the atlas |
| 43 | @param recycled Out parameter storing layers that are atlased but do not need rendering |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame^] | 44 | @param numSamples The number if MSAA samples required |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 45 | */ |
| 46 | static void FindLayersToAtlas(GrContext* context, |
| 47 | const SkPicture* topLevelPicture, |
| 48 | const SkRect& query, |
| 49 | SkTDArray<GrHoistedLayer>* atlasedNeedRendering, |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame^] | 50 | SkTDArray<GrHoistedLayer>* recycled, |
| 51 | int numSamples); |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 52 | |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 53 | /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered |
| 54 | layers can be inside nested sub-pictures. |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 55 | @param context Owner of the layer cache (the source of new layers) |
robertphillips | 30d2cc6 | 2014-09-24 08:52:18 -0700 | [diff] [blame] | 56 | @param topLevelPicture The top-level picture that is about to be rendered |
| 57 | @param query The rectangle that is about to be drawn. |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 58 | @param needRendering Out parameter storing the layers that need rendering. |
| 59 | This should never include atlased layers. |
robertphillips | b5a9715 | 2014-09-30 11:33:02 -0700 | [diff] [blame] | 60 | @param recycled Out parameter storing layers that need hoisting but not rendering |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame^] | 61 | @param numSamples The number if MSAA samples required |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 62 | */ |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 63 | static void FindLayersToHoist(GrContext* context, |
robertphillips | d61ef01 | 2014-10-08 05:17:02 -0700 | [diff] [blame] | 64 | const SkPicture* topLevelPicture, |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 65 | const SkRect& query, |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 66 | SkTDArray<GrHoistedLayer>* needRendering, |
robertphillips | a63f32e | 2014-11-10 08:10:42 -0800 | [diff] [blame^] | 67 | SkTDArray<GrHoistedLayer>* recycled, |
| 68 | int numSamples); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 69 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 70 | /** Draw the specified layers into the atlas. |
robertphillips | 9e6835d | 2014-10-22 05:33:52 -0700 | [diff] [blame] | 71 | @param context Owner of the layer cache (and thus the layers) |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 72 | @param layers The layers to be drawn into the atlas |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 73 | */ |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 74 | static void DrawLayersToAtlas(GrContext* context, const SkTDArray<GrHoistedLayer>& layers); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 75 | |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 76 | /** Draw the specified layers into their own individual textures. |
| 77 | @param context Owner of the layer cache (and thus the layers) |
| 78 | @param layers The layers to be drawn |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 79 | */ |
robertphillips | fd61ed0 | 2014-10-28 07:21:44 -0700 | [diff] [blame] | 80 | static void DrawLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers); |
| 81 | |
| 82 | /** Convert all the layers in 'layers' into replacement objects in 'replacements'. |
| 83 | @param layers The hoisted layers |
| 84 | @param replacements Replacement object that will be used for a replacement draw |
| 85 | */ |
| 86 | static void ConvertLayersToReplacements(const SkTDArray<GrHoistedLayer>& layers, |
| 87 | GrReplacements* replacements); |
| 88 | |
| 89 | /** Unlock a group of layers in the layer cache. |
| 90 | @param context Owner of the layer cache (and thus the layers) |
| 91 | @param layers Unneeded layers in the atlas |
| 92 | */ |
| 93 | static void UnlockLayers(GrContext* context, const SkTDArray<GrHoistedLayer>& layers); |
robertphillips | 4ab5a90 | 2014-10-29 13:56:02 -0700 | [diff] [blame] | 94 | |
| 95 | /** Forceably remove all cached layers and release the atlas. Useful for debugging and timing. |
| 96 | This is only functional when GR_CACHE_HOISTED_LAYERS is set to 1 in GrLayerCache.h |
| 97 | @param context Owner of the layer cache (and thus the layers) |
| 98 | */ |
| 99 | static void PurgeCache(GrContext* context); |
robertphillips | 98d709b | 2014-09-02 10:20:50 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | #endif |