/src/mozilla-central/gfx/2d/SourceSurfaceSkia.h
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 | | #ifndef MOZILLA_GFX_SOURCESURFACESKIA_H_ |
8 | | #define MOZILLA_GFX_SOURCESURFACESKIA_H_ |
9 | | |
10 | | #include "2D.h" |
11 | | #include <vector> |
12 | | #include "mozilla/Mutex.h" |
13 | | #include "skia/include/core/SkCanvas.h" |
14 | | #include "skia/include/core/SkImage.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | namespace gfx { |
19 | | |
20 | | class DrawTargetSkia; |
21 | | class SnapshotLock; |
22 | | |
23 | | class SourceSurfaceSkia : public DataSourceSurface |
24 | | { |
25 | | public: |
26 | | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia, override) |
27 | | |
28 | | SourceSurfaceSkia(); |
29 | | ~SourceSurfaceSkia(); |
30 | | |
31 | 0 | virtual SurfaceType GetType() const override { return SurfaceType::SKIA; } |
32 | | virtual IntSize GetSize() const override; |
33 | | virtual SurfaceFormat GetFormat() const override; |
34 | | |
35 | | // This is only ever called by the DT destructor, which can only ever happen |
36 | | // from one place at a time. Therefore it doesn't need to hold the ChangeMutex |
37 | | // as mSurface is never read to directly and is just there to keep the object |
38 | | // alive, which itself is refcounted in a thread-safe manner. |
39 | 0 | void GiveSurface(sk_sp<SkSurface> &aSurface) { mSurface = aSurface; mDrawTarget = nullptr; } |
40 | | |
41 | | sk_sp<SkImage> GetImage(); |
42 | | |
43 | | bool InitFromData(unsigned char* aData, |
44 | | const IntSize &aSize, |
45 | | int32_t aStride, |
46 | | SurfaceFormat aFormat); |
47 | | |
48 | | bool InitFromImage(const sk_sp<SkImage>& aImage, |
49 | | SurfaceFormat aFormat = SurfaceFormat::UNKNOWN, |
50 | | DrawTargetSkia* aOwner = nullptr); |
51 | | |
52 | | virtual uint8_t* GetData() override; |
53 | | |
54 | | /** |
55 | | * The caller is responsible for ensuring aMappedSurface is not null. |
56 | | */ |
57 | | virtual bool Map(MapType, MappedSurface *aMappedSurface) override; |
58 | | |
59 | | virtual void Unmap() override; |
60 | | |
61 | 0 | virtual int32_t Stride() override { return mStride; } |
62 | | |
63 | | private: |
64 | | friend class DrawTargetSkia; |
65 | | |
66 | | void DrawTargetWillChange(); |
67 | | |
68 | | sk_sp<SkImage> mImage; |
69 | | // This keeps a surface alive if needed because its DrawTarget has gone away. |
70 | | sk_sp<SkSurface> mSurface; |
71 | | SurfaceFormat mFormat; |
72 | | IntSize mSize; |
73 | | int32_t mStride; |
74 | | DrawTargetSkia* mDrawTarget; |
75 | | Mutex mChangeMutex; |
76 | | }; |
77 | | |
78 | | } // namespace gfx |
79 | | } // namespace mozilla |
80 | | |
81 | | #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */ |