Merge "VR services: don't writepid to /dev/cpuset/tasks"
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/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 201b5a3..364ead0 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -81,6 +81,7 @@
#define PROFILE_DATA_DIR_CUR "/data/misc/profiles/cur"
#define PROFILE_DATA_DIR_REF "/data/misc/profiles/ref"
#define WLUTIL "/vendor/xbin/wlutil"
+#define WMTRACE_DATA_DIR "/data/misc/wmtrace"
// TODO(narayan): Since this information has to be kept in sync
// with tombstoned, we should just put it in a common header.
@@ -1210,6 +1211,11 @@
DumpFile("BINDER STATS", "/sys/kernel/debug/binder/stats");
DumpFile("BINDER STATE", "/sys/kernel/debug/binder/state");
+ /* Add window and surface trace files. */
+ if (!PropertiesHelper::IsUserBuild()) {
+ ds.AddDir(WMTRACE_DATA_DIR, false);
+ }
+
ds.DumpstateBoard();
/* Migrate the ril_dumpstate to a device specific dumpstate? */
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index e0d23da..0c2d341 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -889,6 +889,7 @@
CHECK(EndsWith(path, "/"));
path = path + "oat";
if (access(path.c_str(), F_OK) == 0) {
+ LOG(INFO) << "Skipping A/B OTA preopt of already preopted package " << apk_path;
return true;
}
}
@@ -900,7 +901,7 @@
// this tool will wipe the OTA artifact cache and try again (for robustness after
// a failed OTA with remaining cache artifacts).
if (access(apk_path, F_OK) != 0) {
- LOG(WARNING) << "Skipping preopt of non-existing package " << apk_path;
+ LOG(WARNING) << "Skipping A/B OTA preopt of non-existing package " << apk_path;
return true;
}
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/libbufferhubqueue/tests/buffer_hub_queue-test.cpp b/libs/vr/libbufferhubqueue/tests/buffer_hub_queue-test.cpp
index f67ef37..3efa723 100644
--- a/libs/vr/libbufferhubqueue/tests/buffer_hub_queue-test.cpp
+++ b/libs/vr/libbufferhubqueue/tests/buffer_hub_queue-test.cpp
@@ -25,6 +25,8 @@
constexpr uint32_t kBufferLayerCount = 1;
constexpr uint32_t kBufferFormat = HAL_PIXEL_FORMAT_BLOB;
constexpr uint64_t kBufferUsage = GRALLOC_USAGE_SW_READ_RARELY;
+constexpr int kTimeoutMs = 100;
+constexpr int kNoTimeout = 0;
class BufferHubQueueTest : public ::testing::Test {
public:
@@ -84,41 +86,49 @@
};
TEST_F(BufferHubQueueTest, TestDequeue) {
- const size_t nb_dequeue_times = 16;
+ const int64_t nb_dequeue_times = 16;
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<size_t>().Build(),
- UsagePolicy{}));
+ ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
// Allocate only one buffer.
AllocateBuffer();
// But dequeue multiple times.
- for (size_t i = 0; i < nb_dequeue_times; i++) {
+ for (int64_t i = 0; i < nb_dequeue_times; i++) {
size_t slot;
LocalHandle fence;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
- ASSERT_TRUE(p1_status.ok());
+ DvrNativeBufferMetadata mi, mo;
+
+ // Producer gains a buffer.
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
- ASSERT_NE(nullptr, p1);
- size_t mi = i;
- ASSERT_EQ(p1->Post(LocalHandle(), &mi, sizeof(mi)), 0);
- size_t mo;
- auto c1_status = consumer_queue_->Dequeue(100, &slot, &mo, &fence);
- ASSERT_TRUE(c1_status.ok());
+ ASSERT_NE(p1, nullptr);
+
+ // Producer posts the buffer.
+ mi.index = i;
+ EXPECT_EQ(p1->PostAsync(&mi, LocalHandle()), 0);
+
+ // Consumer acquires a buffer.
+ auto c1_status = consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(c1_status.ok());
auto c1 = c1_status.take();
- ASSERT_NE(nullptr, c1);
- ASSERT_EQ(mi, mo);
- c1->Release(LocalHandle());
+ ASSERT_NE(c1, nullptr);
+ EXPECT_EQ(mi.index, i);
+ EXPECT_EQ(mo.index, i);
+
+ // Consumer releases the buffer.
+ EXPECT_EQ(c1->ReleaseAsync(&mi, LocalHandle()), 0);
}
}
TEST_F(BufferHubQueueTest, TestProducerConsumer) {
const size_t kBufferCount = 16;
size_t slot;
- uint64_t seq;
+ DvrNativeBufferMetadata mi, mo;
+ LocalHandle fence;
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<uint64_t>().Build(),
- UsagePolicy{}));
+ ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
for (size_t i = 0; i < kBufferCount; i++) {
AllocateBuffer();
@@ -133,8 +143,7 @@
ASSERT_EQ(consumer_queue_->capacity(), i);
// Dequeue returns timeout since no buffer is ready to consumer, but
// this implicitly triggers buffer import and bump up |capacity|.
- LocalHandle fence;
- auto status = consumer_queue_->Dequeue(100, &slot, &seq, &fence);
+ auto status = consumer_queue_->Dequeue(kNoTimeout, &slot, &mo, &fence);
ASSERT_FALSE(status.ok());
ASSERT_EQ(ETIMEDOUT, status.error());
ASSERT_EQ(consumer_queue_->capacity(), i + 1);
@@ -144,37 +153,37 @@
LocalHandle post_fence(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK));
for (size_t i = 0; i < kBufferCount; i++) {
- LocalHandle fence;
-
// First time there is no buffer available to dequeue.
- auto consumer_status = consumer_queue_->Dequeue(100, &slot, &seq, &fence);
+ auto consumer_status =
+ consumer_queue_->Dequeue(kNoTimeout, &slot, &mo, &fence);
ASSERT_FALSE(consumer_status.ok());
- ASSERT_EQ(ETIMEDOUT, consumer_status.error());
+ ASSERT_EQ(consumer_status.error(), ETIMEDOUT);
// Make sure Producer buffer is POSTED so that it's ready to Accquire
// in the consumer's Dequeue() function.
- auto producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ auto producer_status =
+ producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
auto producer = producer_status.take();
ASSERT_NE(nullptr, producer);
- uint64_t seq_in = static_cast<uint64_t>(i);
- ASSERT_EQ(producer->Post(post_fence, &seq_in, sizeof(seq_in)), 0);
+ mi.index = static_cast<int64_t>(i);
+ ASSERT_EQ(producer->PostAsync(&mi, post_fence), 0);
// Second time the just the POSTED buffer should be dequeued.
- uint64_t seq_out = 0;
- consumer_status = consumer_queue_->Dequeue(100, &slot, &seq_out, &fence);
+ consumer_status = consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(consumer_status.ok());
EXPECT_TRUE(fence.IsValid());
auto consumer = consumer_status.take();
ASSERT_NE(nullptr, consumer);
- ASSERT_EQ(seq_in, seq_out);
+ ASSERT_EQ(mi.index, mo.index);
}
}
TEST_F(BufferHubQueueTest, TestRemoveBuffer) {
ASSERT_TRUE(CreateProducerQueue(config_builder_.Build(), UsagePolicy{}));
+ DvrNativeBufferMetadata mo;
// Allocate buffers.
const size_t kBufferCount = 4u;
@@ -203,7 +212,7 @@
for (size_t i = 0; i < kBufferCount; i++) {
Entry* entry = &buffers[i];
auto producer_status = producer_queue_->Dequeue(
- /*timeout_ms=*/100, &entry->slot, &entry->fence);
+ kTimeoutMs, &entry->slot, &mo, &entry->fence);
ASSERT_TRUE(producer_status.ok());
entry->buffer = producer_status.take();
ASSERT_NE(nullptr, entry->buffer);
@@ -223,7 +232,7 @@
buffers[0].buffer = nullptr;
// Now the consumer queue should know it's gone.
- EXPECT_FALSE(WaitAndHandleOnce(consumer_queue_.get(), /*timeout_ms=*/100));
+ EXPECT_FALSE(WaitAndHandleOnce(consumer_queue_.get(), kTimeoutMs));
ASSERT_EQ(kBufferCount - 1, consumer_queue_->capacity());
// Allocate a new buffer. This should take the first empty slot.
@@ -292,126 +301,154 @@
ASSERT_NE(nullptr, silent_queue);
// Check that silent queue doesn't import buffers on creation.
- EXPECT_EQ(0, silent_queue->capacity());
+ EXPECT_EQ(silent_queue->capacity(), 0U);
// Dequeue and post a buffer.
size_t slot;
LocalHandle fence;
+ DvrNativeBufferMetadata mi, mo;
auto producer_status =
- producer_queue_->Dequeue(/*timeout_ms=*/100, &slot, &fence);
- ASSERT_TRUE(producer_status.ok());
+ producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(producer_status.ok());
auto producer_buffer = producer_status.take();
- ASSERT_NE(nullptr, producer_buffer);
- ASSERT_EQ(0, producer_buffer->Post<void>({}));
+ ASSERT_NE(producer_buffer, nullptr);
+ EXPECT_EQ(producer_buffer->PostAsync(&mi, {}), 0);
// After post, check the number of remaining available buffers.
- EXPECT_EQ(kBufferCount - 1, producer_queue_->count());
+ EXPECT_EQ(producer_queue_->count(), kBufferCount - 1);
// Currently we expect no buffer to be available prior to calling
// WaitForBuffers/HandleQueueEvents.
// TODO(eieio): Note this behavior may change in the future.
- EXPECT_EQ(0u, silent_queue->count());
+ EXPECT_EQ(silent_queue->count(), 0U);
EXPECT_FALSE(silent_queue->HandleQueueEvents());
- EXPECT_EQ(0u, silent_queue->count());
+ EXPECT_EQ(silent_queue->count(), 0U);
// Build a new consumer queue to test multi-consumer queue features.
consumer_queue_ = silent_queue->CreateConsumerQueue();
- ASSERT_NE(nullptr, consumer_queue_);
+ ASSERT_NE(consumer_queue_, nullptr);
// Check that buffers are correctly imported on construction.
- EXPECT_EQ(kBufferCount, consumer_queue_->capacity());
- EXPECT_EQ(1u, consumer_queue_->count());
+ EXPECT_EQ(consumer_queue_->capacity(), kBufferCount);
+ EXPECT_EQ(consumer_queue_->count(), 1U);
// Reclaim released/ignored buffers.
- ASSERT_EQ(kBufferCount - 1, producer_queue_->count());
+ EXPECT_EQ(producer_queue_->count(), kBufferCount - 1);
usleep(10000);
- WaitAndHandleOnce(producer_queue_.get(), /*timeout_ms=*/100);
- ASSERT_EQ(kBufferCount - 1, producer_queue_->count());
+ WaitAndHandleOnce(producer_queue_.get(), kTimeoutMs);
+ EXPECT_EQ(producer_queue_->count(), kBufferCount - 1);
// Post another buffer.
- producer_status = producer_queue_->Dequeue(/*timeout_ms=*/100, &slot, &fence);
- ASSERT_TRUE(producer_status.ok());
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(producer_status.ok());
producer_buffer = producer_status.take();
- ASSERT_NE(nullptr, producer_buffer);
- ASSERT_EQ(0, producer_buffer->Post<void>({}));
+ ASSERT_NE(producer_buffer, nullptr);
+ EXPECT_EQ(producer_buffer->PostAsync(&mi, {}), 0);
// Verify that the consumer queue receives it.
size_t consumer_queue_count = consumer_queue_->count();
- WaitAndHandleOnce(consumer_queue_.get(), /*timeout_ms=*/100);
- EXPECT_LT(consumer_queue_count, consumer_queue_->count());
+ WaitAndHandleOnce(consumer_queue_.get(), kTimeoutMs);
+ EXPECT_GT(consumer_queue_->count(), consumer_queue_count);
// Save the current consumer queue buffer count to compare after the dequeue.
consumer_queue_count = consumer_queue_->count();
// Dequeue and acquire/release (discard) buffers on the consumer end.
auto consumer_status =
- consumer_queue_->Dequeue(/*timeout_ms=*/100, &slot, &fence);
- ASSERT_TRUE(consumer_status.ok());
+ consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(consumer_status.ok());
auto consumer_buffer = consumer_status.take();
- ASSERT_NE(nullptr, consumer_buffer);
+ ASSERT_NE(consumer_buffer, nullptr);
consumer_buffer->Discard();
// Buffer should be returned to the producer queue without being handled by
// the silent consumer queue.
- EXPECT_GT(consumer_queue_count, consumer_queue_->count());
- EXPECT_EQ(kBufferCount - 2, producer_queue_->count());
- EXPECT_TRUE(producer_queue_->HandleQueueEvents());
- EXPECT_EQ(kBufferCount - 1, producer_queue_->count());
+ EXPECT_LT(consumer_queue_->count(), consumer_queue_count);
+ EXPECT_EQ(producer_queue_->count(), kBufferCount - 2);
+
+ WaitAndHandleOnce(producer_queue_.get(), kTimeoutMs);
+ EXPECT_EQ(producer_queue_->count(), kBufferCount - 1);
}
-struct TestMetadata {
+struct TestUserMetadata {
char a;
int32_t b;
int64_t c;
};
-TEST_F(BufferHubQueueTest, TestMetadata) {
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<TestMetadata>().Build(),
- UsagePolicy{}));
+constexpr uint64_t kUserMetadataSize =
+ static_cast<uint64_t>(sizeof(TestUserMetadata));
+
+TEST_F(BufferHubQueueTest, TestUserMetadata) {
+ ASSERT_TRUE(CreateQueues(
+ config_builder_.SetMetadata<TestUserMetadata>().Build(), UsagePolicy{}));
AllocateBuffer();
- std::vector<TestMetadata> ms = {
+ std::vector<TestUserMetadata> user_metadata_list = {
{'0', 0, 0}, {'1', 10, 3333}, {'@', 123, 1000000000}};
- for (auto mi : ms) {
+ for (auto user_metadata : user_metadata_list) {
size_t slot;
LocalHandle fence;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
- ASSERT_TRUE(p1_status.ok());
+ DvrNativeBufferMetadata mi, mo;
+
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
- ASSERT_NE(nullptr, p1);
- ASSERT_EQ(p1->Post(LocalHandle(-1), &mi, sizeof(mi)), 0);
- TestMetadata mo;
- auto c1_status = consumer_queue_->Dequeue(100, &slot, &mo, &fence);
- ASSERT_TRUE(c1_status.ok());
+ ASSERT_NE(p1, nullptr);
+
+ // TODO(b/69469185): Test against metadata from consumer once we implement
+ // release metadata properly.
+ // EXPECT_EQ(mo.user_metadata_ptr, 0U);
+ // EXPECT_EQ(mo.user_metadata_size, 0U);
+
+ mi.user_metadata_size = kUserMetadataSize;
+ mi.user_metadata_ptr = reinterpret_cast<uint64_t>(&user_metadata);
+ EXPECT_EQ(p1->PostAsync(&mi, {}), 0);
+ auto c1_status = consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(c1_status.ok());
auto c1 = c1_status.take();
- ASSERT_EQ(mi.a, mo.a);
- ASSERT_EQ(mi.b, mo.b);
- ASSERT_EQ(mi.c, mo.c);
- c1->Release(LocalHandle(-1));
+ ASSERT_NE(c1, nullptr);
+
+ EXPECT_EQ(mo.user_metadata_size, kUserMetadataSize);
+ auto out_user_metadata =
+ reinterpret_cast<TestUserMetadata*>(mo.user_metadata_ptr);
+ EXPECT_EQ(user_metadata.a, out_user_metadata->a);
+ EXPECT_EQ(user_metadata.b, out_user_metadata->b);
+ EXPECT_EQ(user_metadata.c, out_user_metadata->c);
+
+ // When release, empty metadata is also legit.
+ mi.user_metadata_size = 0U;
+ mi.user_metadata_ptr = 0U;
+ c1->ReleaseAsync(&mi, {});
}
}
-TEST_F(BufferHubQueueTest, TestMetadataMismatch) {
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<int64_t>().Build(),
- UsagePolicy{}));
+TEST_F(BufferHubQueueTest, TestUserMetadataMismatch) {
+ ASSERT_TRUE(CreateQueues(
+ config_builder_.SetMetadata<TestUserMetadata>().Build(), UsagePolicy{}));
AllocateBuffer();
- int64_t mi = 3;
+ TestUserMetadata user_metadata;
size_t slot;
LocalHandle fence;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
- ASSERT_TRUE(p1_status.ok());
+ DvrNativeBufferMetadata mi, mo;
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
+ EXPECT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
- ASSERT_NE(nullptr, p1);
- ASSERT_EQ(p1->Post(LocalHandle(-1), &mi, sizeof(mi)), 0);
+ ASSERT_NE(p1, nullptr);
- int32_t mo;
- // Acquire a buffer with mismatched metadata is not OK.
- auto c1_status = consumer_queue_->Dequeue(100, &slot, &mo, &fence);
- ASSERT_FALSE(c1_status.ok());
+ // Post with mismatched user metadata size will fail. But the producer buffer
+ // itself should stay untouched.
+ mi.user_metadata_ptr = reinterpret_cast<uint64_t>(&user_metadata);
+ mi.user_metadata_size = kUserMetadataSize + 1;
+ EXPECT_EQ(p1->PostAsync(&mi, {}), -E2BIG);
+ // Post with the exact same user metdata size can success.
+ mi.user_metadata_ptr = reinterpret_cast<uint64_t>(&user_metadata);
+ mi.user_metadata_size = kUserMetadataSize;
+ EXPECT_EQ(p1->PostAsync(&mi, {}), 0);
}
TEST_F(BufferHubQueueTest, TestEnqueue) {
@@ -421,32 +458,32 @@
size_t slot;
LocalHandle fence;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
+ DvrNativeBufferMetadata mo;
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
ASSERT_NE(nullptr, p1);
- int64_t mo;
producer_queue_->Enqueue(p1, slot, 0ULL);
- auto c1_status = consumer_queue_->Dequeue(100, &slot, &mo, &fence);
+ auto c1_status = consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_FALSE(c1_status.ok());
}
TEST_F(BufferHubQueueTest, TestAllocateBuffer) {
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<int64_t>().Build(),
- UsagePolicy{}));
+ ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
- size_t s1;
+ size_t ps1;
AllocateBuffer();
LocalHandle fence;
- auto p1_status = producer_queue_->Dequeue(100, &s1, &fence);
+ DvrNativeBufferMetadata mi, mo;
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &ps1, &mo, &fence);
ASSERT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
- ASSERT_NE(nullptr, p1);
+ ASSERT_NE(p1, nullptr);
// producer queue is exhausted
- size_t s2;
- auto p2_status = producer_queue_->Dequeue(100, &s2, &fence);
+ size_t ps2;
+ auto p2_status = producer_queue_->Dequeue(kTimeoutMs, &ps2, &mo, &fence);
ASSERT_FALSE(p2_status.ok());
ASSERT_EQ(ETIMEDOUT, p2_status.error());
@@ -456,41 +493,43 @@
ASSERT_EQ(producer_queue_->capacity(), 2U);
// now we can dequeue again
- p2_status = producer_queue_->Dequeue(100, &s2, &fence);
+ p2_status = producer_queue_->Dequeue(kTimeoutMs, &ps2, &mo, &fence);
ASSERT_TRUE(p2_status.ok());
auto p2 = p2_status.take();
- ASSERT_NE(nullptr, p2);
+ ASSERT_NE(p2, nullptr);
ASSERT_EQ(producer_queue_->count(), 0U);
// p1 and p2 should have different slot number
- ASSERT_NE(s1, s2);
+ ASSERT_NE(ps1, ps2);
// Consumer queue does not import buffers until |Dequeue| or |ImportBuffers|
// are called. So far consumer_queue_ should be empty.
ASSERT_EQ(consumer_queue_->count(), 0U);
int64_t seq = 1;
- ASSERT_EQ(p1->Post(LocalHandle(), seq), 0);
+ mi.index = seq;
+ ASSERT_EQ(p1->PostAsync(&mi, {}), 0);
+
size_t cs1, cs2;
- auto c1_status = consumer_queue_->Dequeue(100, &cs1, &seq, &fence);
+ auto c1_status = consumer_queue_->Dequeue(kTimeoutMs, &cs1, &mo, &fence);
ASSERT_TRUE(c1_status.ok());
auto c1 = c1_status.take();
- ASSERT_NE(nullptr, c1);
+ ASSERT_NE(c1, nullptr);
ASSERT_EQ(consumer_queue_->count(), 0U);
ASSERT_EQ(consumer_queue_->capacity(), 2U);
- ASSERT_EQ(cs1, s1);
+ ASSERT_EQ(cs1, ps1);
- ASSERT_EQ(p2->Post(LocalHandle(), seq), 0);
- auto c2_status = consumer_queue_->Dequeue(100, &cs2, &seq, &fence);
+ ASSERT_EQ(p2->PostAsync(&mi, {}), 0);
+ auto c2_status = consumer_queue_->Dequeue(kTimeoutMs, &cs2, &mo, &fence);
ASSERT_TRUE(c2_status.ok());
auto c2 = c2_status.take();
- ASSERT_NE(nullptr, c2);
- ASSERT_EQ(cs2, s2);
+ ASSERT_NE(c2, nullptr);
+ ASSERT_EQ(cs2, ps2);
}
TEST_F(BufferHubQueueTest, TestUsageSetMask) {
const uint32_t set_mask = GRALLOC_USAGE_SW_WRITE_OFTEN;
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<int64_t>().Build(),
- UsagePolicy{set_mask, 0, 0, 0}));
+ ASSERT_TRUE(
+ CreateQueues(config_builder_.Build(), UsagePolicy{set_mask, 0, 0, 0}));
// When allocation, leave out |set_mask| from usage bits on purpose.
auto status = producer_queue_->AllocateBuffer(
@@ -500,7 +539,8 @@
LocalHandle fence;
size_t slot;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
+ DvrNativeBufferMetadata mo;
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
ASSERT_EQ(p1->usage() & set_mask, set_mask);
@@ -508,8 +548,8 @@
TEST_F(BufferHubQueueTest, TestUsageClearMask) {
const uint32_t clear_mask = GRALLOC_USAGE_SW_WRITE_OFTEN;
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<int64_t>().Build(),
- UsagePolicy{0, clear_mask, 0, 0}));
+ ASSERT_TRUE(
+ CreateQueues(config_builder_.Build(), UsagePolicy{0, clear_mask, 0, 0}));
// When allocation, add |clear_mask| into usage bits on purpose.
auto status = producer_queue_->AllocateBuffer(
@@ -519,10 +559,11 @@
LocalHandle fence;
size_t slot;
- auto p1_status = producer_queue_->Dequeue(100, &slot, &fence);
+ DvrNativeBufferMetadata mo;
+ auto p1_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(p1_status.ok());
auto p1 = p1_status.take();
- ASSERT_EQ(0u, p1->usage() & clear_mask);
+ ASSERT_EQ(p1->usage() & clear_mask, 0U);
}
TEST_F(BufferHubQueueTest, TestUsageDenySetMask) {
@@ -600,16 +641,15 @@
EXPECT_EQ(producer_queue_->capacity(), num_buffers);
size_t slot;
- uint64_t seq;
LocalHandle fence;
pdx::Status<void> status;
pdx::Status<std::shared_ptr<BufferConsumer>> consumer_status;
pdx::Status<std::shared_ptr<BufferProducer>> producer_status;
std::shared_ptr<BufferConsumer> consumer_buffer;
std::shared_ptr<BufferProducer> producer_buffer;
+ DvrNativeBufferMetadata mi, mo;
- ASSERT_TRUE(CreateQueues(config_builder_.SetMetadata<uint64_t>().Build(),
- UsagePolicy{}));
+ ASSERT_TRUE(CreateQueues(config_builder_.Build(), UsagePolicy{}));
// Free all buffers when buffers are avaible for dequeue.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
@@ -618,7 +658,7 @@
// Free all buffers when one buffer is dequeued.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
- producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
status = producer_queue_->FreeAllBuffers();
EXPECT_TRUE(status.ok());
@@ -626,7 +666,7 @@
// Free all buffers when all buffers are dequeued.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
for (size_t i = 0; i < kBufferCount; i++) {
- producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
}
status = producer_queue_->FreeAllBuffers();
@@ -634,22 +674,22 @@
// Free all buffers when one buffer is posted.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
- producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
producer_buffer = producer_status.take();
ASSERT_NE(nullptr, producer_buffer);
- ASSERT_EQ(0, producer_buffer->Post(fence, &seq, sizeof(seq)));
+ ASSERT_EQ(0, producer_buffer->PostAsync(&mi, fence));
status = producer_queue_->FreeAllBuffers();
EXPECT_TRUE(status.ok());
// Free all buffers when all buffers are posted.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
for (size_t i = 0; i < kBufferCount; i++) {
- producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
producer_buffer = producer_status.take();
- ASSERT_NE(nullptr, producer_buffer);
- ASSERT_EQ(0, producer_buffer->Post(fence, &seq, sizeof(seq)));
+ ASSERT_NE(producer_buffer, nullptr);
+ ASSERT_EQ(producer_buffer->PostAsync(&mi, fence), 0);
}
status = producer_queue_->FreeAllBuffers();
EXPECT_TRUE(status.ok());
@@ -657,12 +697,12 @@
// Free all buffers when all buffers are acquired.
CHECK_NO_BUFFER_THEN_ALLOCATE(kBufferCount);
for (size_t i = 0; i < kBufferCount; i++) {
- producer_status = producer_queue_->Dequeue(100, &slot, &fence);
+ producer_status = producer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(producer_status.ok());
producer_buffer = producer_status.take();
- ASSERT_NE(nullptr, producer_buffer);
- ASSERT_EQ(0, producer_buffer->Post(fence, &seq, sizeof(seq)));
- consumer_status = consumer_queue_->Dequeue(100, &slot, &seq, &fence);
+ ASSERT_NE(producer_buffer, nullptr);
+ ASSERT_EQ(producer_buffer->PostAsync(&mi, fence), 0);
+ consumer_status = consumer_queue_->Dequeue(kTimeoutMs, &slot, &mo, &fence);
ASSERT_TRUE(consumer_status.ok());
}
@@ -750,18 +790,18 @@
EXPECT_TRUE(s3.ok());
std::shared_ptr<BufferProducer> p1 = s3.take();
- EXPECT_NE(p1, nullptr);
+ ASSERT_NE(p1, nullptr);
producer_meta.timestamp = 42;
EXPECT_EQ(p1->PostAsync(&producer_meta, LocalHandle()), 0);
// Make sure the buffer can be dequeued from consumer side.
- auto s4 = consumer_queue_->Dequeue(100, &slot, &consumer_meta, &fence);
+ auto s4 = consumer_queue_->Dequeue(kTimeoutMs, &slot, &consumer_meta, &fence);
EXPECT_TRUE(s4.ok());
EXPECT_EQ(consumer_queue_->capacity(), 1U);
auto consumer = s4.take();
- EXPECT_NE(consumer, nullptr);
+ ASSERT_NE(consumer, nullptr);
EXPECT_EQ(producer_meta.timestamp, consumer_meta.timestamp);
}
@@ -817,18 +857,18 @@
EXPECT_TRUE(s2.ok());
std::shared_ptr<BufferProducer> p1 = s2.take();
- EXPECT_NE(p1, nullptr);
+ ASSERT_NE(p1, nullptr);
producer_meta.timestamp = 42;
EXPECT_EQ(p1->PostAsync(&producer_meta, LocalHandle()), 0);
// Make sure the buffer can be dequeued from consumer side.
- auto s3 = consumer_queue_->Dequeue(100, &slot, &consumer_meta, &fence);
+ auto s3 = consumer_queue_->Dequeue(kTimeoutMs, &slot, &consumer_meta, &fence);
EXPECT_TRUE(s3.ok());
EXPECT_EQ(consumer_queue_->capacity(), 1U);
auto consumer = s3.take();
- EXPECT_NE(consumer, nullptr);
+ ASSERT_NE(consumer, nullptr);
EXPECT_EQ(producer_meta.timestamp, consumer_meta.timestamp);
}
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/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index c477a3b..4e214d1 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -262,9 +262,6 @@
}
void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
- if (mHwcLayers.empty()) {
- return;
- }
mSurfaceFlingerConsumer->setReleaseFence(releaseFence);
}
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index ef7d482..6d6781e 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -325,6 +325,14 @@
return mVisibleLayersSortedByZ;
}
+void DisplayDevice::setLayersNeedingFences(const Vector< sp<Layer> >& layers) {
+ mLayersNeedingFences = layers;
+}
+
+const Vector< sp<Layer> >& DisplayDevice::getLayersNeedingFences() const {
+ return mLayersNeedingFences;
+}
+
Region DisplayDevice::getDirtyRegion(bool repaintEverything) const {
Region dirty;
if (repaintEverything) {
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index 50e30b2..e388a5b 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -113,6 +113,8 @@
void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers);
const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const;
+ void setLayersNeedingFences(const Vector< sp<Layer> >& layers);
+ const Vector< sp<Layer> >& getLayersNeedingFences() const;
Region getDirtyRegion(bool repaintEverything) const;
void setLayerStack(uint32_t stack);
@@ -214,6 +216,8 @@
// list of visible layers on that display
Vector< sp<Layer> > mVisibleLayersSortedByZ;
+ // list of layers needing fences
+ Vector< sp<Layer> > mLayersNeedingFences;
/*
* Transaction state
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 5b40aea..3be7f47 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -217,9 +217,9 @@
return true;
}
-void Layer::destroyHwcLayer(int32_t hwcId) {
+bool Layer::destroyHwcLayer(int32_t hwcId) {
if (mHwcLayers.count(hwcId) == 0) {
- return;
+ return false;
}
auto& hwcInfo = mHwcLayers[hwcId];
LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
@@ -228,6 +228,8 @@
// 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");
+
+ return true;
}
void Layer::destroyAllHwcLayers() {
@@ -1100,6 +1102,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++;
@@ -1558,17 +1573,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;
}
@@ -1601,11 +1613,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) {
@@ -1614,6 +1622,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 0fc5ad5..9ea800e 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -414,7 +414,7 @@
// -----------------------------------------------------------------------
bool createHwcLayer(HWComposer* hwc, int32_t hwcId);
- void destroyHwcLayer(int32_t hwcId);
+ bool destroyHwcLayer(int32_t hwcId);
void destroyAllHwcLayers();
bool hasHwcLayer(int32_t hwcId) { return mHwcLayers.count(hwcId) > 0; }
@@ -482,6 +482,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.
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 50ed8f7..ec2a459 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1781,6 +1781,7 @@
Region opaqueRegion;
Region dirtyRegion;
Vector<sp<Layer>> layersSortedByZ;
+ Vector<sp<Layer>> layersNeedingFences;
const sp<DisplayDevice>& displayDevice(mDisplays[dpy]);
const Transform& tr(displayDevice->getTransform());
const Rect bounds(displayDevice->getBounds());
@@ -1788,6 +1789,7 @@
computeVisibleRegions(displayDevice, dirtyRegion, opaqueRegion);
mDrawingState.traverseInZOrder([&](Layer* layer) {
+ bool hwcLayerDestroyed = false;
if (layer->belongsToDisplay(displayDevice->getLayerStack(),
displayDevice->isPrimary())) {
Region drawRegion(tr.transform(
@@ -1798,18 +1800,32 @@
} else {
// Clear out the HWC layer if this layer was
// previously visible, but no longer is
- layer->destroyHwcLayer(
+ hwcLayerDestroyed = layer->destroyHwcLayer(
displayDevice->getHwcDisplayId());
}
} else {
// WM changes displayDevice->layerStack upon sleep/awake.
// Here we make sure we delete the HWC layers even if
// WM changed their layer stack.
- layer->destroyHwcLayer(displayDevice->getHwcDisplayId());
+ hwcLayerDestroyed = layer->destroyHwcLayer(
+ displayDevice->getHwcDisplayId());
+ }
+
+ // If a layer is not going to get a release fence because
+ // it is invisible, but it is also going to release its
+ // old buffer, add it to the list of layers needing
+ // fences.
+ if (hwcLayerDestroyed) {
+ auto found = std::find(mLayersWithQueuedFrames.cbegin(),
+ mLayersWithQueuedFrames.cend(), layer);
+ if (found != mLayersWithQueuedFrames.cend()) {
+ layersNeedingFences.add(layer);
+ }
}
});
}
displayDevice->setVisibleLayersSortedByZ(layersSortedByZ);
+ displayDevice->setLayersNeedingFences(layersNeedingFences);
displayDevice->undefinedRegion.set(bounds);
displayDevice->undefinedRegion.subtractSelf(
tr.transform(opaqueRegion));
@@ -2055,6 +2071,17 @@
layer->onLayerDisplayed(releaseFence);
}
+
+ // We've got a list of layers needing fences, that are disjoint with
+ // displayDevice->getVisibleLayersSortedByZ. The best we can do is to
+ // supply them with the present fence.
+ if (!displayDevice->getLayersNeedingFences().isEmpty()) {
+ sp<Fence> presentFence = mHwc->getPresentFence(hwcId);
+ for (auto& layer : displayDevice->getLayersNeedingFences()) {
+ layer->onLayerDisplayed(presentFence);
+ }
+ }
+
if (hwcId >= 0) {
mHwc->clearReleaseFences(hwcId);
}
@@ -3116,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) {
@@ -4725,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/SurfaceTracing.h b/services/surfaceflinger/SurfaceTracing.h
index 9b21989..590ab96 100644
--- a/services/surfaceflinger/SurfaceTracing.h
+++ b/services/surfaceflinger/SurfaceTracing.h
@@ -37,7 +37,7 @@
void traceLayers(const char* where, LayersProto);
private:
- static constexpr auto DEFAULT_FILENAME = "/data/misc/trace/layerstrace.pb";
+ static constexpr auto DEFAULT_FILENAME = "/data/misc/wmtrace/layers_trace.pb";
status_t writeProtoFileLocked();
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