Bug 1316903 - Merged many webrender commands to single transaction. r=kats

MozReview-Commit-ID: 4iOxYJ6x4ZL
This commit is contained in:
Morris Tseng 2016-11-18 16:07:02 +08:00
Родитель 510d0fe7d7
Коммит 0afb45f905
14 изменённых файлов: 168 добавлений и 102 удалений

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

@ -7,14 +7,11 @@
include "mozilla/GfxMessageUtils.h";
include WebRenderMessages;
include protocol PCompositorBridge;
using WRImageFormat from "webrender.h";
using WRImageKey from "webrender.h";
using WRRect from "webrender.h";
using MaybeImageMask from "mozilla/layers/WebRenderTypes.h";
using mozilla::gfx::ByteBuffer from "mozilla/layers/WebRenderTypes.h";
using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
namespace mozilla {
namespace layers {
@ -32,15 +29,9 @@ parent:
sync UpdateImage(WRImageKey aImageKey, uint32_t aWidth, uint32_t aHeight,
WRImageFormat aFormat, ByteBuffer aBytes);
sync DeleteImage(WRImageKey aImageKey);
sync PushDLBuilder();
sync PopDLBuilder(WRRect aBounds, WRRect aOverflow, Matrix4x4 aMatrix,
uint64_t aScrollId);
sync DPBegin(uint32_t aWidth, uint32_t aHeight)
returns (bool aOutSuccess);
sync DPEnd();
sync DPPushRect(WRRect aBounds, WRRect aClip, float r, float g, float b, float a);
sync DPPushImage(WRRect aBounds, WRRect aClip, MaybeImageMask aMask, WRImageKey aKey);
sync DPPushIframe(WRRect aBounds, WRRect aClip, uint64_t aLayersId);
async DPEnd(WebRenderCommand[] commands);
async __delete__();
};

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

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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/. */
using WRImageKey from "webrender.h";
using WRRect from "webrender.h";
using MaybeImageMask from "mozilla/layers/WebRenderTypes.h";
using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
namespace mozilla {
namespace layers {
struct OpPushDLBuilder { };
struct OpPopDLBuilder {
WRRect bounds;
WRRect overflow;
Matrix4x4 matrix;
uint64_t scrollid;
};
struct OpDPPushRect {
WRRect bounds;
WRRect clip;
float r;
float g;
float b;
float a;
};
struct OpDPPushImage {
WRRect bounds;
WRRect clip;
MaybeImageMask mask;
WRImageKey key;
};
struct OpDPPushIframe {
WRRect bounds;
WRRect clip;
uint64_t layersid;
};
union WebRenderCommand {
OpPushDLBuilder;
OpPopDLBuilder;
OpDPPushRect;
OpDPPushImage;
OpDPPushIframe;
};
} // namespace
} // namespace

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

@ -426,6 +426,7 @@ IPDL_SOURCES = [
'ipc/PTexture.ipdl',
'ipc/PVideoBridge.ipdl',
'ipc/PWebRenderBridge.ipdl',
'ipc/WebRenderMessages.ipdlh',
]
include('/ipc/chromium/chromium-config.mozbuild')

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

@ -12,8 +12,39 @@ namespace mozilla {
namespace layers {
WebRenderBridgeChild::WebRenderBridgeChild(const uint64_t& aPipelineId)
: mIsInTransaction(false)
{
}
void
WebRenderBridgeChild::AddWebRenderCommand(const WebRenderCommand& aCmd)
{
MOZ_ASSERT(mIsInTransaction);
mCommands.AppendElement(aCmd);
}
bool
WebRenderBridgeChild::DPBegin(uint32_t aWidth, uint32_t aHeight)
{
MOZ_ASSERT(!mIsInTransaction);
bool success = false;
this->SendDPBegin(aWidth, aHeight, &success);
if (!success) {
return false;
}
mIsInTransaction = true;
return true;
}
void
WebRenderBridgeChild::DPEnd()
{
MOZ_ASSERT(mIsInTransaction);
this->SendDPEnd(mCommands);
mCommands.Clear();
mIsInTransaction = false;
}
} // namespace layers
} // namespace mozilla

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

@ -25,8 +25,16 @@ class WebRenderBridgeChild final : public PWebRenderBridgeChild
public:
explicit WebRenderBridgeChild(const uint64_t& aPipelineId);
void AddWebRenderCommand(const WebRenderCommand& aCmd);
bool DPBegin(uint32_t aWidth, uint32_t aHeight);
void DPEnd();
protected:
~WebRenderBridgeChild() {}
nsTArray<WebRenderCommand> mCommands;
bool mIsInTransaction;
};
} // namespace layers

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

