Issue #1053 - Part 3a: Remove Android conditionals from /gfx

This commit is contained in:
Moonchild 2020-12-27 06:58:56 +00:00 committed by roytam1
commit 753251e54c
43 changed files with 32 additions and 1708 deletions

View file

@ -38,10 +38,6 @@
#include "nsTArrayForwardDeclare.h" // for InfallibleTArray
#include "UnitTransforms.h" // for TransformTo
#include "gfxPrefs.h"
#if defined(MOZ_WIDGET_ANDROID)
# include <android/log.h>
# include "mozilla/widget/AndroidCompositorWidget.h"
#endif
#include "GeckoProfiler.h"
#include "FrameUniformityData.h"
#include "TreeTraversal.h" // for ForEachNode, BreadthFirstSearch
@ -825,11 +821,7 @@ ExpandRootClipRect(Layer* aLayer, const ScreenMargin& aFixedLayerMargins)
// clear the clip rect on aLayer entirely but this seems more precise.
Maybe<ParentLayerIntRect> rootClipRect = aLayer->AsLayerComposite()->GetShadowClipRect();
if (rootClipRect && aFixedLayerMargins != ScreenMargin()) {
#ifndef MOZ_WIDGET_ANDROID
// We should never enter here on anything other than Fennec, since
// aFixedLayerMargins should be empty everywhere else.
MOZ_ASSERT(false);
#endif
MOZ_ASSERT(false, "aFixedLayerMargins should be empty!");
ParentLayerRect rect(rootClipRect.value());
rect.Deflate(ViewAs<ParentLayerPixel>(aFixedLayerMargins,
PixelCastJustification::ScreenIsParentLayerForRoot));
@ -837,40 +829,6 @@ ExpandRootClipRect(Layer* aLayer, const ScreenMargin& aFixedLayerMargins)
}
}
#ifdef MOZ_WIDGET_ANDROID
static void
MoveScrollbarForLayerMargin(Layer* aRoot, FrameMetrics::ViewID aRootScrollId,
const ScreenMargin& aFixedLayerMargins)
{
// See bug 1223928 comment 9 - once we can detect the RCD with just the
// isRootContent flag on the metrics, we can probably move this code into
// ApplyAsyncTransformToScrollbar rather than having it as a separate
// adjustment on the layer tree.
Layer* scrollbar = BreadthFirstSearch<ReverseIterator>(aRoot,
[aRootScrollId](Layer* aNode) {
return (aNode->GetScrollbarDirection() == Layer::HORIZONTAL &&
aNode->GetScrollbarTargetContainerId() == aRootScrollId);
});
if (scrollbar) {
// Shift the horizontal scrollbar down into the new space exposed by the
// dynamic toolbar hiding. Technically we should also scale the vertical
// scrollbar a bit to expand into the new space but it's not as noticeable
// and it would add a lot more complexity, so we're going with the "it's not
// worth it" justification.
TranslateShadowLayer(scrollbar, ParentLayerPoint(0, -aFixedLayerMargins.bottom), true, nullptr);
if (scrollbar->GetParent()) {
// The layer that has the HORIZONTAL direction sits inside another
// ContainerLayer. This ContainerLayer also has a clip rect that causes
// the scrollbar to get clipped. We need to expand that clip rect to
// prevent that from happening. This is kind of ugly in that we're
// assuming a particular layer tree structure but short of adding more
// flags to the layer there doesn't appear to be a good way to do this.
ExpandRootClipRect(scrollbar->GetParent(), aFixedLayerMargins);
}
}
}
#endif
bool
AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer,
bool* aOutFoundRoot)
@ -974,50 +932,9 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer,
const ScrollMetadata& scrollMetadata = layer->GetScrollMetadata(i);
const FrameMetrics& metrics = scrollMetadata.GetMetrics();
#if defined(MOZ_WIDGET_ANDROID)
// If we find a metrics which is the root content doc, use that. If not, use
// the root layer. Since this function recurses on children first we should
// only end up using the root layer if the entire tree was devoid of a
// root content metrics. This is a temporary solution; in the long term we
// should not need the root content metrics at all. See bug 1201529 comment
// 6 for details.
if (!(*aOutFoundRoot)) {
*aOutFoundRoot = metrics.IsRootContent() || /* RCD */
(layer->GetParent() == nullptr && /* rootmost metrics */
i + 1 >= layer->GetScrollMetadataCount());
if (*aOutFoundRoot) {
mRootScrollableId = metrics.GetScrollId();
CSSToLayerScale geckoZoom = metrics.LayersPixelsPerCSSPixel().ToScaleFactor();
if (mIsFirstPaint) {
LayerIntPoint scrollOffsetLayerPixels = RoundedToInt(metrics.GetScrollOffset() * geckoZoom);
mContentRect = metrics.GetScrollableRect();
SetFirstPaintViewport(scrollOffsetLayerPixels,
geckoZoom,
mContentRect);
} else {
ParentLayerPoint scrollOffset = controller->GetCurrentAsyncScrollOffset(
AsyncPanZoomController::RESPECT_FORCE_DISABLE);
// Compute the painted displayport in document-relative CSS pixels.
CSSRect displayPort(metrics.GetCriticalDisplayPort().IsEmpty() ?
metrics.GetDisplayPort() :
metrics.GetCriticalDisplayPort());
displayPort += metrics.GetScrollOffset();
SyncFrameMetrics(scrollOffset,
geckoZoom * asyncTransformWithoutOverscroll.mScale,
metrics.GetScrollableRect(), displayPort, geckoZoom, mLayersUpdated,
mPaintSyncId, fixedLayerMargins);
mFixedLayerMargins = fixedLayerMargins;
mLayersUpdated = false;
mPaintSyncId = 0;
}
mIsFirstPaint = false;
}
}
#else
// Non-Android platforms still care about this flag being cleared after
// We still care about this flag being cleared after
// the first call to TransformShadowTree().
mIsFirstPaint = false;
#endif
// Transform the current local clips by this APZC's async transform. If we're
// using containerful scrolling, then the clip is not part of the scrolled
@ -1420,12 +1337,8 @@ AsyncCompositionManager::TransformShadowTree(TimeStamp aCurrentFrame,
// in Gecko and partially in Java.
bool foundRoot = false;
if (ApplyAsyncContentTransformToTree(root, &foundRoot)) {
#if defined(MOZ_WIDGET_ANDROID)
MOZ_ASSERT(foundRoot);
if (foundRoot && mFixedLayerMargins != ScreenMargin()) {
MoveScrollbarForLayerMargin(root, mRootScrollableId, mFixedLayerMargins);
}
#endif
// Fixed margin considerations should go here, but we never encounter
// those outside of mobile.
}
// Advance APZ animations to the next expected vsync timestamp, if we can
@ -1458,14 +1371,7 @@ AsyncCompositionManager::SetFirstPaintViewport(const LayerIntPoint& aOffset,
const CSSToLayerScale& aZoom,
const CSSRect& aCssPageRect)
{
#ifdef MOZ_WIDGET_ANDROID
widget::AndroidCompositorWidget* widget =
mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
if (!widget) {
return;
}
widget->SetFirstPaintViewport(aOffset, aZoom, aCssPageRect);
#endif
// ** STUB **
}
void
@ -1478,16 +1384,7 @@ AsyncCompositionManager::SyncFrameMetrics(const ParentLayerPoint& aScrollOffset,
int32_t aPaintSyncId,
ScreenMargin& aFixedLayerMargins)
{
#ifdef MOZ_WIDGET_ANDROID
widget::AndroidCompositorWidget* widget =
mLayerManager->GetCompositor()->GetWidget()->AsAndroid();
if (!widget) {
return;
}
widget->SyncFrameMetrics(
aScrollOffset, aZoom, aCssPageRect, aDisplayPort, aPaintedResolution,
aLayersUpdated, aPaintSyncId, aFixedLayerMargins);
#endif
// ** STUB **
}
} // namespace layers

