Bug 952977: Switch GL world transform to gfx::Matrix r=nical

This commit is contained in:
David Zbarsky 2014-01-16 02:22:19 -05:00
parent 31a9b91a59
commit 3e4ce3885c
19 changed files with 74 additions and 52 deletions

View File

@ -206,6 +206,23 @@ public:
FuzzyEqual(_32, floorf(_32 + 0.5f));
}
/**
* Returns true if matrix is multiple of 90 degrees rotation with flipping,
* scaling and translation.
*/
bool PreservesAxisAlignedRectangles() const {
return ((FuzzyEqual(_11, 0.0) && FuzzyEqual(_22, 0.0))
|| (FuzzyEqual(_12, 0.0) && FuzzyEqual(_21, 0.0)));
}
/**
* Returns true if the matrix has non-integer scale
*/
bool HasNonIntegerScale() const {
return !FuzzyEqual(_11, floor(_11 + 0.5)) ||
!FuzzyEqual(_22, floor(_22 + 0.5));
}
private:
static bool FuzzyEqual(Float aV1, Float aV2) {
// XXX - Check if fabs does the smart thing and just negates the sign bit.

View File

@ -110,6 +110,7 @@ class nsIntRegion;
namespace mozilla {
namespace gfx {
class Matrix;
class Matrix4x4;
class DrawTarget;
}
@ -324,7 +325,7 @@ public:
*/
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect* aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect* aClipRectOut = nullptr,
gfx::Rect* aRenderBoundsOut = nullptr) = 0;
@ -339,7 +340,7 @@ public:
* e.g., by Composer2D.
* aTransform is the transform from user space to window space.
*/
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) = 0;
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) = 0;
/**
* Tidy up if BeginFrame has been called, but EndFrame won't be.

View File

@ -559,7 +559,7 @@ Layer::MayResample()
nsIntRect
Layer::CalculateScissorRect(const nsIntRect& aCurrentScissorRect,
const gfxMatrix* aWorldTransform)
const gfx::Matrix* aWorldTransform)
{
ContainerLayer* container = GetParent();
NS_ASSERTION(container, "This can't be called on the root!");
@ -605,10 +605,10 @@ Layer::CalculateScissorRect(const nsIntRect& aCurrentScissorRect,
if (container) {
scissor.MoveBy(-container->GetIntermediateSurfaceRect().TopLeft());
} else if (aWorldTransform) {
gfxRect r(scissor.x, scissor.y, scissor.width, scissor.height);
gfxRect trScissor = aWorldTransform->TransformBounds(r);
gfx::Rect r(scissor.x, scissor.y, scissor.width, scissor.height);
gfx::Rect trScissor = aWorldTransform->TransformBounds(r);
trScissor.Round();
if (!gfxUtils::GfxRectToIntRect(trScissor, &scissor))
if (!gfxUtils::GfxRectToIntRect(ThebesRect(trScissor), &scissor))
return nsIntRect(currentClip.TopLeft(), nsIntSize(0, 0));
}
return currentClip.Intersect(scissor);

View File

@ -1255,7 +1255,7 @@ public:
* aWorldTransform is non-null.
*/
nsIntRect CalculateScissorRect(const nsIntRect& aCurrentScissorRect,
const gfxMatrix* aWorldTransform);
const gfx::Matrix* aWorldTransform);
virtual const char* Name() const =0;
virtual LayerType GetType() const =0;

View File

@ -530,7 +530,7 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
void
BasicCompositor::BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect *aClipRectOut /* = nullptr */,
gfx::Rect *aRenderBoundsOut /* = nullptr */)

View File

@ -86,12 +86,12 @@ public:
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect *aClipRectOut = nullptr,
gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;
virtual void EndFrame() MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE
{
NS_RUNTIMEABORT("We shouldn't ever hit this");
}

View File

