Bug 1321144 - add WebRender TextureHost related classes. r=sotaro?

Add TextureSourceWebRenderOGL for WR GL composition.
Use BindTextureSource/UnbindTextureSource() to provide the TextureSource for WR external image rendering. Currently,only ImageHost supports these functions.

MozReview-Commit-ID: d5EvPUmlpq
This commit is contained in:
JerryShih 2016-12-22 17:22:37 +08:00
Родитель d3ed6a3313
Коммит b1e2dfd641
7 изменённых файлов: 311 добавлений и 11 удалений

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

@ -241,7 +241,19 @@ public:
/// is is destroyed. /// is is destroyed.
virtual void CleanupResources() {} virtual void CleanupResources() {}
virtual void BindTextureSource() {} // Used for WR
// This call will call the Lock() function and return a TextureSource for WR
// composition.
virtual TextureSource* BindTextureSource()
{
MOZ_RELEASE_ASSERT(true, "No implementation for BindTextureSource()");
return nullptr;
}
virtual void UnbindTextureSource()
{
MOZ_RELEASE_ASSERT(true, "No implementation for UnindTextureSource()");
}
protected: protected:
TextureInfo mTextureInfo; TextureInfo mTextureInfo;

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

@ -434,14 +434,20 @@ ImageHost::Composite(LayerComposite* aLayer,
mBias); mBias);
} }
void TextureSource*
ImageHost::BindTextureSource() ImageHost::BindTextureSource()
{ {
int imageIndex = ChooseImageIndex(); int imageIndex = ChooseImageIndex();
if (imageIndex < 0) { if (imageIndex < 0) {
return; return nullptr;
} }
mBias = UpdateBias(GetCompositor()->GetCompositionTime(),
mImages[imageIndex].mTimeStamp,
uint32_t(imageIndex + 1) < mImages.Length() ?
mImages[imageIndex + 1].mTimeStamp :TimeStamp(),
mBias);
if (uint32_t(imageIndex) + 1 < mImages.Length()) { if (uint32_t(imageIndex) + 1 < mImages.Length()) {
GetCompositor()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS)); GetCompositor()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS));
} }
@ -450,13 +456,23 @@ ImageHost::BindTextureSource()
img->mTextureHost->SetCompositor(GetCompositor()); img->mTextureHost->SetCompositor(GetCompositor());
SetCurrentTextureHost(img->mTextureHost); SetCurrentTextureHost(img->mTextureHost);
// XXX Add TextureSource binding // XXX: handle the lock failed in UnbindTextureSource()
if (!Lock()) {
MOZ_RELEASE_ASSERT(false, "ImageHost::BindTextureSource() locks failed");
return nullptr;
}
if (!mCurrentTextureHost->BindTextureSource(mCurrentTextureSource)) {
MOZ_RELEASE_ASSERT(false, "ImageHost::BindTextureSource() binds textureSource failed");
return nullptr;
}
mBias = UpdateBias( return mCurrentTextureSource.get();
GetCompositor()->GetCompositionTime(), mImages[imageIndex].mTimeStamp, }
uint32_t(imageIndex + 1) < mImages.Length() ?
mImages[imageIndex + 1].mTimeStamp : TimeStamp(), void
mBias); ImageHost::UnbindTextureSource()
{
Unlock();
} }
void void

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

