LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/gpu - GrResourceProvider.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 22 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2015 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 GrResourceProvider_DEFINED
       9             : #define GrResourceProvider_DEFINED
      10             : 
      11             : #include "GrBuffer.h"
      12             : #include "GrGpu.h"
      13             : #include "GrPathRange.h"
      14             : 
      15             : class GrPath;
      16             : class GrRenderTarget;
      17             : class GrSingleOwner;
      18             : class GrStencilAttachment;
      19             : class GrStyle;
      20             : class SkDescriptor;
      21             : class SkPath;
      22             : class SkTypeface;
      23             : 
      24             : /**
      25             :  * A factory for arbitrary resource types. This class is intended for use within the Gr code base.
      26             :  *
      27             :  * Some members force callers to make a flags (pendingIO) decision. This can be relaxed once
      28             :  * https://bug.skia.org/4156 is fixed.
      29             :  */
      30           0 : class GrResourceProvider {
      31             : public:
      32             :     GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* owner);
      33             : 
      34           0 :     template <typename T> T* findAndRefTByUniqueKey(const GrUniqueKey& key) {
      35           0 :         return static_cast<T*>(this->findAndRefResourceByUniqueKey(key));
      36             :     }
      37             : 
      38             :     ///////////////////////////////////////////////////////////////////////////
      39             :     // Textures
      40             : 
      41             :     /**
      42             :      * Creates a new texture in the resource cache and returns it. The caller owns a
      43             :      * ref on the returned texture which must be balanced by a call to unref.
      44             :      *
      45             :      * @param desc          Description of the texture properties.
      46             :      * @param budgeted      Does the texture count against the resource cache budget?
      47             :      * @param texels        A contiguous array of mipmap levels
      48             :      * @param mipLevelCount The amount of elements in the texels array
      49             :      */
      50             :     sk_sp<GrTextureProxy> createMipMappedTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
      51             :                                                  const GrMipLevel* texels, int mipLevelCount,
      52             :                                                  uint32_t flags = 0,
      53             :                                                  SkDestinationSurfaceColorMode mipColorMode =
      54             :                                                         SkDestinationSurfaceColorMode::kLegacy);
      55             : 
      56             :     /** Assigns a unique key to the texture. The texture will be findable via this key using
      57             :     findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */
      58             :     void assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy*);
      59             : 
      60             :     /** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
      61             :     sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey& key);
      62             : 
      63             :     /**
      64             :      * Finds a texture that approximately matches the descriptor. Will be at least as large in width
      65             :      * and height as desc specifies. If desc specifies that the texture should be a render target
      66             :      * then result will be a render target. Format and sample count will always match the request.
      67             :      * The contents of the texture are undefined. The caller owns a ref on the returned texture and
      68             :      * must balance with a call to unref.
      69             :      */
      70             :     GrTexture* createApproxTexture(const GrSurfaceDesc&, uint32_t flags);
      71             : 
      72             :     /** Create an exact fit texture with no initial data to upload.
      73             :      */
      74             :     sk_sp<GrTexture> createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
      75             :                                    uint32_t flags = 0);
      76             : 
      77             :     ///////////////////////////////////////////////////////////////////////////
      78             :     // Wrapped Backend Surfaces
      79             : 
      80             :     /**
      81             :      * Wraps an existing texture with a GrTexture object.
      82             :      *
      83             :      * OpenGL: if the object is a texture Gr may change its GL texture params
      84             :      *         when it is drawn.
      85             :      *
      86             :      * @return GrTexture object or NULL on failure.
      87             :      */
      88             :     sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc& desc,
      89             :                                         GrWrapOwnership = kBorrow_GrWrapOwnership);
      90             : 
      91             :     /**
      92             :      * Wraps an existing render target with a GrRenderTarget object. It is
      93             :      * similar to wrapBackendTexture but can be used to draw into surfaces
      94             :      * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
      95             :      * the client will resolve to a texture). Currently wrapped render targets
      96             :      * always use the kBorrow_GrWrapOwnership semantics.
      97             :      *
      98             :      * @return GrRenderTarget object or NULL on failure.
      99             :      */
     100             :     sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
     101             : 
     102             :     static const int kMinScratchTextureSize;
     103             : 
     104             :     /**
     105             :      * Either finds and refs, or creates an index buffer for instanced drawing with a specific
     106             :      * pattern if the index buffer is not found. If the return is non-null, the caller owns
     107             :      * a ref on the returned GrBuffer.
     108             :      *
     109             :      * @param pattern     the pattern of indices to repeat
     110             :      * @param patternSize size in bytes of the pattern
     111             :      * @param reps        number of times to repeat the pattern
     112             :      * @param vertCount   number of vertices the pattern references
     113             :      * @param key         Key to be assigned to the index buffer.
     114             :      *
     115             :      * @return The index buffer if successful, otherwise nullptr.
     116             :      */
     117           0 :     const GrBuffer* findOrCreateInstancedIndexBuffer(const uint16_t* pattern,
     118             :                                                      int patternSize,
     119             :                                                      int reps,
     120             :                                                      int vertCount,
     121             :                                                      const GrUniqueKey& key) {
     122           0 :         if (GrBuffer* buffer = this->findAndRefTByUniqueKey<GrBuffer>(key)) {
     123           0 :             return buffer;
     124             :         }
     125           0 :         return this->createInstancedIndexBuffer(pattern, patternSize, reps, vertCount, key);
     126             :     }
     127             : 
     128             :     /**
     129             :      * Returns an index buffer that can be used to render quads.
     130             :      * Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
     131             :      * The max number of quads is the buffer's index capacity divided by 6.
     132             :      * Draw with kTriangles_GrPrimitiveType
     133             :      * @ return the quad index buffer
     134             :      */
     135           0 :     const GrBuffer* refQuadIndexBuffer() {
     136           0 :         if (GrBuffer* buffer =
     137           0 :             this->findAndRefTByUniqueKey<GrBuffer>(fQuadIndexBufferKey)) {
     138           0 :             return buffer;
     139             :         }
     140           0 :         return this->createQuadIndexBuffer();
     141             :     }
     142             : 
     143             :     /**
     144             :      * Factories for GrPath and GrPathRange objects. It's an error to call these if path rendering
     145             :      * is not supported.
     146             :      */
     147             :     GrPath* createPath(const SkPath&, const GrStyle&);
     148             :     GrPathRange* createPathRange(GrPathRange::PathGenerator*, const GrStyle&);
     149             :     GrPathRange* createGlyphs(const SkTypeface*, const SkScalerContextEffects&,
     150             :                               const SkDescriptor*, const GrStyle&);
     151             : 
     152             :     /** These flags govern which scratch resources we are allowed to return */
     153             :     enum Flags {
     154             :         kExact_Flag           = 0x1,
     155             : 
     156             :         /** If the caller intends to do direct reads/writes to/from the CPU then this flag must be
     157             :          *  set when accessing resources during a GrOpList flush. This includes the execution of
     158             :          *  GrOp objects. The reason is that these memory operations are done immediately and
     159             :          *  will occur out of order WRT the operations being flushed.
     160             :          *  Make this automatic: https://bug.skia.org/4156
     161             :          */
     162             :         kNoPendingIO_Flag     = 0x2,
     163             : 
     164             :         kNoCreate_Flag        = 0x4,
     165             : 
     166             :         /** Normally the caps may indicate a preference for client-side buffers. Set this flag when
     167             :          *  creating a buffer to guarantee it resides in GPU memory.
     168             :          */
     169             :         kRequireGpuMemory_Flag = 0x8,
     170             :     };
     171             : 
     172             :     /**
     173             :      * Returns a buffer.
     174             :      *
     175             :      * @param size            minimum size of buffer to return.
     176             :      * @param intendedType    hint to the graphics subsystem about what the buffer will be used for.
     177             :      * @param GrAccessPattern hint to the graphics subsystem about how the data will be accessed.
     178             :      * @param flags           see Flags enum.
     179             :      * @param data            optional data with which to initialize the buffer.
     180             :      *
     181             :      * @return the buffer if successful, otherwise nullptr.
     182             :      */
     183             :     GrBuffer* createBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, uint32_t flags,
     184             :                            const void* data = nullptr);
     185             : 
     186             : 
     187             :     /**
     188             :      * If passed in render target already has a stencil buffer, return it. Otherwise attempt to
     189             :      * attach one.
     190             :      */
     191             :     GrStencilAttachment* attachStencilAttachment(GrRenderTarget* rt);
     192             : 
     193             :      /**
     194             :       * Wraps an existing texture with a GrRenderTarget object. This is useful when the provided
     195             :       * texture has a format that cannot be textured from by Skia, but we want to raster to it.
     196             :       *
     197             :       * The texture is wrapped as borrowed. The texture object will not be freed once the
     198             :       * render target is destroyed.
     199             :       *
     200             :       * @return GrRenderTarget object or NULL on failure.
     201             :       */
     202             :      sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc);
     203             : 
     204             :     /**
     205             :      * Assigns a unique key to a resource. If the key is associated with another resource that
     206             :      * association is removed and replaced by this resource.
     207             :      */
     208             :     void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
     209             : 
     210             :     /**
     211             :      * Finds a resource in the cache, based on the specified key. This is intended for use in
     212             :      * conjunction with addResourceToCache(). The return value will be NULL if not found. The
     213             :      * caller must balance with a call to unref().
     214             :      */
     215             :     GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&);
     216             : 
     217             :     sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore();
     218             : 
     219             :     // Takes the GrSemaphore and sets the ownership of the semaphore to the GrGpu object used by
     220             :     // this class. This call is only used when passing a GrSemaphore from one context to another.
     221             :     void takeOwnershipOfSemaphore(sk_sp<GrSemaphore>);
     222             :     // Takes the GrSemaphore and resets the ownership of the semaphore so that it is not owned by
     223             :     // any GrGpu. A follow up call to takeOwnershipofSemaphore must be made so that the underlying
     224             :     // semaphore can be deleted. This call is only used when passing a GrSemaphore from one context
     225             :     // to another.
     226             :     void releaseOwnershipOfSemaphore(sk_sp<GrSemaphore>);
     227             : 
     228           0 :     void abandon() {
     229           0 :         fCache = nullptr;
     230           0 :         fGpu = nullptr;
     231           0 :     }
     232             : 
     233             :     // 'proxy' is about to be used as a texture src or drawn to. This query can be used to
     234             :     // determine if it is going to need a texture domain or a full clear.
     235             :     static bool IsFunctionallyExact(GrSurfaceProxy* proxy);
     236             : 
     237           0 :     const GrCaps* caps() const { return fCaps.get(); }
     238             : 
     239             : private:
     240             :     GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
     241             :     void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
     242             :         SkASSERT(key.isValid());
     243             :         this->assignUniqueKeyToResource(key, texture);
     244             :     }
     245             : 
     246             :     GrTexture* refScratchTexture(const GrSurfaceDesc&, uint32_t scratchTextureFlags);
     247             : 
     248           0 :     GrResourceCache* cache() { return fCache; }
     249             :     const GrResourceCache* cache() const { return fCache; }
     250             : 
     251           0 :     GrGpu* gpu() { return fGpu; }
     252             :     const GrGpu* gpu() const { return fGpu; }
     253             : 
     254           0 :     bool isAbandoned() const {
     255           0 :         SkASSERT(SkToBool(fGpu) == SkToBool(fCache));
     256           0 :         return !SkToBool(fCache);
     257             :     }
     258             : 
     259             :     const GrBuffer* createInstancedIndexBuffer(const uint16_t* pattern,
     260             :                                                int patternSize,
     261             :                                                int reps,
     262             :                                                int vertCount,
     263             :                                                const GrUniqueKey& key);
     264             : 
     265             :     const GrBuffer* createQuadIndexBuffer();
     266             : 
     267             :     GrResourceCache*    fCache;
     268             :     GrGpu*              fGpu;
     269             :     sk_sp<const GrCaps> fCaps;
     270             :     GrUniqueKey         fQuadIndexBufferKey;
     271             : 
     272             :     // In debug builds we guard against improper thread handling
     273             :     SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;)
     274             : };
     275             : 
     276             : #endif

Generated by: LCOV version 1.13