Bug 1551735 - Record compositions in Web Render r=kats

Now that we have a suitable composition recorder infrastructure, it is just a
matter of plumbing the `WebRenderCompositionRecorder` from the
`CompositorBridgeParent` to the `RenderThread` to start recording frames.

Differential Revision: https://phabricator.services.mozilla.com/D32234

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Barret Rennie 2019-05-31 00:31:39 +00:00
Родитель f5ab9bc353
Коммит d9cb9952d0
7 изменённых файлов: 86 добавлений и 3 удалений

Просмотреть файл

@ -2609,10 +2609,15 @@ int32_t RecordContentFrameTime(
mozilla::ipc::IPCResult CompositorBridgeParent::RecvBeginRecording(
const TimeStamp& aRecordingStart) {
mCompositionRecorder = new CompositionRecorder(aRecordingStart);
if (mLayerManager) {
mCompositionRecorder = new CompositionRecorder(aRecordingStart);
mLayerManager->SetCompositionRecorder(do_AddRef(mCompositionRecorder));
} else if (mWrBridge) {
RefPtr<WebRenderCompositionRecorder> recorder =
new WebRenderCompositionRecorder(aRecordingStart,
mWrBridge->PipelineId());
mCompositionRecorder = recorder;
mWrBridge->SetCompositionRecorder(std::move(recorder));
}
return IPC_OK();
@ -2622,6 +2627,11 @@ mozilla::ipc::IPCResult CompositorBridgeParent::RecvEndRecording() {
if (mLayerManager) {
mLayerManager->SetCompositionRecorder(nullptr);
}
// If we are using WebRender, the |RenderThread| will have a handle to this
// |WebRenderCompositionRecorder|, which it will release once the frames have
// been written.
mCompositionRecorder->WriteCollectedFrames();
mCompositionRecorder = nullptr;
return IPC_OK();

Просмотреть файл

@ -801,6 +801,11 @@ bool WebRenderBridgeParent::IsRootWebRenderBridgeParent() const {
return !!mWidget;
}
void WebRenderBridgeParent::SetCompositionRecorder(
RefPtr<layers::WebRenderCompositionRecorder>&& aRecorder) {
Api(wr::RenderRoot::Default)->SetCompositionRecorder(std::move(aRecorder));
}
CompositorBridgeParent* WebRenderBridgeParent::GetRootCompositorBridgeParent()
const {
if (!mCompositorBridge) {

Просмотреть файл

@ -17,6 +17,7 @@
#include "mozilla/layers/CompositorVsyncSchedulerOwner.h"
#include "mozilla/layers/PWebRenderBridgeParent.h"
#include "mozilla/layers/UiCompositorControllerParent.h"
#include "mozilla/layers/WebRenderCompositionRecorder.h"
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
@ -272,6 +273,9 @@ class WebRenderBridgeParent final
LayersId GetLayersId() const;
WRRootId GetWRRootId() const;
void SetCompositionRecorder(
RefPtr<layers::WebRenderCompositionRecorder>&& aRecorder);
private:
class ScheduleSharedSurfaceRelease;

Просмотреть файл

@ -198,6 +198,7 @@ void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {
}
mRenderers.erase(aWindowId);
mCompositionRecorders.erase(aWindowId);
if (mRenderers.size() == 0 && mHandlingDeviceReset) {
mHandlingDeviceReset = false;
@ -229,6 +230,15 @@ size_t RenderThread::RendererCount() {
return mRenderers.size();
}
void RenderThread::SetCompositionRecorderForWindow(
wr::WindowId aWindowId,
RefPtr<layers::WebRenderCompositionRecorder>&& aCompositionRecorder) {
MOZ_ASSERT(IsInRenderThread());
MOZ_ASSERT(GetRenderer(aWindowId));
mCompositionRecorders[aWindowId] = std::move(aCompositionRecorder);
}
void RenderThread::HandleFrame(wr::WindowId aWindowId, bool aRender) {
if (mHasShutdown) {
return;
@ -382,13 +392,28 @@ void RenderThread::UpdateAndRender(
renderer->CheckGraphicsResetStatus();
TimeStamp end = TimeStamp::Now();
auto info = renderer->FlushPipelineInfo();
RefPtr<WebRenderPipelineInfo> info = renderer->FlushPipelineInfo();
layers::CompositorThreadHolder::Loop()->PostTask(
NewRunnableFunction("NotifyDidRenderRunnable", &NotifyDidRender,
renderer->GetCompositorBridge(), info, aStartId,
aStartTime, start, end, aRender, stats));
if (rendered) {
auto recorderIt = mCompositionRecorders.find(aWindowId);
if (recorderIt != mCompositionRecorders.end()) {
bool shouldRelease = recorderIt->second->MaybeRecordFrame(
renderer->GetRenderer(), info.get());
if (shouldRelease) {
mCompositionRecorders.erase(recorderIt);
wr_renderer_release_composition_recorder_structures(
renderer->GetRenderer());
}
}
}
if (rendered) {
// Wait for GPU after posting NotifyDidRender, since the wait is not
// necessary for the NotifyDidRender.

Просмотреть файл

@ -20,6 +20,7 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "mozilla/layers/SynchronousTask.h"
#include "mozilla/layers/WebRenderCompositionRecorder.h"
#include "mozilla/VsyncDispatcher.h"
#include <list>
@ -256,6 +257,10 @@ class RenderThread final {
size_t RendererCount();
void SetCompositionRecorderForWindow(
wr::WindowId aWindowId,
RefPtr<layers::WebRenderCompositionRecorder>&& aCompositionRecorder);
private:
explicit RenderThread(base::Thread* aThread);
@ -280,6 +285,8 @@ class RenderThread final {
RefPtr<gl::GLContext> mSharedGL;
std::map<wr::WindowId, UniquePtr<RendererOGL>> mRenderers;
std::map<wr::WindowId, RefPtr<layers::WebRenderCompositionRecorder>>
mCompositionRecorders;
struct WindowInfo {
bool mIsDestroyed = false;

Просмотреть файл

@ -577,6 +577,34 @@ void WebRenderAPI::Capture() {
wr_api_capture(mDocHandle, path, bits);
}
void WebRenderAPI::SetCompositionRecorder(
RefPtr<layers::WebRenderCompositionRecorder>&& aRecorder) {
class SetCompositionRecorderEvent final : public RendererEvent {
public:
explicit SetCompositionRecorderEvent(
RefPtr<layers::WebRenderCompositionRecorder>&& aRecorder)
: mRecorder(std::move(aRecorder)) {
MOZ_COUNT_CTOR(SetCompositionRecorderEvent);
}
~SetCompositionRecorderEvent() {
MOZ_COUNT_DTOR(SetCompositionRecorderEvent);
}
void Run(RenderThread& aRenderThread, WindowId aWindowId) override {
MOZ_ASSERT(mRecorder);
aRenderThread.SetCompositionRecorderForWindow(aWindowId,
std::move(mRecorder));
}
private:
RefPtr<layers::WebRenderCompositionRecorder> mRecorder;
};
auto event = MakeUnique<SetCompositionRecorderEvent>(std::move(aRecorder));
RunOnRenderThread(std::move(event));
}
void TransactionBuilder::Clear() { wr_resource_updates_clear(mTxn); }
void TransactionBuilder::Notify(wr::Checkpoint aWhen,

Просмотреть файл

@ -16,6 +16,7 @@
#include "mozilla/layers/IpcResourceUpdateQueue.h"
#include "mozilla/layers/ScrollableLayerGuid.h"
#include "mozilla/layers/SyncObject.h"
#include "mozilla/layers/WebRenderCompositionRecorder.h"
#include "mozilla/Range.h"
#include "mozilla/webrender/webrender_ffi.h"
#include "mozilla/webrender/WebRenderTypes.h"
@ -258,6 +259,9 @@ class WebRenderAPI final {
void Capture();
void SetCompositionRecorder(
RefPtr<layers::WebRenderCompositionRecorder>&& aRecorder);
protected:
WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId,
uint32_t aMaxTextureSize, bool aUseANGLE, bool aUseDComp,