Revert "Revert "SF: Add support for screen captures""
This reverts commit 2156613b58e6a792e3ab504ed0b7a0b189ff041b.
Test: Manual and cts -m ViewTestCases
Change-Id: Ia1de956a2f41ecd3e019c8540a60d42c37bc343e
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index e128df7..37f4b0f 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -160,6 +160,8 @@
bool useIdentityTransform) const {
ATRACE_CALL();
+ CompositionInfo& compositionInfo = getBE().compositionInfo;
+
if (CC_UNLIKELY(mActiveBuffer == 0)) {
// the texture has not been created yet, this Layer has
// in fact never been drawn into. This happens frequently with
@@ -241,6 +243,7 @@
mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
mTexture.setFiltering(useFiltering);
mTexture.setMatrix(textureMatrix);
+ compositionInfo.re.texture = mTexture;
engine.setupLayerTexturing(mTexture);
} else {
@@ -250,6 +253,23 @@
engine.disableTexturing();
}
+void BufferLayer::drawNow(const RenderArea& renderArea, bool useIdentityTransform) const {
+ CompositionInfo& compositionInfo = getBE().compositionInfo;
+ auto& engine(mFlinger->getRenderEngine());
+
+ draw(renderArea, useIdentityTransform);
+
+ engine.setupLayerTexturing(compositionInfo.re.texture);
+ engine.setupLayerBlending(compositionInfo.re.preMultipliedAlpha, compositionInfo.re.opaque,
+ false, compositionInfo.re.color);
+ engine.setSourceDataSpace(compositionInfo.hwc.dataspace);
+ engine.setSourceY410BT2020(compositionInfo.re.Y410BT2020);
+ engine.drawMesh(getBE().getMesh());
+ engine.disableBlending();
+ engine.disableTexturing();
+ engine.setSourceY410BT2020(false);
+}
+
void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
mConsumer->setReleaseFence(releaseFence);
}
diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h
index 7f5ff3f..0886f17 100644
--- a/services/surfaceflinger/BufferLayer.h
+++ b/services/surfaceflinger/BufferLayer.h
@@ -101,6 +101,7 @@
*/
void onDraw(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform) const override;
+ void drawNow(const RenderArea& renderArea, bool useIdentityTransform) const;
void onLayerDisplayed(const sp<Fence>& releaseFence) override;
diff --git a/services/surfaceflinger/ColorLayer.cpp b/services/surfaceflinger/ColorLayer.cpp
index aebe4ea..8515fcf 100644
--- a/services/surfaceflinger/ColorLayer.cpp
+++ b/services/surfaceflinger/ColorLayer.cpp
@@ -46,16 +46,27 @@
bool useIdentityTransform) const {
half4 color = getColor();
if (color.a > 0) {
- Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2);
- computeGeometry(renderArea, mesh, useIdentityTransform);
- auto& engine(mFlinger->getRenderEngine());
- engine.setupLayerBlending(getPremultipledAlpha(), false /* opaque */,
- true /* disableTexture */, color);
- engine.drawMesh(mesh);
- engine.disableBlending();
+ computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
+ getBE().compositionInfo.re.preMultipliedAlpha = getPremultipledAlpha();
+ getBE().compositionInfo.re.opaque = false;
+ getBE().compositionInfo.re.disableTexture = true;
+ getBE().compositionInfo.re.color = color;
}
}
+void ColorLayer::drawNow(const RenderArea& renderArea, bool useIdentityTransform) const {
+ CompositionInfo& compositionInfo = getBE().compositionInfo;
+ auto& engine(mFlinger->getRenderEngine());
+
+ draw(renderArea, useIdentityTransform);
+
+ engine.setupLayerBlending(compositionInfo.re.preMultipliedAlpha, compositionInfo.re.opaque,
+ compositionInfo.re.disableTexture, compositionInfo.re.color);
+ engine.setSourceDataSpace(compositionInfo.hwc.dataspace);
+ engine.drawMesh(getBE().getMesh());
+ engine.disableBlending();
+}
+
bool ColorLayer::isVisible() const {
const Layer::State& s(getDrawingState());
return !isHiddenByPolicy() && s.color.a;
diff --git a/services/surfaceflinger/ColorLayer.h b/services/surfaceflinger/ColorLayer.h
index 3408045..8417135 100644
--- a/services/surfaceflinger/ColorLayer.h
+++ b/services/surfaceflinger/ColorLayer.h
@@ -32,6 +32,7 @@
virtual const char* getTypeId() const { return "ColorLayer"; }
virtual void onDraw(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform) const;
+ void drawNow(const RenderArea& , bool ) const;
bool isVisible() const override;
void setPerFrameData(const sp<const DisplayDevice>& display) override;
diff --git a/services/surfaceflinger/ContainerLayer.cpp b/services/surfaceflinger/ContainerLayer.cpp
index f259d93..320c0df 100644
--- a/services/surfaceflinger/ContainerLayer.cpp
+++ b/services/surfaceflinger/ContainerLayer.cpp
@@ -30,6 +30,8 @@
void ContainerLayer::onDraw(const RenderArea&, const Region& /* clip */, bool) const {}
+void ContainerLayer::drawNow(const RenderArea&, bool) const {}
+
bool ContainerLayer::isVisible() const {
return !isHiddenByPolicy();
}
diff --git a/services/surfaceflinger/ContainerLayer.h b/services/surfaceflinger/ContainerLayer.h
index 06cfbcd..29a5c3a 100644
--- a/services/surfaceflinger/ContainerLayer.h
+++ b/services/surfaceflinger/ContainerLayer.h
@@ -32,6 +32,7 @@
const char* getTypeId() const override { return "ContainerLayer"; }
void onDraw(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform) const override;
+ void drawNow(const RenderArea& renderArea, bool useIdentityTransform) const override;
bool isVisible() const override;
void setPerFrameData(const sp<const DisplayDevice>& display) override;
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 03720a9..f724096 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -374,6 +374,16 @@
void draw(const RenderArea& renderArea) const;
/*
+ * drawNow uses the renderEngine to draw the layer. This is different than the
+ * draw function as with the FE/BE split, the draw function runs in the FE and
+ * sets up state for the BE to do the actual drawing. drawNow is used to tell
+ * the layer to skip the state setup and just go ahead and draw the layer. This
+ * is used for screen captures which happens separately from the frame
+ * compositing path.
+ */
+ virtual void drawNow(const RenderArea& renderArea, bool useIdentityTransform) const = 0;
+
+ /*
* doTransaction - process the transaction. This is a good place to figure
* out which attributes of the surface have changed.
*/
diff --git a/services/surfaceflinger/LayerBE.cpp b/services/surfaceflinger/LayerBE.cpp
index bef051f..51b615b 100644
--- a/services/surfaceflinger/LayerBE.cpp
+++ b/services/surfaceflinger/LayerBE.cpp
@@ -57,7 +57,8 @@
ALOGV("[%s]\tblackoutLayer=%d", tag, re.blackoutLayer);
ALOGV("[%s]\tclearArea=%d", tag, re.clearArea);
ALOGV("[%s]\tpreMultipliedAlpha=%d", tag, re.preMultipliedAlpha);
- ALOGV("[%s]\topaque=%d\n", tag, re.opaque);
+ ALOGV("[%s]\topaque=%d", tag, re.opaque);
+ ALOGV("[%s]\tdisableTexture=%d", tag, re.disableTexture);
ALOGV("[%s]\ttexture:name(%d), target(%d), size(%d/%d)", tag, re.texture.getTextureName(), re.texture.getTextureTarget(), (unsigned int)re.texture.getWidth(), (unsigned int)re.texture.getHeight());
ALOGV("[%s]\tuseIdentityTransform=%d\n", tag, re.useIdentityTransform);
}
diff --git a/services/surfaceflinger/LayerBE.h b/services/surfaceflinger/LayerBE.h
index f610677..9aa43f7 100644
--- a/services/surfaceflinger/LayerBE.h
+++ b/services/surfaceflinger/LayerBE.h
@@ -52,7 +52,7 @@
Region visibleRegion;
Region surfaceDamage;
sp<NativeHandle> sidebandStream;
- android_dataspace dataspace;
+ ui::Dataspace dataspace;
hwc_color_t color;
} hwc;
struct {
@@ -61,9 +61,11 @@
bool clearArea = false;
bool preMultipliedAlpha = false;
bool opaque = false;
+ bool disableTexture = false;
half4 color;
Texture texture;
bool useIdentityTransform = false;
+ bool Y410BT2020 = false;
} re;
void dump(const char* tag) const;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 9167399..085dcc2 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5120,7 +5120,7 @@
traverseLayers([&](Layer* layer) {
if (filtering) layer->setFiltering(true);
- layer->draw(renderArea, useIdentityTransform);
+ layer->drawNow(renderArea, useIdentityTransform);
if (filtering) layer->setFiltering(false);
});
}