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

          Line data    Source code
       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 GrGpuResourceCacheAccess_DEFINED
       9             : #define GrGpuResourceCacheAccess_DEFINED
      10             : 
      11             : #include "GrGpuResource.h"
      12             : #include "GrGpuResourcePriv.h"
      13             : 
      14             : namespace skiatest {
      15             :     class Reporter;
      16             : }
      17             : 
      18             : /**
      19             :  * This class allows GrResourceCache increased privileged access to GrGpuResource objects.
      20             :  */
      21             : class GrGpuResource::CacheAccess {
      22             : private:
      23             :     /**
      24             :      * Is the resource currently cached as scratch? This means it is cached, has a valid scratch
      25             :      * key, and does not have a unique key.
      26             :      */
      27           0 :     bool isScratch() const {
      28           0 :         return !fResource->getUniqueKey().isValid() && fResource->fScratchKey.isValid() &&
      29           0 :                 SkBudgeted::kYes == fResource->resourcePriv().isBudgeted();
      30             :     }
      31             : 
      32             :     /**
      33             :      * Called by the cache to delete the resource under normal circumstances.
      34             :      */
      35           0 :     void release() {
      36           0 :         fResource->release();
      37           0 :         if (fResource->isPurgeable()) {
      38           0 :             delete fResource;
      39             :         }
      40           0 :     }
      41             : 
      42             :     /**
      43             :      * Called by the cache to delete the resource when the backend 3D context is no longer valid.
      44             :      */
      45           0 :     void abandon() {
      46           0 :         fResource->abandon();
      47           0 :         if (fResource->isPurgeable()) {
      48           0 :             delete fResource;
      49             :         }
      50           0 :     }
      51             : 
      52             :     /** Called by the cache to assign a new unique key. */
      53           0 :     void setUniqueKey(const GrUniqueKey& key) { fResource->fUniqueKey = key; }
      54             : 
      55             :     /** Called by the cache to make the unique key invalid. */
      56           0 :     void removeUniqueKey() { fResource->fUniqueKey.reset(); }
      57             : 
      58           0 :     uint32_t timestamp() const { return fResource->fTimestamp; }
      59           0 :     void setTimestamp(uint32_t ts) { fResource->fTimestamp = ts; }
      60             : 
      61             :     /** Called by the cache to record when this became purgeable. */
      62           0 :     void setFlushCntWhenResourceBecamePurgeable(uint32_t cnt) {
      63           0 :         SkASSERT(fResource->isPurgeable());
      64           0 :         fResource->fExternalFlushCntWhenBecamePurgeable = cnt;
      65           0 :     }
      66           0 :     void setTimeWhenResourceBecomePurgeable() {
      67           0 :         SkASSERT(fResource->isPurgeable());
      68           0 :         fResource->fTimeWhenBecamePurgeable = GrStdSteadyClock::now();
      69           0 :     }
      70             :     /**
      71             :      * Called by the cache to determine whether this resource has been puregable for more than
      72             :      * a threshold number of external flushes.
      73             :      */
      74           0 :     uint32_t flushCntWhenResourceBecamePurgeable() {
      75           0 :         SkASSERT(fResource->isPurgeable());
      76           0 :         return fResource->fExternalFlushCntWhenBecamePurgeable;
      77             :     }
      78             :     /**
      79             :      * Called by the cache to determine whether this resource should be purged based on the length
      80             :      * of time it has been available for purging.
      81             :      */
      82           0 :     GrStdSteadyClock::time_point timeWhenResourceBecamePurgeable() {
      83           0 :         SkASSERT(fResource->isPurgeable());
      84           0 :         return fResource->fTimeWhenBecamePurgeable;
      85             :     }
      86             : 
      87           0 :     int* accessCacheIndex() const { return &fResource->fCacheArrayIndex; }
      88             : 
      89           0 :     CacheAccess(GrGpuResource* resource) : fResource(resource) {}
      90             :     CacheAccess(const CacheAccess& that) : fResource(that.fResource) {}
      91             :     CacheAccess& operator=(const CacheAccess&); // unimpl
      92             : 
      93             :     // No taking addresses of this type.
      94             :     const CacheAccess* operator&() const;
      95             :     CacheAccess* operator&();
      96             : 
      97             :     GrGpuResource* fResource;
      98             : 
      99             :     friend class GrGpuResource; // to construct/copy this type.
     100             :     friend class GrResourceCache; // to use this type
     101             :     friend void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); // for unit testing
     102             : };
     103             : 
     104           0 : inline GrGpuResource::CacheAccess GrGpuResource::cacheAccess() { return CacheAccess(this); }
     105             : 
     106           0 : inline const GrGpuResource::CacheAccess GrGpuResource::cacheAccess() const {
     107           0 :     return CacheAccess(const_cast<GrGpuResource*>(this));
     108             : }
     109             : 
     110             : #endif

Generated by: LCOV version 1.13