LCOV - code coverage report
Current view: top level - gfx/2d - SourceSurfaceRawData.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 11 31 35.5 %
Date: 2017-07-14 16:53:18 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "SourceSurfaceRawData.h"
       7             : 
       8             : #include "DataSurfaceHelpers.h"
       9             : #include "Logging.h"
      10             : #include "mozilla/Types.h" // for decltype
      11             : 
      12             : namespace mozilla {
      13             : namespace gfx {
      14             : 
      15             : void
      16          83 : SourceSurfaceRawData::InitWrappingData(uint8_t *aData,
      17             :                                        const IntSize &aSize,
      18             :                                        int32_t aStride,
      19             :                                        SurfaceFormat aFormat,
      20             :                                        Factory::SourceSurfaceDeallocator aDeallocator,
      21             :                                        void* aClosure)
      22             : {
      23          83 :   mRawData = aData;
      24          83 :   mSize = aSize;
      25          83 :   mStride = aStride;
      26          83 :   mFormat = aFormat;
      27             : 
      28          83 :   if (aDeallocator) {
      29          74 :     mOwnData = true;
      30             :   }
      31          83 :   mDeallocator = aDeallocator;
      32          83 :   mClosure = aClosure;
      33          83 : }
      34             : 
      35             : void
      36           0 : SourceSurfaceRawData::GuaranteePersistance()
      37             : {
      38           0 :   if (mOwnData) {
      39           0 :     return;
      40             :   }
      41             : 
      42           0 :   uint8_t* oldData = mRawData;
      43           0 :   mRawData = new uint8_t[mStride * mSize.height];
      44             : 
      45           0 :   memcpy(mRawData, oldData, mStride * mSize.height);
      46           0 :   mOwnData = true;
      47             : }
      48             : 
      49             : bool
      50           0 : SourceSurfaceAlignedRawData::Init(const IntSize &aSize,
      51             :                                   SurfaceFormat aFormat,
      52             :                                   bool aClearMem,
      53             :                                   uint8_t aClearValue,
      54             :                                   int32_t aStride)
      55             : {
      56           0 :   mFormat = aFormat;
      57           0 :   mStride = aStride ? aStride : GetAlignedStride<16>(aSize.width, BytesPerPixel(aFormat));
      58             : 
      59           0 :   size_t bufLen = BufferSizeFromStrideAndHeight(mStride, aSize.height);
      60           0 :   if (bufLen > 0) {
      61           0 :     bool zeroMem = aClearMem && !aClearValue;
      62             :     static_assert(sizeof(decltype(mArray[0])) == 1,
      63             :                   "mArray.Realloc() takes an object count, so its objects must be 1-byte sized if we use bufLen");
      64             : 
      65             :     // AlignedArray uses cmalloc to zero mem for a fast path.
      66           0 :     mArray.Realloc(/* actually an object count */ bufLen, zeroMem);
      67           0 :     mSize = aSize;
      68             : 
      69           0 :     if (mArray && aClearMem && aClearValue) {
      70           0 :       memset(mArray, aClearValue, mStride * aSize.height);
      71             :     }
      72             :   } else {
      73           0 :     mArray.Dealloc();
      74           0 :     mSize.SizeTo(0, 0);
      75             :   }
      76             : 
      77           0 :   return mArray != nullptr;
      78             : }
      79             : 
      80             : } // namespace gfx
      81           9 : } // namespace mozilla

Generated by: LCOV version 1.13