LCOV - code coverage report
Current view: top level - gcore - gdal_rasterblock.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 19 100.0 %
Date: 2025-10-01 17:07:58 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Name:     gdal_rasterblock.h
       4             :  * Project:  GDAL Core
       5             :  * Purpose:  Declaration of GDALRasterBlock class
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 1998, Frank Warmerdam
      10             :  * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef GDALRASTERBLOCK_H_INCLUDED
      16             : #define GDALRASTERBLOCK_H_INCLUDED
      17             : 
      18             : #include "cpl_port.h"
      19             : #include "cpl_atomic_ops.h"
      20             : #include "gdal.h"
      21             : 
      22             : /* ******************************************************************** */
      23             : /*                           GDALRasterBlock                            */
      24             : /* ******************************************************************** */
      25             : 
      26             : class GDALRasterBand;
      27             : 
      28             : /** A single raster block in the block cache.
      29             :  *
      30             :  * And the global block manager that manages a least-recently-used list of
      31             :  * blocks from various datasets/bands */
      32             : class CPL_DLL GDALRasterBlock final
      33             : {
      34             :     friend class GDALAbstractBandBlockCache;
      35             : 
      36             :     GDALDataType eType = GDT_Unknown;
      37             : 
      38             :     bool bDirty = false;
      39             :     volatile int nLockCount = 0;
      40             : 
      41             :     int nXOff = 0;
      42             :     int nYOff = 0;
      43             : 
      44             :     int nXSize = 0;
      45             :     int nYSize = 0;
      46             : 
      47             :     void *pData = nullptr;
      48             : 
      49             :     GDALRasterBand *poBand = nullptr;
      50             : 
      51             :     GDALRasterBlock *poNext = nullptr;
      52             :     GDALRasterBlock *poPrevious = nullptr;
      53             : 
      54             :     bool bMustDetach = false;
      55             : 
      56             :     CPL_INTERNAL void Detach_unlocked(void);
      57             :     CPL_INTERNAL void Touch_unlocked(void);
      58             : 
      59             :     CPL_INTERNAL void RecycleFor(int nXOffIn, int nYOffIn);
      60             : 
      61             :   public:
      62             :     GDALRasterBlock(GDALRasterBand *, int, int);
      63             :     GDALRasterBlock(int nXOffIn, int nYOffIn); /* only for lookup purpose */
      64             :     ~GDALRasterBlock();
      65             : 
      66             :     CPLErr Internalize(void);
      67             :     void Touch(void);
      68             :     void MarkDirty(void);
      69             :     void MarkClean(void);
      70             : 
      71             :     /** Increment the lock count */
      72    10512500 :     int AddLock(void)
      73             :     {
      74    10512500 :         return CPLAtomicInc(&nLockCount);
      75             :     }
      76             : 
      77             :     /** Decrement the lock count */
      78    10512986 :     int DropLock(void)
      79             :     {
      80    10512986 :         return CPLAtomicDec(&nLockCount);
      81             :     }
      82             : 
      83             :     void Detach();
      84             : 
      85             :     CPLErr Write();
      86             : 
      87             :     /** Return the data type
      88             :      * @return data type
      89             :      */
      90       19554 :     GDALDataType GetDataType() const
      91             :     {
      92       19554 :         return eType;
      93             :     }
      94             : 
      95             :     /** Return the x offset of the top-left corner of the block
      96             :      * @return x offset
      97             :      */
      98    12330600 :     int GetXOff() const
      99             :     {
     100    12330600 :         return nXOff;
     101             :     }
     102             : 
     103             :     /** Return the y offset of the top-left corner of the block
     104             :      * @return y offset
     105             :      */
     106   483168000 :     int GetYOff() const
     107             :     {
     108   483168000 :         return nYOff;
     109             :     }
     110             : 
     111             :     /** Return the width of the block
     112             :      * @return width
     113             :      */
     114             :     int GetXSize() const
     115             :     {
     116             :         return nXSize;
     117             :     }
     118             : 
     119             :     /** Return the height of the block
     120             :      * @return height
     121             :      */
     122             :     int GetYSize() const
     123             :     {
     124             :         return nYSize;
     125             :     }
     126             : 
     127             :     /** Return the dirty flag
     128             :      * @return dirty flag
     129             :      */
     130     3978220 :     int GetDirty() const
     131             :     {
     132     3978220 :         return bDirty;
     133             :     }
     134             : 
     135             :     /** Return the data buffer
     136             :      * @return data buffer
     137             :      */
     138    13897732 :     void *GetDataRef(void)
     139             :     {
     140    13897732 :         return pData;
     141             :     }
     142             : 
     143             :     /** Return the block size in bytes
     144             :      * @return block size.
     145             :      */
     146     6759550 :     GPtrDiff_t GetBlockSize() const
     147             :     {
     148     6759550 :         return static_cast<GPtrDiff_t>(nXSize) * nYSize *
     149     6759550 :                GDALGetDataTypeSizeBytes(eType);
     150             :     }
     151             : 
     152             :     int TakeLock();
     153             :     int DropLockForRemovalFromStorage();
     154             : 
     155             :     /// @brief Accessor to source GDALRasterBand object.
     156             :     /// @return source raster band of the raster block.
     157       59395 :     GDALRasterBand *GetBand()
     158             :     {
     159       59395 :         return poBand;
     160             :     }
     161             : 
     162             :     static void FlushDirtyBlocks();
     163             :     static int FlushCacheBlock(int bDirtyBlocksOnly = FALSE);
     164             :     static void Verify();
     165             : 
     166             :     static void EnterDisableDirtyBlockFlush();
     167             :     static void LeaveDisableDirtyBlockFlush();
     168             : 
     169             : #ifdef notdef
     170             :     static void CheckNonOrphanedBlocks(GDALRasterBand *poBand);
     171             :     void DumpBlock();
     172             :     static void DumpAll();
     173             : #endif
     174             : 
     175             :     /* Should only be called by GDALDestroyDriverManager() */
     176             :     //! @cond Doxygen_Suppress
     177             :     CPL_INTERNAL static void DestroyRBMutex();
     178             :     //! @endcond
     179             : 
     180             :   private:
     181             :     CPL_DISALLOW_COPY_ASSIGN(GDALRasterBlock)
     182             : };
     183             : 
     184             : #endif

Generated by: LCOV version 1.14