1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxReusableImageSurfaceWrapper.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "gfxReusableImageSurfaceWrapper.h" 1.9 +#include "gfxImageSurface.h" 1.10 + 1.11 +gfxReusableImageSurfaceWrapper::gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface) 1.12 + : mSurface(aSurface) 1.13 +{ 1.14 + MOZ_COUNT_CTOR(gfxReusableImageSurfaceWrapper); 1.15 +} 1.16 + 1.17 +gfxReusableImageSurfaceWrapper::~gfxReusableImageSurfaceWrapper() 1.18 +{ 1.19 + MOZ_COUNT_DTOR(gfxReusableImageSurfaceWrapper); 1.20 +} 1.21 + 1.22 +void 1.23 +gfxReusableImageSurfaceWrapper::ReadLock() 1.24 +{ 1.25 + NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper); 1.26 + AddRef(); 1.27 +} 1.28 + 1.29 +void 1.30 +gfxReusableImageSurfaceWrapper::ReadUnlock() 1.31 +{ 1.32 + Release(); 1.33 +} 1.34 + 1.35 +gfxReusableSurfaceWrapper* 1.36 +gfxReusableImageSurfaceWrapper::GetWritable(gfxImageSurface** aSurface) 1.37 +{ 1.38 + NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper); 1.39 + 1.40 + if (mRefCnt == 1) { 1.41 + *aSurface = mSurface; 1.42 + return this; 1.43 + } 1.44 + 1.45 + // Something else is reading the surface, copy it 1.46 + gfxImageSurface* copySurface = new gfxImageSurface(mSurface->GetSize(), mSurface->Format(), false); 1.47 + copySurface->CopyFrom(mSurface); 1.48 + *aSurface = copySurface; 1.49 + 1.50 + return new gfxReusableImageSurfaceWrapper(copySurface); 1.51 +} 1.52 + 1.53 +const unsigned char* 1.54 +gfxReusableImageSurfaceWrapper::GetReadOnlyData() const 1.55 +{ 1.56 + return mSurface->Data(); 1.57 +} 1.58 + 1.59 +gfxImageFormat 1.60 +gfxReusableImageSurfaceWrapper::Format() 1.61 +{ 1.62 + return mSurface->Format(); 1.63 +} 1.64 +