2017-01-06 21:10:15 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; 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 "RendererOGL.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
2017-01-11 15:49:02 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2017-03-31 17:29:15 +03:00
|
|
|
#include "mozilla/webrender/RenderBufferTextureHost.h"
|
|
|
|
#include "mozilla/webrender/RenderTextureHostOGL.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-01-17 03:22:09 +03:00
|
|
|
namespace wr {
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2017-04-28 09:16:26 +03:00
|
|
|
WrExternalImage LockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex)
|
2017-03-01 12:08:56 +03:00
|
|
|
{
|
2017-03-07 13:37:28 +03:00
|
|
|
RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
|
2017-04-11 00:38:02 +03:00
|
|
|
RenderTextureHost* texture = renderer->GetRenderTexture(aId);
|
2017-03-31 17:29:14 +03:00
|
|
|
|
2017-03-31 17:29:15 +03:00
|
|
|
if (texture->AsBufferTextureHost()) {
|
|
|
|
RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
|
|
|
|
MOZ_ASSERT(bufferTexture);
|
|
|
|
bufferTexture->Lock();
|
2017-05-18 17:59:07 +03:00
|
|
|
RenderBufferTextureHost::RenderBufferData data =
|
|
|
|
bufferTexture->GetBufferDataForRender(aChannelIndex);
|
2017-03-31 17:29:15 +03:00
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
return RawDataToWrExternalImage(data.mData, data.mBufferSize);
|
2017-03-31 17:29:15 +03:00
|
|
|
} else {
|
|
|
|
// texture handle case
|
|
|
|
RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL();
|
|
|
|
MOZ_ASSERT(textureOGL);
|
2017-05-18 17:59:07 +03:00
|
|
|
|
2017-03-31 17:29:15 +03:00
|
|
|
textureOGL->SetGLContext(renderer->mGL);
|
|
|
|
textureOGL->Lock();
|
2017-05-18 17:59:07 +03:00
|
|
|
gfx::IntSize size = textureOGL->GetSize(aChannelIndex);
|
2017-03-31 17:29:15 +03:00
|
|
|
|
2017-05-18 17:59:07 +03:00
|
|
|
return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(aChannelIndex),
|
2017-03-31 17:29:15 +03:00
|
|
|
0, 0,
|
|
|
|
size.width, size.height);
|
|
|
|
}
|
2017-03-01 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:16:26 +03:00
|
|
|
void UnlockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex)
|
2017-03-01 12:08:56 +03:00
|
|
|
{
|
2017-03-07 13:37:28 +03:00
|
|
|
RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
|
2017-04-11 00:38:02 +03:00
|
|
|
RenderTextureHost* texture = renderer->GetRenderTexture(aId);
|
2017-03-07 13:37:28 +03:00
|
|
|
MOZ_ASSERT(texture);
|
|
|
|
texture->Unlock();
|
2017-03-01 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 15:51:27 +03:00
|
|
|
RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
|
|
|
|
RefPtr<gl::GLContext>&& aGL,
|
|
|
|
RefPtr<widget::CompositorWidget>&& aWidget,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::WindowId aWindowId,
|
2017-01-06 21:10:15 +03:00
|
|
|
WrRenderer* aWrRenderer,
|
2017-01-17 03:22:09 +03:00
|
|
|
layers::CompositorBridgeParentBase* aBridge)
|
2017-01-25 00:06:17 +03:00
|
|
|
: mThread(aThread)
|
|
|
|
, mGL(aGL)
|
|
|
|
, mWidget(aWidget)
|
|
|
|
, mWrRenderer(aWrRenderer)
|
|
|
|
, mBridge(aBridge)
|
|
|
|
, mWindowId(aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-10 12:17:30 +03:00
|
|
|
MOZ_ASSERT(mThread);
|
|
|
|
MOZ_ASSERT(mGL);
|
|
|
|
MOZ_ASSERT(mWidget);
|
|
|
|
MOZ_ASSERT(mWrRenderer);
|
|
|
|
MOZ_ASSERT(mBridge);
|
|
|
|
MOZ_COUNT_CTOR(RendererOGL);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RendererOGL::~RendererOGL()
|
|
|
|
{
|
2017-01-10 12:17:30 +03:00
|
|
|
MOZ_COUNT_DTOR(RendererOGL);
|
2017-04-25 18:39:33 +03:00
|
|
|
if (!mGL->MakeCurrent()) {
|
|
|
|
gfxCriticalNote << "Failed to make render context current during destroying.";
|
|
|
|
// Leak resources!
|
|
|
|
return;
|
|
|
|
}
|
2017-01-10 12:17:30 +03:00
|
|
|
wr_renderer_delete(mWrRenderer);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-03-01 12:08:56 +03:00
|
|
|
WrExternalImageHandler
|
|
|
|
RendererOGL::GetExternalImageHandler()
|
|
|
|
{
|
|
|
|
return WrExternalImageHandler {
|
|
|
|
this,
|
|
|
|
LockExternalImage,
|
|
|
|
UnlockExternalImage,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
void
|
|
|
|
RendererOGL::Update()
|
|
|
|
{
|
|
|
|
wr_renderer_update(mWrRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-27 23:30:18 +03:00
|
|
|
RendererOGL::Render()
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
|
|
|
if (!mGL->MakeCurrent()) {
|
|
|
|
gfxCriticalNote << "Failed to make render context current, can't draw.";
|
2017-07-04 13:25:24 +03:00
|
|
|
// XXX This could cause oom in webrender since pending_texture_updates is not handled.
|
|
|
|
// It needs to be addressed.
|
2017-01-06 21:10:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::widget::WidgetRenderingContext widgetContext;
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
widgetContext.mGL = mGL;
|
|
|
|
// TODO: we don't have a notion of compositor here.
|
|
|
|
//#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// widgetContext.mCompositor = mCompositor;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!mWidget->PreRender(&widgetContext)) {
|
2017-07-04 13:25:24 +03:00
|
|
|
// XXX This could cause oom in webrender since pending_texture_updates is not handled.
|
|
|
|
// It needs to be addressed.
|
2017-01-06 21:10:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.
|
|
|
|
|
|
|
|
auto size = mWidget->GetClientSize();
|
|
|
|
wr_renderer_render(mWrRenderer, size.width, size.height);
|
|
|
|
|
|
|
|
mGL->SwapBuffers();
|
|
|
|
mWidget->PostRender(&widgetContext);
|
|
|
|
|
2017-02-10 18:16:47 +03:00
|
|
|
// TODO: Flush pending actions such as texture deletions/unlocks and
|
|
|
|
// textureHosts recycling.
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-05 17:12:11 +03:00
|
|
|
void
|
|
|
|
RendererOGL::Pause()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if (!mGL || mGL->IsDestroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ReleaseSurface internally calls MakeCurrent.
|
|
|
|
mGL->ReleaseSurface();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RendererOGL::Resume()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
if (!mGL || mGL->IsDestroyed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// RenewSurface internally calls MakeCurrent.
|
|
|
|
return mGL->RenewSurface(mWidget);
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-16 17:22:47 +03:00
|
|
|
void
|
|
|
|
RendererOGL::SetProfilerEnabled(bool aEnabled)
|
|
|
|
{
|
|
|
|
wr_renderer_set_profiler_enabled(mWrRenderer, aEnabled);
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:30:18 +03:00
|
|
|
WrRenderedEpochs*
|
|
|
|
RendererOGL::FlushRenderedEpochs()
|
|
|
|
{
|
|
|
|
return wr_renderer_flush_rendered_epochs(mWrRenderer);
|
|
|
|
}
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
RenderTextureHost*
|
2017-04-13 22:31:09 +03:00
|
|
|
RendererOGL::GetRenderTexture(WrExternalImageId aExternalImageId)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
|
|
|
return mThread->GetRenderTexture(aExternalImageId);
|
|
|
|
}
|
|
|
|
|
2017-01-25 00:06:17 +03:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|