Files
palemoon27/gfx/layers/ReadbackProcessor.cpp
T
roytam1 7d12d066b1 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 766345 - Part 1 - Implement DEAA Antialiasing for transformed layers (v5 Patch). r=vladimir, r=djg (a5b4175d8)
- Bug 766345 - Part 2 - Implement Matrix4x4::TransformAndClipRect (v2 Patch). r=vladimir (fba290751)
- Bug 766345 - Part 3 - Implement correct clipping of DEAA edges for quads that cross the w=0 plane (v3 Patch). r=vlad (1574cd5e8)
- Bug 766345 - Part 4: Adjust reftests (v3 patch). r=vlad (8a78cc3c4)
- Bug 1158120 - Replace nsIntSize by mozilla::gfx::IntSize in gfx/layers. r=nical (39b6ad475)
- Bug 1170189 - Simplify TiledContentHost's render loop. r=BenWa (040aac295)
- Bug 1170189 - Simplify the client-side tiling code. r=BenWa (069820cf1)
- Bug 1170189 - Remove the TiledLayerComposer interface. r=BenWa (843da52ff)
- Bug 1158122 - Remove some of the occurences of nsIntRect in gfx. r=nical (600608f14)
- Bug 1181240 - Part 3: Replace gfx3DMatrix with Matrix4x4 in gfx,r=vlad (e27a99500)
- Bug 1181240 - Part 4: Remove gfx3DMatrix,r=vlad (36138a985)
- Bug 997709 part 1 - nsComboboxDisplayFrame can't be split so its reflow status is always NS_FRAME_COMPLETE. r=heycam (15696aad1)
- Bug 997709 part 2 - Prevent the nsComboboxDisplayFrame from being blockified if the parent context has display:flex/grid. r=heycam (7bedb6d69)
- Bug 1140216. Remove asserts that stuff that we never create is not null, since it clearly is null. r=jwatt (aad9d387b)
- Bug 997709 part 3 - tests. (50f3e3a16)
- Bug 1113206: Make nsComboboxControlFrame and nsListControlFrame use logical coordinates and support vertical writing modes - patch by smontagu with additions by jfkthame. r=jfkthame,smontagu (aaaff31e9)
- Bug 1181890 - Center children of ruby content frame if necessary after the bidi reposition. r=jfkthame (8b3b5fdb2)
- Bug 1123284 - pt 1 - Make nsTextBoxFrame somewhat aware of vertical writing mode, to allow <input type=file> to display properly. r=smontagu (b395ba174)
- Bug 1123284 - pt 2 - Fix Get{Min,Pref}ISize in nsLeafBoxFrame for vertical mode. r=smontagu (4a828e0ab)
- Bug 1079151 - patch 1 - Update constraint calculations in nsHTMLReflowState to work with logical coordinates. r=smontagu (ce11e8f6b)
- Bug 1079151 - patch 2 - Convert nsAbsoluteContainingBlock to use logial coordinates. r=smontagu (ad2b0000c)
- Bug 1079151 - patch 3 - Remove failure annotations from the vertical abs-pos reftests. r=smontagu (d95333230)
- Bug 1079151 - patch 4 - Handle unconstrained inline-size when computing constraints for an orthogonal absolutely-positioned block. r=smontagu (99ffede00)
- Bug 1079151 - Updated test files with corrected comments and references as needed. r=jfkthame (c655a98d0)
- Bug 1175492 - unpref transform-origin percentage handling for SVG elements r=jwatt (cda2fffa7)
- Bug 1175094 - Include borderPadding in the combobox's containerWidth, so that dropdown arrow is positioned correctly in RTL. r=smontagu (e93ccaa34)
- Bug 1177614 - Provide a utility method on nsHTMLReflowState to return the computed size including border-padding, for use as a container for logical coordinate conversions, or zero if unconstrained. r=dholbert (89feb2d8a)
- Bug 1180178: Add writing-mode and logical coordinates to frame dumps, r=jfkthame (786a6d878)
- Bug 1157569 - part 12 - Convert physical values from BCPropertyData to logical when returning from Get[Included]OuterBCBorder. r=roc (2d5790f2a)
- Bug 1157569 - part 13 - More conversion of physical to logical terminology in border-collapse calculations. r=dholbert (a85618bf4)
- Bug 1176523 - Convert Get/SetContinuousBCBorderWidth in nsTableColFrame and nsTableColGroupFrame to logical coordinates. r=dholbert (6198c6eb3)
- Bug 1157569 - part 14 - Finish conversion of border-collapse code in nsTableFrame to logical coordinates. r=dholbert (700bbf09b)
- Bug 1157569 - Reftest for RTL table with border-collapse. r=roc (aa4fc0092)
- Bug 1157569 - Followup to address review nits (renamings, comment updates) from parts 13 and 14. (6cccb95df)
- Bug 903135 - Multi platform MAR verification updater support. r=rstrong (7643732df)
- Bug 991993: Disable NSS for updater on OSX and enable native APIs. r=smichaud,rstrong (1490dead8)
2021-03-05 09:13:17 +08:00