@ -103,25 +103,6 @@ WebRenderBridgeParent::RecvDeleteImage(const WRImageKey& aImageKey)
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvPushDLBuilder()
{
MOZ_ASSERT(mWRState);
wr_push_dl_builder(mWRState);
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvPopDLBuilder(const WRRect& aBounds,
const WRRect& aOverflow,
const gfx::Matrix4x4& aMatrix,
const uint64_t& aScrollId)
{
MOZ_ASSERT(mWRState);
wr_pop_dl_builder(mWRWindowState, mWRState, aBounds, aOverflow, &aMatrix.components[0], aScrollId);
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDPBegin(const uint32_t& aWidth,
const uint32_t& aHeight,
@ -145,9 +126,41 @@ WebRenderBridgeParent::RecvDPBegin(const uint32_t& aWidth,
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDPEnd()
WebRenderBridgeParent::RecvDPEnd(InfallibleTArray<WebRenderCommand>&& commands)
{
MOZ_ASSERT(mWRState);
for (InfallibleTArray<WebRenderCommand>::index_type i = 0; i < commands.Length(); ++i) {
const WebRenderCommand& cmd = commands[i];
switch (cmd.type()) {
case WebRenderCommand::TOpPushDLBuilder: {
wr_push_dl_builder(mWRState);
break;
}
case WebRenderCommand::TOpPopDLBuilder: {
const OpPopDLBuilder& op = cmd.get_OpPopDLBuilder();
wr_pop_dl_builder(mWRWindowState, mWRState, op.bounds(), op.overflow(), &(op.matrix().components[0]), op.scrollid());
break;
}
case WebRenderCommand::TOpDPPushRect: {
const OpDPPushRect& op = cmd.get_OpDPPushRect();
wr_dp_push_rect(mWRState, op.bounds(), op.clip(), op.r(), op.g(), op.b(), op.a());
break;
}
case WebRenderCommand::TOpDPPushImage: {
const OpDPPushImage& op = cmd.get_OpDPPushImage();
wr_dp_push_image(mWRState, op.bounds(), op.clip(), op.mask().ptrOr(nullptr), op.key());
break;
}
case WebRenderCommand::TOpDPPushIframe: {
const OpDPPushIframe& op = cmd.get_OpDPPushIframe();
wr_dp_push_iframe(mWRState, op.bounds(), op.clip(), op.layersid());
break;
}
default:
NS_RUNTIMEABORT("not reached");
}
}
mGLContext->MakeCurrent();
wr_dp_end(mWRWindowState, mWRState);
mGLContext->SwapBuffers();
@ -163,38 +176,6 @@ WebRenderBridgeParent::RecvDPEnd()
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDPPushRect(const WRRect& aBounds,
const WRRect& aClip,
const float& r, const float& g,
const float& b, const float& a)
{
MOZ_ASSERT(mWRState);
wr_dp_push_rect(mWRState, aBounds, aClip, r, g, b, a);
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDPPushImage(const WRRect& aBounds,
const WRRect& aClip,
const Maybe<WRImageMask>& aMask,
const WRImageKey& aKey)
{
MOZ_ASSERT(mWRState);
wr_dp_push_image(mWRState, aBounds, aClip, aMask.ptrOr(nullptr), aKey);
return IPC_OK();
}
mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDPPushIframe(const WRRect& aBounds,
const WRRect& aClip,
const uint64_t& aLayersId)
{
MOZ_ASSERT(mWRState);
wr_dp_push_iframe(mWRState, aBounds, aClip, aLayersId);
return IPC_OK();
}
WebRenderBridgeParent::~WebRenderBridgeParent()
{
}

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

@ -56,28 +56,10 @@ public:
const WRImageFormat& aFormat,
const ByteBuffer& aBuffer) override;
mozilla::ipc::IPCResult RecvDeleteImage(const WRImageKey& aImageKey) override;
mozilla::ipc::IPCResult RecvPushDLBuilder() override;
mozilla::ipc::IPCResult RecvPopDLBuilder(const WRRect& aBounds,
const WRRect& aOverflow,
const gfx::Matrix4x4& aMatrix,
const uint64_t& aScrollId) override;
mozilla::ipc::IPCResult RecvDPBegin(const uint32_t& aWidth,
const uint32_t& aHeight,
bool* aOutSuccess) override;
mozilla::ipc::IPCResult RecvDPEnd() override;
mozilla::ipc::IPCResult RecvDPPushRect(const WRRect& aBounds,
const WRRect& aClip,
const float& r,
const float& g,
const float& b,
const float& a) override;
mozilla::ipc::IPCResult RecvDPPushImage(const WRRect& aBounds,
const WRRect& aClip,
const Maybe<WRImageMask>& aMask,
const WRImageKey& aKey) override;
mozilla::ipc::IPCResult RecvDPPushIframe(const WRRect& aBounds,
const WRRect& aClip,
const uint64_t& aLayersId) override;
mozilla::ipc::IPCResult RecvDPEnd(InfallibleTArray<WebRenderCommand>&& commands) override;
void ActorDestroy(ActorDestroyReason aWhy) override {}

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

@ -110,13 +110,14 @@ WebRenderCanvasLayer::RenderLayer()
clip = rect;
}
if (gfxPrefs::LayersDump()) printf_stderr("CanvasLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
WRBridge()->SendPushDLBuilder();
WRBridge()->SendDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key);
WRBridge()->AddWebRenderCommand(OpPushDLBuilder());
WRBridge()->AddWebRenderCommand(OpDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key));
Manager()->AddImageKeyForDiscard(key);
gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();
if (gfxPrefs::LayersDump()) printf_stderr("CanvasLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
WRBridge()->SendPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID);
WRBridge()->AddWebRenderCommand(
OpPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID));
}
} // namespace layers

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

