1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "TextureDIB.h"
15 DIBTextureClient::DIBTextureClient(gfx::SurfaceFormat aFormat
, TextureFlags aFlags
)
16 : TextureClient(aFlags
)
20 MOZ_COUNT_CTOR(DIBTextureClient
);
23 DIBTextureClient::~DIBTextureClient()
25 MOZ_COUNT_DTOR(DIBTextureClient
);
28 TemporaryRef
<TextureClient
>
29 DIBTextureClient::CreateSimilar(TextureFlags aFlags
,
30 TextureAllocationFlags aAllocFlags
) const
32 RefPtr
<TextureClient
> tex
= new DIBTextureClient(mFormat
, mFlags
| aFlags
);
34 if (!tex
->AllocateForSurface(mSize
, aAllocFlags
)) {
42 DIBTextureClient::Lock(OpenMode
)
44 MOZ_ASSERT(!mIsLocked
);
53 DIBTextureClient::Unlock()
55 MOZ_ASSERT(mIsLocked
, "Unlocked called while the texture is not locked!");
58 RefPtr
<SourceSurface
> snapshot
= mDrawTarget
->Snapshot();
59 RefPtr
<DataSourceSurface
> dataSurf
= snapshot
->GetDataSurface();
60 mReadbackSink
->ProcessReadback(dataSurf
);
64 mDrawTarget
= nullptr;
71 DIBTextureClient::ToSurfaceDescriptor(SurfaceDescriptor
& aOutDescriptor
)
73 MOZ_ASSERT(IsValid());
78 // The host will release this ref when it receives the surface descriptor.
79 // We AddRef in case we die before the host receives the pointer.
80 aOutDescriptor
= SurfaceDescriptorDIB(reinterpret_cast<uintptr_t>(mSurface
.get()));
86 DIBTextureClient::BorrowDrawTarget()
88 MOZ_ASSERT(mIsLocked
&& IsAllocated());
92 gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mSurface
, mSize
);
99 DIBTextureClient::AllocateForSurface(gfx::IntSize aSize
, TextureAllocationFlags aFlags
)
101 MOZ_ASSERT(!IsAllocated());
104 mSurface
= new gfxWindowsSurface(gfxIntSize(aSize
.width
, aSize
.height
),
105 SurfaceFormatToImageFormat(mFormat
));
106 if (!mSurface
|| mSurface
->CairoStatus())
108 NS_WARNING("Could not create surface");
116 DIBTextureHost::DIBTextureHost(TextureFlags aFlags
,
117 const SurfaceDescriptorDIB
& aDescriptor
)
118 : TextureHost(aFlags
)
121 // We added an extra ref for transport, so we shouldn't AddRef now.
123 dont_AddRef(reinterpret_cast<gfxWindowsSurface
*>(aDescriptor
.surface()));
124 MOZ_ASSERT(mSurface
);
126 mSize
= ToIntSize(mSurface
->GetSize());
127 mFormat
= ImageFormatToSurfaceFormat(
128 gfxPlatform::GetPlatform()->OptimalFormatForContent(mSurface
->GetContentType()));
132 DIBTextureHost::GetTextureSources()
134 if (!mTextureSource
) {
138 return mTextureSource
;
142 DIBTextureHost::Updated(const nsIntRegion
* aRegion
)
144 if (!mTextureSource
) {
145 mTextureSource
= mCompositor
->CreateDataTextureSource(mFlags
);
148 nsRefPtr
<gfxImageSurface
> imgSurf
= mSurface
->GetAsImageSurface();
150 RefPtr
<DataSourceSurface
> surf
= Factory::CreateWrappingDataSourceSurface(imgSurf
->Data(), imgSurf
->Stride(), mSize
, mFormat
);
152 if (!mTextureSource
->Update(surf
, const_cast<nsIntRegion
*>(aRegion
))) {
153 mTextureSource
= nullptr;
158 DIBTextureHost::Lock()
160 MOZ_ASSERT(!mIsLocked
);
166 DIBTextureHost::Unlock()
168 MOZ_ASSERT(mIsLocked
);
173 DIBTextureHost::SetCompositor(Compositor
* aCompositor
)
175 mCompositor
= aCompositor
;
179 DIBTextureHost::DeallocateDeviceData()
181 if (mTextureSource
) {
182 mTextureSource
->DeallocateDeviceData();