Skip to content

Commit

Permalink
Bug 1319626 - Part 2: Add BorderLayer class and basic support for the…
Browse files Browse the repository at this point in the history
…m. r=mstange
  • Loading branch information
mattwoodrow committed Nov 24, 2016
1 parent 809ae4c commit daac80e
Show file tree
Hide file tree
Showing 19 changed files with 400 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "mozilla/layers/LayersTypes.h"
#include "nsRect.h"
#include "nsRegion.h"
#include "mozilla/Array.h"

#include <stdint.h>

Expand Down Expand Up @@ -1284,6 +1285,26 @@ struct ParamTraits<mozilla::gfx::Glyph>
}
};

template<typename T, size_t Length>
struct ParamTraits<mozilla::Array<T, Length>>
{
typedef mozilla::Array<T, Length> paramType;
static void Write(Message* aMsg, const paramType& aParam) {
for (size_t i = 0; i < Length; i++) {
WriteParam(aMsg, aParam[i]);
}
}

static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
for (size_t i = 0; i < Length; i++) {
if (!ReadParam(aMsg, aIter, &aResult[i])) {
return false;
}
}
return true;
}
};

} /* namespace IPC */

#endif /* __GFXMESSAGEUTILS_H__ */
1 change: 1 addition & 0 deletions gfx/layers/LayerTreeInvalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ CloneLayerTreePropertiesInternal(Layer* aRoot, bool aIsMask /* = false */)
case Layer::TYPE_SHADOW:
case Layer::TYPE_PAINTED:
case Layer::TYPE_TEXT:
case Layer::TYPE_BORDER:
return MakeUnique<LayerPropertiesBase>(aRoot);
}

Expand Down
12 changes: 12 additions & 0 deletions gfx/layers/Layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,18 @@ TextLayer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
layer->set_type(LayersPacket::Layer::TextLayer);
}

void
BorderLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
Layer::PrintInfo(aStream, aPrefix);
}

void
BorderLayer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
{
Layer::DumpPacket(aPacket, aParent);
}

CanvasLayer::CanvasLayer(LayerManager* aManager, void* aImplData)
: Layer(aManager, aImplData)
, mPreTransCallback(nullptr)
Expand Down
81 changes: 81 additions & 0 deletions gfx/layers/Layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gfxRect.h" // for gfxRect
#include "gfx2DGlue.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2, etc
#include "mozilla/Array.h"
#include "mozilla/DebugOnly.h" // for DebugOnly
#include "mozilla/EventForwards.h" // for nsPaintEvent
#include "mozilla/Maybe.h" // for Maybe
Expand Down Expand Up @@ -87,6 +88,7 @@ class ImageLayer;
class ColorLayer;
class TextLayer;
class CanvasLayer;
class BorderLayer;
class ReadbackLayer;
class ReadbackProcessor;
class RefLayer;
Expand Down Expand Up @@ -407,6 +409,11 @@ class LayerManager {
* Create a TextLayer for this manager's layer tree.
*/
virtual already_AddRefed<TextLayer> CreateTextLayer() = 0;
/**
* CONSTRUCTION PHASE ONLY
* Create a BorderLayer for this manager's layer tree.
*/
virtual already_AddRefed<BorderLayer> CreateBorderLayer() { return nullptr; }
/**
* CONSTRUCTION PHASE ONLY
* Create a CanvasLayer for this manager's layer tree.
Expand Down Expand Up @@ -752,6 +759,7 @@ class Layer {
TYPE_CONTAINER,
TYPE_IMAGE,
TYPE_TEXT,
TYPE_BORDER,
TYPE_READBACK,
TYPE_REF,
TYPE_SHADOW,
Expand Down Expand Up @@ -1536,6 +1544,12 @@ class Layer {
*/
virtual TextLayer* AsTextLayer() { return nullptr; }

/**
* Dynamic cast to a Border. Returns null if this is not a
* ColorLayer.
*/
virtual BorderLayer* AsBorderLayer() { return nullptr; }

/**
* Dynamic cast to a LayerComposite. Return null if this is not a
* LayerComposite. Can be used anytime.
Expand Down Expand Up @@ -2391,6 +2405,73 @@ class TextLayer : public Layer {
RefPtr<gfx::ScaledFont> mFont;
};

/**
* A Layer which renders a rounded rect.
*/
class BorderLayer : public Layer {
public:
virtual BorderLayer* AsBorderLayer() override { return this; }

/**
* CONSTRUCTION PHASE ONLY
* Set the color of the layer.
*/

// Colors of each side as in css::Side
virtual void SetColors(const BorderColors& aColors)
{
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Colors", this));
PodCopy(&mColors[0], &aColors[0], 4);
Mutated();
}

virtual void SetRect(const LayerRect& aRect)
{
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Rect", this));
mRect = aRect;
Mutated();
}

// Size of each rounded corner as in css::Corner, 0.0 means a
// rectangular corner.
virtual void SetCornerRadii(const BorderCorners& aCorners)
{
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Corners", this));
PodCopy(&mCorners[0], &aCorners[0], 4);
Mutated();
}

virtual void SetWidths(const BorderWidths& aWidths)
{
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) Widths", this));
PodCopy(&mWidths[0], &aWidths[0], 4);
Mutated();
}

MOZ_LAYER_DECL_NAME("BorderLayer", TYPE_BORDER)

virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
{
gfx::Matrix4x4 idealTransform = GetLocalTransform() * aTransformToSurface;
mEffectiveTransform = SnapTransformTranslation(idealTransform, nullptr);
ComputeEffectiveTransformForMaskLayers(aTransformToSurface);
}

protected:
BorderLayer(LayerManager* aManager, void* aImplData)
: Layer(aManager, aImplData)
{}

virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;

virtual void DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent) override;