@ -25,8 +25,8 @@ WebRenderColorLayer::RenderLayer()
clip = rect;
}
if (gfxPrefs::LayersDump()) printf_stderr("ColorLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
WRBridge()->SendDPPushRect(toWrRect(rect), toWrRect(clip),
mColor.r, mColor.g, mColor.b, mColor.a);
WRBridge()->AddWebRenderCommand(
OpDPPushRect(toWrRect(rect), toWrRect(clip), mColor.r, mColor.g, mColor.b, mColor.a));
}
} // namespace layers

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

@ -24,11 +24,12 @@ WebRenderContainerLayer::RenderLayer()
gfx::Matrix4x4 transform;// = GetTransform();
if (gfxPrefs::LayersDump()) printf_stderr("ContainerLayer %p using %s as bounds/overflow, %s as transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
WRBridge()->SendPushDLBuilder();
WRBridge()->AddWebRenderCommand(OpPushDLBuilder());
for (Layer* child : children) {
ToWebRenderLayer(child)->RenderLayer();
}
WRBridge()->SendPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID);
WRBridge()->AddWebRenderCommand(
OpPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID));
}
void
@ -39,7 +40,7 @@ WebRenderRefLayer::RenderLayer()
gfx::Rect relBounds = TransformedVisibleBoundsRelativeToParent();
gfx::Matrix4x4 transform;// = GetTransform();
if (gfxPrefs::LayersDump()) printf_stderr("RefLayer %p (%" PRIu64 ") using %s as bounds/overflow, %s as transform\n", this, mId, Stringify(relBounds).c_str(), Stringify(transform).c_str());
WRBridge()->SendDPPushIframe(toWrRect(relBounds), toWrRect(relBounds), mId);
WRBridge()->AddWebRenderCommand(OpDPPushIframe(toWrRect(relBounds), toWrRect(relBounds), mId));
}
} // namespace layers

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

@ -58,14 +58,15 @@ WebRenderImageLayer::RenderLayer()
clip = rect;
}
if (gfxPrefs::LayersDump()) printf_stderr("ImageLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
WRBridge()->SendPushDLBuilder();
WRBridge()->SendDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key);
WRBridge()->AddWebRenderCommand(OpPushDLBuilder());
WRBridge()->AddWebRenderCommand(OpDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key));
Manager()->AddImageKeyForDiscard(key);
Rect relBounds = TransformedVisibleBoundsRelativeToParent();
Matrix4x4 transform;// = GetTransform();
if (gfxPrefs::LayersDump()) printf_stderr("ImageLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
WRBridge()->SendPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID);
WRBridge()->AddWebRenderCommand(
OpPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID));
//mContainer->SetImageFactory(originalIF);
}

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

