michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxReusableImageSurfaceWrapper.h" michael@0: #include "gfxImageSurface.h" michael@0: michael@0: gfxReusableImageSurfaceWrapper::gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface) michael@0: : mSurface(aSurface) michael@0: { michael@0: MOZ_COUNT_CTOR(gfxReusableImageSurfaceWrapper); michael@0: } michael@0: michael@0: gfxReusableImageSurfaceWrapper::~gfxReusableImageSurfaceWrapper() michael@0: { michael@0: MOZ_COUNT_DTOR(gfxReusableImageSurfaceWrapper); michael@0: } michael@0: michael@0: void michael@0: gfxReusableImageSurfaceWrapper::ReadLock() michael@0: { michael@0: NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper); michael@0: AddRef(); michael@0: } michael@0: michael@0: void michael@0: gfxReusableImageSurfaceWrapper::ReadUnlock() michael@0: { michael@0: Release(); michael@0: } michael@0: michael@0: gfxReusableSurfaceWrapper* michael@0: gfxReusableImageSurfaceWrapper::GetWritable(gfxImageSurface** aSurface) michael@0: { michael@0: NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper); michael@0: michael@0: if (mRefCnt == 1) { michael@0: *aSurface = mSurface; michael@0: return this; michael@0: } michael@0: michael@0: // Something else is reading the surface, copy it michael@0: gfxImageSurface* copySurface = new gfxImageSurface(mSurface->GetSize(), mSurface->Format(), false); michael@0: copySurface->CopyFrom(mSurface); michael@0: *aSurface = copySurface; michael@0: michael@0: return new gfxReusableImageSurfaceWrapper(copySurface); michael@0: } michael@0: michael@0: const unsigned char* michael@0: gfxReusableImageSurfaceWrapper::GetReadOnlyData() const michael@0: { michael@0: return mSurface->Data(); michael@0: } michael@0: michael@0: gfxImageFormat michael@0: gfxReusableImageSurfaceWrapper::Format() michael@0: { michael@0: return mSurface->Format(); michael@0: } michael@0: