Bug 1866777 - Disable test_race_cache_with_network.js on windows opt for frequent...
[gecko.git] / gfx / 2d / SourceSurfaceRawData.h
blob904f0fa1c8e164eda7b3fd6ebc40be23c2b0c2ee
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/. */
7 #ifndef MOZILLA_GFX_SOURCESURFACERAWDATA_H_
8 #define MOZILLA_GFX_SOURCESURFACERAWDATA_H_
10 #include "2D.h"
11 #include "Tools.h"
12 #include "mozilla/Atomics.h"
14 namespace mozilla {
15 namespace gfx {
17 class SourceSurfaceMappedData final : public DataSourceSurface {
18 public:
19 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceMappedData, final)
21 SourceSurfaceMappedData(ScopedMap&& aMap, const IntSize& aSize,
22 SurfaceFormat aFormat)
23 : mMap(std::move(aMap)), mSize(aSize), mFormat(aFormat) {}
25 ~SourceSurfaceMappedData() final = default;
27 uint8_t* GetData() final { return mMap.GetData(); }
28 int32_t Stride() final { return mMap.GetStride(); }
30 SurfaceType GetType() const final { return SurfaceType::DATA_MAPPED; }
31 IntSize GetSize() const final { return mSize; }
32 SurfaceFormat GetFormat() const final { return mFormat; }
34 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
35 SizeOfInfo& aInfo) const override {
36 aInfo.AddType(SurfaceType::DATA_MAPPED);
37 mMap.GetSurface()->SizeOfExcludingThis(aMallocSizeOf, aInfo);
40 const DataSourceSurface* GetScopedSurface() const {
41 return mMap.GetSurface();
44 private:
45 ScopedMap mMap;
46 IntSize mSize;
47 SurfaceFormat mFormat;
50 class SourceSurfaceRawData : public DataSourceSurface {
51 public:
52 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRawData, override)
54 SourceSurfaceRawData()
55 : mRawData(0),
56 mStride(0),
57 mFormat(SurfaceFormat::UNKNOWN),
58 mDeallocator(nullptr),
59 mClosure(nullptr) {}
61 virtual ~SourceSurfaceRawData() {
62 if (mDeallocator) {
63 mDeallocator(mClosure);
67 virtual uint8_t* GetData() override { return mRawData; }
68 virtual int32_t Stride() override { return mStride; }
70 virtual SurfaceType GetType() const override { return SurfaceType::DATA; }
71 virtual IntSize GetSize() const override { return mSize; }
72 virtual SurfaceFormat GetFormat() const override { return mFormat; }
74 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
75 SizeOfInfo& aInfo) const override;
77 private:
78 friend class Factory;
80 // If we have a custom deallocator, the |aData| will be released using the
81 // custom deallocator and |aClosure| in dtor. The assumption is that the
82 // caller will check for valid size and stride before making this call.
83 void InitWrappingData(unsigned char* aData, const IntSize& aSize,
84 int32_t aStride, SurfaceFormat aFormat,
85 Factory::SourceSurfaceDeallocator aDeallocator,
86 void* aClosure);
88 uint8_t* mRawData;
89 int32_t mStride;
90 SurfaceFormat mFormat;
91 IntSize mSize;
93 Factory::SourceSurfaceDeallocator mDeallocator;
94 void* mClosure;
97 class SourceSurfaceAlignedRawData : public DataSourceSurface {
98 public:
99 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceAlignedRawData,
100 override)
101 SourceSurfaceAlignedRawData() : mStride(0), mFormat(SurfaceFormat::UNKNOWN) {}
102 ~SourceSurfaceAlignedRawData() override = default;
104 bool Init(const IntSize& aSize, SurfaceFormat aFormat, bool aClearMem,
105 uint8_t aClearValue, int32_t aStride = 0);
107 uint8_t* GetData() override { return mArray; }
108 int32_t Stride() override { return mStride; }
110 SurfaceType GetType() const override { return SurfaceType::DATA_ALIGNED; }
111 IntSize GetSize() const override { return mSize; }
112 SurfaceFormat GetFormat() const override { return mFormat; }
114 void SizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
115 SizeOfInfo& aInfo) const override;
117 private:
118 friend class Factory;
120 AlignedArray<uint8_t> mArray;
121 int32_t mStride;
122 SurfaceFormat mFormat;
123 IntSize mSize;
126 } // namespace gfx
127 } // namespace mozilla
129 #endif /* MOZILLA_GFX_SOURCESURFACERAWDATA_H_ */