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_
11 #include "mozilla/Mutex.h"
12 #include "skia/include/core/SkRefCnt.h"
24 class SourceSurfaceSkia
: public DataSourceSurface
{
26 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceSkia
, override
)
29 virtual ~SourceSurfaceSkia();
31 SurfaceType
GetType() const override
{ return SurfaceType::SKIA
; }
32 IntSize
GetSize() const override
;
33 SurfaceFormat
GetFormat() const override
;
35 void GiveSurface(SkSurface
* aSurface
);
37 sk_sp
<SkImage
> GetImage(Maybe
<MutexAutoLock
>* aLock
);
39 bool InitFromData(unsigned char* aData
, const IntSize
& aSize
, int32_t aStride
,
40 SurfaceFormat aFormat
);
42 bool InitFromImage(const sk_sp
<SkImage
>& aImage
,
43 SurfaceFormat aFormat
= SurfaceFormat::UNKNOWN
,
44 DrawTargetSkia
* aOwner
= nullptr);
46 already_AddRefed
<SourceSurface
> ExtractSubrect(const IntRect
& aRect
) override
;
48 uint8_t* GetData() override
;
51 * The caller is responsible for ensuring aMappedSurface is not null.
53 bool Map(MapType
, MappedSurface
* aMappedSurface
) override
;
55 void Unmap() override
;
57 int32_t Stride() override
{ return mStride
; }
60 friend class DrawTargetSkia
;
62 void DrawTargetWillChange();
64 sk_sp
<SkImage
> mImage
;
65 // This keeps a surface alive if needed because its DrawTarget has gone away.
66 sk_sp
<SkSurface
> mSurface
;
67 SurfaceFormat mFormat
;
70 Atomic
<DrawTargetSkia
*> mDrawTarget
;
71 Mutex mChangeMutex MOZ_UNANNOTATED
;
76 } // namespace mozilla
78 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */