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/. */
|
|
|
|
|
2017-06-09 06:56:13 +03:00
|
|
|
#include "base/task.h"
|
|
|
|
#include "GeckoProfiler.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
#include "RenderThread.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2017-07-03 15:08:22 +03:00
|
|
|
#include "mtransport/runnable_utils.h"
|
2018-05-28 18:29:41 +03:00
|
|
|
#include "mozilla/layers/AsyncImagePipelineManager.h"
|
2018-06-13 18:01:06 +03:00
|
|
|
#include "mozilla/gfx/GPUParent.h"
|
2017-01-27 23:30:18 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2018-04-23 14:57:17 +03:00
|
|
|
#include "mozilla/layers/SharedSurfacesParent.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2018-06-25 17:55:26 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-03-07 13:37:28 +03:00
|
|
|
#include "mozilla/webrender/RendererOGL.h"
|
2017-03-31 17:29:14 +03:00
|
|
|
#include "mozilla/webrender/RenderTextureHost.h"
|
2017-03-07 13:37:28 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2018-03-29 05:21:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/widget/WinCompositorWindowThread.h"
|
|
|
|
#endif
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
namespace mozilla {
|
2017-01-17 03:22:09 +03:00
|
|
|
namespace wr {
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
static StaticRefPtr<RenderThread> sRenderThread;
|
|
|
|
|
|
|
|
RenderThread::RenderThread(base::Thread* aThread)
|
2017-01-25 00:06:17 +03:00
|
|
|
: mThread(aThread)
|
2017-11-03 05:22:28 +03:00
|
|
|
, mFrameCountMapLock("RenderThread.mFrameCountMapLock")
|
2017-03-07 13:37:28 +03:00
|
|
|
, mRenderTextureMapLock("RenderThread.mRenderTextureMapLock")
|
2017-07-03 15:08:22 +03:00
|
|
|
, mHasShutdown(false)
|
2018-06-13 18:01:06 +03:00
|
|
|
, mHandlingDeviceReset(false)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderThread::~RenderThread()
|
|
|
|
{
|
2018-06-15 01:18:48 +03:00
|
|
|
MOZ_ASSERT(mRenderTexturesDeferred.empty());
|
2017-01-06 21:10:15 +03:00
|
|
|
delete mThread;
|
|
|
|
}
|
|
|
|
|
2017-01-17 03:22:09 +03:00
|
|
|
// static
|
2017-01-06 21:10:15 +03:00
|
|
|
RenderThread*
|
|
|
|
RenderThread::Get()
|
|
|
|
{
|
|
|
|
return sRenderThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
RenderThread::Start()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!sRenderThread);
|
|
|
|
|
2017-01-11 15:51:27 +03:00
|
|
|
base::Thread* thread = new base::Thread("Renderer");
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
base::Thread::Options options;
|
|
|
|
// TODO(nical): The compositor thread has a bunch of specific options, see
|
|
|
|
// which ones make sense here.
|
|
|
|
if (!thread->StartWithOptions(options)) {
|
|
|
|
delete thread;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sRenderThread = new RenderThread(thread);
|
2018-03-29 05:21:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
widget::WinCompositorWindowThread::Start();
|
|
|
|
#endif
|
2018-04-23 14:57:17 +03:00
|
|
|
layers::SharedSurfacesParent::Initialize();
|
2018-05-31 09:07:34 +03:00
|
|
|
|
|
|
|
if (XRE_IsGPUProcess() &&
|
|
|
|
gfx::gfxVars::UseWebRenderProgramBinary()) {
|
|
|
|
MOZ_ASSERT(gfx::gfxVars::UseWebRender());
|
|
|
|
// Initialize program cache if necessary
|
|
|
|
RefPtr<Runnable> runnable = WrapRunnable(
|
|
|
|
RefPtr<RenderThread>(sRenderThread.get()),
|
|
|
|
&RenderThread::ProgramCacheTask);
|
|
|
|
sRenderThread->Loop()->PostTask(runnable.forget());
|
|
|
|
}
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
RenderThread::ShutDown()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(sRenderThread);
|
|
|
|
|
2017-07-03 15:08:22 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(sRenderThread->mRenderTextureMapLock);
|
|
|
|
sRenderThread->mHasShutdown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
layers::SynchronousTask task("RenderThread");
|
|
|
|
RefPtr<Runnable> runnable = WrapRunnable(
|
|
|
|
RefPtr<RenderThread>(sRenderThread.get()),
|
|
|
|
&RenderThread::ShutDownTask,
|
|
|
|
&task);
|
|
|
|
sRenderThread->Loop()->PostTask(runnable.forget());
|
|
|
|
task.Wait();
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
sRenderThread = nullptr;
|
2018-03-29 05:21:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
widget::WinCompositorWindowThread::ShutDown();
|
|
|
|
#endif
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2018-04-25 05:24:55 +03:00
|
|
|
extern void ClearAllBlobImageResources();
|
|
|
|
|
2017-07-03 15:08:22 +03:00
|
|
|
void
|
|
|
|
RenderThread::ShutDownTask(layers::SynchronousTask* aTask)
|
|
|
|
{
|
|
|
|
layers::AutoCompleteTask complete(aTask);
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
2018-04-23 14:57:17 +03:00
|
|
|
|
|
|
|
// Releasing on the render thread will allow us to avoid dispatching to remove
|
|
|
|
// remaining textures from the texture map.
|
|
|
|
layers::SharedSurfacesParent::Shutdown();
|
2018-04-25 05:24:55 +03:00
|
|
|
|
|
|
|
ClearAllBlobImageResources();
|
2017-07-03 15:08:22 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
// static
|
|
|
|
MessageLoop*
|
|
|
|
RenderThread::Loop()
|
|
|
|
{
|
|
|
|
return sRenderThread ? sRenderThread->mThread->message_loop() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
RenderThread::IsInRenderThread()
|
|
|
|
{
|
|
|
|
return sRenderThread && sRenderThread->mThread->thread_id() == PlatformThread::CurrentId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-17 03:22:09 +03:00
|
|
|
RenderThread::AddRenderer(wr::WindowId aWindowId, UniquePtr<RendererOGL> aRenderer)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-16 17:22:47 +03:00
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
2017-07-03 15:08:22 +03:00
|
|
|
|
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
mRenderers[aWindowId] = std::move(aRenderer);
|
2017-05-19 03:21:38 +03:00
|
|
|
|
2017-11-03 05:22:28 +03:00
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
mWindowInfos.emplace(AsUint64(aWindowId), new WindowInfo());
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-17 03:22:09 +03:00
|
|
|
RenderThread::RemoveRenderer(wr::WindowId aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-16 17:22:47 +03:00
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
2017-07-03 15:08:22 +03:00
|
|
|
|
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
mRenderers.erase(aWindowId);
|
2017-05-19 03:21:38 +03:00
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
if (mRenderers.size() == 0 && mHandlingDeviceReset) {
|
|
|
|
mHandlingDeviceReset = false;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:22:28 +03:00
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
MOZ_ASSERT(it != mWindowInfos.end());
|
|
|
|
WindowInfo* toDelete = it->second;
|
|
|
|
mWindowInfos.erase(it);
|
|
|
|
delete toDelete;
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-01-16 17:22:47 +03:00
|
|
|
RendererOGL*
|
2017-01-17 03:22:09 +03:00
|
|
|
RenderThread::GetRenderer(wr::WindowId aWindowId)
|
2017-01-16 17:22:47 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
|
|
|
auto it = mRenderers.find(aWindowId);
|
|
|
|
MOZ_ASSERT(it != mRenderers.end());
|
|
|
|
|
|
|
|
if (it == mRenderers.end()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-25 00:20:54 +03:00
|
|
|
return it->second.get();
|
2017-01-16 17:22:47 +03:00
|
|
|
}
|
2017-01-06 21:10:15 +03:00
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
size_t
|
|
|
|
RenderThread::RendererCount()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
return mRenderers.size();
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
void
|
2017-01-17 03:22:09 +03:00
|
|
|
RenderThread::NewFrameReady(wr::WindowId aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-07-03 15:08:22 +03:00
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
if (!IsInRenderThread()) {
|
2017-06-12 22:34:10 +03:00
|
|
|
Loop()->PostTask(
|
|
|
|
NewRunnableMethod<wr::WindowId>("wr::RenderThread::NewFrameReady",
|
|
|
|
this,
|
|
|
|
&RenderThread::NewFrameReady,
|
|
|
|
aWindowId));
|
2017-01-06 21:10:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 12:34:50 +03:00
|
|
|
if (IsDestroyed(aWindowId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
if (mHandlingDeviceReset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 00:37:35 +03:00
|
|
|
TimeStamp startTime;
|
|
|
|
|
|
|
|
{ // scope lock
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
MOZ_ASSERT(it != mWindowInfos.end());
|
|
|
|
WindowInfo* info = it->second;
|
|
|
|
MOZ_ASSERT(info->mPendingCount > 0);
|
|
|
|
startTime = info->mStartTimes.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateAndRender(aWindowId, startTime);
|
2018-04-27 14:41:03 +03:00
|
|
|
FrameRenderingComplete(aWindowId);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2018-02-13 22:08:54 +03:00
|
|
|
void
|
|
|
|
RenderThread::WakeUp(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsInRenderThread()) {
|
|
|
|
Loop()->PostTask(
|
|
|
|
NewRunnableMethod<wr::WindowId>("wr::RenderThread::WakeUp",
|
|
|
|
this,
|
|
|
|
&RenderThread::WakeUp,
|
|
|
|
aWindowId));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsDestroyed(aWindowId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
if (mHandlingDeviceReset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:08:54 +03:00
|
|
|
auto it = mRenderers.find(aWindowId);
|
|
|
|
MOZ_ASSERT(it != mRenderers.end());
|
|
|
|
if (it != mRenderers.end()) {
|
|
|
|
it->second->Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
void
|
2017-01-17 03:22:09 +03:00
|
|
|
RenderThread::RunEvent(wr::WindowId aWindowId, UniquePtr<RendererEvent> aEvent)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
|
|
|
if (!IsInRenderThread()) {
|
2017-06-12 22:34:10 +03:00
|
|
|
Loop()->PostTask(
|
|
|
|
NewRunnableMethod<wr::WindowId, UniquePtr<RendererEvent>&&>(
|
|
|
|
"wr::RenderThread::RunEvent",
|
|
|
|
this,
|
|
|
|
&RenderThread::RunEvent,
|
|
|
|
aWindowId,
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(aEvent)));
|
2017-01-11 15:51:27 +03:00
|
|
|
return;
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->Run(*this, aWindowId);
|
|
|
|
aEvent = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:30:18 +03:00
|
|
|
static void
|
2018-05-28 18:29:41 +03:00
|
|
|
NotifyDidRender(layers::CompositorBridgeParent* aBridge,
|
2018-04-11 00:26:54 +03:00
|
|
|
wr::WrPipelineInfo aInfo,
|
2017-01-27 23:30:18 +03:00
|
|
|
TimeStamp aStart,
|
|
|
|
TimeStamp aEnd)
|
|
|
|
{
|
2018-04-11 00:26:54 +03:00
|
|
|
for (uintptr_t i = 0; i < aInfo.epochs.length; i++) {
|
2018-04-27 17:32:30 +03:00
|
|
|
aBridge->NotifyPipelineRendered(
|
2018-04-11 00:26:54 +03:00
|
|
|
aInfo.epochs.data[i].pipeline_id,
|
|
|
|
aInfo.epochs.data[i].epoch,
|
|
|
|
aStart,
|
|
|
|
aEnd);
|
2017-01-27 23:30:18 +03:00
|
|
|
}
|
2018-02-12 19:37:02 +03:00
|
|
|
|
|
|
|
wr_pipeline_info_delete(aInfo);
|
2017-01-27 23:30:18 +03:00
|
|
|
}
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
void
|
2018-06-26 00:37:35 +03:00
|
|
|
RenderThread::UpdateAndRender(wr::WindowId aWindowId,
|
|
|
|
const TimeStamp& aStartTime,
|
|
|
|
bool aReadback)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-10-04 01:11:18 +03:00
|
|
|
AUTO_PROFILER_TRACING("Paint", "Composite");
|
2017-01-16 17:22:47 +03:00
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
auto it = mRenderers.find(aWindowId);
|
|
|
|
MOZ_ASSERT(it != mRenderers.end());
|
|
|
|
if (it == mRenderers.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& renderer = it->second;
|
|
|
|
|
2018-02-15 05:29:40 +03:00
|
|
|
bool ret = renderer->UpdateAndRender(aReadback);
|
2017-07-04 13:25:24 +03:00
|
|
|
if (!ret) {
|
|
|
|
// Render did not happen, do not call NotifyDidRender.
|
|
|
|
return;
|
|
|
|
}
|
2017-01-27 23:30:18 +03:00
|
|
|
|
|
|
|
TimeStamp end = TimeStamp::Now();
|
|
|
|
|
2018-02-12 19:37:02 +03:00
|
|
|
auto info = renderer->FlushPipelineInfo();
|
2018-05-28 18:29:41 +03:00
|
|
|
RefPtr<layers::AsyncImagePipelineManager> pipelineMgr =
|
|
|
|
renderer->GetCompositorBridge()->GetAsyncImagePipelineManager();
|
|
|
|
// pipelineMgr should always be non-null here because it is only nulled out
|
|
|
|
// after the WebRenderAPI instance for the CompositorBridgeParent is
|
|
|
|
// destroyed, and that destruction blocks until the renderer thread has
|
|
|
|
// removed the relevant renderer. And after that happens we should never reach
|
|
|
|
// this code at all; it would bail out at the mRenderers.find check above.
|
|
|
|
MOZ_ASSERT(pipelineMgr);
|
|
|
|
pipelineMgr->NotifyPipelinesUpdated(info);
|
|
|
|
|
2017-01-27 23:30:18 +03:00
|
|
|
layers::CompositorThreadHolder::Loop()->PostTask(NewRunnableFunction(
|
2017-10-27 23:39:28 +03:00
|
|
|
"NotifyDidRenderRunnable",
|
2017-01-27 23:30:18 +03:00
|
|
|
&NotifyDidRender,
|
|
|
|
renderer->GetCompositorBridge(),
|
2018-02-12 19:37:02 +03:00
|
|
|
info,
|
2018-06-26 00:37:35 +03:00
|
|
|
aStartTime, end
|
2017-01-27 23:30:18 +03:00
|
|
|
));
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 17:12:11 +03:00
|
|
|
void
|
|
|
|
RenderThread::Pause(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
|
|
|
auto it = mRenderers.find(aWindowId);
|
|
|
|
MOZ_ASSERT(it != mRenderers.end());
|
|
|
|
if (it == mRenderers.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto& renderer = it->second;
|
|
|
|
renderer->Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RenderThread::Resume(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
|
|
|
auto it = mRenderers.find(aWindowId);
|
|
|
|
MOZ_ASSERT(it != mRenderers.end());
|
|
|
|
if (it == mRenderers.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto& renderer = it->second;
|
|
|
|
return renderer->Resume();
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:22:28 +03:00
|
|
|
bool
|
|
|
|
RenderThread::TooManyPendingFrames(wr::WindowId aWindowId)
|
2017-05-19 03:21:38 +03:00
|
|
|
{
|
2017-11-03 05:22:28 +03:00
|
|
|
const int64_t maxFrameCount = 1;
|
|
|
|
|
|
|
|
// Too many pending frames if pending frames exit more than maxFrameCount
|
|
|
|
// or if RenderBackend is still processing a frame.
|
|
|
|
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-11-03 05:22:28 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
WindowInfo* info = it->second;
|
2017-11-03 05:22:28 +03:00
|
|
|
|
2018-06-25 17:55:19 +03:00
|
|
|
if (info->mPendingCount > maxFrameCount) {
|
2017-11-24 12:34:50 +03:00
|
|
|
return true;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
MOZ_ASSERT(info->mPendingCount >= info->mRenderingCount);
|
|
|
|
return info->mPendingCount > info->mRenderingCount;
|
2017-11-24 12:34:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RenderThread::IsDestroyed(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-11-03 05:22:28 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-24 12:34:50 +03:00
|
|
|
|
2018-06-25 17:55:19 +03:00
|
|
|
return it->second->mIsDestroyed;
|
2017-11-24 12:34:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RenderThread::SetDestroyed(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-11-24 12:34:50 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
it->second->mIsDestroyed = true;
|
2017-05-19 03:21:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-06-25 17:55:26 +03:00
|
|
|
RenderThread::IncPendingFrameCount(wr::WindowId aWindowId, const TimeStamp& aStartTime)
|
2017-05-19 03:21:38 +03:00
|
|
|
{
|
2017-11-03 05:22:28 +03:00
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-05-19 03:21:38 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
it->second->mPendingCount++;
|
2018-06-25 17:55:26 +03:00
|
|
|
it->second->mStartTimes.push(aStartTime);
|
2017-11-03 05:22:28 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 14:41:03 +03:00
|
|
|
void
|
|
|
|
RenderThread::DecPendingFrameCount(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2018-04-27 14:41:03 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
WindowInfo* info = it->second;
|
|
|
|
MOZ_ASSERT(info->mPendingCount > 0);
|
|
|
|
if (info->mPendingCount <= 0) {
|
2018-04-27 14:41:03 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
info->mPendingCount--;
|
2018-06-25 17:55:26 +03:00
|
|
|
// This function gets called for "nop frames" where nothing was rendered or
|
|
|
|
// composited. But we count this time because the non-WR codepath equivalent
|
|
|
|
// in CompositorBridgeParent::ComposeToTarget also counts such frames. And
|
|
|
|
// anyway this should be relatively infrequent so it shouldn't skew the
|
|
|
|
// numbers much.
|
|
|
|
mozilla::Telemetry::AccumulateTimeDelta(mozilla::Telemetry::COMPOSITE_TIME,
|
|
|
|
info->mStartTimes.front());
|
|
|
|
info->mStartTimes.pop();
|
2018-04-27 14:41:03 +03:00
|
|
|
}
|
|
|
|
|
2017-11-03 05:22:28 +03:00
|
|
|
void
|
|
|
|
RenderThread::IncRenderingFrameCount(wr::WindowId aWindowId)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-11-03 05:22:28 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
it->second->mRenderingCount++;
|
2017-05-19 03:21:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-27 14:41:03 +03:00
|
|
|
RenderThread::FrameRenderingComplete(wr::WindowId aWindowId)
|
2017-05-19 03:21:38 +03:00
|
|
|
{
|
2017-11-03 05:22:28 +03:00
|
|
|
MutexAutoLock lock(mFrameCountMapLock);
|
2018-06-25 17:55:19 +03:00
|
|
|
auto it = mWindowInfos.find(AsUint64(aWindowId));
|
|
|
|
if (it == mWindowInfos.end()) {
|
2017-05-19 03:21:38 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
WindowInfo* info = it->second;
|
|
|
|
MOZ_ASSERT(info->mPendingCount > 0);
|
|
|
|
MOZ_ASSERT(info->mRenderingCount > 0);
|
|
|
|
if (info->mPendingCount <= 0) {
|
2017-05-19 03:21:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-06-25 17:55:19 +03:00
|
|
|
info->mPendingCount--;
|
|
|
|
info->mRenderingCount--;
|
2018-06-25 17:55:26 +03:00
|
|
|
// The start time is from WebRenderBridgeParent::CompositeToTarget. From that
|
|
|
|
// point until now (when the frame is finally pushed to the screen) is
|
|
|
|
// equivalent to the COMPOSITE_TIME metric in the non-WR codepath.
|
|
|
|
mozilla::Telemetry::AccumulateTimeDelta(mozilla::Telemetry::COMPOSITE_TIME,
|
|
|
|
info->mStartTimes.front());
|
|
|
|
info->mStartTimes.pop();
|
2017-05-19 03:21:38 +03:00
|
|
|
}
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
void
|
2017-06-07 18:44:05 +03:00
|
|
|
RenderThread::RegisterExternalImage(uint64_t aExternalImageId, already_AddRefed<RenderTextureHost> aTexture)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
2017-06-07 18:44:05 +03:00
|
|
|
|
2017-07-03 15:08:22 +03:00
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-10 12:15:47 +03:00
|
|
|
MOZ_ASSERT(mRenderTextures.find(aExternalImageId) == mRenderTextures.end());
|
|
|
|
mRenderTextures.emplace(aExternalImageId, std::move(aTexture));
|
2017-03-07 13:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RenderThread::UnregisterExternalImage(uint64_t aExternalImageId)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
2017-07-03 15:08:22 +03:00
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-10 12:15:47 +03:00
|
|
|
auto it = mRenderTextures.find(aExternalImageId);
|
|
|
|
MOZ_ASSERT(it != mRenderTextures.end());
|
2017-06-07 18:44:05 +03:00
|
|
|
if (!IsInRenderThread()) {
|
|
|
|
// The RenderTextureHost should be released in render thread. So, post the
|
|
|
|
// deletion task here.
|
|
|
|
// The shmem and raw buffer are owned by compositor ipc channel. It's
|
|
|
|
// possible that RenderTextureHost is still exist after the shmem/raw buffer
|
|
|
|
// deletion. Then the buffer in RenderTextureHost becomes invalid. It's fine
|
|
|
|
// for this situation. Gecko will only release the buffer if WR doesn't need
|
|
|
|
// it. So, no one will access the invalid buffer in RenderTextureHost.
|
2018-07-10 12:15:47 +03:00
|
|
|
RefPtr<RenderTextureHost> texture = it->second;
|
|
|
|
mRenderTextures.erase(it);
|
2018-06-15 01:18:48 +03:00
|
|
|
mRenderTexturesDeferred.emplace_back(std::move(texture));
|
|
|
|
Loop()->PostTask(NewRunnableMethod(
|
2017-06-12 22:34:10 +03:00
|
|
|
"RenderThread::DeferredRenderTextureHostDestroy",
|
2018-06-15 01:18:48 +03:00
|
|
|
this, &RenderThread::DeferredRenderTextureHostDestroy
|
2017-06-07 18:44:05 +03:00
|
|
|
));
|
|
|
|
} else {
|
2018-07-10 12:15:47 +03:00
|
|
|
mRenderTextures.erase(it);
|
2017-06-07 18:44:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 17:30:08 +03:00
|
|
|
void
|
|
|
|
RenderThread::UpdateRenderTextureHost(uint64_t aSrcExternalImageId, uint64_t aWrappedExternalImageId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSrcExternalImageId != aWrappedExternalImageId);
|
|
|
|
|
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
|
|
|
if (mHasShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto src = mRenderTextures.find(aSrcExternalImageId);
|
|
|
|
auto wrapped = mRenderTextures.find(aWrappedExternalImageId);
|
|
|
|
if (src == mRenderTextures.end() || wrapped == mRenderTextures.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(src->second->AsRenderTextureHostWrapper());
|
|
|
|
MOZ_ASSERT(!wrapped->second->AsRenderTextureHostWrapper());
|
|
|
|
RenderTextureHostWrapper* wrapper = src->second->AsRenderTextureHostWrapper();
|
|
|
|
if (!wrapper) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to happen");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!wrapper->IsInited()) {
|
|
|
|
wrapper->UpdateRenderTextureHost(wrapped->second);
|
|
|
|
MOZ_ASSERT(wrapper->IsInited());
|
|
|
|
} else {
|
|
|
|
Loop()->PostTask(NewRunnableMethod<RenderTextureHost*>(
|
|
|
|
"RenderThread::DeferredRenderTextureHostDestroy",
|
|
|
|
wrapper, &RenderTextureHostWrapper::UpdateRenderTextureHost, wrapped->second
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 14:57:17 +03:00
|
|
|
void
|
|
|
|
RenderThread::UnregisterExternalImageDuringShutdown(uint64_t aExternalImageId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
|
|
|
MOZ_ASSERT(mHasShutdown);
|
2018-07-10 12:15:47 +03:00
|
|
|
MOZ_ASSERT(mRenderTextures.find(aExternalImageId) != mRenderTextures.end());
|
|
|
|
mRenderTextures.erase(aExternalImageId);
|
2018-04-23 14:57:17 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 18:44:05 +03:00
|
|
|
void
|
2018-06-15 01:18:48 +03:00
|
|
|
RenderThread::DeferredRenderTextureHostDestroy()
|
2017-06-07 18:44:05 +03:00
|
|
|
{
|
2018-06-15 01:18:48 +03:00
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
|
|
|
mRenderTexturesDeferred.clear();
|
2017-03-07 13:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderTextureHost*
|
2017-06-28 02:20:36 +03:00
|
|
|
RenderThread::GetRenderTexture(wr::WrExternalImageId aExternalImageId)
|
2017-03-07 13:37:28 +03:00
|
|
|
{
|
2017-06-07 18:44:05 +03:00
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
2017-03-07 13:37:28 +03:00
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
2018-07-10 12:15:47 +03:00
|
|
|
auto it = mRenderTextures.find(aExternalImageId.mHandle);
|
|
|
|
MOZ_ASSERT(it != mRenderTextures.end());
|
|
|
|
if (it == mRenderTextures.end()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return it->second;
|
2017-03-07 13:37:28 +03:00
|
|
|
}
|
|
|
|
|
2018-05-31 09:07:34 +03:00
|
|
|
void
|
|
|
|
RenderThread::ProgramCacheTask()
|
|
|
|
{
|
|
|
|
ProgramCache();
|
|
|
|
}
|
|
|
|
|
2018-06-13 18:01:06 +03:00
|
|
|
void
|
2018-06-19 13:27:37 +03:00
|
|
|
RenderThread::HandleDeviceReset(const char* aWhere, bool aNotify)
|
2018-06-13 18:01:06 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
|
|
|
if (mHandlingDeviceReset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-19 13:27:37 +03:00
|
|
|
if (aNotify) {
|
|
|
|
gfxCriticalNote << "GFX: RenderThread detected a device reset in " << aWhere;
|
|
|
|
if (XRE_IsGPUProcess()) {
|
|
|
|
gfx::GPUParent::GetSingleton()->NotifyDeviceReset();
|
|
|
|
}
|
2018-06-13 18:01:06 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 01:18:48 +03:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mRenderTextureMapLock);
|
|
|
|
mRenderTexturesDeferred.clear();
|
2018-07-10 12:15:47 +03:00
|
|
|
for (const auto& entry : mRenderTextures) {
|
|
|
|
entry.second->ClearCachedResources();
|
2018-06-15 01:18:48 +03:00
|
|
|
}
|
2018-06-13 18:01:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mHandlingDeviceReset = true;
|
|
|
|
// All RenderCompositors will be destroyed by GPUChild::RecvNotifyDeviceReset()
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
RenderThread::IsHandlingDeviceReset()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
return mHandlingDeviceReset;
|
|
|
|
}
|
|
|
|
|
2018-06-19 13:27:37 +03:00
|
|
|
void
|
|
|
|
RenderThread::SimulateDeviceReset()
|
|
|
|
{
|
|
|
|
if (!IsInRenderThread()) {
|
|
|
|
Loop()->PostTask(NewRunnableMethod(
|
|
|
|
"RenderThread::SimulateDeviceReset",
|
|
|
|
this, &RenderThread::SimulateDeviceReset
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
// When this function is called GPUProcessManager::SimulateDeviceReset() already
|
|
|
|
// triggers destroying all CompositorSessions before re-creating them.
|
|
|
|
HandleDeviceReset("SimulateDeviceReset", /* aNotify */ false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 14:58:24 +03:00
|
|
|
WebRenderProgramCache*
|
|
|
|
RenderThread::ProgramCache()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsInRenderThread());
|
|
|
|
|
|
|
|
if (!mProgramCache) {
|
2018-05-31 09:07:34 +03:00
|
|
|
mProgramCache = MakeUnique<WebRenderProgramCache>(ThreadPool().Raw());
|
2017-11-24 14:58:24 +03:00
|
|
|
}
|
|
|
|
return mProgramCache.get();
|
|
|
|
}
|
|
|
|
|
2017-06-13 18:57:16 +03:00
|
|
|
WebRenderThreadPool::WebRenderThreadPool()
|
|
|
|
{
|
|
|
|
mThreadPool = wr_thread_pool_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderThreadPool::~WebRenderThreadPool()
|
|
|
|
{
|
|
|
|
wr_thread_pool_delete(mThreadPool);
|
|
|
|
}
|
|
|
|
|
2018-05-31 09:07:34 +03:00
|
|
|
WebRenderProgramCache::WebRenderProgramCache(wr::WrThreadPool* aThreadPool)
|
2017-11-24 14:58:24 +03:00
|
|
|
{
|
2018-05-31 09:07:34 +03:00
|
|
|
MOZ_ASSERT(aThreadPool);
|
|
|
|
|
|
|
|
nsAutoString path;
|
|
|
|
if (gfxVars::UseWebRenderProgramBinaryDisk()) {
|
|
|
|
path.Append(gfx::gfxVars::ProfDirectory());
|
|
|
|
}
|
|
|
|
mProgramCache = wr_program_cache_new(&path, aThreadPool);
|
|
|
|
wr_try_load_shader_from_disk(mProgramCache);
|
2017-11-24 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WebRenderProgramCache::~WebRenderProgramCache()
|
|
|
|
{
|
|
|
|
wr_program_cache_delete(mProgramCache);
|
|
|
|
}
|
|
|
|
|
2017-01-25 00:06:17 +03:00
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|
2017-01-06 21:10:15 +03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2018-01-17 19:19:39 +03:00
|
|
|
static void NewFrameReady(mozilla::wr::WrWindowId aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-11-03 05:22:28 +03:00
|
|
|
mozilla::wr::RenderThread::Get()->IncRenderingFrameCount(aWindowId);
|
2018-04-27 14:41:03 +03:00
|
|
|
mozilla::wr::RenderThread::Get()->NewFrameReady(aWindowId);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 18:49:25 +03:00
|
|
|
void wr_notifier_wake_up(mozilla::wr::WrWindowId aWindowId)
|
|
|
|
{
|
2018-04-27 14:41:03 +03:00
|
|
|
mozilla::wr::RenderThread::Get()->WakeUp(aWindowId);
|
2018-02-08 18:49:25 +03:00
|
|
|
}
|
|
|
|
|
2018-01-17 19:19:39 +03:00
|
|
|
void wr_notifier_new_frame_ready(mozilla::wr::WrWindowId aWindowId)
|
|
|
|
{
|
|
|
|
NewFrameReady(aWindowId);
|
|
|
|
}
|
|
|
|
|
2018-04-27 14:41:03 +03:00
|
|
|
void wr_notifier_nop_frame_done(mozilla::wr::WrWindowId aWindowId)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2018-04-27 14:41:03 +03:00
|
|
|
mozilla::wr::RenderThread::Get()->DecPendingFrameCount(aWindowId);
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 02:20:36 +03:00
|
|
|
void wr_notifier_external_event(mozilla::wr::WrWindowId aWindowId, size_t aRawEvent)
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2017-01-17 03:22:09 +03:00
|
|
|
mozilla::UniquePtr<mozilla::wr::RendererEvent> evt(
|
|
|
|
reinterpret_cast<mozilla::wr::RendererEvent*>(aRawEvent));
|
|
|
|
mozilla::wr::RenderThread::Get()->RunEvent(mozilla::wr::WindowId(aWindowId),
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(evt));
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2018-05-11 16:09:16 +03:00
|
|
|
void wr_schedule_render(mozilla::wr::WrWindowId aWindowId)
|
|
|
|
{
|
|
|
|
RefPtr<mozilla::layers::CompositorBridgeParent> cbp =
|
|
|
|
mozilla::layers::CompositorBridgeParent::GetCompositorBridgeParentFromWindowId(aWindowId);
|
|
|
|
if (cbp) {
|
|
|
|
cbp->ScheduleRenderOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
} // extern C
|