Home | History | Annotate | Download | only in gpu
      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;
     16 class GrReplacements;
     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     struct HoistedLayer {
     27         const SkPicture* fPicture;
     28         GrCachedLayer*   fLayer;
     29     };
     30 
     31     /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
     32         layers can be inside nested sub-pictures.
     33         @param topLevelPicture The top-level picture that is about to be rendered
     34         @param query       The rectangle that is about to be drawn.
     35         @param atlased     Out parameter storing the layers that should be hoisted to the atlas
     36         @param nonAtlased  Out parameter storing the layers that should be hoisted stand alone
     37         @param layerCache The source of new layers
     38         Return true if any layers are suitable for hoisting; false otherwise
     39     */
     40     static bool FindLayersToHoist(const SkPicture* topLevelPicture,
     41                                   const SkRect& query,
     42                                   SkTDArray<HoistedLayer>* altased,
     43                                   SkTDArray<HoistedLayer>* nonAtlased,
     44                                   GrLayerCache* layerCache);
     45 
     46     /** Draw the specified layers into either the atlas or free floating textures.
     47         @param atlased      The layers to be drawn into the atlas
     48         @param nonAtlased   The layers to be drawn into their own textures
     49         @oaram replacements The replacement structure to fill in with the rendered layer info
     50     */
     51     static void DrawLayers(const SkTDArray<HoistedLayer>& atlased,
     52                            const SkTDArray<HoistedLayer>& nonAtlased,
     53                            GrReplacements* replacements);
     54 
     55     /** Unlock unneeded layers in the layer cache.
     56         @param layerCache holder of the locked layers
     57         @param atlased    Unneeded layers in the atlas
     58         @param nonAtlased Unneeded layers in their own textures
     59     */
     60     static void UnlockLayers(GrLayerCache* layerCache,
     61                              const SkTDArray<HoistedLayer>& atlased,
     62                              const SkTDArray<HoistedLayer>& nonAtlased);
     63 };
     64 
     65 #endif
     66