Bug 1312316 - Add stubbed WebRenderCompositorOGL r=nical

This commit is contained in:
sotaro
2016-11-17 18:02:56 +09:00
parent f21354f632
commit ebe36d991c
8 changed files with 229 additions and 5 deletions

View File

@@ -577,7 +577,7 @@ public:
// A stale Compositor has no CompositorBridgeParent; it will not process
// frames and should not be used.
void SetInvalid();
bool IsValid() const;
virtual bool IsValid() const;
CompositorBridgeParent* GetCompositorBridgeParent() const {
return mParent;
}

View File

@@ -50,6 +50,7 @@
#include "mozilla/layers/PLayerTransactionParent.h"
#include "mozilla/layers/RemoteContentController.h"
#include "mozilla/layers/WebRenderBridgeParent.h"
#include "mozilla/layers/WebRenderCompositorOGL.h"
#include "mozilla/layout/RenderFrameParent.h"
#include "mozilla/media/MediaSystemResourceService.h" // for MediaSystemResourceService
#include "mozilla/mozalloc.h" // for operator new, etc
@@ -1852,8 +1853,9 @@ CompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t& aPipelineId,
MOZ_ASSERT(aPipelineId == mRootLayerTreeID);
RefPtr<gl::GLContext> glc(gl::GLContextProvider::CreateForCompositorWidget(mWidget, true));
RefPtr<Compositor> compositor = new WebRenderCompositorOGL(glc.get());
WebRenderBridgeParent* parent = new WebRenderBridgeParent(aPipelineId,
&aResourcePath, mWidget, glc.get(), nullptr);
&aResourcePath, mWidget, glc.get(), nullptr, compositor.get());
parent->AddRef(); // IPDL reference
MonitorAutoLock lock(*sIndirectLayerTreesLock);
MOZ_ASSERT(sIndirectLayerTrees[aPipelineId].mWRBridge == nullptr);

View File

@@ -269,7 +269,7 @@ CrossProcessCompositorBridgeParent::AllocPWebRenderBridgeParent(const uint64_t&
WebRenderBridgeParent* root = sIndirectLayerTrees[cbp->RootLayerTreeId()].mWRBridge.get();
WebRenderBridgeParent* parent = new WebRenderBridgeParent(
aPipelineId, nullptr, nullptr, root->GLContext(), root->WindowState());
aPipelineId, nullptr, nullptr, root->GLContext(), root->WindowState(), root->Compositor());
parent->AddRef(); // IPDL reference
sIndirectLayerTrees[aPipelineId].mWRBridge = parent;

View File

@@ -204,6 +204,7 @@ EXPORTS.mozilla.layers += [
'TransactionIdAllocator.h',
'wr/WebRenderBridgeChild.h',
'wr/WebRenderBridgeParent.h',
'wr/WebRenderCompositorOGL.h',
'wr/WebRenderLayerManager.h',
'wr/WebRenderTypes.h',
]
@@ -380,6 +381,7 @@ UNIFIED_SOURCES += [
'wr/WebRenderBridgeParent.cpp',
'wr/WebRenderCanvasLayer.cpp',
'wr/WebRenderColorLayer.cpp',
'wr/WebRenderCompositorOGL.cpp',
'wr/WebRenderContainerLayer.cpp',
'wr/WebRenderImageLayer.cpp',
'wr/WebRenderLayerManager.cpp',

View File

@@ -8,6 +8,7 @@
#include "GLContext.h"
#include "GLContextProvider.h"
#include "mozilla/layers/Compositor.h"
#include "mozilla/widget/CompositorWidget.h"
namespace mozilla {
@@ -17,14 +18,17 @@ WebRenderBridgeParent::WebRenderBridgeParent(const uint64_t& aPipelineId,
const nsString* aResourcePath,
widget::CompositorWidget* aWidget,
gl::GLContext* aGlContext,
wrwindowstate* aWrWindowState)
wrwindowstate* aWrWindowState,
layers::Compositor* aCompositor)
: mPipelineId(aPipelineId)
, mWidget(aWidget)
, mWRState(nullptr)
, mGLContext(aGlContext)
, mWRWindowState(aWrWindowState)
, mCompositor(aCompositor)
{
MOZ_ASSERT(mGLContext);
MOZ_ASSERT(mCompositor);
if (!mWRWindowState) {
// mWRWindowState should only be null for the root WRBP of a layers tree,
// i.e. the one created by the CompositorBridgeParent as opposed to the
@@ -53,8 +57,12 @@ mozilla::ipc::IPCResult
WebRenderBridgeParent::RecvDestroy()
{
MOZ_ASSERT(mWRState);
MOZ_ASSERT(mCompositor);
wr_destroy(mWRState);
mWRState = nullptr;
if (mWidget) {
mCompositor->Destroy();
}
return IPC_OK();
}

View File

@@ -23,6 +23,8 @@ class CompositorWidget;
namespace layers {
class Compositor;
class WebRenderBridgeParent final : public PWebRenderBridgeParent
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebRenderBridgeParent)
@@ -32,10 +34,12 @@ public:
const nsString* aResourcePath,
widget::CompositorWidget* aWidget,
gl::GLContext* aGlContext,
wrwindowstate* aWrWindowState);
wrwindowstate* aWrWindowState,
layers::Compositor* aCompositor);
uint64_t PipelineId() { return mPipelineId; }
gl::GLContext* GLContext() { return mGLContext.get(); }
wrwindowstate* WindowState() { return mWRWindowState; }
layers::Compositor* Compositor() { return mCompositor.get(); }
mozilla::ipc::IPCResult RecvCreate(const uint32_t& aWidth,
const uint32_t& aHeight) override;
@@ -87,6 +91,7 @@ private:
wrstate* mWRState;
RefPtr<gl::GLContext> mGLContext;
wrwindowstate* mWRWindowState;
RefPtr<layers::Compositor> mCompositor;
std::vector<WRImageKey> mKeysToDelete;
};

