Coverage Report

Created: 2018-09-25 14:53

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