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_SOURCESURFACESKIA_H_
8 #define MOZILLA_GFX_SOURCESURFACESKIA_H_
12 #include "mozilla/Mutex.h"
13 #include "skia/include/core/SkCanvas.h"
14 #include "skia/include/core/SkImage.h"
23 class SourceSurfaceSkia
: public DataSourceSurface
{
25 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia
, override
)
28 virtual ~SourceSurfaceSkia();
30 SurfaceType
GetType() const override
{ return SurfaceType::SKIA
; }
31 IntSize
GetSize() const override
;
32 SurfaceFormat
GetFormat() const override
;
34 // This is only ever called by the DT destructor, which can only ever happen
35 // from one place at a time. Therefore it doesn't need to hold the ChangeMutex
36 // as mSurface is never read to directly and is just there to keep the object
37 // alive, which itself is refcounted in a thread-safe manner.
38 void GiveSurface(sk_sp
<SkSurface
>& aSurface
) {
40 mDrawTarget
= nullptr;
43 sk_sp
<SkImage
> GetImage();
45 bool InitFromData(unsigned char* aData
, const IntSize
& aSize
, int32_t aStride
,
46 SurfaceFormat aFormat
);
48 bool InitFromImage(const sk_sp
<SkImage
>& aImage
,
49 SurfaceFormat aFormat
= SurfaceFormat::UNKNOWN
,
50 DrawTargetSkia
* aOwner
= nullptr);
52 uint8_t* GetData() override
;
55 * The caller is responsible for ensuring aMappedSurface is not null.
57 bool Map(MapType
, MappedSurface
* aMappedSurface
) override
;
59 void Unmap() override
;
61 int32_t Stride() override
{ return mStride
; }
64 friend class DrawTargetSkia
;
66 void DrawTargetWillChange();
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
;
74 DrawTargetSkia
* mDrawTarget
;
80 } // namespace mozilla
82 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */