Merge "Support dumpsys timeouts in milliseconds"
diff --git a/cmds/cmd/cmd.cpp b/cmds/cmd/cmd.cpp
index 40dbbf5..6511b44 100644
--- a/cmds/cmd/cmd.cpp
+++ b/cmds/cmd/cmd.cpp
@@ -72,6 +72,9 @@
aerr << "Open attempt after active for: " << fullPath << endl;
return -EPERM;
}
+#if DEBUG
+ ALOGD("openFile: %s, full=%s", path8.string(), fullPath.string());
+#endif
int flags = 0;
bool checkRead = false;
bool checkWrite = false;
@@ -92,6 +95,9 @@
return -EINVAL;
}
int fd = open(fullPath.string(), flags, S_IRWXU|S_IRWXG);
+#if DEBUG
+ ALOGD("openFile: fd=%d", fd);
+#endif
if (fd < 0) {
return fd;
}
@@ -104,6 +110,9 @@
int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(),
"file", "write", NULL);
if (accessGranted != 0) {
+#if DEBUG
+ ALOGD("openFile: failed selinux write check!");
+#endif
close(fd);
aerr << "System server has no access to write file context " << context.get()
<< " (from path " << fullPath.string() << ", context "
@@ -115,6 +124,9 @@
int accessGranted = selinux_check_access(seLinuxContext8.string(), context.get(),
"file", "read", NULL);
if (accessGranted != 0) {
+#if DEBUG
+ ALOGD("openFile: failed selinux read check!");
+#endif
close(fd);
aerr << "System server has no access to read file context " << context.get()
<< " (from path " << fullPath.string() << ", context "
@@ -164,6 +176,9 @@
proc->setThreadPoolMaxThreadCount(0);
proc->startThreadPool();
+#if DEBUG
+ ALOGD("cmd: starting");
+#endif
sp<IServiceManager> sm = defaultServiceManager();
fflush(stdout);
if (sm == NULL) {
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index 34c52d0..f86f876 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -254,11 +254,15 @@
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
}
-TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
+TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
status_t status;
- const size_t pointerCount = 0;
+ const size_t pointerCount = 1;
PointerProperties pointerProperties[pointerCount];
PointerCoords pointerCoords[pointerCount];
+ for (size_t i = 0; i < pointerCount; i++) {
+ pointerProperties[i].clear();
+ pointerCoords[i].clear();
+ }
status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
pointerCount, pointerProperties, pointerCoords);
@@ -266,7 +270,20 @@
<< "publisher publishMotionEvent should return BAD_VALUE";
}
-TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
+TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
+ status_t status;
+ const size_t pointerCount = 0;
+ PointerProperties pointerProperties[pointerCount];
+ PointerCoords pointerCoords[pointerCount];
+
+ status = mPublisher->publishMotionEvent(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ pointerCount, pointerProperties, pointerCoords);
+ ASSERT_EQ(BAD_VALUE, status)
+ << "publisher publishMotionEvent should return BAD_VALUE";
+}
+
+TEST_F(InputPublisherAndConsumerTest,
+ PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
status_t status;
const size_t pointerCount = MAX_POINTERS + 1;
PointerProperties pointerProperties[pointerCount];
@@ -276,7 +293,7 @@
pointerCoords[i].clear();
}
- status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ status = mPublisher->publishMotionEvent(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
pointerCount, pointerProperties, pointerCoords);
ASSERT_EQ(BAD_VALUE, status)
<< "publisher publishMotionEvent should return BAD_VALUE";
diff --git a/libs/vr/libvrsensor/Android.bp b/libs/vr/libvrsensor/Android.bp
index ec36088..fe54b4b 100644
--- a/libs/vr/libvrsensor/Android.bp
+++ b/libs/vr/libvrsensor/Android.bp
@@ -14,7 +14,6 @@
sourceFiles = [
"pose_client.cpp",
- "sensor_client.cpp",
"latency_model.cpp",
]
diff --git a/libs/vr/libvrsensor/include/private/dvr/sensor-ipc.h b/libs/vr/libvrsensor/include/private/dvr/sensor-ipc.h
deleted file mode 100644
index b2ebd95..0000000
--- a/libs/vr/libvrsensor/include/private/dvr/sensor-ipc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef ANDROID_DVR_SENSOR_IPC_H_
-#define ANDROID_DVR_SENSOR_IPC_H_
-
-#define DVR_SENSOR_SERVICE_BASE "system/vr/sensors"
-
-#define DVR_SENSOR_SERVICE_CLIENT (DVR_SENSOR_SERVICE_BASE "/client")
-
-/*
- * Endpoint ops
- */
-enum {
- DVR_SENSOR_START = 0,
- DVR_SENSOR_STOP,
- DVR_SENSOR_POLL,
-};
-
-#endif // ANDROID_DVR_SENSOR_IPC_H_
diff --git a/libs/vr/libvrsensor/include/private/dvr/sensor_client.h b/libs/vr/libvrsensor/include/private/dvr/sensor_client.h
deleted file mode 100644
index 15a9b8f..0000000
--- a/libs/vr/libvrsensor/include/private/dvr/sensor_client.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef ANDROID_DVR_SENSOR_CLIENT_H_
-#define ANDROID_DVR_SENSOR_CLIENT_H_
-
-#include <hardware/sensors.h>
-#include <pdx/client.h>
-#include <poll.h>
-
-namespace android {
-namespace dvr {
-
-// SensorClient is a remote interface to the sensor service in sensord.
-class SensorClient : public pdx::ClientBase<SensorClient> {
- public:
- ~SensorClient();
-
- int StartSensor();
- int StopSensor();
- int Poll(sensors_event_t* events, int max_count);
-
- private:
- friend BASE;
-
- // Set up a channel associated with the sensor of the indicated type.
- // NOTE(segal): If our hardware ends up with multiple sensors of the same
- // type, we'll have to change this.
- explicit SensorClient(int sensor_type);
-
- int sensor_type_;
-
- SensorClient(const SensorClient&);
- SensorClient& operator=(const SensorClient&);
-};
-
-} // namespace dvr
-} // namespace android
-
-#endif // ANDROID_DVR_SENSOR_CLIENT_H_
diff --git a/libs/vr/libvrsensor/sensor_client.cpp b/libs/vr/libvrsensor/sensor_client.cpp
deleted file mode 100644
index 04e88cc..0000000
--- a/libs/vr/libvrsensor/sensor_client.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#define LOG_TAG "SensorClient"
-#include <private/dvr/sensor_client.h>
-
-#include <log/log.h>
-#include <poll.h>
-
-#include <pdx/default_transport/client_channel_factory.h>
-#include <private/dvr/sensor-ipc.h>
-
-using android::pdx::Transaction;
-
-namespace android {
-namespace dvr {
-
-SensorClient::SensorClient(int sensor_type)
- : BASE(pdx::default_transport::ClientChannelFactory::Create(
- DVR_SENSOR_SERVICE_CLIENT)),
- sensor_type_(sensor_type) {}
-
-SensorClient::~SensorClient() {}
-
-int SensorClient::StartSensor() {
- Transaction trans{*this};
- auto status = trans.Send<int>(DVR_SENSOR_START, &sensor_type_,
- sizeof(sensor_type_), nullptr, 0);
- ALOGE_IF(!status, "startSensor() failed because: %s\n",
- status.GetErrorMessage().c_str());
- return ReturnStatusOrError(status);
-}
-
-int SensorClient::StopSensor() {
- Transaction trans{*this};
- auto status = trans.Send<int>(DVR_SENSOR_STOP);
- ALOGE_IF(!status, "stopSensor() failed because: %s\n",
- status.GetErrorMessage().c_str());
- return ReturnStatusOrError(status);
-}
-
-int SensorClient::Poll(sensors_event_t* events, int max_events) {
- int num_events = 0;
- struct iovec rvec[] = {
- {.iov_base = &num_events, .iov_len = sizeof(int)},
- {.iov_base = events, .iov_len = max_events * sizeof(sensors_event_t)},
- };
- Transaction trans{*this};
- auto status = trans.SendVector<int>(DVR_SENSOR_POLL, nullptr, rvec);
- ALOGE_IF(!status, "Sensor poll() failed because: %s\n",
- status.GetErrorMessage().c_str());
- return !status ? -status.error() : num_events;
-}
-
-} // namespace dvr
-} // namespace android
-
-// Entrypoints to simplify using the library when programmatically dynamicly
-// loading it.
-// Allows us to call this library without linking it, as, for instance,
-// when compiling GVR in Google3.
-// NOTE(segal): It's kind of a hack.
-
-extern "C" uint64_t dvrStartSensor(int type) {
- android::dvr::SensorClient* service =
- android::dvr::SensorClient::Create(type).release();
- service->StartSensor();
- return (uint64_t)service;
-}
-
-extern "C" void dvrStopSensor(uint64_t service) {
- android::dvr::SensorClient* iss =
- reinterpret_cast<android::dvr::SensorClient*>(service);
- iss->StopSensor();
- delete iss;
-}
-
-extern "C" int dvrPollSensor(uint64_t service, int max_count,
- sensors_event_t* events) {
- return reinterpret_cast<android::dvr::SensorClient*>(service)->Poll(
- events, max_count);
-}
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 399affc..9822849 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -340,6 +340,14 @@
result = std::string("/vendor/lib/egl/lib") + kind + "_emulation.so";
#endif
return result;
+ case 2:
+ // Use guest side swiftshader library
+#if defined(__LP64__)
+ result = std::string("/vendor/lib64/egl/lib") + kind + "_swiftshader.so";
+#else
+ result = std::string("/vendor/lib/egl/lib") + kind + "_swiftshader.so";
+#endif
+ return result;
default:
// Not in emulator, or use other guest-side implementation
break;
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 4e214d1..2fa17e9 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -88,7 +88,7 @@
}
mFlinger->deleteTextureAsync(mTextureName);
- if (!mHwcLayers.empty()) {
+ if (!getBE().mHwcLayers.empty()) {
ALOGE("Found stale hardware composer layers when destroying "
"surface flinger layer %s",
mName.string());
@@ -115,7 +115,7 @@
bool BufferLayer::isVisible() const {
return !(isHiddenByPolicy()) && getAlpha() > 0.0f &&
- (mActiveBuffer != NULL || mSidebandStream != NULL);
+ (mActiveBuffer != NULL || getBE().mSidebandStream != NULL);
}
bool BufferLayer::isFixedSize() const {
@@ -249,7 +249,8 @@
}
// Set things up for texturing.
- mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
+ mTexture.setDimensions(mActiveBuffer->getWidth(),
+ mActiveBuffer->getHeight());
mTexture.setFiltering(useFiltering);
mTexture.setMatrix(textureMatrix);
@@ -299,10 +300,12 @@
bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
if (mBufferLatched) {
Mutex::Autolock lock(mFrameEventHistoryMutex);
- mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime);
+ mFrameEventHistory.addPreComposition(mCurrentFrameNumber,
+ refreshStartTime);
}
mRefreshPending = false;
- return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh;
+ return mQueuedFrames > 0 || mSidebandStreamChanged ||
+ mAutoRefresh;
}
bool BufferLayer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence,
const std::shared_ptr<FenceTime>& presentFence,
@@ -314,8 +317,8 @@
// Update mFrameEventHistory.
{
Mutex::Autolock lock(mFrameEventHistoryMutex);
- mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence,
- compositorTiming);
+ mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence,
+ presentFence, compositorTiming);
}
// Update mFrameTracker.
@@ -382,7 +385,9 @@
if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) {
// mSidebandStreamChanged was true
mSidebandStream = mSurfaceFlingerConsumer->getSidebandStream();
- if (mSidebandStream != NULL) {
+ // replicated in LayerBE until FE/BE is ready to be synchronized
+ getBE().mSidebandStream = mSidebandStream;
+ if (getBE().mSidebandStream != NULL) {
setTransactionFlags(eTransactionNeeded);
mFlinger->setTransactionFlags(eTraversalNeeded);
}
@@ -429,11 +434,12 @@
// buffer mode.
bool queuedBuffer = false;
LayerRejecter r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
- getProducerStickyTransform() != 0, mName.string(), mOverrideScalingMode,
- mFreezeGeometryUpdates);
+ getProducerStickyTransform() != 0, mName.string(),
+ mOverrideScalingMode, mFreezeGeometryUpdates);
status_t updateResult =
- mSurfaceFlingerConsumer->updateTexImage(&r, mFlinger->mPrimaryDispSync, &mAutoRefresh,
- &queuedBuffer, mLastFrameNumberReceived);
+ mSurfaceFlingerConsumer->updateTexImage(&r, mFlinger->mPrimaryDispSync,
+ &mAutoRefresh, &queuedBuffer,
+ mLastFrameNumberReceived);
if (updateResult == BufferQueue::PRESENT_LATER) {
// Producer doesn't want buffer to be displayed yet. Signal a
// layer update so we check again at the next opportunity.
@@ -486,12 +492,14 @@
// Decrement the queued-frames count. Signal another event if we
// have more frames pending.
- if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) || mAutoRefresh) {
+ if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) ||
+ mAutoRefresh) {
mFlinger->signalLayerUpdate();
}
// update the active buffer
- mActiveBuffer = mSurfaceFlingerConsumer->getCurrentBuffer(&mActiveBufferSlot);
+ mActiveBuffer =
+ mSurfaceFlingerConsumer->getCurrentBuffer(&mActiveBufferSlot);
if (mActiveBuffer == NULL) {
// this can only happen if the very first buffer was rejected.
return outDirtyRegion;
@@ -519,7 +527,8 @@
Rect crop(mSurfaceFlingerConsumer->getCurrentCrop());
const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform());
const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode());
- if ((crop != mCurrentCrop) || (transform != mCurrentTransform) ||
+ if ((crop != mCurrentCrop) ||
+ (transform != mCurrentTransform) ||
(scalingMode != mCurrentScalingMode)) {
mCurrentCrop = crop;
mCurrentTransform = transform;
@@ -582,7 +591,7 @@
const auto& viewport = displayDevice->getViewport();
Region visible = tr.transform(visibleRegion.intersect(viewport));
auto hwcId = displayDevice->getHwcDisplayId();
- auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcInfo = getBE().mHwcLayers[hwcId];
auto& hwcLayer = hwcInfo.layer;
auto error = hwcLayer->setVisibleRegion(visible);
if (error != HWC2::Error::None) {
@@ -599,13 +608,14 @@
}
// Sideband layers
- if (mSidebandStream.get()) {
+ if (getBE().mSidebandStream.get()) {
setCompositionType(hwcId, HWC2::Composition::Sideband);
ALOGV("[%s] Requesting Sideband composition", mName.string());
- error = hwcLayer->setSidebandStream(mSidebandStream->handle());
+ error = hwcLayer->setSidebandStream(getBE().mSidebandStream->handle());
if (error != HWC2::Error::None) {
ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(),
- mSidebandStream->handle(), to_string(error).c_str(), static_cast<int32_t>(error));
+ getBE().mSidebandStream->handle(), to_string(error).c_str(),
+ static_cast<int32_t>(error));
}
return;
}
@@ -628,20 +638,22 @@
uint32_t hwcSlot = 0;
sp<GraphicBuffer> hwcBuffer;
- hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot, &hwcBuffer);
+ hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot,
+ mActiveBuffer, &hwcSlot, &hwcBuffer);
auto acquireFence = mSurfaceFlingerConsumer->getCurrentFence();
error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
if (error != HWC2::Error::None) {
- ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(), mActiveBuffer->handle,
- to_string(error).c_str(), static_cast<int32_t>(error));
+ ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
+ mActiveBuffer->handle, to_string(error).c_str(),
+ static_cast<int32_t>(error));
}
}
bool BufferLayer::isOpaque(const Layer::State& s) const {
// if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
// layer's opaque flag.
- if ((mSidebandStream == nullptr) && (mActiveBuffer == nullptr)) {
+ if ((getBE().mSidebandStream == nullptr) && (mActiveBuffer == nullptr)) {
return false;
}
@@ -688,7 +700,8 @@
// Ensure that callbacks are handled in order
while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
- status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
+ status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
+ ms2ns(500));
if (result != NO_ERROR) {
ALOGE("[%s] Timed out waiting on callback", mName.string());
}
@@ -711,7 +724,8 @@
// Ensure that callbacks are handled in order
while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
- status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
+ status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
+ ms2ns(500));
if (result != NO_ERROR) {
ALOGE("[%s] Timed out waiting on callback", mName.string());
}
@@ -765,7 +779,7 @@
void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const {
const State& s(getDrawingState());
- computeGeometry(renderArea, mMesh, useIdentityTransform);
+ computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
/*
* NOTE: the way we compute the texture coordinates here produces
@@ -802,7 +816,7 @@
// TODO: we probably want to generate the texture coords with the mesh
// here we assume that we only have 4 vertices
- Mesh::VertexArray<vec2> texCoords(mMesh.getTexCoordArray<vec2>());
+ Mesh::VertexArray<vec2> texCoords(getBE().mMesh.getTexCoordArray<vec2>());
texCoords[0] = vec2(left, 1.0f - top);
texCoords[1] = vec2(left, 1.0f - bottom);
texCoords[2] = vec2(right, 1.0f - bottom);
@@ -812,7 +826,7 @@
engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), false /* disableTexture */,
getColor());
engine.setSourceDataSpace(mCurrentState.dataSpace);
- engine.drawMesh(mMesh);
+ engine.drawMesh(getBE().mMesh);
engine.disableBlending();
}
@@ -866,7 +880,8 @@
// able to be latched. To avoid this, grab this buffer anyway.
return true;
}
- return mQueueItems[0].mFenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
+ return mQueueItems[0].mFenceTime->getSignalTime() !=
+ Fence::SIGNAL_TIME_PENDING;
}
uint32_t BufferLayer::getEffectiveScalingMode() const {
diff --git a/services/surfaceflinger/ColorLayer.cpp b/services/surfaceflinger/ColorLayer.cpp
index 292e1a7..b784c8d 100644
--- a/services/surfaceflinger/ColorLayer.cpp
+++ b/services/surfaceflinger/ColorLayer.cpp
@@ -66,7 +66,7 @@
const auto& viewport = displayDevice->getViewport();
Region visible = tr.transform(visibleRegion.intersect(viewport));
auto hwcId = displayDevice->getHwcDisplayId();
- auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcInfo = getBE().mHwcLayers[hwcId];
auto& hwcLayer = hwcInfo.layer;
auto error = hwcLayer->setVisibleRegion(visible);
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 58b5db0..359b64f 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -62,6 +62,11 @@
namespace android {
+LayerBE::LayerBE()
+ : mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2) {
+}
+
+
int32_t Layer::sSequence = 1;
Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w,
@@ -84,7 +89,6 @@
mFrameLatencyNeeded(false),
mFiltering(false),
mNeedsFiltering(false),
- mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2),
mProtectedByApp(false),
mClientRef(client),
mPotentialCursor(false),
@@ -133,6 +137,7 @@
CompositorTiming compositorTiming;
flinger->getCompositorTiming(&compositorTiming);
mFrameEventHistory.initializeCompositorTiming(compositorTiming);
+
}
void Layer::onFirstRef() {}
@@ -204,41 +209,42 @@
// ---------------------------------------------------------------------------
bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
- LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Already have a layer for hwcId %d", hwcId);
+ LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
+ "Already have a layer for hwcId %d", hwcId);
HWC2::Layer* layer = hwc->createLayer(hwcId);
if (!layer) {
return false;
}
- HWCInfo& hwcInfo = mHwcLayers[hwcId];
+ LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[hwcId];
hwcInfo.hwc = hwc;
hwcInfo.layer = layer;
layer->setLayerDestroyedListener(
- [this, hwcId](HWC2::Layer* /*layer*/) { mHwcLayers.erase(hwcId); });
+ [this, hwcId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(hwcId); });
return true;
}
bool Layer::destroyHwcLayer(int32_t hwcId) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
return false;
}
- auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcInfo = getBE().mHwcLayers[hwcId];
LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
// The layer destroyed listener should have cleared the entry from
// mHwcLayers. Verify that.
- LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Stale layer entry in mHwcLayers");
-
+ LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
+ "Stale layer entry in getBE().mHwcLayers");
return true;
}
void Layer::destroyAllHwcLayers() {
- size_t numLayers = mHwcLayers.size();
+ size_t numLayers = getBE().mHwcLayers.size();
for (size_t i = 0; i < numLayers; ++i) {
- LOG_ALWAYS_FATAL_IF(mHwcLayers.empty(), "destroyAllHwcLayers failed");
- destroyHwcLayer(mHwcLayers.begin()->first);
+ LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
+ destroyHwcLayer(getBE().mHwcLayers.begin()->first);
}
- LOG_ALWAYS_FATAL_IF(!mHwcLayers.empty(),
+ LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
"All hardware composer layers should have been destroyed");
}
@@ -459,7 +465,7 @@
void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
{
const auto hwcId = displayDevice->getHwcDisplayId();
- auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcInfo = getBE().mHwcLayers[hwcId];
// enable this layer
hwcInfo.forceClientComposition = false;
@@ -615,26 +621,27 @@
}
void Layer::forceClientComposition(int32_t hwcId) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
return;
}
- mHwcLayers[hwcId].forceClientComposition = true;
+ getBE().mHwcLayers[hwcId].forceClientComposition = true;
}
bool Layer::getForceClientComposition(int32_t hwcId) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("getForceClientComposition: no HWC layer found (%d)", hwcId);
return false;
}
- return mHwcLayers[hwcId].forceClientComposition;
+ return getBE().mHwcLayers[hwcId].forceClientComposition;
}
void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
auto hwcId = displayDevice->getHwcDisplayId();
- if (mHwcLayers.count(hwcId) == 0 || getCompositionType(hwcId) != HWC2::Composition::Cursor) {
+ if (getBE().mHwcLayers.count(hwcId) == 0 ||
+ getCompositionType(hwcId) != HWC2::Composition::Cursor) {
return;
}
@@ -657,7 +664,8 @@
auto& displayTransform(displayDevice->getTransform());
auto position = displayTransform.transform(frame);
- auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, position.top);
+ auto error = getBE().mHwcLayers[hwcId].layer->setCursorPosition(position.left,
+ position.top);
ALOGE_IF(error != HWC2::Error::None,
"[%s] Failed to set cursor position "
"to (%d, %d): %s (%d)",
@@ -684,9 +692,9 @@
void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
float alpha) const {
RenderEngine& engine(mFlinger->getRenderEngine());
- computeGeometry(renderArea, mMesh, false);
+ computeGeometry(renderArea, getBE().mMesh, false);
engine.setupFillWithColor(red, green, blue, alpha);
- engine.drawMesh(mMesh);
+ engine.drawMesh(getBE().mMesh);
}
void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
@@ -694,11 +702,11 @@
}
void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("setCompositionType called without a valid HWC layer");
return;
}
- auto& hwcInfo = mHwcLayers[hwcId];
+ auto& hwcInfo = getBE().mHwcLayers[hwcId];
auto& hwcLayer = hwcInfo.layer;
ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
static_cast<int>(callIntoHwc));
@@ -722,27 +730,27 @@
// have a HWC counterpart, then it will always be Client
return HWC2::Composition::Client;
}
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("getCompositionType called with an invalid HWC layer");
return HWC2::Composition::Invalid;
}
- return mHwcLayers.at(hwcId).compositionType;
+ return getBE().mHwcLayers.at(hwcId).compositionType;
}
void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("setClearClientTarget called without a valid HWC layer");
return;
}
- mHwcLayers[hwcId].clearClientTarget = clear;
+ getBE().mHwcLayers[hwcId].clearClientTarget = clear;
}
bool Layer::getClearClientTarget(int32_t hwcId) const {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
ALOGE("getClearClientTarget called without a valid HWC layer");
return false;
}
- return mHwcLayers.at(hwcId).clearClientTarget;
+ return getBE().mHwcLayers.at(hwcId).clearClientTarget;
}
bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
@@ -961,11 +969,12 @@
" requested={ wh={%4u,%4u} }}\n"
" drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
" requested={ wh={%4u,%4u} }}\n",
- this, getName().string(), mCurrentTransform, getEffectiveScalingMode(), c.active.w,
- c.active.h, c.crop.left, c.crop.top, c.crop.right, c.crop.bottom,
- c.crop.getWidth(), c.crop.getHeight(), c.requested.w, c.requested.h, s.active.w,
- s.active.h, s.crop.left, s.crop.top, s.crop.right, s.crop.bottom,
- s.crop.getWidth(), s.crop.getHeight(), s.requested.w, s.requested.h);
+ this, getName().string(), mCurrentTransform,
+ getEffectiveScalingMode(), c.active.w, c.active.h, c.crop.left, c.crop.top,
+ c.crop.right, c.crop.bottom, c.crop.getWidth(), c.crop.getHeight(), c.requested.w,
+ c.requested.h, s.active.w, s.active.h, s.crop.left, s.crop.top, s.crop.right,
+ s.crop.bottom, s.crop.getWidth(), s.crop.getHeight(), s.requested.w,
+ s.requested.h);
// record the new size, form this point on, when the client request
// a buffer, it'll get the new size.
@@ -993,7 +1002,7 @@
const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
(mActiveBuffer != nullptr);
if (!isFixedSize()) {
- if (resizePending && mSidebandStream == NULL) {
+ if (resizePending && getBE().mSidebandStream == NULL) {
flags |= eDontUpdateGeometryState;
}
}
@@ -1102,6 +1111,19 @@
return true;
}
+bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
+ const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
+ ssize_t idx = mCurrentChildren.indexOf(childLayer);
+ if (idx < 0) {
+ return false;
+ }
+ if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
+ mCurrentChildren.removeAt(idx);
+ mCurrentChildren.add(childLayer);
+ }
+ return true;
+}
+
bool Layer::setLayer(int32_t z) {
if (mCurrentState.z == z) return false;
mCurrentState.sequence++;
@@ -1410,7 +1432,7 @@
}
void Layer::miniDump(String8& result, int32_t hwcId) const {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
return;
}
@@ -1428,7 +1450,7 @@
result.appendFormat(" %s\n", name.string());
const Layer::State& layerState(getDrawingState());
- const HWCInfo& hwcInfo = mHwcLayers.at(hwcId);
+ const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(hwcId);
result.appendFormat(" %10d | ", layerState.z);
result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
const Rect& frame = hwcInfo.displayFrame;
@@ -1560,17 +1582,14 @@
}
bool Layer::detachChildren() {
- traverseInZOrder(LayerVector::StateSet::Drawing, [this](Layer* child) {
- if (child == this) {
- return;
- }
-
+ for (const sp<Layer>& child : mCurrentChildren) {
sp<Client> parentClient = mClientRef.promote();
sp<Client> client(child->mClientRef.promote());
if (client != nullptr && parentClient != client) {
- client->detachLayer(child);
+ client->detachLayer(child.get());
+ child->detachChildren();
}
- });
+ }
return true;
}
@@ -1603,11 +1622,7 @@
const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
const State& state = useDrawing ? mDrawingState : mCurrentState;
- if (state.zOrderRelatives.size() == 0) {
- return children;
- }
LayerVector traverse;
-
for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
sp<Layer> strongRelative = weakRelative.promote();
if (strongRelative != nullptr) {
@@ -1616,6 +1631,10 @@
}
for (const sp<Layer>& child : children) {
+ const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
+ if (childState.zOrderRelativeOf != nullptr) {
+ continue;
+ }
traverse.add(child);
}
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 44b178a..b7b7a3a 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -65,13 +65,51 @@
class GraphicBuffer;
class SurfaceFlinger;
class LayerDebugInfo;
+class LayerBE;
// ---------------------------------------------------------------------------
+class LayerBE {
+public:
+ LayerBE();
+
+ sp<NativeHandle> mSidebandStream;
+
+ // The mesh used to draw the layer in GLES composition mode
+ Mesh mMesh;
+
+ // HWC items, accessed from the main thread
+ struct HWCInfo {
+ HWCInfo()
+ : hwc(nullptr),
+ layer(nullptr),
+ forceClientComposition(false),
+ compositionType(HWC2::Composition::Invalid),
+ clearClientTarget(false) {}
+
+ HWComposer* hwc;
+ HWC2::Layer* layer;
+ bool forceClientComposition;
+ HWC2::Composition compositionType;
+ bool clearClientTarget;
+ Rect displayFrame;
+ FloatRect sourceCrop;
+ HWComposerBufferCache bufferCache;
+ };
+
+ // A layer can be attached to multiple displays when operating in mirror mode
+ // (a.k.a: when several displays are attached with equal layerStack). In this
+ // case we need to keep track. In non-mirror mode, a layer will have only one
+ // HWCInfo. This map key is a display layerStack.
+ std::unordered_map<int32_t, HWCInfo> mHwcLayers;
+};
+
class Layer : public virtual RefBase {
static int32_t sSequence;
public:
+ LayerBE& getBE() { return mBE; }
+ LayerBE& getBE() const { return mBE; }
mutable bool contentDirty;
// regions below are in window-manager space
Region visibleRegion;
@@ -417,13 +455,15 @@
bool destroyHwcLayer(int32_t hwcId);
void destroyAllHwcLayers();
- bool hasHwcLayer(int32_t hwcId) { return mHwcLayers.count(hwcId) > 0; }
+ bool hasHwcLayer(int32_t hwcId) {
+ return getBE().mHwcLayers.count(hwcId) > 0;
+ }
HWC2::Layer* getHwcLayer(int32_t hwcId) {
- if (mHwcLayers.count(hwcId) == 0) {
+ if (getBE().mHwcLayers.count(hwcId) == 0) {
return nullptr;
}
- return mHwcLayers[hwcId].layer;
+ return getBE().mHwcLayers[hwcId].layer;
}
// -----------------------------------------------------------------------
@@ -482,6 +522,8 @@
bool hasParent() const { return getParent() != nullptr; }
Rect computeScreenBounds(bool reduceTransparentRegion = true) const;
bool setChildLayer(const sp<Layer>& childLayer, int32_t z);
+ bool setChildRelativeLayer(const sp<Layer>& childLayer,
+ const sp<IBinder>& relativeToHandle, int32_t relativeZ);
// Copy the current list of children to the drawing state. Called by
// SurfaceFlinger to complete a transaction.
@@ -650,36 +692,9 @@
bool mFiltering;
// Whether filtering is needed b/c of the drawingstate
bool mNeedsFiltering;
- // The mesh used to draw the layer in GLES composition mode
- mutable Mesh mMesh;
bool mPendingRemoval = false;
- // HWC items, accessed from the main thread
- struct HWCInfo {
- HWCInfo()
- : hwc(nullptr),
- layer(nullptr),
- forceClientComposition(false),
- compositionType(HWC2::Composition::Invalid),
- clearClientTarget(false) {}
-
- HWComposer* hwc;
- HWC2::Layer* layer;
- bool forceClientComposition;
- HWC2::Composition compositionType;
- bool clearClientTarget;
- Rect displayFrame;
- FloatRect sourceCrop;
- HWComposerBufferCache bufferCache;
- };
-
- // A layer can be attached to multiple displays when operating in mirror mode
- // (a.k.a: when several displays are attached with equal layerStack). In this
- // case we need to keep track. In non-mirror mode, a layer will have only one
- // HWCInfo. This map key is a display layerStack.
- std::unordered_map<int32_t, HWCInfo> mHwcLayers;
-
// page-flip thread (currently main thread)
bool mProtectedByApp; // application requires protected path to external sink
@@ -706,6 +721,8 @@
wp<Layer> mCurrentParent;
wp<Layer> mDrawingParent;
+
+ mutable LayerBE mBE;
};
// ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index dc178d7..ec2a459 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3143,11 +3143,21 @@
}
}
if (what & layer_state_t::eRelativeLayerChanged) {
- ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
- if (layer->setRelativeLayer(s.relativeLayerHandle, s.z)) {
- mCurrentState.layersSortedByZ.removeAt(idx);
- mCurrentState.layersSortedByZ.add(layer);
- flags |= eTransactionNeeded|eTraversalNeeded;
+ // NOTE: index needs to be calculated before we update the state
+ const auto& p = layer->getParent();
+ if (p == nullptr) {
+ ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
+ if (layer->setRelativeLayer(s.relativeLayerHandle, s.z) && idx >= 0) {
+ mCurrentState.layersSortedByZ.removeAt(idx);
+ mCurrentState.layersSortedByZ.add(layer);
+ // we need traversal (state changed)
+ // AND transaction (list changed)
+ flags |= eTransactionNeeded|eTraversalNeeded;
+ }
+ } else {
+ if (p->setChildRelativeLayer(layer, s.relativeLayerHandle, s.z)) {
+ flags |= eTransactionNeeded|eTraversalNeeded;
+ }
}
}
if (what & layer_state_t::eSizeChanged) {
@@ -4752,7 +4762,8 @@
continue;
}
const Layer::State& state(layer->getDrawingState());
- if (state.z < minLayerZ || state.z > maxLayerZ) {
+ // relative layers are traversed in Layer::traverseInZOrder
+ if (state.zOrderRelativeOf != nullptr || state.z < minLayerZ || state.z > maxLayerZ) {
continue;
}
layer->traverseInZOrder(LayerVector::StateSet::Drawing, [&](Layer* layer) {
diff --git a/services/surfaceflinger/tests/SurfaceFlinger_test.filter b/services/surfaceflinger/tests/SurfaceFlinger_test.filter
index 5c188dc..be4127c 100644
--- a/services/surfaceflinger/tests/SurfaceFlinger_test.filter
+++ b/services/surfaceflinger/tests/SurfaceFlinger_test.filter
@@ -1,5 +1,5 @@
{
"presubmit": {
- "filter": "LayerUpdateTest.*:ChildLayerTest.*:SurfaceFlingerStress.*:CropLatchingTest.*:GeometryLatchingTest.*:LayerColorTest.*"
+ "filter": "LayerTransactionTest.*:LayerUpdateTest.*:ChildLayerTest.*:SurfaceFlingerStress.*:CropLatchingTest.*:GeometryLatchingTest.*"
}
-}
\ No newline at end of file
+}
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index 16a16a5..943fafd 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -14,6 +14,11 @@
* limitations under the License.
*/
+#include <algorithm>
+#include <functional>
+#include <limits>
+#include <ostream>
+
#include <gtest/gtest.h>
#include <android/native_window.h>
@@ -25,21 +30,121 @@
#include <gui/SurfaceComposerClient.h>
#include <private/gui/ComposerService.h>
-#include <utils/String8.h>
#include <ui/DisplayInfo.h>
+#include <ui/Rect.h>
+#include <utils/String8.h>
#include <math.h>
#include <math/vec3.h>
-#include <functional>
-
namespace android {
+namespace {
+
+struct Color {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+
+ static const Color RED;
+ static const Color GREEN;
+ static const Color BLUE;
+ static const Color WHITE;
+ static const Color BLACK;
+ static const Color TRANSPARENT;
+};
+
+const Color Color::RED{255, 0, 0, 255};
+const Color Color::GREEN{0, 255, 0, 255};
+const Color Color::BLUE{0, 0, 255, 255};
+const Color Color::WHITE{255, 255, 255, 255};
+const Color Color::BLACK{0, 0, 0, 255};
+const Color Color::TRANSPARENT{0, 0, 0, 0};
+
+std::ostream& operator<<(std::ostream& os, const Color& color) {
+ os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a);
+ return os;
+}
+
+// Fill a region with the specified color.
+void fillBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, const Color& color) {
+ int32_t x = rect.left;
+ int32_t y = rect.top;
+ int32_t width = rect.right - rect.left;
+ int32_t height = rect.bottom - rect.top;
+
+ if (x < 0) {
+ width += x;
+ x = 0;
+ }
+ if (y < 0) {
+ height += y;
+ y = 0;
+ }
+ if (x + width > buffer.width) {
+ x = std::min(x, buffer.width);
+ width = buffer.width - x;
+ }
+ if (y + height > buffer.height) {
+ y = std::min(y, buffer.height);
+ height = buffer.height - y;
+ }
+
+ for (int32_t j = 0; j < height; j++) {
+ uint8_t* dst = static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (y + j) + x) * 4;
+ for (int32_t i = 0; i < width; i++) {
+ dst[0] = color.r;
+ dst[1] = color.g;
+ dst[2] = color.b;
+ dst[3] = color.a;
+ dst += 4;
+ }
+ }
+}
+
+// Check if a region has the specified color.
+void expectBufferColor(const CpuConsumer::LockedBuffer& buffer, const Rect& rect,
+ const Color& color, uint8_t tolerance) {
+ int32_t x = rect.left;
+ int32_t y = rect.top;
+ int32_t width = rect.right - rect.left;
+ int32_t height = rect.bottom - rect.top;
+
+ if (x + width > int32_t(buffer.width)) {
+ x = std::min(x, int32_t(buffer.width));
+ width = buffer.width - x;
+ }
+ if (y + height > int32_t(buffer.height)) {
+ y = std::min(y, int32_t(buffer.height));
+ height = buffer.height - y;
+ }
+
+ auto colorCompare = [tolerance](uint8_t a, uint8_t b) {
+ uint8_t tmp = a >= b ? a - b : b - a;
+ return tmp <= tolerance;
+ };
+ for (int32_t j = 0; j < height; j++) {
+ const uint8_t* src =
+ static_cast<const uint8_t*>(buffer.data) + (buffer.stride * (y + j) + x) * 4;
+ for (int32_t i = 0; i < width; i++) {
+ const uint8_t expected[4] = {color.r, color.g, color.b, color.a};
+ EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare))
+ << "pixel @ (" << x + i << ", " << y + j << "): "
+ << "expected (" << color << "), "
+ << "got (" << Color{src[0], src[1], src[2], src[3]} << ")";
+ src += 4;
+ }
+ }
+}
+
+} // anonymous namespace
+
using Transaction = SurfaceComposerClient::Transaction;
// Fill an RGBA_8888 formatted surface with a single color.
-static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc,
- uint8_t r, uint8_t g, uint8_t b, bool unlock=true) {
+static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b,
+ bool unlock = true) {
ANativeWindow_Buffer outBuffer;
sp<Surface> s = sc->getSurface();
ASSERT_TRUE(s != NULL);
@@ -47,7 +152,7 @@
uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
for (int y = 0; y < outBuffer.height; y++) {
for (int x = 0; x < outBuffer.width; x++) {
- uint8_t* pixel = img + (4 * (y*outBuffer.stride + x));
+ uint8_t* pixel = img + (4 * (y * outBuffer.stride + x));
pixel[0] = r;
pixel[1] = g;
pixel[2] = b;
@@ -63,54 +168,107 @@
// individual pixel values for testing purposes.
class ScreenCapture : public RefBase {
public:
- static void captureScreen(sp<ScreenCapture>* sc) {
+ static void captureScreen(sp<ScreenCapture>* sc, int32_t minLayerZ = 0,
+ int32_t maxLayerZ = std::numeric_limits<int32_t>::max()) {
sp<IGraphicBufferProducer> producer;
sp<IGraphicBufferConsumer> consumer;
BufferQueue::createBufferQueue(&producer, &consumer);
sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
- sp<IBinder> display(sf->getBuiltInDisplay(
- ISurfaceComposer::eDisplayIdMain));
+ sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
SurfaceComposerClient::Transaction().apply(true);
- ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
- 0, INT_MAX, false));
+ ASSERT_EQ(NO_ERROR,
+ sf->captureScreen(display, producer, Rect(), 0, 0, minLayerZ, maxLayerZ, false));
*sc = new ScreenCapture(cpuConsumer);
}
+ void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
+ ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
+ expectBufferColor(mBuf, rect, color, tolerance);
+ }
+
+ void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) {
+ ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
+ const bool leftBorder = rect.left > 0;
+ const bool topBorder = rect.top > 0;
+ const bool rightBorder = rect.right < int32_t(mBuf.width);
+ const bool bottomBorder = rect.bottom < int32_t(mBuf.height);
+
+ if (topBorder) {
+ Rect top(rect.left, rect.top - 1, rect.right, rect.top);
+ if (leftBorder) {
+ top.left -= 1;
+ }
+ if (rightBorder) {
+ top.right += 1;
+ }
+ expectColor(top, color, tolerance);
+ }
+ if (leftBorder) {
+ Rect left(rect.left - 1, rect.top, rect.left, rect.bottom);
+ expectColor(left, color, tolerance);
+ }
+ if (rightBorder) {
+ Rect right(rect.right, rect.top, rect.right + 1, rect.bottom);
+ expectColor(right, color, tolerance);
+ }
+ if (bottomBorder) {
+ Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1);
+ if (leftBorder) {
+ bottom.left -= 1;
+ }
+ if (rightBorder) {
+ bottom.right += 1;
+ }
+ expectColor(bottom, color, tolerance);
+ }
+ }
+
+ void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight,
+ const Color& bottomLeft, const Color& bottomRight, bool filtered = false,
+ uint8_t tolerance = 0) {
+ ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0);
+
+ const int32_t centerX = rect.left + (rect.right - rect.left) / 2;
+ const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2;
+ // avoid checking borders due to unspecified filtering behavior
+ const int32_t offsetX = filtered ? 2 : 0;
+ const int32_t offsetY = filtered ? 2 : 0;
+ expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft,
+ tolerance);
+ expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight,
+ tolerance);
+ expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft,
+ tolerance);
+ expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom),
+ bottomRight, tolerance);
+ }
+
void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
const uint8_t* img = static_cast<const uint8_t*>(mBuf.data);
const uint8_t* pixel = img + (4 * (y * mBuf.stride + x));
if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
String8 err(String8::format("pixel @ (%3d, %3d): "
- "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
- x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
+ "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
+ x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
EXPECT_EQ(String8(), err) << err.string();
}
}
- void expectFGColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 195, 63, 63);
- }
+ void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); }
- void expectBGColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 63, 63, 195);
- }
+ void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); }
- void expectChildColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 200, 200, 200);
- }
+ void expectChildColor(uint32_t x, uint32_t y) { checkPixel(x, y, 200, 200, 200); }
private:
- ScreenCapture(const sp<CpuConsumer>& cc) :
- mCC(cc) {
+ ScreenCapture(const sp<CpuConsumer>& cc) : mCC(cc) {
EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf));
}
- ~ScreenCapture() {
- mCC->unlockBuffer(mBuf);
- }
+ ~ScreenCapture() { mCC->unlockBuffer(mBuf); }
sp<CpuConsumer> mCC;
CpuConsumer::LockedBuffer mBuf;
@@ -124,8 +282,7 @@
BufferQueue::createBufferQueue(&producer, &consumer);
sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
- sp<IBinder> display(sf->getBuiltInDisplay(
- ISurfaceComposer::eDisplayIdMain));
+ sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
SurfaceComposerClient::Transaction().apply(true);
ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, producer));
*sc = std::make_unique<CaptureLayer>(cpuConsumer);
@@ -137,38 +294,1215 @@
const uint8_t* pixel = img + (4 * (y * mBuffer.stride + x));
if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
String8 err(String8::format("pixel @ (%3d, %3d): "
- "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
+ "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
EXPECT_EQ(String8(), err) << err.string();
}
}
- void expectFGColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 195, 63, 63);
- }
+ void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); }
- void expectBGColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 63, 63, 195);
- }
+ void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); }
- void expectChildColor(uint32_t x, uint32_t y) {
- checkPixel(x, y, 200, 200, 200);
- }
+ void expectChildColor(uint32_t x, uint32_t y) { checkPixel(x, y, 200, 200, 200); }
- CaptureLayer(const sp<CpuConsumer>& cc) :
- mCC(cc) {
+ CaptureLayer(const sp<CpuConsumer>& cc) : mCC(cc) {
EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuffer));
}
- ~CaptureLayer() {
- mCC->unlockBuffer(mBuffer);
- }
+ ~CaptureLayer() { mCC->unlockBuffer(mBuffer); }
private:
sp<CpuConsumer> mCC;
CpuConsumer::LockedBuffer mBuffer;
};
+class LayerTransactionTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ mClient = new SurfaceComposerClient;
+ ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient";
+
+ ASSERT_NO_FATAL_FAILURE(SetUpDisplay());
+ }
+
+ sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height,
+ uint32_t flags = 0) {
+ auto layer =
+ mClient->createSurface(String8(name), width, height, PIXEL_FORMAT_RGBA_8888, flags);
+ EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl";
+
+ status_t error = Transaction()
+ .setLayerStack(layer, mDisplayLayerStack)
+ .setLayer(layer, mLayerZBase)
+ .apply();
+ if (error != NO_ERROR) {
+ ADD_FAILURE() << "failed to initialize SurfaceControl";
+ layer.clear();
+ }
+
+ return layer;
+ }
+
+ ANativeWindow_Buffer getLayerBuffer(const sp<SurfaceControl>& layer) {
+ // wait for previous transactions (such as setSize) to complete
+ Transaction().apply(true);
+
+ ANativeWindow_Buffer buffer = {};
+ EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr));
+
+ return buffer;
+ }
+
+ void postLayerBuffer(const sp<SurfaceControl>& layer) {
+ ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost());
+
+ // wait for the newly posted buffer to be latched
+ waitForLayerBuffers();
+ }
+
+ void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color) {
+ ANativeWindow_Buffer buffer;
+ ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer));
+ fillBufferColor(buffer, Rect(0, 0, buffer.width, buffer.height), color);
+ postLayerBuffer(layer);
+ }
+
+ void fillLayerQuadrant(const sp<SurfaceControl>& layer, const Color& topLeft,
+ const Color& topRight, const Color& bottomLeft,
+ const Color& bottomRight) {
+ ANativeWindow_Buffer buffer;
+ ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer));
+ ASSERT_TRUE(buffer.width % 2 == 0 && buffer.height % 2 == 0);
+
+ const int32_t halfW = buffer.width / 2;
+ const int32_t halfH = buffer.height / 2;
+ fillBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft);
+ fillBufferColor(buffer, Rect(halfW, 0, buffer.width, halfH), topRight);
+ fillBufferColor(buffer, Rect(0, halfH, halfW, buffer.height), bottomLeft);
+ fillBufferColor(buffer, Rect(halfW, halfH, buffer.width, buffer.height), bottomRight);
+
+ postLayerBuffer(layer);
+ }
+
+ sp<ScreenCapture> screenshot() {
+ sp<ScreenCapture> screenshot;
+ ScreenCapture::captureScreen(&screenshot, mLayerZBase);
+ return screenshot;
+ }
+
+ sp<SurfaceComposerClient> mClient;
+
+ sp<IBinder> mDisplay;
+ uint32_t mDisplayWidth;
+ uint32_t mDisplayHeight;
+ uint32_t mDisplayLayerStack;
+
+ // leave room for ~256 layers
+ const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256;
+
+private:
+ void SetUpDisplay() {
+ mDisplay = mClient->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain);
+ ASSERT_NE(nullptr, mDisplay.get()) << "failed to get built-in display";
+
+ // get display width/height
+ DisplayInfo info;
+ SurfaceComposerClient::getDisplayInfo(mDisplay, &info);
+ mDisplayWidth = info.w;
+ mDisplayHeight = info.h;
+
+ // After a new buffer is queued, SurfaceFlinger is notified and will
+ // latch the new buffer on next vsync. Let's heuristically wait for 3
+ // vsyncs.
+ mBufferPostDelay = int32_t(1e6 / info.fps) * 3;
+
+ mDisplayLayerStack = 0;
+ // set layer stack (b/68888219)
+ Transaction t;
+ t.setDisplayLayerStack(mDisplay, mDisplayLayerStack);
+ t.apply();
+ }
+
+ void waitForLayerBuffers() { usleep(mBufferPostDelay); }
+
+ int32_t mBufferPostDelay;
+};
+
+TEST_F(LayerTransactionTest, SetPositionBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ {
+ SCOPED_TRACE("default position");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
+ }
+
+ Transaction().setPosition(layer, 5, 10).apply();
+ {
+ SCOPED_TRACE("new position");
+ auto shot = screenshot();
+ shot->expectColor(Rect(5, 10, 37, 42), Color::RED);
+ shot->expectBorder(Rect(5, 10, 37, 42), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionRounding) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // GLES requires only 4 bits of subpixel precision during rasterization
+ // XXX GLES composition does not match HWC composition due to precision
+ // loss (b/69315223)
+ const float epsilon = 1.0f / 16.0f;
+ Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply();
+ {
+ SCOPED_TRACE("rounding down");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply();
+ {
+ SCOPED_TRACE("rounding up");
+ screenshot()->expectColor(Rect(1, 1, 33, 33), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionOutOfBounds) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ Transaction().setPosition(layer, -32, -32).apply();
+ {
+ SCOPED_TRACE("negative coordinates");
+ screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
+ }
+
+ Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply();
+ {
+ SCOPED_TRACE("positive coordinates");
+ screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionPartiallyOutOfBounds) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // partially out of bounds
+ Transaction().setPosition(layer, -30, -30).apply();
+ {
+ SCOPED_TRACE("negative coordinates");
+ screenshot()->expectColor(Rect(0, 0, 2, 2), Color::RED);
+ }
+
+ Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply();
+ {
+ SCOPED_TRACE("positive coordinates");
+ screenshot()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth,
+ mDisplayHeight),
+ Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionWithResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setPosition is applied immediately by default, with or without resize
+ // pending
+ Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(5, 10, 37, 42), Color::RED);
+ shot->expectBorder(Rect(5, 10, 37, 42), Color::BLACK);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("resize applied");
+ screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionWithNextResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // request setPosition to be applied with the next resize
+ Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply();
+ {
+ SCOPED_TRACE("new position pending");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setPosition(layer, 15, 20).apply();
+ {
+ SCOPED_TRACE("pending new position modified");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setSize(layer, 64, 64).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ // finally resize and latch the buffer
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("new position applied");
+ screenshot()->expectColor(Rect(15, 20, 79, 84), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetPositionWithNextResizeScaleToWindow) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setPosition is not immediate even with SCALE_TO_WINDOW override
+ Transaction()
+ .setPosition(layer, 5, 10)
+ .setSize(layer, 64, 64)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .setGeometryAppliesWithResize(layer)
+ .apply();
+ {
+ SCOPED_TRACE("new position pending");
+ screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("new position applied");
+ screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetSizeBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ Transaction().setSize(layer, 64, 64).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("resize applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 64, 64), Color::RED);
+ shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetSizeInvalid) {
+ // cannot test robustness against invalid sizes (zero or really huge)
+}
+
+TEST_F(LayerTransactionTest, SetSizeWithScaleToWindow) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition
+ Transaction()
+ .setSize(layer, 64, 64)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .apply();
+ screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetZBasic) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+
+ Transaction().setLayer(layerR, mLayerZBase + 1).apply();
+ {
+ SCOPED_TRACE("layerR");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setLayer(layerG, mLayerZBase + 2).apply();
+ {
+ SCOPED_TRACE("layerG");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::GREEN);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetZNegative) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+
+ Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply();
+ {
+ SCOPED_TRACE("layerR");
+ sp<ScreenCapture> screenshot;
+ ScreenCapture::captureScreen(&screenshot, -2, -1);
+ screenshot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setLayer(layerR, -3).apply();
+ {
+ SCOPED_TRACE("layerG");
+ sp<ScreenCapture> screenshot;
+ ScreenCapture::captureScreen(&screenshot, -3, -1);
+ screenshot->expectColor(Rect(0, 0, 32, 32), Color::GREEN);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetRelativeZBasic) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+
+ Transaction()
+ .setPosition(layerG, 16, 16)
+ .setRelativeLayer(layerG, layerR->getHandle(), 1)
+ .apply();
+ {
+ SCOPED_TRACE("layerG above");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 16, 16), Color::RED);
+ shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN);
+ }
+
+ Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply();
+ {
+ SCOPED_TRACE("layerG below");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetRelativeZNegative) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ sp<SurfaceControl> layerB;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+ ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE));
+
+ // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2
+ Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply();
+
+ sp<ScreenCapture> screenshot;
+ // only layerB is in this range
+ ScreenCapture::captureScreen(&screenshot, -2, -1);
+ screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE);
+}
+
+TEST_F(LayerTransactionTest, SetRelativeZGroup) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ sp<SurfaceControl> layerB;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+ ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE));
+
+ // layerR = 0, layerG = layerR + 3, layerB = 2
+ Transaction()
+ .setPosition(layerG, 8, 8)
+ .setRelativeLayer(layerG, layerR->getHandle(), 3)
+ .setPosition(layerB, 16, 16)
+ .setLayer(layerB, mLayerZBase + 2)
+ .apply();
+ {
+ SCOPED_TRACE("(layerR < layerG) < layerB");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 8, 8), Color::RED);
+ shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN);
+ shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE);
+ }
+
+ // layerR = 4, layerG = layerR + 3, layerB = 2
+ Transaction().setLayer(layerR, mLayerZBase + 4).apply();
+ {
+ SCOPED_TRACE("layerB < (layerR < layerG)");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 8, 8), Color::RED);
+ shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN);
+ shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE);
+ }
+
+ // layerR = 4, layerG = layerR - 3, layerB = 2
+ Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply();
+ {
+ SCOPED_TRACE("layerB < (layerG < layerR)");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN);
+ shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE);
+ }
+
+ // restore to absolute z
+ // layerR = 4, layerG = 0, layerB = 2
+ Transaction().setLayer(layerG, mLayerZBase).apply();
+ {
+ SCOPED_TRACE("layerG < layerB < layerR");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE);
+ }
+
+ // layerR should not affect layerG anymore
+ // layerR = 1, layerG = 0, layerB = 2
+ Transaction().setLayer(layerR, mLayerZBase + 1).apply();
+ {
+ SCOPED_TRACE("layerG < layerR < layerB");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 16, 16), Color::RED);
+ shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetRelativeZBug64572777) {
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+
+ Transaction()
+ .setPosition(layerG, 16, 16)
+ .setRelativeLayer(layerG, layerR->getHandle(), 1)
+ .apply();
+
+ mClient->destroySurface(layerG->getHandle());
+ // layerG should have been removed
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetFlagsHidden) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply();
+ {
+ SCOPED_TRACE("layer hidden");
+ screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
+ }
+
+ Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply();
+ {
+ SCOPED_TRACE("layer shown");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFlagsOpaque) {
+ const Color translucentRed = {100, 0, 0, 100};
+ sp<SurfaceControl> layerR;
+ sp<SurfaceControl> layerG;
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed));
+ ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN));
+
+ Transaction()
+ .setLayer(layerR, mLayerZBase + 1)
+ .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque)
+ .apply();
+ {
+ SCOPED_TRACE("layerR opaque");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255});
+ }
+
+ Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply();
+ {
+ SCOPED_TRACE("layerR translucent");
+ const uint8_t g = uint8_t(255 - translucentRed.a);
+ screenshot()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255});
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFlagsSecure) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ sp<ISurfaceComposer> composer = ComposerService::getComposerService();
+ sp<IGraphicBufferProducer> producer;
+ sp<IGraphicBufferConsumer> consumer;
+ BufferQueue::createBufferQueue(&producer, &consumer);
+ sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
+
+ Transaction()
+ .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure)
+ .apply(true);
+ ASSERT_EQ(PERMISSION_DENIED,
+ composer->captureScreen(mDisplay, producer, Rect(), 0, 0, mLayerZBase, mLayerZBase,
+ false));
+
+ Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true);
+ ASSERT_EQ(NO_ERROR,
+ composer->captureScreen(mDisplay, producer, Rect(), 0, 0, mLayerZBase, mLayerZBase,
+ false));
+}
+
+TEST_F(LayerTransactionTest, SetTransparentRegionHintBasic) {
+ const Rect top(0, 0, 32, 16);
+ const Rect bottom(0, 16, 32, 32);
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+
+ ANativeWindow_Buffer buffer;
+ ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer));
+ ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, top, Color::TRANSPARENT));
+ ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, bottom, Color::RED));
+ // setTransparentRegionHint always applies to the following buffer
+ Transaction().setTransparentRegionHint(layer, Region(top)).apply();
+ ASSERT_NO_FATAL_FAILURE(postLayerBuffer(layer));
+ {
+ SCOPED_TRACE("top transparent");
+ auto shot = screenshot();
+ shot->expectColor(top, Color::BLACK);
+ shot->expectColor(bottom, Color::RED);
+ }
+
+ Transaction().setTransparentRegionHint(layer, Region(bottom)).apply();
+ {
+ SCOPED_TRACE("transparent region hint pending");
+ auto shot = screenshot();
+ shot->expectColor(top, Color::BLACK);
+ shot->expectColor(bottom, Color::RED);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer));
+ ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, top, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, bottom, Color::TRANSPARENT));
+ ASSERT_NO_FATAL_FAILURE(postLayerBuffer(layer));
+ {
+ SCOPED_TRACE("bottom transparent");
+ auto shot = screenshot();
+ shot->expectColor(top, Color::RED);
+ shot->expectColor(bottom, Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetTransparentRegionHintOutOfBounds) {
+ sp<SurfaceControl> layerTransparent;
+ sp<SurfaceControl> layerR;
+ ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32));
+
+ // check that transparent region hint is bound by the layer size
+ Transaction()
+ .setTransparentRegionHint(layerTransparent,
+ Region(Rect(0, 0, mDisplayWidth, mDisplayHeight)))
+ .setPosition(layerR, 16, 16)
+ .setLayer(layerR, mLayerZBase + 1)
+ .apply();
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerTransparent, Color::TRANSPARENT));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED));
+ screenshot()->expectColor(Rect(16, 16, 48, 48), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetAlphaBasic) {
+ sp<SurfaceControl> layer1;
+ sp<SurfaceControl> layer2;
+ ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer1, {64, 0, 0, 255}));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer2, {0, 64, 0, 255}));
+
+ Transaction()
+ .setAlpha(layer1, 0.25f)
+ .setAlpha(layer2, 0.75f)
+ .setPosition(layer2, 16, 0)
+ .setLayer(layer2, mLayerZBase + 1)
+ .apply();
+ {
+ auto shot = screenshot();
+ uint8_t r = 16; // 64 * 0.25f
+ uint8_t g = 48; // 64 * 0.75f
+ shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255});
+ shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255});
+
+ r /= 4; // r * (1.0f - 0.75f)
+ shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255});
+ }
+}
+
+TEST_F(LayerTransactionTest, SetAlphaClamped) {
+ const Color color = {64, 0, 0, 255};
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color));
+
+ Transaction().setAlpha(layer, 2.0f).apply();
+ {
+ SCOPED_TRACE("clamped to 1.0f");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), color);
+ }
+
+ Transaction().setAlpha(layer, -1.0f).apply();
+ {
+ SCOPED_TRACE("clamped to 0.0f");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetColorBasic) {
+ sp<SurfaceControl> bufferLayer;
+ sp<SurfaceControl> colorLayer;
+ ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(
+ colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor));
+
+ Transaction().setLayer(colorLayer, mLayerZBase + 1).apply();
+ {
+ SCOPED_TRACE("default color");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK);
+ }
+
+ const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f);
+ const Color expected = {15, 51, 85, 255};
+ // this is handwavy, but the precison loss scaled by 255 (8-bit per
+ // channel) should be less than one
+ const uint8_t tolerance = 1;
+ Transaction().setColor(colorLayer, color).apply();
+ {
+ SCOPED_TRACE("new color");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), expected, tolerance);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetColorClamped) {
+ sp<SurfaceControl> colorLayer;
+ ASSERT_NO_FATAL_FAILURE(
+ colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor));
+
+ Transaction().setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetColorWithAlpha) {
+ sp<SurfaceControl> bufferLayer;
+ sp<SurfaceControl> colorLayer;
+ ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED));
+ ASSERT_NO_FATAL_FAILURE(
+ colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor));
+
+ const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f);
+ const float alpha = 0.25f;
+ const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f);
+ // this is handwavy, but the precison loss scaled by 255 (8-bit per
+ // channel) should be less than one
+ const uint8_t tolerance = 1;
+ Transaction()
+ .setColor(colorLayer, color)
+ .setAlpha(colorLayer, alpha)
+ .setLayer(colorLayer, mLayerZBase + 1)
+ .apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255},
+ tolerance);
+}
+
+TEST_F(LayerTransactionTest, SetColorWithBuffer) {
+ sp<SurfaceControl> bufferLayer;
+ ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED));
+
+ // color is ignored
+ Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetLayerStackBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply();
+ {
+ SCOPED_TRACE("non-existing layer stack");
+ screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK);
+ }
+
+ Transaction().setLayerStack(layer, mDisplayLayerStack).apply();
+ {
+ SCOPED_TRACE("original layer stack");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetMatrixBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE));
+
+ Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply();
+ {
+ SCOPED_TRACE("IDENTITY");
+ screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, Color::BLUE,
+ Color::WHITE);
+ }
+
+ Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply();
+ {
+ SCOPED_TRACE("FLIP_H");
+ screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE,
+ Color::BLUE);
+ }
+
+ Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply();
+ {
+ SCOPED_TRACE("FLIP_V");
+ screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED,
+ Color::GREEN);
+ }
+
+ Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply();
+ {
+ SCOPED_TRACE("ROT_90");
+ screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE,
+ Color::GREEN);
+ }
+
+ Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply();
+ {
+ SCOPED_TRACE("SCALE");
+ screenshot()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, Color::BLUE,
+ Color::WHITE, true /* filtered */);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetMatrixRot45) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE));
+
+ const float rot = M_SQRT1_2; // 45 degrees
+ const float trans = M_SQRT2 * 16.0f;
+ Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply();
+
+ auto shot = screenshot();
+ // check a 8x8 region inside each color
+ auto get8x8Rect = [](int32_t centerX, int32_t centerY) {
+ const int32_t halfL = 4;
+ return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL);
+ };
+ const int32_t unit = int32_t(trans / 2);
+ shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED);
+ shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN);
+ shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE);
+ shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE);
+}
+
+TEST_F(LayerTransactionTest, SetMatrixWithResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setMatrix is applied after any pending resize, unlike setPosition
+ Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("resize applied");
+ screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetMatrixWithScaleToWindow) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition
+ Transaction()
+ .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f)
+ .setSize(layer, 64, 64)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .apply();
+ screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED);
+}
+
+TEST_F(LayerTransactionTest, SetOverrideScalingModeBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE));
+
+ // XXX SCALE_CROP is not respected; calling setSize and
+ // setOverrideScalingMode in separate transactions does not work
+ // (b/69315456)
+ Transaction()
+ .setSize(layer, 64, 16)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .apply();
+ {
+ SCOPED_TRACE("SCALE_TO_WINDOW");
+ screenshot()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, Color::BLUE,
+ Color::WHITE, true /* filtered */);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetCropBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ const Rect crop(8, 8, 24, 24);
+
+ Transaction().setCrop(layer, crop).apply();
+ auto shot = screenshot();
+ shot->expectColor(crop, Color::RED);
+ shot->expectBorder(crop, Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetCropEmpty) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ {
+ SCOPED_TRACE("empty rect");
+ Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ {
+ SCOPED_TRACE("negative rect");
+ Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetCropOutOfBounds) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ Transaction().setCrop(layer, Rect(-128, -64, 128, 64)).apply();
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetCropWithTranslation) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ const Point position(32, 32);
+ const Rect crop(8, 8, 24, 24);
+ Transaction().setPosition(layer, position.x, position.y).setCrop(layer, crop).apply();
+ auto shot = screenshot();
+ shot->expectColor(crop + position, Color::RED);
+ shot->expectBorder(crop + position, Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetCropWithScale) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // crop is affected by matrix
+ Transaction()
+ .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f)
+ .setCrop(layer, Rect(8, 8, 24, 24))
+ .apply();
+ auto shot = screenshot();
+ shot->expectColor(Rect(16, 16, 48, 48), Color::RED);
+ shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetCropWithResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setCrop is applied immediately by default, with or without resize pending
+ Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(8, 8, 24, 24), Color::RED);
+ shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("resize applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(8, 8, 16, 16), Color::RED);
+ shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetCropWithNextResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // request setCrop to be applied with the next resize
+ Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setGeometryAppliesWithResize(layer).apply();
+ {
+ SCOPED_TRACE("waiting for next resize");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setCrop(layer, Rect(4, 4, 12, 12)).apply();
+ {
+ SCOPED_TRACE("pending crop modified");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setSize(layer, 16, 16).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ // finally resize
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("new crop applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(4, 4, 12, 12), Color::RED);
+ shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // setCrop is not immediate even with SCALE_TO_WINDOW override
+ Transaction()
+ .setCrop(layer, Rect(4, 4, 12, 12))
+ .setSize(layer, 16, 16)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .setGeometryAppliesWithResize(layer)
+ .apply();
+ {
+ SCOPED_TRACE("new crop pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 16, 16), Color::RED);
+ shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK);
+ }
+
+ // XXX crop is never latched without other geometry change (b/69315677)
+ Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply();
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ Transaction().setPosition(layer, 0, 0).apply();
+ {
+ SCOPED_TRACE("new crop applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(4, 4, 12, 12), Color::RED);
+ shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropBasic) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ const Rect crop(8, 8, 24, 24);
+
+ // same as in SetCropBasic
+ Transaction().setFinalCrop(layer, crop).apply();
+ auto shot = screenshot();
+ shot->expectColor(crop, Color::RED);
+ shot->expectBorder(crop, Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropEmpty) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // same as in SetCropEmpty
+ {
+ SCOPED_TRACE("empty rect");
+ Transaction().setFinalCrop(layer, Rect(8, 8, 8, 8)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ {
+ SCOPED_TRACE("negative rect");
+ Transaction().setFinalCrop(layer, Rect(8, 8, 0, 0)).apply();
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropOutOfBounds) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // same as in SetCropOutOfBounds
+ Transaction().setFinalCrop(layer, Rect(-128, -64, 128, 64)).apply();
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropWithTranslation) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // final crop is applied post-translation
+ Transaction().setPosition(layer, 16, 16).setFinalCrop(layer, Rect(8, 8, 24, 24)).apply();
+ auto shot = screenshot();
+ shot->expectColor(Rect(16, 16, 24, 24), Color::RED);
+ shot->expectBorder(Rect(16, 16, 24, 24), Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropWithScale) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // final crop is not affected by matrix
+ Transaction()
+ .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f)
+ .setFinalCrop(layer, Rect(8, 8, 24, 24))
+ .apply();
+ auto shot = screenshot();
+ shot->expectColor(Rect(8, 8, 24, 24), Color::RED);
+ shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK);
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropWithResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // same as in SetCropWithResize
+ Transaction().setFinalCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(8, 8, 24, 24), Color::RED);
+ shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("resize applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(8, 8, 16, 16), Color::RED);
+ shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropWithNextResize) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // same as in SetCropWithNextResize
+ Transaction()
+ .setFinalCrop(layer, Rect(8, 8, 24, 24))
+ .setGeometryAppliesWithResize(layer)
+ .apply();
+ {
+ SCOPED_TRACE("waiting for next resize");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setFinalCrop(layer, Rect(4, 4, 12, 12)).apply();
+ {
+ SCOPED_TRACE("pending final crop modified");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ Transaction().setSize(layer, 16, 16).apply();
+ {
+ SCOPED_TRACE("resize pending");
+ screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED);
+ }
+
+ // finally resize
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ {
+ SCOPED_TRACE("new final crop applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(4, 4, 12, 12), Color::RED);
+ shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK);
+ }
+}
+
+TEST_F(LayerTransactionTest, SetFinalCropWithNextResizeScaleToWindow) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32));
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+
+ // same as in SetCropWithNextResizeScaleToWindow
+ Transaction()
+ .setFinalCrop(layer, Rect(4, 4, 12, 12))
+ .setSize(layer, 16, 16)
+ .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW)
+ .setGeometryAppliesWithResize(layer)
+ .apply();
+ {
+ SCOPED_TRACE("new final crop pending");
+ auto shot = screenshot();
+ shot->expectColor(Rect(0, 0, 16, 16), Color::RED);
+ shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK);
+ }
+
+ // XXX final crop is never latched without other geometry change (b/69315677)
+ Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply();
+ ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED));
+ Transaction().setPosition(layer, 0, 0).apply();
+ {
+ SCOPED_TRACE("new final crop applied");
+ auto shot = screenshot();
+ shot->expectColor(Rect(4, 4, 12, 12), Color::RED);
+ shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK);
+ }
+}
class LayerUpdateTest : public ::testing::Test {
protected:
@@ -176,8 +1510,8 @@
mComposerClient = new SurfaceComposerClient;
ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
- sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
- ISurfaceComposer::eDisplayIdMain));
+ sp<IBinder> display(
+ SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
DisplayInfo info;
SurfaceComposerClient::getDisplayInfo(display, &info);
@@ -185,24 +1519,24 @@
ssize_t displayHeight = info.h;
// Background surface
- mBGSurfaceControl = mComposerClient->createSurface(
- String8("BG Test Surface"), displayWidth, displayHeight,
- PIXEL_FORMAT_RGBA_8888, 0);
+ mBGSurfaceControl =
+ mComposerClient->createSurface(String8("BG Test Surface"), displayWidth,
+ displayHeight, PIXEL_FORMAT_RGBA_8888, 0);
ASSERT_TRUE(mBGSurfaceControl != NULL);
ASSERT_TRUE(mBGSurfaceControl->isValid());
fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195);
// Foreground surface
- mFGSurfaceControl = mComposerClient->createSurface(
- String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
+ mFGSurfaceControl = mComposerClient->createSurface(String8("FG Test Surface"), 64, 64,
+ PIXEL_FORMAT_RGBA_8888, 0);
ASSERT_TRUE(mFGSurfaceControl != NULL);
ASSERT_TRUE(mFGSurfaceControl->isValid());
fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
// Synchronization surface
- mSyncSurfaceControl = mComposerClient->createSurface(
- String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0);
+ mSyncSurfaceControl = mComposerClient->createSurface(String8("Sync Test Surface"), 1, 1,
+ PIXEL_FORMAT_RGBA_8888, 0);
ASSERT_TRUE(mSyncSurfaceControl != NULL);
ASSERT_TRUE(mSyncSurfaceControl->isValid());
@@ -211,17 +1545,15 @@
asTransaction([&](Transaction& t) {
t.setDisplayLayerStack(display, 0);
- t.setLayer(mBGSurfaceControl, INT32_MAX-2)
- .show(mBGSurfaceControl);
+ t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl);
- t.setLayer(mFGSurfaceControl, INT32_MAX-1)
- .setPosition(mFGSurfaceControl, 64, 64)
- .show(mFGSurfaceControl);
+ t.setLayer(mFGSurfaceControl, INT32_MAX - 1)
+ .setPosition(mFGSurfaceControl, 64, 64)
+ .show(mFGSurfaceControl);
- t.setLayer(mSyncSurfaceControl, INT32_MAX-1)
- .setPosition(mSyncSurfaceControl, displayWidth-2,
- displayHeight-2)
- .show(mSyncSurfaceControl);
+ t.setLayer(mSyncSurfaceControl, INT32_MAX - 1)
+ .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2)
+ .show(mSyncSurfaceControl);
});
}
@@ -258,293 +1590,45 @@
sp<SurfaceControl> mSyncSurfaceControl;
};
-TEST_F(LayerUpdateTest, LayerMoveWorks) {
+TEST_F(LayerUpdateTest, RelativesAreNotDetached) {
sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before move");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(0, 12);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
- asTransaction([&](Transaction& t) {
- t.setPosition(mFGSurfaceControl, 128, 128);
- });
-
- {
- // This should reflect the new position, but not the new color.
- SCOPED_TRACE("after move, before redraw");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectFGColor(145, 145);
- }
-
- fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
+ sp<SurfaceControl> relative = mComposerClient->createSurface(String8("relativeTestSurface"), 10,
+ 10, PIXEL_FORMAT_RGBA_8888, 0);
+ fillSurfaceRGBA8(relative, 10, 10, 10);
waitForPostedBuffers();
- {
- // This should reflect the new position and the new color.
- SCOPED_TRACE("after redraw");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->checkPixel(145, 145, 63, 195, 63);
- }
-}
-TEST_F(LayerUpdateTest, LayerResizeWorks) {
- sp<ScreenCapture> sc;
+ Transaction{}
+ .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1)
+ .setPosition(relative, 64, 64)
+ .apply();
+
{
- SCOPED_TRACE("before resize");
+ // The relative should be on top of the FG control.
ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(0, 12);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
+ sc->checkPixel(64, 64, 10, 10, 10);
+ }
+ Transaction{}.detachChildren(mFGSurfaceControl).apply();
+
+ {
+ // Nothing should change at this point.
+ ScreenCapture::captureScreen(&sc);
+ sc->checkPixel(64, 64, 10, 10, 10);
}
- ALOGD("resizing");
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- });
- ALOGD("resized");
- {
- // This should not reflect the new size or color because SurfaceFlinger
- // has not yet received a buffer of the correct size.
- SCOPED_TRACE("after resize, before redraw");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(0, 12);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- ALOGD("drawing");
- fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
- waitForPostedBuffers();
- ALOGD("drawn");
- {
- // This should reflect the new size and the new color.
- SCOPED_TRACE("after redraw");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->checkPixel(75, 75, 63, 195, 63);
- sc->checkPixel(145, 145, 63, 195, 63);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerCropWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before crop");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- Rect cropRect(16, 16, 32, 32);
- t.setCrop(mFGSurfaceControl, cropRect);
- });
- {
- // This should crop the foreground surface.
- SCOPED_TRACE("after crop");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectFGColor(95, 80);
- sc->expectFGColor(80, 95);
- sc->expectBGColor(96, 96);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerFinalCropWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before crop");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
- asTransaction([&](Transaction& t) {
- Rect cropRect(16, 16, 32, 32);
- t.setFinalCrop(mFGSurfaceControl, cropRect);
- });
- {
- // This should crop the foreground surface.
- SCOPED_TRACE("after crop");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectBGColor(95, 80);
- sc->expectBGColor(80, 95);
- sc->expectBGColor(96, 96);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerSetLayerWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setLayer");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.setLayer(mFGSurfaceControl, INT_MAX - 3);
- });
+ Transaction{}.hide(relative).apply();
{
- // This should hide the foreground surface beneath the background.
- SCOPED_TRACE("after setLayer");
+ // Ensure that the relative was actually hidden, rather than
+ // being left in the detached but visible state.
ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerShowHideWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before hide");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.hide(mFGSurfaceControl);
- });
-
- {
- // This should hide the foreground surface.
- SCOPED_TRACE("after hide, before show");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.show(mFGSurfaceControl);
- });
-
- {
- // This should show the foreground surface.
- SCOPED_TRACE("after show");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerSetAlphaWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setAlpha");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.setAlpha(mFGSurfaceControl, 0.75f);
- });
-
- {
- // This should set foreground to be 75% opaque.
- SCOPED_TRACE("after setAlpha");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->checkPixel(75, 75, 162, 63, 96);
- sc->expectBGColor(145, 145);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setLayerStack");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.setLayerStack(mFGSurfaceControl, 1);
- });
- {
- // This should hide the foreground surface since it goes to a different
- // layer stack.
- SCOPED_TRACE("after setLayerStack");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerSetFlagsWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setFlags");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.setFlags(mFGSurfaceControl,
- layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
- });
- {
- // This should hide the foreground surface
- SCOPED_TRACE("after setFlags");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectBGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-}
-
-TEST_F(LayerUpdateTest, LayerSetMatrixWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setMatrix");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(91, 96);
- sc->expectFGColor(96, 101);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.setMatrix(mFGSurfaceControl,
- M_SQRT1_2, M_SQRT1_2,
- -M_SQRT1_2, M_SQRT1_2);
- });
- {
- SCOPED_TRACE("after setMatrix");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(91, 96);
- sc->expectBGColor(96, 91);
- sc->expectBGColor(145, 145);
+ sc->expectFGColor(64, 64);
}
}
class GeometryLatchingTest : public LayerUpdateTest {
protected:
- void EXPECT_INITIAL_STATE(const char * trace) {
+ void EXPECT_INITIAL_STATE(const char* trace) {
SCOPED_TRACE(trace);
ScreenCapture::captureScreen(&sc);
// We find the leading edge of the FG surface.
@@ -552,9 +1636,7 @@
sc->expectBGColor(128, 128);
}
- void lockAndFillFGBuffer() {
- fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false);
- }
+ void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); }
void unlockFGBuffer() {
sp<Surface> s = mFGSurfaceControl->getSurface();
@@ -579,53 +1661,6 @@
sp<ScreenCapture> sc;
};
-TEST_F(GeometryLatchingTest, SurfacePositionLatching) {
- EXPECT_INITIAL_STATE("before anything");
-
- // By default position can be updated even while
- // a resize is pending.
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 32, 32);
- t.setPosition(mFGSurfaceControl, 100, 100);
- });
-
- {
- SCOPED_TRACE("After moving surface");
- ScreenCapture::captureScreen(&sc);
- // If we moved, the FG Surface should cover up what was previously BG
- // however if we didn't move the FG wouldn't be large enough now.
- sc->expectFGColor(163, 163);
- }
-
- restoreInitialState();
-
- // Now we repeat with setGeometryAppliesWithResize
- // and verify the position DOESN'T latch.
- asTransaction([&](Transaction& t) {
- t.setGeometryAppliesWithResize(mFGSurfaceControl);
- t.setSize(mFGSurfaceControl, 32, 32);
- t.setPosition(mFGSurfaceControl, 100, 100);
- });
-
- {
- SCOPED_TRACE("While resize is pending");
- ScreenCapture::captureScreen(&sc);
- // This time we shouldn't have moved, so the BG color
- // should still be visible.
- sc->expectBGColor(128, 128);
- }
-
- completeFGResize();
-
- {
- SCOPED_TRACE("After the resize");
- ScreenCapture::captureScreen(&sc);
- // But after the resize completes, we should move
- // and the FG should be visible here.
- sc->expectFGColor(128, 128);
- }
-}
-
class CropLatchingTest : public GeometryLatchingTest {
protected:
void EXPECT_CROPPED_STATE(const char* trace) {
@@ -647,56 +1682,6 @@
}
};
-TEST_F(CropLatchingTest, CropLatching) {
- EXPECT_INITIAL_STATE("before anything");
- // Normally the crop applies immediately even while a resize is pending.
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- t.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
- });
-
- EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
-
- restoreInitialState();
-
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- t.setGeometryAppliesWithResize(mFGSurfaceControl);
- t.setCrop(mFGSurfaceControl, Rect(0, 0, 63, 63));
- });
-
- EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
-
- completeFGResize();
-
- EXPECT_CROPPED_STATE("after the resize finishes");
-}
-
-TEST_F(CropLatchingTest, FinalCropLatching) {
- EXPECT_INITIAL_STATE("before anything");
- // Normally the crop applies immediately even while a resize is pending.
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
- });
-
- EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
-
- restoreInitialState();
-
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- t.setGeometryAppliesWithResize(mFGSurfaceControl);
- t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
- });
-
- EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
-
- completeFGResize();
-
- EXPECT_CROPPED_STATE("after the resize finishes");
-}
-
// In this test we ensure that setGeometryAppliesWithResize actually demands
// a buffer of the new size, and not just any size.
TEST_F(CropLatchingTest, FinalCropLatchingBufferOldSize) {
@@ -734,30 +1719,6 @@
EXPECT_CROPPED_STATE("after the resize finishes");
}
-TEST_F(CropLatchingTest, FinalCropLatchingRegressionForb37531386) {
- EXPECT_INITIAL_STATE("before anything");
- // In this scenario, we attempt to set the final crop a second time while the resize
- // is still pending, and ensure we are successful. Success meaning the second crop
- // is the one which eventually latches and not the first.
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 128);
- t.setGeometryAppliesWithResize(mFGSurfaceControl);
- t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127));
- });
-
- EXPECT_INITIAL_STATE("after setting crops with geometryAppliesWithResize");
-
- asTransaction([&](Transaction& t) {
- t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1));
- });
-
- EXPECT_INITIAL_STATE("after setting another crop");
-
- completeFGResize();
-
- EXPECT_RESIZE_STATE("after the resize finishes");
-}
-
TEST_F(LayerUpdateTest, DeferredTransactionTest) {
sp<ScreenCapture> sc;
{
@@ -772,13 +1733,13 @@
asTransaction([&](Transaction& t) {
t.setAlpha(mFGSurfaceControl, 0.75);
t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(),
- mSyncSurfaceControl->getSurface()->getNextFrameNumber());
+ mSyncSurfaceControl->getSurface()->getNextFrameNumber());
});
asTransaction([&](Transaction& t) {
- t.setPosition(mFGSurfaceControl, 128,128);
+ t.setPosition(mFGSurfaceControl, 128, 128);
t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(),
- mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
+ mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
});
{
@@ -800,9 +1761,7 @@
}
// should show up immediately since it's not deferred
- asTransaction([&](Transaction& t) {
- t.setAlpha(mFGSurfaceControl, 1.0);
- });
+ asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); });
// trigger the second deferred transaction
fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
@@ -815,64 +1774,18 @@
}
}
-TEST_F(LayerUpdateTest, LayerSetRelativeLayerWorks) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before adding relative surface");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(24, 24);
- sc->expectFGColor(75, 75);
- sc->expectBGColor(145, 145);
- }
-
- auto relativeSurfaceControl = mComposerClient->createSurface(
- String8("Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
- fillSurfaceRGBA8(relativeSurfaceControl, 255, 177, 177);
- waitForPostedBuffers();
-
- // Now we stack the surface above the foreground surface and make sure it is visible.
- asTransaction([&](Transaction& t) {
- t.setPosition(relativeSurfaceControl, 64, 64);
- t.show(relativeSurfaceControl);
- t.setRelativeLayer(relativeSurfaceControl, mFGSurfaceControl->getHandle(), 1);
- });
-
- {
- SCOPED_TRACE("after adding relative surface");
- ScreenCapture::captureScreen(&sc);
- // our relative surface should be visible now.
- sc->checkPixel(75, 75, 255, 177, 177);
- }
-
- // A call to setLayer will override a call to setRelativeLayer
- asTransaction([&](Transaction& t) {
- t.setLayer(relativeSurfaceControl, 0);
- });
-
- {
- SCOPED_TRACE("after set layer");
- ScreenCapture::captureScreen(&sc);
- // now the FG surface should be visible again.
- sc->expectFGColor(75, 75);
- }
-}
-
TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) {
sp<ScreenCapture> sc;
sp<SurfaceControl> childNoBuffer =
- mComposerClient->createSurface(String8("Bufferless child"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
- sp<SurfaceControl> childBuffer = mComposerClient->createSurface(
- String8("Buffered child"), 20, 20,
- PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get());
+ mComposerClient->createSurface(String8("Bufferless child"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> childBuffer =
+ mComposerClient->createSurface(String8("Buffered child"), 20, 20,
+ PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get());
fillSurfaceRGBA8(childBuffer, 200, 200, 200);
- SurfaceComposerClient::Transaction{}
- .show(childNoBuffer)
- .show(childBuffer)
- .apply(true);
+ SurfaceComposerClient::Transaction{}.show(childNoBuffer).show(childBuffer).apply(true);
{
ScreenCapture::captureScreen(&sc);
@@ -880,9 +1793,7 @@
sc->expectFGColor(74, 74);
}
- SurfaceComposerClient::Transaction{}
- .setSize(childNoBuffer, 20, 20)
- .apply(true);
+ SurfaceComposerClient::Transaction{}.setSize(childNoBuffer, 20, 20).apply(true);
{
ScreenCapture::captureScreen(&sc);
@@ -919,10 +1830,8 @@
protected:
void SetUp() override {
LayerUpdateTest::SetUp();
- mChild = mComposerClient->createSurface(
- String8("Child surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ mChild = mComposerClient->createSurface(String8("Child surface"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get());
fillSurfaceRGBA8(mChild, 200, 200, 200);
{
@@ -957,9 +1866,7 @@
mCapture->expectFGColor(84, 84);
}
- asTransaction([&](Transaction& t) {
- t.setPosition(mFGSurfaceControl, 0, 0);
- });
+ asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1023,9 +1930,7 @@
}
TEST_F(ChildLayerTest, ChildLayerScaling) {
- asTransaction([&](Transaction& t) {
- t.setPosition(mFGSurfaceControl, 0, 0);
- });
+ asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); });
// Find the boundary between the parent and child
{
@@ -1034,9 +1939,7 @@
mCapture->expectFGColor(10, 10);
}
- asTransaction([&](Transaction& t) {
- t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0);
- });
+ asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); });
// The boundary should be twice as far from the origin now.
// The pixels from the last test should all be child now
@@ -1067,9 +1970,7 @@
mCapture->checkPixel(0, 0, 0, 254, 0);
}
- asTransaction([&](Transaction& t) {
- t.setAlpha(mChild, 0.5);
- });
+ asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1077,9 +1978,7 @@
mCapture->checkPixel(0, 0, 127, 127, 0);
}
- asTransaction([&](Transaction& t) {
- t.setAlpha(mFGSurfaceControl, 0.5);
- });
+ asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1138,13 +2037,9 @@
mCapture->expectFGColor(84, 84);
}
- asTransaction([&](Transaction& t) {
- t.detachChildren(mFGSurfaceControl);
- });
+ asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); });
- asTransaction([&](Transaction& t) {
- t.hide(mChild);
- });
+ asTransaction([&](Transaction& t) { t.hide(mChild); });
// Since the child has the same client as the parent, it will not get
// detached and will be hidden.
@@ -1158,9 +2053,9 @@
TEST_F(ChildLayerTest, DetachChildrenDifferentClient) {
sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient;
- sp<SurfaceControl> mChildNewClient = mNewComposerClient->createSurface(
- String8("New Child Test Surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> mChildNewClient =
+ mNewComposerClient->createSurface(String8("New Child Test Surface"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get());
ASSERT_TRUE(mChildNewClient != NULL);
ASSERT_TRUE(mChildNewClient->isValid());
@@ -1184,13 +2079,9 @@
mCapture->expectFGColor(84, 84);
}
- asTransaction([&](Transaction& t) {
- t.detachChildren(mFGSurfaceControl);
- });
+ asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); });
- asTransaction([&](Transaction& t) {
- t.hide(mChildNewClient);
- });
+ asTransaction([&](Transaction& t) { t.hide(mChildNewClient); });
// Nothing should have changed.
{
@@ -1250,9 +2141,7 @@
}
// We set things up as in b/37673612 so that there is a mismatch between the buffer size and
// the WM specified state size.
- asTransaction([&](Transaction& t) {
- t.setSize(mFGSurfaceControl, 128, 64);
- });
+ asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); });
sp<Surface> s = mFGSurfaceControl->getSurface();
auto anw = static_cast<ANativeWindow*>(s.get());
native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90);
@@ -1281,7 +2170,7 @@
// Show the child layer in a deferred transaction
asTransaction([&](Transaction& t) {
t.deferTransactionUntil(mChild, mFGSurfaceControl->getHandle(),
- mFGSurfaceControl->getSurface()->getNextFrameNumber());
+ mFGSurfaceControl->getSurface()->getNextFrameNumber());
t.show(mChild);
});
@@ -1317,9 +2206,7 @@
mCapture->expectFGColor(84, 84);
}
- asTransaction([&](Transaction& t) {
- t.reparent(mChild, mBGSurfaceControl->getHandle());
- });
+ asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1349,9 +2236,7 @@
// And 10 more pixels we should be back to the foreground surface
mCapture->expectFGColor(84, 84);
}
- asTransaction([&](Transaction& t) {
- t.reparent(mChild, nullptr);
- });
+ asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); });
{
ScreenCapture::captureScreen(&mCapture);
// Nothing should have changed.
@@ -1362,8 +2247,8 @@
}
TEST_F(ChildLayerTest, ReparentFromNoParent) {
- sp<SurfaceControl> newSurface = mComposerClient->createSurface(
- String8("New Surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, 0);
+ sp<SurfaceControl> newSurface = mComposerClient->createSurface(String8("New Surface"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0);
ASSERT_TRUE(newSurface != NULL);
ASSERT_TRUE(newSurface->isValid());
@@ -1372,7 +2257,7 @@
t.hide(mChild);
t.show(newSurface);
t.setPosition(newSurface, 10, 10);
- t.setLayer(newSurface, INT32_MAX-2);
+ t.setLayer(newSurface, INT32_MAX - 2);
t.setPosition(mFGSurfaceControl, 64, 64);
});
@@ -1384,9 +2269,7 @@
mCapture->checkPixel(10, 10, 63, 195, 63);
}
- asTransaction([&](Transaction& t) {
- t.reparent(newSurface, mFGSurfaceControl->getHandle());
- });
+ asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); });
{
ScreenCapture::captureScreen(&mCapture);
@@ -1399,10 +2282,9 @@
}
TEST_F(ChildLayerTest, NestedChildren) {
- sp<SurfaceControl> grandchild = mComposerClient->createSurface(
- String8("Grandchild surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mChild.get());
+ sp<SurfaceControl> grandchild =
+ mComposerClient->createSurface(String8("Grandchild surface"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0, mChild.get());
fillSurfaceRGBA8(grandchild, 50, 50, 50);
{
@@ -1413,99 +2295,24 @@
}
}
-class LayerColorTest : public LayerUpdateTest {
- protected:
- void SetUp() override {
- LayerUpdateTest::SetUp();
+TEST_F(ChildLayerTest, ChildLayerRelativeLayer) {
+ sp<SurfaceControl> relative = mComposerClient->createSurface(String8("Relative surface"), 128,
+ 128, PIXEL_FORMAT_RGBA_8888, 0);
+ fillSurfaceRGBA8(relative, 255, 255, 255);
- mLayerColorControl = mComposerClient->createSurface(
- String8("Layer color surface"),
- 128, 128, PIXEL_FORMAT_RGBA_8888,
- ISurfaceComposerClient::eFXSurfaceColor);
+ Transaction t;
+ t.setLayer(relative, INT32_MAX)
+ .setRelativeLayer(mChild, relative->getHandle(), 1)
+ .setPosition(mFGSurfaceControl, 0, 0)
+ .apply(true);
- ASSERT_TRUE(mLayerColorControl != NULL);
- ASSERT_TRUE(mLayerColorControl->isValid());
-
- asTransaction([&](Transaction& t) {
- t.setLayer(mLayerColorControl, INT32_MAX-1);
- t.setPosition(mLayerColorControl, 140, 140);
- t.hide(mLayerColorControl);
- t.hide(mFGSurfaceControl);
- });
- }
-
- void TearDown() override {
- LayerUpdateTest::TearDown();
- mLayerColorControl = 0;
- }
-
- sp<SurfaceControl> mLayerColorControl;
-};
-
-TEST_F(LayerColorTest, ColorLayerNoAlpha) {
- sp<ScreenCapture> sc;
-
+ // We expect that the child should have been elevated above our
+ // INT_MAX layer even though it's not a child of it.
{
- SCOPED_TRACE("before setColor");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
- t.setColor(mLayerColorControl, color);
- t.show(mLayerColorControl);
- });
-
- {
- // There should now be a color
- SCOPED_TRACE("after setColor");
-
- ScreenCapture::captureScreen(&sc);
- sc->checkPixel(145, 145, 43, 207, 131);
- }
-}
-
-TEST_F(LayerColorTest, ColorLayerWithAlpha) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setColor");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- half3 color(43.0f/255.0f, 207.0f/255.0f, 131.0f/255.0f);
- t.setColor(mLayerColorControl, color);
- t.setAlpha(mLayerColorControl, .75f);
- t.show(mLayerColorControl);
- });
-
- {
- // There should now be a color with .75 alpha
- SCOPED_TRACE("after setColor");
- ScreenCapture::captureScreen(&sc);
- sc->checkPixel(145, 145, 48, 171, 147);
- }
-}
-
-TEST_F(LayerColorTest, ColorLayerWithNoColor) {
- sp<ScreenCapture> sc;
- {
- SCOPED_TRACE("before setColor");
- ScreenCapture::captureScreen(&sc);
- sc->expectBGColor(145, 145);
- }
-
- asTransaction([&](Transaction& t) {
- t.show(mLayerColorControl);
- });
-
- {
- // There should now be set to 0,0,0 (black) as default.
- SCOPED_TRACE("after setColor");
- ScreenCapture::captureScreen(&sc);
- sc->checkPixel(145, 145, 0, 0, 0);
+ ScreenCapture::captureScreen(&mCapture);
+ mCapture->expectChildColor(0, 0);
+ mCapture->expectChildColor(9, 9);
+ mCapture->checkPixel(10, 10, 255, 255, 255);
}
}
@@ -1525,15 +2332,12 @@
TEST_F(ScreenCaptureTest, CaptureLayerWithChild) {
auto fgHandle = mFGSurfaceControl->getHandle();
- sp<SurfaceControl> child = mComposerClient->createSurface(
- String8("Child surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
fillSurfaceRGBA8(child, 200, 200, 200);
- SurfaceComposerClient::Transaction()
- .show(child)
- .apply(true);
+ SurfaceComposerClient::Transaction().show(child).apply(true);
// Captures mFGSurfaceControl layer and its child.
CaptureLayer::captureScreen(&mCapture, fgHandle);
@@ -1544,22 +2348,21 @@
TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) {
auto fgHandle = mFGSurfaceControl->getHandle();
- sp<SurfaceControl> child = mComposerClient->createSurface(
- String8("Child surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
fillSurfaceRGBA8(child, 200, 200, 200);
- sp<SurfaceControl> grandchild = mComposerClient->createSurface(
- String8("Grandchild surface"), 5, 5,
- PIXEL_FORMAT_RGBA_8888, 0, child.get());
+ sp<SurfaceControl> grandchild =
+ mComposerClient->createSurface(String8("Grandchild surface"), 5, 5,
+ PIXEL_FORMAT_RGBA_8888, 0, child.get());
fillSurfaceRGBA8(grandchild, 50, 50, 50);
SurfaceComposerClient::Transaction()
- .show(child)
- .setPosition(grandchild, 5, 5)
- .show(grandchild)
- .apply(true);
+ .show(child)
+ .setPosition(grandchild, 5, 5)
+ .show(grandchild)
+ .apply(true);
// Captures mFGSurfaceControl, its child, and the grandchild.
CaptureLayer::captureScreen(&mCapture, fgHandle);
@@ -1569,17 +2372,13 @@
}
TEST_F(ScreenCaptureTest, CaptureChildOnly) {
- sp<SurfaceControl> child = mComposerClient->createSurface(
- String8("Child surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
fillSurfaceRGBA8(child, 200, 200, 200);
auto childHandle = child->getHandle();
- SurfaceComposerClient::Transaction()
- .setPosition(child, 5, 5)
- .show(child)
- .apply(true);
+ SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true);
// Captures only the child layer, and not the parent.
CaptureLayer::captureScreen(&mCapture, childHandle);
@@ -1588,23 +2387,22 @@
}
TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) {
- sp<SurfaceControl> child = mComposerClient->createSurface(
- String8("Child surface"),
- 10, 10, PIXEL_FORMAT_RGBA_8888,
- 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
fillSurfaceRGBA8(child, 200, 200, 200);
auto childHandle = child->getHandle();
- sp<SurfaceControl> grandchild = mComposerClient->createSurface(
- String8("Grandchild surface"), 5, 5,
- PIXEL_FORMAT_RGBA_8888, 0, child.get());
+ sp<SurfaceControl> grandchild =
+ mComposerClient->createSurface(String8("Grandchild surface"), 5, 5,
+ PIXEL_FORMAT_RGBA_8888, 0, child.get());
fillSurfaceRGBA8(grandchild, 50, 50, 50);
SurfaceComposerClient::Transaction()
- .show(child)
- .setPosition(grandchild, 5, 5)
- .show(grandchild)
- .apply(true);
+ .show(child)
+ .setPosition(grandchild, 5, 5)
+ .show(grandchild)
+ .apply(true);
auto grandchildHandle = grandchild->getHandle();
@@ -1614,4 +2412,4 @@
mCapture->checkPixel(4, 4, 50, 50, 50);
}
-}
+} // namespace android
diff --git a/services/vr/bufferhubd/bufferhubd.rc b/services/vr/bufferhubd/bufferhubd.rc
index 46fe5f9..c470de5 100644
--- a/services/vr/bufferhubd/bufferhubd.rc
+++ b/services/vr/bufferhubd/bufferhubd.rc
@@ -2,5 +2,4 @@
class core
user system
group system
- writepid /dev/cpuset/tasks
socket pdx/system/buffer_hub/client stream 0660 system system u:object_r:pdx_bufferhub_client_endpoint_socket:s0
diff --git a/services/vr/performanced/performanced.rc b/services/vr/performanced/performanced.rc
index 2605a47..af9760e 100644
--- a/services/vr/performanced/performanced.rc
+++ b/services/vr/performanced/performanced.rc
@@ -2,5 +2,4 @@
class core
user root
group system readproc
- writepid /dev/cpuset/tasks
socket pdx/system/performance/client stream 0666 system system u:object_r:pdx_performance_client_endpoint_socket:s0