@ -102,7 +102,7 @@ WRScrollFrameStackingContextGenerator::WRScrollFrameStackingContextGenerator(
continue;
}
if (gfxPrefs::LayersDump()) printf_stderr("Pushing stacking context id %" PRIu64"\n", fm.GetScrollId());
mLayer->WRBridge()->SendPushDLBuilder();
mLayer->WRBridge()->AddWebRenderCommand(OpPushDLBuilder());
}
}
@ -129,7 +129,8 @@ WRScrollFrameStackingContextGenerator::~WRScrollFrameStackingContextGenerator()
printf_stderr("Popping stacking context id %" PRIu64 " with bounds=%s overflow=%s\n",
fm.GetScrollId(), Stringify(bounds).c_str(), Stringify(overflow).c_str());
}
mLayer->WRBridge()->SendPopDLBuilder(toWrRect(bounds), toWrRect(overflow), identity, fm.GetScrollId());
mLayer->WRBridge()->AddWebRenderCommand(
OpPopDLBuilder(toWrRect(bounds), toWrRect(overflow), identity, fm.GetScrollId()));
}
}
@ -223,15 +224,13 @@ WebRenderLayerManager::EndTransaction(DrawPaintedLayerCallback aCallback,
mAnimationReadyTime = TimeStamp::Now();
LayoutDeviceIntSize size = mWidget->GetClientSize();
bool success = false;
WRBridge()->SendDPBegin(size.width, size.height, &success);
if (!success) {
if (!WRBridge()->DPBegin(size.width, size.height)) {
return;
}
WebRenderLayer::ToWebRenderLayer(mRoot)->RenderLayer();
WRBridge()->SendDPEnd();
WRBridge()->DPEnd();
}
void

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

@ -26,7 +26,7 @@ WebRenderPaintedLayer::RenderLayer()
}
WRScrollFrameStackingContextGenerator scrollFrames(this);
WRBridge()->SendPushDLBuilder();
WRBridge()->AddWebRenderCommand(OpPushDLBuilder());
RefPtr<DrawTarget> target = gfx::Factory::CreateDrawTarget(gfx::BackendType::SKIA, size.ToUnknownSize(), SurfaceFormat::B8G8R8A8);
target->SetTransform(Matrix().PreTranslate(-bounds.x, -bounds.y));
@ -67,13 +67,14 @@ WebRenderPaintedLayer::RenderLayer()
clip = rect;
}
if (gfxPrefs::LayersDump()) printf_stderr("PaintedLayer %p using rect:%s clip:%s\n", this, Stringify(rect).c_str(), Stringify(clip).c_str());
WRBridge()->SendDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key);
WRBridge()->AddWebRenderCommand(OpDPPushImage(toWrRect(rect), toWrRect(clip), Nothing(), key));
Manager()->AddImageKeyForDiscard(key);
Rect relBounds = TransformedVisibleBoundsRelativeToParent();
Matrix4x4 transform;// = GetTransform();
if (gfxPrefs::LayersDump()) printf_stderr("PaintedLayer %p using %s as bounds/overflow, %s for transform\n", this, Stringify(relBounds).c_str(), Stringify(transform).c_str());
WRBridge()->SendPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID);
WRBridge()->AddWebRenderCommand(
OpPopDLBuilder(toWrRect(relBounds), toWrRect(relBounds), transform, FrameMetrics::NULL_SCROLL_ID));
}
} // namespace layers

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

@ -18,6 +18,10 @@ enum WRImageFormat {
struct WRImageKey {
uint32_t a;
uint32_t b;
bool operator==(const WRImageKey& aRhs) const {
return a == aRhs.a && b == aRhs.b;
}
};
struct WRRect {
@ -25,6 +29,11 @@ struct WRRect {
float y;
float width;
float height;
bool operator==(const WRRect& aRhs) const {
return x == aRhs.x && y == aRhs.y &&
width == aRhs.width && height == aRhs.height;
}
};
struct WRImageMask
@ -32,6 +41,10 @@ struct WRImageMask
WRImageKey image;
WRRect rect;
bool repeat;
bool operator==(const WRImageMask& aRhs) const {
return image == aRhs.image && rect == aRhs.rect && repeat == aRhs.repeat;
}
};