Skip to content

Commit

Permalink
surface_control: Replace C++ constructs with C-compatible code
Browse files Browse the repository at this point in the history
This header currently cannot be processed by a C compiler as it contains
C++ patterns, which prevent us from generating bindings in the [Rust
`ndk-sys` crate].  This was originally reported at https://github.com/
android/ndk/issues/1920.

The compatibility changes are as follows:

- Remove `= -1` default-argument;
- Suffix `ADataSpace` usage with `enum` tag.  A word of warning: other
  bindings take this as an `int`, which is less descriptive.  What is
  correct for these APIs, and can we unify it?;
- Replace `&` references with `*` pointers, and marked them as
  `_Nonnull`.  Confusingly lots of headers and functions here are
  lacking `_Nonnull`/`_Nullable` annotations, making our mapping "job"
  in Rust pretty terrible.

Some improvements to the bindings:

- Make HDR metadata struct pointers `const` as they are only used for
  reading;
- Remove the duplicate `Available since API level 34.` on
  `ASurfaceTransaction_setExtendedRangeBrightness()` that was introduced
  in the wrong place in I62df5447bc547be52f6b00fedf1006c8d66a5faf,
  and later added again _after_ the parameter list in
  I8bebb31f0bd38e36139026a539030e5b61b75b4c.  Note that the other
  notions _above_ the parameter list (also added by the first linked
  change) are kept;
- Fix a typo reference to `SurfaceControlStats` as reported in [comment
  14].

[Rust `ndk-sys` crate]: https://github.com/rust-mobile/ndk
[comment 14]: https://issuetracker.google.com/issues/300602767#comment14

Change-Id: I9186df4abe7cb8246b2d10c1b41ab13664bad3ec
Signed-off-by: Marijn Suijten <[email protected]>
  • Loading branch information
MarijnS95 committed Jan 22, 2024
1 parent fe499b4 commit 63bc197
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions include/android/surface_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* _Nonnu
* addition of a buffer to a particular surface as a unique ref. When a transaction updates or
* removes a buffer from a surface, or removes the surface itself from the tree, this ref is
* guaranteed to be released in the OnComplete callback for this transaction. The
* ASurfaceControlStats provided in the callback for this surface may contain an optional fence
* \a ASurfaceTransactionStats provided in the callback for this surface may contain an optional fence
* which must be signaled before the ref is assumed to be released.
*
* The client must ensure that all pending refs on a buffer are released before attempting to reuse
Expand Down Expand Up @@ -346,7 +346,7 @@ void ASurfaceTransaction_setZOrder(ASurfaceTransaction* _Nonnull transaction,
*/
void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control, AHardwareBuffer* _Nonnull buffer,
int acquire_fence_fd = -1) __INTRODUCED_IN(29);
int acquire_fence_fd ) __INTRODUCED_IN(29);

/**
* Updates the color for \a surface_control. This will make the background color for the
Expand All @@ -358,7 +358,7 @@ void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
*/
void ASurfaceTransaction_setColor(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control, float r, float g, float b,
float alpha, ADataSpace dataspace)
float alpha, enum ADataSpace dataspace)
__INTRODUCED_IN(29);

/**
Expand All @@ -382,8 +382,8 @@ void ASurfaceTransaction_setColor(ASurfaceTransaction* _Nonnull transaction,
* properties at once.
*/
void ASurfaceTransaction_setGeometry(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control, const ARect& source,
const ARect& destination, int32_t transform)
ASurfaceControl* _Nonnull surface_control, const ARect* _Nonnull source,
const ARect* _Nonnull destination, int32_t transform)
__INTRODUCED_IN(29);

/**
Expand All @@ -396,7 +396,7 @@ void ASurfaceTransaction_setGeometry(ASurfaceTransaction* _Nonnull transaction,
* Available since API level 31.
*/
void ASurfaceTransaction_setCrop(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control, const ARect& crop)
ASurfaceControl* _Nonnull surface_control, const ARect* _Nonnull crop)
__INTRODUCED_IN(31);

/**
Expand Down Expand Up @@ -497,7 +497,7 @@ void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* _Nonnull transactio
* Available since API level 29.
*/
void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control, ADataSpace data_space)
ASurfaceControl* _Nonnull surface_control, enum ADataSpace data_space)
__INTRODUCED_IN(29);

/**
Expand All @@ -510,7 +510,7 @@ void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* _Nonnull transa
*/
void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control,
struct AHdrMetadata_smpte2086* _Nullable metadata)
const struct AHdrMetadata_smpte2086* _Nullable metadata)
__INTRODUCED_IN(29);

/**
Expand All @@ -523,15 +523,13 @@ void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* _Nonnull
*/
void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* _Nonnull transaction,
ASurfaceControl* _Nonnull surface_control,
struct AHdrMetadata_cta861_3* _Nullable metadata)
const struct AHdrMetadata_cta861_3* _Nullable metadata)
__INTRODUCED_IN(29);

/**
* Sets the desired extended range brightness for the layer. This only applies for layers whose
* dataspace has RANGE_EXTENDED set on it.
*
* Available since API level 34.
*
* @param surface_control The layer whose extended range brightness is being specified
* @param currentBufferRatio The current hdr/sdr ratio of the current buffer as represented as
* peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the
Expand Down

0 comments on commit 63bc197

Please sign in to comment.