@ -91,7 +91,8 @@ public:
virtual void CleanupResources() override; virtual void CleanupResources() override;
virtual void BindTextureSource() override; virtual TextureSource* BindTextureSource() override;
virtual void UnbindTextureSource() override;
int32_t GetFrameID() int32_t GetFrameID()
{ {

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

@ -49,6 +49,7 @@ class ISurfaceAllocator;
class TextureHostOGL; class TextureHostOGL;
class TextureReadLock; class TextureReadLock;
class TextureSourceOGL; class TextureSourceOGL;
class TextureSourceWebRenderOGL;
class TextureSourceD3D9; class TextureSourceD3D9;
class TextureSourceD3D11; class TextureSourceD3D11;
class TextureSourceBasic; class TextureSourceBasic;
@ -116,10 +117,16 @@ public:
/** /**
* Cast to a TextureSource for for each backend.. * Cast to a TextureSource for for each backend..
*/ */
virtual TextureSourceOGL* AsSourceOGL() { virtual TextureSourceOGL* AsSourceOGL()
{
gfxCriticalNote << "Failed to cast " << Name() << " into a TextureSourceOGL"; gfxCriticalNote << "Failed to cast " << Name() << " into a TextureSourceOGL";
return nullptr; return nullptr;
} }
virtual TextureSourceWebRenderOGL* AsSourceWebRenderOGL()
{
gfxCriticalNote << "Failed to cast " << Name() << " into a TextureSourceWebRenderOGL";
return nullptr;
}
virtual TextureSourceD3D9* AsSourceD3D9() { return nullptr; } virtual TextureSourceD3D9* AsSourceD3D9() { return nullptr; }
virtual TextureSourceD3D11* AsSourceD3D11() { return nullptr; } virtual TextureSourceD3D11* AsSourceD3D11() { return nullptr; }
virtual TextureSourceBasic* AsSourceBasic() { return nullptr; } virtual TextureSourceBasic* AsSourceBasic() { return nullptr; }

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

@ -202,6 +202,7 @@ EXPORTS.mozilla.layers += [
'RenderTrace.h', 'RenderTrace.h',
'TextureWrapperImage.h', 'TextureWrapperImage.h',
'TransactionIdAllocator.h', 'TransactionIdAllocator.h',
'wr/TextureHostWebRenderOGL.h',
'wr/WebRenderBridgeChild.h', 'wr/WebRenderBridgeChild.h',
'wr/WebRenderBridgeParent.h', 'wr/WebRenderBridgeParent.h',
'wr/WebRenderCompositorOGL.h', 'wr/WebRenderCompositorOGL.h',
@ -381,6 +382,7 @@ UNIFIED_SOURCES += [
'RenderTrace.cpp', 'RenderTrace.cpp',
'RotatedBuffer.cpp', 'RotatedBuffer.cpp',
'TextureWrapperImage.cpp', 'TextureWrapperImage.cpp',
'wr/TextureHostWebRenderOGL.cpp',
'wr/WebRenderBridgeChild.cpp', 'wr/WebRenderBridgeChild.cpp',
'wr/WebRenderBridgeParent.cpp', 'wr/WebRenderBridgeParent.cpp',
'wr/WebRenderCanvasLayer.cpp', 'wr/WebRenderCanvasLayer.cpp',

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

@ -0,0 +1,130 @@
/* -*- 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 "TextureHostWebRenderOGL.h"
#include "WebRenderCompositorOGL.h"
namespace mozilla {
namespace layers {
WebRenderCompositorOGL* AssertWebRenderCompositorOGL(Compositor* aCompositor)
{
WebRenderCompositorOGL* compositor =
aCompositor ? aCompositor->AsWebRenderCompositorOGL() : nullptr;
MOZ_ASSERT(!!compositor);
return compositor;
}
bool
TextureImageTextureSourceWebRenderOGL::Update(gfx::DataSourceSurface* aSurface,
nsIntRegion* aDestRegion,
gfx::IntPoint* aSrcOffset)
{
GLContext *gl = mCompositor->gl();
MOZ_ASSERT(gl);
if (!gl || !gl->MakeCurrent()) {
NS_WARNING("trying to update TextureImageTextureSourceWebRenderOGL without a GLContext");
return false;
}
if (!aSurface) {
gfxCriticalError() << "Invalid surface for WebRenderOGL update";
return false;
}
MOZ_ASSERT(aSurface);
IntSize size = aSurface->GetSize();
if (!mTexImage ||
(mTexImage->GetSize() != size && !aSrcOffset) ||
mTexImage->GetContentType() != gfx::ContentForFormat(aSurface->GetFormat())) {
if (mFlags & TextureFlags::DISALLOW_BIGIMAGE) {
GLint maxTextureSize;
gl->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTextureSize);
if (size.width > maxTextureSize || size.height > maxTextureSize) {
NS_WARNING("Texture exceeds maximum texture size, refusing upload");
return false;
}
// Explicitly use CreateBasicTextureImage instead of CreateTextureImage,
// because CreateTextureImage might still choose to create a tiled
// texture image.
mTexImage = CreateBasicTextureImage(gl, size,
gfx::ContentForFormat(aSurface->GetFormat()),
LOCAL_GL_CLAMP_TO_EDGE,
FlagsToGLFlags(mFlags));
} else {
// XXX - clarify which size we want to use. IncrementalContentHost will
// require the size of the destination surface to be different from
// the size of aSurface.
// See bug 893300 (tracks the implementation of ContentHost for new textures).
mTexImage = CreateTextureImage(gl,
size,
gfx::ContentForFormat(aSurface->GetFormat()),
LOCAL_GL_CLAMP_TO_EDGE,
FlagsToGLFlags(mFlags),
SurfaceFormatToImageFormat(aSurface->GetFormat()));
}
if (aDestRegion &&
!aSrcOffset &&
!aDestRegion->IsEqual(gfx::IntRect(0, 0, size.width, size.height))) {
// UpdateFromDataSource will ignore our specified aDestRegion since the texture
// hasn't been allocated with glTexImage2D yet. Call Resize() to force the
// allocation (full size, but no upload), and then we'll only upload the pixels
// we care about below.
mTexImage->Resize(size);
}
}
mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
return true;
}
void
TextureImageTextureSourceWebRenderOGL::SetCompositor(Compositor* aCompositor)
{
WebRenderCompositorOGL* glCompositor = AssertWebRenderCompositorOGL(aCompositor);
if (!glCompositor) {
DeallocateDeviceData();
return;
}
if (mCompositor != glCompositor) {
DeallocateDeviceData();
mCompositor = glCompositor;
}
}
gfx::IntSize
TextureImageTextureSourceWebRenderOGL::GetSize() const
{
if (mTexImage) {
if (mIterating) {
return mTexImage->GetTileRect().Size();
}
return mTexImage->GetSize();
}
NS_WARNING("Trying to query the size of an empty TextureSource.");
return gfx::IntSize(0, 0);
}
gfx::SurfaceFormat
TextureImageTextureSourceWebRenderOGL::GetFormat() const
{
if (mTexImage) {
return mTexImage->GetTextureFormat();
}
NS_WARNING("Trying to query the format of an empty TextureSource.");
return gfx::SurfaceFormat::UNKNOWN;
}
gfx::IntRect
TextureImageTextureSourceWebRenderOGL::GetTileRect()
{
return mTexImage->GetTileRect();
}
} // namespace layers
} // namespace mozilla

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

@ -0,0 +1,132 @@
/* -*- 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_TEXTUREHOSTWEBRENDEROGL_H
#define MOZILLA_GFX_TEXTUREHOSTWEBRENDEROGL_H
#include <stddef.h> // for size_t
#include <stdint.h> // for uint64_t
#include "GLContextTypes.h" // for GLContext
#include "GLTextureImage.h" // for TextureImage
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Attributes.h" // for override
#include "mozilla/RefPtr.h" // for RefPtr
#include "mozilla/gfx/Point.h" // for IntSize, IntPoint
#include "mozilla/gfx/Types.h" // for SurfaceFormat, etc
#include "mozilla/layers/CompositorTypes.h" // for TextureFlags
#include "mozilla/layers/TextureHost.h" // for TextureHost, etc
#include "nsRegionFwd.h" // for nsIntRegion
namespace mozilla {
namespace layers {
class Compositor;
class TextureImageTextureSourceWebRenderOGL;
class TextureSourceWebRenderOGL
{
public:
TextureSourceWebRenderOGL() {}
virtual ~TextureSourceWebRenderOGL() {}
virtual gl::TextureImage* GetTextureImage() = 0;
virtual TextureImageTextureSourceWebRenderOGL* AsTextureImageTextureSource() { return nullptr; }
};
/**
* A TextureSourceWebRenderOGL backed by a TextureImage.
*/
class TextureImageTextureSourceWebRenderOGL final : public DataTextureSource
, public TextureSourceWebRenderOGL
, public BigImageIterator
{
public:
explicit TextureImageTextureSourceWebRenderOGL(WebRenderCompositorOGL *aCompositor,
TextureFlags aFlags = TextureFlags::DEFAULT)
: mCompositor(aCompositor)
, mFlags(aFlags)
, mIterating(false)
{
}
virtual const char* Name() const override
{
return "TextureImageTextureSourceWebRenderOGL";
}
virtual TextureImageTextureSourceWebRenderOGL* AsTextureImageTextureSource() override
{
return this;
}
virtual gl::TextureImage* GetTextureImage() override
{
return mTexImage.get();
}
// DataTextureSource
virtual bool Update(gfx::DataSourceSurface* aSurface,
nsIntRegion* aDestRegion = nullptr,
gfx::IntPoint* aSrcOffset = nullptr) override;
//
// TextureSource
virtual void DeallocateDeviceData() override
{
mTexImage = nullptr;
SetUpdateSerial(0);
}
virtual TextureSourceWebRenderOGL* AsSourceWebRenderOGL() override
{
return this;
}
virtual gfx::IntSize GetSize() const override;
virtual gfx::SurfaceFormat GetFormat() const override;
virtual void SetCompositor(Compositor* aCompositor) override;
//
// BigImageIterator
virtual BigImageIterator* AsBigImageIterator() override { return this; }
virtual void BeginBigImageIteration() override
{
mTexImage->BeginBigImageIteration();
mIterating = true;
}
virtual void EndBigImageIteration() override
{
mIterating = false;
}
virtual gfx::IntRect GetTileRect() override;
virtual size_t GetTileCount() override
{
return mTexImage->GetTileCount();
}
virtual bool NextTile() override
{
return mTexImage->NextTile();
}
//
private:
RefPtr<gl::TextureImage> mTexImage;
RefPtr<WebRenderCompositorOGL> mCompositor;
TextureFlags mFlags;
bool mIterating;
};
} // namespace layers
} // namespace mozilla
#endif /* MOZILLA_GFX_TEXTUREOGL_H */