2017-03-07 13:37:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebRenderTextureHost.h"
|
|
|
|
|
2017-03-09 05:10:09 +03:00
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2017-03-31 17:29:14 +03:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
2017-03-31 17:29:14 +03:00
|
|
|
#include "mozilla/webrender/RenderBufferTextureHost.h"
|
2017-03-31 17:29:14 +03:00
|
|
|
#include "mozilla/webrender/RenderTextureHost.h"
|
2017-03-07 13:37:28 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
|
|
|
|
#include "mozilla/webrender/RenderMacIOSurfaceTextureHostOGL.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
WebRenderTextureHost::WebRenderTextureHost(const SurfaceDescriptor& aDesc,
|
|
|
|
TextureFlags aFlags,
|
2017-04-20 04:24:13 +03:00
|
|
|
TextureHost* aTexture,
|
|
|
|
wr::ExternalImageId& aExternalImageId)
|
2017-03-07 13:37:28 +03:00
|
|
|
: TextureHost(aFlags)
|
2017-04-20 04:24:13 +03:00
|
|
|
, mExternalImageId(aExternalImageId)
|
2017-03-31 17:29:14 +03:00
|
|
|
, mIsWrappingNativeHandle(false)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(WebRenderTextureHost);
|
|
|
|
mWrappedTextureHost = aTexture;
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
CreateRenderTextureHost(aDesc, aTexture);
|
2017-03-07 13:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderTextureHost::~WebRenderTextureHost()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(WebRenderTextureHost);
|
2017-04-19 12:59:53 +03:00
|
|
|
wr::RenderThread::Get()->UnregisterExternalImage(wr::AsUint64(mExternalImageId));
|
2017-03-07 13:37:28 +03:00
|
|
|
}
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
void
|
|
|
|
WebRenderTextureHost::CreateRenderTextureHost(const layers::SurfaceDescriptor& aDesc,
|
|
|
|
TextureHost* aTexture)
|
|
|
|
{
|
|
|
|
RefPtr<wr::RenderTextureHost> texture;
|
|
|
|
|
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorBuffer: {
|
|
|
|
BufferTextureHost* bufferTexture = aTexture->AsBufferTextureHost();
|
|
|
|
MOZ_ASSERT(bufferTexture);
|
|
|
|
texture = new wr::RenderBufferTextureHost(bufferTexture->GetBuffer(),
|
|
|
|
bufferTexture->GetBufferDescriptor());
|
|
|
|
mIsWrappingNativeHandle = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
|
|
|
|
MacIOSurfaceTextureHostOGL* macTexture = aTexture->AsMacIOSurfaceTextureHost();
|
|
|
|
MOZ_ASSERT(macTexture);
|
|
|
|
texture = new wr::RenderMacIOSurfaceTextureHostOGL(macTexture->GetMacIOSurface());
|
|
|
|
mIsWrappingNativeHandle = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
gfxCriticalError() << "No WR implement for texture type:" << aDesc.type();
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:59:53 +03:00
|
|
|
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(mExternalImageId), texture);
|
2017-03-31 17:29:14 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
bool
|
|
|
|
WebRenderTextureHost::Lock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderTextureHost::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebRenderTextureHost::BindTextureSource(CompositableTextureSourceRef& aTexture)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfx::DataSourceSurface>
|
|
|
|
WebRenderTextureHost::GetAsSurface()
|
|
|
|
{
|
|
|
|
if (!mWrappedTextureHost) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mWrappedTextureHost->GetAsSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-22 06:32:54 +03:00
|
|
|
WebRenderTextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
YUVColorSpace
|
|
|
|
WebRenderTextureHost::GetYUVColorSpace() const
|
|
|
|
{
|
|
|
|
if (mWrappedTextureHost) {
|
|
|
|
return mWrappedTextureHost->GetYUVColorSpace();
|
|
|
|
}
|
|
|
|
return YUVColorSpace::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
WebRenderTextureHost::GetSize() const
|
|
|
|
{
|
|
|
|
if (!mWrappedTextureHost) {
|
|
|
|
return gfx::IntSize();
|
|
|
|
}
|
|
|
|
return mWrappedTextureHost->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
WebRenderTextureHost::GetFormat() const
|
|
|
|
{
|
|
|
|
if (!mWrappedTextureHost) {
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
}
|
|
|
|
return mWrappedTextureHost->GetFormat();
|
|
|
|
}
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
gfx::SurfaceFormat
|
|
|
|
WebRenderTextureHost::GetReadFormat() const
|
|
|
|
{
|
|
|
|
if (!mWrappedTextureHost) {
|
|
|
|
return gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
}
|
|
|
|
return mWrappedTextureHost->GetReadFormat();
|
|
|
|
}
|
|
|
|
|
2017-03-09 05:10:09 +03:00
|
|
|
int32_t
|
|
|
|
WebRenderTextureHost::GetRGBStride()
|
|
|
|
{
|
|
|
|
if (!mWrappedTextureHost) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
gfx::SurfaceFormat format = GetFormat();
|
2017-03-31 17:29:14 +03:00
|
|
|
if (GetFormat() == gfx::SurfaceFormat::YUV) {
|
2017-03-09 05:10:09 +03:00
|
|
|
// XXX this stride is used until yuv image rendering by webrender is used.
|
|
|
|
// Software converted RGB buffers strides are aliened to 16
|
2017-03-31 17:29:14 +03:00
|
|
|
return gfx::GetAlignedStride<16>(GetSize().width, BytesPerPixel(gfx::SurfaceFormat::B8G8R8A8));
|
2017-03-09 05:10:09 +03:00
|
|
|
}
|
|
|
|
return ImageDataSerializer::ComputeRGBStride(format, GetSize().width);
|
|
|
|
}
|
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
void
|
|
|
|
WebRenderTextureHost::AddWRImage(wr::WebRenderAPI* aAPI,
|
2017-05-18 19:25:41 +03:00
|
|
|
Range<const wr::ImageKey>& aImageKeys,
|
2017-05-18 17:59:07 +03:00
|
|
|
const wr::ExternalImageId& aExtID)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mWrappedTextureHost);
|
|
|
|
MOZ_ASSERT(mExternalImageId == aExtID);
|
|
|
|
|
2017-05-18 19:25:41 +03:00
|
|
|
mWrappedTextureHost->AddWRImage(aAPI, aImageKeys, aExtID);
|
2017-05-18 17:59:07 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|