2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
#ifndef GFX_READBACKLAYER_H
|
|
|
|
#define GFX_READBACKLAYER_H
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint64_t
|
|
|
|
#include "Layers.h" // for Layer, etc
|
2015-09-25 05:24:16 +03:00
|
|
|
#include "mozilla/gfx/Rect.h" // for gfxRect
|
|
|
|
#include "mozilla/gfx/Point.h" // for IntPoint
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/mozalloc.h" // for operator delete
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsPoint.h" // for nsIntPoint
|
|
|
|
#include "nscore.h" // for nsACString
|
|
|
|
|
|
|
|
class gfxContext;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class ReadbackProcessor;
|
|
|
|
|
2014-07-28 00:32:00 +04:00
|
|
|
namespace layerscope {
|
|
|
|
class LayersPacket;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layerscope
|
2014-07-28 00:32:00 +04:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
/**
|
|
|
|
* A ReadbackSink receives a stream of updates to a rectangle of pixels.
|
|
|
|
* These update callbacks are always called on the main thread, either during
|
|
|
|
* EndTransaction or from the event loop.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class ReadbackSink {
|
2011-02-17 01:43:30 +03:00
|
|
|
public:
|
2020-03-04 18:39:20 +03:00
|
|
|
ReadbackSink() = default;
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~ReadbackSink() = default;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends an update to indicate that the background is currently unknown.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual void SetUnknown(uint64_t aSequenceNumber) = 0;
|
2011-02-17 01:43:30 +03:00
|
|
|
/**
|
|
|
|
* Called by the layer system to indicate that the contents of part of
|
|
|
|
* the readback area are changing.
|
|
|
|
* @param aRect is the rectangle of content that is being updated,
|
|
|
|
* in the coordinate system of the ReadbackLayer.
|
|
|
|
* @param aSequenceNumber updates issued out of order should be ignored.
|
|
|
|
* Only use updates whose sequence counter is greater than all other updates
|
|
|
|
* seen so far. Return null when a non-fresh sequence value is given.
|
|
|
|
* @return a context into which the update should be drawn. This should be
|
|
|
|
* set up to clip to aRect. Zero should never be passed as a sequence number.
|
|
|
|
* If this returns null, EndUpdate should NOT be called. If it returns
|
|
|
|
* non-null, EndUpdate must be called.
|
|
|
|
*
|
|
|
|
* We don't support partially unknown backgrounds. Therefore, the
|
|
|
|
* first BeginUpdate after a SetUnknown will have the complete background.
|
|
|
|
*/
|
2015-12-18 06:39:10 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> BeginUpdate(
|
2015-04-21 18:04:57 +03:00
|
|
|
const gfx::IntRect& aRect, uint64_t aSequenceNumber) = 0;
|
2011-02-17 01:43:30 +03:00
|
|
|
/**
|
|
|
|
* EndUpdate must be called immediately after BeginUpdate, without returning
|
|
|
|
* to the event loop.
|
|
|
|
* @param aContext the context returned by BeginUpdate
|
|
|
|
* Implicitly Restore()s the state of aContext.
|
|
|
|
*/
|
2015-12-18 06:39:09 +03:00
|
|
|
virtual void EndUpdate(const gfx::IntRect& aRect) = 0;
|
2011-02-17 01:43:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A ReadbackLayer never renders anything. It enables clients to extract
|
|
|
|
* the rendered contents of the layer tree below the ReadbackLayer.
|
|
|
|
* The rendered contents are delivered asynchronously via calls to a
|
|
|
|
* ReadbackSink object supplied by the client.
|
|
|
|
*
|
|
|
|
* This is a "best effort" API; it is possible for the layer system to tell
|
|
|
|
* the ReadbackSink that the contents of the readback area are unknown.
|
|
|
|
*
|
|
|
|
* This API exists to work around the limitations of transparent windowless
|
|
|
|
* plugin rendering APIs. It should not be used for anything else.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class ReadbackLayer : public Layer {
|
2011-02-17 01:43:30 +03:00
|
|
|
public:
|
|
|
|
MOZ_LAYER_DECL_NAME("ReadbackLayer", TYPE_READBACK)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ComputeEffectiveTransforms(
|
|
|
|
const gfx::Matrix4x4& aTransformToSurface) override {
|
2011-02-17 01:43:30 +03:00
|
|
|
// Snap our local transform first, and snap the inherited transform as well.
|
|
|
|
// This makes our snapping equivalent to what would happen if our content
|
2014-09-26 21:06:08 +04:00
|
|
|
// was drawn into a PaintedLayer (gfxContext would snap using the local
|
|
|
|
// transform, then we'd snap again when compositing the PaintedLayer).
|
2014-01-27 19:27:20 +04:00
|
|
|
mEffectiveTransform =
|
2014-01-27 19:28:18 +04:00
|
|
|
SnapTransform(GetLocalTransform(),
|
|
|
|
gfxRect(0, 0, mSize.width, mSize.height), nullptr) *
|
2014-01-27 19:28:04 +04:00
|
|
|
SnapTransformTranslation(aTransformToSurface, nullptr);
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the callback object to which readback updates will be delivered.
|
|
|
|
* This also resets the "needed rectangle" so that on the next layer tree
|
|
|
|
* transaction we will try to deliver the full contents of the readback
|
|
|
|
* area to the sink.
|
|
|
|
* This layer takes ownership of the sink. It will be deleted when the
|
|
|
|
* layer is destroyed or when a new sink is set.
|
|
|
|
* Initially the contents of the readback area are completely unknown.
|
|
|
|
*/
|
|
|
|
void SetSink(ReadbackSink* aSink) {
|
|
|
|
SetUnknown();
|
2020-01-21 04:25:28 +03:00
|
|
|
mSink = mozilla::WrapUnique(aSink);
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
2020-01-21 04:25:28 +03:00
|
|
|
ReadbackSink* GetSink() { return mSink.get(); }
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the size of content that should be read back. The readback area
|
|
|
|
* has its top-left at 0,0 and has size aSize.
|
|
|
|
* Can only be called while the sink is null!
|
|
|
|
*/
|
2015-04-21 18:04:57 +03:00
|
|
|
void SetSize(const gfx::IntSize& aSize) {
|
2011-02-17 01:43:30 +03:00
|
|
|
NS_ASSERTION(!mSink, "Should have no sink while changing size!");
|
|
|
|
mSize = aSize;
|
|
|
|
}
|
2015-04-21 18:04:57 +03:00
|
|
|
const gfx::IntSize& GetSize() { return mSize; }
|
|
|
|
gfx::IntRect GetRect() { return gfx::IntRect(gfx::IntPoint(0, 0), mSize); }
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsBackgroundKnown() {
|
2015-09-25 04:16:45 +03:00
|
|
|
return mBackgroundLayer || mBackgroundColor.a == 1.f;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyRemoved() {
|
|
|
|
SetUnknown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mSink = nullptr;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
2014-09-26 21:06:08 +04:00
|
|
|
void NotifyPaintedLayerRemoved(PaintedLayer* aLayer) {
|
2011-02-17 01:43:30 +03:00
|
|
|
if (mBackgroundLayer == aLayer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mBackgroundLayer = nullptr;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIntPoint& GetBackgroundLayerOffset() {
|
|
|
|
return mBackgroundLayerOffset;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t AllocateSequenceNumber() { return ++mSequenceCounter; }
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
void SetUnknown() {
|
|
|
|
if (IsBackgroundKnown()) {
|
|
|
|
if (mSink) {
|
|
|
|
mSink->SetUnknown(AllocateSequenceNumber());
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mBackgroundLayer = nullptr;
|
2020-03-09 17:16:17 +03:00
|
|
|
mBackgroundColor = gfx::DeviceColor();
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class ReadbackProcessor;
|
|
|
|
|
|
|
|
ReadbackLayer(LayerManager* aManager, void* aImplData)
|
|
|
|
: Layer(aManager, aImplData),
|
|
|
|
mSequenceCounter(0),
|
|
|
|
mSize(0, 0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mBackgroundLayer(nullptr),
|
2011-02-17 01:43:30 +03:00
|
|
|
mBackgroundLayerOffset(0, 0),
|
2020-03-09 17:16:17 +03:00
|
|
|
mBackgroundColor(gfx::DeviceColor()) {}
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PrintInfo(std::stringstream& aStream,
|
|
|
|
const char* aPrefix) override;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DumpPacket(layerscope::LayersPacket* aPacket,
|
|
|
|
const void* aParent) override;
|
2014-07-28 00:32:00 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mSequenceCounter;
|
2020-01-21 04:25:28 +03:00
|
|
|
UniquePtr<ReadbackSink> mSink;
|
2015-04-21 18:04:57 +03:00
|
|
|
gfx::IntSize mSize;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2014-09-26 21:06:08 +04:00
|
|
|
// This can refer to any (earlier) sibling PaintedLayer. That PaintedLayer
|
|
|
|
// must have mUsedForReadback set on it. If the PaintedLayer is removed
|
|
|
|
// for the container, this will be set to null by NotifyPaintedLayerRemoved.
|
|
|
|
// This PaintedLayer contains the contents which have previously been reported
|
|
|
|
// to mSink. The PaintedLayer had only an integer translation transform,
|
2011-02-17 01:43:30 +03:00
|
|
|
// and it covered the entire readback area. This layer also had only an
|
|
|
|
// integer translation transform.
|
2014-09-26 21:06:08 +04:00
|
|
|
PaintedLayer* mBackgroundLayer;
|
2011-02-17 01:43:30 +03:00
|
|
|
// When mBackgroundLayer is non-null, this is the offset to add to
|
|
|
|
// convert from the coordinates of mBackgroundLayer to the coordinates
|
|
|
|
// of this layer.
|
|
|
|
nsIntPoint mBackgroundLayerOffset;
|
|
|
|
// When mBackgroundColor is opaque, this is the color of the ColorLayer
|
|
|
|
// that contained the contents we reported to mSink, which covered the
|
|
|
|
// entire readback area.
|
2020-03-09 17:16:17 +03:00
|
|
|
gfx::DeviceColor mBackgroundColor;
|
2011-02-17 01:43:30 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
#endif /* GFX_READBACKLAYER_H */
|