mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Extract some compositor functions into a LayersHelpers header. (bug 1365879 part 3, r=mattwoodrow)
This commit is contained in:
parent
65b03ef2d4
commit
f52c24e301
@ -14,6 +14,7 @@
|
||||
#include "mozilla/mozalloc.h" // for operator delete, etc
|
||||
#include "gfx2DGlue.h"
|
||||
#include "nsAppRunner.h"
|
||||
#include "LayersHelpers.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
@ -267,7 +268,7 @@ Compositor::DrawTriangles(const nsTArray<gfx::TexturedTriangle>& aTriangles,
|
||||
}
|
||||
}
|
||||
|
||||
static nsTArray<gfx::TexturedTriangle>
|
||||
nsTArray<gfx::TexturedTriangle>
|
||||
GenerateTexturedTriangles(const gfx::Polygon& aPolygon,
|
||||
const gfx::Rect& aRect,
|
||||
const gfx::Rect& aTexRect)
|
||||
@ -584,37 +585,13 @@ Compositor::ComputeBackdropCopyRect(const gfx::Rect& aRect,
|
||||
gfx::IntPoint rtOffset = GetCurrentRenderTarget()->GetOrigin();
|
||||
gfx::IntSize rtSize = GetCurrentRenderTarget()->GetSize();
|
||||
|
||||
gfx::IntRect renderBounds(0, 0, rtSize.width, rtSize.height);
|
||||
renderBounds.IntersectRect(renderBounds, aClipRect);
|
||||
renderBounds.MoveBy(rtOffset);
|
||||
|
||||
// Apply the layer transform.
|
||||
gfx::RectDouble dest = aTransform.TransformAndClipBounds(
|
||||
gfx::RectDouble(aRect.x, aRect.y, aRect.width, aRect.height),
|
||||
gfx::RectDouble(renderBounds.x, renderBounds.y, renderBounds.width, renderBounds.height));
|
||||
dest -= rtOffset;
|
||||
|
||||
// Ensure we don't round out to -1, which trips up Direct3D.
|
||||
dest.IntersectRect(dest, gfx::RectDouble(0, 0, rtSize.width, rtSize.height));
|
||||
|
||||
if (aOutLayerQuad) {
|
||||
*aOutLayerQuad = gfx::Rect(dest.x, dest.y, dest.width, dest.height);
|
||||
}
|
||||
|
||||
// Round out to integer.
|
||||
gfx::IntRect result;
|
||||
dest.RoundOut();
|
||||
dest.ToIntRect(&result);
|
||||
|
||||
// Create a transform from adjusted clip space to render target space,
|
||||
// translate it for the backdrop rect, then transform it into the backdrop's
|
||||
// uv-space.
|
||||
gfx::Matrix4x4 transform;
|
||||
transform.PostScale(rtSize.width, rtSize.height, 1.0);
|
||||
transform.PostTranslate(-result.x, -result.y, 0.0);
|
||||
transform.PostScale(1 / float(result.width), 1 / float(result.height), 1.0);
|
||||
*aOutTransform = transform;
|
||||
return result;
|
||||
return layers::ComputeBackdropCopyRect(
|
||||
aRect,
|
||||
aClipRect,
|
||||
aTransform,
|
||||
gfx::IntRect(rtOffset, rtSize),
|
||||
aOutTransform,
|
||||
aOutLayerQuad);
|
||||
}
|
||||
|
||||
gfx::IntRect
|
||||
|
59
gfx/layers/LayersHelpers.cpp
Normal file
59
gfx/layers/LayersHelpers.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* -*- 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 "LayersHelpers.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
using namespace gfx;
|
||||
|
||||
gfx::IntRect
|
||||
ComputeBackdropCopyRect(const gfx::Rect& aRect,
|
||||
const gfx::IntRect& aClipRect,
|
||||
const gfx::Matrix4x4& aTransform,
|
||||
const gfx::IntRect& aRenderTargetRect,
|
||||
gfx::Matrix4x4* aOutTransform,
|
||||
gfx::Rect* aOutLayerQuad)
|
||||
{
|
||||
// Compute the clip.
|
||||
IntPoint rtOffset = aRenderTargetRect.TopLeft();
|
||||
IntSize rtSize = aRenderTargetRect.Size();
|
||||
|
||||
gfx::IntRect renderBounds(0, 0, rtSize.width, rtSize.height);
|
||||
renderBounds.IntersectRect(renderBounds, aClipRect);
|
||||
renderBounds.MoveBy(rtOffset);
|
||||
|
||||
// Apply the layer transform.
|
||||
RectDouble dest = aTransform.TransformAndClipBounds(
|
||||
RectDouble(aRect.x, aRect.y, aRect.width, aRect.height),
|
||||
RectDouble(renderBounds.x, renderBounds.y, renderBounds.width, renderBounds.height));
|
||||
dest -= rtOffset;
|
||||
|
||||
// Ensure we don't round out to -1, which trips up Direct3D.
|
||||
dest.IntersectRect(dest, RectDouble(0, 0, rtSize.width, rtSize.height));
|
||||
|
||||
if (aOutLayerQuad) {
|
||||
*aOutLayerQuad = Rect(dest.x, dest.y, dest.width, dest.height);
|
||||
}
|
||||
|
||||
// Round out to integer.
|
||||
IntRect result;
|
||||
dest.RoundOut();
|
||||
dest.ToIntRect(&result);
|
||||
|
||||
// Create a transform from adjusted clip space to render target space,
|
||||
// translate it for the backdrop rect, then transform it into the backdrop's
|
||||
// uv-space.
|
||||
Matrix4x4 transform;
|
||||
transform.PostScale(rtSize.width, rtSize.height, 1.0);
|
||||
transform.PostTranslate(-result.x, -result.y, 0.0);
|
||||
transform.PostScale(1 / float(result.width), 1 / float(result.height), 1.0);
|
||||
*aOutTransform = transform;
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
54
gfx/layers/LayersHelpers.h
Normal file
54
gfx/layers/LayersHelpers.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- 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_layers_LayersHelpers_h
|
||||
#define mozilla_gfx_layers_LayersHelpers_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/gfx/Rect.h"
|
||||
#include "mozilla/gfx/Matrix.h"
|
||||
#include "mozilla/gfx/Polygon.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class Layer;
|
||||
|
||||
// Compute compositor information for copying the backdrop for a mix-blend
|
||||
// operation.
|
||||
gfx::IntRect
|
||||
ComputeBackdropCopyRect(const gfx::Rect& aRect,
|
||||
const gfx::IntRect& aClipRect,
|
||||
const gfx::Matrix4x4& aTransform,
|
||||
const gfx::IntRect& aRenderTargetRect,
|
||||
gfx::Matrix4x4* aOutTransform,
|
||||
gfx::Rect* aOutLayerQuad = nullptr);
|
||||
|
||||
// Compute uv-coordinates for a rect inside a texture.
|
||||
template <typename T>
|
||||
static inline gfx::Rect
|
||||
TextureRectToCoords(const T& aRect, const gfx::IntSize& aSize)
|
||||
{
|
||||
return gfx::Rect(
|
||||
float(aRect.x) / aSize.width,
|
||||
float(aRect.y) / aSize.height,
|
||||
float(aRect.width) / aSize.width,
|
||||
float(aRect.height) / aSize.height);
|
||||
}
|
||||
|
||||
// This is defined in Compositor.cpp.
|
||||
nsTArray<gfx::TexturedTriangle>
|
||||
GenerateTexturedTriangles(const gfx::Polygon& aPolygon,
|
||||
const gfx::Rect& aRect,
|
||||
const gfx::Rect& aTexRect);
|
||||
|
||||
// This is defined in ContainerLayerComposite.cpp.
|
||||
void TransformLayerGeometry(Layer* aLayer, Maybe<gfx::Polygon>& aGeometry);
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_gfx_layers_LayersHelpers_h
|
@ -129,7 +129,7 @@ SelectLayerGeometry(const Maybe<gfx::Polygon>& aParentGeometry,
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
TransformLayerGeometry(Layer* aLayer, Maybe<gfx::Polygon>& aGeometry)
|
||||
{
|
||||
Layer* parent = aLayer;
|
||||
|
@ -191,6 +191,7 @@ EXPORTS.mozilla.layers += [
|
||||
'ipc/VideoBridgeParent.h',
|
||||
'LayerAttributes.h',
|
||||
'LayerMetricsWrapper.h',
|
||||
'LayersHelpers.h',
|
||||
'LayersTypes.h',
|
||||
'opengl/CompositingRenderTargetOGL.h',
|
||||
'opengl/CompositorOGL.h',
|
||||
@ -387,6 +388,7 @@ UNIFIED_SOURCES += [
|
||||
'ipc/VideoBridgeChild.cpp',
|
||||
'ipc/VideoBridgeParent.cpp',
|
||||
'LayerScope.cpp',
|
||||
'LayersHelpers.cpp',
|
||||
'LayersLogging.cpp',
|
||||
'LayerSorter.cpp',
|
||||
'LayersTypes.cpp',
|
||||
|
@ -237,7 +237,7 @@ WebRenderBridgeChild::GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont)
|
||||
(aScaledFont->GetType() == gfx::FontType::MAC) ||
|
||||
(aScaledFont->GetType() == gfx::FontType::FONTCONFIG));
|
||||
|
||||
RefPtr<UnscaledFont> unscaled = aScaledFont->GetUnscaledFont();
|
||||
RefPtr<gfx::UnscaledFont> unscaled = aScaledFont->GetUnscaledFont();
|
||||
MOZ_ASSERT(unscaled);
|
||||
|
||||
wr::FontKey key = {0, 0};
|
||||
@ -264,7 +264,7 @@ WebRenderBridgeChild::GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont)
|
||||
void
|
||||
WebRenderBridgeChild::RemoveExpiredFontKeys()
|
||||
{
|
||||
uint32_t counter = UnscaledFont::DeletionCounter();
|
||||
uint32_t counter = gfx::UnscaledFont::DeletionCounter();
|
||||
if (mFontKeysDeleted != counter) {
|
||||
mFontKeysDeleted = counter;
|
||||
for (auto iter = mFontKeys.Iter(); !iter.Done(); iter.Next()) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "LayersLogging.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/layers/ImageClient.h"
|
||||
#include "mozilla/layers/ScrollingLayersHelper.h"
|
||||
#include "mozilla/layers/StackingContextHelper.h"
|
||||
#include "mozilla/layers/WebRenderBridgeChild.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user