View File

@@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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 "WebRenderCompositorOGL.h"
#include "GLContext.h" // for GLContext
#include "GLUploadHelpers.h"
#include "mozilla/layers/TextureHost.h" // for TextureSource, etc
#include "mozilla/layers/TextureHostOGL.h" // for TextureSourceOGL, etc
namespace mozilla {
using namespace gfx;
namespace layers {
using namespace mozilla::gl;
WebRenderCompositorOGL::WebRenderCompositorOGL(GLContext* aGLContext)
: Compositor(nullptr, nullptr)
, mDestroyed(false)
{
MOZ_COUNT_CTOR(WebRenderCompositorOGL);
}
WebRenderCompositorOGL::~WebRenderCompositorOGL()
{
MOZ_COUNT_DTOR(WebRenderCompositorOGL);
Destroy();
}
void
WebRenderCompositorOGL::Destroy()
{
Compositor::Destroy();
if (!mDestroyed) {
mDestroyed = true;
mGLContext = nullptr;;
}
}
bool
WebRenderCompositorOGL::Initialize(nsCString* const out_failureReason)
{
MOZ_ASSERT(mGLContext);
return true;
}
already_AddRefed<DataTextureSource>
WebRenderCompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
{
return nullptr;
}
bool
WebRenderCompositorOGL::SupportsPartialTextureUpdate()
{
return CanUploadSubTextures(mGLContext);
}
int32_t
WebRenderCompositorOGL::GetMaxTextureSize() const
{
MOZ_ASSERT(mGLContext);
GLint texSize = 0;
mGLContext->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE,
&texSize);
MOZ_ASSERT(texSize != 0);
return texSize;
}
void
WebRenderCompositorOGL::MakeCurrent(MakeCurrentFlags aFlags) {
if (mDestroyed) {
NS_WARNING("Call on destroyed layer manager");
return;
}
mGLContext->MakeCurrent(aFlags & ForceMakeCurrent);
}
} // namespace layers
} // namespace mozilla

View File

@@ -0,0 +1,122 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#ifndef MOZILLA_GFX_WEBRENDERCOMPOSITOROGL_H
#define MOZILLA_GFX_WEBRENDERCOMPOSITOROGL_H
#include "GLContextTypes.h" // for GLContext, etc
#include "GLDefs.h" // for GLuint, LOCAL_GL_TEXTURE_2D, etc
#include "mozilla/layers/Compositor.h" // for SurfaceInitMode, Compositor, etc
namespace mozilla {
namespace layers {
class WebRenderCompositorOGL final : public Compositor
{
typedef mozilla::gl::GLContext GLContext;
public:
explicit WebRenderCompositorOGL(GLContext* aGLContext);
protected:
virtual ~WebRenderCompositorOGL();
public:
virtual already_AddRefed<DataTextureSource>
CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
virtual bool Initialize(nsCString* const out_failureReason) override;
virtual void Destroy() override;
virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override
{
TextureFactoryIdentifier result =
TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL,
XRE_GetProcessType(),
GetMaxTextureSize(),
true,
SupportsPartialTextureUpdate());
return result;
}
virtual already_AddRefed<CompositingRenderTarget>
CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) override { return nullptr; }
virtual already_AddRefed<CompositingRenderTarget>
CreateRenderTargetFromSource(const gfx::IntRect &aRect,
const CompositingRenderTarget *aSource,
const gfx::IntPoint &aSourcePoint) override { return nullptr; }
virtual void SetRenderTarget(CompositingRenderTarget *aSurface) override { }
virtual CompositingRenderTarget* GetCurrentRenderTarget() const override { return nullptr; }
virtual void DrawQuad(const gfx::Rect& aRect,
const gfx::IntRect& aClipRect,
const EffectChain &aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4& aTransform,
const gfx::Rect& aVisibleRect) { }
virtual void DrawTriangle(const gfx::TexturedTriangle& aTriangle,
const gfx::IntRect& aClipRect,
const EffectChain& aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4& aTransform,
const gfx::Rect& aVisibleRect) { }
virtual void ClearRect(const gfx::Rect& aRect) { }
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::IntRect *aClipRectIn,
const gfx::IntRect& aRenderBounds,
const nsIntRegion& aOpaqueRegion,
gfx::IntRect *aClipRectOut = nullptr,
gfx::IntRect *aRenderBoundsOut = nullptr) override { }
virtual void EndFrame() override { }
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) override { }
virtual bool SupportsPartialTextureUpdate() override;
virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) override
{
if (!mGLContext)
return false;
int32_t maxSize = GetMaxTextureSize();
return aSize <= gfx::IntSize(maxSize, maxSize);
}
virtual int32_t GetMaxTextureSize() const override;
virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) override { }
virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) override { }
virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) override;
#ifdef MOZ_DUMP_PAINTING
virtual const char* Name() const override { return "WROGL"; }
#endif // MOZ_DUMP_PAINTING
virtual LayersBackend GetBackendType() const override {
return LayersBackend::LAYERS_OPENGL;
}
virtual bool IsValid() const override { return true; }
GLContext* gl() const { return mGLContext; }
private:
RefPtr<GLContext> mGLContext;
bool mDestroyed;
};
} // namespace layers
} // namespace mozilla
#endif /* MOZILLA_GFX_WEBRENDERCOMPOSITOROGL_H */