mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
Bug 1337130 - Create a DisplayItemLayer type. r=mattwoodrow
This commit is contained in:
parent
53923cec18
commit
ef3d9a921c
@ -737,6 +737,7 @@ CloneLayerTreePropertiesInternal(Layer* aRoot, bool aIsMask /* = false */)
|
||||
return MakeUnique<BorderLayerProperties>(static_cast<BorderLayer*>(aRoot));
|
||||
case Layer::TYPE_TEXT:
|
||||
return MakeUnique<TextLayerProperties>(static_cast<TextLayer*>(aRoot));
|
||||
case Layer::TYPE_DISPLAYITEM:
|
||||
case Layer::TYPE_READBACK:
|
||||
case Layer::TYPE_SHADOW:
|
||||
case Layer::TYPE_PAINTED:
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "mozilla/layers/ShadowLayers.h" // for ShadowableLayer
|
||||
#include "nsAString.h"
|
||||
#include "nsCSSValue.h" // for nsCSSValue::Array, etc
|
||||
#include "nsDisplayList.h" // for nsDisplayItem
|
||||
#include "nsPrintfCString.h" // for nsPrintfCString
|
||||
#include "nsStyleStruct.h" // for nsTimingFunction, etc
|
||||
#include "protobuf/LayerScopePacket.pb.h"
|
||||
@ -2121,6 +2122,34 @@ ContainerLayer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParen
|
||||
layer->set_type(LayersPacket::Layer::ContainerLayer);
|
||||
}
|
||||
|
||||
void
|
||||
DisplayItemLayer::EndTransaction() {
|
||||
mItem = nullptr;
|
||||
mBuilder = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
DisplayItemLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
{
|
||||
Layer::PrintInfo(aStream, aPrefix);
|
||||
const char* type = "TYPE_UNKNOWN";
|
||||
if (mItem) {
|
||||
type = mItem->Name();
|
||||
}
|
||||
|
||||
aStream << " [itype type=" << type << "]";
|
||||
}
|
||||
|
||||
void
|
||||
DisplayItemLayer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
|
||||
{
|
||||
Layer::DumpPacket(aPacket, aParent);
|
||||
// Get this layer data
|
||||
using namespace layerscope;
|
||||
LayersPacket::Layer* layer = aPacket->mutable_layer(aPacket->layer_size()-1);
|
||||
layer->set_type(LayersPacket::Layer::DisplayItemLayer);
|
||||
}
|
||||
|
||||
void
|
||||
ColorLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@
|
||||
#include "ImageContainer.h"
|
||||
|
||||
class gfxContext;
|
||||
class nsDisplayListBuilder;
|
||||
class nsDisplayItem;
|
||||
|
||||
extern uint8_t gLayerManagerLayerBuilder;
|
||||
|
||||
@ -83,6 +85,7 @@ class LayerMetricsWrapper;
|
||||
class PaintedLayer;
|
||||
class ContainerLayer;
|
||||
class ImageLayer;
|
||||
class DisplayItemLayer;
|
||||
class ColorLayer;
|
||||
class CompositorBridgeChild;
|
||||
class TextLayer;
|
||||
@ -439,8 +442,11 @@ public:
|
||||
* Create a RefLayer for this manager's layer tree.
|
||||
*/
|
||||
virtual already_AddRefed<RefLayer> CreateRefLayer() { return nullptr; }
|
||||
|
||||
|
||||
/**
|
||||
* CONSTRUCTION PHASE ONLY
|
||||
* Create a DisplayItemLayer for this manager's layer tree.
|
||||
*/
|
||||
virtual already_AddRefed<DisplayItemLayer> CreateDisplayItemLayer() { return nullptr; }
|
||||
/**
|
||||
* Can be called anytime, from any thread.
|
||||
*
|
||||
@ -780,6 +786,7 @@ public:
|
||||
TYPE_CANVAS,
|
||||
TYPE_COLOR,
|
||||
TYPE_CONTAINER,
|
||||
TYPE_DISPLAYITEM,
|
||||
TYPE_IMAGE,
|
||||
TYPE_TEXT,
|
||||
TYPE_BORDER,
|
||||
@ -1569,6 +1576,12 @@ public:
|
||||
*/
|
||||
virtual ShadowableLayer* AsShadowableLayer() { return nullptr; }
|
||||
|
||||
/**
|
||||
* Dynamic cast as a DisplayItemLayer. Return null if not a
|
||||
* DisplayItemLayer. Can be used anytime.
|
||||
*/
|
||||
virtual DisplayItemLayer* AsDisplayItemLayer() { return nullptr; }
|
||||
|
||||
// These getters can be used anytime. They return the effective
|
||||
// values that should be used when drawing this layer to screen,
|
||||
// accounting for this layer possibly being a shadow.
|
||||
@ -2305,6 +2318,61 @@ protected:
|
||||
EventRegionsOverride mEventRegionsOverride;
|
||||
};
|
||||
|
||||
/**
|
||||
* A generic layer that references back to its display item.
|
||||
*
|
||||
* In order to not throw away information early in the pipeline from layout -> webrender,
|
||||
* we'd like a generic layer type that can represent all the nsDisplayItems instead of
|
||||
* creating a new layer type for each nsDisplayItem for Webrender. Another option
|
||||
* is to break down nsDisplayItems into smaller nsDisplayItems early in the pipeline.
|
||||
* The problem with this is that the whole pipeline would have to deal with more
|
||||
* display items, which is slower.
|
||||
*
|
||||
* An alternative is to create a DisplayItemLayer, but the wrinkle with this is that
|
||||
* it has a pointer to its nsDisplayItem. Managing the lifetime is key as display items
|
||||
* only live as long as their display list builder, which goes away at the end of a paint.
|
||||
* Layers however, are retained between paints.
|
||||
* It's ok to recycle a DisplayItemLayer for a different display item since its just a pointer.
|
||||
* Instead, when a layer transaction is completed, it is up to the layer manager to tell
|
||||
* DisplayItemLayers that the display item pointer is no longer valid.
|
||||
*/
|
||||
class DisplayItemLayer : public Layer {
|
||||
public:
|
||||
virtual DisplayItemLayer* AsDisplayItemLayer() override { return this; }
|
||||
void EndTransaction();
|
||||
|
||||
MOZ_LAYER_DECL_NAME("DisplayItemLayer", TYPE_DISPLAYITEM)
|
||||
|
||||
void SetDisplayItem(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder) {
|
||||
mItem = aItem;
|
||||
mBuilder = aBuilder;
|
||||
}
|
||||
|
||||
nsDisplayItem* GetDisplayItem() { return mItem; }
|
||||
nsDisplayListBuilder* GetDisplayListBuilder() { return mBuilder; }
|
||||
|
||||
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
|
||||
{
|
||||
gfx::Matrix4x4 idealTransform = GetLocalTransform() * aTransformToSurface;
|
||||
mEffectiveTransform = SnapTransformTranslation(idealTransform, nullptr);
|
||||
ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
|
||||
}
|
||||
|
||||
protected:
|
||||
DisplayItemLayer(LayerManager* aManager, void* aImplData)
|
||||
: Layer(aManager, aImplData)
|
||||
, mItem(nullptr)
|
||||
{}
|
||||
|
||||
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
|
||||
|
||||
virtual void DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent) override;
|
||||
|
||||
// READ COMMENT ABOVE TO ENSURE WE DON'T HAVE A DANGLING POINTER
|
||||
nsDisplayItem* mItem;
|
||||
nsDisplayListBuilder* mBuilder;
|
||||
};
|
||||
|
||||
/**
|
||||
* A Layer which just renders a solid color in its visible region. It actually
|
||||
* can fill any area that contains the visible region, so if you need to
|
||||
|
84
gfx/layers/basic/BasicDisplayItemLayer.cpp
Normal file
84
gfx/layers/basic/BasicDisplayItemLayer.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 "BasicLayersImpl.h" // for FillRectWithMask, etc
|
||||
#include "Layers.h" // for Layer, etc
|
||||
#include "BasicImplData.h" // for BasicImplData
|
||||
#include "BasicLayers.h" // for BasicLayerManager
|
||||
#include "gfxContext.h" // for gfxContext, etc
|
||||
#include "gfxRect.h" // for gfxRect
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/mozalloc.h" // for operator new
|
||||
#include "nsCOMPtr.h" // for already_AddRefed
|
||||
#include "nsDebug.h" // for NS_ASSERTION
|
||||
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
|
||||
#include "nsRect.h" // for mozilla::gfx::IntRect
|
||||
#include "nsRegion.h" // for nsIntRegion
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "nsDisplayList.h" // for nsDisplayItem
|
||||
#include "nsCaret.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class BasicDisplayItemLayer : public DisplayItemLayer, public BasicImplData {
|
||||
public:
|
||||
explicit BasicDisplayItemLayer(BasicLayerManager* aLayerManager) :
|
||||
DisplayItemLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
||||
{
|
||||
MOZ_COUNT_CTOR(BasicDisplayItemLayer);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~BasicDisplayItemLayer()
|
||||
{
|
||||
MOZ_COUNT_DTOR(BasicDisplayItemLayer);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
|
||||
{
|
||||
NS_ASSERTION(BasicManager()->InConstruction(),
|
||||
"Can only set properties in construction phase");
|
||||
DisplayItemLayer::SetVisibleRegion(aRegion);
|
||||
}
|
||||
|
||||
virtual void Paint(DrawTarget* aDT,
|
||||
const gfx::Point& aDeviceOffset,
|
||||
Layer* aMaskLayer) override
|
||||
{
|
||||
if (IsHidden() || !mItem || !mBuilder) {
|
||||
return;
|
||||
}
|
||||
|
||||
AutoRestoreTransform autoRestoreTransform(aDT);
|
||||
Matrix transform = aDT->GetTransform();
|
||||
RefPtr<gfxContext> context = gfxContext::CreateOrNull(aDT, aDeviceOffset);
|
||||
context->SetMatrix(ThebesMatrix(transform));
|
||||
|
||||
nsRenderingContext ctx(context);
|
||||
mItem->Paint(mBuilder, &ctx);
|
||||
}
|
||||
|
||||
protected:
|
||||
BasicLayerManager* BasicManager()
|
||||
{
|
||||
return static_cast<BasicLayerManager*>(mManager);
|
||||
}
|
||||
};
|
||||
|
||||
already_AddRefed<DisplayItemLayer>
|
||||
BasicLayerManager::CreateDisplayItemLayer()
|
||||
{
|
||||
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
||||
RefPtr<DisplayItemLayer> layer = new BasicDisplayItemLayer(this);
|
||||
mDisplayItemLayers.AppendElement(layer);
|
||||
return layer.forget();
|
||||
}
|
||||
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
@ -546,6 +546,18 @@ BasicLayerManager::EndTransaction(DrawPaintedLayerCallback aCallback,
|
||||
mInTransaction = false;
|
||||
|
||||
EndTransactionInternal(aCallback, aCallbackData, aFlags);
|
||||
|
||||
ClearDisplayItemLayers();
|
||||
}
|
||||
|
||||
void
|
||||
BasicLayerManager::ClearDisplayItemLayers()
|
||||
{
|
||||
for (uint32_t i = 0; i < mDisplayItemLayers.Length(); i++) {
|
||||
mDisplayItemLayers[i]->EndTransaction();
|
||||
}
|
||||
|
||||
mDisplayItemLayers.Clear();
|
||||
}
|
||||
|
||||
void
|
||||
@ -734,7 +746,7 @@ BasicLayerManager::PaintSelfOrChildren(PaintLayerContext& aPaintContext,
|
||||
}
|
||||
|
||||
PaintLayer(aGroupTarget, layer, aPaintContext.mCallback,
|
||||
aPaintContext.mCallbackData);
|
||||
aPaintContext.mCallbackData);
|
||||
if (mTransactionIncomplete)
|
||||
break;
|
||||
}
|
||||
@ -816,7 +828,8 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget,
|
||||
PROFILER_LABEL("BasicLayerManager", "PaintLayer",
|
||||
js::ProfileEntry::Category::GRAPHICS);
|
||||
|
||||
PaintLayerContext paintLayerContext(aTarget, aLayer, aCallback, aCallbackData);
|
||||
PaintLayerContext paintLayerContext(aTarget, aLayer,
|
||||
aCallback, aCallbackData);
|
||||
|
||||
// Don't attempt to paint layers with a singular transform, cairo will
|
||||
// just throw an error.
|
||||
|
@ -24,6 +24,7 @@ class nsIWidget;
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class DisplayItemLayer;
|
||||
class ImageFactory;
|
||||
class ImageLayer;
|
||||
class PaintLayerContext;
|
||||
@ -117,6 +118,7 @@ public:
|
||||
virtual already_AddRefed<TextLayer> CreateTextLayer() override;
|
||||
virtual already_AddRefed<BorderLayer> CreateBorderLayer() override;
|
||||
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
|
||||
virtual already_AddRefed<DisplayItemLayer> CreateDisplayItemLayer() override;
|
||||
virtual ImageFactory *GetImageFactory();
|
||||
|
||||
virtual LayersBackend GetBackendType() override { return LayersBackend::LAYERS_BASIC; }
|
||||
@ -211,6 +213,14 @@ protected:
|
||||
bool mUsingDefaultTarget;
|
||||
bool mTransactionIncomplete;
|
||||
bool mCompositorMightResample;
|
||||
|
||||
private:
|
||||
// Display items are only valid during this transaction.
|
||||
// At the end of the transaction, we have to go and clear out
|
||||
// DisplayItemLayer's and null their display item. See comment
|
||||
// above DisplayItemLayer declaration.
|
||||
void ClearDisplayItemLayers();
|
||||
nsTArray<RefPtr<DisplayItemLayer>> mDisplayItemLayers;
|
||||
};
|
||||
|
||||
} // namespace layers
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "mozilla/layers/TransactionIdAllocator.h"
|
||||
#include "nsIWidget.h" // For plugin window configuration information structs
|
||||
|
||||
class nsDisplayListBuilder;
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "mozilla/gfx/gfxVars.h" // for gfxVars
|
||||
#include "VRManager.h" // for VRManager
|
||||
#include "mozilla/ipc/Transport.h" // for Transport
|
||||
#include "mozilla/gfx/gfxVars.h"
|
||||
#include "mozilla/layers/APZCTreeManager.h" // for APZCTreeManager
|
||||
#include "mozilla/layers/APZCTreeManagerParent.h" // for APZCTreeManagerParent
|
||||
#include "mozilla/layers/APZThreadUtils.h" // for APZCTreeManager
|
||||
|
@ -293,6 +293,7 @@ UNIFIED_SOURCES += [
|
||||
'basic/BasicColorLayer.cpp',
|
||||
'basic/BasicCompositor.cpp',
|
||||
'basic/BasicContainerLayer.cpp',
|
||||
'basic/BasicDisplayItemLayer.cpp',
|
||||
'basic/BasicImages.cpp',
|
||||
'basic/BasicLayerManager.cpp',
|
||||
'basic/BasicLayersImpl.cpp',
|
||||
|
@ -74,7 +74,8 @@ enum LayersPacket_Layer_LayerType {
|
||||
LayersPacket_Layer_LayerType_ColorLayer = 6,
|
||||
LayersPacket_Layer_LayerType_TextLayer = 7,
|
||||
LayersPacket_Layer_LayerType_RefLayer = 8,
|
||||
LayersPacket_Layer_LayerType_ReadbackLayer = 9
|
||||
LayersPacket_Layer_LayerType_ReadbackLayer = 9,
|
||||
LayersPacket_Layer_LayerType_DisplayItemLayer = 10
|
||||
};
|
||||
bool LayersPacket_Layer_LayerType_IsValid(int value);
|
||||
const LayersPacket_Layer_LayerType LayersPacket_Layer_LayerType_LayerType_MIN = LayersPacket_Layer_LayerType_UnknownLayer;
|
||||
@ -1674,6 +1675,7 @@ class LayersPacket_Layer : public ::google::protobuf::MessageLite {
|
||||
static const LayerType CanvasLayer = LayersPacket_Layer_LayerType_CanvasLayer;
|
||||
static const LayerType ImageLayer = LayersPacket_Layer_LayerType_ImageLayer;
|
||||
static const LayerType ColorLayer = LayersPacket_Layer_LayerType_ColorLayer;
|
||||
static const LayerType DisplayItemLayer = LayersPacket_Layer_LayerType_DisplayItemLayer;
|
||||
static const LayerType TextLayer = LayersPacket_Layer_LayerType_TextLayer;
|
||||
static const LayerType RefLayer = LayersPacket_Layer_LayerType_RefLayer;
|
||||
static const LayerType ReadbackLayer = LayersPacket_Layer_LayerType_ReadbackLayer;
|
||||
|
@ -4,8 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "WebRenderImageHost.h"
|
||||
|
||||
#include "LayersLogging.h" // for AppendToString
|
||||
#include "WebRenderLayersLogging.h" // for AppendToString
|
||||
|
||||
#include "mozilla/layers/Compositor.h" // for Compositor
|
||||
#include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc
|
||||
|
@ -3,9 +3,8 @@
|
||||
* 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 "WebRenderImageLayer.h"
|
||||
|
||||
#include "WebRenderLayersLogging.h"
|
||||
#include "WebRenderImageLayer.h"
|
||||
#include "mozilla/layers/ImageClient.h"
|
||||
#include "mozilla/layers/TextureClientRecycleAllocator.h"
|
||||
#include "mozilla/layers/TextureWrapperImage.h"
|
||||
|
@ -455,6 +455,7 @@ private:
|
||||
DECL_GFX_PREF(Live, "layers.advanced.border-layers", LayersAllowBorderLayers, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.advanced.text-layers", LayersAllowTextLayers, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.advanced.bullet-layers", LayersAllowBulletLayers, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.advanced.caret-layers", LayersAllowCaretLayers, bool, false);
|
||||
DECL_GFX_PREF(Once, "layers.allow-d3d9-fallback", LayersAllowD3D9Fallback, bool, false);
|
||||
DECL_GFX_PREF(Once, "layers.amd-switchable-gfx.enabled", LayersAMDSwitchableGfxEnabled, bool, false);
|
||||
DECL_GFX_PREF(Once, "layers.async-pan-zoom.enabled", AsyncPanZoomEnabledDoNotUseDirectly, bool, true);
|
||||
|
@ -537,13 +537,20 @@ nsCaret::GetPaintGeometry(nsRect* aRect)
|
||||
return frame;
|
||||
}
|
||||
|
||||
nsIFrame*
|
||||
nsCaret::GetFrame(int32_t* aContentOffset) {
|
||||
return GetFrameAndOffset(GetSelectionInternal(),
|
||||
mOverrideContent,
|
||||
mOverrideOffset,
|
||||
aContentOffset);
|
||||
}
|
||||
|
||||
void nsCaret::PaintCaret(DrawTarget& aDrawTarget,
|
||||
nsIFrame* aForFrame,
|
||||
const nsPoint &aOffset)
|
||||
{
|
||||
int32_t contentOffset;
|
||||
nsIFrame* frame = GetFrameAndOffset(GetSelectionInternal(),
|
||||
mOverrideContent, mOverrideOffset, &contentOffset);
|
||||
nsIFrame* frame = GetFrame(&contentOffset);
|
||||
if (!frame) {
|
||||
return;
|
||||
}
|
||||
|
@ -179,6 +179,10 @@ class nsCaret final : public nsISelectionListener
|
||||
|
||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
nsIFrame* GetFrame(int32_t* aContentOffset);
|
||||
void ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
|
||||
nsRect* aCaretRect, nsRect* aHookRect);
|
||||
|
||||
protected:
|
||||
static void CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
@ -196,9 +200,6 @@ protected:
|
||||
static Metrics ComputeMetrics(nsIFrame* aFrame, int32_t aOffset,
|
||||
nscoord aCaretHeight);
|
||||
|
||||
void ComputeCaretRects(nsIFrame* aFrame, int32_t aFrameOffset,
|
||||
nsRect* aCaretRect, nsRect* aHookRect);
|
||||
|
||||
// Returns true if we should not draw the caret because of XUL menu popups.
|
||||
// The caret should be hidden if:
|
||||
// 1. An open popup contains the caret, but a menu popup exists before the
|
||||
|
@ -81,6 +81,8 @@
|
||||
#include "nsCSSProps.h"
|
||||
#include "nsPluginFrame.h"
|
||||
#include "nsSVGMaskFrame.h"
|
||||
#include "mozilla/layers/WebrenderLayerManager.h"
|
||||
#include "mozilla/layers/WebrenderMessages.h"
|
||||
|
||||
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
||||
// GetTickCount().
|
||||
@ -2728,6 +2730,27 @@ nsDisplayItem::GetClippedBounds(nsDisplayListBuilder* aBuilder)
|
||||
return GetClip().ApplyNonRoundedIntersection(r);
|
||||
}
|
||||
|
||||
already_AddRefed<Layer>
|
||||
nsDisplayItem::BuildDisplayItemLayer(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aContainerParameters)
|
||||
{
|
||||
RefPtr<DisplayItemLayer> layer = static_cast<DisplayItemLayer*>
|
||||
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, this));
|
||||
if (!layer) {
|
||||
layer = aManager->CreateDisplayItemLayer();
|
||||
|
||||
if (!layer) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
layer->SetDisplayItem(this, aBuilder);
|
||||
layer->SetBaseTransform(gfx::Matrix4x4::Translation(aContainerParameters.mOffset.x,
|
||||
aContainerParameters.mOffset.y, 0));
|
||||
return layer.forget();
|
||||
}
|
||||
|
||||
nsRect
|
||||
nsDisplaySolidColor::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
||||
{
|
||||
@ -4321,6 +4344,69 @@ nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
||||
mCaret->PaintCaret(*aCtx->GetDrawTarget(), mFrame, ToReferenceFrame());
|
||||
}
|
||||
|
||||
void
|
||||
nsDisplayCaret::CreateWebRenderCommands(nsTArray<WebRenderCommand>& aCommands,
|
||||
WebRenderLayer* aLayer) {
|
||||
using namespace mozilla::layers;
|
||||
int32_t contentOffset;
|
||||
nsIFrame* frame = mCaret->GetFrame(&contentOffset);
|
||||
if (!frame) {
|
||||
return;
|
||||
}
|
||||
NS_ASSERTION(frame == mFrame, "We're referring different frame");
|
||||
|
||||
int32_t appUnitsPerDevPixel = frame->PresContext()->AppUnitsPerDevPixel();
|
||||
|
||||
nsRect caretRect;
|
||||
nsRect hookRect;
|
||||
mCaret->ComputeCaretRects(frame, contentOffset, &caretRect, &hookRect);
|
||||
|
||||
gfx::Color color = ToDeviceColor(frame->GetCaretColorAt(contentOffset));
|
||||
Rect devCaretRect =
|
||||
NSRectToRect(caretRect + ToReferenceFrame(), appUnitsPerDevPixel);
|
||||
Rect devHookRect =
|
||||
NSRectToRect(hookRect + ToReferenceFrame(), appUnitsPerDevPixel);
|
||||
|
||||
Rect caretTransformedRect = aLayer->RelativeToParent(devCaretRect);
|
||||
Rect hookTransformedRect = aLayer->RelativeToParent(devHookRect);
|
||||
|
||||
IntRect caret = RoundedToInt(caretTransformedRect);
|
||||
IntRect hook = RoundedToInt(hookTransformedRect);
|
||||
|
||||
// Note, WR will pixel snap anything that is layout aligned.
|
||||
aCommands.AppendElement(OpDPPushRect(
|
||||
wr::ToWrRect(caret),
|
||||
wr::ToWrRect(caret),
|
||||
wr::ToWrColor(color)));
|
||||
|
||||
if (!devHookRect.IsEmpty()) {
|
||||
aCommands.AppendElement(OpDPPushRect(
|
||||
wr::ToWrRect(hook),
|
||||
wr::ToWrRect(hook),
|
||||
wr::ToWrColor(color)));
|
||||
}
|
||||
}
|
||||
|
||||
LayerState
|
||||
nsDisplayCaret::GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aParameters)
|
||||
{
|
||||
if (gfxPrefs::LayersAllowCaretLayers()) {
|
||||
return LAYER_ACTIVE;
|
||||
}
|
||||
|
||||
return LAYER_INACTIVE;
|
||||
}
|
||||
|
||||
already_AddRefed<Layer>
|
||||
nsDisplayCaret::BuildLayer(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aContainerParameters)
|
||||
{
|
||||
return BuildDisplayItemLayer(aBuilder, aManager, aContainerParameters);
|
||||
}
|
||||
|
||||
nsDisplayBorder::nsDisplayBorder(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
||||
: nsDisplayItem(aBuilder, aFrame)
|
||||
{
|
||||
|
@ -57,6 +57,8 @@ namespace layers {
|
||||
class Layer;
|
||||
class ImageLayer;
|
||||
class ImageContainer;
|
||||
class WebRenderCommand;
|
||||
class WebRenderLayer;
|
||||
} // namespace layers
|
||||
} // namespace mozilla
|
||||
|
||||
@ -1584,7 +1586,10 @@ public:
|
||||
typedef mozilla::layers::FrameMetrics::ViewID ViewID;
|
||||
typedef mozilla::layers::Layer Layer;
|
||||
typedef mozilla::layers::LayerManager LayerManager;
|
||||
typedef mozilla::layers::WebRenderCommand WebRenderCommand;
|
||||
typedef mozilla::layers::WebRenderLayer WebRenderLayer;
|
||||
typedef mozilla::LayerState LayerState;
|
||||
typedef class mozilla::gfx::DrawTarget DrawTarget;
|
||||
|
||||
// This is never instantiated directly (it has pure virtual methods), so no
|
||||
// need to count constructors and destructors.
|
||||
@ -1917,6 +1922,21 @@ public:
|
||||
const ContainerLayerParameters& aContainerParameters)
|
||||
{ return nullptr; }
|
||||
|
||||
/**
|
||||
* Create the WebRenderCommands required to paint this display item.
|
||||
* The layer this item is in is passed in as rects must be relative
|
||||
* to their parent.
|
||||
*/
|
||||
virtual void CreateWebRenderCommands(nsTArray<WebRenderCommand>& aCommands,
|
||||
WebRenderLayer* aLayer) {}
|
||||
/**
|
||||
* Builds a DisplayItemLayer and sets the display item to this.
|
||||
*/
|
||||
already_AddRefed<Layer>
|
||||
BuildDisplayItemLayer(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aContainerParameters);
|
||||
|
||||
/**
|
||||
* On entry, aVisibleRegion contains the region (relative to ReferenceFrame())
|
||||
* which may be visible. If the display item opaquely covers an area, it
|
||||
@ -2617,8 +2637,6 @@ public:
|
||||
*/
|
||||
class nsDisplayGeneric : public nsDisplayItem {
|
||||
public:
|
||||
typedef class mozilla::gfx::DrawTarget DrawTarget;
|
||||
|
||||
typedef void (* PaintCallback)(nsIFrame* aFrame, DrawTarget* aDrawTarget,
|
||||
const nsRect& aDirtyRect, nsPoint aFramePt);
|
||||
|
||||
@ -2799,6 +2817,15 @@ public:
|
||||
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;
|
||||
NS_DISPLAY_DECL_NAME("Caret", TYPE_CARET)
|
||||
|
||||
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aParameters) override;
|
||||
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
||||
LayerManager* aManager,
|
||||
const ContainerLayerParameters& aContainerParameters) override;
|
||||
virtual void CreateWebRenderCommands(nsTArray<WebRenderCommand>& aCommands,
|
||||
WebRenderLayer* aLayer) override;
|
||||
|
||||
protected:
|
||||
RefPtr<nsCaret> mCaret;
|
||||
nsRect mBounds;
|
||||
@ -4194,7 +4221,6 @@ protected:
|
||||
class nsDisplayMask : public nsDisplaySVGEffects {
|
||||
public:
|
||||
typedef mozilla::layers::ImageLayer ImageLayer;
|
||||
typedef class mozilla::gfx::DrawTarget DrawTarget;
|
||||
|
||||
nsDisplayMask(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
||||
nsDisplayList* aList, bool aHandleOpacity,
|
||||
|
Loading…
Reference in New Issue
Block a user