190 lines
6.7 KiB
C++

/* -*- 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 "ReadbackProcessor.h"
#include <sys/types.h> // for int32_t
#include "Layers.h" // for Layer, PaintedLayer, etc
#include "ReadbackLayer.h" // for ReadbackLayer, ReadbackSink
#include "UnitTransforms.h" // for ViewAs
#include "Units.h" // for ParentLayerIntRect
#include "gfxColor.h" // for gfxRGBA
#include "gfxContext.h" // for gfxContext
#include "gfxUtils.h"
#include "gfxRect.h" // for gfxRect
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/BasePoint.h" // for BasePoint
#include "mozilla/gfx/BaseRect.h" // for BaseRect
#include "mozilla/gfx/Point.h" // for Intsize
#include "nsAutoPtr.h" // for nsRefPtr, nsAutoPtr
#include "nsDebug.h" // for NS_ASSERTION
#include "nsISupportsImpl.h" // for gfxContext::Release, etc
#include "nsPoint.h" // for nsIntPoint
#include "nsRegion.h" // for nsIntRegion
using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
void
ReadbackProcessor::BuildUpdates(ContainerLayer* aContainer)
{
NS_ASSERTION(mAllUpdates.IsEmpty(), "Some updates not processed?");
if (!aContainer->mMayHaveReadbackChild)
return;
aContainer->mMayHaveReadbackChild = false;
// go backwards so the updates read from earlier layers are later in the
// array.
for (Layer* l = aContainer->GetLastChild(); l; l = l->GetPrevSibling()) {
if (l->GetType() == Layer::TYPE_READBACK) {
aContainer->mMayHaveReadbackChild = true;
BuildUpdatesForLayer(static_cast<ReadbackLayer*>(l));
}
}
}
static Layer*
FindBackgroundLayer(ReadbackLayer* aLayer, nsIntPoint* aOffset)
{
gfx::Matrix transform;
if (!aLayer->GetTransform().Is2D(&transform) ||
transform.HasNonIntegerTranslation())
return nullptr;
nsIntPoint transformOffset(int32_t(transform._31), int32_t(transform._32));
for (Layer* l = aLayer->GetPrevSibling(); l; l = l->GetPrevSibling()) {
gfx::Matrix backgroundTransform;
if (!l->GetTransform().Is2D(&backgroundTransform) ||
gfx::ThebesMatrix(backgroundTransform).HasNonIntegerTranslation())
return nullptr;
nsIntPoint backgroundOffset(int32_t(backgroundTransform._31), int32_t(backgroundTransform._32));
IntRect rectInBackground(transformOffset - backgroundOffset, aLayer->GetSize());
const nsIntRegion& visibleRegion = l->GetEffectiveVisibleRegion();
if (!visibleRegion.Intersects(rectInBackground))
continue;
// Since l is present in the background, from here on we either choose l
// or nothing.
if (!visibleRegion.Contains(rectInBackground))
return nullptr;
if (l->GetEffectiveOpacity() != 1.0 ||
l->HasMaskLayers() ||
!(l->GetContentFlags() & Layer::CONTENT_OPAQUE))
{
return nullptr;
}
// cliprects are post-transform
const Maybe<ParentLayerIntRect>& clipRect = l->GetEffectiveClipRect();
if (clipRect && !clipRect->Contains(ViewAs<ParentLayerPixel>(IntRect(transformOffset, aLayer->GetSize()))))
return nullptr;
Layer::LayerType type = l->GetType();
if (type != Layer::TYPE_COLOR && type != Layer::TYPE_PAINTED)
return nullptr;
*aOffset = backgroundOffset - transformOffset;
return l;
}
return nullptr;
}
void
ReadbackProcessor::BuildUpdatesForLayer(ReadbackLayer* aLayer)
{
if (!aLayer->mSink)
return;
nsIntPoint offset;
Layer* newBackground = FindBackgroundLayer(aLayer, &offset);
if (!newBackground) {
aLayer->SetUnknown();
return;
}
if (newBackground->GetType() == Layer::TYPE_COLOR) {
ColorLayer* colorLayer = static_cast<ColorLayer*>(newBackground);
if (aLayer->mBackgroundColor != colorLayer->GetColor()) {
aLayer->mBackgroundLayer = nullptr;
aLayer->mBackgroundColor = colorLayer->GetColor();
NS_ASSERTION(aLayer->mBackgroundColor.a == 1.0,
"Color layer said it was opaque!");
nsRefPtr<gfxContext> ctx =
aLayer->mSink->BeginUpdate(aLayer->GetRect(),
aLayer->AllocateSequenceNumber());
if (ctx) {
ColorPattern color(ToDeviceColor(aLayer->mBackgroundColor));
IntSize size = aLayer->GetSize();
ctx->GetDrawTarget()->FillRect(Rect(0, 0, size.width, size.height),
color);
aLayer->mSink->EndUpdate(ctx, aLayer->GetRect());
}
}
} else {
NS_ASSERTION(newBackground->AsPaintedLayer(), "Must be PaintedLayer");
PaintedLayer* paintedLayer = static_cast<PaintedLayer*>(newBackground);
// updateRect is relative to the PaintedLayer
IntRect updateRect = aLayer->GetRect() - offset;
if (paintedLayer != aLayer->mBackgroundLayer ||
offset != aLayer->mBackgroundLayerOffset) {
aLayer->mBackgroundLayer = paintedLayer;
aLayer->mBackgroundLayerOffset = offset;
aLayer->mBackgroundColor = gfxRGBA(0,0,0,0);
paintedLayer->SetUsedForReadback(true);
} else {
nsIntRegion invalid;
invalid.Sub(updateRect, paintedLayer->GetValidRegion());
updateRect = invalid.GetBounds();
}
Update update = { aLayer, updateRect, aLayer->AllocateSequenceNumber() };
mAllUpdates.AppendElement(update);
}
}
void
ReadbackProcessor::GetPaintedLayerUpdates(PaintedLayer* aLayer,
nsTArray<Update>* aUpdates,
nsIntRegion* aUpdateRegion)
{
// All PaintedLayers used for readback are in mAllUpdates (some possibly
// with an empty update rect).
aLayer->SetUsedForReadback(false);
if (aUpdateRegion) {
aUpdateRegion->SetEmpty();
}
for (uint32_t i = mAllUpdates.Length(); i > 0; --i) {
const Update& update = mAllUpdates[i - 1];
if (update.mLayer->mBackgroundLayer == aLayer) {
aLayer->SetUsedForReadback(true);
// Don't bother asking for updates if we have an empty update rect.
if (!update.mUpdateRect.IsEmpty()) {
aUpdates->AppendElement(update);
if (aUpdateRegion) {
aUpdateRegion->Or(*aUpdateRegion, update.mUpdateRect);
}
}
mAllUpdates.RemoveElementAt(i - 1);
}
}
}
ReadbackProcessor::~ReadbackProcessor()
{
for (uint32_t i = mAllUpdates.Length(); i > 0; --i) {
const Update& update = mAllUpdates[i - 1];
// Unprocessed update. Notify the readback sink that this content is
// unknown.
update.mLayer->SetUnknown();
}
}
} // namespace layers
} // namespace mozilla