Merge "SurfaceFlinger: add explicit register for DISPLAY_EVENT_CONFIG_CHANGED" into qt-r1-dev am: aacc75c204
am: ba225e3f3c
Change-Id: I89a902e389ce521cf8e7f320f68a1dc0005fc8de
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 1a932c3..4f7cdf3 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -4,13 +4,16 @@
[Builtin Hooks Options]
# Only turn on clang-format check for the following subfolders.
clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
+ include/input/
libs/binder/ndk/
libs/graphicsenv/
libs/gui/
+ libs/input/
libs/renderengine/
libs/ui/
libs/vr/
services/bufferhub/
+ services/inputflinger/
services/surfaceflinger/
services/vr/
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index ef2ad99..abb8368 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -130,7 +130,7 @@
/**
* Returns a sync fence that signals when the transaction has been presented.
* The recipient of the callback takes ownership of the fence and is responsible for closing
- * it.
+ * it. If a device does not support present fences, a -1 will be returned.
*/
int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats)
__INTRODUCED_IN(29);
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 458961b..c389d18 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -616,7 +616,7 @@
return err == NO_ERROR;
}
-uid_t Parcel::readCallingWorkSourceUid()
+uid_t Parcel::readCallingWorkSourceUid() const
{
if (!mRequestHeaderPresent) {
return IPCThreadState::kUnsetWorkSource;
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index 0cdabb0..0046e3a 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -399,7 +399,7 @@
bool replaceCallingWorkSourceUid(uid_t uid);
// Returns the work source provided by the caller. This can only be trusted for trusted calling
// uid.
- uid_t readCallingWorkSourceUid();
+ uid_t readCallingWorkSourceUid() const;
void readRequestHeaders() const;
private:
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index 34575f5..b2a7557 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -15,6 +15,10 @@
name: "libgui_headers",
vendor_available: true,
export_include_dirs: ["include"],
+
+ // we must build this module to get the required header as that is generated
+ export_shared_lib_headers: [ "android.hidl.token@1.0-utils" ],
+ shared_libs: [ "android.hidl.token@1.0-utils" ],
}
cc_library_shared {
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index d6f88fc..cc9e468 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -623,6 +623,7 @@
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
+ return *this;
}
s->what |= layer_state_t::eRelativeLayerChanged;
s->what &= ~layer_state_t::eLayerChanged;
@@ -1052,6 +1053,7 @@
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
+ return *this;
}
s->what |= layer_state_t::eDetachChildren;
diff --git a/libs/gui/tests/RegionSampling_test.cpp b/libs/gui/tests/RegionSampling_test.cpp
index d33ecfb..c9de37d 100644
--- a/libs/gui/tests/RegionSampling_test.cpp
+++ b/libs/gui/tests/RegionSampling_test.cpp
@@ -297,4 +297,70 @@
composer->removeRegionSamplingListener(grayListener);
}
+TEST_F(RegionSamplingTest, DISABLED_TestIfInvalidInputParameters) {
+ sp<ISurfaceComposer> composer = ComposerService::getComposerService();
+ sp<Listener> listener = new Listener();
+ const Rect sampleArea{100, 100, 200, 200};
+ // Invalid input sampleArea
+ EXPECT_EQ(BAD_VALUE,
+ composer->addRegionSamplingListener(Rect::INVALID_RECT, mTopLayer->getHandle(),
+ listener));
+ listener->reset();
+ // Invalid input binder
+ EXPECT_EQ(NO_ERROR, composer->addRegionSamplingListener(sampleArea, NULL, listener));
+ // Invalid input listener
+ EXPECT_EQ(BAD_VALUE,
+ composer->addRegionSamplingListener(sampleArea, mTopLayer->getHandle(), NULL));
+ EXPECT_EQ(BAD_VALUE, composer->removeRegionSamplingListener(NULL));
+ // remove the listener
+ composer->removeRegionSamplingListener(listener);
+}
+
+TEST_F(RegionSamplingTest, DISABLED_TestCallbackAfterRemoveListener) {
+ fill_render(rgba_green);
+ sp<ISurfaceComposer> composer = ComposerService::getComposerService();
+ sp<Listener> listener = new Listener();
+ const Rect sampleArea{100, 100, 200, 200};
+ composer->addRegionSamplingListener(sampleArea, mTopLayer->getHandle(), listener);
+ fill_render(rgba_green);
+
+ EXPECT_TRUE(listener->wait_event(300ms)) << "timed out waiting for luma event to be received";
+ EXPECT_NEAR(listener->luma(), luma_green, error_margin);
+
+ listener->reset();
+ composer->removeRegionSamplingListener(listener);
+ fill_render(rgba_green);
+ EXPECT_FALSE(listener->wait_event(100ms))
+ << "callback should stop after remove the region sampling listener";
+}
+
+TEST_F(RegionSamplingTest, DISABLED_CollectsLumaFromMovingLayer) {
+ sp<ISurfaceComposer> composer = ComposerService::getComposerService();
+ sp<Listener> listener = new Listener();
+ Rect sampleArea{100, 100, 200, 200};
+
+ // Test: listener in (100, 100). See layer before move, no layer after move.
+ fill_render(rgba_blue);
+ composer->addRegionSamplingListener(sampleArea, mTopLayer->getHandle(), listener);
+ EXPECT_TRUE(listener->wait_event(300ms)) << "timed out waiting for luma event to be received";
+ EXPECT_NEAR(listener->luma(), luma_blue, error_margin);
+ listener->reset();
+ SurfaceComposerClient::Transaction{}.setPosition(mContentLayer, 600, 600).apply();
+ EXPECT_TRUE(listener->wait_event(300ms)) << "timed out waiting for luma event to be received";
+ EXPECT_NEAR(listener->luma(), luma_gray, error_margin);
+ composer->removeRegionSamplingListener(listener);
+
+ // Test: listener offset to (600, 600). No layer before move, see layer after move.
+ fill_render(rgba_green);
+ sampleArea.offsetTo(600, 600);
+ composer->addRegionSamplingListener(sampleArea, mTopLayer->getHandle(), listener);
+ EXPECT_TRUE(listener->wait_event(300ms)) << "timed out waiting for luma event to be received";
+ EXPECT_NEAR(listener->luma(), luma_gray, error_margin);
+ listener->reset();
+ SurfaceComposerClient::Transaction{}.setPosition(mContentLayer, 600, 600).apply();
+ EXPECT_TRUE(listener->wait_event(300ms)) << "timed out waiting for luma event to be received";
+ EXPECT_NEAR(listener->luma(), luma_green, error_margin);
+ composer->removeRegionSamplingListener(listener);
+}
+
} // namespace android::test
diff --git a/libs/vr/libbufferhub/consumer_buffer.cpp b/libs/vr/libbufferhub/consumer_buffer.cpp
index 115e866..7823e36 100644
--- a/libs/vr/libbufferhub/consumer_buffer.cpp
+++ b/libs/vr/libbufferhub/consumer_buffer.cpp
@@ -52,12 +52,6 @@
while (!buffer_state_->compare_exchange_weak(
current_buffer_state, updated_buffer_state, std::memory_order_acq_rel,
std::memory_order_acquire)) {
- ALOGD(
- "%s Failed to acquire the buffer. Current buffer state was changed to "
- "%" PRIx32
- " when trying to acquire the buffer and modify the buffer state to "
- "%" PRIx32 ". About to try again if the buffer is still posted.",
- __FUNCTION__, current_buffer_state, updated_buffer_state);
if (!BufferHubDefs::isClientPosted(current_buffer_state,
client_state_mask())) {
ALOGE(
@@ -152,12 +146,6 @@
while (!buffer_state_->compare_exchange_weak(
current_buffer_state, updated_buffer_state, std::memory_order_acq_rel,
std::memory_order_acquire)) {
- ALOGD(
- "%s: Failed to release the buffer. Current buffer state was changed to "
- "%" PRIx32
- " when trying to release the buffer and modify the buffer state to "
- "%" PRIx32 ". About to try again.",
- __FUNCTION__, current_buffer_state, updated_buffer_state);
// The failure of compare_exchange_weak updates current_buffer_state.
updated_buffer_state = current_buffer_state & (~client_state_mask());
}
diff --git a/libs/vr/libbufferhub/producer_buffer.cpp b/libs/vr/libbufferhub/producer_buffer.cpp
index 3d88ba5..aa9d072 100644
--- a/libs/vr/libbufferhub/producer_buffer.cpp
+++ b/libs/vr/libbufferhub/producer_buffer.cpp
@@ -96,13 +96,6 @@
while (!buffer_state_->compare_exchange_weak(
current_buffer_state, updated_buffer_state, std::memory_order_acq_rel,
std::memory_order_acquire)) {
- ALOGD(
- "%s: Failed to post the buffer. Current buffer state was changed to "
- "%" PRIx32
- " when trying to post the buffer and modify the buffer state to "
- "%" PRIx32
- ". About to try again if the buffer is still gained by this client.",
- __FUNCTION__, current_buffer_state, updated_buffer_state);
if (!BufferHubDefs::isClientGained(current_buffer_state,
client_state_mask())) {
ALOGE(
@@ -186,15 +179,6 @@
while (!buffer_state_->compare_exchange_weak(
current_buffer_state, updated_buffer_state, std::memory_order_acq_rel,
std::memory_order_acquire)) {
- ALOGD(
- "%s: Failed to gain the buffer. Current buffer state was changed to "
- "%" PRIx32
- " when trying to gain the buffer and modify the buffer state to "
- "%" PRIx32
- ". About to try again if the buffer is still not read by other "
- "clients.",
- __FUNCTION__, current_buffer_state, updated_buffer_state);
-
if (BufferHubDefs::isAnyClientAcquired(current_buffer_state) ||
BufferHubDefs::isAnyClientGained(current_buffer_state) ||
(BufferHubDefs::isAnyClientPosted(
diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp
index abc7a72..8144c8a 100644
--- a/opengl/libs/Android.bp
+++ b/opengl/libs/Android.bp
@@ -162,7 +162,7 @@
"libEGL_getProcAddress",
"libEGL_blobCache",
],
- ldflags: ["-Wl,--exclude-libs=ALL"],
+ ldflags: ["-Wl,--exclude-libs=ALL,--Bsymbolic-functions"],
export_include_dirs: ["EGL/include"],
}
diff --git a/services/inputflinger/EventHub.cpp b/services/inputflinger/EventHub.cpp
index ce56272..af02314 100644
--- a/services/inputflinger/EventHub.cpp
+++ b/services/inputflinger/EventHub.cpp
@@ -28,7 +28,6 @@
#include <sys/limits.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
-#include <sys/utsname.h>
#include <unistd.h>
#define LOG_TAG "EventHub"
@@ -94,14 +93,6 @@
return out;
}
-static void getLinuxRelease(int* major, int* minor) {
- struct utsname info;
- if (uname(&info) || sscanf(info.release, "%d.%d", major, minor) <= 0) {
- *major = 0, *minor = 0;
- ALOGE("Could not get linux version: %s", strerror(errno));
- }
-}
-
/**
* Return true if name matches "v4l-touch*"
*/
@@ -292,11 +283,6 @@
result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance. errno=%d",
errno);
-
- int major, minor;
- getLinuxRelease(&major, &minor);
- // EPOLLWAKEUP was introduced in kernel 3.5
- mUsingEpollWakeup = major > 3 || (major == 3 && minor >= 5);
}
EventHub::~EventHub(void) {
@@ -1487,28 +1473,13 @@
}
}
- std::string wakeMechanism = "EPOLLWAKEUP";
- if (!mUsingEpollWakeup) {
-#ifndef EVIOCSSUSPENDBLOCK
- // uapi headers don't include EVIOCSSUSPENDBLOCK, and future kernels
- // will use an epoll flag instead, so as long as we want to support
- // this feature, we need to be prepared to define the ioctl ourselves.
-#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)
-#endif
- if (ioctl(device->fd, EVIOCSSUSPENDBLOCK, 1)) {
- wakeMechanism = "<none>";
- } else {
- wakeMechanism = "EVIOCSSUSPENDBLOCK";
- }
- }
// Tell the kernel that we want to use the monotonic clock for reporting timestamps
// associated with input events. This is important because the input system
// uses the timestamps extensively and assumes they were recorded using the monotonic
// clock.
int clockId = CLOCK_MONOTONIC;
bool usingClockIoctl = !ioctl(device->fd, EVIOCSCLOCKID, &clockId);
- ALOGI("wakeMechanism=%s, usingClockIoctl=%s", wakeMechanism.c_str(),
- toString(usingClockIoctl));
+ ALOGI("usingClockIoctl=%s", toString(usingClockIoctl));
}
void EventHub::openVideoDeviceLocked(const std::string& devicePath) {
diff --git a/services/inputflinger/EventHub.h b/services/inputflinger/EventHub.h
index 63a20ef..eb4e8f2 100644
--- a/services/inputflinger/EventHub.h
+++ b/services/inputflinger/EventHub.h
@@ -479,8 +479,6 @@
size_t mPendingEventCount;
size_t mPendingEventIndex;
bool mPendingINotify;
-
- bool mUsingEpollWakeup;
};
}; // namespace android
diff --git a/services/surfaceflinger/CompositionEngine/tests/FloatRectMatcher.h b/services/surfaceflinger/CompositionEngine/tests/FloatRectMatcher.h
new file mode 100644
index 0000000..6741cc9
--- /dev/null
+++ b/services/surfaceflinger/CompositionEngine/tests/FloatRectMatcher.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+#include <android-base/stringprintf.h>
+#include <gmock/gmock.h>
+
+namespace {
+
+using android::base::StringAppendF;
+using FloatRect = android::FloatRect;
+
+void dumpFloatRect(const FloatRect& rect, std::string& result, const char* name) {
+ StringAppendF(&result, "%s (%f %f %f %f) ", name, rect.left, rect.top, rect.right, rect.bottom);
+}
+
+// Checks for a region match
+MATCHER_P(FloatRectEq, expected, "") {
+ std::string buf;
+ buf.append("FloatRects are not equal\n");
+ dumpFloatRect(expected, buf, "expected rect");
+ dumpFloatRect(arg, buf, "actual rect");
+ *result_listener << buf;
+
+ const float TOLERANCE = 1e-3f;
+ return (std::fabs(expected.left - arg.left) < TOLERANCE) &&
+ (std::fabs(expected.top - arg.top) < TOLERANCE) &&
+ (std::fabs(expected.right - arg.right) < TOLERANCE) &&
+ (std::fabs(expected.bottom - arg.bottom) < TOLERANCE);
+}
+
+} // namespace
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index 2060c5a..ae906cd 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -21,6 +21,7 @@
#include <compositionengine/mock/Output.h>
#include <gtest/gtest.h>
+#include "FloatRectMatcher.h"
#include "MockHWC2.h"
#include "MockHWComposer.h"
#include "RectMatcher.h"
@@ -106,6 +107,114 @@
}
/*
+ * OutputLayer::calculateOutputSourceCrop()
+ */
+
+struct OutputLayerSourceCropTest : public OutputLayerTest {
+ OutputLayerSourceCropTest() {
+ // Set reasonable default values for a simple case. Each test will
+ // set one specific value to something different.
+ mLayerState.frontEnd.geomUsesSourceCrop = true;
+ mLayerState.frontEnd.geomContentCrop = Rect{0, 0, 1920, 1080};
+ mLayerState.frontEnd.geomActiveTransparentRegion = Region{};
+ mLayerState.frontEnd.geomLayerBounds = FloatRect{0.f, 0.f, 1920.f, 1080.f};
+ mLayerState.frontEnd.geomLayerTransform = ui::Transform{TR_IDENT};
+ mLayerState.frontEnd.geomBufferSize = Rect{0, 0, 1920, 1080};
+ mLayerState.frontEnd.geomBufferTransform = TR_IDENT;
+
+ mOutputState.viewport = Rect{0, 0, 1920, 1080};
+ }
+
+ FloatRect calculateOutputSourceCrop() {
+ mLayerState.frontEnd.geomInverseLayerTransform =
+ mLayerState.frontEnd.geomLayerTransform.inverse();
+
+ return mOutputLayer.calculateOutputSourceCrop();
+ }
+};
+
+TEST_F(OutputLayerSourceCropTest, computesEmptyIfSourceCropNotUsed) {
+ mLayerState.frontEnd.geomUsesSourceCrop = false;
+
+ const FloatRect expected{};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+TEST_F(OutputLayerSourceCropTest, correctForSimpleDefaultCase) {
+ const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewport) {
+ mLayerState.frontEnd.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
+
+ const FloatRect expected{0.f, 0.f, 1920.f, 1080.f};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+TEST_F(OutputLayerSourceCropTest, handlesBoundsOutsideViewportRotated) {
+ mLayerState.frontEnd.geomLayerBounds = FloatRect{-2000.f, -2000.f, 2000.f, 2000.f};
+ mLayerState.frontEnd.geomLayerTransform.set(HAL_TRANSFORM_ROT_90, 1920, 1080);
+
+ const FloatRect expected{0.f, 0.f, 1080.f, 1080.f};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+TEST_F(OutputLayerSourceCropTest, calculateOutputSourceCropWorksWithATransformedBuffer) {
+ struct Entry {
+ uint32_t bufferInvDisplay;
+ uint32_t buffer;
+ uint32_t display;
+ FloatRect expected;
+ };
+ // Not an exhaustive list of cases, but hopefully enough.
+ const std::array<Entry, 12> testData = {
+ // clang-format off
+ // inv buffer display expected
+ /* 0 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 1 */ Entry{false, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 2 */ Entry{false, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 3 */ Entry{false, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+
+ /* 4 */ Entry{true, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 5 */ Entry{true, TR_IDENT, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 6 */ Entry{true, TR_IDENT, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 7 */ Entry{true, TR_IDENT, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+
+ /* 8 */ Entry{false, TR_IDENT, TR_IDENT, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 9 */ Entry{false, TR_ROT_90, TR_ROT_90, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 10 */ Entry{false, TR_ROT_180, TR_ROT_180, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+ /* 11 */ Entry{false, TR_ROT_270, TR_ROT_270, FloatRect{0.f, 0.f, 1920.f, 1080.f}},
+
+ // clang-format on
+ };
+
+ for (size_t i = 0; i < testData.size(); i++) {
+ const auto& entry = testData[i];
+
+ mLayerState.frontEnd.geomBufferUsesDisplayInverseTransform = entry.bufferInvDisplay;
+ mLayerState.frontEnd.geomBufferTransform = entry.buffer;
+ mOutputState.orientation = entry.display;
+
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(entry.expected)) << "entry " << i;
+ }
+}
+
+TEST_F(OutputLayerSourceCropTest, geomContentCropAffectsCrop) {
+ mLayerState.frontEnd.geomContentCrop = Rect{0, 0, 960, 540};
+
+ const FloatRect expected{0.f, 0.f, 960.f, 540.f};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+TEST_F(OutputLayerSourceCropTest, viewportAffectsCrop) {
+ mOutputState.viewport = Rect{0, 0, 960, 540};
+
+ const FloatRect expected{0.f, 0.f, 960.f, 540.f};
+ EXPECT_THAT(calculateOutputSourceCrop(), FloatRectEq(expected));
+}
+
+/*
* OutputLayer::calculateOutputDisplayFrame()
*/
@@ -163,7 +272,7 @@
EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
}
-TEST_F(OutputLayerDisplayFrameTest, geomLayerSnapToBoundsAffectsFrame) {
+TEST_F(OutputLayerDisplayFrameTest, geomLayerBoundsAffectsFrame) {
mLayerState.frontEnd.geomLayerBounds = FloatRect{0.f, 0.f, 960.f, 540.f};
const Rect expected{0, 0, 960, 540};
EXPECT_THAT(calculateOutputDisplayFrame(), RectEq(expected));
@@ -242,6 +351,159 @@
}
}
+TEST_F(OutputLayerTest,
+ calculateOutputRelativeBufferTransformTestWithOfBufferUsesDisplayInverseTransform) {
+ mLayerState.frontEnd.geomBufferUsesDisplayInverseTransform = true;
+
+ struct Entry {
+ uint32_t layer;
+ uint32_t buffer;
+ uint32_t display;
+ uint32_t expected;
+ };
+ // Not an exhaustive list of cases, but hopefully enough.
+ const std::array<Entry, 24> testData = {
+ // clang-format off
+ // layer buffer display expected
+ /* 0 */ Entry{TR_IDENT, TR_IDENT, TR_IDENT, TR_IDENT},
+ /* 1 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_90, TR_IDENT},
+ /* 2 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_180, TR_IDENT},
+ /* 3 */ Entry{TR_IDENT, TR_IDENT, TR_ROT_270, TR_IDENT},
+
+ /* 4 */ Entry{TR_IDENT, TR_FLP_H, TR_IDENT, TR_FLP_H},
+ /* 5 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_90, TR_FLP_H},
+ /* 6 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_180, TR_FLP_H},
+ /* 7 */ Entry{TR_IDENT, TR_FLP_H, TR_ROT_270, TR_FLP_H},
+
+ /* 8 */ Entry{TR_IDENT, TR_FLP_V, TR_IDENT, TR_FLP_V},
+ /* 9 */ Entry{TR_IDENT, TR_ROT_90, TR_ROT_90, TR_ROT_90},
+ /* 10 */ Entry{TR_IDENT, TR_ROT_180, TR_ROT_180, TR_ROT_180},
+ /* 11 */ Entry{TR_IDENT, TR_ROT_270, TR_ROT_270, TR_ROT_270},
+
+ /* 12 */ Entry{TR_ROT_90, TR_IDENT, TR_IDENT, TR_IDENT},
+ /* 13 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_90, TR_FLP_H},
+ /* 14 */ Entry{TR_ROT_90, TR_IDENT, TR_ROT_180, TR_IDENT},
+ /* 15 */ Entry{TR_ROT_90, TR_FLP_H, TR_ROT_270, TR_FLP_H},
+
+ /* 16 */ Entry{TR_ROT_180, TR_FLP_H, TR_IDENT, TR_FLP_H},
+ /* 17 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_90, TR_IDENT},
+ /* 18 */ Entry{TR_ROT_180, TR_FLP_H, TR_ROT_180, TR_FLP_H},
+ /* 19 */ Entry{TR_ROT_180, TR_IDENT, TR_ROT_270, TR_IDENT},
+
+ /* 20 */ Entry{TR_ROT_270, TR_IDENT, TR_IDENT, TR_IDENT},
+ /* 21 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_90, TR_FLP_H},
+ /* 22 */ Entry{TR_ROT_270, TR_FLP_H, TR_ROT_180, TR_FLP_H},
+ /* 23 */ Entry{TR_ROT_270, TR_IDENT, TR_ROT_270, TR_IDENT},
+ // clang-format on
+ };
+
+ for (size_t i = 0; i < testData.size(); i++) {
+ const auto& entry = testData[i];
+
+ mLayerState.frontEnd.geomLayerTransform = ui::Transform{entry.layer};
+ mLayerState.frontEnd.geomBufferTransform = entry.buffer;
+ mOutputState.orientation = entry.display;
+
+ auto actual = mOutputLayer.calculateOutputRelativeBufferTransform();
+ EXPECT_EQ(entry.expected, actual) << "entry " << i;
+ }
+}
+
+/*
+ * OutputLayer::updateCompositionState()
+ */
+
+struct OutputLayerPartialMockForUpdateCompositionState : public impl::OutputLayer {
+ OutputLayerPartialMockForUpdateCompositionState(const compositionengine::Output& output,
+ std::shared_ptr<compositionengine::Layer> layer,
+ sp<compositionengine::LayerFE> layerFE)
+ : impl::OutputLayer(output, layer, layerFE) {}
+ // Mock everything called by updateCompositionState to simplify testing it.
+ MOCK_CONST_METHOD0(calculateOutputSourceCrop, FloatRect());
+ MOCK_CONST_METHOD0(calculateOutputDisplayFrame, Rect());
+ MOCK_CONST_METHOD0(calculateOutputRelativeBufferTransform, uint32_t());
+};
+
+struct OutputLayerUpdateCompositionStateTest : public OutputLayerTest {
+public:
+ OutputLayerUpdateCompositionStateTest() {
+ EXPECT_CALL(*mLayer, getState()).WillRepeatedly(ReturnRef(mLayerState));
+ EXPECT_CALL(mOutput, getState()).WillRepeatedly(ReturnRef(mOutputState));
+ }
+
+ ~OutputLayerUpdateCompositionStateTest() = default;
+
+ void setupGeometryChildCallValues() {
+ EXPECT_CALL(mOutputLayer, calculateOutputSourceCrop()).WillOnce(Return(kSourceCrop));
+ EXPECT_CALL(mOutputLayer, calculateOutputDisplayFrame()).WillOnce(Return(kDisplayFrame));
+ EXPECT_CALL(mOutputLayer, calculateOutputRelativeBufferTransform())
+ .WillOnce(Return(mBufferTransform));
+ }
+
+ void validateComputedGeometryState() {
+ const auto& state = mOutputLayer.getState();
+ EXPECT_EQ(kSourceCrop, state.sourceCrop);
+ EXPECT_EQ(kDisplayFrame, state.displayFrame);
+ EXPECT_EQ(static_cast<Hwc2::Transform>(mBufferTransform), state.bufferTransform);
+ }
+
+ const FloatRect kSourceCrop{1.f, 2.f, 3.f, 4.f};
+ const Rect kDisplayFrame{11, 12, 13, 14};
+ uint32_t mBufferTransform{21};
+
+ using OutputLayer = OutputLayerPartialMockForUpdateCompositionState;
+ StrictMock<OutputLayer> mOutputLayer{mOutput, mLayer, mLayerFE};
+};
+
+TEST_F(OutputLayerUpdateCompositionStateTest, setsStateNormally) {
+ mLayerState.frontEnd.isSecure = true;
+ mOutputState.isSecure = true;
+
+ setupGeometryChildCallValues();
+
+ mOutputLayer.updateCompositionState(true);
+
+ validateComputedGeometryState();
+
+ EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
+}
+
+TEST_F(OutputLayerUpdateCompositionStateTest,
+ alsoSetsForceCompositionIfSecureLayerOnNonsecureOutput) {
+ mLayerState.frontEnd.isSecure = true;
+ mOutputState.isSecure = false;
+
+ setupGeometryChildCallValues();
+
+ mOutputLayer.updateCompositionState(true);
+
+ validateComputedGeometryState();
+
+ EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
+}
+
+TEST_F(OutputLayerUpdateCompositionStateTest,
+ alsoSetsForceCompositionIfUnsupportedBufferTransform) {
+ mLayerState.frontEnd.isSecure = true;
+ mOutputState.isSecure = true;
+
+ mBufferTransform = ui::Transform::ROT_INVALID;
+
+ setupGeometryChildCallValues();
+
+ mOutputLayer.updateCompositionState(true);
+
+ validateComputedGeometryState();
+
+ EXPECT_EQ(true, mOutputLayer.getState().forceClientComposition);
+}
+
+TEST_F(OutputLayerUpdateCompositionStateTest, doesNotRecomputeGeometryIfNotRequested) {
+ mOutputLayer.updateCompositionState(false);
+
+ EXPECT_EQ(false, mOutputLayer.getState().forceClientComposition);
+}
+
/*
* OutputLayer::writeStateToHWC()
*/
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 898f3bc..cae1b46 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -428,7 +428,7 @@
auto& parentState = parent->getDrawingState();
const int parentType = parentState.metadata.getInt32(METADATA_WINDOW_TYPE, 0);
const int parentAppId = parentState.metadata.getInt32(METADATA_OWNER_UID, 0);
- if (parentType >= 0 || parentAppId >= 0) {
+ if (parentType > 0 && parentAppId > 0) {
type = parentType;
appId = parentAppId;
}
diff --git a/services/vr/bufferhubd/producer_channel.cpp b/services/vr/bufferhubd/producer_channel.cpp
index a7fd912..b71964b 100644
--- a/services/vr/bufferhubd/producer_channel.cpp
+++ b/services/vr/bufferhubd/producer_channel.cpp
@@ -350,7 +350,7 @@
while (!buffer_state_->compare_exchange_weak(
current_buffer_state, updated_buffer_state, std::memory_order_acq_rel,
std::memory_order_acquire)) {
- ALOGI(
+ ALOGV(
"%s: Failed to post to the new consumer. "
"Current buffer state was changed to %" PRIx32
" when trying to acquire the buffer and modify the buffer state to "
diff --git a/services/vr/hardware_composer/impl/vr_hwc.cpp b/services/vr/hardware_composer/impl/vr_hwc.cpp
index fb7932d..7323277 100644
--- a/services/vr/hardware_composer/impl/vr_hwc.cpp
+++ b/services/vr/hardware_composer/impl/vr_hwc.cpp
@@ -994,6 +994,26 @@
vsync_callback_->SetEventCallback(send_vsync ? event_callback_ : nullptr);
}
+Return<void> VrHwc::debug(const hidl_handle& fd,
+ const hidl_vec<hidl_string>& args) {
+ std::string result;
+
+ {
+ std::lock_guard<std::mutex> guard(mutex_);
+ for (const auto& pair : displays_) {
+ result += StringPrintf("Display id: %d\n", static_cast<int>(pair.first));
+ pair.second->dumpDebugInfo(&result);
+ }
+ result += "\n";
+ }
+
+ FILE* out = fdopen(dup(fd->data[0]), "w");
+ fprintf(out, "%s", result.c_str());
+ fclose(out);
+
+ return Void();
+}
+
void HwcLayer::dumpDebugInfo(std::string* result) const {
if (!result) {
return;
diff --git a/services/vr/hardware_composer/impl/vr_hwc.h b/services/vr/hardware_composer/impl/vr_hwc.h
index e8c0212..15358c5 100644
--- a/services/vr/hardware_composer/impl/vr_hwc.h
+++ b/services/vr/hardware_composer/impl/vr_hwc.h
@@ -295,6 +295,9 @@
void RegisterObserver(Observer* observer) override;
void UnregisterObserver(Observer* observer) override;
+ Return<void> debug(const hidl_handle& fd,
+ const hidl_vec<hidl_string>& args) override;
+
private:
class VsyncCallback : public BnVsyncCallback {
public:
diff --git a/services/vr/virtual_touchpad/virtual_touchpad.rc b/services/vr/virtual_touchpad/virtual_touchpad.rc
index 99315ef..0de0f9e 100644
--- a/services/vr/virtual_touchpad/virtual_touchpad.rc
+++ b/services/vr/virtual_touchpad/virtual_touchpad.rc
@@ -1,5 +1,5 @@
service virtual_touchpad /system/bin/virtual_touchpad
class core
user system
- group system input
+ group system input uhid
writepid /dev/cpuset/system/tasks
diff --git a/vulkan/libvulkan/api_gen.cpp b/vulkan/libvulkan/api_gen.cpp
index df86af0..ad46c3b 100644
--- a/vulkan/libvulkan/api_gen.cpp
+++ b/vulkan/libvulkan/api_gen.cpp
@@ -16,12 +16,11 @@
// WARNING: This file is generated. See ../README.md for instructions.
+#include <log/log.h>
#include <string.h>
#include <algorithm>
-#include <log/log.h>
-
// to catch mismatches between vulkan.h and this file
#undef VK_NO_PROTOTYPES
#include "api.h"
diff --git a/vulkan/libvulkan/api_gen.h b/vulkan/libvulkan/api_gen.h
index 4bedbeb..f582224 100644
--- a/vulkan/libvulkan/api_gen.h
+++ b/vulkan/libvulkan/api_gen.h
@@ -20,7 +20,9 @@
#define LIBVULKAN_API_GEN_H
#include <vulkan/vulkan.h>
+
#include <bitset>
+
#include "driver_gen.h"
namespace vulkan {
diff --git a/vulkan/libvulkan/code-generator.tmpl b/vulkan/libvulkan/code-generator.tmpl
index bdd3573..940b747 100644
--- a/vulkan/libvulkan/code-generator.tmpl
+++ b/vulkan/libvulkan/code-generator.tmpl
@@ -37,8 +37,10 @@
#ifndef LIBVULKAN_API_GEN_H
#define LIBVULKAN_API_GEN_H
¶
-#include <bitset>
#include <vulkan/vulkan.h>
+¶
+#include <bitset>
+¶
#include "driver_gen.h"
¶
namespace vulkan {«
@@ -90,12 +92,11 @@
¶
// WARNING: This file is generated. See ../README.md for instructions.
¶
+#include <log/log.h>
#include <string.h>
¶
#include <algorithm>
¶
-#include <log/log.h>
-¶
// to catch mismatches between vulkan.h and this file
#undef VK_NO_PROTOTYPES
#include "api.h"
@@ -217,9 +218,10 @@
#ifndef LIBVULKAN_DRIVER_GEN_H
#define LIBVULKAN_DRIVER_GEN_H
¶
-#include <bitset>
-#include <vulkan/vulkan.h>
#include <vulkan/vk_android_native_buffer.h>
+#include <vulkan/vulkan.h>
+¶
+#include <bitset>
¶
namespace vulkan {«
namespace driver {«
@@ -271,12 +273,11 @@
¶
// WARNING: This file is generated. See ../README.md for instructions.
¶
+#include <log/log.h>
#include <string.h>
¶
#include <algorithm>
¶
-#include <log/log.h>
-¶
#include "driver.h"
¶
namespace vulkan {«
diff --git a/vulkan/libvulkan/driver_gen.cpp b/vulkan/libvulkan/driver_gen.cpp
index 574c327..7020be1 100644
--- a/vulkan/libvulkan/driver_gen.cpp
+++ b/vulkan/libvulkan/driver_gen.cpp
@@ -16,12 +16,11 @@
// WARNING: This file is generated. See ../README.md for instructions.
+#include <log/log.h>
#include <string.h>
#include <algorithm>
-#include <log/log.h>
-
#include "driver.h"
namespace vulkan {
diff --git a/vulkan/libvulkan/driver_gen.h b/vulkan/libvulkan/driver_gen.h
index 3faf6c0..c299549 100644
--- a/vulkan/libvulkan/driver_gen.h
+++ b/vulkan/libvulkan/driver_gen.h
@@ -21,6 +21,7 @@
#include <vulkan/vk_android_native_buffer.h>
#include <vulkan/vulkan.h>
+
#include <bitset>
namespace vulkan {
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index a8949d3..524fe0e 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -34,10 +34,6 @@
using android::hardware::graphics::common::V1_0::BufferUsage;
-// TODO(jessehall): Currently we don't have a good error code for when a native
-// window operation fails. Just returning INITIALIZATION_FAILED for now. Later
-// versions (post SDK 0.9) of the API/extension have a better error code.
-// When updating to that version, audit all error returns.
namespace vulkan {
namespace driver {
@@ -48,29 +44,12 @@
VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR |
VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR |
VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR |
- // TODO(jessehall): See TODO in TranslateNativeToVulkanTransform.
- // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR |
- // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR |
- // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR |
- // VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR |
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR |
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR |
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR |
+ VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR |
VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR;
-int TranslateVulkanToNativeTransform(VkSurfaceTransformFlagBitsKHR transform) {
- switch (transform) {
- // TODO: See TODO in TranslateNativeToVulkanTransform
- case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR:
- return NATIVE_WINDOW_TRANSFORM_ROT_90;
- case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR:
- return NATIVE_WINDOW_TRANSFORM_ROT_180;
- case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR:
- return NATIVE_WINDOW_TRANSFORM_ROT_270;
- case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR:
- case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR:
- default:
- return 0;
- }
-}
-
VkSurfaceTransformFlagBitsKHR TranslateNativeToVulkanTransform(int native) {
// Native and Vulkan transforms are isomorphic, but are represented
// differently. Vulkan transforms are built up of an optional horizontal
@@ -78,27 +57,22 @@
// transforms are built up from a horizontal flip, vertical flip, and
// 90-degree rotation, all optional but always in that order.
- // TODO(jessehall): For now, only support pure rotations, not
- // flip or flip-and-rotate, until I have more time to test them and build
- // sample code. As far as I know we never actually use anything besides
- // pure rotations anyway.
-
switch (native) {
- case 0: // 0x0
+ case 0:
return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
- // case NATIVE_WINDOW_TRANSFORM_FLIP_H: // 0x1
- // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR;
- // case NATIVE_WINDOW_TRANSFORM_FLIP_V: // 0x2
- // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR;
- case NATIVE_WINDOW_TRANSFORM_ROT_180: // FLIP_H | FLIP_V
+ case NATIVE_WINDOW_TRANSFORM_FLIP_H:
+ return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR;
+ case NATIVE_WINDOW_TRANSFORM_FLIP_V:
+ return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR;
+ case NATIVE_WINDOW_TRANSFORM_ROT_180:
return VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR;
- case NATIVE_WINDOW_TRANSFORM_ROT_90: // 0x4
+ case NATIVE_WINDOW_TRANSFORM_ROT_90:
return VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR;
- // case NATIVE_WINDOW_TRANSFORM_FLIP_H | NATIVE_WINDOW_TRANSFORM_ROT_90:
- // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR;
- // case NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_ROT_90:
- // return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR;
- case NATIVE_WINDOW_TRANSFORM_ROT_270: // FLIP_H | FLIP_V | ROT_90
+ case NATIVE_WINDOW_TRANSFORM_FLIP_H | NATIVE_WINDOW_TRANSFORM_ROT_90:
+ return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR;
+ case NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_ROT_90:
+ return VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR;
+ case NATIVE_WINDOW_TRANSFORM_ROT_270:
return VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR;
case NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY:
default:
@@ -106,6 +80,31 @@
}
}
+int TranslateVulkanToNativeTransform(VkSurfaceTransformFlagBitsKHR transform) {
+ switch (transform) {
+ case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_ROT_90;
+ case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_ROT_180;
+ case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_ROT_270;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_H;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_H |
+ NATIVE_WINDOW_TRANSFORM_ROT_90;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_V;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_V |
+ NATIVE_WINDOW_TRANSFORM_ROT_90;
+ case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR:
+ case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR:
+ default:
+ return 0;
+ }
+}
+
int InvertTransformToNative(VkSurfaceTransformFlagBitsKHR transform) {
switch (transform) {
case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR:
@@ -114,17 +113,16 @@
return NATIVE_WINDOW_TRANSFORM_ROT_180;
case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR:
return NATIVE_WINDOW_TRANSFORM_ROT_90;
- // TODO(jessehall): See TODO in TranslateNativeToVulkanTransform.
- // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR:
- // return NATIVE_WINDOW_TRANSFORM_FLIP_H;
- // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR:
- // return NATIVE_WINDOW_TRANSFORM_FLIP_H |
- // NATIVE_WINDOW_TRANSFORM_ROT_90;
- // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR:
- // return NATIVE_WINDOW_TRANSFORM_FLIP_V;
- // case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR:
- // return NATIVE_WINDOW_TRANSFORM_FLIP_V |
- // NATIVE_WINDOW_TRANSFORM_ROT_90;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_H;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_H |
+ NATIVE_WINDOW_TRANSFORM_ROT_90;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_V;
+ case VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR:
+ return NATIVE_WINDOW_TRANSFORM_FLIP_V |
+ NATIVE_WINDOW_TRANSFORM_ROT_90;
case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR:
case VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR:
default:
@@ -201,8 +199,6 @@
{ NATIVE_WINDOW_TIMESTAMP_PENDING };
};
-// ----------------------------------------------------------------------------
-
struct Surface {
android::sp<ANativeWindow> window;
VkSwapchainKHR swapchain_handle;
@@ -285,6 +281,8 @@
ANativeWindow* window,
int release_fence,
Swapchain::Image& image) {
+ ATRACE_CALL();
+
ALOG_ASSERT(release_fence == -1 || image.dequeued,
"ReleaseSwapchainImage: can't provide a release fence for "
"non-dequeued images");
@@ -323,7 +321,9 @@
}
if (image.image) {
+ ATRACE_BEGIN("DestroyImage");
GetData(device).driver.DestroyImage(device, image.image, nullptr);
+ ATRACE_END();
image.image = VK_NULL_HANDLE;
}
@@ -539,15 +539,12 @@
strerror(-err), err);
surface->~Surface();
allocator->pfnFree(allocator->pUserData, surface);
- return VK_ERROR_INITIALIZATION_FAILED;
+ return VK_ERROR_SURFACE_LOST_KHR;
}
- // TODO(jessehall): Create and use NATIVE_WINDOW_API_VULKAN.
err =
native_window_api_connect(surface->window.get(), NATIVE_WINDOW_API_EGL);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_api_connect() failed: %s (%d)", strerror(-err),
err);
surface->~Surface();
@@ -656,7 +653,6 @@
return VK_ERROR_SURFACE_LOST_KHR;
}
- // TODO(jessehall): Figure out what the min/max values should be.
int max_buffer_count;
err = window->query(window, NATIVE_WINDOW_MAX_BUFFER_COUNT, &max_buffer_count);
if (err != 0) {
@@ -670,8 +666,7 @@
capabilities->currentExtent =
VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
- // TODO(jessehall): Figure out what the max extent should be. Maximum
- // texture dimension maybe?
+ // TODO(http://b/134182502): Figure out what the max extent should be.
capabilities->minImageExtent = VkExtent2D{1, 1};
capabilities->maxImageExtent = VkExtent2D{4096, 4096};
@@ -685,11 +680,6 @@
// associated with the bufferqueue. It can't be changed from here.
capabilities->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
- // TODO(jessehall): I think these are right, but haven't thought hard about
- // it. Do we need to query the driver for support of any of these?
- // Currently not included:
- // - VK_IMAGE_USAGE_DEPTH_STENCIL_BIT: definitely not
- // - VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT: definitely not
capabilities->supportedUsageFlags =
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
@@ -729,8 +719,7 @@
int err = native_window_get_wide_color_support(surface.window.get(),
&wide_color_support);
if (err) {
- // Not allowed to return a more sensible error code, so do this
- return VK_ERROR_OUT_OF_HOST_MEMORY;
+ return VK_ERROR_SURFACE_LOST_KHR;
}
ALOGV("wide_color_support is: %d", wide_color_support);
wide_color_support =
@@ -978,6 +967,40 @@
return VK_SUCCESS;
}
+static void DestroySwapchainInternal(VkDevice device,
+ VkSwapchainKHR swapchain_handle,
+ const VkAllocationCallbacks* allocator) {
+ ATRACE_CALL();
+
+ const auto& dispatch = GetData(device).driver;
+ Swapchain* swapchain = SwapchainFromHandle(swapchain_handle);
+ if (!swapchain) {
+ return;
+ }
+
+ bool active = swapchain->surface.swapchain_handle == swapchain_handle;
+ ANativeWindow* window = active ? swapchain->surface.window.get() : nullptr;
+
+ if (window && swapchain->frame_timestamps_enabled) {
+ native_window_enable_frame_timestamps(window, false);
+ }
+
+ for (uint32_t i = 0; i < swapchain->num_images; i++) {
+ ReleaseSwapchainImage(device, window, -1, swapchain->images[i]);
+ }
+
+ if (active) {
+ swapchain->surface.swapchain_handle = VK_NULL_HANDLE;
+ }
+
+ if (!allocator) {
+ allocator = &GetData(device).allocator;
+ }
+
+ swapchain->~Swapchain();
+ allocator->pfnFree(allocator->pUserData, swapchain);
+}
+
VKAPI_ATTR
VkResult CreateSwapchainKHR(VkDevice device,
const VkSwapchainCreateInfoKHR* create_info,
@@ -1052,6 +1075,8 @@
// non-FREE state at any given time. Disconnecting and re-connecting
// orphans the previous buffers, getting us back to the state where we can
// dequeue all buffers.
+ //
+ // TODO(http://b/134186185) recycle swapchain images more efficiently
err = native_window_api_disconnect(surface.window.get(),
NATIVE_WINDOW_API_EGL);
ALOGW_IF(err != 0, "native_window_api_disconnect failed: %s (%d)",
@@ -1072,8 +1097,6 @@
create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR ? 0 : 1;
err = surface.window->setSwapInterval(surface.window.get(), swap_interval);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window->setSwapInterval(1) failed: %s (%d)",
strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1100,8 +1123,6 @@
err = native_window_set_buffers_format(surface.window.get(),
native_pixel_format);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_buffers_format(%d) failed: %s (%d)",
native_pixel_format, strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1109,8 +1130,6 @@
err = native_window_set_buffers_data_space(surface.window.get(),
native_dataspace);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_buffers_data_space(%d) failed: %s (%d)",
native_dataspace, strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1120,8 +1139,6 @@
surface.window.get(), static_cast<int>(create_info->imageExtent.width),
static_cast<int>(create_info->imageExtent.height));
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_buffers_dimensions(%d,%d) failed: %s (%d)",
create_info->imageExtent.width, create_info->imageExtent.height,
strerror(-err), err);
@@ -1140,8 +1157,6 @@
surface.window.get(),
InvertTransformToNative(create_info->preTransform));
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_buffers_transform(%d) failed: %s (%d)",
InvertTransformToNative(create_info->preTransform),
strerror(-err), err);
@@ -1151,8 +1166,6 @@
err = native_window_set_scaling_mode(
surface.window.get(), NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_scaling_mode(SCALE_TO_WINDOW) failed: %s (%d)",
strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1182,8 +1195,6 @@
NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
&query_value);
if (err != 0 || query_value < 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("window->query failed: %s (%d) value=%d", strerror(-err), err,
query_value);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1201,8 +1212,6 @@
// can't actually use!).
err = native_window_set_buffer_count(surface.window.get(), std::max(2u, num_images));
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_buffer_count(%d) failed: %s (%d)", num_images,
strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
@@ -1211,7 +1220,7 @@
int32_t legacy_usage = 0;
if (dispatch.GetSwapchainGrallocUsage2ANDROID) {
uint64_t consumer_usage, producer_usage;
- ATRACE_BEGIN("dispatch.GetSwapchainGrallocUsage2ANDROID");
+ ATRACE_BEGIN("GetSwapchainGrallocUsage2ANDROID");
result = dispatch.GetSwapchainGrallocUsage2ANDROID(
device, create_info->imageFormat, create_info->imageUsage,
swapchain_image_usage, &consumer_usage, &producer_usage);
@@ -1223,7 +1232,7 @@
legacy_usage =
android_convertGralloc1To0Usage(producer_usage, consumer_usage);
} else if (dispatch.GetSwapchainGrallocUsageANDROID) {
- ATRACE_BEGIN("dispatch.GetSwapchainGrallocUsageANDROID");
+ ATRACE_BEGIN("GetSwapchainGrallocUsageANDROID");
result = dispatch.GetSwapchainGrallocUsageANDROID(
device, create_info->imageFormat, create_info->imageUsage,
&legacy_usage);
@@ -1242,8 +1251,6 @@
}
err = native_window_set_usage(surface.window.get(), native_usage);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("native_window_set_usage failed: %s (%d)", strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
}
@@ -1301,8 +1308,6 @@
err = surface.window->dequeueBuffer(surface.window.get(), &buffer,
&img.dequeue_fence);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate
- // possible errors and translate them to valid Vulkan result codes?
ALOGE("dequeueBuffer[%u] failed: %s (%d)", i, strerror(-err), err);
result = VK_ERROR_SURFACE_LOST_KHR;
break;
@@ -1322,7 +1327,7 @@
&image_native_buffer.usage2.producer,
&image_native_buffer.usage2.consumer);
- ATRACE_BEGIN("dispatch.CreateImage");
+ ATRACE_BEGIN("CreateImage");
result =
dispatch.CreateImage(device, &image_create, nullptr, &img.image);
ATRACE_END();
@@ -1335,9 +1340,6 @@
// -- Cancel all buffers, returning them to the queue --
// If an error occurred before, also destroy the VkImage and release the
// buffer reference. Otherwise, we retain a strong reference to the buffer.
- //
- // TODO(jessehall): The error path here is the same as DestroySwapchain,
- // but not the non-error path. Should refactor/unify.
for (uint32_t i = 0; i < num_images; i++) {
Swapchain::Image& img = swapchain->images[i];
if (img.dequeued) {
@@ -1348,18 +1350,11 @@
img.dequeued = false;
}
}
- if (result != VK_SUCCESS) {
- if (img.image) {
- ATRACE_BEGIN("dispatch.DestroyImage");
- dispatch.DestroyImage(device, img.image, nullptr);
- ATRACE_END();
- }
- }
}
if (result != VK_SUCCESS) {
- swapchain->~Swapchain();
- allocator->pfnFree(allocator->pUserData, swapchain);
+ DestroySwapchainInternal(device, HandleFromSwapchain(swapchain),
+ allocator);
return result;
}
@@ -1374,24 +1369,7 @@
const VkAllocationCallbacks* allocator) {
ATRACE_CALL();
- const auto& dispatch = GetData(device).driver;
- Swapchain* swapchain = SwapchainFromHandle(swapchain_handle);
- if (!swapchain)
- return;
- bool active = swapchain->surface.swapchain_handle == swapchain_handle;
- ANativeWindow* window = active ? swapchain->surface.window.get() : nullptr;
-
- if (swapchain->frame_timestamps_enabled) {
- native_window_enable_frame_timestamps(window, false);
- }
- for (uint32_t i = 0; i < swapchain->num_images; i++)
- ReleaseSwapchainImage(device, window, -1, swapchain->images[i]);
- if (active)
- swapchain->surface.swapchain_handle = VK_NULL_HANDLE;
- if (!allocator)
- allocator = &GetData(device).allocator;
- swapchain->~Swapchain();
- allocator->pfnFree(allocator->pUserData, swapchain);
+ DestroySwapchainInternal(device, swapchain_handle, allocator);
}
VKAPI_ATTR
@@ -1457,8 +1435,6 @@
int fence_fd;
err = window->dequeueBuffer(window, &buffer, &fence_fd);
if (err != 0) {
- // TODO(jessehall): Improve error reporting. Can we enumerate possible
- // errors and translate them to valid Vulkan result codes?
ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), err);
return VK_ERROR_SURFACE_LOST_KHR;
}
@@ -1513,8 +1489,6 @@
uint32_t* pImageIndex) {
ATRACE_CALL();
- // TODO: this should actually be the other way around and this function
- // should handle any additional structures that get passed in
return AcquireNextImageKHR(device, pAcquireInfo->swapchain,
pAcquireInfo->timeout, pAcquireInfo->semaphore,
pAcquireInfo->fence, pImageIndex);
@@ -1692,17 +1666,16 @@
err = window->queueBuffer(window, img.buffer.get(), fence);
// queueBuffer always closes fence, even on error
if (err != 0) {
- // TODO(jessehall): What now? We should probably cancel the
- // buffer, I guess?
ALOGE("queueBuffer failed: %s (%d)", strerror(-err), err);
swapchain_result = WorstPresentResult(
swapchain_result, VK_ERROR_OUT_OF_DATE_KHR);
+ } else {
+ if (img.dequeue_fence >= 0) {
+ close(img.dequeue_fence);
+ img.dequeue_fence = -1;
+ }
+ img.dequeued = false;
}
- if (img.dequeue_fence >= 0) {
- close(img.dequeue_fence);
- img.dequeue_fence = -1;
- }
- img.dequeued = false;
// If the swapchain is in shared mode, immediately dequeue the
// buffer so it can be presented again without an intervening
@@ -1729,7 +1702,6 @@
}
}
if (swapchain_result != VK_SUCCESS) {
- ReleaseSwapchainImage(device, window, fence, img);
OrphanSwapchain(device, &swapchain);
}
int window_transform_hint;
diff --git a/vulkan/nulldrv/null_driver.tmpl b/vulkan/nulldrv/null_driver.tmpl
index ce15517..0f53015 100644
--- a/vulkan/nulldrv/null_driver.tmpl
+++ b/vulkan/nulldrv/null_driver.tmpl
@@ -97,9 +97,10 @@
¶
// WARNING: This file is generated. See ../README.md for instructions.
¶
-#include "null_driver_gen.h"
#include <algorithm>
¶
+#include "null_driver_gen.h"
+¶
using namespace null_driver;
¶
namespace {
diff --git a/vulkan/nulldrv/null_driver_gen.cpp b/vulkan/nulldrv/null_driver_gen.cpp
index 92b7468..b8d7d2b 100644
--- a/vulkan/nulldrv/null_driver_gen.cpp
+++ b/vulkan/nulldrv/null_driver_gen.cpp
@@ -17,6 +17,7 @@
// WARNING: This file is generated. See ../README.md for instructions.
#include <algorithm>
+
#include "null_driver_gen.h"
using namespace null_driver;