BorderColors mColors;
LayerRect mRect;
BorderCorners mCorners;
BorderWidths mWidths;
};

/**
* A Layer for HTML Canvas elements. It's backed by either a
* gfxASurface or a GLContext (for WebGL layers), and has some control
Expand Down
4 changes: 4 additions & 0 deletions gfx/layers/LayersTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ typedef gfx::Matrix4x4Typed<LayerPixel, CSSTransformedLayerPixel> CSSTransformMa
typedef gfx::Matrix4x4Typed<ParentLayerPixel, ParentLayerPixel> AsyncTransformComponentMatrix;
typedef gfx::Matrix4x4Typed<CSSTransformedLayerPixel, ParentLayerPixel> AsyncTransformMatrix;

typedef Array<gfx::Color, 4> BorderColors;
typedef Array<LayerSize, 4> BorderCorners;
typedef Array<LayerCoord, 4> BorderWidths;

} // namespace layers
} // namespace mozilla

Expand Down
83 changes: 83 additions & 0 deletions gfx/layers/basic/BasicBorderLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* -*- 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 ColorLayer, 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"

using namespace mozilla::gfx;

namespace mozilla {
namespace layers {

class BasicBorderLayer : public BorderLayer, public BasicImplData {
public:
explicit BasicBorderLayer(BasicLayerManager* aLayerManager) :
BorderLayer(aLayerManager, static_cast<BasicImplData*>(this))
{
MOZ_COUNT_CTOR(BasicBorderLayer);
}

protected:
virtual ~BasicBorderLayer()
{
MOZ_COUNT_DTOR(BasicBorderLayer);
}

public:
virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
{
NS_ASSERTION(BasicManager()->InConstruction(),
"Can only set properties in construction phase");
BorderLayer::SetVisibleRegion(aRegion);
}

virtual void Paint(DrawTarget* aDT,
const gfx::Point& aDeviceOffset,
Layer* aMaskLayer) override
{
if (IsHidden()) {
return;
}

// We currently assume that we never have rounded corners,
// and that all borders have the same width and color.

ColorPattern color(mColors[0]);
StrokeOptions strokeOptions(mWidths[0]);

Rect rect = mRect.ToUnknownRect();
rect.Deflate(mWidths[0] / 2.0);
aDT->StrokeRect(rect, color, strokeOptions);
}

protected:
BasicLayerManager* BasicManager()
{
return static_cast<BasicLayerManager*>(mManager);
}
};

already_AddRefed<BorderLayer>
BasicLayerManager::CreateBorderLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
RefPtr<BorderLayer> layer = new BasicBorderLayer(this);
return layer.forget();
}

} // namespace layers
} // namespace mozilla
1 change: 1 addition & 0 deletions gfx/layers/basic/BasicLayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class BasicLayerManager final :
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
virtual already_AddRefed<ColorLayer> CreateColorLayer() override;
virtual already_AddRefed<TextLayer> CreateTextLayer() override;
virtual already_AddRefed<BorderLayer> CreateBorderLayer() override;
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
virtual ImageFactory *GetImageFactory();

Expand Down
79 changes: 79 additions & 0 deletions gfx/layers/client/ClientBorderLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* -*- 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 "ClientLayerManager.h" // for ClientLayerManager, etc
#include "Layers.h" // for ColorLayer, etc
#include "mozilla/layers/LayersMessages.h" // for ColorLayerAttributes, etc
#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 "nsRegion.h" // for nsIntRegion

namespace mozilla {
namespace layers {

using namespace mozilla::gfx;

class ClientBorderLayer : public BorderLayer,
public ClientLayer {
public:
explicit ClientBorderLayer(ClientLayerManager* aLayerManager) :
BorderLayer(aLayerManager, static_cast<ClientLayer*>(this))
{
MOZ_COUNT_CTOR(ClientBorderLayer);
}

protected:
virtual ~ClientBorderLayer()
{
MOZ_COUNT_DTOR(ClientBorderLayer);
}

public:
virtual void SetVisibleRegion(const LayerIntRegion& aRegion)
{
NS_ASSERTION(ClientManager()->InConstruction(),
"Can only set properties in construction phase");
BorderLayer::SetVisibleRegion(aRegion);
}

virtual void RenderLayer()
{
RenderMaskLayers(this);
}

virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
{
aAttrs = BorderLayerAttributes(mRect, mColors, mCorners, mWidths);
}

virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; }

virtual void Disconnect()
{
ClientLayer::Disconnect();
}

protected:
ClientLayerManager* ClientManager()
{
return static_cast<ClientLayerManager*>(mManager);
}
};

already_AddRefed<BorderLayer>
ClientLayerManager::CreateBorderLayer()
{
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
RefPtr<ClientBorderLayer> layer =
new ClientBorderLayer(this);
CREATE_SHADOW(Border);
return layer.forget();
}

} // namespace layers
} // namespace mozilla
1 change: 1 addition & 0 deletions gfx/layers/client/ClientLayerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ClientLayerManager final : public LayerManager
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
virtual already_AddRefed<ColorLayer> CreateColorLayer() override;
virtual already_AddRefed<TextLayer> CreateTextLayer() override;
virtual already_AddRefed<BorderLayer> CreateBorderLayer() override;
virtual already_AddRefed<RefLayer> CreateRefLayer() override;

void UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier);
Expand Down
Loading

0 comments on commit daac80e

Please sign in to comment.