@ -20,7 +20,6 @@
#include "Units.h" // for ScreenIntRect
#include "gfx2DGlue.h" // for ToMatrix4x4
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxMatrix.h" // for gfxMatrix
#include "gfxPlatform.h" // for gfxPlatform
#ifdef XP_MACOSX
#include "gfxPlatformMac.h"
@ -416,7 +415,7 @@ LayerManagerComposite::Render()
}
void
LayerManagerComposite::SetWorldTransform(const gfxMatrix& aMatrix)
LayerManagerComposite::SetWorldTransform(const gfx::Matrix& aMatrix)
{
NS_ASSERTION(aMatrix.PreservesAxisAlignedRectangles(),
"SetWorldTransform only accepts matrices that satisfy PreservesAxisAlignedRectangles");
@ -426,7 +425,7 @@ LayerManagerComposite::SetWorldTransform(const gfxMatrix& aMatrix)
mWorldMatrix = aMatrix;
}
gfxMatrix&
gfx::Matrix&
LayerManagerComposite::GetWorldTransform(void)
{
return mWorldMatrix;
@ -435,7 +434,7 @@ LayerManagerComposite::GetWorldTransform(void)
void
LayerManagerComposite::WorldTransformRect(nsIntRect& aRect)
{
gfxRect grect(aRect.x, aRect.y, aRect.width, aRect.height);
gfx::Rect grect(aRect.x, aRect.y, aRect.width, aRect.height);
grect = mWorldMatrix.TransformBounds(grect);
aRect.SetRect(grect.X(), grect.Y(), grect.Width(), grect.Height());
}

View File

@ -10,7 +10,6 @@
#include "GLDefs.h" // for GLenum
#include "Layers.h"
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxMatrix.h" // for gfxMatrix
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Attributes.h" // for MOZ_OVERRIDE
#include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef
@ -162,8 +161,8 @@ public:
* Transform will be ignored if it is not PreservesAxisAlignedRectangles
* or has non integer scale
*/
void SetWorldTransform(const gfxMatrix& aMatrix);
gfxMatrix& GetWorldTransform(void);
void SetWorldTransform(const gfx::Matrix& aMatrix);
gfx::Matrix& GetWorldTransform(void);
/**
* RAII helper class to add a mask effect with the compositable from aMaskLayer
@ -259,7 +258,7 @@ private:
RefPtr<Compositor> mCompositor;
gfxMatrix mWorldMatrix;
gfx::Matrix mWorldMatrix;
bool mInTransaction;
bool mIsCompositorReady;

View File

@ -669,7 +669,7 @@ CompositorD3D11::DrawQuad(const gfx::Rect& aRect,
void
CompositorD3D11::BeginFrame(const nsIntRegion& aInvalidRegion,
const Rect* aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const Rect& aRenderBounds,
Rect* aClipRectOut,
Rect* aRenderBoundsOut)

View File

@ -102,7 +102,7 @@ public:
*/
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect *aClipRectOut = nullptr,
gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;
@ -116,7 +116,7 @@ public:
* Post rendering stuff if the rendering is outside of this Compositor
* e.g., by Composer2D
*/
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE {}
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {}
/**
* Tidy up if BeginFrame has been called, but EndFrame won't be

View File

@ -586,7 +586,7 @@ CancelCompositing(Rect* aRenderBoundsOut)
void
CompositorD3D9::BeginFrame(const nsIntRegion& aInvalidRegion,
const Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const Rect& aRenderBounds,
Rect *aClipRectOut,
Rect *aRenderBoundsOut)

View File

@ -63,14 +63,14 @@ public:
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect *aClipRectOut = nullptr,
gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;
virtual void EndFrame() MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE {}
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {}
virtual void AbortFrame() MOZ_OVERRIDE {}

View File

@ -26,9 +26,12 @@
* layer manager fall back on full GPU composition.
*/
struct gfxMatrix;
namespace mozilla {
namespace gfx {
struct Matrix;
}
namespace layers {
class Layer;
@ -53,7 +56,7 @@ public:
* Currently, when TryRender() returns true, the entire framebuffer
* must have been rendered.
*/
virtual bool TryRender(Layer* aRoot, const gfxMatrix& aWorldTransform) = 0;
virtual bool TryRender(Layer* aRoot, const gfx::Matrix& aWorldTransform) = 0;
};
} // namespace layers

View File

@ -770,7 +770,7 @@ CalculatePOTSize(const IntSize& aSize, GLContext* gl)
void
CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
const Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Matrix& aTransform,
const Rect& aRenderBounds,
Rect *aClipRectOut,
Rect *aRenderBoundsOut)
@ -783,11 +783,11 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
mVBOs.Reset();
mFrameInProgress = true;
gfxRect rect;
gfx::Rect rect;
if (mUseExternalSurfaceSize) {
rect = gfxRect(0, 0, mSurfaceSize.width, mSurfaceSize.height);
rect = gfx::Rect(0, 0, mSurfaceSize.width, mSurfaceSize.height);
} else {
rect = gfxRect(aRenderBounds.x, aRenderBounds.y, aRenderBounds.width, aRenderBounds.height);
rect = gfx::Rect(aRenderBounds.x, aRenderBounds.y, aRenderBounds.width, aRenderBounds.height);
// If render bounds is not updated explicitly, try to infer it from widget
if (rect.width == 0 || rect.height == 0) {
// FIXME/bug XXXXXX this races with rotation changes on the main
@ -795,13 +795,13 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
// sent atomically with rotation changes
nsIntRect intRect;
mWidget->GetClientBounds(intRect);
rect = gfxRect(0, 0, intRect.width, intRect.height);
rect = gfx::Rect(0, 0, intRect.width, intRect.height);
}
}
rect = aTransform.TransformBounds(rect);
if (aRenderBoundsOut) {
*aRenderBoundsOut = Rect(rect.x, rect.y, rect.width, rect.height);
*aRenderBoundsOut = rect;
}
GLint width = rect.width;
@ -834,7 +834,7 @@ CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
mCurrentRenderTarget = CompositingRenderTargetOGL::RenderTargetForWindow(this,
IntSize(width, height),
aTransform);
ThebesMatrix(aTransform));
mCurrentRenderTarget->BindRenderTarget();
#ifdef DEBUG
mWindowRenderTarget = mCurrentRenderTarget;
@ -1427,7 +1427,7 @@ CompositorOGL::EndFrame()
}
void
CompositorOGL::EndFrameForExternalComposition(const gfxMatrix& aTransform)
CompositorOGL::EndFrameForExternalComposition(const gfx::Matrix& aTransform)
{
if (sDrawFPS) {
if (!mFPS) {
@ -1440,7 +1440,7 @@ CompositorOGL::EndFrameForExternalComposition(const gfxMatrix& aTransform)
// This lets us reftest and screenshot content rendered externally
if (mTarget) {
MakeCurrent();
CopyToTarget(mTarget, aTransform);
CopyToTarget(mTarget, ThebesMatrix(aTransform));
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
}
}

View File

@ -112,7 +112,7 @@ public:
virtual void EndFrame() MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE;
virtual void AbortFrame() MOZ_OVERRIDE;
virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE;
@ -257,8 +257,8 @@ private:
*/
virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
const gfx::Rect *aClipRectIn,
const gfxMatrix& aTransform,
const gfx::Rect& aRenderBounds,
const gfx::Matrix& aTransform,
const gfx::Rect& aRenderBounds,
gfx::Rect *aClipRectOut = nullptr,
gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;

View File

@ -8,7 +8,8 @@
#ifndef mozilla_WidgetUtils_h
#define mozilla_WidgetUtils_h
#include "gfxMatrix.h"
#include "nsRect.h"
#include "mozilla/gfx/Matrix.h"
namespace mozilla {
@ -22,8 +23,8 @@ enum ScreenRotation {
ROTATION_COUNT
};
gfxMatrix ComputeTransformForRotation(const nsIntRect& aBounds,
ScreenRotation aRotation);
gfx::Matrix ComputeTransformForRotation(const nsIntRect& aBounds,
ScreenRotation aRotation);
} // namespace mozilla

View File

@ -26,6 +26,7 @@
#include "mozilla/layers/ShadowLayerUtilsGralloc.h"
#include "mozilla/StaticPtr.h"
#include "cutils/properties.h"
#include "gfx2DGlue.h"
#if ANDROID_VERSION >= 18
#include "libdisplay/FramebufferSurface.h"
@ -648,8 +649,9 @@ HwcComposer2D::Reset()
bool
HwcComposer2D::TryRender(Layer* aRoot,
const gfxMatrix& aGLWorldTransform)
const gfx::Matrix& GLWorldTransform)
{
gfxMatrix aGLWorldTransform = ThebesMatrix(GLWorldTransform);
if (!aGLWorldTransform.PreservesAxisAlignedRectangles()) {
LOGD("Render aborted. World transform has non-square angle rotation");
return false;

View File

@ -58,7 +58,7 @@ public:
// Returns TRUE if the container has been succesfully rendered
// Returns FALSE if the container cannot be fully rendered
// by this composer so nothing was rendered at all
bool TryRender(layers::Layer* aRoot, const gfxMatrix& aGLWorldTransform) MOZ_OVERRIDE;
bool TryRender(layers::Layer* aRoot, const gfx::Matrix& aGLWorldTransform) MOZ_OVERRIDE;
bool Render(EGLDisplay dpy, EGLSurface sur);

View File

@ -9,25 +9,25 @@
namespace mozilla {
gfxMatrix
gfx::Matrix
ComputeTransformForRotation(const nsIntRect& aBounds,
ScreenRotation aRotation)
{
gfxMatrix transform;
gfx::Matrix transform;
switch (aRotation) {
case ROTATION_0:
break;
case ROTATION_90:
transform.Translate(gfxPoint(aBounds.width, 0));
transform.Rotate(M_PI / 2);
transform.Translate(aBounds.width, 0);
transform = gfx::Matrix::Rotation(M_PI / 2) * transform;
break;
case ROTATION_180:
transform.Translate(gfxPoint(aBounds.width, aBounds.height));
transform.Rotate(M_PI);
transform.Translate(aBounds.width, aBounds.height);
transform = gfx::Matrix::Rotation(M_PI) * transform;
break;
case ROTATION_270:
transform.Translate(gfxPoint(0, aBounds.height));
transform.Rotate(M_PI * 3 / 2);
transform.Translate(0, aBounds.height);
transform = gfx::Matrix::Rotation(M_PI * 3 / 2) * transform;
break;
default:
MOZ_CRASH("Unknown rotation");