View file

@ -238,14 +238,6 @@ private:
LayerTransformRecorder mLayerTransformRecorder;
TimeStamp mPreviousFrameTimeStamp;
#ifdef MOZ_WIDGET_ANDROID
// The following two fields are only needed on Fennec with C++ APZ, because
// then we need to reposition the gecko scrollbar to deal with the
// dynamic toolbar shifting content around.
FrameMetrics::ViewID mRootScrollableId;
ScreenMargin mFixedLayerMargins;
#endif
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(AsyncCompositionManager::TransformsToSkip)

View file

@ -133,18 +133,7 @@ CanvasLayerComposite::CleanupResources()
gfx::SamplingFilter
CanvasLayerComposite::GetSamplingFilter()
{
gfx::SamplingFilter filter = mSamplingFilter;
#ifdef ANDROID
// Bug 691354
// Using the LINEAR filter we get unexplained artifacts.
// Use NEAREST when no scaling is required.
Matrix matrix;
bool is2D = GetEffectiveTransform().Is2D(&matrix);
if (is2D && !ThebesMatrix(matrix).HasNonTranslationOrFlip()) {
filter = SamplingFilter::POINT;
}
#endif
return filter;
return mSamplingFilter;
}
void

View file

@ -54,16 +54,6 @@
#include "nsPoint.h" // for nsIntPoint
#include "nsRect.h" // for mozilla::gfx::IntRect
#include "nsRegion.h" // for nsIntRegion, etc
#ifdef MOZ_WIDGET_ANDROID
#include <android/log.h>
#include <android/native_window.h>
#endif
#if defined(MOZ_WIDGET_ANDROID)
#include "opengl/CompositorOGL.h"
#include "GLContextEGL.h"
#include "GLContextProvider.h"
#include "ScopedGLHelpers.h"
#endif
#include "GeckoProfiler.h"
#include "TextRenderer.h" // for TextRenderer
#include "mozilla/layers/CompositorBridgeParent.h"
@ -490,9 +480,6 @@ LayerManagerComposite::UpdateAndRender()
}
Render(invalid, opaque);
#if defined(MOZ_WIDGET_ANDROID)
RenderToPresentationSurface();
#endif
mGeometryChanged = false;
mWindowOverlayChanged = false;
@ -618,42 +605,6 @@ LayerManagerComposite::RenderDebugOverlay(const IntRect& aBounds)
}
float alpha = 1;
#ifdef ANDROID
// Draw a translation delay warning overlay
int width;
int border;
if (!mWarnTime.IsNull() && (now - mWarnTime).ToMilliseconds() < kVisualWarningDuration) {
EffectChain effects;
// Black blorder
border = 4;
width = 6;
effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(0, 0, 0, 1));
mCompositor->DrawQuad(gfx::Rect(border, border, aBounds.width - 2 * border, width),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(border, aBounds.height - border - width, aBounds.width - 2 * border, width),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(border, border + width, width, aBounds.height - 2 * border - width * 2),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(aBounds.width - border - width, border + width, width, aBounds.height - 2 * border - 2 * width),
aBounds, effects, alpha, gfx::Matrix4x4());
// Content
border = 5;
width = 4;
effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(1, 1.f - mWarningLevel, 0, 1));
mCompositor->DrawQuad(gfx::Rect(border, border, aBounds.width - 2 * border, width),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(border, aBounds.height - border - width, aBounds.width - 2 * border, width),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(border, border + width, width, aBounds.height - 2 * border - width * 2),
aBounds, effects, alpha, gfx::Matrix4x4());
mCompositor->DrawQuad(gfx::Rect(aBounds.width - border - width, border + width, width, aBounds.height - 2 * border - 2 * width),
aBounds, effects, alpha, gfx::Matrix4x4());
SetDebugOverlayWantsNextFrame(true);
}
#endif
float fillRatio = mCompositor->GetFillRatio();
mFPS->DrawFPS(now, drawFrameColorBars ? 10 : 1, 2, unsigned(fillRatio), mCompositor);
@ -932,8 +883,6 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
mozilla::widget::WidgetRenderingContext widgetContext;
#if defined(XP_MACOSX)
widgetContext.mLayerManager = this;
#elif defined(MOZ_WIDGET_ANDROID)
widgetContext.mCompositor = GetCompositor();
#endif
{
@ -952,14 +901,6 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
CompositorBench(mCompositor, bounds);
MOZ_ASSERT(mRoot->GetOpacity() == 1);
#if defined(MOZ_WIDGET_ANDROID)
LayerMetricsWrapper wrapper = GetRootContentLayer();
if (wrapper) {
mCompositor->SetClearColor(wrapper.Metadata().GetBackgroundColor());
} else {
mCompositor->SetClearColorToDefault();
}
#endif
if (mRoot->GetClipRect()) {
clipRect = *mRoot->GetClipRect();
IntRect rect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
@ -1029,182 +970,6 @@ LayerManagerComposite::Render(const nsIntRegion& aInvalidRegion, const nsIntRegi
RecordFrame();
}
#if defined(MOZ_WIDGET_ANDROID)
class ScopedCompositorProjMatrix {
public:
ScopedCompositorProjMatrix(CompositorOGL* aCompositor, const Matrix4x4& aProjMatrix):
mCompositor(aCompositor),
mOriginalProjMatrix(mCompositor->GetProjMatrix())
{
mCompositor->SetProjMatrix(aProjMatrix);
}
~ScopedCompositorProjMatrix()
{
mCompositor->SetProjMatrix(mOriginalProjMatrix);
}
private:
CompositorOGL* const mCompositor;
const Matrix4x4 mOriginalProjMatrix;
};
class ScopedCompostitorSurfaceSize {
public:
ScopedCompostitorSurfaceSize(CompositorOGL* aCompositor, const gfx::IntSize& aSize) :
mCompositor(aCompositor),
mOriginalSize(mCompositor->GetDestinationSurfaceSize())
{
mCompositor->SetDestinationSurfaceSize(aSize);
}
~ScopedCompostitorSurfaceSize()
{
mCompositor->SetDestinationSurfaceSize(mOriginalSize);
}
private:
CompositorOGL* const mCompositor;
const gfx::IntSize mOriginalSize;
};
class ScopedCompositorRenderOffset {
public:
ScopedCompositorRenderOffset(CompositorOGL* aCompositor, const ScreenPoint& aOffset) :
mCompositor(aCompositor),
mOriginalOffset(mCompositor->GetScreenRenderOffset())
{
mCompositor->SetScreenRenderOffset(aOffset);
}
~ScopedCompositorRenderOffset()
{
mCompositor->SetScreenRenderOffset(mOriginalOffset);
}
private:
CompositorOGL* const mCompositor;
const ScreenPoint mOriginalOffset;
};
class ScopedContextSurfaceOverride {
public:
ScopedContextSurfaceOverride(GLContextEGL* aContext, void* aSurface) :
mContext(aContext)
{
MOZ_ASSERT(aSurface);
mContext->SetEGLSurfaceOverride(aSurface);
mContext->MakeCurrent(true);
}
~ScopedContextSurfaceOverride()
{
mContext->SetEGLSurfaceOverride(EGL_NO_SURFACE);
mContext->MakeCurrent(true);
}
private:
GLContextEGL* const mContext;
};
void
LayerManagerComposite::RenderToPresentationSurface()
{
#ifdef MOZ_WIDGET_ANDROID
nsIWidget* const widget = mCompositor->GetWidget()->RealWidget();
auto window = static_cast<ANativeWindow*>(
widget->GetNativeData(NS_PRESENTATION_WINDOW));
if (!window) {
return;
}
EGLSurface surface = widget->GetNativeData(NS_PRESENTATION_SURFACE);
if (!surface) {
//create surface;
surface = GLContextProviderEGL::CreateEGLSurface(window);
if (!surface) {
return;
}
widget->SetNativeData(NS_PRESENTATION_SURFACE,
reinterpret_cast<uintptr_t>(surface));
}
CompositorOGL* compositor = mCompositor->AsCompositorOGL();
GLContext* gl = compositor->gl();
GLContextEGL* egl = GLContextEGL::Cast(gl);
if (!egl) {
return;
}
const IntSize windowSize(ANativeWindow_getWidth(window),
ANativeWindow_getHeight(window));
#endif
if ((windowSize.width <= 0) || (windowSize.height <= 0)) {
return;
}
ScreenRotation rotation = compositor->GetScreenRotation();
const int actualWidth = windowSize.width;
const int actualHeight = windowSize.height;
const gfx::IntSize originalSize = compositor->GetDestinationSurfaceSize();
const nsIntRect originalRect = nsIntRect(0, 0, originalSize.width, originalSize.height);
int pageWidth = originalSize.width;
int pageHeight = originalSize.height;
if (rotation == ROTATION_90 || rotation == ROTATION_270) {
pageWidth = originalSize.height;
pageHeight = originalSize.width;
}
float scale = 1.0;
if ((pageWidth > actualWidth) || (pageHeight > actualHeight)) {
const float scaleWidth = (float)actualWidth / (float)pageWidth;
const float scaleHeight = (float)actualHeight / (float)pageHeight;
scale = scaleWidth <= scaleHeight ? scaleWidth : scaleHeight;
}
const gfx::IntSize actualSize(actualWidth, actualHeight);
ScopedCompostitorSurfaceSize overrideSurfaceSize(compositor, actualSize);
const ScreenPoint offset((actualWidth - (int)(scale * pageWidth)) / 2, 0);
ScopedContextSurfaceOverride overrideSurface(egl, surface);
Matrix viewMatrix = ComputeTransformForRotation(originalRect,
rotation);
viewMatrix.Invert(); // unrotate
viewMatrix.PostScale(scale, scale);
viewMatrix.PostTranslate(offset.x, offset.y);
Matrix4x4 matrix = Matrix4x4::From2D(viewMatrix);
mRoot->ComputeEffectiveTransforms(matrix);
nsIntRegion opaque;
LayerIntRegion visible;
PostProcessLayers(mRoot, opaque, visible, Nothing());
nsIntRegion invalid;
IntRect bounds = IntRect::Truncate(0, 0, scale * pageWidth, actualHeight);
IntRect rect, actualBounds;
MOZ_ASSERT(mRoot->GetOpacity() == 1);
mCompositor->BeginFrame(invalid, nullptr, bounds, nsIntRegion(), &rect, &actualBounds);
// The Java side of Fennec sets a scissor rect that accounts for
// chrome such as the URL bar. Override that so that the entire frame buffer
// is cleared.
ScopedScissorRect scissorRect(egl, 0, 0, actualWidth, actualHeight);
egl->fClearColor(0.0, 0.0, 0.0, 0.0);
egl->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
const IntRect clipRect = IntRect::Truncate(0, 0, actualWidth, actualHeight);
RootLayer()->Prepare(RenderTargetIntRect::FromUnknownRect(clipRect));
RootLayer()->RenderLayer(clipRect);
mCompositor->EndFrame();
}
#endif
already_AddRefed<PaintedLayerComposite>
LayerManagerComposite::CreatePaintedLayerComposite()
{

View file

@ -327,9 +327,6 @@ private:
* Render the current layer tree to the active target.
*/
void Render(const nsIntRegion& aInvalidRegion, const nsIntRegion& aOpaqueRegion);
#if defined(MOZ_WIDGET_ANDROID)
void RenderToPresentationSurface();
#endif
/**
* We need to know our invalid region before we're ready to render.