gfx/thebes/gfxReusableImageSurfaceWrapper.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:503778de5ff5
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/. */
4
5 #include "gfxReusableImageSurfaceWrapper.h"
6 #include "gfxImageSurface.h"
7
8 gfxReusableImageSurfaceWrapper::gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface)
9 : mSurface(aSurface)
10 {
11 MOZ_COUNT_CTOR(gfxReusableImageSurfaceWrapper);
12 }
13
14 gfxReusableImageSurfaceWrapper::~gfxReusableImageSurfaceWrapper()
15 {
16 MOZ_COUNT_DTOR(gfxReusableImageSurfaceWrapper);
17 }
18
19 void
20 gfxReusableImageSurfaceWrapper::ReadLock()
21 {
22 NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
23 AddRef();
24 }
25
26 void
27 gfxReusableImageSurfaceWrapper::ReadUnlock()
28 {
29 Release();
30 }
31
32 gfxReusableSurfaceWrapper*
33 gfxReusableImageSurfaceWrapper::GetWritable(gfxImageSurface** aSurface)
34 {
35 NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
36
37 if (mRefCnt == 1) {
38 *aSurface = mSurface;
39 return this;
40 }
41
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;
46
47 return new gfxReusableImageSurfaceWrapper(copySurface);
48 }
49
50 const unsigned char*
51 gfxReusableImageSurfaceWrapper::GetReadOnlyData() const
52 {
53 return mSurface->Data();
54 }
55
56 gfxImageFormat
57 gfxReusableImageSurfaceWrapper::Format()
58 {
59 return mSurface->Format();
60 }
61

mercurial