Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "gfxReusableImageSurfaceWrapper.h"
6 #include "gfxImageSurface.h"
8 gfxReusableImageSurfaceWrapper::gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface)
9 : mSurface(aSurface)
10 {
11 MOZ_COUNT_CTOR(gfxReusableImageSurfaceWrapper);
12 }
14 gfxReusableImageSurfaceWrapper::~gfxReusableImageSurfaceWrapper()
15 {
16 MOZ_COUNT_DTOR(gfxReusableImageSurfaceWrapper);
17 }
19 void
20 gfxReusableImageSurfaceWrapper::ReadLock()
21 {
22 NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
23 AddRef();
24 }
26 void
27 gfxReusableImageSurfaceWrapper::ReadUnlock()
28 {
29 Release();
30 }
32 gfxReusableSurfaceWrapper*
33 gfxReusableImageSurfaceWrapper::GetWritable(gfxImageSurface** aSurface)
34 {
35 NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
37 if (mRefCnt == 1) {
38 *aSurface = mSurface;
39 return this;
40 }
42 // Something else is reading the surface, copy it
43 gfxImageSurface* copySurface = new gfxImageSurface(mSurface->GetSize(), mSurface->Format(), false);
44 copySurface->CopyFrom(mSurface);
45 *aSurface = copySurface;
47 return new gfxReusableImageSurfaceWrapper(copySurface);
48 }
50 const unsigned char*
51 gfxReusableImageSurfaceWrapper::GetReadOnlyData() const
52 {
53 return mSurface->Data();
54 }
56 gfxImageFormat
57 gfxReusableImageSurfaceWrapper::Format()
58 {
59 return mSurface->Format();
60 }