Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49be9676 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10860171 from cdfbf434 to 24Q1-release

Change-Id: I03ab5de941a5924355cb7baa0b33f72d32526684
parents 2e66d172 cdfbf434
Loading
Loading
Loading
Loading
+72 −7
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@

#include <ftl/string.h>

// Returns the name of enumerator E::V (i.e. "V") as std::optional<std::string_view> by parsing the
// compiler-generated string literal for the signature of this function. The function is defined in
// the global namespace with a short name and inferred return type to reduce bloat in the read-only
// data segment.
template <typename E, E V>
constexpr auto ftl_enum() {
// Returns the name of enumerator E::V and optionally the class (i.e. "E::V" or "V") as
// std::optional<std::string_view> by parsing the compiler-generated string literal for the
// signature of this function. The function is defined in the global namespace with a short name
// and inferred return type to reduce bloat in the read-only data segment.
template <bool S, typename E, E V>
constexpr auto ftl_enum_builder() {
  static_assert(std::is_enum_v<E>);

  using R = std::optional<std::string_view>;
@@ -58,7 +58,9 @@ constexpr auto ftl_enum() {
  //   V = android::test::Enum::kValue
  //
  view = view.substr(value_begin);
  const auto name_begin = view.rfind("::"sv);
  const auto pos = S ? view.rfind("::"sv) - 2 : view.npos;

  const auto name_begin = view.rfind("::"sv, pos);
  if (name_begin == view.npos) return R{};

  // Chop off the leading "::".
@@ -68,6 +70,18 @@ constexpr auto ftl_enum() {
  return name.find(')') == view.npos ? R{name} : R{};
}

// Returns the name of enumerator E::V (i.e. "V") as std::optional<std::string_view>
template <typename E, E V>
constexpr auto ftl_enum() {
  return ftl_enum_builder<false, E, V>();
}

// Returns the name of enumerator and class E::V (i.e. "E::V") as std::optional<std::string_view>
template <typename E, E V>
constexpr auto ftl_enum_full() {
  return ftl_enum_builder<true, E, V>();
}

namespace android::ftl {

// Trait for determining whether a type is specifically a scoped enum or not. By definition, a
@@ -191,6 +205,11 @@ struct EnumName {
  static constexpr auto value = ftl_enum<decltype(V), V>();
};

template <auto V>
struct EnumNameFull {
  static constexpr auto value = ftl_enum_full<decltype(V), V>();
};

template <auto I>
struct FlagName {
  using E = decltype(I);
@@ -230,6 +249,18 @@ constexpr std::string_view enum_name() {
  return *kName;
}

// Returns a stringified enumerator with class at compile time.
//
//   enum class E { A, B, C };
//   static_assert(ftl::enum_name<E::B>() == "E::B");
//
template <auto V>
constexpr std::string_view enum_name_full() {
  constexpr auto kName = ftl_enum_full<decltype(V), V>();
  static_assert(kName, "Unknown enumerator");
  return *kName;
}

// Returns a stringified enumerator, possibly at compile time.
//
//   enum class E { A, B, C, F = 5, ftl_last = F };
@@ -249,6 +280,25 @@ constexpr std::optional<std::string_view> enum_name(E v) {
  return kRange.values[value - kBegin];
}

// Returns a stringified enumerator with class, possibly at compile time.
//
//   enum class E { A, B, C, F = 5, ftl_last = F };
//
//   static_assert(ftl::enum_name(E::C).value_or("?") == "E::C");
//   static_assert(ftl::enum_name(E{3}).value_or("?") == "?");
//
template <typename E>
constexpr std::optional<std::string_view> enum_name_full(E v) {
  const auto value = to_underlying(v);

  constexpr auto kBegin = to_underlying(enum_begin_v<E>);
  constexpr auto kLast = to_underlying(enum_last_v<E>);
  if (value < kBegin || value > kLast) return {};

  constexpr auto kRange = details::EnumRange<E, details::EnumNameFull>{};
  return kRange.values[value - kBegin];
}

// Returns a stringified flag enumerator, possibly at compile time.
//
//   enum class F : std::uint16_t { X = 0b1, Y = 0b10, Z = 0b100 };
@@ -282,6 +332,21 @@ inline std::string enum_string(E v) {
  return to_string(to_underlying(v));
}

// Returns a stringified enumerator with class, or its integral value if not named.
//
//   enum class E { A, B, C, F = 5, ftl_last = F };
//
//   assert(ftl::enum_string(E::C) == "E::C");
//   assert(ftl::enum_string(E{3}) == "3");
//
template <typename E>
inline std::string enum_string_full(E v) {
  if (const auto name = enum_name_full(v)) {
      return std::string(*name);
  }
  return to_string(to_underlying(v));
}

// Returns a stringified flag enumerator, or its integral value if not named.
//
//   enum class F : std::uint16_t { X = 0b1, Y = 0b10, Z = 0b100 };
+27 −0
Original line number Diff line number Diff line
// Copyright (C) 2023 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.

android_app {
    name: "BufferStreamsDemoApp",
    srcs: ["java/**/*.java"],
    sdk_version: "current",

    jni_uses_platform_apis: true,
    jni_libs: ["libbufferstreamdemoapp"],
    use_embedded_native_libs: true,

    static_libs: [
        "androidx.appcompat_appcompat",
    ],
}
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.graphics.bufferstreamsdemoapp"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light"
        tools:targetApi="34">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
 No newline at end of file
+39 −0
Original line number Diff line number Diff line
// Copyright (C) 2023 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.

package com.android.graphics.bufferstreamsdemoapp;

import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    // Used to load the 'bufferstreamsdemoapp' library on application startup.
    static { System.loadLibrary("bufferstreamdemoapp"); }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RunBufferQueue();
        System.out.println("stringFromJNI: " + stringFromJNI());
    }

    /**
     * A native method that is implemented by the 'bufferstreamsdemoapp' native
     * library, which is packaged with this application.
     */
    public native String stringFromJNI();
    public native void RunBufferQueue();
}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
// Copyright (C) 2023 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.

cc_library_shared {
    name: "libbufferstreamdemoapp",
    cflags: [
        "-Werror",
        "-Wno-error=unused-parameter",
    ],
    shared_libs: [
        "libgui",
        "libbase",
        "libutils",
    ],
    header_libs: ["jni_headers"],
    srcs: ["*.cpp"],
}
Loading