2016-11-16 16:54:51 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-10-28 02:10:06 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-11-16 16:54:51 +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 "mozilla/layers/WebRenderBridgeParent.h"
|
|
|
|
|
2016-11-24 09:48:01 +03:00
|
|
|
#include "CompositableHost.h"
|
2017-07-29 03:17:19 +03:00
|
|
|
#include "gfxEnv.h"
|
2017-04-27 19:04:25 +03:00
|
|
|
#include "gfxPrefs.h"
|
2017-07-28 15:08:05 +03:00
|
|
|
#include "gfxEnv.h"
|
2017-06-09 06:56:13 +03:00
|
|
|
#include "GeckoProfiler.h"
|
2016-11-16 16:54:51 +03:00
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
2017-01-13 13:25:07 +03:00
|
|
|
#include "mozilla/Range.h"
|
2017-03-28 12:11:03 +03:00
|
|
|
#include "mozilla/layers/AnimationHelper.h"
|
2018-03-06 18:25:37 +03:00
|
|
|
#include "mozilla/layers/APZSampler.h"
|
2018-03-29 01:36:42 +03:00
|
|
|
#include "mozilla/layers/APZUpdater.h"
|
2016-11-17 12:02:56 +03:00
|
|
|
#include "mozilla/layers/Compositor.h"
|
2016-11-30 05:59:14 +03:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2016-12-02 01:10:10 +03:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2016-11-22 05:56:38 +03:00
|
|
|
#include "mozilla/layers/CompositorVsyncScheduler.h"
|
2017-01-05 18:03:17 +03:00
|
|
|
#include "mozilla/layers/ImageBridgeParent.h"
|
2016-11-28 05:39:42 +03:00
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2017-09-14 19:48:55 +03:00
|
|
|
#include "mozilla/layers/IpcResourceUpdateQueue.h"
|
2017-10-30 20:10:29 +03:00
|
|
|
#include "mozilla/layers/SharedSurfacesParent.h"
|
2016-11-28 05:39:42 +03:00
|
|
|
#include "mozilla/layers/TextureHost.h"
|
2017-07-25 11:54:36 +03:00
|
|
|
#include "mozilla/layers/AsyncImagePipelineManager.h"
|
2017-04-27 19:34:54 +03:00
|
|
|
#include "mozilla/layers/WebRenderImageHost.h"
|
2017-03-07 13:37:28 +03:00
|
|
|
#include "mozilla/layers/WebRenderTextureHost.h"
|
2018-06-26 21:43:14 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-04-27 19:34:54 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2017-06-30 04:06:11 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-01-17 03:21:52 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
2016-11-28 05:39:42 +03:00
|
|
|
#include "mozilla/widget/CompositorWidget.h"
|
2016-11-16 16:54:51 +03:00
|
|
|
|
2017-03-02 04:36:27 +03:00
|
|
|
bool is_in_main_thread()
|
|
|
|
{
|
|
|
|
return NS_IsMainThread();
|
|
|
|
}
|
|
|
|
|
2016-12-02 01:10:10 +03:00
|
|
|
bool is_in_compositor_thread()
|
|
|
|
{
|
|
|
|
return mozilla::layers::CompositorThreadHolder::IsInCompositorThread();
|
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
bool is_in_render_thread()
|
|
|
|
{
|
2017-01-17 03:22:09 +03:00
|
|
|
return mozilla::wr::RenderThread::IsInRenderThread();
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 19:10:40 +03:00
|
|
|
bool is_glcontext_egl(void* glcontext_ptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(glcontext_ptr);
|
|
|
|
|
|
|
|
mozilla::gl::GLContext* glcontext = reinterpret_cast<mozilla::gl::GLContext*>(glcontext_ptr);
|
|
|
|
if (!glcontext) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return glcontext->GetContextType() == mozilla::gl::GLContextType::EGL;
|
|
|
|
}
|
|
|
|
|
2017-12-06 23:06:40 +03:00
|
|
|
bool is_glcontext_angle(void* glcontext_ptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(glcontext_ptr);
|
|
|
|
|
|
|
|
mozilla::gl::GLContext* glcontext = reinterpret_cast<mozilla::gl::GLContext*>(glcontext_ptr);
|
|
|
|
if (!glcontext) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return glcontext->IsANGLE();
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:38:22 +03:00
|
|
|
bool gfx_use_wrench()
|
|
|
|
{
|
|
|
|
return gfxEnv::EnableWebRenderRecording();
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:38:56 +03:00
|
|
|
const char* gfx_wr_resource_path_override()
|
|
|
|
{
|
2017-10-08 05:11:13 +03:00
|
|
|
const char* resourcePath = PR_GetEnv("WR_RESOURCE_PATH");
|
2017-10-06 21:38:56 +03:00
|
|
|
if (!resourcePath || resourcePath[0] == '\0') {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return resourcePath;
|
|
|
|
}
|
|
|
|
|
2017-03-27 21:32:39 +03:00
|
|
|
void gfx_critical_note(const char* msg)
|
|
|
|
{
|
|
|
|
gfxCriticalNote << msg;
|
|
|
|
}
|
|
|
|
|
2017-10-30 06:31:38 +03:00
|
|
|
void gfx_critical_error(const char* msg)
|
|
|
|
{
|
|
|
|
gfxCriticalError() << msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gecko_printf_stderr_output(const char* msg)
|
|
|
|
{
|
|
|
|
printf_stderr("%s\n", msg);
|
|
|
|
}
|
|
|
|
|
2016-12-21 07:22:04 +03:00
|
|
|
void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(glcontext_ptr);
|
|
|
|
|
|
|
|
mozilla::gl::GLContext* glcontext = reinterpret_cast<mozilla::gl::GLContext*>(glcontext_ptr);
|
|
|
|
if (!glcontext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
PRFuncPtr p = glcontext->LookupSymbol(procname);
|
|
|
|
return reinterpret_cast<void*>(p);
|
|
|
|
}
|
|
|
|
|
2017-11-11 13:57:31 +03:00
|
|
|
void
|
|
|
|
gecko_profiler_register_thread(const char* name)
|
|
|
|
{
|
2017-11-12 17:21:22 +03:00
|
|
|
PROFILER_REGISTER_THREAD(name);
|
2017-11-11 13:57:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gecko_profiler_unregister_thread()
|
|
|
|
{
|
2017-11-12 17:21:22 +03:00
|
|
|
PROFILER_UNREGISTER_THREAD();
|
2017-11-11 13:57:31 +03:00
|
|
|
}
|
|
|
|
|
2018-07-04 14:52:22 +03:00
|
|
|
void
|
|
|
|
record_telemetry_time(mozilla::wr::TelemetryProbe aProbe, uint64_t aTimeNs)
|
|
|
|
{
|
|
|
|
uint32_t time_ms = (uint32_t)(aTimeNs / 1000000);
|
|
|
|
switch (aProbe) {
|
|
|
|
case mozilla::wr::TelemetryProbe::SceneBuildTime:
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::WR_SCENEBUILD_TIME, time_ms);
|
|
|
|
break;
|
|
|
|
case mozilla::wr::TelemetryProbe::SceneSwapTime:
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::WR_SCENESWAP_TIME, time_ms);
|
|
|
|
break;
|
|
|
|
case mozilla::wr::TelemetryProbe::RenderTime:
|
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::WR_RENDER_TIME, time_ms);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:54:51 +03:00
|
|
|
namespace mozilla {
|
2017-12-01 02:14:41 +03:00
|
|
|
|
2016-11-16 16:54:51 +03:00
|
|
|
namespace layers {
|
|
|
|
|
2016-11-28 05:39:42 +03:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2018-09-21 19:47:18 +03:00
|
|
|
class ScheduleObserveLayersUpdate: public wr::NotificationHandler {
|
|
|
|
public:
|
|
|
|
ScheduleObserveLayersUpdate(RefPtr<CompositorBridgeParentBase> aBridge,
|
|
|
|
LayersId aLayersId,
|
|
|
|
LayersObserverEpoch aEpoch,
|
|
|
|
bool aIsActive)
|
|
|
|
: mBridge(aBridge)
|
|
|
|
, mLayersId(aLayersId)
|
|
|
|
, mObserverEpoch(aEpoch)
|
|
|
|
, mIsActive(aIsActive)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void Notify(wr::Checkpoint) override {
|
|
|
|
CompositorThreadHolder::Loop()->PostTask(
|
|
|
|
NewRunnableMethod<LayersId, LayersObserverEpoch, int>(
|
|
|
|
"ObserveLayersUpdate",
|
|
|
|
mBridge, &CompositorBridgeParentBase::ObserveLayersUpdate,
|
|
|
|
mLayersId, mObserverEpoch, mIsActive
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
RefPtr<CompositorBridgeParentBase> mBridge;
|
|
|
|
LayersId mLayersId;
|
|
|
|
LayersObserverEpoch mObserverEpoch;
|
|
|
|
bool mIsActive;
|
|
|
|
};
|
|
|
|
|
2016-12-07 13:02:04 +03:00
|
|
|
class MOZ_STACK_CLASS AutoWebRenderBridgeParentAsyncMessageSender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoWebRenderBridgeParentAsyncMessageSender(WebRenderBridgeParent* aWebRenderBridgeParent,
|
|
|
|
InfallibleTArray<OpDestroy>* aDestroyActors = nullptr)
|
|
|
|
: mWebRenderBridgeParent(aWebRenderBridgeParent)
|
|
|
|
, mActorsToDestroy(aDestroyActors)
|
|
|
|
{
|
|
|
|
mWebRenderBridgeParent->SetAboutToSendAsyncMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoWebRenderBridgeParentAsyncMessageSender()
|
|
|
|
{
|
|
|
|
mWebRenderBridgeParent->SendPendingAsyncMessages();
|
|
|
|
if (mActorsToDestroy) {
|
|
|
|
// Destroy the actors after sending the async messages because the latter may contain
|
|
|
|
// references to some actors.
|
|
|
|
for (const auto& op : *mActorsToDestroy) {
|
|
|
|
mWebRenderBridgeParent->DestroyActor(op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
WebRenderBridgeParent* mWebRenderBridgeParent;
|
|
|
|
InfallibleTArray<OpDestroy>* mActorsToDestroy;
|
|
|
|
};
|
|
|
|
|
2017-01-11 15:51:27 +03:00
|
|
|
WebRenderBridgeParent::WebRenderBridgeParent(CompositorBridgeParentBase* aCompositorBridge,
|
2017-01-17 23:13:41 +03:00
|
|
|
const wr::PipelineId& aPipelineId,
|
2017-01-11 15:51:27 +03:00
|
|
|
widget::CompositorWidget* aWidget,
|
2017-02-27 03:27:04 +03:00
|
|
|
CompositorVsyncScheduler* aScheduler,
|
2017-01-20 05:00:17 +03:00
|
|
|
RefPtr<wr::WebRenderAPI>&& aApi,
|
2017-07-25 11:54:36 +03:00
|
|
|
RefPtr<AsyncImagePipelineManager>&& aImageMgr,
|
2018-06-26 21:43:14 +03:00
|
|
|
RefPtr<CompositorAnimationStorage>&& aAnimStorage,
|
|
|
|
TimeDuration aVsyncRate)
|
2017-01-11 15:51:27 +03:00
|
|
|
: mCompositorBridge(aCompositorBridge)
|
|
|
|
, mPipelineId(aPipelineId)
|
|
|
|
, mWidget(aWidget)
|
|
|
|
, mApi(aApi)
|
2017-07-25 11:54:36 +03:00
|
|
|
, mAsyncImageManager(aImageMgr)
|
2017-02-27 03:27:04 +03:00
|
|
|
, mCompositorScheduler(aScheduler)
|
2017-06-15 10:36:03 +03:00
|
|
|
, mAnimStorage(aAnimStorage)
|
2018-06-26 21:43:14 +03:00
|
|
|
, mVsyncRate(aVsyncRate)
|
2018-07-30 16:24:50 +03:00
|
|
|
, mChildLayersObserverEpoch{0}
|
|
|
|
, mParentLayersObserverEpoch{0}
|
2018-04-10 19:29:56 +03:00
|
|
|
, mWrEpoch{0}
|
2017-07-31 21:21:18 +03:00
|
|
|
, mIdNamespace(aApi->GetNamespace())
|
2017-04-05 17:12:11 +03:00
|
|
|
, mPaused(false)
|
2017-01-11 15:51:27 +03:00
|
|
|
, mDestroyed(false)
|
2018-03-06 22:20:56 +03:00
|
|
|
, mReceivedDisplayList(false)
|
2018-10-19 16:48:04 +03:00
|
|
|
, mIsFirstPaint(true)
|
2017-01-11 15:51:27 +03:00
|
|
|
{
|
2017-07-25 11:54:36 +03:00
|
|
|
MOZ_ASSERT(mAsyncImageManager);
|
2017-06-15 10:36:03 +03:00
|
|
|
MOZ_ASSERT(mAnimStorage);
|
2017-07-25 11:54:36 +03:00
|
|
|
mAsyncImageManager->AddPipeline(mPipelineId);
|
2018-06-26 21:37:31 +03:00
|
|
|
if (IsRootWebRenderBridgeParent()) {
|
2017-02-27 03:27:04 +03:00
|
|
|
MOZ_ASSERT(!mCompositorScheduler);
|
2017-01-11 15:51:27 +03:00
|
|
|
mCompositorScheduler = new CompositorVsyncScheduler(this, mWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 16:41:53 +03:00
|
|
|
WebRenderBridgeParent::WebRenderBridgeParent(const wr::PipelineId& aPipelineId)
|
2017-06-30 04:06:11 +03:00
|
|
|
: mCompositorBridge(nullptr)
|
2017-08-29 16:41:53 +03:00
|
|
|
, mPipelineId(aPipelineId)
|
2018-07-30 16:24:50 +03:00
|
|
|
, mChildLayersObserverEpoch{0}
|
|
|
|
, mParentLayersObserverEpoch{0}
|
2018-04-10 19:29:56 +03:00
|
|
|
, mWrEpoch{0}
|
2017-07-31 21:21:18 +03:00
|
|
|
, mIdNamespace{0}
|
2017-06-30 04:06:11 +03:00
|
|
|
, mPaused(false)
|
|
|
|
, mDestroyed(true)
|
2018-03-06 22:20:56 +03:00
|
|
|
, mReceivedDisplayList(false)
|
2018-10-19 16:48:04 +03:00
|
|
|
, mIsFirstPaint(false)
|
2017-06-30 04:06:11 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ WebRenderBridgeParent*
|
2017-08-29 16:41:53 +03:00
|
|
|
WebRenderBridgeParent::CreateDestroyed(const wr::PipelineId& aPipelineId)
|
2017-06-30 04:06:11 +03:00
|
|
|
{
|
2017-08-29 16:41:53 +03:00
|
|
|
return new WebRenderBridgeParent(aPipelineId);
|
2017-06-30 04:06:11 +03:00
|
|
|
}
|
|
|
|
|
2017-06-02 10:11:34 +03:00
|
|
|
WebRenderBridgeParent::~WebRenderBridgeParent()
|
|
|
|
{
|
|
|
|
}
|
2017-01-11 15:51:27 +03:00
|
|
|
|
2018-10-05 10:35:29 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvEnsureConnected(TextureFactoryIdentifier* aTextureFactoryIdentifier,
|
|
|
|
MaybeIdNamespace* aMaybeIdNamespace)
|
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
*aTextureFactoryIdentifier = TextureFactoryIdentifier(LayersBackend::LAYERS_NONE);
|
|
|
|
*aMaybeIdNamespace = Nothing();
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mIdNamespace.mHandle != 0);
|
|
|
|
*aTextureFactoryIdentifier = GetTextureFactoryIdentifier();
|
|
|
|
*aMaybeIdNamespace = Some(mIdNamespace);
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:54:51 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2016-11-25 04:36:37 +03:00
|
|
|
WebRenderBridgeParent::RecvShutdown()
|
2017-06-29 21:46:36 +03:00
|
|
|
{
|
|
|
|
return HandleShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvShutdownSync()
|
|
|
|
{
|
|
|
|
return HandleShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::HandleShutdown()
|
2016-11-16 16:54:51 +03:00
|
|
|
{
|
2016-11-28 04:21:33 +03:00
|
|
|
Destroy();
|
2017-05-18 03:31:46 +03:00
|
|
|
IProtocol* mgr = Manager();
|
2016-11-25 04:36:37 +03:00
|
|
|
if (!Send__delete__(this)) {
|
2017-05-18 03:31:46 +03:00
|
|
|
return IPC_FAIL_NO_REASON(mgr);
|
2016-11-25 04:36:37 +03:00
|
|
|
}
|
2016-11-16 16:54:51 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2016-11-28 04:21:33 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::Destroy()
|
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mDestroyed = true;
|
|
|
|
ClearResources();
|
|
|
|
}
|
|
|
|
|
2017-09-14 19:48:55 +03:00
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::UpdateResources(const nsTArray<OpUpdateResource>& aResourceUpdates,
|
2018-01-12 17:11:28 +03:00
|
|
|
const nsTArray<RefCountedShmem>& aSmallShmems,
|
2017-09-20 14:39:19 +03:00
|
|
|
const nsTArray<ipc::Shmem>& aLargeShmems,
|
2018-01-29 16:33:39 +03:00
|
|
|
wr::TransactionBuilder& aUpdates)
|
2017-09-14 19:48:55 +03:00
|
|
|
{
|
2017-09-20 14:39:19 +03:00
|
|
|
wr::ShmSegmentsReader reader(aSmallShmems, aLargeShmems);
|
2017-09-14 19:48:55 +03:00
|
|
|
|
|
|
|
for (const auto& cmd : aResourceUpdates) {
|
|
|
|
switch (cmd.type()) {
|
|
|
|
case OpUpdateResource::TOpAddImage: {
|
|
|
|
const auto& op = cmd.get_OpAddImage();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-09-14 19:48:55 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aUpdates.AddImage(op.key(), op.descriptor(), bytes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpUpdateImage: {
|
|
|
|
const auto& op = cmd.get_OpUpdateImage();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-09-14 19:48:55 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aUpdates.UpdateImageBuffer(op.key(), op.descriptor(), bytes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpAddBlobImage: {
|
|
|
|
const auto& op = cmd.get_OpAddBlobImage();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-09-14 19:48:55 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aUpdates.AddBlobImage(op.key(), op.descriptor(), bytes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpUpdateBlobImage: {
|
|
|
|
const auto& op = cmd.get_OpUpdateBlobImage();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-09-14 19:48:55 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-03 23:38:33 +03:00
|
|
|
aUpdates.UpdateBlobImage(op.key(), op.descriptor(), bytes, wr::ToDeviceUintRect(op.dirtyRect()));
|
2017-09-14 19:48:55 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-07-19 23:33:05 +03:00
|
|
|
case OpUpdateResource::TOpSetImageVisibleArea: {
|
|
|
|
const auto& op = cmd.get_OpSetImageVisibleArea();
|
2018-09-26 17:32:41 +03:00
|
|
|
wr::DeviceUintRect area;
|
2018-07-19 23:33:05 +03:00
|
|
|
area.origin.x = op.area().x;
|
|
|
|
area.origin.y = op.area().y;
|
|
|
|
area.size.width = op.area().width;
|
|
|
|
area.size.height = op.area().height;
|
|
|
|
aUpdates.SetImageVisibleArea(op.key(), area);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-20 11:56:09 +03:00
|
|
|
case OpUpdateResource::TOpAddExternalImage: {
|
|
|
|
const auto& op = cmd.get_OpAddExternalImage();
|
|
|
|
if (!AddExternalImage(op.externalImageId(), op.key(), aUpdates)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-07-11 11:45:28 +03:00
|
|
|
case OpUpdateResource::TOpPushExternalImageForTexture: {
|
|
|
|
const auto& op = cmd.get_OpPushExternalImageForTexture();
|
2018-07-06 15:25:33 +03:00
|
|
|
CompositableTextureHostRef texture;
|
|
|
|
texture = TextureHost::AsTextureHost(op.textureParent());
|
2018-07-11 11:45:28 +03:00
|
|
|
if (!PushExternalImageForTexture(op.externalImageId(), op.key(), texture, op.isUpdate(), aUpdates)) {
|
2018-07-06 15:25:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-07-12 18:43:09 +03:00
|
|
|
case OpUpdateResource::TOpUpdateExternalImage: {
|
|
|
|
const auto& op = cmd.get_OpUpdateExternalImage();
|
|
|
|
if (!UpdateExternalImage(op.externalImageId(), op.key(), op.dirtyRect(), aUpdates)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-09-14 19:48:55 +03:00
|
|
|
case OpUpdateResource::TOpAddRawFont: {
|
|
|
|
const auto& op = cmd.get_OpAddRawFont();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-09-14 19:48:55 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aUpdates.AddRawFont(op.key(), bytes, op.fontIndex());
|
|
|
|
break;
|
|
|
|
}
|
2017-11-07 04:19:46 +03:00
|
|
|
case OpUpdateResource::TOpAddFontDescriptor: {
|
|
|
|
const auto& op = cmd.get_OpAddFontDescriptor();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> bytes;
|
2017-11-07 04:19:46 +03:00
|
|
|
if (!reader.Read(op.bytes(), bytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aUpdates.AddFontDescriptor(op.key(), bytes, op.fontIndex());
|
|
|
|
break;
|
|
|
|
}
|
2017-09-14 19:48:55 +03:00
|
|
|
case OpUpdateResource::TOpAddFontInstance: {
|
|
|
|
const auto& op = cmd.get_OpAddFontInstance();
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> variations;
|
2017-09-21 06:18:23 +03:00
|
|
|
if (!reader.Read(op.variations(), variations)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-14 19:48:55 +03:00
|
|
|
aUpdates.AddFontInstance(op.instanceKey(), op.fontKey(),
|
|
|
|
op.glyphSize(),
|
|
|
|
op.options().ptrOr(nullptr),
|
2017-09-21 06:18:23 +03:00
|
|
|
op.platformOptions().ptrOr(nullptr),
|
|
|
|
variations);
|
2017-09-14 19:48:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpDeleteImage: {
|
|
|
|
const auto& op = cmd.get_OpDeleteImage();
|
2018-10-02 20:27:52 +03:00
|
|
|
DeleteImage(op.key(), aUpdates);
|
2017-09-14 19:48:55 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpDeleteFont: {
|
|
|
|
const auto& op = cmd.get_OpDeleteFont();
|
|
|
|
aUpdates.DeleteFont(op.key());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::TOpDeleteFontInstance: {
|
|
|
|
const auto& op = cmd.get_OpDeleteFontInstance();
|
|
|
|
aUpdates.DeleteFontInstance(op.key());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OpUpdateResource::T__None: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:56:09 +03:00
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey,
|
2018-01-29 16:33:39 +03:00
|
|
|
wr::TransactionBuilder& aResources)
|
2017-09-20 11:56:09 +03:00
|
|
|
{
|
2017-09-26 16:30:51 +03:00
|
|
|
Range<wr::ImageKey> keys(&aKey, 1);
|
2017-09-20 11:56:09 +03:00
|
|
|
// Check if key is obsoleted.
|
|
|
|
if (keys[0].mNamespace != mIdNamespace) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
auto key = wr::AsUint64(aKey);
|
|
|
|
auto it = mSharedSurfaceIds.find(key);
|
|
|
|
if (it != mSharedSurfaceIds.end()) {
|
|
|
|
gfxCriticalNote << "Readding known shared surface: " << key;
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-23 14:57:15 +03:00
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
RefPtr<DataSourceSurface> dSurf = SharedSurfacesParent::Acquire(aExtId);
|
|
|
|
if (!dSurf) {
|
2018-07-06 15:25:33 +03:00
|
|
|
gfxCriticalNote << "DataSourceSurface of SharedSurfaces does not exist for extId:" << wr::AsUint64(aExtId);
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-30 20:10:29 +03:00
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
mSharedSurfaceIds.insert(std::make_pair(key, aExtId));
|
|
|
|
|
|
|
|
if (!gfxEnv::EnableWebRenderRecording()) {
|
|
|
|
wr::ImageDescriptor descriptor(dSurf->GetSize(), dSurf->Stride(),
|
|
|
|
dSurf->GetFormat());
|
|
|
|
aResources.AddExternalImage(aKey, descriptor, aExtId,
|
|
|
|
wr::WrExternalImageBufferType::ExternalBuffer,
|
|
|
|
0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-06 15:25:33 +03:00
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
if (!dSurf->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
|
|
|
|
gfxCriticalNote << "DataSourceSurface failed to map for Image for extId:" << wr::AsUint64(aExtId);
|
|
|
|
return false;
|
2017-09-20 11:56:09 +03:00
|
|
|
}
|
2017-10-30 20:10:29 +03:00
|
|
|
|
2018-07-06 15:25:33 +03:00
|
|
|
IntSize size = dSurf->GetSize();
|
|
|
|
wr::ImageDescriptor descriptor(size, map.mStride, dSurf->GetFormat());
|
|
|
|
wr::Vec<uint8_t> data;
|
|
|
|
data.PushBytes(Range<uint8_t>(map.mData, size.height * map.mStride));
|
|
|
|
aResources.AddImage(keys[0], descriptor, data);
|
|
|
|
dSurf->Unmap();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-11 11:45:28 +03:00
|
|
|
WebRenderBridgeParent::PushExternalImageForTexture(wr::ExternalImageId aExtId,
|
|
|
|
wr::ImageKey aKey,
|
|
|
|
TextureHost* aTexture,
|
|
|
|
bool aIsUpdate,
|
|
|
|
wr::TransactionBuilder& aResources)
|
2018-07-06 15:25:33 +03:00
|
|
|
{
|
2018-07-11 11:45:28 +03:00
|
|
|
auto op = aIsUpdate ? TextureHost::UPDATE_IMAGE : TextureHost::ADD_IMAGE;
|
2018-07-06 15:25:33 +03:00
|
|
|
Range<wr::ImageKey> keys(&aKey, 1);
|
|
|
|
// Check if key is obsoleted.
|
|
|
|
if (keys[0].mNamespace != mIdNamespace) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!aTexture) {
|
|
|
|
gfxCriticalNote << "TextureHost does not exist for extId:" << wr::AsUint64(aExtId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfxEnv::EnableWebRenderRecording()) {
|
|
|
|
WebRenderTextureHost* wrTexture = aTexture->AsWebRenderTextureHost();
|
|
|
|
if (wrTexture) {
|
2018-07-11 11:45:28 +03:00
|
|
|
wrTexture->PushResourceUpdates(aResources, op, keys,
|
2018-07-06 15:25:33 +03:00
|
|
|
wrTexture->GetExternalImageKey());
|
2018-07-11 11:45:28 +03:00
|
|
|
auto it = mTextureHosts.find(wr::AsUint64(aKey));
|
|
|
|
MOZ_ASSERT((it == mTextureHosts.end() && !aIsUpdate) ||
|
|
|
|
(it != mTextureHosts.end() && aIsUpdate));
|
|
|
|
if (it != mTextureHosts.end()) {
|
|
|
|
// Release Texture if it exists.
|
|
|
|
ReleaseTextureOfImage(aKey);
|
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
mTextureHosts.emplace(wr::AsUint64(aKey), CompositableTextureHostRef(aTexture));
|
2018-07-06 15:25:33 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefPtr<DataSourceSurface> dSurf = aTexture->GetAsSurface();
|
2017-09-20 11:56:09 +03:00
|
|
|
if (!dSurf) {
|
2018-01-11 15:44:00 +03:00
|
|
|
gfxCriticalNote << "TextureHost does not return DataSourceSurface for extId:" << wr::AsUint64(aExtId);
|
2017-09-20 11:56:09 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceSurface::MappedSurface map;
|
|
|
|
if (!dSurf->Map(gfx::DataSourceSurface::MapType::READ, &map)) {
|
2018-01-11 15:44:00 +03:00
|
|
|
gfxCriticalNote << "DataSourceSurface failed to map for Image for extId:" << wr::AsUint64(aExtId);
|
2017-09-20 11:56:09 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize size = dSurf->GetSize();
|
|
|
|
wr::ImageDescriptor descriptor(size, map.mStride, dSurf->GetFormat());
|
2018-01-04 21:23:34 +03:00
|
|
|
wr::Vec<uint8_t> data;
|
2017-09-20 11:56:09 +03:00
|
|
|
data.PushBytes(Range<uint8_t>(map.mData, size.height * map.mStride));
|
2018-07-11 11:45:28 +03:00
|
|
|
|
|
|
|
if (op == TextureHost::UPDATE_IMAGE) {
|
|
|
|
aResources.UpdateImageBuffer(keys[0], descriptor, data);
|
|
|
|
} else {
|
|
|
|
aResources.AddImage(keys[0], descriptor, data);
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:56:09 +03:00
|
|
|
dSurf->Unmap();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:43:09 +03:00
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::UpdateExternalImage(wr::ExternalImageId aExtId,
|
|
|
|
wr::ImageKey aKey,
|
|
|
|
const ImageIntRect& aDirtyRect,
|
|
|
|
wr::TransactionBuilder& aResources)
|
|
|
|
{
|
|
|
|
Range<wr::ImageKey> keys(&aKey, 1);
|
|
|
|
// Check if key is obsoleted.
|
|
|
|
if (keys[0].mNamespace != mIdNamespace) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
auto key = wr::AsUint64(aKey);
|
|
|
|
auto it = mSharedSurfaceIds.find(key);
|
|
|
|
if (it == mSharedSurfaceIds.end()) {
|
|
|
|
gfxCriticalNote << "Updating unknown shared surface: " << key;
|
2018-07-12 18:43:09 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
RefPtr<DataSourceSurface> dSurf;
|
|
|
|
if (it->second == aExtId) {
|
|
|
|
dSurf = SharedSurfacesParent::Get(aExtId);
|
|
|
|
} else {
|
|
|
|
dSurf = SharedSurfacesParent::Acquire(aExtId);
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:43:09 +03:00
|
|
|
if (!dSurf) {
|
|
|
|
gfxCriticalNote << "Shared surface does not exist for extId:" << wr::AsUint64(aExtId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
if (!(it->second == aExtId)) {
|
|
|
|
// We already have a mapping for this image key, so ensure we release the
|
|
|
|
// previous external image ID.
|
|
|
|
mAsyncImageManager->HoldExternalImage(mPipelineId, mWrEpoch, it->second);
|
|
|
|
it->second = aExtId;
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:43:09 +03:00
|
|
|
if (!gfxEnv::EnableWebRenderRecording()) {
|
|
|
|
wr::ImageDescriptor descriptor(dSurf->GetSize(), dSurf->Stride(),
|
|
|
|
dSurf->GetFormat());
|
|
|
|
aResources.UpdateExternalImageWithDirtyRect(aKey, descriptor, aExtId,
|
|
|
|
wr::WrExternalImageBufferType::ExternalBuffer,
|
|
|
|
wr::ToDeviceUintRect(aDirtyRect),
|
|
|
|
0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataSourceSurface::ScopedMap map(dSurf, DataSourceSurface::READ);
|
|
|
|
if (!map.IsMapped()) {
|
|
|
|
gfxCriticalNote << "DataSourceSurface failed to map for Image for extId:" << wr::AsUint64(aExtId);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize size = dSurf->GetSize();
|
|
|
|
wr::ImageDescriptor descriptor(size, map.GetStride(), dSurf->GetFormat());
|
|
|
|
wr::Vec<uint8_t> data;
|
|
|
|
data.PushBytes(Range<uint8_t>(map.GetData(), size.height * map.GetStride()));
|
|
|
|
aResources.UpdateImageBuffer(keys[0], descriptor, data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:54:51 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-09-14 19:48:55 +03:00
|
|
|
WebRenderBridgeParent::RecvUpdateResources(nsTArray<OpUpdateResource>&& aResourceUpdates,
|
2018-01-12 17:11:28 +03:00
|
|
|
nsTArray<RefCountedShmem>&& aSmallShmems,
|
2017-09-20 14:39:19 +03:00
|
|
|
nsTArray<ipc::Shmem>&& aLargeShmems)
|
2017-09-04 14:59:26 +03:00
|
|
|
{
|
2017-09-04 14:59:42 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(!IsRootWebRenderBridgeParent());
|
2017-09-14 19:48:55 +03:00
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
if (!UpdateResources(aResourceUpdates, aSmallShmems, aLargeShmems, txn)) {
|
2018-01-12 17:11:32 +03:00
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aSmallShmems);
|
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aLargeShmems);
|
2017-09-14 19:48:55 +03:00
|
|
|
IPC_FAIL(this, "Invalid WebRender resource data shmem or address.");
|
|
|
|
}
|
|
|
|
|
2018-01-12 14:24:07 +03:00
|
|
|
mApi->SendTransaction(txn);
|
|
|
|
|
2018-01-12 17:11:32 +03:00
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aSmallShmems);
|
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aLargeShmems);
|
2017-09-04 14:59:42 +03:00
|
|
|
return IPC_OK();
|
2017-09-04 14:59:26 +03:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:54:11 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-04-26 05:58:50 +03:00
|
|
|
WebRenderBridgeParent::RecvDeleteCompositorAnimations(InfallibleTArray<uint64_t>&& aIds)
|
2017-04-19 12:54:11 +03:00
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:32:31 +03:00
|
|
|
// Once mWrEpoch has been rendered, we can delete these compositor animations
|
2018-05-30 22:15:35 +03:00
|
|
|
mCompositorAnimationsToDelete.push(CompositorAnimationIdsForEpoch(mWrEpoch, std::move(aIds)));
|
2018-04-27 17:32:31 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderBridgeParent::RemoveEpochDataPriorTo(const wr::Epoch& aRenderedEpoch)
|
|
|
|
{
|
|
|
|
while (!mCompositorAnimationsToDelete.empty()) {
|
|
|
|
if (mCompositorAnimationsToDelete.front().mEpoch.mHandle > aRenderedEpoch.mHandle) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (uint64_t id : mCompositorAnimationsToDelete.front().mIds) {
|
|
|
|
if (mActiveAnimations.erase(id) > 0) {
|
|
|
|
mAnimStorage->ClearById(id);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Tried to delete invalid animation");
|
|
|
|
}
|
2017-06-15 10:36:03 +03:00
|
|
|
}
|
2018-04-27 17:32:31 +03:00
|
|
|
mCompositorAnimationsToDelete.pop();
|
2017-04-26 05:58:50 +03:00
|
|
|
}
|
2017-04-19 12:54:11 +03:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:37:31 +03:00
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::IsRootWebRenderBridgeParent() const
|
|
|
|
{
|
|
|
|
return !!mWidget;
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:58:17 +03:00
|
|
|
CompositorBridgeParent*
|
|
|
|
WebRenderBridgeParent::GetRootCompositorBridgeParent() const
|
2017-04-20 17:38:06 +03:00
|
|
|
{
|
|
|
|
if (!mCompositorBridge) {
|
2017-05-12 20:58:17 +03:00
|
|
|
return nullptr;
|
2017-04-20 17:38:06 +03:00
|
|
|
}
|
|
|
|
|
2018-06-26 21:37:31 +03:00
|
|
|
if (IsRootWebRenderBridgeParent()) {
|
2017-04-20 17:38:06 +03:00
|
|
|
// This WebRenderBridgeParent is attached to the root
|
|
|
|
// CompositorBridgeParent.
|
2017-05-12 20:58:17 +03:00
|
|
|
return static_cast<CompositorBridgeParent*>(mCompositorBridge);
|
2017-04-20 17:38:06 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:58:17 +03:00
|
|
|
// Otherwise, this WebRenderBridgeParent is attached to a
|
|
|
|
// CrossProcessCompositorBridgeParent so we have an extra level of
|
|
|
|
// indirection to unravel.
|
|
|
|
CompositorBridgeParent::LayerTreeState* lts =
|
2017-05-28 14:51:53 +03:00
|
|
|
CompositorBridgeParent::GetIndirectShadowTree(GetLayersId());
|
2017-08-23 07:44:22 +03:00
|
|
|
if (!lts) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-12 20:58:17 +03:00
|
|
|
return lts->mParent;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:13:39 +03:00
|
|
|
RefPtr<WebRenderBridgeParent>
|
|
|
|
WebRenderBridgeParent::GetRootWebRenderBridgeParent() const
|
|
|
|
{
|
|
|
|
CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
|
|
|
|
if (!cbp) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cbp->GetWebRenderBridgeParent();
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:58:17 +03:00
|
|
|
void
|
2018-04-10 19:29:56 +03:00
|
|
|
WebRenderBridgeParent::UpdateAPZFocusState(const FocusTarget& aFocus)
|
2017-05-12 20:58:17 +03:00
|
|
|
{
|
|
|
|
CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
|
|
|
|
if (!cbp) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-25 02:06:01 +03:00
|
|
|
LayersId rootLayersId = cbp->RootLayerTreeId();
|
2018-04-10 19:29:56 +03:00
|
|
|
if (RefPtr<APZUpdater> apz = cbp->GetAPZUpdater()) {
|
|
|
|
apz->UpdateFocusState(rootLayersId, GetLayersId(), aFocus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-04-10 19:30:01 +03:00
|
|
|
WebRenderBridgeParent::UpdateAPZScrollData(const wr::Epoch& aEpoch,
|
|
|
|
WebRenderScrollData&& aData)
|
2018-04-10 19:29:56 +03:00
|
|
|
{
|
|
|
|
CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
|
|
|
|
if (!cbp) {
|
2017-04-20 17:38:06 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-10 19:29:56 +03:00
|
|
|
LayersId rootLayersId = cbp->RootLayerTreeId();
|
2018-03-29 01:36:42 +03:00
|
|
|
if (RefPtr<APZUpdater> apz = cbp->GetAPZUpdater()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
apz->UpdateScrollDataAndTreeState(rootLayersId, GetLayersId(), aEpoch, std::move(aData));
|
2017-04-20 17:38:06 +03:00
|
|
|
}
|
2016-12-30 00:51:32 +03:00
|
|
|
}
|
|
|
|
|
2018-05-12 04:18:22 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::UpdateAPZScrollOffsets(ScrollUpdatesMap&& aUpdates,
|
|
|
|
uint32_t aPaintSequenceNumber)
|
|
|
|
{
|
|
|
|
CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
|
|
|
|
if (!cbp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LayersId rootLayersId = cbp->RootLayerTreeId();
|
|
|
|
if (RefPtr<APZUpdater> apz = cbp->GetAPZUpdater()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
apz->UpdateScrollOffsets(rootLayersId, GetLayersId(), std::move(aUpdates), aPaintSequenceNumber);
|
2018-05-12 04:18:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 00:39:26 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::SetAPZSampleTime()
|
2017-05-12 20:58:20 +03:00
|
|
|
{
|
|
|
|
CompositorBridgeParent* cbp = GetRootCompositorBridgeParent();
|
|
|
|
if (!cbp) {
|
2018-04-17 00:39:26 +03:00
|
|
|
return;
|
2017-05-12 20:58:20 +03:00
|
|
|
}
|
2018-03-06 18:25:37 +03:00
|
|
|
if (RefPtr<APZSampler> apz = cbp->GetAPZSampler()) {
|
2017-06-28 03:29:05 +03:00
|
|
|
TimeStamp animationTime = cbp->GetTestingTimeStamp().valueOr(
|
|
|
|
mCompositorScheduler->GetLastComposeTime());
|
2017-05-12 20:58:20 +03:00
|
|
|
TimeDuration frameInterval = cbp->GetVsyncInterval();
|
|
|
|
// As with the non-webrender codepath in AsyncCompositionManager, we want to
|
|
|
|
// use the timestamp for the next vsync when advancing animations.
|
|
|
|
if (frameInterval != TimeDuration::Forever()) {
|
|
|
|
animationTime += frameInterval;
|
|
|
|
}
|
2018-04-17 00:39:26 +03:00
|
|
|
apz->SetSampleTime(animationTime);
|
2017-05-12 20:58:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-30 00:51:32 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-09-04 14:59:26 +03:00
|
|
|
WebRenderBridgeParent::RecvSetDisplayList(const gfx::IntSize& aSize,
|
|
|
|
InfallibleTArray<WebRenderParentCommand>&& aCommands,
|
|
|
|
InfallibleTArray<OpDestroy>&& aToDestroy,
|
|
|
|
const uint64_t& aFwdTransactionId,
|
2018-04-20 22:13:06 +03:00
|
|
|
const TransactionId& aTransactionId,
|
2017-09-04 14:59:26 +03:00
|
|
|
const wr::LayoutSize& aContentSize,
|
2017-11-30 15:16:21 +03:00
|
|
|
ipc::ByteBuf&& dl,
|
2017-09-04 14:59:26 +03:00
|
|
|
const wr::BuiltDisplayListDescriptor& dlDesc,
|
|
|
|
const WebRenderScrollData& aScrollData,
|
2017-09-14 19:48:55 +03:00
|
|
|
nsTArray<OpUpdateResource>&& aResourceUpdates,
|
2018-01-12 17:11:28 +03:00
|
|
|
nsTArray<RefCountedShmem>&& aSmallShmems,
|
2017-09-20 14:39:19 +03:00
|
|
|
nsTArray<ipc::Shmem>&& aLargeShmems,
|
2017-09-04 14:59:26 +03:00
|
|
|
const wr::IdNamespace& aIdNamespace,
|
2018-09-18 06:13:18 +03:00
|
|
|
const bool& aContainsSVGGroup,
|
2018-06-26 21:43:14 +03:00
|
|
|
const TimeStamp& aRefreshStartTime,
|
2017-09-04 14:59:26 +03:00
|
|
|
const TimeStamp& aTxnStartTime,
|
|
|
|
const TimeStamp& aFwdTime)
|
2017-03-02 04:36:27 +03:00
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
2017-09-04 14:59:26 +03:00
|
|
|
for (const auto& op : aToDestroy) {
|
|
|
|
DestroyActor(op);
|
|
|
|
}
|
2017-06-05 09:41:21 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-09-04 14:59:26 +03:00
|
|
|
|
2017-10-04 01:11:18 +03:00
|
|
|
AUTO_PROFILER_TRACING("Paint", "SetDisplayList");
|
2017-09-04 14:59:26 +03:00
|
|
|
UpdateFwdTransactionId(aFwdTransactionId);
|
|
|
|
|
|
|
|
// This ensures that destroy operations are always processed. It is not safe
|
|
|
|
// to early-return from RecvDPEnd without doing so.
|
|
|
|
AutoWebRenderBridgeParentAsyncMessageSender autoAsyncMessageSender(this, &aToDestroy);
|
|
|
|
|
2018-04-10 19:29:56 +03:00
|
|
|
wr::Epoch wrEpoch = GetNextWrEpoch();
|
2017-09-20 11:56:09 +03:00
|
|
|
|
|
|
|
mAsyncImageManager->SetCompositionTime(TimeStamp::Now());
|
2018-01-12 14:24:03 +03:00
|
|
|
|
2018-08-21 15:29:09 +03:00
|
|
|
// If id namespaces do not match, it means the command is obsolete, probably
|
|
|
|
// because the tab just moved to a new window.
|
|
|
|
// In that case do not send the commands to webrender.
|
|
|
|
bool validTransaction = aIdNamespace == mIdNamespace;
|
2018-01-29 16:33:39 +03:00
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(!IsRootWebRenderBridgeParent());
|
2018-08-21 15:29:09 +03:00
|
|
|
Maybe<wr::AutoTransactionSender> sender;
|
|
|
|
if (validTransaction) {
|
|
|
|
sender.emplace(mApi, &txn);
|
|
|
|
}
|
2018-05-08 15:49:44 +03:00
|
|
|
|
2018-09-06 05:36:10 +03:00
|
|
|
if (!ProcessWebRenderParentCommands(aCommands, txn)) {
|
|
|
|
return IPC_FAIL(this, "Invalid parent command found");
|
|
|
|
}
|
2018-05-08 15:49:44 +03:00
|
|
|
|
2018-01-29 16:33:39 +03:00
|
|
|
if (!UpdateResources(aResourceUpdates, aSmallShmems, aLargeShmems, txn)) {
|
2017-09-20 14:39:19 +03:00
|
|
|
return IPC_FAIL(this, "Failed to deserialize resource updates");
|
|
|
|
}
|
2017-09-04 14:59:26 +03:00
|
|
|
|
2018-03-06 22:20:56 +03:00
|
|
|
mReceivedDisplayList = true;
|
|
|
|
|
2018-10-19 16:48:04 +03:00
|
|
|
if (aScrollData.IsFirstPaint()) {
|
|
|
|
mIsFirstPaint = true;
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:30:01 +03:00
|
|
|
// aScrollData is moved into this function but that is not reflected by the
|
|
|
|
// function signature due to the way the IPDL generator works. We remove the
|
|
|
|
// const so that we can move this structure all the way to the desired
|
|
|
|
// destination.
|
|
|
|
// Also note that this needs to happen before the display list transaction is
|
|
|
|
// sent to WebRender, so that the UpdateHitTestingTree call is guaranteed to
|
|
|
|
// be in the updater queue at the time that the scene swap completes.
|
2018-05-30 22:15:35 +03:00
|
|
|
UpdateAPZScrollData(wrEpoch, std::move(const_cast<WebRenderScrollData&>(aScrollData)));
|
2018-04-10 19:30:01 +03:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
wr::Vec<uint8_t> dlData(std::move(dl));
|
2017-12-01 02:14:41 +03:00
|
|
|
|
2018-09-21 19:47:18 +03:00
|
|
|
bool observeLayersUpdate = ShouldParentObserveEpoch();
|
|
|
|
|
2018-08-21 15:29:09 +03:00
|
|
|
if (validTransaction) {
|
2018-06-26 21:37:31 +03:00
|
|
|
if (IsRootWebRenderBridgeParent()) {
|
2018-01-29 16:33:35 +03:00
|
|
|
LayoutDeviceIntSize widgetSize = mWidget->GetClientSize();
|
|
|
|
LayoutDeviceIntRect docRect(LayoutDeviceIntPoint(), widgetSize);
|
|
|
|
txn.SetWindowParameters(widgetSize, docRect);
|
2017-09-20 11:56:09 +03:00
|
|
|
}
|
2017-09-28 17:30:58 +03:00
|
|
|
gfx::Color clearColor(0.f, 0.f, 0.f, 0.f);
|
2018-04-10 19:29:56 +03:00
|
|
|
txn.SetDisplayList(clearColor, wrEpoch, LayerSize(aSize.width, aSize.height),
|
2018-01-12 14:24:03 +03:00
|
|
|
mPipelineId, aContentSize,
|
|
|
|
dlDesc, dlData);
|
|
|
|
|
2018-09-21 19:47:18 +03:00
|
|
|
if (observeLayersUpdate) {
|
|
|
|
txn.Notify(
|
|
|
|
wr::Checkpoint::SceneBuilt,
|
|
|
|
MakeUnique<ScheduleObserveLayersUpdate>(
|
|
|
|
mCompositorBridge,
|
|
|
|
GetLayersId(),
|
|
|
|
mChildLayersObserverEpoch,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-12 14:24:03 +03:00
|
|
|
mApi->SendTransaction(txn);
|
2017-09-20 11:56:09 +03:00
|
|
|
|
2018-07-10 15:49:21 +03:00
|
|
|
// We will schedule generating a frame after the scene
|
|
|
|
// build is done, so we don't need to do it here.
|
2018-09-21 19:47:18 +03:00
|
|
|
} else if (observeLayersUpdate) {
|
|
|
|
mCompositorBridge->ObserveLayersUpdate(GetLayersId(), mChildLayersObserverEpoch, true);
|
2017-09-20 11:56:09 +03:00
|
|
|
}
|
|
|
|
|
2018-09-18 06:13:18 +03:00
|
|
|
HoldPendingTransactionId(wrEpoch, aTransactionId, aContainsSVGGroup,
|
2018-10-19 16:48:04 +03:00
|
|
|
aRefreshStartTime, aTxnStartTime, aFwdTime, mIsFirstPaint);
|
|
|
|
mIsFirstPaint = false;
|
2017-09-04 14:59:26 +03:00
|
|
|
|
2018-08-21 15:29:09 +03:00
|
|
|
if (!validTransaction) {
|
2017-09-04 14:59:26 +03:00
|
|
|
// Pretend we composited since someone is wating for this event,
|
|
|
|
// though DisplayList was not pushed to webrender.
|
2018-07-27 16:42:30 +03:00
|
|
|
if (CompositorBridgeParent* cbp = GetRootCompositorBridgeParent()) {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
cbp->NotifyPipelineRendered(mPipelineId, wrEpoch, now, now);
|
|
|
|
}
|
2017-09-04 14:59:26 +03:00
|
|
|
}
|
|
|
|
|
2018-01-12 17:11:32 +03:00
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aSmallShmems);
|
|
|
|
wr::IpcResourceUpdateQueue::ReleaseShmems(this, aLargeShmems);
|
2016-11-21 18:16:11 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-12 04:13:10 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvEmptyTransaction(const FocusTarget& aFocusTarget,
|
2018-05-12 04:18:22 +03:00
|
|
|
const ScrollUpdatesMap& aUpdates,
|
|
|
|
const uint32_t& aPaintSequenceNumber,
|
2017-10-12 04:13:10 +03:00
|
|
|
InfallibleTArray<WebRenderParentCommand>&& aCommands,
|
|
|
|
InfallibleTArray<OpDestroy>&& aToDestroy,
|
|
|
|
const uint64_t& aFwdTransactionId,
|
2018-04-20 22:13:06 +03:00
|
|
|
const TransactionId& aTransactionId,
|
2017-10-12 04:13:10 +03:00
|
|
|
const wr::IdNamespace& aIdNamespace,
|
2018-06-26 21:43:14 +03:00
|
|
|
const TimeStamp& aRefreshStartTime,
|
2017-10-12 04:13:10 +03:00
|
|
|
const TimeStamp& aTxnStartTime,
|
|
|
|
const TimeStamp& aFwdTime)
|
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
for (const auto& op : aToDestroy) {
|
|
|
|
DestroyActor(op);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-13 22:03:13 +03:00
|
|
|
AUTO_PROFILER_TRACING("Paint", "EmptyTransaction");
|
2017-10-12 04:13:10 +03:00
|
|
|
UpdateFwdTransactionId(aFwdTransactionId);
|
|
|
|
|
|
|
|
// This ensures that destroy operations are always processed. It is not safe
|
|
|
|
// to early-return without doing so.
|
|
|
|
AutoWebRenderBridgeParentAsyncMessageSender autoAsyncMessageSender(this, &aToDestroy);
|
|
|
|
|
2018-05-15 15:49:34 +03:00
|
|
|
bool scheduleComposite = false;
|
2017-10-12 04:13:10 +03:00
|
|
|
|
2018-04-10 19:29:56 +03:00
|
|
|
UpdateAPZFocusState(aFocusTarget);
|
2018-05-12 04:18:22 +03:00
|
|
|
if (!aUpdates.empty()) {
|
|
|
|
// aUpdates is moved into this function but that is not reflected by the
|
|
|
|
// function signature due to the way the IPDL generator works. We remove the
|
|
|
|
// const so that we can move this structure all the way to the desired
|
|
|
|
// destination.
|
2018-05-30 22:15:35 +03:00
|
|
|
UpdateAPZScrollOffsets(std::move(const_cast<ScrollUpdatesMap&>(aUpdates)), aPaintSequenceNumber);
|
2018-05-15 15:49:34 +03:00
|
|
|
scheduleComposite = true;
|
2018-05-12 04:18:22 +03:00
|
|
|
}
|
2017-10-12 04:13:10 +03:00
|
|
|
|
2017-11-15 02:00:57 +03:00
|
|
|
if (!aCommands.IsEmpty()) {
|
2018-05-15 15:49:34 +03:00
|
|
|
mAsyncImageManager->SetCompositionTime(TimeStamp::Now());
|
2018-01-12 14:24:03 +03:00
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(!IsRootWebRenderBridgeParent());
|
2018-04-10 19:29:56 +03:00
|
|
|
wr::Epoch wrEpoch = GetNextWrEpoch();
|
|
|
|
txn.UpdateEpoch(mPipelineId, wrEpoch);
|
2018-09-06 05:36:10 +03:00
|
|
|
if (!ProcessWebRenderParentCommands(aCommands, txn)) {
|
|
|
|
return IPC_FAIL(this, "Invalid parent command found");
|
|
|
|
}
|
2018-09-21 19:47:18 +03:00
|
|
|
if (ShouldParentObserveEpoch()) {
|
|
|
|
txn.Notify(
|
|
|
|
wr::Checkpoint::SceneBuilt,
|
|
|
|
MakeUnique<ScheduleObserveLayersUpdate>(
|
|
|
|
mCompositorBridge,
|
|
|
|
GetLayersId(),
|
|
|
|
mChildLayersObserverEpoch,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-12 14:24:03 +03:00
|
|
|
mApi->SendTransaction(txn);
|
2018-05-15 15:49:34 +03:00
|
|
|
scheduleComposite = true;
|
|
|
|
}
|
2018-01-12 14:24:03 +03:00
|
|
|
|
2018-05-15 15:49:34 +03:00
|
|
|
bool sendDidComposite = true;
|
|
|
|
if (scheduleComposite || !mPendingTransactionIds.empty()) {
|
|
|
|
// If we are going to kick off a new composite as a result of this
|
|
|
|
// transaction, or if there are already composite-triggering pending
|
|
|
|
// transactions inflight, then set sendDidComposite to false because we will
|
|
|
|
// send the DidComposite message after the composite occurs.
|
|
|
|
// If there are no pending transactions and we're not going to do a
|
|
|
|
// composite, then we leave sendDidComposite as true so we just send
|
|
|
|
// the DidComposite notification now.
|
|
|
|
sendDidComposite = false;
|
|
|
|
}
|
|
|
|
|
2018-08-15 08:13:49 +03:00
|
|
|
// Only register a value for CONTENT_FRAME_TIME telemetry if we actually drew
|
|
|
|
// something. It is for consistency with disabling WebRender.
|
|
|
|
HoldPendingTransactionId(mWrEpoch,
|
|
|
|
aTransactionId,
|
2018-09-18 06:13:18 +03:00
|
|
|
false,
|
2018-08-15 08:13:49 +03:00
|
|
|
aRefreshStartTime,
|
|
|
|
aTxnStartTime,
|
|
|
|
aFwdTime,
|
2018-10-19 16:48:04 +03:00
|
|
|
/* aIsFirstPaint */false,
|
2018-08-15 08:13:49 +03:00
|
|
|
/* aUseForTelemetry */scheduleComposite);
|
2018-05-15 15:49:34 +03:00
|
|
|
|
|
|
|
if (scheduleComposite) {
|
|
|
|
ScheduleGenerateFrame();
|
|
|
|
} else if (sendDidComposite) {
|
2018-07-27 16:42:30 +03:00
|
|
|
// The only thing in the pending transaction id queue should be the entry
|
|
|
|
// we just added, and now we're going to pretend we rendered it
|
|
|
|
MOZ_ASSERT(mPendingTransactionIds.size() == 1);
|
|
|
|
if (CompositorBridgeParent* cbp = GetRootCompositorBridgeParent()) {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
2018-07-27 16:43:41 +03:00
|
|
|
cbp->NotifyPipelineRendered(mPipelineId, mWrEpoch, now, now);
|
2018-07-27 16:42:30 +03:00
|
|
|
}
|
2017-11-15 02:00:57 +03:00
|
|
|
}
|
2018-01-12 14:24:03 +03:00
|
|
|
|
2017-10-12 04:13:10 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-02 23:49:55 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSetFocusTarget(const FocusTarget& aFocusTarget)
|
|
|
|
{
|
2018-04-10 19:29:56 +03:00
|
|
|
UpdateAPZFocusState(aFocusTarget);
|
2017-10-02 23:49:55 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-06-15 07:38:22 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvParentCommands(nsTArray<WebRenderParentCommand>&& aCommands)
|
2016-11-16 16:54:51 +03:00
|
|
|
{
|
2017-06-15 07:38:22 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2018-05-08 15:49:44 +03:00
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(!IsRootWebRenderBridgeParent());
|
2018-09-06 05:36:10 +03:00
|
|
|
if (!ProcessWebRenderParentCommands(aCommands, txn)) {
|
|
|
|
return IPC_FAIL(this, "Invalid parent command found");
|
|
|
|
}
|
2018-05-08 15:49:44 +03:00
|
|
|
mApi->SendTransaction(txn);
|
2017-06-15 07:38:22 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
2016-12-05 07:15:02 +03:00
|
|
|
|
2018-09-06 05:36:10 +03:00
|
|
|
bool
|
2018-05-08 15:49:44 +03:00
|
|
|
WebRenderBridgeParent::ProcessWebRenderParentCommands(const InfallibleTArray<WebRenderParentCommand>& aCommands,
|
|
|
|
wr::TransactionBuilder& aTxn)
|
2017-06-15 07:38:22 +03:00
|
|
|
{
|
2018-09-26 05:45:30 +03:00
|
|
|
// Transaction for async image pipeline that uses ImageBridge always need to be non low priority.
|
|
|
|
wr::TransactionBuilder txnForImageBridge;
|
|
|
|
wr::AutoTransactionSender sender(mApi, &txnForImageBridge);
|
|
|
|
|
2017-03-03 00:33:03 +03:00
|
|
|
for (InfallibleTArray<WebRenderParentCommand>::index_type i = 0; i < aCommands.Length(); ++i) {
|
|
|
|
const WebRenderParentCommand& cmd = aCommands[i];
|
2016-11-18 11:07:02 +03:00
|
|
|
switch (cmd.type()) {
|
2018-04-12 16:13:06 +03:00
|
|
|
case WebRenderParentCommand::TOpAddPipelineIdForCompositable: {
|
|
|
|
const OpAddPipelineIdForCompositable& op = cmd.get_OpAddPipelineIdForCompositable();
|
|
|
|
AddPipelineIdForCompositable(op.pipelineId(),
|
|
|
|
op.handle(),
|
2018-07-19 01:51:37 +03:00
|
|
|
op.isAsync(),
|
2018-09-26 05:45:30 +03:00
|
|
|
aTxn,
|
|
|
|
txnForImageBridge);
|
2018-04-12 16:13:06 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WebRenderParentCommand::TOpRemovePipelineIdForCompositable: {
|
|
|
|
const OpRemovePipelineIdForCompositable& op = cmd.get_OpRemovePipelineIdForCompositable();
|
2018-05-08 15:49:44 +03:00
|
|
|
RemovePipelineIdForCompositable(op.pipelineId(), aTxn);
|
2018-04-12 16:13:06 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-07-06 15:25:33 +03:00
|
|
|
case WebRenderParentCommand::TOpReleaseTextureOfImage: {
|
|
|
|
const OpReleaseTextureOfImage& op = cmd.get_OpReleaseTextureOfImage();
|
|
|
|
ReleaseTextureOfImage(op.key());
|
|
|
|
break;
|
|
|
|
}
|
2017-06-02 10:11:34 +03:00
|
|
|
case WebRenderParentCommand::TOpUpdateAsyncImagePipeline: {
|
|
|
|
const OpUpdateAsyncImagePipeline& op = cmd.get_OpUpdateAsyncImagePipeline();
|
2017-07-25 11:54:36 +03:00
|
|
|
mAsyncImageManager->UpdateAsyncImagePipeline(op.pipelineId(),
|
2018-04-12 16:13:06 +03:00
|
|
|
op.scBounds(),
|
|
|
|
op.scTransform(),
|
|
|
|
op.scaleToSize(),
|
|
|
|
op.filter(),
|
|
|
|
op.mixBlendMode());
|
2018-09-26 05:45:30 +03:00
|
|
|
mAsyncImageManager->ApplyAsyncImageForPipeline(op.pipelineId(), aTxn, txnForImageBridge);
|
2018-07-19 01:51:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WebRenderParentCommand::TOpUpdatedAsyncImagePipeline: {
|
|
|
|
const OpUpdatedAsyncImagePipeline& op = cmd.get_OpUpdatedAsyncImagePipeline();
|
2018-09-26 05:45:30 +03:00
|
|
|
mAsyncImageManager->ApplyAsyncImageForPipeline(op.pipelineId(), aTxn, txnForImageBridge);
|
2016-12-05 07:15:02 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-03-03 00:33:03 +03:00
|
|
|
case WebRenderParentCommand::TCompositableOperation: {
|
2016-12-07 02:34:54 +03:00
|
|
|
if (!ReceiveCompositableUpdate(cmd.get_CompositableOperation())) {
|
2016-12-05 07:15:02 +03:00
|
|
|
NS_ERROR("ReceiveCompositableUpdate failed");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-03-28 12:11:03 +03:00
|
|
|
case WebRenderParentCommand::TOpAddCompositorAnimations: {
|
|
|
|
const OpAddCompositorAnimations& op = cmd.get_OpAddCompositorAnimations();
|
2018-05-30 22:15:35 +03:00
|
|
|
CompositorAnimations data(std::move(op.data()));
|
2018-09-06 05:36:10 +03:00
|
|
|
// AnimationHelper::GetNextCompositorAnimationsId() encodes the child process PID
|
|
|
|
// in the upper 32 bits of the id, verify that this is as expected.
|
|
|
|
if ((data.id() >> 32) != (uint64_t)OtherPid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-28 12:11:03 +03:00
|
|
|
if (data.animations().Length()) {
|
2017-06-15 10:36:03 +03:00
|
|
|
mAnimStorage->SetAnimations(data.id(), data.animations());
|
|
|
|
mActiveAnimations.insert(data.id());
|
2017-03-28 12:11:03 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-03-02 04:36:27 +03:00
|
|
|
default: {
|
|
|
|
// other commands are handle on the child
|
2017-02-16 21:23:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-11-18 11:07:02 +03:00
|
|
|
}
|
|
|
|
}
|
2018-09-06 05:36:10 +03:00
|
|
|
return true;
|
2017-06-15 07:38:22 +03:00
|
|
|
}
|
|
|
|
|
2018-05-28 18:29:52 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::FlushSceneBuilds()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
2018-07-10 15:49:21 +03:00
|
|
|
// Since we are sending transactions through the scene builder thread, we need
|
|
|
|
// to block until all the inflight transactions have been processed. This
|
|
|
|
// flush message blocks until all previously sent scenes have been built
|
|
|
|
// and received by the render backend thread.
|
|
|
|
mApi->FlushSceneBuilder();
|
|
|
|
// The post-swap hook for async-scene-building calls the
|
|
|
|
// ScheduleRenderOnCompositorThread function from the scene builder thread,
|
|
|
|
// which then triggers a call to ScheduleGenerateFrame() on the compositor
|
|
|
|
// thread. But since *this* function is running on the compositor thread,
|
|
|
|
// that scheduling will not happen until this call stack unwinds (or we
|
|
|
|
// could spin a nested event loop, but that's more messy). Instead, we
|
|
|
|
// simulate it ourselves by calling ScheduleGenerateFrame() directly.
|
|
|
|
// Note also that the post-swap hook will run and do another
|
|
|
|
// ScheduleGenerateFrame() after we unwind here, so we will end up with an
|
|
|
|
// extra render/composite that is probably avoidable, but in practice we
|
|
|
|
// shouldn't be calling this function all that much in production so this
|
|
|
|
// is probably fine. If it becomes an issue we can add more state tracking
|
|
|
|
// machinery to optimize it away.
|
|
|
|
ScheduleGenerateFrame();
|
2018-05-28 18:29:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderBridgeParent::FlushFrameGeneration()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent()); // This function is only useful on the root WRBP
|
2018-05-28 18:29:52 +03:00
|
|
|
|
|
|
|
// This forces a new GenerateFrame transaction to be sent to the render
|
|
|
|
// backend thread, if one is pending. This doesn't block on any other threads.
|
2018-08-10 02:10:11 +03:00
|
|
|
if (mCompositorScheduler->NeedsComposite()) {
|
|
|
|
mCompositorScheduler->CancelCurrentCompositeTask();
|
|
|
|
// Update timestamp of scheduler for APZ and animation.
|
|
|
|
mCompositorScheduler->UpdateLastComposeTime();
|
|
|
|
MaybeGenerateFrame(/* aForceGenerateFrame */ true);
|
|
|
|
}
|
2018-05-28 18:29:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderBridgeParent::FlushFramePresentation()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
|
|
|
|
|
|
|
// This sends a message to the render backend thread to send a message
|
|
|
|
// to the renderer thread, and waits for that message to be processed. So
|
|
|
|
// this effectively blocks on the render backend and renderer threads,
|
|
|
|
// following the same codepath that WebRender takes to render and composite
|
|
|
|
// a frame.
|
|
|
|
mApi->WaitFlushed();
|
|
|
|
}
|
|
|
|
|
2016-11-19 03:10:53 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-09-04 14:59:26 +03:00
|
|
|
WebRenderBridgeParent::RecvGetSnapshot(PTextureParent* aTexture)
|
2016-11-19 03:10:53 +03:00
|
|
|
{
|
2016-11-28 04:21:33 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-04-05 17:12:11 +03:00
|
|
|
MOZ_ASSERT(!mPaused);
|
2016-11-28 05:39:42 +03:00
|
|
|
|
2018-04-18 23:44:03 +03:00
|
|
|
// This function should only get called in the root WRBP. If this function
|
|
|
|
// gets called in a non-root WRBP, we will set mForceRendering in this WRBP
|
|
|
|
// but it will have no effect because CompositeToTarget (which reads the
|
|
|
|
// flag) only gets invoked in the root WRBP. So we assert that this is the
|
|
|
|
// root WRBP (i.e. has a non-null mWidget) to catch violations of this rule.
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
2018-04-18 23:44:03 +03:00
|
|
|
|
2016-11-28 05:39:42 +03:00
|
|
|
RefPtr<TextureHost> texture = TextureHost::AsTextureHost(aTexture);
|
|
|
|
if (!texture) {
|
|
|
|
// We kill the content process rather than have it continue with an invalid
|
|
|
|
// snapshot, that may be too harsh and we could decide to return some sort
|
|
|
|
// of error to the child process and let it deal with it...
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Add other TextureHost supports.
|
|
|
|
// Only BufferTextureHost is supported now.
|
|
|
|
BufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
|
|
|
|
if (!bufferTexture) {
|
|
|
|
// We kill the content process rather than have it continue with an invalid
|
|
|
|
// snapshot, that may be too harsh and we could decide to return some sort
|
|
|
|
// of error to the child process and let it deal with it...
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
2018-06-26 00:37:35 +03:00
|
|
|
TimeStamp start = TimeStamp::Now();
|
2016-11-28 05:39:42 +03:00
|
|
|
MOZ_ASSERT(bufferTexture->GetBufferDescriptor().type() == BufferDescriptor::TRGBDescriptor);
|
2016-12-04 11:53:28 +03:00
|
|
|
DebugOnly<uint32_t> stride = ImageDataSerializer::GetRGBStride(bufferTexture->GetBufferDescriptor().get_RGBDescriptor());
|
2016-12-02 21:39:40 +03:00
|
|
|
uint8_t* buffer = bufferTexture->GetBuffer();
|
|
|
|
IntSize size = bufferTexture->GetSize();
|
2016-11-28 05:39:42 +03:00
|
|
|
|
2016-12-02 21:39:40 +03:00
|
|
|
// We only support B8G8R8A8 for now.
|
|
|
|
MOZ_ASSERT(buffer);
|
|
|
|
MOZ_ASSERT(bufferTexture->GetFormat() == SurfaceFormat::B8G8R8A8);
|
|
|
|
uint32_t buffer_size = size.width * size.height * 4;
|
2016-11-19 03:10:53 +03:00
|
|
|
|
2016-12-10 12:30:49 +03:00
|
|
|
// Assert the stride of the buffer is what webrender expects
|
2016-12-02 21:39:40 +03:00
|
|
|
MOZ_ASSERT((uint32_t)(size.width * 4) == stride);
|
2016-11-19 03:10:53 +03:00
|
|
|
|
2018-05-24 23:16:00 +03:00
|
|
|
FlushSceneBuilds();
|
|
|
|
FlushFrameGeneration();
|
2018-10-17 01:54:01 +03:00
|
|
|
mApi->Readback(start, size, Range<uint8_t>(buffer, buffer_size));
|
2016-11-19 03:10:53 +03:00
|
|
|
|
2016-11-18 16:56:47 +03:00
|
|
|
return IPC_OK();
|
2016-11-16 16:54:51 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 16:13:06 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::AddPipelineIdForCompositable(const wr::PipelineId& aPipelineId,
|
|
|
|
const CompositableHandle& aHandle,
|
2018-07-19 01:51:37 +03:00
|
|
|
const bool& aAsync,
|
2018-09-26 05:45:30 +03:00
|
|
|
wr::TransactionBuilder& aTxn,
|
|
|
|
wr::TransactionBuilder& aTxnForImageBridge)
|
2016-11-24 09:48:01 +03:00
|
|
|
{
|
2016-11-28 04:21:33 +03:00
|
|
|
if (mDestroyed) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-11-28 04:21:33 +03:00
|
|
|
}
|
2017-01-19 02:46:21 +03:00
|
|
|
|
2018-07-10 05:06:08 +03:00
|
|
|
MOZ_ASSERT(mAsyncCompositables.find(wr::AsUint64(aPipelineId)) == mAsyncCompositables.end());
|
2016-11-24 09:48:01 +03:00
|
|
|
|
2017-08-03 08:55:13 +03:00
|
|
|
RefPtr<CompositableHost> host;
|
|
|
|
if (aAsync) {
|
|
|
|
RefPtr<ImageBridgeParent> imageBridge = ImageBridgeParent::GetInstance(OtherPid());
|
|
|
|
if (!imageBridge) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2017-08-03 08:55:13 +03:00
|
|
|
}
|
|
|
|
host = imageBridge->FindCompositable(aHandle);
|
|
|
|
} else {
|
|
|
|
host = FindCompositable(aHandle);
|
2017-01-05 18:03:17 +03:00
|
|
|
}
|
|
|
|
if (!host) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-11-24 09:48:01 +03:00
|
|
|
}
|
2017-11-03 10:38:34 +03:00
|
|
|
|
2017-04-27 19:34:54 +03:00
|
|
|
WebRenderImageHost* wrHost = host->AsWebRenderImageHost();
|
2017-11-03 10:38:34 +03:00
|
|
|
MOZ_ASSERT(wrHost);
|
|
|
|
if (!wrHost) {
|
|
|
|
gfxCriticalNote << "Incompatible CompositableHost at WebRenderBridgeParent.";
|
|
|
|
}
|
|
|
|
|
2017-04-27 19:34:54 +03:00
|
|
|
if (!wrHost) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-11-24 09:48:01 +03:00
|
|
|
}
|
|
|
|
|
2017-05-16 08:18:54 +03:00
|
|
|
wrHost->SetWrBridge(this);
|
2017-10-28 00:54:56 +03:00
|
|
|
wrHost->EnableUseAsyncImagePipeline();
|
2018-07-10 05:06:08 +03:00
|
|
|
mAsyncCompositables.emplace(wr::AsUint64(aPipelineId), wrHost);
|
2017-07-25 11:54:36 +03:00
|
|
|
mAsyncImageManager->AddAsyncImagePipeline(aPipelineId, wrHost);
|
2017-02-10 18:16:47 +03:00
|
|
|
|
2018-07-19 01:51:37 +03:00
|
|
|
// If this is being called from WebRenderBridgeParent::RecvSetDisplayList,
|
|
|
|
// then aTxn might contain a display list that references pipelines that
|
|
|
|
// we just added to the async image manager.
|
|
|
|
// If we send the display list alone then WR will not yet have the content for
|
|
|
|
// the pipelines and so it will emit errors; the SetEmptyDisplayList call
|
|
|
|
// below ensure that we provide its content to WR as part of the same transaction.
|
2018-09-26 05:45:30 +03:00
|
|
|
mAsyncImageManager->SetEmptyDisplayList(aPipelineId, aTxn, aTxnForImageBridge);
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-12-08 04:52:24 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 16:13:06 +03:00
|
|
|
void
|
2018-04-30 16:35:41 +03:00
|
|
|
WebRenderBridgeParent::RemovePipelineIdForCompositable(const wr::PipelineId& aPipelineId,
|
|
|
|
wr::TransactionBuilder& aTxn)
|
2017-06-02 10:11:34 +03:00
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2017-06-02 10:11:34 +03:00
|
|
|
}
|
|
|
|
|
2018-07-10 05:06:08 +03:00
|
|
|
auto it = mAsyncCompositables.find(wr::AsUint64(aPipelineId));
|
|
|
|
if (it == mAsyncCompositables.end()) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2017-06-02 10:11:34 +03:00
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
RefPtr<WebRenderImageHost>& wrHost = it->second;
|
2017-06-30 04:06:11 +03:00
|
|
|
|
|
|
|
wrHost->ClearWrBridge();
|
2018-04-30 16:35:41 +03:00
|
|
|
mAsyncImageManager->RemoveAsyncImagePipeline(aPipelineId, aTxn);
|
|
|
|
aTxn.RemovePipeline(aPipelineId);
|
2018-07-10 05:06:08 +03:00
|
|
|
mAsyncCompositables.erase(wr::AsUint64(aPipelineId));
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2017-06-02 10:11:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 16:13:06 +03:00
|
|
|
void
|
2018-10-02 20:27:52 +03:00
|
|
|
WebRenderBridgeParent::DeleteImage(const ImageKey& aKey,
|
|
|
|
wr::TransactionBuilder& aUpdates)
|
2016-12-08 04:52:24 +03:00
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-12-08 04:52:24 +03:00
|
|
|
}
|
2017-11-03 10:38:34 +03:00
|
|
|
|
2018-10-02 20:27:52 +03:00
|
|
|
auto it = mSharedSurfaceIds.find(wr::AsUint64(aKey));
|
|
|
|
if (it != mSharedSurfaceIds.end()) {
|
|
|
|
mAsyncImageManager->HoldExternalImage(mPipelineId, mWrEpoch, it->second);
|
|
|
|
mSharedSurfaceIds.erase(it);
|
2016-12-08 04:52:24 +03:00
|
|
|
}
|
2018-10-02 20:27:52 +03:00
|
|
|
|
|
|
|
aUpdates.DeleteImage(aKey);
|
2016-11-24 09:48:01 +03:00
|
|
|
}
|
|
|
|
|
2018-04-12 16:13:06 +03:00
|
|
|
void
|
2018-07-06 15:25:33 +03:00
|
|
|
WebRenderBridgeParent::ReleaseTextureOfImage(const wr::ImageKey& aKey)
|
2016-11-24 09:48:01 +03:00
|
|
|
{
|
2016-11-28 04:21:33 +03:00
|
|
|
if (mDestroyed) {
|
2018-04-12 16:13:06 +03:00
|
|
|
return;
|
2016-11-28 04:21:33 +03:00
|
|
|
}
|
2017-10-30 20:10:29 +03:00
|
|
|
|
2018-07-06 15:25:33 +03:00
|
|
|
uint64_t id = wr::AsUint64(aKey);
|
|
|
|
CompositableTextureHostRef texture;
|
|
|
|
WebRenderTextureHost* wrTexture = nullptr;
|
2018-04-23 14:57:15 +03:00
|
|
|
|
2018-07-10 05:06:08 +03:00
|
|
|
auto it = mTextureHosts.find(id);
|
|
|
|
if (it != mTextureHosts.end()) {
|
|
|
|
wrTexture = (*it).second->AsWebRenderTextureHost();
|
2017-04-27 19:34:54 +03:00
|
|
|
}
|
2018-07-06 15:25:33 +03:00
|
|
|
if (wrTexture) {
|
|
|
|
mAsyncImageManager->HoldExternalImage(mPipelineId, mWrEpoch, wrTexture);
|
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
mTextureHosts.erase(id);
|
2016-11-24 09:48:01 +03:00
|
|
|
}
|
|
|
|
|
2016-11-30 05:59:14 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2018-07-30 16:24:50 +03:00
|
|
|
WebRenderBridgeParent::RecvSetLayersObserverEpoch(const LayersObserverEpoch& aChildEpoch)
|
2016-11-30 05:59:14 +03:00
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2018-07-30 16:24:50 +03:00
|
|
|
mChildLayersObserverEpoch = aChildEpoch;
|
2016-11-30 05:59:14 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvClearCachedResources()
|
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-07-11 03:13:15 +03:00
|
|
|
|
|
|
|
// Clear resources
|
2018-01-12 14:24:07 +03:00
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(true);
|
2018-04-10 19:29:56 +03:00
|
|
|
txn.ClearDisplayList(GetNextWrEpoch(), mPipelineId);
|
2018-09-21 19:47:18 +03:00
|
|
|
txn.Notify(
|
|
|
|
wr::Checkpoint::SceneBuilt,
|
|
|
|
MakeUnique<ScheduleObserveLayersUpdate>(
|
|
|
|
mCompositorBridge,
|
|
|
|
GetLayersId(),
|
|
|
|
mChildLayersObserverEpoch,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-01-12 14:24:07 +03:00
|
|
|
mApi->SendTransaction(txn);
|
2017-11-30 15:38:47 +03:00
|
|
|
// Schedule generate frame to clean up Pipeline
|
|
|
|
ScheduleGenerateFrame();
|
2017-07-11 03:13:15 +03:00
|
|
|
// Remove animations.
|
2018-07-07 03:30:50 +03:00
|
|
|
for (const auto& id : mActiveAnimations) {
|
|
|
|
mAnimStorage->ClearById(id);
|
2017-07-11 03:13:15 +03:00
|
|
|
}
|
|
|
|
mActiveAnimations.clear();
|
2018-04-27 17:32:31 +03:00
|
|
|
std::queue<CompositorAnimationIdsForEpoch>().swap(mCompositorAnimationsToDelete); // clear queue
|
2016-11-30 05:59:14 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:42:30 +03:00
|
|
|
wr::Epoch
|
2017-06-30 04:06:11 +03:00
|
|
|
WebRenderBridgeParent::UpdateWebRender(CompositorVsyncScheduler* aScheduler,
|
|
|
|
wr::WebRenderAPI* aApi,
|
2017-07-25 11:54:36 +03:00
|
|
|
AsyncImagePipelineManager* aImageMgr,
|
2018-07-03 02:43:17 +03:00
|
|
|
CompositorAnimationStorage* aAnimStorage,
|
|
|
|
const TextureFactoryIdentifier& aTextureFactoryIdentifier)
|
2017-06-30 04:06:11 +03:00
|
|
|
{
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(!IsRootWebRenderBridgeParent());
|
2017-06-30 04:06:11 +03:00
|
|
|
MOZ_ASSERT(aScheduler);
|
|
|
|
MOZ_ASSERT(aApi);
|
2017-07-25 11:54:36 +03:00
|
|
|
MOZ_ASSERT(aImageMgr);
|
2017-06-30 04:06:11 +03:00
|
|
|
MOZ_ASSERT(aAnimStorage);
|
|
|
|
|
|
|
|
if (mDestroyed) {
|
2018-07-27 16:42:30 +03:00
|
|
|
return mWrEpoch;
|
2017-06-30 04:06:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update id name space to identify obsoleted keys.
|
|
|
|
// Since usage of invalid keys could cause crash in webrender.
|
2017-07-31 21:21:18 +03:00
|
|
|
mIdNamespace = aApi->GetNamespace();
|
2017-06-30 04:06:11 +03:00
|
|
|
// XXX Remove it when webrender supports sharing/moving Keys between different webrender instances.
|
|
|
|
// XXX It requests client to update/reallocate webrender related resources,
|
|
|
|
// but parent side does not wait end of the update.
|
|
|
|
// The code could become simpler if we could serialise old keys deallocation and new keys allocation.
|
|
|
|
// But we do not do it, it is because client side deallocate old layers/webrender keys
|
|
|
|
// after new layers/webrender keys allocation.
|
|
|
|
// Without client side's layout refactoring, we could not finish all old layers/webrender keys removals
|
|
|
|
// before new layer/webrender keys allocation. In future, we could address the problem.
|
2018-07-03 02:43:17 +03:00
|
|
|
Unused << SendWrUpdated(mIdNamespace, aTextureFactoryIdentifier);
|
2017-06-30 04:06:11 +03:00
|
|
|
CompositorBridgeParentBase* cBridge = mCompositorBridge;
|
|
|
|
// XXX Stop to clear resources if webreder supports resources sharing between different webrender instances.
|
|
|
|
ClearResources();
|
|
|
|
mCompositorBridge = cBridge;
|
|
|
|
mCompositorScheduler = aScheduler;
|
|
|
|
mApi = aApi;
|
2017-07-25 11:54:36 +03:00
|
|
|
mAsyncImageManager = aImageMgr;
|
2017-06-30 04:06:11 +03:00
|
|
|
mAnimStorage = aAnimStorage;
|
|
|
|
|
2017-07-25 11:54:36 +03:00
|
|
|
// Register pipeline to updated AsyncImageManager.
|
|
|
|
mAsyncImageManager->AddPipeline(mPipelineId);
|
2018-07-27 16:42:30 +03:00
|
|
|
|
|
|
|
return GetNextWrEpoch(); // Update webrender epoch
|
2017-06-30 04:06:11 +03:00
|
|
|
}
|
|
|
|
|
2017-04-10 09:58:29 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2018-02-02 16:57:35 +03:00
|
|
|
WebRenderBridgeParent::RecvScheduleComposite()
|
2018-10-15 14:28:01 +03:00
|
|
|
{
|
|
|
|
ScheduleGenerateFrame();
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderBridgeParent::ScheduleForcedGenerateFrame()
|
2017-04-10 09:58:29 +03:00
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
2018-10-15 14:28:01 +03:00
|
|
|
return;
|
2017-04-10 09:58:29 +03:00
|
|
|
}
|
2018-10-10 06:20:23 +03:00
|
|
|
|
|
|
|
wr::TransactionBuilder fastTxn(/* aUseSceneBuilderThread */ false);
|
|
|
|
fastTxn.InvalidateRenderedFrame();
|
|
|
|
mApi->SendTransaction(fastTxn);
|
|
|
|
|
2017-11-30 15:38:47 +03:00
|
|
|
ScheduleGenerateFrame();
|
2017-04-10 09:58:29 +03:00
|
|
|
}
|
|
|
|
|
2018-01-26 18:09:30 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvCapture()
|
|
|
|
{
|
|
|
|
if (!mDestroyed) {
|
|
|
|
mApi->Capture();
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-05-28 18:29:52 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSyncWithCompositor()
|
|
|
|
{
|
|
|
|
FlushSceneBuilds();
|
|
|
|
if (RefPtr<WebRenderBridgeParent> root = GetRootWebRenderBridgeParent()) {
|
|
|
|
root->FlushFrameGeneration();
|
|
|
|
}
|
|
|
|
FlushFramePresentation();
|
|
|
|
// Finally, we force the AsyncImagePipelineManager to handle all the
|
|
|
|
// pipeline updates produced in the last step, so that it frees any
|
|
|
|
// unneeded textures. Then we can return from this sync IPC call knowing
|
|
|
|
// that we've done everything we can to flush stuff on the compositor.
|
|
|
|
mAsyncImageManager->ProcessPipelineUpdates();
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-28 14:51:51 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSetConfirmedTargetAPZC(const uint64_t& aBlockId,
|
|
|
|
nsTArray<ScrollableLayerGuid>&& aTargets)
|
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-05-28 14:51:53 +03:00
|
|
|
mCompositorBridge->SetConfirmedTargetAPZC(GetLayersId(), aBlockId, aTargets);
|
2017-05-28 14:51:51 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:29:06 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSetTestSampleTime(const TimeStamp& aTime)
|
|
|
|
{
|
|
|
|
if (!mCompositorBridge->SetTestSampleTime(GetLayersId(), aTime)) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvLeaveTestMode()
|
|
|
|
{
|
|
|
|
mCompositorBridge->LeaveTestMode(GetLayersId());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-07-31 00:13:15 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvGetAnimationValue(const uint64_t& aCompositorAnimationsId,
|
|
|
|
OMTAValue* aValue)
|
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mAnimStorage);
|
|
|
|
if (RefPtr<WebRenderBridgeParent> root = GetRootWebRenderBridgeParent()) {
|
|
|
|
root->AdvanceAnimations();
|
|
|
|
} else {
|
|
|
|
AdvanceAnimations();
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = mAnimStorage->GetOMTAValue(aCompositorAnimationsId);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-28 14:48:36 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSetAsyncScrollOffset(const FrameMetrics::ViewID& aScrollId,
|
|
|
|
const float& aX,
|
|
|
|
const float& aY)
|
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2018-03-06 18:25:37 +03:00
|
|
|
mCompositorBridge->SetTestAsyncScrollOffset(GetLayersId(), aScrollId, CSSPoint(aX, aY));
|
2017-05-28 14:48:36 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvSetAsyncZoom(const FrameMetrics::ViewID& aScrollId,
|
|
|
|
const float& aZoom)
|
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2018-03-06 18:25:37 +03:00
|
|
|
mCompositorBridge->SetTestAsyncZoom(GetLayersId(), aScrollId, LayerToParentLayerScale(aZoom));
|
2017-05-28 14:48:36 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvFlushApzRepaints()
|
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-05-28 14:51:53 +03:00
|
|
|
mCompositorBridge->FlushApzRepaints(GetLayersId());
|
2017-05-28 14:48:36 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-06-05 05:29:35 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvGetAPZTestData(APZTestData* aOutData)
|
|
|
|
{
|
|
|
|
mCompositorBridge->GetAPZTestData(GetLayersId(), aOutData);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2016-11-22 17:22:54 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2016-11-28 04:21:33 +03:00
|
|
|
Destroy();
|
2016-11-22 17:22:54 +03:00
|
|
|
}
|
|
|
|
|
2018-05-08 09:48:27 +03:00
|
|
|
bool
|
2017-06-28 03:29:05 +03:00
|
|
|
WebRenderBridgeParent::AdvanceAnimations()
|
|
|
|
{
|
|
|
|
if (CompositorBridgeParent* cbp = GetRootCompositorBridgeParent()) {
|
2018-04-23 00:27:19 +03:00
|
|
|
Maybe<TimeStamp> testingTimeStamp = cbp->GetTestingTimeStamp();
|
|
|
|
if (testingTimeStamp) {
|
|
|
|
// If we are on testing refresh mode, use the testing time stamp. And
|
|
|
|
// also we don't update mPreviousFrameTimeStamp since unlike normal
|
|
|
|
// refresh mode, on the testing mode animations on the compositor are
|
|
|
|
// synchronously composed, so we don't need to worry about the time gap
|
|
|
|
// between the main thread and compositor thread.
|
2018-05-08 09:48:27 +03:00
|
|
|
return AnimationHelper::SampleAnimations(mAnimStorage,
|
|
|
|
*testingTimeStamp,
|
|
|
|
*testingTimeStamp);
|
2018-04-23 00:27:19 +03:00
|
|
|
}
|
2017-06-28 03:29:05 +03:00
|
|
|
}
|
2017-06-29 23:44:00 +03:00
|
|
|
|
2018-04-23 00:27:19 +03:00
|
|
|
TimeStamp lastComposeTime = mCompositorScheduler->GetLastComposeTime();
|
2018-05-08 09:48:27 +03:00
|
|
|
const bool isAnimating =
|
|
|
|
AnimationHelper::SampleAnimations(mAnimStorage,
|
|
|
|
mPreviousFrameTimeStamp,
|
|
|
|
lastComposeTime);
|
2017-06-29 23:44:00 +03:00
|
|
|
|
|
|
|
// Reset the previous time stamp if we don't already have any running
|
|
|
|
// animations to avoid using the time which is far behind for newly
|
|
|
|
// started animations.
|
2018-05-08 09:58:54 +03:00
|
|
|
mPreviousFrameTimeStamp = isAnimating ? lastComposeTime : TimeStamp();
|
2018-05-08 09:48:27 +03:00
|
|
|
|
|
|
|
return isAnimating;
|
2017-06-28 03:29:05 +03:00
|
|
|
}
|
|
|
|
|
2018-05-08 09:48:27 +03:00
|
|
|
bool
|
2017-06-28 02:20:36 +03:00
|
|
|
WebRenderBridgeParent::SampleAnimations(nsTArray<wr::WrOpacityProperty>& aOpacityArray,
|
|
|
|
nsTArray<wr::WrTransformProperty>& aTransformArray)
|
2017-04-12 11:40:48 +03:00
|
|
|
{
|
2018-05-08 09:48:27 +03:00
|
|
|
const bool isAnimating = AdvanceAnimations();
|
2017-04-12 11:40:48 +03:00
|
|
|
|
|
|
|
// return the animated data if has
|
2017-06-15 10:36:03 +03:00
|
|
|
if (mAnimStorage->AnimatedValueCount()) {
|
|
|
|
for(auto iter = mAnimStorage->ConstAnimatedValueTableIter();
|
2017-04-12 11:40:48 +03:00
|
|
|
!iter.Done(); iter.Next()) {
|
|
|
|
AnimatedValue * value = iter.UserData();
|
|
|
|
if (value->mType == AnimatedValue::TRANSFORM) {
|
|
|
|
aTransformArray.AppendElement(
|
|
|
|
wr::ToWrTransformProperty(iter.Key(), value->mTransform.mTransformInDevSpace));
|
|
|
|
} else if (value->mType == AnimatedValue::OPACITY) {
|
|
|
|
aOpacityArray.AppendElement(
|
|
|
|
wr::ToWrOpacityProperty(iter.Key(), value->mOpacity));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 09:48:27 +03:00
|
|
|
|
|
|
|
return isAnimating;
|
2017-04-12 11:40:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-22 05:56:38 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::CompositeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect)
|
|
|
|
{
|
2018-04-18 23:44:03 +03:00
|
|
|
// This function should only get called in the root WRBP
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
2018-04-18 23:44:03 +03:00
|
|
|
|
2018-02-02 18:48:25 +03:00
|
|
|
// The two arguments are part of the CompositorVsyncSchedulerOwner API but in
|
|
|
|
// this implementation they should never be non-null.
|
|
|
|
MOZ_ASSERT(aTarget == nullptr);
|
|
|
|
MOZ_ASSERT(aRect == nullptr);
|
|
|
|
|
2018-10-03 00:19:17 +03:00
|
|
|
AUTO_PROFILER_TRACING("Paint", "CompositeToTarget");
|
2018-03-06 22:20:56 +03:00
|
|
|
if (mPaused || !mReceivedDisplayList) {
|
2018-05-03 09:57:19 +03:00
|
|
|
mPreviousFrameTimeStamp = TimeStamp();
|
2017-04-05 17:12:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-04-12 11:40:48 +03:00
|
|
|
|
2018-08-10 02:10:11 +03:00
|
|
|
if (wr::RenderThread::Get()->TooManyPendingFrames(mApi->GetId())) {
|
2017-05-19 03:21:38 +03:00
|
|
|
// Render thread is busy, try next time.
|
2017-11-30 15:38:47 +03:00
|
|
|
mCompositorScheduler->ScheduleComposition();
|
2018-05-03 09:57:19 +03:00
|
|
|
mPreviousFrameTimeStamp = TimeStamp();
|
2017-05-19 03:21:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-08-10 02:10:11 +03:00
|
|
|
MaybeGenerateFrame(/* aForceGenerateFrame */ false);
|
|
|
|
}
|
2017-05-19 03:21:38 +03:00
|
|
|
|
2018-10-16 03:33:51 +03:00
|
|
|
TimeDuration
|
|
|
|
WebRenderBridgeParent::GetVsyncInterval() const
|
|
|
|
{
|
|
|
|
// This function should only get called in the root WRBP
|
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
|
|
|
if (CompositorBridgeParent* cbp = GetRootCompositorBridgeParent()) {
|
|
|
|
return cbp->GetVsyncInterval();
|
|
|
|
}
|
|
|
|
return TimeDuration();
|
|
|
|
}
|
|
|
|
|
2018-08-10 02:10:11 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::MaybeGenerateFrame(bool aForceGenerateFrame)
|
|
|
|
{
|
2018-09-20 11:47:05 +03:00
|
|
|
// This function should only get called in the root WRBP
|
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
|
|
|
|
2018-06-25 17:55:26 +03:00
|
|
|
TimeStamp start = TimeStamp::Now();
|
|
|
|
mAsyncImageManager->SetCompositionTime(start);
|
2018-05-08 15:47:02 +03:00
|
|
|
|
2018-08-07 13:12:06 +03:00
|
|
|
// Ensure GenerateFrame is handled on the render backend thread rather
|
|
|
|
// than going through the scene builder thread. That way we continue generating
|
|
|
|
// frames with the old scene even during slow scene builds.
|
2018-09-12 18:30:17 +03:00
|
|
|
bool useSceneBuilderThread = false;
|
|
|
|
wr::TransactionBuilder fastTxn(useSceneBuilderThread);
|
2018-08-07 13:12:06 +03:00
|
|
|
|
|
|
|
// Handle transaction that is related to DisplayList.
|
|
|
|
wr::TransactionBuilder sceneBuilderTxn;
|
|
|
|
wr::AutoTransactionSender sender(mApi, &sceneBuilderTxn);
|
|
|
|
|
|
|
|
// Adding and updating wr::ImageKeys of ImageHosts that uses ImageBridge are
|
|
|
|
// done without using transaction of scene builder thread. With it, updating of
|
|
|
|
// video frame becomes faster.
|
|
|
|
mAsyncImageManager->ApplyAsyncImagesOfImageBridge(sceneBuilderTxn, fastTxn);
|
2017-06-02 10:11:34 +03:00
|
|
|
|
2017-11-30 15:38:47 +03:00
|
|
|
if (!mAsyncImageManager->GetCompositeUntilTime().IsNull()) {
|
|
|
|
// Trigger another CompositeToTarget() call because there might be another
|
|
|
|
// frame that we want to generate after this one.
|
|
|
|
// It will check if we actually want to generate the frame or not.
|
|
|
|
mCompositorScheduler->ScheduleComposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAsyncImageManager->GetAndResetWillGenerateFrame() &&
|
2018-08-07 13:12:06 +03:00
|
|
|
fastTxn.IsEmpty() &&
|
2018-08-10 02:10:11 +03:00
|
|
|
!aForceGenerateFrame) {
|
2017-11-30 15:38:47 +03:00
|
|
|
// Could skip generating frame now.
|
2018-05-03 09:57:19 +03:00
|
|
|
mPreviousFrameTimeStamp = TimeStamp();
|
2017-11-30 15:38:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<wr::WrOpacityProperty> opacityArray;
|
|
|
|
nsTArray<wr::WrTransformProperty> transformArray;
|
|
|
|
|
2018-05-08 09:48:27 +03:00
|
|
|
if (SampleAnimations(opacityArray, transformArray)) {
|
2017-11-30 15:38:47 +03:00
|
|
|
ScheduleGenerateFrame();
|
2017-04-12 11:40:48 +03:00
|
|
|
}
|
2018-04-11 22:28:00 +03:00
|
|
|
// We do this even if the arrays are empty, because it will clear out any
|
2018-04-17 00:39:26 +03:00
|
|
|
// previous properties store on the WR side, which is desirable.
|
2018-08-07 13:12:06 +03:00
|
|
|
fastTxn.UpdateDynamicProperties(opacityArray, transformArray);
|
2017-04-17 17:22:47 +03:00
|
|
|
|
2018-04-17 00:39:26 +03:00
|
|
|
SetAPZSampleTime();
|
2017-05-23 17:50:42 +03:00
|
|
|
|
2018-06-25 17:55:26 +03:00
|
|
|
wr::RenderThread::Get()->IncPendingFrameCount(mApi->GetId(), start);
|
2017-07-24 03:22:20 +03:00
|
|
|
|
2017-07-28 02:05:56 +03:00
|
|
|
#if defined(ENABLE_FRAME_LATENCY_LOG)
|
|
|
|
auto startTime = TimeStamp::Now();
|
|
|
|
mApi->SetFrameStartTime(startTime);
|
|
|
|
#endif
|
|
|
|
|
2018-08-07 13:12:06 +03:00
|
|
|
fastTxn.GenerateFrame();
|
2018-01-12 14:24:03 +03:00
|
|
|
|
2018-08-07 13:12:06 +03:00
|
|
|
mApi->SendTransaction(fastTxn);
|
2016-11-22 05:56:38 +03:00
|
|
|
}
|
|
|
|
|
2017-01-06 21:10:15 +03:00
|
|
|
void
|
2018-04-10 19:29:56 +03:00
|
|
|
WebRenderBridgeParent::HoldPendingTransactionId(const wr::Epoch& aWrEpoch,
|
2018-04-20 22:13:06 +03:00
|
|
|
TransactionId aTransactionId,
|
2018-09-18 06:13:18 +03:00
|
|
|
bool aContainsSVGGroup,
|
2018-06-26 21:43:14 +03:00
|
|
|
const TimeStamp& aRefreshStartTime,
|
2017-08-11 04:57:21 +03:00
|
|
|
const TimeStamp& aTxnStartTime,
|
2018-08-15 08:13:49 +03:00
|
|
|
const TimeStamp& aFwdTime,
|
2018-10-19 16:48:04 +03:00
|
|
|
const bool aIsFirstPaint,
|
2018-08-15 08:13:49 +03:00
|
|
|
const bool aUseForTelemetry)
|
2017-02-24 06:22:59 +03:00
|
|
|
{
|
2018-02-09 21:41:18 +03:00
|
|
|
MOZ_ASSERT(aTransactionId > LastPendingTransactionId());
|
2018-06-26 21:43:14 +03:00
|
|
|
mPendingTransactionIds.push(PendingTransactionId(aWrEpoch,
|
|
|
|
aTransactionId,
|
2018-09-18 06:13:18 +03:00
|
|
|
aContainsSVGGroup,
|
2018-06-26 21:43:14 +03:00
|
|
|
aRefreshStartTime,
|
|
|
|
aTxnStartTime,
|
2018-08-15 08:13:49 +03:00
|
|
|
aFwdTime,
|
2018-10-19 16:48:04 +03:00
|
|
|
aIsFirstPaint,
|
2018-08-15 08:13:49 +03:00
|
|
|
aUseForTelemetry));
|
2017-02-24 06:22:59 +03:00
|
|
|
}
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
TransactionId
|
2017-02-24 06:22:59 +03:00
|
|
|
WebRenderBridgeParent::LastPendingTransactionId()
|
2017-01-06 21:10:15 +03:00
|
|
|
{
|
2018-04-20 22:13:06 +03:00
|
|
|
TransactionId id{0};
|
2017-02-24 06:22:59 +03:00
|
|
|
if (!mPendingTransactionIds.empty()) {
|
|
|
|
id = mPendingTransactionIds.back().mId;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
TransactionId
|
2018-10-19 16:48:04 +03:00
|
|
|
WebRenderBridgeParent::FlushTransactionIdsForEpoch(const wr::Epoch& aEpoch, const TimeStamp& aEndTime,
|
|
|
|
UiCompositorControllerParent* aUiController)
|
2017-02-24 06:22:59 +03:00
|
|
|
{
|
2018-04-20 22:13:06 +03:00
|
|
|
TransactionId id{0};
|
2017-02-24 06:22:59 +03:00
|
|
|
while (!mPendingTransactionIds.empty()) {
|
2018-08-15 08:13:24 +03:00
|
|
|
const auto& transactionId = mPendingTransactionIds.front();
|
|
|
|
|
|
|
|
if (aEpoch.mHandle < transactionId.mEpoch.mHandle) {
|
2017-02-24 06:22:59 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-06-26 21:43:14 +03:00
|
|
|
|
2018-08-15 08:13:49 +03:00
|
|
|
if (!IsRootWebRenderBridgeParent() && !mVsyncRate.IsZero() && transactionId.mUseForTelemetry) {
|
2018-08-15 08:13:24 +03:00
|
|
|
double latencyMs = (aEndTime - transactionId.mTxnStartTime).ToMilliseconds();
|
2018-06-26 21:43:14 +03:00
|
|
|
double latencyNorm = latencyMs / mVsyncRate.ToMilliseconds();
|
|
|
|
int32_t fracLatencyNorm = lround(latencyNorm * 100.0);
|
|
|
|
Telemetry::Accumulate(Telemetry::CONTENT_FRAME_TIME, fracLatencyNorm);
|
2018-09-18 06:13:18 +03:00
|
|
|
if (transactionId.mContainsSVGGroup) {
|
|
|
|
Telemetry::Accumulate(Telemetry::CONTENT_FRAME_TIME_WITH_SVG, fracLatencyNorm);
|
|
|
|
}
|
2018-06-26 21:43:14 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 02:05:56 +03:00
|
|
|
#if defined(ENABLE_FRAME_LATENCY_LOG)
|
2018-08-15 08:13:24 +03:00
|
|
|
if (transactionId.mRefreshStartTime) {
|
|
|
|
int32_t latencyMs = lround((aEndTime - transactionId.mRefreshStartTime).ToMilliseconds());
|
2017-08-11 04:57:21 +03:00
|
|
|
printf_stderr("From transaction start to end of generate frame latencyMs %d this %p\n", latencyMs, this);
|
|
|
|
}
|
2018-08-15 08:13:24 +03:00
|
|
|
if (transactionId.mFwdTime) {
|
|
|
|
int32_t latencyMs = lround((aEndTime - transactionId.mFwdTime).ToMilliseconds());
|
2017-08-11 04:57:21 +03:00
|
|
|
printf_stderr("From forwarding transaction to end of generate frame latencyMs %d this %p\n", latencyMs, this);
|
2017-07-28 02:05:56 +03:00
|
|
|
}
|
|
|
|
#endif
|
2018-10-19 16:48:04 +03:00
|
|
|
|
|
|
|
if (aUiController && transactionId.mIsFirstPaint) {
|
|
|
|
aUiController->NotifyFirstPaint();
|
|
|
|
}
|
|
|
|
|
2018-08-15 08:13:24 +03:00
|
|
|
id = transactionId.mId;
|
2017-02-24 06:22:59 +03:00
|
|
|
mPendingTransactionIds.pop();
|
|
|
|
}
|
|
|
|
return id;
|
2017-01-06 21:10:15 +03:00
|
|
|
}
|
|
|
|
|
2018-03-25 02:06:01 +03:00
|
|
|
LayersId
|
2017-05-28 14:51:53 +03:00
|
|
|
WebRenderBridgeParent::GetLayersId() const
|
|
|
|
{
|
2018-03-25 02:06:01 +03:00
|
|
|
return wr::AsLayersId(mPipelineId);
|
2017-05-28 14:51:53 +03:00
|
|
|
}
|
|
|
|
|
2016-11-22 05:56:38 +03:00
|
|
|
void
|
2017-11-30 15:38:47 +03:00
|
|
|
WebRenderBridgeParent::ScheduleGenerateFrame()
|
2016-11-22 05:56:38 +03:00
|
|
|
{
|
2017-02-27 03:27:04 +03:00
|
|
|
if (mCompositorScheduler) {
|
2017-11-30 15:38:47 +03:00
|
|
|
mAsyncImageManager->SetWillGenerateFrame();
|
2017-02-27 03:27:04 +03:00
|
|
|
mCompositorScheduler->ScheduleComposition();
|
|
|
|
}
|
2016-11-22 05:56:38 +03:00
|
|
|
}
|
|
|
|
|
2017-06-02 02:07:59 +03:00
|
|
|
void
|
2018-07-28 11:47:08 +03:00
|
|
|
WebRenderBridgeParent::FlushRendering(bool aWaitForPresent)
|
2017-06-02 02:07:59 +03:00
|
|
|
{
|
|
|
|
if (mDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-17 18:34:31 +03:00
|
|
|
// This gets called during e.g. window resizes, so we need to flush the
|
|
|
|
// scene (which has the display list at the new window size).
|
|
|
|
FlushSceneBuilds();
|
2018-05-28 18:29:52 +03:00
|
|
|
FlushFrameGeneration();
|
2018-07-28 11:47:08 +03:00
|
|
|
if (aWaitForPresent) {
|
|
|
|
FlushFramePresentation();
|
2018-02-02 18:48:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-05 17:12:11 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::Pause()
|
|
|
|
{
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
2017-04-05 17:12:11 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2018-06-26 21:37:31 +03:00
|
|
|
if (!IsRootWebRenderBridgeParent() || mDestroyed) {
|
2017-04-05 17:12:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mApi->Pause();
|
|
|
|
#endif
|
|
|
|
mPaused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::Resume()
|
|
|
|
{
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
2017-04-05 17:12:11 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2018-06-26 21:37:31 +03:00
|
|
|
if (!IsRootWebRenderBridgeParent() || mDestroyed) {
|
2017-04-05 17:12:11 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mApi->Resume()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mPaused = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-22 17:22:54 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::ClearResources()
|
|
|
|
{
|
2017-05-17 03:28:20 +03:00
|
|
|
if (!mApi) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-10 19:29:56 +03:00
|
|
|
wr::Epoch wrEpoch = GetNextWrEpoch();
|
2018-01-12 14:24:07 +03:00
|
|
|
|
|
|
|
wr::TransactionBuilder txn;
|
2018-09-12 18:30:17 +03:00
|
|
|
txn.SetLowPriority(true);
|
2018-04-10 19:29:56 +03:00
|
|
|
txn.ClearDisplayList(wrEpoch, mPipelineId);
|
2018-03-06 22:20:56 +03:00
|
|
|
mReceivedDisplayList = false;
|
2018-01-12 14:24:07 +03:00
|
|
|
|
2017-11-30 15:38:47 +03:00
|
|
|
// Schedule generate frame to clean up Pipeline
|
|
|
|
ScheduleGenerateFrame();
|
2017-08-16 04:09:35 +03:00
|
|
|
// WrFontKeys and WrImageKeys are deleted during WebRenderAPI destruction.
|
2018-07-10 05:06:08 +03:00
|
|
|
for (const auto& entry : mTextureHosts) {
|
|
|
|
WebRenderTextureHost* wrTexture = entry.second->AsWebRenderTextureHost();
|
2018-07-06 15:25:33 +03:00
|
|
|
MOZ_ASSERT(wrTexture);
|
|
|
|
if (wrTexture) {
|
|
|
|
mAsyncImageManager->HoldExternalImage(mPipelineId, wrEpoch, wrTexture);
|
|
|
|
}
|
2017-04-27 19:34:54 +03:00
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
mTextureHosts.clear();
|
|
|
|
for (const auto& entry : mAsyncCompositables) {
|
|
|
|
wr::PipelineId pipelineId = wr::AsPipelineId(entry.first);
|
|
|
|
RefPtr<WebRenderImageHost> host = entry.second;
|
2017-06-02 10:11:34 +03:00
|
|
|
host->ClearWrBridge();
|
2018-01-12 14:24:07 +03:00
|
|
|
mAsyncImageManager->RemoveAsyncImagePipeline(pipelineId, txn);
|
2018-08-02 07:17:36 +03:00
|
|
|
txn.RemovePipeline(pipelineId);
|
2017-06-02 10:11:34 +03:00
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
mAsyncCompositables.clear();
|
|
|
|
for (const auto& entry : mSharedSurfaceIds) {
|
2018-10-02 20:27:52 +03:00
|
|
|
mAsyncImageManager->HoldExternalImage(mPipelineId, mWrEpoch, entry.second);
|
2018-04-23 14:57:15 +03:00
|
|
|
}
|
2018-07-10 05:06:08 +03:00
|
|
|
mSharedSurfaceIds.clear();
|
2017-06-02 10:11:34 +03:00
|
|
|
|
2018-04-10 19:29:56 +03:00
|
|
|
mAsyncImageManager->RemovePipeline(mPipelineId, wrEpoch);
|
2018-01-12 14:24:07 +03:00
|
|
|
txn.RemovePipeline(mPipelineId);
|
|
|
|
|
|
|
|
mApi->SendTransaction(txn);
|
2016-11-24 11:53:17 +03:00
|
|
|
|
2018-07-07 03:30:50 +03:00
|
|
|
for (const auto& id : mActiveAnimations) {
|
|
|
|
mAnimStorage->ClearById(id);
|
2017-06-15 10:36:03 +03:00
|
|
|
}
|
|
|
|
mActiveAnimations.clear();
|
2018-04-27 17:32:31 +03:00
|
|
|
std::queue<CompositorAnimationIdsForEpoch>().swap(mCompositorAnimationsToDelete); // clear queue
|
2017-06-15 10:36:03 +03:00
|
|
|
|
2018-06-26 21:37:31 +03:00
|
|
|
if (IsRootWebRenderBridgeParent()) {
|
2016-11-22 17:22:54 +03:00
|
|
|
mCompositorScheduler->Destroy();
|
|
|
|
}
|
2018-06-02 19:15:15 +03:00
|
|
|
|
2017-06-15 10:36:03 +03:00
|
|
|
mAnimStorage = nullptr;
|
2017-02-27 03:27:04 +03:00
|
|
|
mCompositorScheduler = nullptr;
|
2017-08-09 15:46:25 +03:00
|
|
|
mAsyncImageManager = nullptr;
|
2017-01-27 23:30:18 +03:00
|
|
|
mApi = nullptr;
|
2016-11-30 05:59:14 +03:00
|
|
|
mCompositorBridge = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::ShouldParentObserveEpoch()
|
|
|
|
{
|
2018-07-30 16:24:50 +03:00
|
|
|
if (mParentLayersObserverEpoch == mChildLayersObserverEpoch) {
|
2016-11-30 05:59:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-30 16:24:50 +03:00
|
|
|
mParentLayersObserverEpoch = mChildLayersObserverEpoch;
|
2016-11-30 05:59:14 +03:00
|
|
|
return true;
|
2016-11-22 17:22:54 +03:00
|
|
|
}
|
|
|
|
|
2016-11-30 13:57:26 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:02:04 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::SendPendingAsyncMessages()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCompositorBridge);
|
|
|
|
mCompositorBridge->SendPendingAsyncMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebRenderBridgeParent::SetAboutToSendAsyncMessages()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCompositorBridge);
|
|
|
|
mCompositorBridge->SetAboutToSendAsyncMessages();
|
|
|
|
}
|
|
|
|
|
2016-11-30 13:57:26 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
}
|
|
|
|
|
|
|
|
base::ProcessId
|
|
|
|
WebRenderBridgeParent::GetChildProcessId()
|
|
|
|
{
|
|
|
|
return OtherPid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebRenderBridgeParent::IsSameProcess() const
|
|
|
|
{
|
|
|
|
return OtherPid() == base::GetCurrentProcId();
|
|
|
|
}
|
|
|
|
|
2017-01-18 21:47:27 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvNewCompositable(const CompositableHandle& aHandle,
|
|
|
|
const TextureInfo& aInfo)
|
2016-11-30 13:57:26 +03:00
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
Bug 1354411 - Rebuild CompositorSessions if WebRender is disabled r=kats
When WebRender creation is failed, WebRender is disabled in gecko. There is a case that WebRenderBridgeParents exist when WebRender is disabled. To handle this, gecko needs to rebuild all CompositorSessions.
There is also a problem related to gfxVars::UseWebRender on compositor thread. If e10s is enabled, but no-gpu process(default on linux and mac), gfxVars::UseWebRender change is soon notified by compositor thread tasks. If WebRender creation failure happens at 2nd WebRender creation, several WebRenderBridgeParents for 1st WebRender could exist. IPC messages from WebRenderLayerManager are normally async, then there is a chance that the WebRenderBridgeParents receive the messages after the gfxVars::UseWebRender change. Further the gfxVars::UseWebRender change in content process could be delayed than WebRenderBridgeParents, then content process does not have a way to stop sending PWebRenderBridge IPC until the change of gfxVars::UseWebRender is received. WebRenderBridgeParent related tasks handle the message, but some tasks are done based on gfxVars::UseWebRender. At this time, gfxVars::UseWebRender returned false on compositor thread, then it cause unexpected result for WebRenderBridgeParent and WebRender. To addres this inconsistent situation, WebRenderBridgeParent related tasks on compositor thread stop to use gfxVars::UseWebRender.
2017-08-04 08:36:41 +03:00
|
|
|
if (!AddCompositable(aHandle, aInfo, /* aUseWebRender */ true)) {
|
2017-01-18 21:47:27 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
2016-11-30 13:57:26 +03:00
|
|
|
}
|
|
|
|
|
2017-01-18 21:47:27 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WebRenderBridgeParent::RecvReleaseCompositable(const CompositableHandle& aHandle)
|
2016-11-30 13:57:26 +03:00
|
|
|
{
|
2017-06-05 09:41:21 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2017-01-18 21:47:27 +03:00
|
|
|
ReleaseCompositable(aHandle);
|
|
|
|
return IPC_OK();
|
2016-11-30 13:57:26 +03:00
|
|
|
}
|
|
|
|
|
2017-01-18 22:50:00 +03:00
|
|
|
TextureFactoryIdentifier
|
|
|
|
WebRenderBridgeParent::GetTextureFactoryIdentifier()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mApi);
|
|
|
|
|
2017-01-22 07:24:52 +03:00
|
|
|
return TextureFactoryIdentifier(LayersBackend::LAYERS_WR,
|
2017-01-18 22:50:00 +03:00
|
|
|
XRE_GetProcessType(),
|
2017-02-23 11:46:56 +03:00
|
|
|
mApi->GetMaxTextureSize(),
|
2018-05-03 04:20:25 +03:00
|
|
|
false,
|
2017-08-07 13:15:25 +03:00
|
|
|
mApi->GetUseANGLE(),
|
2018-07-20 16:58:40 +03:00
|
|
|
mApi->GetUseDComp(),
|
2017-08-07 13:15:25 +03:00
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
mApi->GetSyncHandle());
|
2017-01-18 22:50:00 +03:00
|
|
|
}
|
|
|
|
|
2018-04-10 19:29:56 +03:00
|
|
|
wr::Epoch
|
2017-07-24 15:20:22 +03:00
|
|
|
WebRenderBridgeParent::GetNextWrEpoch()
|
|
|
|
{
|
2018-04-10 19:29:56 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mWrEpoch.mHandle != UINT32_MAX);
|
|
|
|
mWrEpoch.mHandle++;
|
|
|
|
return mWrEpoch;
|
2017-07-24 15:20:22 +03:00
|
|
|
}
|
|
|
|
|
2017-07-31 07:00:06 +03:00
|
|
|
void
|
|
|
|
WebRenderBridgeParent::ExtractImageCompositeNotifications(nsTArray<ImageCompositeNotificationInfo>* aNotifications)
|
|
|
|
{
|
2018-06-26 21:37:31 +03:00
|
|
|
MOZ_ASSERT(IsRootWebRenderBridgeParent());
|
2017-08-09 15:46:25 +03:00
|
|
|
if (mDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-31 07:00:06 +03:00
|
|
|
mAsyncImageManager->FlushImageNotifications(aNotifications);
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:54:51 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|