2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-01-06 21:10:15 +03:00
|
|
|
/* 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 "mozilla/gfx/Logging.h"
|
2017-08-23 13:00:37 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.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-08-11 04:57:21 +03:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2018-01-15 16:22:15 +03:00
|
|
|
#include "mozilla/webrender/RenderCompositor.h"
|
|
|
|
#include "mozilla/webrender/RenderTextureHost.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-06-28 02:20:36 +03:00
|
|
|
wr::WrExternalImage LockExternalImage(void* aObj, wr::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-10-30 20:10:29 +03:00
|
|
|
MOZ_ASSERT(texture);
|
2018-01-11 15:20:53 +03:00
|
|
|
if (!texture) {
|
|
|
|
gfxCriticalNote << "Failed to lock ExternalImage for extId:" << AsUint64(aId);
|
|
|
|
return InvalidToWrExternalImage();
|
|
|
|
}
|
2018-01-15 16:22:15 +03:00
|
|
|
return texture->Lock(aChannelIndex, renderer->gl());
|
2017-03-01 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 02:20:36 +03:00
|
|
|
void UnlockExternalImage(void* aObj, wr::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);
|
2018-01-11 15:20:53 +03:00
|
|
|
if (!texture) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-07 13:37:28 +03:00
|
|
|
texture->Unlock();
|
2017-03-01 12:08:56 +03:00
|
|
|
}
|
|
|
|
|
2017-01-11 15:51:27 +03:00
|
|
|
RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
|
2018-01-15 16:22:15 +03:00
|
|
|
UniquePtr<RenderCompositor> aCompositor,
|
2017-01-17 03:22:09 +03:00
|
|
|
wr::WindowId aWindowId,
|
2017-07-19 10:28:58 +03:00
|
|
|
wr::Renderer* aRenderer,
|
2017-01-17 03:22:09 +03:00
|
|
|
layers::CompositorBridgeParentBase* aBridge)
|
2017-01-25 00:06:17 +03:00
|
|
|
: mThread(aThread)
|
2018-01-15 16:22:15 +03:00
|
|
|
, mCompositor(Move(aCompositor))
|
2017-07-19 10:28:58 +03:00
|
|
|
, mRenderer(aRenderer)
|
2017-01-25 00:06:17 +03:00
|
|
|
, mBridge(aBridge)
|
|
|
|
, mWindowId(aWindowId)
|
2017-08-23 13:00:37 +03:00
|
|
|
, mDebugFlags({ 0 })
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-10 12:17:30 +03:00
|
|
|
MOZ_ASSERT(mThread);
|
2018-01-15 16:22:15 +03:00
|
|
|
MOZ_ASSERT(mCompositor);
|
2017-07-19 10:28:58 +03:00
|
|
|
MOZ_ASSERT(mRenderer);
|
2017-01-10 12:17:30 +03:00
|
|
|
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);
|
2018-01-15 16:22:15 +03:00
|
|
|
if (!mCompositor->gl()->MakeCurrent()) {
|
2017-04-25 18:39:33 +03:00
|
|
|
gfxCriticalNote << "Failed to make render context current during destroying.";
|
|
|
|
// Leak resources!
|
|
|
|
return;
|
|
|
|
}
|
2017-07-19 10:28:58 +03:00
|
|
|
wr_renderer_delete(mRenderer);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 02:20:36 +03:00
|
|
|
wr::WrExternalImageHandler
|
2017-03-01 12:08:56 +03:00
|
|
|
RendererOGL::GetExternalImageHandler()
|
|
|
|
{
|
2017-06-28 02:20:36 +03:00
|
|
|
return wr::WrExternalImageHandler {
|
2017-03-01 12:08:56 +03:00
|
|
|
this,
|
|
|
|
LockExternalImage,
|
|
|
|
UnlockExternalImage,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
bool
|
2018-02-01 05:34:43 +03:00
|
|
|
RendererOGL::UpdateAndRender()
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-08-23 13:00:37 +03:00
|
|
|
uint32_t flags = gfx::gfxVars::WebRenderDebugFlags();
|
|
|
|
|
|
|
|
if (mDebugFlags.mBits != flags) {
|
|
|
|
mDebugFlags.mBits = flags;
|
|
|
|
wr_renderer_set_debug_flags(mRenderer, mDebugFlags);
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
mozilla::widget::WidgetRenderingContext widgetContext;
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX)
|
2018-01-15 16:22:15 +03:00
|
|
|
widgetContext.mGL = mCompositor->gl();
|
2017-01-06 21:10:15 +03:00
|
|
|
// TODO: we don't have a notion of compositor here.
|
|
|
|
//#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// widgetContext.mCompositor = mCompositor;
|
|
|
|
#endif
|
|
|
|
|
2018-01-15 16:22:15 +03:00
|
|
|
if (!mCompositor->GetWidget()->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.
|
|
|
|
|
2018-01-15 16:22:15 +03:00
|
|
|
if (!mCompositor->BeginFrame()) {
|
|
|
|
return false;
|
2017-08-07 13:15:25 +03:00
|
|
|
}
|
|
|
|
|
2018-02-01 05:34:43 +03:00
|
|
|
wr_renderer_update(mRenderer);
|
|
|
|
|
2018-02-01 15:39:31 +03:00
|
|
|
auto size = mCompositor->GetBufferSize();
|
2018-01-15 16:22:15 +03:00
|
|
|
|
2017-09-01 16:39:28 +03:00
|
|
|
if (!wr_renderer_render(mRenderer, size.width, size.height)) {
|
|
|
|
NotifyWebRenderError(WebRenderError::RENDER);
|
|
|
|
}
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2018-01-15 16:22:15 +03:00
|
|
|
mCompositor->EndFrame();
|
|
|
|
|
|
|
|
mCompositor->GetWidget()->PostRender(&widgetContext);
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2017-07-28 02:05:56 +03:00
|
|
|
#if defined(ENABLE_FRAME_LATENCY_LOG)
|
|
|
|
if (mFrameStartTime) {
|
|
|
|
uint32_t latencyMs = round((TimeStamp::Now() - mFrameStartTime).ToMilliseconds());
|
|
|
|
printf_stderr("generate frame latencyMs latencyMs %d\n", latencyMs);
|
|
|
|
}
|
|
|
|
// Clear frame start time
|
|
|
|
mFrameStartTime = TimeStamp();
|
|
|
|
#endif
|
|
|
|
|
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()
|
|
|
|
{
|
2018-01-15 16:22:15 +03:00
|
|
|
mCompositor->Pause();
|
2017-04-05 17:12:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RendererOGL::Resume()
|
|
|
|
{
|
2018-01-15 16:22:15 +03:00
|
|
|
return mCompositor->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
layers::SyncObjectHost*
|
|
|
|
RendererOGL::GetSyncObject() const
|
|
|
|
{
|
|
|
|
return mCompositor->GetSyncObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
gl::GLContext*
|
|
|
|
RendererOGL::gl() const
|
|
|
|
{
|
|
|
|
return mCompositor->gl();
|
2017-04-05 17:12:11 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 02:05:56 +03:00
|
|
|
void
|
|
|
|
RendererOGL::SetFrameStartTime(const TimeStamp& aTime)
|
|
|
|
{
|
|
|
|
if (mFrameStartTime) {
|
|
|
|
// frame start time is already set. This could happen when multiple
|
|
|
|
// generate frame requests are merged by webrender.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mFrameStartTime = aTime;
|
|
|
|
}
|
|
|
|
|
2017-06-28 02:20:36 +03:00
|
|
|
wr::WrRenderedEpochs*
|
2017-01-27 23:30:18 +03:00
|
|
|
RendererOGL::FlushRenderedEpochs()
|
|
|
|
{
|
2017-07-19 10:28:58 +03:00
|
|
|
return wr_renderer_flush_rendered_epochs(mRenderer);
|
2017-01-27 23:30:18 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
RenderTextureHost*
|
2017-06-28 02:20:36 +03:00
|
|
|
RendererOGL::GetRenderTexture(wr::WrExternalImageId aExternalImageId)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
|
|
|
return mThread->GetRenderTexture(aExternalImageId);
|
|
|
|
}
|
|
|
|
|
2017-08-30 03:10:22 +03:00
|
|
|
static void
|
|
|
|
DoNotifyWebRenderError(layers::CompositorBridgeParentBase* aBridge, WebRenderError aError)
|
|
|
|
{
|
|
|
|
aBridge->NotifyWebRenderError(aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RendererOGL::NotifyWebRenderError(WebRenderError aError)
|
|
|
|
{
|
|
|
|
layers::CompositorThreadHolder::Loop()->PostTask(NewRunnableFunction(
|
2017-10-27 23:39:28 +03:00
|
|
|
"DoNotifyWebRenderErrorRunnable",
|
2017-08-30 03:10:22 +03:00
|
|
|
&DoNotifyWebRenderError,
|
|
|
|
mBridge,
|
|
|
|
aError
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-01-25 00:06:17 +03:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|