Merge "Fix ASharedMemory doxygen formatting, add availability." am: 519485d161
am: 036335d276
Change-Id: Ieb3b9f3b543bf8d93fa616b98adb04a29ddbc768
diff --git a/data/etc/aosp_excluded_hardware.xml b/data/etc/aosp_excluded_hardware.xml
index 013f278..c12f435 100644
--- a/data/etc/aosp_excluded_hardware.xml
+++ b/data/etc/aosp_excluded_hardware.xml
@@ -18,4 +18,5 @@
<!-- This should be used to exclude this feature from aosp targets. As aosp configurations
may or may not have a valid location provider -->
<unavailable-feature name="android.hardware.location.network" />
+ <unavailable-feature name="android.software.device_id_attestation" />
</permissions>
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index 43346fe..11f8f6b 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -30,8 +30,6 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 24
-
struct AChoreographer;
typedef struct AChoreographer AChoreographer;
@@ -49,23 +47,23 @@
* Get the AChoreographer instance for the current thread. This must be called
* on an ALooper thread.
*/
-AChoreographer* AChoreographer_getInstance();
+AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24);
/**
* Post a callback to be run on the next frame. The data pointer provided will
* be passed to the callback function when it's called.
*/
void AChoreographer_postFrameCallback(AChoreographer* choreographer,
- AChoreographer_frameCallback callback, void* data);
+ AChoreographer_frameCallback callback, void* data) __INTRODUCED_IN(24);
+
/**
* Post a callback to be run on the frame following the specified delay. The
* data pointer provided will be passed to the callback function when it's
* called.
*/
void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
- AChoreographer_frameCallback callback, void* data, long delayMillis);
-
-#endif /* __ANDROID_API__ >= 24 */
+ AChoreographer_frameCallback callback, void* data,
+ long delayMillis) __INTRODUCED_IN(24);
__END_DECLS
diff --git a/include/android/configuration.h b/include/android/configuration.h
index 6287332..81aedca 100644
--- a/include/android/configuration.h
+++ b/include/android/configuration.h
@@ -30,6 +30,10 @@
#include <android/asset_manager.h>
+#if !defined(__INTRODUCED_IN)
+#define __INTRODUCED_IN(__api_level) /* nothing */
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -671,53 +675,49 @@
*/
void AConfiguration_setUiModeNight(AConfiguration* config, int32_t uiModeNight);
-#if __ANDROID_API__ >= 13
/**
* Return the current configuration screen width in dp units, or
* ACONFIGURATION_SCREEN_WIDTH_DP_ANY if not set.
*/
-int32_t AConfiguration_getScreenWidthDp(AConfiguration* config);
+int32_t AConfiguration_getScreenWidthDp(AConfiguration* config) __INTRODUCED_IN(13);
/**
* Set the configuration's current screen width in dp units.
*/
-void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value);
+void AConfiguration_setScreenWidthDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13);
/**
* Return the current configuration screen height in dp units, or
* ACONFIGURATION_SCREEN_HEIGHT_DP_ANY if not set.
*/
-int32_t AConfiguration_getScreenHeightDp(AConfiguration* config);
+int32_t AConfiguration_getScreenHeightDp(AConfiguration* config) __INTRODUCED_IN(13);
/**
* Set the configuration's current screen width in dp units.
*/
-void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value);
+void AConfiguration_setScreenHeightDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13);
/**
* Return the configuration's smallest screen width in dp units, or
* ACONFIGURATION_SMALLEST_SCREEN_WIDTH_DP_ANY if not set.
*/
-int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config);
+int32_t AConfiguration_getSmallestScreenWidthDp(AConfiguration* config) __INTRODUCED_IN(13);
/**
* Set the configuration's smallest screen width in dp units.
*/
-void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value);
-#endif /* __ANDROID_API__ >= 13 */
+void AConfiguration_setSmallestScreenWidthDp(AConfiguration* config, int32_t value) __INTRODUCED_IN(13);
-#if __ANDROID_API__ >= 17
/**
* Return the configuration's layout direction, or
* ACONFIGURATION_LAYOUTDIR_ANY if not set.
*/
-int32_t AConfiguration_getLayoutDirection(AConfiguration* config);
+int32_t AConfiguration_getLayoutDirection(AConfiguration* config) __INTRODUCED_IN(17);
/**
* Set the configuration's layout direction.
*/
-void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value);
-#endif /* __ANDROID_API__ >= 17 */
+void AConfiguration_setLayoutDirection(AConfiguration* config, int32_t value) __INTRODUCED_IN(17);
/**
* Perform a diff between two configurations. Returns a bit mask of
diff --git a/include/android/input.h b/include/android/input.h
index 0829989..1e49b7a 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -56,6 +56,10 @@
#include <android/keycodes.h>
#include <android/looper.h>
+#if !defined(__INTRODUCED_IN)
+#define __INTRODUCED_IN(__api_level) /* nothing */
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -982,10 +986,8 @@
*/
int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
-#if __ANDROID_API__ >= 14
/** Get the button state of all buttons that are pressed. */
-int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event);
-#endif
+int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) __INTRODUCED_IN(14);
/**
* Get a bitfield indicating which edges, if any, were touched by this motion event.
@@ -1050,14 +1052,12 @@
*/
int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
-#if __ANDROID_API__ >= 14
/**
* Get the tool type of a pointer for the given pointer index.
* The tool type indicates the type of tool used to make contact such as a
* finger or stylus, if known.
*/
-int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index);
-#endif
+int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) __INTRODUCED_IN(14);
/**
* Get the original raw X coordinate of this event.
@@ -1147,11 +1147,9 @@
*/
float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
-#if __ANDROID_API__ >= 13
/** Get the value of the request axis for the given pointer index. */
float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
- int32_t axis, size_t pointer_index);
-#endif
+ int32_t axis, size_t pointer_index) __INTRODUCED_IN(13);
/**
* Get the number of historical points in this event. These are movements that
@@ -1282,14 +1280,12 @@
float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
size_t history_index);
-#if __ANDROID_API__ >= 13
/**
* Get the historical value of the request axis for the given pointer index
* that occurred between this event and the previous motion event.
*/
float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
- int32_t axis, size_t pointer_index, size_t history_index);
-#endif
+ int32_t axis, size_t pointer_index, size_t history_index) __INTRODUCED_IN(13);
struct AInputQueue;
diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h
index 5f2a57f..55df9f8 100644
--- a/include/android/multinetwork.h
+++ b/include/android/multinetwork.h
@@ -60,8 +60,6 @@
* on failure with an appropriate errno value set.
*/
-#if __ANDROID_API__ >= 24
-
/**
* Set the network to be used by the given socket file descriptor.
*
@@ -70,7 +68,7 @@
* This is the equivalent of: [android.net.Network#bindSocket()](https://developer.android.com/reference/android/net/Network.html#bindSocket(java.net.Socket))
*
*/
-int android_setsocknetwork(net_handle_t network, int fd);
+int android_setsocknetwork(net_handle_t network, int fd) __INTRODUCED_IN(23);
/**
@@ -87,7 +85,7 @@
* This is the equivalent of: [android.net.ConnectivityManager#setProcessDefaultNetwork()](https://developer.android.com/reference/android/net/ConnectivityManager.html#setProcessDefaultNetwork(android.net.Network))
*
*/
-int android_setprocnetwork(net_handle_t network);
+int android_setprocnetwork(net_handle_t network) __INTRODUCED_IN(23);
/**
@@ -106,9 +104,7 @@
*/
int android_getaddrinfofornetwork(net_handle_t network,
const char *node, const char *service,
- const struct addrinfo *hints, struct addrinfo **res);
-
-#endif /* __ANDROID_API__ >= 24 */
+ const struct addrinfo *hints, struct addrinfo **res) __INTRODUCED_IN(23);
__END_DECLS
diff --git a/include/android/native_window_jni.h b/include/android/native_window_jni.h
index 082fab2..74e43c7 100644
--- a/include/android/native_window_jni.h
+++ b/include/android/native_window_jni.h
@@ -44,7 +44,6 @@
*/
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface);
-#if __ANDROID_API__ >= 26
/**
* Return a Java Surface object derived from the ANativeWindow, for interacting
* with it through Java code. The returned Java object acquires a reference on
@@ -52,8 +51,7 @@
* and will automatically release the reference when the Java object gets garbage
* collected.
*/
-jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window);
-#endif
+jobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) __INTRODUCED_IN(26);
#ifdef __cplusplus
};
diff --git a/include/android/sensor.h b/include/android/sensor.h
index 191777c..59229c1 100644
--- a/include/android/sensor.h
+++ b/include/android/sensor.h
@@ -478,7 +478,6 @@
ASensorManager* ASensorManager_getInstance();
#endif
-#if __ANDROID_API__ >= __ANDROID_API_O__
/**
* Get a reference to the sensor manager. ASensorManager is a singleton
* per package as different packages may have access to different sensors.
@@ -488,8 +487,7 @@
* ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
*
*/
-ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName);
-#endif
+ASensorManager* ASensorManager_getInstanceForPackage(const char* packageName) __INTRODUCED_IN(26);
/**
* Returns the list of available sensors.
@@ -502,13 +500,11 @@
*/
ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type);
-#if __ANDROID_API__ >= 21
/**
* Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
* of this type and wakeUp properties exists.
*/
-ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp);
-#endif
+ASensor const* ASensorManager_getDefaultSensorEx(ASensorManager* manager, int type, bool wakeUp) __INTRODUCED_IN(21);
/**
* Creates a new sensor event queue and associate it with a looper.
@@ -525,7 +521,6 @@
*/
int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue);
-#if __ANDROID_API__ >= __ANDROID_API_O__
/**
* Create direct channel based on shared memory
*
@@ -542,7 +537,7 @@
* {@link ASensorManager_destroyDirectChannel} and
* {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
*/
-int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size);
+int ASensorManager_createSharedMemoryDirectChannel(ASensorManager* manager, int fd, size_t size) __INTRODUCED_IN(26);
/**
* Create direct channel based on AHardwareBuffer
@@ -560,7 +555,7 @@
* {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
*/
int ASensorManager_createHardwareBufferDirectChannel(
- ASensorManager* manager, AHardwareBuffer const * buffer, size_t size);
+ ASensorManager* manager, AHardwareBuffer const * buffer, size_t size) __INTRODUCED_IN(26);
/**
* Destroy a direct channel
@@ -575,7 +570,7 @@
* {@link ASensorManager_createSharedMemoryDirectChannel} or
* {@link ASensorManager_createHardwareBufferDirectChannel}.
*/
-void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId);
+void ASensorManager_destroyDirectChannel(ASensorManager* manager, int channelId) __INTRODUCED_IN(26);
/**
* Configure direct report on channel
@@ -612,9 +607,8 @@
*
* \return positive token for success or negative error code.
*/
-int ASensorManager_configureDirectReport(
- ASensorManager* manager, ASensor const* sensor, int channelId, int rate);
-#endif
+int ASensorManager_configureDirectReport(ASensorManager* manager,
+ ASensor const* sensor, int channelId, int rate) __INTRODUCED_IN(26);
/*****************************************************************************/
@@ -733,35 +727,32 @@
*/
int ASensor_getMinDelay(ASensor const* sensor);
-#if __ANDROID_API__ >= 21
/**
* Returns the maximum size of batches for this sensor. Batches will often be
* smaller, as the hardware fifo might be used for other sensors.
*/
-int ASensor_getFifoMaxEventCount(ASensor const* sensor);
+int ASensor_getFifoMaxEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
/**
* Returns the hardware batch fifo size reserved to this sensor.
*/
-int ASensor_getFifoReservedEventCount(ASensor const* sensor);
+int ASensor_getFifoReservedEventCount(ASensor const* sensor) __INTRODUCED_IN(21);
/**
* Returns this sensor's string type.
*/
-const char* ASensor_getStringType(ASensor const* sensor);
+const char* ASensor_getStringType(ASensor const* sensor) __INTRODUCED_IN(21);
/**
* Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
*/
-int ASensor_getReportingMode(ASensor const* sensor);
+int ASensor_getReportingMode(ASensor const* sensor) __INTRODUCED_IN(21);
/**
* Returns true if this is a wake up sensor, false otherwise.
*/
-bool ASensor_isWakeUpSensor(ASensor const* sensor);
-#endif /* __ANDROID_API__ >= 21 */
+bool ASensor_isWakeUpSensor(ASensor const* sensor) __INTRODUCED_IN(21);
-#if __ANDROID_API__ >= __ANDROID_API_O__
/**
* Test if sensor supports a certain type of direct channel.
*
@@ -771,7 +762,8 @@
* or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
* \returns true if sensor supports the specified direct channel type.
*/
-bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType);
+bool ASensor_isDirectChannelTypeSupported(ASensor const* sensor, int channelType) __INTRODUCED_IN(26);
+
/**
* Get the highest direct rate level that a sensor support.
*
@@ -781,8 +773,7 @@
* If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
* does not support direct report.
*/
-int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor);
-#endif
+int ASensor_getHighestDirectReportRateLevel(ASensor const* sensor) __INTRODUCED_IN(26);
#ifdef __cplusplus
};
diff --git a/include/android/sharedmem.h b/include/android/sharedmem.h
index 107de64..5a4f695 100644
--- a/include/android/sharedmem.h
+++ b/include/android/sharedmem.h
@@ -49,8 +49,6 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= __ANDROID_API_O__
-
/**
* Create a shared memory region.
*
@@ -66,7 +64,7 @@
* \param size size of the shared memory region
* \return file descriptor that denotes the shared memory; error code on failure.
*/
-int ASharedMemory_create(const char *name, size_t size);
+int ASharedMemory_create(const char *name, size_t size) __INTRODUCED_IN(26);
/**
* Get the size of the shared memory region.
@@ -76,7 +74,7 @@
* \param fd file descriptor of the shared memory region
* \return size in bytes; 0 if fd is not a valid shared memory file descriptor.
*/
-size_t ASharedMemory_getSize(int fd);
+size_t ASharedMemory_getSize(int fd) __INTRODUCED_IN(26);
/**
* Restrict access of shared memory region.
@@ -109,9 +107,7 @@
* updated access. Note access can only be removed, but not added back.
* \return 0 for success, error code on failure.
*/
-int ASharedMemory_setProt(int fd, int prot);
-
-#endif
+int ASharedMemory_setProt(int fd, int prot) __INTRODUCED_IN(26);
#ifdef __cplusplus
};
diff --git a/include/android/sharedmem_jni.h b/include/android/sharedmem_jni.h
index 2af3955..5abc245 100644
--- a/include/android/sharedmem_jni.h
+++ b/include/android/sharedmem_jni.h
@@ -51,8 +51,6 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= __ANDROID_API_O_MR1__
-
/**
* Returns a dup'd FD from the given Java android.os.SharedMemory object. The returned file
* descriptor has all the same properties & capabilities as the FD returned from
@@ -69,9 +67,7 @@
* already closed, if the JNIEnv or jobject is NULL, or if there are too many open file
* descriptors (errno=EMFILE)
*/
-int ASharedMemory_dupFromJava(JNIEnv* env, jobject sharedMemory);
-
-#endif
+int ASharedMemory_dupFromJava(JNIEnv* env, jobject sharedMemory) __INTRODUCED_IN(27);
#ifdef __cplusplus
};
diff --git a/include/android/surface_texture.h b/include/android/surface_texture.h
index 56b3342..db10a16 100644
--- a/include/android/surface_texture.h
+++ b/include/android/surface_texture.h
@@ -64,7 +64,7 @@
* Failing to do so will result in leaked memory and graphic resources.
* \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture()
*/
-void ASurfaceTexture_release(ASurfaceTexture* st);
+void ASurfaceTexture_release(ASurfaceTexture* st) __INTRODUCED_IN(28);
/**
* Returns a reference to an ANativeWindow (i.e. the Producer) for this SurfaceTexture.
@@ -75,7 +75,7 @@
* using ANativeWindow_release(). Failing to do so will result in leaked resources. nullptr is
* returned if \st is null or if it's not an instance of android.graphics.SurfaceTexture
*/
-ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st);
+ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st) __INTRODUCED_IN(28);
/**
* Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread. A
@@ -92,7 +92,7 @@
* must be unusued in the OpenGL ES context that is current on the calling thread.
* \return 0 on success, negative posix error code otherwise (see <errno.h>)
*/
-int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t texName);
+int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t texName) __INTRODUCED_IN(28);
/**
* Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object.
@@ -108,7 +108,7 @@
* \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture()
* \return 0 on success, negative posix error code otherwise (see <errno.h>)
*/
-int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st);
+int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st) __INTRODUCED_IN(28);
/**
* Update the texture image to the most recent frame from the image stream. This may only be
@@ -118,7 +118,7 @@
* \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture()
* \return 0 on success, negative posix error code otherwise (see <errno.h>)
*/
-int ASurfaceTexture_updateTexImage(ASurfaceTexture* st);
+int ASurfaceTexture_updateTexImage(ASurfaceTexture* st) __INTRODUCED_IN(28);
/**
* Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by
@@ -136,7 +136,7 @@
* \param mtx the array into which the 4x4 matrix will be stored. The array must have exactly
* 16 elements.
*/
-void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]);
+void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) __INTRODUCED_IN(28);
/**
* Retrieve the timestamp associated with the texture image set by the most recent call to
@@ -155,7 +155,7 @@
*
* \param st A ASurfaceTexture reference acquired with ASurfaceTexture_fromSurfaceTexture()
*/
-int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st);
+int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) __INTRODUCED_IN(28);
__END_DECLS
diff --git a/include/android/trace.h b/include/android/trace.h
index 99b3f82..0c44732 100644
--- a/include/android/trace.h
+++ b/include/android/trace.h
@@ -39,15 +39,13 @@
extern "C" {
#endif
-#if __ANDROID_API__ >= 23
-
/**
* Returns true if tracing is enabled. Use this to avoid expensive computation only necessary
* when tracing is enabled.
*
* Available since API level 23.
*/
-bool ATrace_isEnabled();
+bool ATrace_isEnabled() __INTRODUCED_IN(23);
/**
* Writes a tracing message to indicate that the given section of code has begun. This call must be
@@ -59,7 +57,7 @@
*
* Available since API level 23.
*/
-void ATrace_beginSection(const char* sectionName);
+void ATrace_beginSection(const char* sectionName) __INTRODUCED_IN(23);
/**
* Writes a tracing message to indicate that a given section of code has ended. This call must be
@@ -69,9 +67,7 @@
*
* Available since API level 23.
*/
-void ATrace_endSection();
-
-#endif /* __ANDROID_API__ >= 23 */
+void ATrace_endSection() __INTRODUCED_IN(23);
#ifdef __cplusplus
};
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 17e098c..d0ed31e 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -149,12 +149,13 @@
const bool isVendorService =
strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0;
const long timeout = uptimeMillis() + 5000;
- if (!gSystemBootCompleted) {
+ if (!gSystemBootCompleted && !isVendorService) {
+ // Vendor code can't access system properties
char bootCompleted[PROPERTY_VALUE_MAX];
property_get("sys.boot_completed", bootCompleted, "0");
gSystemBootCompleted = strcmp(bootCompleted, "1") == 0 ? true : false;
}
- // retry interval in millisecond.
+ // retry interval in millisecond; note that vendor services stay at 100ms
const long sleepTime = gSystemBootCompleted ? 1000 : 100;
int n = 0;
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index c8021e4..c96a2dd 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -381,7 +381,6 @@
{ // Autolock scope
Mutex::Autolock lock(mCore->mMutex);
- mCore->waitWhileAllocatingLocked();
if (format == 0) {
format = mCore->mDefaultBufferFormat;
@@ -1345,7 +1344,9 @@
return;
}
- newBufferCount = mCore->mFreeSlots.size();
+ // Only allocate one buffer at a time to reduce risks of overlapping an allocation from
+ // both allocateBuffers and dequeueBuffer.
+ newBufferCount = mCore->mFreeSlots.empty() ? 0 : 1;
if (newBufferCount == 0) {
return;
}
@@ -1360,7 +1361,7 @@
} // Autolock scope
Vector<sp<GraphicBuffer>> buffers;
- for (size_t i = 0; i < newBufferCount; ++i) {
+ for (size_t i = 0; i < newBufferCount; ++i) {
sp<GraphicBuffer> graphicBuffer = new GraphicBuffer(
allocWidth, allocHeight, allocFormat, BQ_LAYER_COUNT,
allocUsage, allocName);
diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp
index 0749fde..0b37960 100644
--- a/libs/gui/IGraphicBufferProducer.cpp
+++ b/libs/gui/IGraphicBufferProducer.cpp
@@ -355,7 +355,7 @@
data.writeUint32(height);
data.writeInt32(static_cast<int32_t>(format));
data.writeUint64(usage);
- status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
+ status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply, TF_ONE_WAY);
if (result != NO_ERROR) {
ALOGE("allocateBuffers failed to transact: %d", result);
}
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 339bd0f..2de14c8 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -464,8 +464,12 @@
if (interval > maxSwapInterval)
interval = maxSwapInterval;
+ const bool wasSwapIntervalZero = mSwapIntervalZero;
mSwapIntervalZero = (interval == 0);
- mGraphicBufferProducer->setAsyncMode(mSwapIntervalZero);
+
+ if (mSwapIntervalZero != wasSwapIntervalZero) {
+ mGraphicBufferProducer->setAsyncMode(mSwapIntervalZero);
+ }
return NO_ERROR;
}
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index c2bb6ad..320e11f 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -27,6 +27,7 @@
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2",
"android.hardware.power@1.0",
+ "android.hardware.power@1.3",
"libbase",
"libbinder",
"libbufferhubqueue",
@@ -69,6 +70,7 @@
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2",
+ "android.hardware.power@1.3",
"libhidlbase",
"libhidltransport",
"libhwbinder",
@@ -96,6 +98,7 @@
"DisplayHardware/HWC2.cpp",
"DisplayHardware/HWComposer.cpp",
"DisplayHardware/HWComposerBufferCache.cpp",
+ "DisplayHardware/PowerAdvisor.cpp",
"DisplayHardware/VirtualDisplaySurface.cpp",
"DispSync.cpp",
"Effects/Daltonizer.cpp",
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index fda7906..12267ad 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -63,7 +63,7 @@
mRefreshPending(false) {
ALOGV("Creating Layer %s", name.string());
- mFlinger->getRenderEngine().genTextures(1, &mTextureName);
+ mTextureName = mFlinger->getNewTexture();
mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName);
if (flags & ISurfaceComposerClient::eNonPremultiplied) mPremultipliedAlpha = false;
@@ -706,8 +706,12 @@
sp<IGraphicBufferConsumer> consumer;
BufferQueue::createBufferQueue(&producer, &consumer, true);
mProducer = new MonitoredProducer(producer, mFlinger, this);
- mConsumer = new BufferLayerConsumer(consumer,
- mFlinger->getRenderEngine(), mTextureName, this);
+ {
+ // Grab the SF state lock during this since it's the only safe way to access RenderEngine
+ Mutex::Autolock lock(mFlinger->mStateLock);
+ mConsumer = new BufferLayerConsumer(consumer, mFlinger->getRenderEngine(), mTextureName,
+ this);
+ }
mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
mConsumer->setContentsChangedListener(this);
mConsumer->setName(mName);
diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp
index 077469b..0b59147 100644
--- a/services/surfaceflinger/Client.cpp
+++ b/services/surfaceflinger/Client.cpp
@@ -170,48 +170,8 @@
}
}
- /*
- * createSurface must be called from the GL thread so that it can
- * have access to the GL context.
- */
- class MessageCreateLayer : public MessageBase {
- SurfaceFlinger* flinger;
- Client* client;
- sp<IBinder>* handle;
- sp<IGraphicBufferProducer>* gbp;
- status_t result;
- const String8& name;
- uint32_t w, h;
- PixelFormat format;
- uint32_t flags;
- sp<Layer>* parent;
- int32_t windowType;
- int32_t ownerUid;
- public:
- MessageCreateLayer(SurfaceFlinger* flinger,
- const String8& name, Client* client,
- uint32_t w, uint32_t h, PixelFormat format, uint32_t flags,
- sp<IBinder>* handle, int32_t windowType, int32_t ownerUid,
- sp<IGraphicBufferProducer>* gbp,
- sp<Layer>* parent)
- : flinger(flinger), client(client),
- handle(handle), gbp(gbp), result(NO_ERROR),
- name(name), w(w), h(h), format(format), flags(flags),
- parent(parent), windowType(windowType), ownerUid(ownerUid) {
- }
- status_t getResult() const { return result; }
- virtual bool handler() {
- result = flinger->createLayer(name, client, w, h, format, flags,
- windowType, ownerUid, handle, gbp, parent);
- return true;
- }
- };
-
- sp<MessageBase> msg = new MessageCreateLayer(mFlinger.get(),
- name, this, w, h, format, flags, handle,
- windowType, ownerUid, gbp, &parent);
- mFlinger->postMessageSync(msg);
- return static_cast<MessageCreateLayer*>( msg.get() )->getResult();
+ return mFlinger->createLayer(name, this, w, h, format, flags, windowType,
+ ownerUid, handle, gbp, &parent);
}
status_t Client::destroySurface(const sp<IBinder>& handle) {
diff --git a/services/surfaceflinger/ContainerLayer.h b/services/surfaceflinger/ContainerLayer.h
index 543f60a..b352b96 100644
--- a/services/surfaceflinger/ContainerLayer.h
+++ b/services/surfaceflinger/ContainerLayer.h
@@ -35,6 +35,8 @@
bool isVisible() const override;
void setPerFrameData(const sp<const DisplayDevice>& displayDevice) override;
+
+ bool isCreatedFromMainThread() const override { return true; }
};
} // namespace android
diff --git a/services/surfaceflinger/DispSync.cpp b/services/surfaceflinger/DispSync.cpp
index 7acbd11..37dc27d 100644
--- a/services/surfaceflinger/DispSync.cpp
+++ b/services/surfaceflinger/DispSync.cpp
@@ -222,7 +222,13 @@
// Pretend that the last time this event was handled at the same frame but with the
// new offset to allow for a seamless offset change without double-firing or
// skipping.
- listener.mLastEventTime -= (oldPhase - phase);
+ nsecs_t diff = oldPhase - phase;
+ if (diff > mPeriod / 2) {
+ diff -= mPeriod;
+ } else if (diff < -mPeriod / 2) {
+ diff += mPeriod;
+ }
+ listener.mLastEventTime -= diff;
mCond.signal();
return NO_ERROR;
}
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index 61758b6..1a60c83 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -138,7 +138,7 @@
}
auto display = std::make_unique<Display>(
- *mComposer.get(), mCapabilities, displayId, DisplayType::Virtual);
+ *mComposer.get(), mPowerAdvisor, mCapabilities, displayId, DisplayType::Virtual);
display->setConnected(true);
*outDisplay = display.get();
mDisplays.emplace(displayId, std::move(display));
@@ -177,7 +177,7 @@
}
auto newDisplay = std::make_unique<Display>(
- *mComposer.get(), mCapabilities, displayId, displayType);
+ *mComposer.get(), mPowerAdvisor, mCapabilities, displayId, displayType);
newDisplay->setConnected(true);
mDisplays.emplace(displayId, std::move(newDisplay));
} else if (connection == Connection::Disconnected) {
@@ -219,10 +219,11 @@
// Display methods
-Display::Display(android::Hwc2::Composer& composer,
+Display::Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor,
const std::unordered_set<Capability>& capabilities, hwc2_display_t id,
DisplayType type)
: mComposer(composer),
+ mPowerAdvisor(advisor),
mCapabilities(capabilities),
mId(id),
mIsConnected(false),
@@ -605,6 +606,12 @@
Error Display::setColorMode(ColorMode mode, RenderIntent renderIntent)
{
+ // When the color mode is switched to DISPLAY_P3, we want to boost the GPU frequency
+ // so that GPU composition can finish in time. When color mode is switched from
+ // DISPLAY_P3, we want to reset GPU frequency.
+ const bool expensiveRenderingExpected = (mode == ColorMode::DISPLAY_P3);
+ mPowerAdvisor.setExpensiveRenderingExpected(mId, expensiveRenderingExpected);
+
auto intError = mComposer.setColorMode(mId, mode, renderIntent);
return static_cast<Error>(intError);
}
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index 29d7a47..e423167 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -37,6 +37,8 @@
#include <unordered_set>
#include <vector>
+#include "PowerAdvisor.h"
+
namespace android {
class Fence;
class FloatRect;
@@ -119,6 +121,7 @@
std::unique_ptr<android::Hwc2::Composer> mComposer;
std::unordered_set<Capability> mCapabilities;
std::unordered_map<hwc2_display_t, std::unique_ptr<Display>> mDisplays;
+ android::Hwc2::impl::PowerAdvisor mPowerAdvisor;
bool mRegisteredCallback = false;
};
@@ -126,7 +129,8 @@
class Display
{
public:
- Display(android::Hwc2::Composer& composer, const std::unordered_set<Capability>& capabilities,
+ Display(android::Hwc2::Composer& composer, android::Hwc2::PowerAdvisor& advisor,
+ const std::unordered_set<Capability>& capabilities,
hwc2_display_t id, DisplayType type);
~Display();
@@ -282,6 +286,7 @@
// this HWC2::Display, so these references are guaranteed to be valid for
// the lifetime of this object.
android::Hwc2::Composer& mComposer;
+ android::Hwc2::PowerAdvisor& mPowerAdvisor;
const std::unordered_set<Capability>& mCapabilities;
hwc2_display_t mId;
diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp
new file mode 100644
index 0000000..12bbae2
--- /dev/null
+++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2018 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.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "PowerAdvisor"
+
+#include <cinttypes>
+
+#include <utils/Log.h>
+#include <utils/Mutex.h>
+
+#include "PowerAdvisor.h"
+
+namespace android {
+namespace Hwc2 {
+
+PowerAdvisor::~PowerAdvisor() = default;
+
+namespace impl {
+
+namespace V1_0 = android::hardware::power::V1_0;
+using V1_3::PowerHint;
+
+PowerAdvisor::~PowerAdvisor() = default;
+
+PowerAdvisor::PowerAdvisor() = default;
+
+void PowerAdvisor::setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) {
+ if (expected) {
+ mExpensiveDisplays.insert(displayId);
+ } else {
+ mExpensiveDisplays.erase(displayId);
+ }
+
+ const bool expectsExpensiveRendering = !mExpensiveDisplays.empty();
+ if (mNotifiedExpensiveRendering != expectsExpensiveRendering) {
+ const sp<V1_3::IPower> powerHal = getPowerHal();
+ if (powerHal == nullptr) {
+ return;
+ }
+ auto ret = powerHal->powerHintAsync_1_3(PowerHint::EXPENSIVE_RENDERING,
+ expectsExpensiveRendering);
+ // If Power HAL 1.3 was available previously but now fails,
+ // it may restart, so attempt to reconnect next time
+ if (!ret.isOk()) {
+ mReconnectPowerHal = true;
+ return;
+ }
+ mNotifiedExpensiveRendering = expectsExpensiveRendering;
+ }
+}
+
+sp<V1_3::IPower> PowerAdvisor::getPowerHal() {
+ static sp<V1_3::IPower> sPowerHal_1_3 = nullptr;
+ static bool sHasPowerHal_1_3 = true;
+
+ if (mReconnectPowerHal) {
+ sPowerHal_1_3 = nullptr;
+ mReconnectPowerHal = false;
+ }
+
+ // Power HAL 1.3 is not guaranteed to be available, thus we need to query
+ // Power HAL 1.0 first and try to cast it to Power HAL 1.3.
+ // Power HAL 1.0 is always available, thus if we fail to query it, it means
+ // Power HAL is not available temporarily and we should retry later. However,
+ // if Power HAL 1.0 is available and we can't cast it to Power HAL 1.3,
+ // it means Power HAL 1.3 is not available at all, so we should stop trying.
+ if (sHasPowerHal_1_3 && sPowerHal_1_3 == nullptr) {
+ sp<V1_0::IPower> powerHal_1_0 = V1_0::IPower::getService();
+ if (powerHal_1_0 != nullptr) {
+ // Try to cast to Power HAL 1.3
+ sPowerHal_1_3 = V1_3::IPower::castFrom(powerHal_1_0);
+ if (sPowerHal_1_3 == nullptr) {
+ ALOGW("No Power HAL 1.3 service in system");
+ sHasPowerHal_1_3 = false;
+ } else {
+ ALOGI("Loaded Power HAL 1.3 service");
+ }
+ }
+ }
+ return sPowerHal_1_3;
+}
+
+} // namespace impl
+} // namespace Hwc2
+} // namespace android
diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.h b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h
new file mode 100644
index 0000000..573a1a9
--- /dev/null
+++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2018 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
+
+#define HWC2_INCLUDE_STRINGIFICATION
+#define HWC2_USE_CPP11
+#include <hardware/hwcomposer2.h>
+#undef HWC2_INCLUDE_STRINGIFICATION
+#undef HWC2_USE_CPP11
+
+#include <android/hardware/power/1.3/IPower.h>
+#include <utils/StrongPointer.h>
+
+#include <unordered_set>
+
+namespace android {
+namespace Hwc2 {
+
+class PowerAdvisor {
+public:
+ virtual ~PowerAdvisor();
+
+ virtual void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) = 0;
+};
+
+namespace impl {
+
+namespace V1_3 = android::hardware::power::V1_3;
+
+// PowerAdvisor is a wrapper around IPower HAL which takes into account the
+// full state of the system when sending out power hints to things like the GPU.
+class PowerAdvisor final : public Hwc2::PowerAdvisor {
+public:
+ PowerAdvisor();
+ ~PowerAdvisor() override;
+
+ void setExpensiveRenderingExpected(hwc2_display_t displayId, bool expected) override;
+
+private:
+ sp<V1_3::IPower> getPowerHal();
+
+ std::unordered_set<hwc2_display_t> mExpensiveDisplays;
+ bool mNotifiedExpensiveRendering = false;
+ bool mReconnectPowerHal = false;
+};
+
+} // namespace impl
+} // namespace Hwc2
+} // namespace android
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 2595ec1..a14bb98 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -130,17 +130,26 @@
// drawing state & current state are identical
mDrawingState = mCurrentState;
- const auto& hwc = flinger->getHwComposer();
- const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
- nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
- mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
-
CompositorTiming compositorTiming;
flinger->getCompositorTiming(&compositorTiming);
mFrameEventHistory.initializeCompositorTiming(compositorTiming);
}
-void Layer::onFirstRef() {}
+void Layer::onFirstRef() NO_THREAD_SAFETY_ANALYSIS {
+ if (!isCreatedFromMainThread()) {
+ // Grab the SF state lock during this since it's the only way to safely access HWC
+ mFlinger->mStateLock.lock();
+ }
+
+ const auto& hwc = mFlinger->getHwComposer();
+ const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
+ nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
+ mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
+
+ if (!isCreatedFromMainThread()) {
+ mFlinger->mStateLock.unlock();
+ }
+}
Layer::~Layer() {
sp<Client> c(mClientRef.promote());
@@ -345,20 +354,25 @@
win.intersect(s.crop, &win);
}
- Rect bounds = win;
const auto& p = mDrawingParent.promote();
+ FloatRect floatWin = win.toFloatRect();
+ FloatRect parentBounds = floatWin;
if (p != nullptr) {
- // Look in computeScreenBounds recursive call for explanation of
- // why we pass false here.
- bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
+ // We pass an empty Region here for reasons mirroring that of the case described in
+ // the computeScreenBounds reduceTransparentRegion=false case.
+ parentBounds = p->computeBounds(Region());
}
- Transform t = getTransform();
+ Transform t = s.active.transform;
- FloatRect floatWin = win.toFloatRect();
- if (p != nullptr) {
+
+ if (p != nullptr || !s.finalCrop.isEmpty()) {
floatWin = t.transform(floatWin);
- floatWin = floatWin.intersect(bounds.toFloatRect());
+ floatWin = floatWin.intersect(parentBounds);
+
+ if (!s.finalCrop.isEmpty()) {
+ floatWin = floatWin.intersect(s.finalCrop.toFloatRect());
+ }
floatWin = t.inverse().transform(floatWin);
}
@@ -1249,7 +1263,15 @@
return true;
}
-bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
+bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix,
+ bool allowNonRectPreservingTransforms) {
+ Transform t;
+ t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
+
+ if (!allowNonRectPreservingTransforms && !t.preserveRects()) {
+ ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER ignored");
+ return false;
+ }
mCurrentState.sequence++;
mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
mCurrentState.modified = true;
@@ -1974,6 +1996,16 @@
layerInfo->set_refresh_pending(isBufferLatched());
layerInfo->set_window_type(state.type);
layerInfo->set_app_id(state.appId);
+ layerInfo->set_curr_frame(mCurrentFrameNumber);
+
+ for (const auto& pendingState : mPendingStates) {
+ auto barrierLayer = pendingState.barrierLayer.promote();
+ if (barrierLayer != nullptr) {
+ BarrierLayerProto* barrierLayerProto = layerInfo->add_barrier_layer();
+ barrierLayerProto->set_id(barrierLayer->sequence);
+ barrierLayerProto->set_frame_number(pendingState.frameNumber);
+ }
+ }
}
void Layer::writeToProto(LayerProto* layerInfo, int32_t hwcId) {
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 34811fb..2239679 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -258,7 +258,7 @@
// Set a 2x2 transformation matrix on the layer. This transform
// will be applied after parent transforms, but before any final
// producer specified transform.
- bool setMatrix(const layer_state_t::matrix22_t& matrix);
+ bool setMatrix(const layer_state_t::matrix22_t& matrix, bool allowNonRectPreservingTransforms);
// This second set of geometry attributes are controlled by
// setGeometryAppliesWithResize, and their default mode is to be
@@ -360,6 +360,11 @@
*/
virtual bool isFixedSize() const { return true; }
+ // Most layers aren't created from the main thread, and therefore need to
+ // grab the SF state lock to access HWC, but ContainerLayer does, so we need
+ // to avoid grabbing the lock again to avoid deadlock
+ virtual bool isCreatedFromMainThread() const { return false; }
+
bool isPendingRemoval() const { return mPendingRemoval; }
diff --git a/services/surfaceflinger/RenderEngine/Description.cpp b/services/surfaceflinger/RenderEngine/Description.cpp
index 09414fd..c218e4d 100644
--- a/services/surfaceflinger/RenderEngine/Description.cpp
+++ b/services/surfaceflinger/RenderEngine/Description.cpp
@@ -51,10 +51,6 @@
mProjectionMatrix = mtx;
}
-void Description::setSaturationMatrix(const mat4& mtx) {
- mSaturationMatrix = mtx;
-}
-
void Description::setColorMatrix(const mat4& mtx) {
mColorMatrix = mtx;
}
@@ -82,11 +78,6 @@
return mColorMatrix != identity;
}
-bool Description::hasSaturationMatrix() const {
- const mat4 identity;
- return mSaturationMatrix != identity;
-}
-
const mat4& Description::getColorMatrix() const {
return mColorMatrix;
}
diff --git a/services/surfaceflinger/RenderEngine/Description.h b/services/surfaceflinger/RenderEngine/Description.h
index 06eaf35..6ebb340 100644
--- a/services/surfaceflinger/RenderEngine/Description.h
+++ b/services/surfaceflinger/RenderEngine/Description.h
@@ -42,14 +42,12 @@
void disableTexture();
void setColor(const half4& color);
void setProjectionMatrix(const mat4& mtx);
- void setSaturationMatrix(const mat4& mtx);
void setColorMatrix(const mat4& mtx);
void setInputTransformMatrix(const mat3& matrix);
void setOutputTransformMatrix(const mat4& matrix);
bool hasInputTransformMatrix() const;
bool hasOutputTransformMatrix() const;
bool hasColorMatrix() const;
- bool hasSaturationMatrix() const;
const mat4& getColorMatrix() const;
void setY410BT2020(bool enable);
@@ -92,7 +90,6 @@
// projection matrix
mat4 mProjectionMatrix;
mat4 mColorMatrix;
- mat4 mSaturationMatrix;
mat3 mInputTransformMatrix;
mat4 mOutputTransformMatrix;
};
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
index 0048000..744a70c 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
@@ -267,10 +267,6 @@
mState.setColorMatrix(colorTransform);
}
-void GLES20RenderEngine::setSaturationMatrix(const mat4& saturationMatrix) {
- mState.setSaturationMatrix(saturationMatrix);
-}
-
void GLES20RenderEngine::disableTexturing() {
mState.disableTexture();
}
@@ -383,11 +379,10 @@
// we need to convert the RGB value to linear space and convert it back when:
// - there is a color matrix that is not an identity matrix, or
- // - there is a saturation matrix that is not an identity matrix, or
// - there is an output transform matrix that is not an identity matrix, or
// - the input transfer function doesn't match the output transfer function.
- if (wideColorState.hasColorMatrix() || wideColorState.hasSaturationMatrix() ||
- wideColorState.hasOutputTransformMatrix() || inputTransfer != outputTransfer) {
+ if (wideColorState.hasColorMatrix() || wideColorState.hasOutputTransformMatrix() ||
+ inputTransfer != outputTransfer) {
switch (inputTransfer) {
case Dataspace::TRANSFER_ST2084:
wideColorState.setInputTransferFunction(Description::TransferFunction::ST2084);
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
index de5761b..cc8eb1d 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.h
@@ -81,7 +81,6 @@
virtual void setupLayerBlackedOut();
virtual void setupFillWithColor(float r, float g, float b, float a);
virtual void setupColorTransform(const mat4& colorTransform);
- virtual void setSaturationMatrix(const mat4& saturationMatrix);
virtual void disableTexturing();
virtual void disableBlending();
diff --git a/services/surfaceflinger/RenderEngine/Program.cpp b/services/surfaceflinger/RenderEngine/Program.cpp
index 95adaca..fe536f0 100644
--- a/services/surfaceflinger/RenderEngine/Program.cpp
+++ b/services/surfaceflinger/RenderEngine/Program.cpp
@@ -135,22 +135,13 @@
glUniform4fv(mColorLoc, 1, color);
}
if (mInputTransformMatrixLoc >= 0) {
- // If the input transform matrix is not identity matrix, we want to merge
- // the saturation matrix with input transform matrix so that the saturation
- // matrix is applied at the correct stage.
- mat4 inputTransformMatrix = mat4(desc.mInputTransformMatrix) * desc.mSaturationMatrix;
+ mat4 inputTransformMatrix = mat4(desc.mInputTransformMatrix);
glUniformMatrix4fv(mInputTransformMatrixLoc, 1, GL_FALSE, inputTransformMatrix.asArray());
}
if (mOutputTransformMatrixLoc >= 0) {
// The output transform matrix and color matrix can be combined as one matrix
// that is applied right before applying OETF.
mat4 outputTransformMatrix = desc.mColorMatrix * desc.mOutputTransformMatrix;
- // If there is no input transform matrix, we want to merge the saturation
- // matrix with output transform matrix to avoid extra matrix multiplication
- // in shader.
- if (mInputTransformMatrixLoc < 0) {
- outputTransformMatrix *= desc.mSaturationMatrix;
- }
glUniformMatrix4fv(mOutputTransformMatrixLoc, 1, GL_FALSE,
outputTransformMatrix.asArray());
}
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
index 796901a..9dc6858 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
@@ -149,8 +149,7 @@
description.hasInputTransformMatrix() ?
Key::INPUT_TRANSFORM_MATRIX_ON : Key::INPUT_TRANSFORM_MATRIX_OFF)
.set(Key::Key::OUTPUT_TRANSFORM_MATRIX_MASK,
- description.hasOutputTransformMatrix() || description.hasColorMatrix() ||
- (!description.hasInputTransformMatrix() && description.hasSaturationMatrix()) ?
+ description.hasOutputTransformMatrix() || description.hasColorMatrix() ?
Key::OUTPUT_TRANSFORM_MATRIX_ON : Key::OUTPUT_TRANSFORM_MATRIX_OFF);
needs.set(Key::Y410_BT2020_MASK,
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h
index 1196216..1786155 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.h
@@ -113,7 +113,6 @@
virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
virtual void setupColorTransform(const mat4& /* colorTransform */) = 0;
- virtual void setSaturationMatrix(const mat4& /* saturationMatrix */) = 0;
virtual void disableTexturing() = 0;
virtual void disableBlending() = 0;
@@ -228,7 +227,6 @@
void checkErrors() const override;
void setupColorTransform(const mat4& /* colorTransform */) override {}
- void setSaturationMatrix(const mat4& /* saturationMatrix */) override {}
// internal to RenderEngine
EGLDisplay getEGLDisplay() const;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 87baf8c..cf53930 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -37,6 +37,7 @@
#include <dvr/vr_flinger.h>
+#include <ui/ColorSpace.h>
#include <ui/DebugUtils.h>
#include <ui/DisplayInfo.h>
#include <ui/DisplayStatInfo.h>
@@ -222,6 +223,7 @@
mVisibleRegionsDirty(false),
mGeometryInvalid(false),
mAnimCompositionPending(false),
+ mBootStage(BootStage::BOOTLOADER),
mDebugRegion(0),
mDebugDDMS(0),
mDebugDisableHWC(0),
@@ -230,7 +232,6 @@
mLastSwapBufferTime(0),
mDebugInTransaction(0),
mLastTransactionTime(0),
- mBootFinished(false),
mForceFullDamage(false),
mPrimaryDispSync("PrimaryDispSync"),
mPrimaryHWVsyncEnabled(false),
@@ -331,11 +332,26 @@
auto listSize = property_get_int32("debug.sf.max_igbp_list_size", int32_t(defaultListSize));
mMaxGraphicBufferProducerListSize = (listSize > 0) ? size_t(listSize) : defaultListSize;
- property_get("debug.sf.early_phase_offset_ns", value, "0");
- const int earlyWakeupOffsetOffsetNs = atoi(value);
- ALOGI_IF(earlyWakeupOffsetOffsetNs != 0, "Enabling separate early offset");
- mVsyncModulator.setPhaseOffsets(sfVsyncPhaseOffsetNs - earlyWakeupOffsetOffsetNs,
- sfVsyncPhaseOffsetNs);
+ property_get("debug.sf.early_phase_offset_ns", value, "-1");
+ const int earlySfOffsetNs = atoi(value);
+
+ property_get("debug.sf.early_gl_phase_offset_ns", value, "-1");
+ const int earlyGlSfOffsetNs = atoi(value);
+
+ property_get("debug.sf.early_app_phase_offset_ns", value, "-1");
+ const int earlyAppOffsetNs = atoi(value);
+
+ property_get("debug.sf.early_gl_app_phase_offset_ns", value, "-1");
+ const int earlyGlAppOffsetNs = atoi(value);
+
+ const VSyncModulator::Offsets earlyOffsets =
+ {earlySfOffsetNs != -1 ? earlySfOffsetNs : sfVsyncPhaseOffsetNs,
+ earlyAppOffsetNs != -1 ? earlyAppOffsetNs : vsyncPhaseOffsetNs};
+ const VSyncModulator::Offsets earlyGlOffsets =
+ {earlyGlSfOffsetNs != -1 ? earlyGlSfOffsetNs : sfVsyncPhaseOffsetNs,
+ earlyGlAppOffsetNs != -1 ? earlyGlAppOffsetNs : vsyncPhaseOffsetNs};
+ mVsyncModulator.setPhaseOffsets(earlyOffsets, earlyGlOffsets,
+ {sfVsyncPhaseOffsetNs, vsyncPhaseOffsetNs});
// We should be reading 'persist.sys.sf.color_saturation' here
// but since /data may be encrypted, we need to wait until after vold
@@ -482,10 +498,32 @@
sp<LambdaMessage> readProperties = new LambdaMessage([&]() {
readPersistentProperties();
+ mBootStage = BootStage::FINISHED;
});
postMessageAsync(readProperties);
}
+uint32_t SurfaceFlinger::getNewTexture() {
+ {
+ std::lock_guard lock(mTexturePoolMutex);
+ if (!mTexturePool.empty()) {
+ uint32_t name = mTexturePool.back();
+ mTexturePool.pop_back();
+ ATRACE_INT("TexturePoolSize", mTexturePool.size());
+ return name;
+ }
+
+ // The pool was too small, so increase it for the future
+ ++mTexturePoolSize;
+ }
+
+ // The pool was empty, so we need to get a new texture name directly using a
+ // blocking call to the main thread
+ uint32_t name = 0;
+ postMessageSync(new LambdaMessage([&]() { getRenderEngine().genTextures(1, &name); }));
+ return name;
+}
+
void SurfaceFlinger::deleteTextureAsync(uint32_t texture) {
class MessageDestroyGLTexture : public MessageBase {
RE::RenderEngine& engine;
@@ -662,7 +700,7 @@
},
"sfEventThread");
mEventQueue->setEventThread(mSFEventThread.get());
- mVsyncModulator.setEventThread(mSFEventThread.get());
+ mVsyncModulator.setEventThreads(mSFEventThread.get(), mEventThread.get());
// Get a RenderEngine for the given display / config (can't fail)
getBE().mRenderEngine =
@@ -732,9 +770,24 @@
ALOGE("Run StartPropertySetThread failed!");
}
- mLegacySrgbSaturationMatrix = getBE().mHwc->getDataspaceSaturationMatrix(HWC_DISPLAY_PRIMARY,
+ // This is a hack. Per definition of getDataspaceSaturationMatrix, the returned matrix
+ // is used to saturate legacy sRGB content. However, to make sure the same color under
+ // Display P3 will be saturated to the same color, we intentionally break the API spec
+ // and apply this saturation matrix on Display P3 content. Unless the risk of applying
+ // such saturation matrix on Display P3 is understood fully, the API should always return
+ // identify matrix.
+ mEnhancedSaturationMatrix = getBE().mHwc->getDataspaceSaturationMatrix(HWC_DISPLAY_PRIMARY,
Dataspace::SRGB_LINEAR);
+ // we will apply this on Display P3.
+ if (mEnhancedSaturationMatrix != mat4()) {
+ ColorSpace srgb(ColorSpace::sRGB());
+ ColorSpace displayP3(ColorSpace::DisplayP3());
+ mat4 srgbToP3 = mat4(ColorSpaceConnector(srgb, displayP3).getTransform());
+ mat4 p3ToSrgb = mat4(ColorSpaceConnector(displayP3, srgb).getTransform());
+ mEnhancedSaturationMatrix = srgbToP3 * mEnhancedSaturationMatrix * p3ToSrgb;
+ }
+
ALOGV("Done initializing");
}
@@ -1496,7 +1549,7 @@
bool refreshNeeded = handleMessageTransaction();
refreshNeeded |= handleMessageInvalidate();
refreshNeeded |= mRepaintEverything;
- if (refreshNeeded) {
+ if (refreshNeeded && CC_LIKELY(mBootStage != BootStage::BOOTLOADER)) {
// Signal a refresh if a transaction modified the window state,
// a new buffer was latched, or if HWC has requested a full
// repaint
@@ -1809,6 +1862,17 @@
getBE().mTotalTime += elapsedTime;
}
getBE().mLastSwapTime = currentTime;
+
+ {
+ std::lock_guard lock(mTexturePoolMutex);
+ const size_t refillCount = mTexturePoolSize - mTexturePool.size();
+ if (refillCount > 0) {
+ const size_t offset = mTexturePool.size();
+ mTexturePool.resize(mTexturePoolSize);
+ getRenderEngine().genTextures(refillCount, mTexturePool.data() + offset);
+ ATRACE_INT("TexturePoolSize", mTexturePool.size());
+ }
+ }
}
void SurfaceFlinger::rebuildLayerStacks() {
@@ -2855,6 +2919,12 @@
signalLayerUpdate();
}
+ // enter boot animation on first buffer latch
+ if (CC_UNLIKELY(mBootStage == BootStage::BOOTLOADER && newDataLatched)) {
+ ALOGI("Enter boot animation");
+ mBootStage = BootStage::BOOTANIMATION;
+ }
+
// Only continue with the refresh if there is actually new work to do
return !mLayersWithQueuedFrames.empty() && newDataLatched;
}
@@ -2897,8 +2967,7 @@
ATRACE_INT("hasClientComposition", hasClientComposition);
bool applyColorMatrix = false;
- bool needsLegacyColorMatrix = false;
- bool legacyColorMatrixApplied = false;
+ bool needsEnhancedColorMatrix = false;
if (hasClientComposition) {
ALOGV("hasClientComposition");
@@ -2915,15 +2984,23 @@
const bool skipClientColorTransform = getBE().mHwc->hasCapability(
HWC2::Capability::SkipClientColorTransform);
+ mat4 colorMatrix;
applyColorMatrix = !hasDeviceComposition && !skipClientColorTransform;
if (applyColorMatrix) {
- getRenderEngine().setupColorTransform(mDrawingState.colorMatrix);
+ colorMatrix = mDrawingState.colorMatrix;
}
- needsLegacyColorMatrix =
+ // The current enhanced saturation matrix is designed to enhance Display P3,
+ // thus we only apply this matrix when the render intent is not colorimetric
+ // and the output color space is Display P3.
+ needsEnhancedColorMatrix =
(displayDevice->getActiveRenderIntent() >= RenderIntent::ENHANCE &&
- outputDataspace != Dataspace::UNKNOWN &&
- outputDataspace != Dataspace::SRGB);
+ outputDataspace == Dataspace::DISPLAY_P3);
+ if (needsEnhancedColorMatrix) {
+ colorMatrix *= mEnhancedSaturationMatrix;
+ }
+
+ getRenderEngine().setupColorTransform(colorMatrix);
if (!displayDevice->makeCurrent()) {
ALOGW("DisplayDevice::makeCurrent failed. Aborting surface composition for display %s",
@@ -3010,17 +3087,6 @@
break;
}
case HWC2::Composition::Client: {
- // switch color matrices lazily
- if (layer->isLegacyDataSpace() && needsLegacyColorMatrix) {
- if (!legacyColorMatrixApplied) {
- getRenderEngine().setSaturationMatrix(mLegacySrgbSaturationMatrix);
- legacyColorMatrixApplied = true;
- }
- } else if (legacyColorMatrixApplied) {
- getRenderEngine().setSaturationMatrix(mat4());
- legacyColorMatrixApplied = false;
- }
-
layer->draw(renderArea, clip);
break;
}
@@ -3033,12 +3099,9 @@
firstLayer = false;
}
- if (applyColorMatrix) {
+ if (applyColorMatrix || needsEnhancedColorMatrix) {
getRenderEngine().setupColorTransform(mat4());
}
- if (needsLegacyColorMatrix && legacyColorMatrixApplied) {
- getRenderEngine().setSaturationMatrix(mat4());
- }
// disable scissor at the end of the frame
getBE().mRenderEngine->disableScissor();
@@ -3327,6 +3390,18 @@
return flags;
}
+bool callingThreadHasUnscopedSurfaceFlingerAccess() {
+ IPCThreadState* ipc = IPCThreadState::self();
+ const int pid = ipc->getCallingPid();
+ const int uid = ipc->getCallingUid();
+
+ if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) &&
+ !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
+ return false;
+ }
+ return true;
+}
+
uint32_t SurfaceFlinger::setClientStateLocked(const ComposerState& composerState) {
const layer_state_t& s = composerState.state;
sp<Client> client(static_cast<Client*>(composerState.client.get()));
@@ -3408,7 +3483,22 @@
flags |= eTraversalNeeded;
}
if (what & layer_state_t::eMatrixChanged) {
- if (layer->setMatrix(s.matrix))
+ // TODO: b/109894387
+ //
+ // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
+ // rotation. To see the problem observe that if we have a square parent, and a child
+ // of the same size, then we rotate the child 45 degrees around it's center, the child
+ // must now be cropped to a non rectangular 8 sided region.
+ //
+ // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
+ // private API, and the WindowManager only uses rotation in one case, which is on a top
+ // level layer in which cropping is not an issue.
+ //
+ // However given that abuse of rotation matrices could lead to surfaces extending outside
+ // of cropped areas, we need to prevent non-root clients without permission ACCESS_SURFACE_FLINGER
+ // (a.k.a. everyone except WindowManager and tests) from setting non rectangle preserving
+ // transformations.
+ if (layer->setMatrix(s.matrix, callingThreadHasUnscopedSurfaceFlingerAccess()))
flags |= eTraversalNeeded;
}
if (what & layer_state_t::eTransparentRegionChanged) {
@@ -3574,10 +3664,13 @@
// Tack on our counter whether there is a hit or not, so everyone gets a tag
String8 uniqueName = name + "#" + String8(std::to_string(dupeCounter).c_str());
+ // Grab the state lock since we're accessing mCurrentState
+ Mutex::Autolock lock(mStateLock);
+
// Loop over layers until we're sure there is no matching name
while (matchFound) {
matchFound = false;
- mDrawingState.traverseInZOrder([&](Layer* layer) {
+ mCurrentState.traverseInZOrder([&](Layer* layer) {
if (layer->getName() == uniqueName) {
matchFound = true;
uniqueName = name + "#" + String8(std::to_string(++dupeCounter).c_str());
@@ -4207,9 +4300,22 @@
colorizer.bold(result);
result.append("DispSync configuration: ");
colorizer.reset(result);
- result.appendFormat("app phase %" PRId64 " ns, sf phase %" PRId64 " ns, early sf phase %" PRId64
- " ns, present offset %" PRId64 " ns (refresh %" PRId64 " ns)",
- vsyncPhaseOffsetNs, sfVsyncPhaseOffsetNs, mVsyncModulator.getEarlyPhaseOffset(),
+ const auto [sfEarlyOffset, appEarlyOffset] = mVsyncModulator.getEarlyOffsets();
+ const auto [sfEarlyGlOffset, appEarlyGlOffset] = mVsyncModulator.getEarlyGlOffsets();
+ result.appendFormat(
+ "app phase %" PRId64 " ns, "
+ "sf phase %" PRId64 " ns, "
+ "early app phase %" PRId64 " ns, "
+ "early sf phase %" PRId64 " ns, "
+ "early app gl phase %" PRId64 " ns, "
+ "early sf gl phase %" PRId64 " ns, "
+ "present offset %" PRId64 " ns (refresh %" PRId64 " ns)",
+ vsyncPhaseOffsetNs,
+ sfVsyncPhaseOffsetNs,
+ appEarlyOffset,
+ sfEarlyOffset,
+ appEarlyGlOffset,
+ sfEarlyOffset,
dispSyncPresentTimeOffset, activeConfig->getVsyncPeriod());
result.append("\n");
@@ -4412,12 +4518,10 @@
case INJECT_VSYNC:
{
// codes that require permission check
- IPCThreadState* ipc = IPCThreadState::self();
- const int pid = ipc->getCallingPid();
- const int uid = ipc->getCallingUid();
- if ((uid != AID_GRAPHICS && uid != AID_SYSTEM) &&
- !PermissionCache::checkPermission(sAccessSurfaceFlinger, pid, uid)) {
- ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", pid, uid);
+ if (!callingThreadHasUnscopedSurfaceFlingerAccess()) {
+ IPCThreadState* ipc = IPCThreadState::self();
+ ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d",
+ ipc->getCallingPid(), ipc->getCallingUid());
return PERMISSION_DENIED;
}
break;
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 8566b03..8f724e9 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -320,6 +320,10 @@
return getDefaultDisplayDeviceLocked();
}
+ // Obtains a name from the texture pool, or, if the pool is empty, posts a
+ // synchronous message to the main thread to obtain one on the fly
+ uint32_t getNewTexture();
+
// utility function to delete a texture on the main thread
void deleteTextureAsync(uint32_t texture);
@@ -808,6 +812,13 @@
sp<Fence> mPreviousPresentFence = Fence::NO_FENCE;
bool mHadClientComposition = false;
+ enum class BootStage {
+ BOOTLOADER,
+ BOOTANIMATION,
+ FINISHED,
+ };
+ BootStage mBootStage;
+
struct HotplugEvent {
hwc2_display_t display;
HWC2::Connection connection = HWC2::Connection::Invalid;
@@ -828,7 +839,6 @@
nsecs_t mLastSwapBufferTime;
volatile nsecs_t mDebugInTransaction;
nsecs_t mLastTransactionTime;
- bool mBootFinished;
bool mForceFullDamage;
bool mPropagateBackpressure = true;
std::unique_ptr<SurfaceInterceptor> mInterceptor =
@@ -858,6 +868,13 @@
std::atomic<bool> mRefreshPending{false};
+ // We maintain a pool of pre-generated texture names to hand out to avoid
+ // layer creation needing to run on the main thread (which it would
+ // otherwise need to do to access RenderEngine).
+ std::mutex mTexturePoolMutex;
+ uint32_t mTexturePoolSize = 0;
+ std::vector<uint32_t> mTexturePool;
+
/* ------------------------------------------------------------------------
* Feature prototyping
*/
@@ -878,9 +895,9 @@
static bool useVrFlinger;
std::thread::id mMainThreadId;
- DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::MANAGED;
- // Applied on sRGB layers when the render intent is non-colorimetric.
- mat4 mLegacySrgbSaturationMatrix;
+ DisplayColorSetting mDisplayColorSetting = DisplayColorSetting::ENHANCED;
+ // Applied on Display P3 layers when the render intent is non-colorimetric.
+ mat4 mEnhancedSaturationMatrix;
using CreateBufferQueueFunction =
std::function<void(sp<IGraphicBufferProducer>* /* outProducer */,
diff --git a/services/surfaceflinger/VSyncModulator.h b/services/surfaceflinger/VSyncModulator.h
index d526313..e071a59 100644
--- a/services/surfaceflinger/VSyncModulator.h
+++ b/services/surfaceflinger/VSyncModulator.h
@@ -36,6 +36,11 @@
public:
+ struct Offsets {
+ nsecs_t sf;
+ nsecs_t app;
+ };
+
enum TransactionStart {
EARLY,
NORMAL
@@ -43,21 +48,32 @@
// Sets the phase offsets
//
- // early: the phase offset when waking up early. May be the same as late, in which case we don't
- // shift offsets.
- // late: the regular sf phase offset.
- void setPhaseOffsets(nsecs_t early, nsecs_t late) {
- mEarlyPhaseOffset = early;
- mLatePhaseOffset = late;
- mPhaseOffset = late;
+ // sfEarly: The phase offset when waking up SF early, which happens when marking a transaction
+ // as early. May be the same as late, in which case we don't shift offsets.
+ // sfEarlyGl: Like sfEarly, but only if we used GL composition. If we use both GL composition
+ // and the transaction was marked as early, we'll use sfEarly.
+ // sfLate: The regular SF vsync phase offset.
+ // appEarly: Like sfEarly, but for the app-vsync
+ // appEarlyGl: Like sfEarlyGl, but for the app-vsync.
+ // appLate: The regular app vsync phase offset.
+ void setPhaseOffsets(Offsets early, Offsets earlyGl, Offsets late) {
+ mEarlyOffsets = early;
+ mEarlyGlOffsets = earlyGl;
+ mLateOffsets = late;
+ mOffsets = late;
}
- nsecs_t getEarlyPhaseOffset() const {
- return mEarlyPhaseOffset;
+ Offsets getEarlyOffsets() const {
+ return mEarlyOffsets;
}
- void setEventThread(EventThread* eventThread) {
- mEventThread = eventThread;
+ Offsets getEarlyGlOffsets() const {
+ return mEarlyGlOffsets;
+ }
+
+ void setEventThreads(EventThread* sfEventThread, EventThread* appEventThread) {
+ mSfEventThread = sfEventThread;
+ mAppEventThread = appEventThread;
}
void setTransactionStart(TransactionStart transactionStart) {
@@ -71,63 +87,70 @@
return;
}
mTransactionStart = transactionStart;
- updatePhaseOffsets();
+ updateOffsets();
}
void onTransactionHandled() {
if (mTransactionStart == TransactionStart::NORMAL) return;
mTransactionStart = TransactionStart::NORMAL;
- updatePhaseOffsets();
+ updateOffsets();
}
void onRefreshed(bool usedRenderEngine) {
- bool updatePhaseOffsetsNeeded = false;
+ bool updateOffsetsNeeded = false;
if (mRemainingEarlyFrameCount > 0) {
mRemainingEarlyFrameCount--;
- updatePhaseOffsetsNeeded = true;
+ updateOffsetsNeeded = true;
}
if (usedRenderEngine != mLastFrameUsedRenderEngine) {
mLastFrameUsedRenderEngine = usedRenderEngine;
- updatePhaseOffsetsNeeded = true;
+ updateOffsetsNeeded = true;
}
- if (updatePhaseOffsetsNeeded) {
- updatePhaseOffsets();
+ if (updateOffsetsNeeded) {
+ updateOffsets();
}
}
private:
- void updatePhaseOffsets() {
+ void updateOffsets() {
+ const Offsets desired = getOffsets();
+ const Offsets current = mOffsets;
- // Do not change phase offsets if disabled.
- if (mEarlyPhaseOffset == mLatePhaseOffset) return;
+ bool changed = false;
+ if (desired.sf != current.sf) {
+ mSfEventThread->setPhaseOffset(desired.sf);
+ changed = true;
+ }
+ if (desired.app != current.app) {
+ mAppEventThread->setPhaseOffset(desired.app);
+ changed = true;
+ }
- if (shouldUseEarlyOffset()) {
- if (mPhaseOffset != mEarlyPhaseOffset) {
- if (mEventThread) {
- mEventThread->setPhaseOffset(mEarlyPhaseOffset);
- }
- mPhaseOffset = mEarlyPhaseOffset;
- }
- } else {
- if (mPhaseOffset != mLatePhaseOffset) {
- if (mEventThread) {
- mEventThread->setPhaseOffset(mLatePhaseOffset);
- }
- mPhaseOffset = mLatePhaseOffset;
- }
+ if (changed) {
+ mOffsets = desired;
}
}
- bool shouldUseEarlyOffset() {
- return mTransactionStart == TransactionStart::EARLY || mLastFrameUsedRenderEngine
- || mRemainingEarlyFrameCount > 0;
+ Offsets getOffsets() {
+ if (mTransactionStart == TransactionStart::EARLY || mRemainingEarlyFrameCount > 0) {
+ return mEarlyOffsets;
+ } else if (mLastFrameUsedRenderEngine) {
+ return mEarlyGlOffsets;
+ } else {
+ return mLateOffsets;
+ }
}
- nsecs_t mLatePhaseOffset = 0;
- nsecs_t mEarlyPhaseOffset = 0;
- EventThread* mEventThread = nullptr;
- std::atomic<nsecs_t> mPhaseOffset = 0;
+ Offsets mLateOffsets;
+ Offsets mEarlyOffsets;
+ Offsets mEarlyGlOffsets;
+
+ EventThread* mSfEventThread = nullptr;
+ EventThread* mAppEventThread = nullptr;
+
+ std::atomic<Offsets> mOffsets;
+
std::atomic<TransactionStart> mTransactionStart = TransactionStart::NORMAL;
std::atomic<bool> mLastFrameUsedRenderEngine = false;
std::atomic<int> mRemainingEarlyFrameCount = 0;
diff --git a/services/surfaceflinger/layerproto/layers.proto b/services/surfaceflinger/layerproto/layers.proto
index 77c6675..edf56ab 100644
--- a/services/surfaceflinger/layerproto/layers.proto
+++ b/services/surfaceflinger/layerproto/layers.proto
@@ -80,6 +80,10 @@
optional int32 hwc_composition_type = 35;
// If it's a buffer layer, indicate if the content is protected
optional bool is_protected = 36;
+ // Current frame number being rendered.
+ optional uint64 curr_frame = 37;
+ // A list of barriers that the layer is waiting to update state.
+ repeated BarrierLayerProto barrier_layer = 38;
}
message PositionProto {
@@ -131,3 +135,10 @@
optional float b = 3;
optional float a = 4;
}
+
+message BarrierLayerProto {
+ // layer id the barrier is waiting on.
+ optional int32 id = 1;
+ // frame number the barrier is waiting on.
+ optional uint64 frame_number = 2;
+}
diff --git a/services/surfaceflinger/main_surfaceflinger.cpp b/services/surfaceflinger/main_surfaceflinger.cpp
index 8255b41..b1ff522 100644
--- a/services/surfaceflinger/main_surfaceflinger.cpp
+++ b/services/surfaceflinger/main_surfaceflinger.cpp
@@ -102,7 +102,7 @@
// publish surface flinger
sp<IServiceManager> sm(defaultServiceManager());
sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false,
- IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL);
+ IServiceManager::DUMP_FLAG_PRIORITY_CRITICAL | IServiceManager::DUMP_FLAG_PROTO);
// publish GpuService
sp<GpuService> gpuservice = new GpuService();
diff --git a/services/surfaceflinger/tests/fakehwc/Android.bp b/services/surfaceflinger/tests/fakehwc/Android.bp
index 19af82c..6ad1b87 100644
--- a/services/surfaceflinger/tests/fakehwc/Android.bp
+++ b/services/surfaceflinger/tests/fakehwc/Android.bp
@@ -11,6 +11,7 @@
shared_libs: [
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.mapper@2.0",
+ "android.hardware.power@1.3",
"libbase",
"libbinder",
"libcutils",
diff --git a/services/surfaceflinger/tests/unittests/Android.bp b/services/surfaceflinger/tests/unittests/Android.bp
index 8c268b2..9949bfa 100644
--- a/services/surfaceflinger/tests/unittests/Android.bp
+++ b/services/surfaceflinger/tests/unittests/Android.bp
@@ -23,6 +23,7 @@
"EventThreadTest.cpp",
"mock/DisplayHardware/MockComposer.cpp",
"mock/DisplayHardware/MockDisplaySurface.cpp",
+ "mock/DisplayHardware/MockPowerAdvisor.cpp",
"mock/gui/MockGraphicBufferConsumer.cpp",
"mock/gui/MockGraphicBufferProducer.cpp",
"mock/MockEventControlThread.cpp",
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index f1556d8..acd16fe 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -149,12 +149,18 @@
* Wrapper classes for Read-write access to private data to set up
* preconditions and assert post-conditions.
*/
+ class FakePowerAdvisor : public Hwc2::PowerAdvisor {
+ public:
+ FakePowerAdvisor() = default;
+ ~FakePowerAdvisor() override = default;
+ void setExpensiveRenderingExpected(hwc2_display_t, bool) override { }
+ };
struct HWC2Display : public HWC2::Display {
- HWC2Display(Hwc2::Composer& composer,
+ HWC2Display(Hwc2::Composer& composer, Hwc2::PowerAdvisor& advisor,
const std::unordered_set<HWC2::Capability>& capabilities, hwc2_display_t id,
HWC2::DisplayType type)
- : HWC2::Display(composer, capabilities, id, type) {}
+ : HWC2::Display(composer, advisor, capabilities, id, type) {}
~HWC2Display() {
// Prevents a call to disable vsyncs.
mType = HWC2::DisplayType::Invalid;
@@ -217,8 +223,8 @@
}
void inject(TestableSurfaceFlinger* flinger, Hwc2::Composer* composer) {
- auto display = std::make_unique<HWC2Display>(*composer, mCapabilities, mHwcDisplayId,
- mHwcDisplayType);
+ auto display = std::make_unique<HWC2Display>(*composer, mPowerAdvisor, mCapabilities,
+ mHwcDisplayId, mHwcDisplayType);
auto config = HWC2::Display::Config::Builder(*display, mActiveConfig);
config.setWidth(mWidth);
@@ -248,6 +254,7 @@
int32_t mDpiY = DEFAULT_DPI;
int32_t mActiveConfig = DEFAULT_ACTIVE_CONFIG;
std::unordered_set<HWC2::Capability> mCapabilities;
+ FakePowerAdvisor mPowerAdvisor;
};
class FakeDisplayDeviceInjector {
diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.cpp b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.cpp
new file mode 100644
index 0000000..8be7077
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "MockPowerAdvisor.h"
+
+namespace android {
+namespace Hwc2 {
+namespace mock {
+
+// Explicit default instantiation is recommended.
+PowerAdvisor::PowerAdvisor() = default;
+PowerAdvisor::~PowerAdvisor() = default;
+
+} // namespace mock
+} // namespace Hwc2
+} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h
new file mode 100644
index 0000000..dc6d83b
--- /dev/null
+++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2018 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 <gmock/gmock.h>
+
+#include "DisplayHardware/PowerAdvisor.h"
+
+namespace android {
+namespace Hwc2 {
+namespace mock {
+
+class PowerAdvisor : public android::Hwc2::PowerAdvisor {
+public:
+ PowerAdvisor();
+ ~PowerAdvisor() override;
+
+ MOCK_METHOD2(setExpensiveRenderingExpected, void(hwc2_display_t displayId, bool expected));
+};
+
+} // namespace mock
+} // namespace Hwc2
+} // namespace android