commit 4022351e22982e5e165abaa7247bde2d1750b392 Author: The412Banner Date: Sat Sep 19 13:39:17 2026 -0400 SteamDeck: a standalone launcher for the native ARM64 Linux Steam client Lifts Bannerlator's Linux/gamescope runtime out into an app of its own: the Wayland compositor, the proot session, the runtime installer, the fake-evdev controller path and the PulseAudio server, with none of the Wine, container or store machinery around them. One activity installs the runtime from the same winlator-contents catalog and a second one runs the session: compositor on a SurfaceView, gamescope and Valve's native arm64 client under proot, a physical pad republished into the fake-input rings, and the session's milestones on screen until the first frame arrives. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..0dedd6526e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,98 @@ +name: Build APK + +# One job: the two glibc preload libraries the session needs, then the app around them. +# Nothing is built on a developer machine — this workflow is the only thing that produces an apk. + +on: + push: + branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-24.04 + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - uses: gradle/actions/setup-gradle@v4 + + # ── The session's preloads ─────────────────────────────────────────────────────────── + # Both are glibc aarch64 libraries that live inside the rootfs, so they are cross-compiled + # here rather than by the NDK. They ship in assets (not in the runtime tarball) so a fix in + # either reaches an already-installed runtime on the next launch instead of waiting on a + # ~790 MB runtime re-host. + - name: Build libfakeinput.so and libblsession.so (glibc aarch64) + run: | + set -euo pipefail + sudo apt-get update -qq + sudo apt-get install -y -qq gcc-aarch64-linux-gnu g++-aarch64-linux-gnu >/dev/null + D=app/src/main/assets/linuxfs + mkdir -p "$D" + # Statically linked C++ runtime: this is preloaded into every Steam process, and Steam + # ships its own libstdc++ while rewriting LD_LIBRARY_PATH. Pulling the system one in + # ahead of it is a version conflict waiting to happen. Only libc is left as a dependency. + aarch64-linux-gnu-g++ -shared -fPIC -O2 -Wall -Wno-attributes -Wno-nonnull-compare \ + -pthread -std=c++17 -static-libstdc++ -static-libgcc \ + -o "$D/libfakeinput.so" app/src/main/cpp/fakeinput.cpp -ldl + aarch64-linux-gnu-strip --strip-unneeded "$D/libfakeinput.so" + NEED=$(aarch64-linux-gnu-readelf -d "$D/libfakeinput.so" | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p') + echo "libfakeinput NEEDED: $NEED" + for bad in libstdc++.so.6 libgcc_s.so.1; do + if printf '%s\n' "$NEED" | grep -qx "$bad"; then + echo "::error::libfakeinput.so links $bad — the C++ runtime must stay static"; exit 1 + fi + done + # The interposers are the whole point: if one is missing the client sees no controller. + SYMS=$(aarch64-linux-gnu-nm -D --defined-only "$D/libfakeinput.so" | awk '{print $NF}') + for sym in open openat ioctl read close poll ppoll select stat fstat access scandir; do + grep -qx "$sym" <<<"$SYMS" || { echo "::error::libfakeinput.so does not export $sym"; exit 1; } + done + + aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \ + -o "$D/libblsession.so" tools/linuxfs/preload/*.c -ldl + aarch64-linux-gnu-strip --strip-unneeded "$D/libblsession.so" + for sym in socket bind getsockname setsockopt; do + aarch64-linux-gnu-nm -D --defined-only "$D/libblsession.so" | awk '{print $NF}' \ + | grep -qx "$sym" || { echo "::error::libblsession.so does not export $sym"; exit 1; } + done + + # The session's scripts travel the same way, for the same reason. + for script in tools/linuxfs/overlay/usr/local/bin/bannerlator-*; do + install -Dm644 "$script" "$D/usr/local/bin/$(basename "$script")" + done + ls -lR "$D" + + - name: Resolve the runner's NDK + run: | + NDK="${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-$ANDROID_NDK_ROOT}}" + VERSION=$(sed -n 's/^Pkg.Revision *= *//p' "$NDK/source.properties") + echo "NDK $VERSION at $NDK" + echo "NDK_VERSION=$VERSION" >> "$GITHUB_ENV" + + - name: Build + run: ./gradlew --no-daemon assembleDebug -PndkVersion="$NDK_VERSION" + + - name: Describe the apk + run: | + set -euo pipefail + APK=$(find app/build/outputs/apk -name '*.apk' | head -1) + echo "apk: $APK" + ls -l "$APK" + sha256sum "$APK" + unzip -l "$APK" | grep -E 'lib/arm64-v8a|assets/linuxfs' | head -30 + + - uses: actions/upload-artifact@v4 + with: + name: steamdeck-apk + path: app/build/outputs/apk/debug/*.apk + if-no-files-found: error + retention-days: 30 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..4a3450942c --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +*.iml +.gradle/ +local.properties +.idea/ +.DS_Store +build/ +captures/ +.externalNativeBuild/ +.cxx/ +# Built in CI from tools/linuxfs and app/src/main/cpp/fakeinput.cpp, never committed, so the two +# copies cannot drift. +app/src/main/assets/linuxfs/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..5ae980bfc6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Pluvia is an unofficial Steam client app for Android + Copyright (C) 2024 Oxters Wyzgowski + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Pluvia Copyright (C) 2024 Oxters Wyzgowski + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000000..96ad7d0a1e --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# SteamDeck + +Valve's **native aarch64 Linux Steam client**, running on an Android phone or handheld: a glibc +rootfs under proot, gamescope as a Wayland client of an in-app Vulkan compositor, Xwayland and +Zink for the client's CEF, and the device's Turnip driver underneath. There is no Wine here, and +no x86 translation for the client itself — it is ARM code running as ARM code. Windows games it +launches go through Valve's own ARM64 Proton build, which is where FEX comes in. + +One screen, one button: install the runtime, press Play, Big Picture comes up. + +## How it fits together + +``` + Android app (this repo) + ├── libbannerwayland.so Wayland compositor, presents into the activity's Surface (Vulkan/Turnip) + ├── PulseAudio 13 + AAudio the guest's audio server, on a socket bound into the session + ├── fake-evdev rings a physical pad, republished as /dev/input/eventN for the client + └── proot ── linuxfs (~790 MB, downloaded once) + ├── gamescope ── Xwayland ── Zink + └── Steam (steamrtarm64, fetched from Valve on first run) ── Proton ARM64 ── FEX +``` + +The runtime image is the one published for Bannerlator (`linuxfs.json` in +`The412Banner/winlator-contents`); this app installs and updates it from that catalog. **No Valve +software is redistributed** — the client is fetched from Valve's own manifest on the device at +first use. + +## Building + +Nothing is built locally. Push, and the `Build APK` workflow produces `steamdeck-apk`, a +debug-signed arm64 apk. It cross-compiles the two glibc preloads the session needs +(`libfakeinput.so`, `libblsession.so`) from the sources in this repo before the app build, so +those can never drift from what ships. + +## Device switches + +Files in `/sdcard/Download`, for a device that cannot be reached with a debugger: + +| File | Effect | +|---|---| +| `steamdeck-no-pad` | Turns the controller feature off entirely (a true baseline) | +| `steamdeck-pad-log` | Traces every interposer call into the session log | +| `steamdeck-driver` | `a7xx`, `a8xx` or `system` — overrides the Turnip build the compositor loads | + +Session logs land in `/sdcard/Download/SteamDeck/`. + +## Lineage and licence + +GPL-3.0. The gamescope runtime, the session shim and the fake-evdev interposer come from +maxjivi05's WinNative work and from Bannerlator, both GPL-3.0; the Wayland compositor and the +runtime plumbing are Bannerlator's. Valve, Steam and Proton are Valve Corporation's; this project +is not affiliated with Valve. diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000000..3402f2f438 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,74 @@ +plugins { + id 'com.android.application' +} +apply plugin: 'kotlin-android' + +android { + namespace 'com.the412banner.steamdeck' + compileSdk 34 + // The NDK is pinned by property so CI can hand in whatever the runner already has rather than + // downloading a second copy; see gradle.properties. + ndkVersion project.findProperty('ndkVersion') ?: '27.0.12077973' + + defaultConfig { + applicationId "com.the412banner.steamdeck" + minSdkVersion 26 + // 28 is not a leftover. An app on targetSdk 29+ runs in a domain that may not execute a + // file out of its own data directory, and this app's entire job is to exec a rootfs: + // proot, gamescope, the Steam client and everything it launches all live under files/. + targetSdkVersion 28 + versionCode 1 + versionName "0.1.0" + + ndk { + abiFilters 'arm64-v8a' + } + externalNativeBuild { + cmake { + arguments '-DANDROID_STL=c++_shared' + } + } + } + + externalNativeBuild { + cmake { + path 'src/main/cpp/CMakeLists.txt' + version '3.22.1' + } + } + + buildTypes { + debug { + minifyEnabled false + } + release { + minifyEnabled false + // Signed with the debug key for now: this is a test build handed to a device, not a + // published app, and a release key would have to live in the repo's secrets first. + signingConfig signingConfigs.debug + } + } + + packagingOptions { + jniLibs { + // The PulseAudio daemon is executed from the native library directory and its + // libraries are read out of the apk by the class loader: both want the old, + // uncompressed-and-extracted layout. + useLegacyPackaging = true + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = '17' + } +} + +dependencies { + // The runtime tarball is a zstd-compressed tar; nothing else in the app needs a library. + implementation 'com.github.luben:zstd-jni:1.5.2-3@aar' + implementation 'org.apache.commons:commons-compress:1.20' +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..26286ee44f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/assets/graphics_driver/adrenotools-turnip-sdk36.tzst b/app/src/main/assets/graphics_driver/adrenotools-turnip-sdk36.tzst new file mode 100644 index 0000000000..abcb8fbe85 Binary files /dev/null and b/app/src/main/assets/graphics_driver/adrenotools-turnip-sdk36.tzst differ diff --git a/app/src/main/assets/graphics_driver/adrenotools-turnip25.1.0.tzst b/app/src/main/assets/graphics_driver/adrenotools-turnip25.1.0.tzst new file mode 100644 index 0000000000..99db0ac054 Binary files /dev/null and b/app/src/main/assets/graphics_driver/adrenotools-turnip25.1.0.tzst differ diff --git a/app/src/main/assets/pulseaudio.tzst b/app/src/main/assets/pulseaudio.tzst new file mode 100644 index 0000000000..bf95d68533 Binary files /dev/null and b/app/src/main/assets/pulseaudio.tzst differ diff --git a/app/src/main/assets/wayland/keymap.xkb b/app/src/main/assets/wayland/keymap.xkb new file mode 100644 index 0000000000..d1689e661c --- /dev/null +++ b/app/src/main/assets/wayland/keymap.xkb @@ -0,0 +1,2039 @@ +xkb_keymap { +xkb_keycodes "evdev_aliases(qwerty)" { + minimum = 8; + maximum = 709; + = 9; + = 10; + = 11; + = 12; + = 13; + = 14; + = 15; + = 16; + = 17; + = 18; + = 19; + = 20; + = 21; + = 22; + = 23; + = 24; + = 25; + = 26; + = 27; + = 28; + = 29; + = 30; + = 31; + = 32; + = 33; + = 34; + = 35; + = 36; + = 37; + = 38; + = 39; + = 40; + = 41; + = 42; + = 43; + = 44; + = 45; + = 46; + = 47; + = 48; + = 49; + = 50; + = 51; + = 52; + = 53; + = 54; + = 55; + = 56; + = 57; + = 58; + = 59; + = 60; + = 61; + = 62; + = 63; + = 64; + = 65; + = 66; + = 67; + = 68; + = 69; + = 70; + = 71; + = 72; + = 73; + = 74; + = 75; + = 76; + = 77; + = 78; + = 79; + = 80; + = 81; + = 82; + = 83; + = 84; + = 85; + = 86; + = 87; + = 88; + = 89; + = 90; + = 91; + = 92; + = 93; + = 94; + = 95; + = 96; + = 97; + = 98; + = 99; + = 100; + = 101; + = 102; + = 103; + = 104; + = 105; + = 106; + = 107; + = 108; + = 109; + = 110; + = 111; + = 112; + = 113; + = 114; + = 115; + = 116; + = 117; + = 118; + = 119; + = 120; + = 121; + = 122; + = 123; + = 124; + = 125; + = 126; + = 127; + = 128; + = 129; + = 130; + = 131; + = 132; + = 133; + = 134; + = 135; + = 136; + = 137; + = 138; + = 139; + = 140; + = 141; + = 142; + = 143; + = 144; + = 145; + = 146; + = 147; + = 148; + = 149; + = 150; + = 151; + = 152; + = 153; + = 154; + = 155; + = 156; + = 157; + = 158; + = 159; + = 160; + = 161; + = 162; + = 163; + = 164; + = 165; + = 166; + = 167; + = 168; + = 169; + = 170; + = 171; + = 172; + = 173; + = 174; + = 175; + = 176; + = 177; + = 178; + = 179; + = 180; + = 181; + = 182; + = 183; + = 184; + = 185; + = 186; + = 187; + = 188; + = 189; + = 190; + = 191; + = 192; + = 193; + = 194; + = 195; + = 196; + = 197; + = 198; + = 199; + = 200; + = 201; + = 202; + = 203; + = 204; + = 205; + = 206; + = 207; + = 208; + = 209; + = 210; + = 211; + = 212; + = 213; + = 214; + = 215; + = 216; + = 217; + = 218; + = 219; + = 220; + = 221; + = 222; + = 223; + = 224; + = 225; + = 226; + = 227; + = 228; + = 229; + = 230; + = 231; + = 232; + = 233; + = 234; + = 235; + = 236; + = 237; + = 238; + = 239; + = 240; + = 241; + = 242; + = 243; + = 244; + = 245; + = 246; + = 247; + = 248; + = 249; + = 250; + = 251; + = 252; + = 253; + = 254; + = 255; + = 256; + = 360; + = 361; + = 362; + = 363; + = 364; + = 365; + = 366; + = 367; + = 368; + = 369; + = 370; + = 371; + = 372; + = 373; + = 374; + = 375; + = 376; + = 377; + = 378; + = 379; + = 380; + = 381; + = 382; + = 383; + = 384; + = 385; + = 386; + = 387; + = 388; + = 389; + = 390; + = 391; + = 392; + = 393; + = 394; + = 395; + = 396; + = 397; + = 398; + = 399; + = 400; + = 401; + = 402; + = 403; + = 404; + = 405; + = 406; + = 407; + = 408; + = 409; + = 410; + = 411; + = 412; + = 413; + = 414; + = 415; + = 416; + = 417; + = 418; + = 419; + = 420; + = 421; + = 422; + = 423; + = 424; + = 425; + = 426; + = 427; + = 428; + = 429; + = 430; + = 431; + = 432; + = 433; + = 434; + = 435; + = 436; + = 437; + = 438; + = 439; + = 440; + = 441; + = 442; + = 443; + = 444; + = 445; + = 446; + = 447; + = 448; + = 449; + = 450; + = 452; + = 453; + = 454; + = 455; + = 456; + = 457; + = 458; + = 459; + = 472; + = 473; + = 474; + = 475; + = 476; + = 477; + = 478; + = 479; + = 480; + = 481; + = 482; + = 483; + = 484; + = 485; + = 486; + = 487; + = 488; + = 489; + = 490; + = 491; + = 492; + = 493; + = 505; + = 506; + = 507; + = 508; + = 509; + = 510; + = 511; + = 512; + = 513; + = 514; + = 520; + = 521; + = 522; + = 523; + = 524; + = 525; + = 526; + = 527; + = 528; + = 529; + = 530; + = 531; + = 532; + = 533; + = 534; + = 535; + = 536; + = 537; + = 538; + = 539; + = 540; + = 541; + = 542; + = 543; + = 544; + = 545; + = 546; + = 547; + = 548; + = 549; + = 550; + = 568; + = 569; + = 570; + = 584; + = 585; + = 586; + = 587; + = 588; + = 589; + = 590; + = 591; + = 592; + = 593; + = 594; + = 595; + = 596; + = 597; + = 598; + = 599; + = 600; + = 601; + = 616; + = 617; + = 618; + = 619; + = 620; + = 621; + = 622; + = 623; + = 624; + = 625; + = 626; + = 627; + = 628; + = 629; + = 630; + = 631; + = 632; + = 633; + = 634; + = 635; + = 636; + = 637; + = 638; + = 639; + = 640; + = 641; + = 642; + = 643; + = 644; + = 645; + = 646; + = 647; + = 648; + = 649; + = 650; + = 651; + = 652; + = 653; + = 654; + = 655; + = 656; + = 657; + = 664; + = 665; + = 666; + = 667; + = 668; + = 669; + = 670; + = 671; + = 672; + = 673; + = 674; + = 675; + = 676; + = 677; + = 678; + = 679; + = 680; + = 681; + = 682; + = 683; + = 684; + = 685; + = 686; + = 687; + = 688; + = 689; + = 690; + = 691; + = 692; + = 693; + = 696; + = 697; + = 698; + = 699; + = 700; + = 701; + = 704; + = 705; + = 706; + = 707; + = 708; + = 709; + indicator 1 = "Caps Lock"; + indicator 2 = "Num Lock"; + indicator 3 = "Scroll Lock"; + indicator 4 = "Compose"; + indicator 5 = "Kana"; + indicator 6 = "Sleep"; + indicator 7 = "Suspend"; + indicator 8 = "Mute"; + indicator 9 = "Misc"; + indicator 10 = "Mail"; + indicator 11 = "Charging"; + indicator 12 = "Shift Lock"; + indicator 13 = "Group 2"; + indicator 14 = "Mouse Keys"; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; + alias = ; +}; + +xkb_types "complete" { + virtual_modifiers NumLock,Alt,LevelThree,Super,LevelFive,Meta,Hyper=0x4000,ScrollLock=0x8000; + + type "ONE_LEVEL" { + modifiers= none; + level_name[1]= "Any"; + }; + type "TWO_LEVEL" { + modifiers= Shift; + map[Shift]= 2; + level_name[1]= "Base"; + level_name[2]= "Shift"; + }; + type "ALPHABETIC" { + modifiers= Shift+Lock; + map[Shift]= 2; + map[Lock]= 2; + level_name[1]= "Base"; + level_name[2]= "Caps"; + }; + type "PC_ALT_LEVEL2" { + modifiers= Alt; + map[Alt]= 2; + level_name[1]= "Base"; + level_name[2]= "Alt"; + }; + type "PC_SUPER_LEVEL2" { + modifiers= Super; + map[Super]= 2; + level_name[1]= "Base"; + level_name[2]= "Super"; + }; + type "PC_SHIFT_SUPER_LEVEL2" { + modifiers= Shift+Super; + map[Shift+Super]= 2; + level_name[1]= "Base"; + level_name[2]= "Super"; + }; + type "PC_CONTROL_LEVEL2" { + modifiers= Control; + map[Control]= 2; + level_name[1]= "Base"; + level_name[2]= "Control"; + }; + type "PC_CONTROL_SUPER_LEVEL2" { + modifiers= Control+Super; + map[Control+Super]= 2; + map[Control]= 1; + preserve[Control]= Control; + map[Super]= 1; + preserve[Super]= Super; + level_name[1]= "Base"; + level_name[2]= "Control + Super"; + }; + type "CTRL+ALT" { + modifiers= Shift+Control+Alt+LevelThree; + map[Shift]= 2; + preserve[Shift]= Shift; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + preserve[Shift+LevelThree]= Shift; + map[Control]= 1; + preserve[Control]= Control; + map[Shift+Control]= 2; + preserve[Shift+Control]= Shift+Control; + map[Control+LevelThree]= 3; + preserve[Control+LevelThree]= Control; + map[Shift+Control+LevelThree]= 4; + preserve[Shift+Control+LevelThree]= Shift+Control; + map[Alt]= 1; + preserve[Alt]= Alt; + map[Shift+Alt]= 2; + preserve[Shift+Alt]= Shift+Alt; + map[Alt+LevelThree]= 3; + preserve[Alt+LevelThree]= Alt; + map[Shift+Alt+LevelThree]= 4; + preserve[Shift+Alt+LevelThree]= Shift+Alt; + map[Control+Alt]= 5; + map[Shift+Control+Alt]= 2; + preserve[Shift+Control+Alt]= Shift+Control+Alt; + map[Control+Alt+LevelThree]= 3; + preserve[Control+Alt+LevelThree]= Control+Alt; + map[Shift+Control+Alt+LevelThree]= 4; + preserve[Shift+Control+Alt+LevelThree]= Shift+Control+Alt; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "Ctrl+Alt"; + }; + type "THREE_LEVEL" { + modifiers= Shift+LevelThree; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 3; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "Level3"; + }; + type "FOUR_LEVEL" { + modifiers= Shift+LevelThree; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + }; + type "FOUR_LEVEL_ALPHABETIC" { + modifiers= Shift+Lock+LevelThree; + map[Shift]= 2; + map[Lock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 4; + map[Shift+Lock+LevelThree]= 3; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + }; + type "FOUR_LEVEL_SEMIALPHABETIC" { + modifiers= Shift+Lock+LevelThree; + map[Shift]= 2; + map[Lock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 3; + preserve[Lock+LevelThree]= Lock; + map[Shift+Lock+LevelThree]= 4; + preserve[Shift+Lock+LevelThree]= Lock; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + }; + type "FOUR_LEVEL_KEYPAD" { + modifiers= Shift+NumLock+LevelThree; + map[Shift]= 2; + map[NumLock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[NumLock+LevelThree]= 4; + map[Shift+NumLock+LevelThree]= 3; + level_name[1]= "Base"; + level_name[2]= "Shift/Numlock"; + level_name[3]= "AltGr"; + level_name[4]= "Shift/Numlock AltGr"; + }; + type "FOUR_LEVEL_MIXED_KEYPAD" { + modifiers= Shift+NumLock+LevelThree; + map[Shift]= 2; + map[NumLock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[NumLock+LevelThree]= 3; + map[Shift+NumLock+LevelThree]= 4; + level_name[1]= "Base"; + level_name[2]= "Number"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + }; + type "FOUR_LEVEL_LOCKABLE_LEVEL2" { + modifiers= Shift+LevelThree+LevelFive; + map[Shift]= 2; + map[LevelFive]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[LevelThree+LevelFive]= 3; + map[Shift+LevelThree+LevelFive]= 4; + level_name[1]= "Base"; + level_name[2]= "Digit"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + }; + type "FOUR_LEVEL_X" { + modifiers= Shift+Control+Alt+LevelThree; + map[LevelThree]= 2; + map[Shift+LevelThree]= 3; + map[Control+Alt]= 4; + level_name[1]= "Base"; + level_name[2]= "AltGr"; + level_name[3]= "Shift AltGr"; + level_name[4]= "Ctrl+Alt"; + }; + type "SEPARATE_CAPS_AND_SHIFT_ALPHABETIC" { + modifiers= Shift+Lock+LevelThree; + map[Shift]= 2; + map[Lock]= 4; + preserve[Lock]= Lock; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 3; + preserve[Lock+LevelThree]= Lock; + map[Shift+Lock+LevelThree]= 3; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Caps / Shift AltGr"; + }; + type "FOUR_LEVEL_PLUS_LOCK" { + modifiers= Shift+Lock+LevelThree; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock]= 5; + map[Shift+Lock]= 2; + map[Lock+LevelThree]= 3; + map[Shift+Lock+LevelThree]= 4; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "Lock"; + }; + type "EIGHT_LEVEL" { + modifiers= Shift+LevelThree+LevelFive; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[LevelFive]= 5; + map[Shift+LevelFive]= 6; + map[LevelThree+LevelFive]= 7; + map[Shift+LevelThree+LevelFive]= 8; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "X"; + level_name[6]= "X Shift"; + level_name[7]= "X AltGr"; + level_name[8]= "X Shift AltGr"; + }; + type "EIGHT_LEVEL_ALPHABETIC" { + modifiers= Shift+Lock+LevelThree+LevelFive; + map[Shift]= 2; + map[Lock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 4; + map[Shift+Lock+LevelThree]= 3; + map[LevelFive]= 5; + map[Shift+LevelFive]= 6; + map[Lock+LevelFive]= 6; + map[Shift+Lock+LevelFive]= 5; + map[LevelThree+LevelFive]= 7; + map[Shift+LevelThree+LevelFive]= 8; + map[Lock+LevelThree+LevelFive]= 8; + map[Shift+Lock+LevelThree+LevelFive]= 7; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "X"; + level_name[6]= "X Shift"; + level_name[7]= "X AltGr"; + level_name[8]= "X Shift AltGr"; + }; + type "EIGHT_LEVEL_SEMIALPHABETIC" { + modifiers= Shift+Lock+LevelThree+LevelFive; + map[Shift]= 2; + map[Lock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 3; + preserve[Lock+LevelThree]= Lock; + map[Shift+Lock+LevelThree]= 4; + preserve[Shift+Lock+LevelThree]= Lock; + map[LevelFive]= 5; + map[Shift+LevelFive]= 6; + map[Lock+LevelFive]= 6; + map[Shift+Lock+LevelFive]= 5; + map[LevelThree+LevelFive]= 7; + map[Shift+LevelThree+LevelFive]= 8; + map[Lock+LevelThree+LevelFive]= 7; + preserve[Lock+LevelThree+LevelFive]= Lock; + map[Shift+Lock+LevelThree+LevelFive]= 8; + preserve[Shift+Lock+LevelThree+LevelFive]= Lock; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "X"; + level_name[6]= "X Shift"; + level_name[7]= "X AltGr"; + level_name[8]= "X Shift AltGr"; + }; + type "EIGHT_LEVEL_WITH_LEVEL5_LOCK" { + modifiers= Shift+NumLock+LevelThree+LevelFive; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[LevelFive]= 5; + map[Shift+LevelFive]= 6; + preserve[Shift+LevelFive]= Shift; + map[LevelThree+LevelFive]= 7; + map[Shift+LevelThree+LevelFive]= 8; + map[NumLock]= 5; + map[Shift+NumLock]= 6; + preserve[Shift+NumLock]= Shift; + map[NumLock+LevelThree]= 7; + map[Shift+NumLock+LevelThree]= 8; + map[Shift+NumLock+LevelFive]= 2; + map[NumLock+LevelThree+LevelFive]= 3; + map[Shift+NumLock+LevelThree+LevelFive]= 4; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "X"; + level_name[6]= "X Shift"; + level_name[7]= "X AltGr"; + level_name[8]= "X Shift AltGr"; + }; + type "EIGHT_LEVEL_ALPHABETIC_WITH_LEVEL5_LOCK" { + modifiers= Shift+Lock+NumLock+LevelThree+LevelFive; + map[Shift]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[LevelFive]= 5; + map[Shift+LevelFive]= 6; + preserve[Shift+LevelFive]= Shift; + map[LevelThree+LevelFive]= 7; + map[Shift+LevelThree+LevelFive]= 8; + map[NumLock]= 5; + map[Shift+NumLock]= 6; + preserve[Shift+NumLock]= Shift; + map[NumLock+LevelThree]= 7; + map[Shift+NumLock+LevelThree]= 8; + map[Shift+NumLock+LevelFive]= 2; + map[NumLock+LevelThree+LevelFive]= 3; + map[Shift+NumLock+LevelThree+LevelFive]= 4; + map[Lock]= 2; + map[Lock+LevelThree]= 3; + map[Shift+Lock+LevelThree]= 4; + map[Lock+LevelFive]= 5; + map[Shift+Lock+LevelFive]= 6; + map[Lock+LevelThree+LevelFive]= 7; + map[Shift+Lock+LevelThree+LevelFive]= 8; + map[Lock+NumLock]= 5; + map[Shift+Lock+NumLock]= 6; + map[Lock+NumLock+LevelThree]= 7; + map[Shift+Lock+NumLock+LevelThree]= 8; + map[Lock+NumLock+LevelFive]= 2; + map[Lock+NumLock+LevelThree+LevelFive]= 3; + map[Shift+Lock+NumLock+LevelThree+LevelFive]= 4; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "AltGr"; + level_name[4]= "Shift AltGr"; + level_name[5]= "X"; + level_name[6]= "X Shift"; + level_name[7]= "X AltGr"; + level_name[8]= "X Shift AltGr"; + }; + type "EIGHT_LEVEL_BY_CTRL" { + modifiers= Shift+Lock+Control+LevelThree; + map[Shift]= 2; + map[Lock]= 2; + map[LevelThree]= 3; + map[Shift+LevelThree]= 4; + map[Lock+LevelThree]= 4; + map[Shift+Lock+LevelThree]= 3; + map[Control]= 5; + map[Shift+Control]= 6; + map[Lock+Control]= 6; + map[Shift+Lock+Control]= 5; + map[Control+LevelThree]= 7; + map[Shift+Control+LevelThree]= 8; + map[Lock+Control+LevelThree]= 8; + map[Shift+Lock+Control+LevelThree]= 7; + level_name[1]= "Base"; + level_name[2]= "Shift"; + level_name[3]= "Level3"; + level_name[4]= "Shift Level3"; + level_name[5]= "Ctrl"; + level_name[6]= "Shift Ctrl"; + level_name[7]= "Level3 Ctrl"; + level_name[8]= "Shift Level3 Ctrl"; + }; + type "KEYPAD" { + modifiers= Shift+NumLock; + map[NumLock]= 2; + level_name[1]= "Base"; + level_name[2]= "Number"; + }; + type "SHIFT+ALT" { + modifiers= Shift+Alt; + map[Shift+Alt]= 2; + level_name[1]= "Base"; + level_name[2]= "Shift+Alt"; + }; +}; + +xkb_compatibility "complete" { + virtual_modifiers NumLock,Alt,LevelThree,Super,LevelFive,Meta,Hyper=0x4000,ScrollLock=0x8000; + + interpret.useModMapMods= AnyLevel; + interpret.repeat= False; + interpret ISO_Level2_Latch+Exactly(Shift) { + useModMapMods=level1; + action= LatchMods(modifiers=Shift,clearLocks,latchToLock); + }; + interpret Shift_Lock+AnyOf(Shift+Lock) { + action= LockMods(modifiers=Shift); + }; + interpret Num_Lock+AnyOf(all) { + virtualModifier= NumLock; + action= LockMods(modifiers=NumLock); + }; + interpret ISO_Level3_Shift+AnyOf(all) { + virtualModifier= LevelThree; + useModMapMods=level1; + action= SetMods(modifiers=LevelThree,clearLocks); + }; + interpret ISO_Level3_Latch+AnyOf(all) { + virtualModifier= LevelThree; + useModMapMods=level1; + action= LatchMods(modifiers=LevelThree,clearLocks,latchToLock); + }; + interpret ISO_Level3_Lock+AnyOf(all) { + virtualModifier= LevelThree; + useModMapMods=level1; + action= LockMods(modifiers=LevelThree); + }; + interpret Alt_L+AnyOf(all) { + virtualModifier= Alt; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Alt_R+AnyOf(all) { + virtualModifier= Alt; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Meta_L+AnyOf(all) { + virtualModifier= Meta; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Meta_R+AnyOf(all) { + virtualModifier= Meta; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Super_L+AnyOf(all) { + virtualModifier= Super; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Super_R+AnyOf(all) { + virtualModifier= Super; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Hyper_L+AnyOf(all) { + virtualModifier= Hyper; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Hyper_R+AnyOf(all) { + virtualModifier= Hyper; + action= SetMods(modifiers=modMapMods,clearLocks); + }; + interpret Scroll_Lock+AnyOf(all) { + virtualModifier= ScrollLock; + action= LockMods(modifiers=modMapMods); + }; + interpret ISO_Level5_Shift+AnyOf(all) { + virtualModifier= LevelFive; + useModMapMods=level1; + action= SetMods(modifiers=LevelFive,clearLocks); + }; + interpret ISO_Level5_Latch+AnyOf(all) { + virtualModifier= LevelFive; + useModMapMods=level1; + action= LatchMods(modifiers=LevelFive,clearLocks,latchToLock); + }; + interpret ISO_Level5_Lock+AnyOf(all) { + virtualModifier= LevelFive; + useModMapMods=level1; + action= LockMods(modifiers=LevelFive); + }; + interpret Mode_switch+AnyOfOrNone(all) { + action= SetGroup(group=+1); + }; + interpret ISO_Level3_Shift+AnyOfOrNone(all) { + action= SetMods(modifiers=LevelThree,clearLocks); + }; + interpret ISO_Level3_Latch+AnyOfOrNone(all) { + action= LatchMods(modifiers=LevelThree,clearLocks,latchToLock); + }; + interpret ISO_Level3_Lock+AnyOfOrNone(all) { + action= LockMods(modifiers=LevelThree); + }; + interpret ISO_Group_Latch+AnyOfOrNone(all) { + action= LatchGroup(group=2); + }; + interpret ISO_Next_Group+AnyOfOrNone(all) { + action= LockGroup(group=+1); + }; + interpret ISO_Prev_Group+AnyOfOrNone(all) { + action= LockGroup(group=-1); + }; + interpret ISO_First_Group+AnyOfOrNone(all) { + action= LockGroup(group=1); + }; + interpret ISO_Last_Group+AnyOfOrNone(all) { + action= LockGroup(group=2); + }; + interpret KP_1+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=+1); + }; + interpret KP_End+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=+1); + }; + interpret KP_2+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+0,y=+1); + }; + interpret KP_Down+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+0,y=+1); + }; + interpret KP_3+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=+1); + }; + interpret KP_Next+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=+1); + }; + interpret KP_4+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=+0); + }; + interpret KP_Left+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=+0); + }; + interpret KP_6+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=+0); + }; + interpret KP_Right+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=+0); + }; + interpret KP_7+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=-1); + }; + interpret KP_Home+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=-1); + }; + interpret KP_8+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+0,y=-1); + }; + interpret KP_Up+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+0,y=-1); + }; + interpret KP_9+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=-1); + }; + interpret KP_Prior+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=-1); + }; + interpret KP_5+AnyOfOrNone(all) { + repeat= True; + action= PtrBtn(button=default); + }; + interpret KP_Begin+AnyOfOrNone(all) { + repeat= True; + action= PtrBtn(button=default); + }; + interpret KP_F2+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=1); + }; + interpret KP_Divide+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=1); + }; + interpret KP_F3+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=2); + }; + interpret KP_Multiply+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=2); + }; + interpret KP_F4+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=3); + }; + interpret KP_Subtract+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=3); + }; + interpret KP_Separator+AnyOfOrNone(all) { + repeat= True; + action= PtrBtn(button=default,count=2); + }; + interpret KP_Add+AnyOfOrNone(all) { + repeat= True; + action= PtrBtn(button=default,count=2); + }; + interpret KP_0+AnyOfOrNone(all) { + repeat= True; + action= LockPtrBtn(button=default,affect=lock); + }; + interpret KP_Insert+AnyOfOrNone(all) { + repeat= True; + action= LockPtrBtn(button=default,affect=lock); + }; + interpret KP_Decimal+AnyOfOrNone(all) { + repeat= True; + action= LockPtrBtn(button=default,affect=unlock); + }; + interpret KP_Delete+AnyOfOrNone(all) { + repeat= True; + action= LockPtrBtn(button=default,affect=unlock); + }; + interpret F25+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=1); + }; + interpret F26+AnyOfOrNone(all) { + repeat= True; + action= SetPtrDflt(affect=button,button=2); + }; + interpret F27+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=-1); + }; + interpret F29+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=-1); + }; + interpret F31+AnyOfOrNone(all) { + repeat= True; + action= PtrBtn(button=default); + }; + interpret F33+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=-1,y=+1); + }; + interpret F35+AnyOfOrNone(all) { + repeat= True; + action= MovePtr(x=+1,y=+1); + }; + interpret Pointer_Button_Dflt+AnyOfOrNone(all) { + action= PtrBtn(button=default); + }; + interpret Pointer_Button1+AnyOfOrNone(all) { + action= PtrBtn(button=1); + }; + interpret Pointer_Button2+AnyOfOrNone(all) { + action= PtrBtn(button=2); + }; + interpret Pointer_Button3+AnyOfOrNone(all) { + action= PtrBtn(button=3); + }; + interpret Pointer_DblClick_Dflt+AnyOfOrNone(all) { + action= PtrBtn(button=default,count=2); + }; + interpret Pointer_DblClick1+AnyOfOrNone(all) { + action= PtrBtn(button=1,count=2); + }; + interpret Pointer_DblClick2+AnyOfOrNone(all) { + action= PtrBtn(button=2,count=2); + }; + interpret Pointer_DblClick3+AnyOfOrNone(all) { + action= PtrBtn(button=3,count=2); + }; + interpret Pointer_Drag_Dflt+AnyOfOrNone(all) { + action= LockPtrBtn(button=default,affect=both); + }; + interpret Pointer_Drag1+AnyOfOrNone(all) { + action= LockPtrBtn(button=1,affect=both); + }; + interpret Pointer_Drag2+AnyOfOrNone(all) { + action= LockPtrBtn(button=2,affect=both); + }; + interpret Pointer_Drag3+AnyOfOrNone(all) { + action= LockPtrBtn(button=3,affect=both); + }; + interpret Pointer_EnableKeys+AnyOfOrNone(all) { + action= LockControls(controls=MouseKeys); + }; + interpret Pointer_Accelerate+AnyOfOrNone(all) { + action= LockControls(controls=MouseKeysAccel); + }; + interpret Pointer_DfltBtnNext+AnyOfOrNone(all) { + action= SetPtrDflt(affect=button,button=+1); + }; + interpret Pointer_DfltBtnPrev+AnyOfOrNone(all) { + action= SetPtrDflt(affect=button,button=-1); + }; + interpret AccessX_Enable+AnyOfOrNone(all) { + action= LockControls(controls=AccessXKeys); + }; + interpret AccessX_Feedback_Enable+AnyOfOrNone(all) { + action= LockControls(controls=AccessXFeedback); + }; + interpret RepeatKeys_Enable+AnyOfOrNone(all) { + action= LockControls(controls=RepeatKeys); + }; + interpret SlowKeys_Enable+AnyOfOrNone(all) { + action= LockControls(controls=SlowKeys); + }; + interpret BounceKeys_Enable+AnyOfOrNone(all) { + action= LockControls(controls=BounceKeys); + }; + interpret StickyKeys_Enable+AnyOfOrNone(all) { + action= LockControls(controls=StickyKeys); + }; + interpret MouseKeys_Enable+AnyOfOrNone(all) { + action= LockControls(controls=MouseKeys); + }; + interpret MouseKeys_Accel_Enable+AnyOfOrNone(all) { + action= LockControls(controls=MouseKeysAccel); + }; + interpret Overlay1_Enable+AnyOfOrNone(all) { + action= LockControls(controls=none); + }; + interpret Overlay2_Enable+AnyOfOrNone(all) { + action= LockControls(controls=none); + }; + interpret AudibleBell_Enable+AnyOfOrNone(all) { + action= LockControls(controls=AudibleBell); + }; + interpret Terminate_Server+AnyOfOrNone(all) { + action= Terminate(); + }; + interpret Alt_L+AnyOfOrNone(all) { + action= SetMods(modifiers=Alt,clearLocks); + }; + interpret Alt_R+AnyOfOrNone(all) { + action= SetMods(modifiers=Alt,clearLocks); + }; + interpret Meta_L+AnyOfOrNone(all) { + action= SetMods(modifiers=Meta,clearLocks); + }; + interpret Meta_R+AnyOfOrNone(all) { + action= SetMods(modifiers=Meta,clearLocks); + }; + interpret Super_L+AnyOfOrNone(all) { + action= SetMods(modifiers=Super,clearLocks); + }; + interpret Super_R+AnyOfOrNone(all) { + action= SetMods(modifiers=Super,clearLocks); + }; + interpret Hyper_L+AnyOfOrNone(all) { + action= SetMods(modifiers=Hyper,clearLocks); + }; + interpret Hyper_R+AnyOfOrNone(all) { + action= SetMods(modifiers=Hyper,clearLocks); + }; + interpret Shift_L+AnyOfOrNone(all) { + action= SetMods(modifiers=Shift,clearLocks); + }; + interpret Shift_R+AnyOfOrNone(all) { + action= SetMods(modifiers=Shift,clearLocks); + }; + interpret XF86Switch_VT_1+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=1,!same); + }; + interpret XF86Switch_VT_2+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=2,!same); + }; + interpret XF86Switch_VT_3+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=3,!same); + }; + interpret XF86Switch_VT_4+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=4,!same); + }; + interpret XF86Switch_VT_5+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=5,!same); + }; + interpret XF86Switch_VT_6+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=6,!same); + }; + interpret XF86Switch_VT_7+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=7,!same); + }; + interpret XF86Switch_VT_8+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=8,!same); + }; + interpret XF86Switch_VT_9+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=9,!same); + }; + interpret XF86Switch_VT_10+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=10,!same); + }; + interpret XF86Switch_VT_11+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=11,!same); + }; + interpret XF86Switch_VT_12+AnyOfOrNone(all) { + repeat= True; + action= SwitchScreen(screen=12,!same); + }; + interpret XF86LogGrabInfo+AnyOfOrNone(all) { + repeat= True; + action= Private(type=0x86,data[0]=0x50,data[1]=0x72,data[2]=0x47,data[3]=0x72,data[4]=0x62,data[5]=0x73,data[6]=0x00); + }; + interpret XF86LogWindowTree+AnyOfOrNone(all) { + repeat= True; + action= Private(type=0x86,data[0]=0x50,data[1]=0x72,data[2]=0x57,data[3]=0x69,data[4]=0x6e,data[5]=0x73,data[6]=0x00); + }; + interpret XF86Next_VMode+AnyOfOrNone(all) { + repeat= True; + action= Private(type=0x86,data[0]=0x2b,data[1]=0x56,data[2]=0x4d,data[3]=0x6f,data[4]=0x64,data[5]=0x65,data[6]=0x00); + }; + interpret XF86Prev_VMode+AnyOfOrNone(all) { + repeat= True; + action= Private(type=0x86,data[0]=0x2d,data[1]=0x56,data[2]=0x4d,data[3]=0x6f,data[4]=0x64,data[5]=0x65,data[6]=0x00); + }; + interpret ISO_Level5_Shift+AnyOfOrNone(all) { + action= SetMods(modifiers=LevelFive,clearLocks); + }; + interpret ISO_Level5_Latch+AnyOfOrNone(all) { + action= LatchMods(modifiers=LevelFive,clearLocks,latchToLock); + }; + interpret ISO_Level5_Lock+AnyOfOrNone(all) { + action= LockMods(modifiers=LevelFive); + }; + interpret Caps_Lock+AnyOfOrNone(all) { + action= LockMods(modifiers=Lock); + }; + interpret Any+Exactly(Lock) { + action= LockMods(modifiers=Lock); + }; + interpret Any+AnyOf(all) { + action= SetMods(modifiers=modMapMods,clearLocks); + }; + indicator "Caps Lock" { + whichModState= locked; + modifiers= Lock; + }; + indicator "Num Lock" { + whichModState= locked; + modifiers= NumLock; + }; + indicator "Scroll Lock" { + whichModState= locked; + modifiers= ScrollLock; + }; + indicator "Shift Lock" { + whichModState= locked; + modifiers= Shift; + }; + indicator "Group 2" { + groups= 0xfffffffe; + }; + indicator "Mouse Keys" { + controls= MouseKeys; + }; +}; + +xkb_symbols "pc_us_inet(evdev)" { + name[1]="English (US)"; + + key { [ Escape ] }; + key { [ 1, exclam ] }; + key { [ 2, at ] }; + key { [ 3, numbersign ] }; + key { [ 4, dollar ] }; + key { [ 5, percent ] }; + key { [ 6, asciicircum ] }; + key { [ 7, ampersand ] }; + key { [ 8, asterisk ] }; + key { [ 9, parenleft ] }; + key { [ 0, parenright ] }; + key { [ minus, underscore ] }; + key { [ equal, plus ] }; + key { [ BackSpace, BackSpace ] }; + key { [ Tab, ISO_Left_Tab ] }; + key { [ q, Q ] }; + key { [ w, W ] }; + key { [ e, E ] }; + key { [ r, R ] }; + key { [ t, T ] }; + key { [ y, Y ] }; + key { [ u, U ] }; + key { [ i, I ] }; + key { [ o, O ] }; + key { [ p, P ] }; + key { [ bracketleft, braceleft ] }; + key { [ bracketright, braceright ] }; + key { [ Return ] }; + key { [ Control_L ] }; + key { [ a, A ] }; + key { [ s, S ] }; + key { [ d, D ] }; + key { [ f, F ] }; + key { [ g, G ] }; + key { [ h, H ] }; + key { [ j, J ] }; + key { [ k, K ] }; + key { [ l, L ] }; + key { [ semicolon, colon ] }; + key { [ apostrophe, quotedbl ] }; + key { [ grave, asciitilde ] }; + key { [ Shift_L ] }; + key { [ backslash, bar ] }; + key { [ z, Z ] }; + key { [ x, X ] }; + key { [ c, C ] }; + key { [ v, V ] }; + key { [ b, B ] }; + key { [ n, N ] }; + key { [ m, M ] }; + key { [ comma, less ] }; + key { [ period, greater ] }; + key { [ slash, question ] }; + key { [ Shift_R ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ KP_Multiply, KP_Multiply, KP_Multiply, KP_Multiply, XF86ClearGrab ] + }; + key { [ Alt_L ] }; + key { [ space ] }; + key { [ Caps_Lock ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ F1, F1, F1, F1, XF86Switch_VT_1 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F2, F2, F2, F2, XF86Switch_VT_2 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F3, F3, F3, F3, XF86Switch_VT_3 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F4, F4, F4, F4, XF86Switch_VT_4 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F5, F5, F5, F5, XF86Switch_VT_5 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F6, F6, F6, F6, XF86Switch_VT_6 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F7, F7, F7, F7, XF86Switch_VT_7 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F8, F8, F8, F8, XF86Switch_VT_8 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F9, F9, F9, F9, XF86Switch_VT_9 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F10, F10, F10, F10, XF86Switch_VT_10 ] + }; + key { [ Num_Lock ] }; + key { [ Scroll_Lock ] }; + key { [ KP_Home, KP_7 ] }; + key { [ KP_Up, KP_8 ] }; + key { [ KP_Prior, KP_9 ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ KP_Subtract, KP_Subtract, KP_Subtract, KP_Subtract, XF86Prev_VMode ] + }; + key { [ KP_Left, KP_4 ] }; + key { [ KP_Begin, KP_5 ] }; + key { [ KP_Right, KP_6 ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ KP_Add, KP_Add, KP_Add, KP_Add, XF86Next_VMode ] + }; + key { [ KP_End, KP_1 ] }; + key { [ KP_Down, KP_2 ] }; + key { [ KP_Next, KP_3 ] }; + key { [ KP_Insert, KP_0 ] }; + key { [ KP_Delete, KP_Decimal ] }; + key { [ ISO_Level3_Shift ] }; + key { + type= "PC_CONTROL_SUPER_LEVEL2", + symbols[1]= [ F24, XF86TouchpadToggle ] + }; + key { [ less, greater, bar, brokenbar ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ F11, F11, F11, F11, XF86Switch_VT_11 ] + }; + key { + type= "CTRL+ALT", + symbols[1]= [ F12, F12, F12, F12, XF86Switch_VT_12 ] + }; + key { [ Katakana ] }; + key { [ Hiragana ] }; + key { [ Henkan_Mode ] }; + key { [ Hiragana_Katakana ] }; + key { [ Muhenkan ] }; + key { [ KP_Enter ] }; + key { [ Control_R ] }; + key { + type= "CTRL+ALT", + symbols[1]= [ KP_Divide, KP_Divide, KP_Divide, KP_Divide, XF86Ungrab ] + }; + key { + type= "PC_ALT_LEVEL2", + symbols[1]= [ Print, Sys_Req ] + }; + key { [ Alt_R ] }; + key { [ Linefeed ] }; + key { [ Home ] }; + key { [ Up ] }; + key { [ Prior ] }; + key { [ Left ] }; + key { [ Right ] }; + key { [ End ] }; + key { [ Down ] }; + key { [ Next ] }; + key { [ Insert ] }; + key { [ Delete ] }; + key { [ XF86AudioMute ] }; + key { [ XF86AudioLowerVolume ] }; + key { [ XF86AudioRaiseVolume ] }; + key { [ XF86PowerOff ] }; + key { [ KP_Equal ] }; + key { [ plusminus ] }; + key { + type= "PC_CONTROL_LEVEL2", + symbols[1]= [ Pause, Break ] + }; + key { [ XF86LaunchA ] }; + key { [ KP_Decimal, KP_Decimal ] }; + key { [ Hangul ] }; + key { [ Hangul_Hanja ] }; + key { [ Super_L ] }; + key { [ Super_R ] }; + key { [ Menu ] }; + key { [ Cancel ] }; + key { [ Redo ] }; + key { [ SunProps ] }; + key { [ Undo ] }; + key { [ SunFront ] }; + key { [ XF86Copy ] }; + key { [ XF86Open ] }; + key { [ XF86Paste ] }; + key { [ Find ] }; + key { [ XF86Cut ] }; + key { [ Help ] }; + key { [ XF86MenuKB ] }; + key { [ XF86Calculator ] }; + key { [ XF86Sleep ] }; + key { [ XF86WakeUp ] }; + key { [ XF86Explorer ] }; + key { [ XF86Send ] }; + key { [ XF86Xfer ] }; + key { [ XF86Launch1 ] }; + key { [ XF86Launch2 ] }; + key { [ XF86WWW ] }; + key { [ XF86DOS ] }; + key { [ XF86ScreenSaver ] }; + key { [ XF86RotateWindows ] }; + key { [ XF86TaskPane ] }; + key { [ XF86Mail ] }; + key { [ XF86Favorites ] }; + key { [ XF86MyComputer ] }; + key { [ XF86Back ] }; + key { [ XF86Forward ] }; + key { [ XF86Eject ] }; + key { [ XF86Eject ] }; + key { [ XF86AudioNext ] }; + key { [ XF86AudioPlay, XF86AudioPause ] }; + key { [ XF86AudioPrev ] }; + key { [ XF86AudioStop, XF86Eject ] }; + key { [ XF86AudioRecord ] }; + key { [ XF86AudioRewind ] }; + key { [ XF86Phone ] }; + key { [ XF86Tools ] }; + key { [ XF86HomePage ] }; + key { [ XF86Reload ] }; + key { [ XF86Close ] }; + key { [ XF86ScrollUp ] }; + key { [ XF86ScrollDown ] }; + key { [ parenleft ] }; + key { [ parenright ] }; + key { [ XF86New ] }; + key { [ Redo ] }; + key { [ XF86Tools ] }; + key { [ XF86Launch5 ] }; + key { [ XF86Launch6 ] }; + key { [ XF86Launch7 ] }; + key { [ XF86Launch8 ] }; + key { [ XF86Launch9 ] }; + key { [ F19 ] }; + key { [ XF86AudioMicMute ] }; + key { [ XF86TouchpadToggle ] }; + key { [ XF86TouchpadOn ] }; + key { + type= "PC_SHIFT_SUPER_LEVEL2", + symbols[1]= [ F23, XF86Assistant ] + }; + key { + type= "PC_CONTROL_SUPER_LEVEL2", + symbols[1]= [ F24, XF86TouchpadToggle ] + }; + key { [ ISO_Level5_Shift ] }; + key { [ NoSymbol, Alt_L ] }; + key { [ NoSymbol, Meta_L ] }; + key { [ NoSymbol, Super_L ] }; + key { [ NoSymbol, Hyper_L ] }; + key { [ XF86AudioPlay ] }; + key { [ XF86AudioPause ] }; + key { [ XF86Launch3 ] }; + key { [ XF86Launch4 ] }; + key { [ XF86LaunchB ] }; + key { [ XF86Suspend ] }; + key { [ XF86Close ] }; + key { [ XF86AudioPlay ] }; + key { [ XF86AudioForward ] }; + key { [ XF86AudioBassBoost ] }; + key { [ Print ] }; + key { [ XF86WebCam ] }; + key { [ XF86AudioPreset ] }; + key { [ XF86Mail ] }; + key { [ XF86Messenger ] }; + key { [ XF86Search ] }; + key { [ XF86Go ] }; + key { [ XF86Finance ] }; + key { [ XF86Game ] }; + key { [ XF86Shop ] }; + key { [ Cancel ] }; + key { [ XF86MonBrightnessDown ] }; + key { [ XF86MonBrightnessUp ] }; + key { [ XF86AudioMedia ] }; + key { [ XF86Display ] }; + key { [ XF86KbdLightOnOff ] }; + key { [ XF86KbdBrightnessDown ] }; + key { [ XF86KbdBrightnessUp ] }; + key { [ XF86Send ] }; + key { [ XF86Reply ] }; + key { [ XF86MailForward ] }; + key { [ XF86Save ] }; + key { [ XF86Documents ] }; + key { [ XF86Battery ] }; + key { [ XF86Bluetooth ] }; + key { [ XF86WLAN ] }; + key { [ XF86UWB ] }; + key { [ XF86Next_VMode ] }; + key { [ XF86Prev_VMode ] }; + key { [ XF86MonBrightnessCycle ] }; + key { [ XF86BrightnessAuto ] }; + key { [ XF86DisplayOff ] }; + key { [ XF86WWAN ] }; + key { [ XF86RFKill ] }; + key { [ XF86AudioMicMute ] }; + key { [ XF86OK ] }; + key { [ XF86Select ] }; + key { [ XF86GoTo ] }; + key { [ XF86Clear ] }; + key { [ XF86Option ] }; + key { [ XF86Info ] }; + key { [ XF86Time ] }; + key { [ XF86VendorLogo ] }; + key { [ XF86MediaSelectProgramGuide ] }; + key { [ XF86NextFavorite ] }; + key { [ XF86Favorites ] }; + key { [ XF86MediaSelectProgramGuide ] }; + key { [ XF86MediaSelectHome ] }; + key { [ XF86MediaLanguageMenu ] }; + key { [ XF86MediaTitleMenu ] }; + key { [ XF86Subtitle ] }; + key { [ XF86CycleAngle ] }; + key { [ XF86FullScreen ] }; + key { [ XF86AudioChannelMode ] }; + key { [ XF86Keyboard ] }; + key { [ XF86AspectRatio ] }; + key { [ XF86MediaSelectPC ] }; + key { [ XF86MediaSelectTV ] }; + key { [ XF86MediaSelectCable ] }; + key { [ XF86MediaSelectVCR ] }; + key { [ XF86MediaSelectVCRPlus ] }; + key { [ XF86MediaSelectSatellite ] }; + key { [ XF86CD ] }; + key { [ XF86MediaSelectTape ] }; + key { [ XF86MediaSelectRadio ] }; + key { [ XF86MediaSelectTuner ] }; + key { [ XF86MediaPlayer ] }; + key { [ XF86MediaSelectTeletext ] }; + key { [ XF86DVD ] }; + key { [ XF86MediaSelectAuxiliary ] }; + key { [ XF86Audio ] }; + key { [ XF86Video ] }; + key { [ XF86Memo ] }; + key { [ XF86Calendar ] }; + key { [ XF86Red ] }; + key { [ XF86Green ] }; + key { [ XF86Yellow ] }; + key { [ XF86Blue ] }; + key { [ XF86ChannelUp ] }; + key { [ XF86ChannelDown ] }; + key { [ XF86MediaPlaySlow ] }; + key { [ XF86AudioRandomPlay ] }; + key { [ XF86Break ] }; + key { [ XF86NumberEntryMode ] }; + key { [ XF86VideoPhone ] }; + key { [ XF86Game ] }; + key { [ XF86ZoomIn ] }; + key { [ XF86ZoomOut ] }; + key { [ XF86ZoomReset ] }; + key { [ XF86Word ] }; + key { [ XF86Editor ] }; + key { [ XF86Excel ] }; + key { [ XF86GraphicsEditor ] }; + key { [ XF86Presentation ] }; + key { [ XF86Database ] }; + key { [ XF86News ] }; + key { [ XF86Voicemail ] }; + key { [ XF86Addressbook ] }; + key { [ XF86Messenger ] }; + key { [ XF86DisplayToggle ] }; + key { [ XF86SpellCheck ] }; + key { [ XF86LogOff ] }; + key { [ dollar ] }; + key { [ EuroSign ] }; + key { [ XF86FrameBack ] }; + key { [ XF86FrameForward ] }; + key { [ XF86ContextMenu ] }; + key { [ XF86MediaRepeat ] }; + key { [ XF8610ChannelsUp ] }; + key { [ XF8610ChannelsDown ] }; + key { [ XF86Images ] }; + key { [ XF86NotificationCenter ] }; + key { [ XF86PickupPhone ] }; + key { [ XF86HangupPhone ] }; + key { [ XF86LinkPhone ] }; + key { [ XF86Fn ] }; + key { [ XF86Fn_Esc ] }; + key { [ XF86Fn_F1 ] }; + key { [ XF86Fn_F2 ] }; + key { [ XF86Fn_F3 ] }; + key { [ XF86Fn_F4 ] }; + key { [ XF86Fn_F5 ] }; + key { [ XF86Fn_F6 ] }; + key { [ XF86Fn_F7 ] }; + key { [ XF86Fn_F8 ] }; + key { [ XF86Fn_F9 ] }; + key { [ XF86Fn_F10 ] }; + key { [ XF86Fn_F11 ] }; + key { [ XF86Fn_F12 ] }; + key { [ XF86Fn_1 ] }; + key { [ XF86Fn_2 ] }; + key { [ XF86Fn_D ] }; + key { [ XF86Fn_E ] }; + key { [ XF86Fn_F ] }; + key { [ XF86Fn_S ] }; + key { [ XF86Fn_B ] }; + key { [ XF86FnRightShift ] }; + key { [ braille_dot_1 ] }; + key { [ braille_dot_2 ] }; + key { [ braille_dot_3 ] }; + key { [ braille_dot_4 ] }; + key { [ braille_dot_5 ] }; + key { [ braille_dot_6 ] }; + key { [ braille_dot_7 ] }; + key { [ braille_dot_8 ] }; + key { [ braille_dot_9 ] }; + key { [ braille_dot_1 ] }; + key { [ XF86Numeric0 ] }; + key { [ XF86Numeric1 ] }; + key { [ XF86Numeric2 ] }; + key { [ XF86Numeric3 ] }; + key { [ XF86Numeric4 ] }; + key { [ XF86Numeric5 ] }; + key { [ XF86Numeric6 ] }; + key { [ XF86Numeric7 ] }; + key { [ XF86Numeric8 ] }; + key { [ XF86Numeric9 ] }; + key { [ XF86NumericStar ] }; + key { [ XF86NumericPound ] }; + key { [ XF86NumericA ] }; + key { [ XF86NumericB ] }; + key { [ XF86NumericC ] }; + key { [ XF86NumericD ] }; + key { [ XF86CameraFocus ] }; + key { [ XF86WPSButton ] }; + key { [ XF86TouchpadToggle ] }; + key { [ XF86TouchpadOn ] }; + key { [ XF86TouchpadOff ] }; + key { [ XF86CameraZoomIn ] }; + key { [ XF86CameraZoomOut ] }; + key { [ XF86CameraUp ] }; + key { [ XF86CameraDown ] }; + key { [ XF86CameraLeft ] }; + key { [ XF86CameraRight ] }; + key { [ XF86AttendantOn ] }; + key { [ XF86AttendantOff ] }; + key { [ XF86AttendantToggle ] }; + key { [ XF86LightsToggle ] }; + key { [ XF86ALSToggle ] }; + key { [ XF86RotationLockToggle ] }; + key { [ XF86RefreshRateToggle ] }; + key { [ XF86Buttonconfig ] }; + key { [ XF86Taskmanager ] }; + key { [ XF86Journal ] }; + key { [ XF86ControlPanel ] }; + key { [ XF86AppSelect ] }; + key { [ XF86Screensaver ] }; + key { [ XF86VoiceCommand ] }; + key { [ XF86Assistant ] }; + key { [ ISO_Next_Group ] }; + key { [ XF86EmojiPicker ] }; + key { [ XF86Dictate ] }; + key { [ XF86CameraAccessEnable ] }; + key { [ XF86CameraAccessDisable ] }; + key { [ XF86CameraAccessToggle ] }; + key { [ XF86Accessibility ] }; + key { [ XF86DoNotDisturb ] }; + key { [ XF86BrightnessMin ] }; + key { [ XF86BrightnessMax ] }; + key { [ XF86KbdInputAssistPrev ] }; + key { [ XF86KbdInputAssistNext ] }; + key { [ XF86KbdInputAssistPrevgroup ] }; + key { [ XF86KbdInputAssistNextgroup ] }; + key { [ XF86KbdInputAssistAccept ] }; + key { [ XF86KbdInputAssistCancel ] }; + key { [ XF86RightUp ] }; + key { [ XF86RightDown ] }; + key { [ XF86LeftUp ] }; + key { [ XF86LeftDown ] }; + key { [ XF86RootMenu ] }; + key { [ XF86MediaTopMenu ] }; + key { [ XF86Numeric11 ] }; + key { [ XF86Numeric12 ] }; + key { [ XF86AudioDesc ] }; + key { [ XF863DMode ] }; + key { [ XF86NextFavorite ] }; + key { [ XF86StopRecord ] }; + key { [ XF86PauseRecord ] }; + key { [ XF86VOD ] }; + key { [ XF86Unmute ] }; + key { [ XF86FastReverse ] }; + key { [ XF86SlowReverse ] }; + key { [ XF86Data ] }; + key { [ XF86OnScreenKeyboard ] }; + key { [ XF86PrivacyScreenToggle ] }; + key { [ XF86SelectiveScreenshot ] }; + key { [ XF86NextElement ] }; + key { [ XF86PreviousElement ] }; + key { [ XF86AutopilotEngageToggle ] }; + key { [ XF86MarkWaypoint ] }; + key { [ XF86Sos ] }; + key { [ XF86NavChart ] }; + key { [ XF86FishingChart ] }; + key { [ XF86SingleRangeRadar ] }; + key { [ XF86DualRangeRadar ] }; + key { [ XF86RadarOverlay ] }; + key { [ XF86TraditionalSonar ] }; + key { [ XF86ClearvuSonar ] }; + key { [ XF86SidevuSonar ] }; + key { [ XF86NavInfo ] }; + key { [ XF86BrightnessAdjust ] }; + key { [ XF86Macro1 ] }; + key { [ XF86Macro2 ] }; + key { [ XF86Macro3 ] }; + key { [ XF86Macro4 ] }; + key { [ XF86Macro5 ] }; + key { [ XF86Macro6 ] }; + key { [ XF86Macro7 ] }; + key { [ XF86Macro8 ] }; + key { [ XF86Macro9 ] }; + key { [ XF86Macro10 ] }; + key { [ XF86Macro11 ] }; + key { [ XF86Macro12 ] }; + key { [ XF86Macro13 ] }; + key { [ XF86Macro14 ] }; + key { [ XF86Macro15 ] }; + key { [ XF86Macro16 ] }; + key { [ XF86Macro17 ] }; + key { [ XF86Macro18 ] }; + key { [ XF86Macro19 ] }; + key { [ XF86Macro20 ] }; + key { [ XF86Macro21 ] }; + key { [ XF86Macro22 ] }; + key { [ XF86Macro23 ] }; + key { [ XF86Macro24 ] }; + key { [ XF86Macro25 ] }; + key { [ XF86Macro26 ] }; + key { [ XF86Macro27 ] }; + key { [ XF86Macro28 ] }; + key { [ XF86Macro29 ] }; + key { [ XF86Macro30 ] }; + key { [ XF86MacroRecordStart ] }; + key { [ XF86MacroRecordStop ] }; + key { [ XF86MacroPresetCycle ] }; + key { [ XF86MacroPreset1 ] }; + key { [ XF86MacroPreset2 ] }; + key { [ XF86MacroPreset3 ] }; + key { [ XF86KbdLcdMenu1 ] }; + key { [ XF86KbdLcdMenu2 ] }; + key { [ XF86KbdLcdMenu3 ] }; + key { [ XF86KbdLcdMenu4 ] }; + key { [ XF86KbdLcdMenu5 ] }; + key { [ XF86PerformanceMode ] }; + modifier_map Shift { , }; + modifier_map Lock { }; + modifier_map Control { , }; + modifier_map Mod1 { , , , }; + modifier_map Mod2 { }; + modifier_map Mod3 { }; + modifier_map Mod4 { , , }; + modifier_map Mod5 { }; +}; + +}; diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000..1653647cfb --- /dev/null +++ b/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,11 @@ +# The app's native side: the Wayland compositor the session presents into, the adrenotools loader +# it opens Turnip with, and one small library for the fake-input ring's memory fence. +cmake_minimum_required(VERSION 3.22.1) +project(steamdeck C CXX) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Wno-unused-function -Wimplicit-function-declaration") + +add_subdirectory(adrenotools) +add_subdirectory(waylandcomp) +add_library(sdnative SHARED sdnative/sdnative.c) +target_link_libraries(sdnative log) diff --git a/app/src/main/cpp/adrenotools/.gitmodules b/app/src/main/cpp/adrenotools/.gitmodules new file mode 100644 index 0000000000..9c18d908da --- /dev/null +++ b/app/src/main/cpp/adrenotools/.gitmodules @@ -0,0 +1,4 @@ +[submodule "lib/linkernsbypass"] + path = lib/linkernsbypass + url = https://github.com/Pipetto-crypto/liblinkernsbypass.git + branch = master diff --git a/app/src/main/cpp/adrenotools/CMakeLists.txt b/app/src/main/cpp/adrenotools/CMakeLists.txt new file mode 100644 index 0000000000..16c6092302 --- /dev/null +++ b/app/src/main/cpp/adrenotools/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.14) + +if(NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a) + message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_ANDROID_ARCH_ABI}. Please make an issue on the repo!") +endif() + +project(adrenotools LANGUAGES CXX C) + +set(GEN_INSTALL_TARGET OFF CACHE BOOL "") + +add_subdirectory(lib/linkernsbypass) + +set(LIB_SOURCES src/bcenabler.cpp + src/driver.cpp + include/adrenotools/bcenabler.h + include/adrenotools/driver.h + include/adrenotools/priv.h) + +add_library(adrenotools ${LIB_SOURCES}) + +target_include_directories(adrenotools PUBLIC include) +target_include_directories(adrenotools PRIVATE .) +target_compile_options(adrenotools PRIVATE -Wall -Wextra) +target_link_libraries(adrenotools android linkernsbypass) + +add_subdirectory(src/hook) +if (${BUILD_SHARED_LIBS}) + target_link_options(adrenotools PRIVATE "-Wl,-s,--exclude-libs,liblinkernsbypass.a") +endif() +if (${GEN_INSTALL_TARGET}) + configure_file(adrenotools.pc.in adrenotools.pc @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/adrenotools.pc DESTINATION lib/pkgconfig) + install(TARGETS adrenotools main_hook file_redirect_hook gsl_alloc_hook hook_impl) + install(DIRECTORY include/ + DESTINATION include + FILES_MATCHING PATTERN "*.h*") +endif() diff --git a/app/src/main/cpp/adrenotools/LICENSE b/app/src/main/cpp/adrenotools/LICENSE new file mode 100644 index 0000000000..a8f664a745 --- /dev/null +++ b/app/src/main/cpp/adrenotools/LICENSE @@ -0,0 +1,24 @@ +BSD 2-Clause License + +Copyright (c) 2021, Billy Laws + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/app/src/main/cpp/adrenotools/README.md b/app/src/main/cpp/adrenotools/README.md new file mode 100644 index 0000000000..b265f4c8b1 --- /dev/null +++ b/app/src/main/cpp/adrenotools/README.md @@ -0,0 +1,30 @@ +### Adreno Tools +A library for applying rootless Adreno GPU driver modifications/replacements. Currently supports loading custom GPU drivers such as [turnip](https://docs.mesa3d.org/android.html#building-using-the-android-ndk), enabling BCn textures and redirecting file operations to allow accessing shader dumps and modification of the [driver config file](https://gist.github.com/bylaws/04130932e2634d1c6a2a9729e3940d60) without root. + +#### Documentation +API is documented in the `include/adrenotools` headers. + +#### Support +Android 9+ +Arm64 + +Please create an issue if support for anything else is desired. + +### FAQ + +#### Is there an example project? + +There is a simple bare-bones project [AdrenoToolsTest](https://github.com/darksylinc/AdrenoToolsTest) demonstrating how to get libadrenotools working. + +#### How do I use this to update the drivers on my phone? Where's the apk? + +You don't. This library is **not** for installing into Android and is **not** for end users. +This library is aimed at other developers. + +Each individual app must explicitly make use of libadrenotools in order to load custom drivers into an app / game. + +#### How do I use this library to make \ use newer drivers? + +See previous question. It's up to the game developer to add support & use this library. + +You could contact them to so they add support for it; but that's out of our power. \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/adrenotools.pc.in b/app/src/main/cpp/adrenotools/adrenotools.pc.in new file mode 100644 index 0000000000..1102f434c8 --- /dev/null +++ b/app/src/main/cpp/adrenotools/adrenotools.pc.in @@ -0,0 +1,13 @@ +prefix="@CMAKE_INSTALL_PREFIX@" +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: adrenotools +Description: +URL: +Version: 1.0.0 +Libs: -L${libdir} -ladrenotools +Libs.private: +Requires.private: +Cflags: -I${includedir} diff --git a/app/src/main/cpp/adrenotools/build_asm.sh b/app/src/main/cpp/adrenotools/build_asm.sh new file mode 100755 index 0000000000..b53d25c1ba --- /dev/null +++ b/app/src/main/cpp/adrenotools/build_asm.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +aarch64-linux-gnu-gcc -c src/bcenabler_patch.s -o /tmp/patch.o +aarch64-linux-gnu-objcopy -O binary -j .text /tmp/patch.o /tmp/patch.bin + +# Must be smaller than a single page +bin2c -o gen/bcenabler_patch.h -n PatchRawData /tmp/patch.bin + +rm /tmp/patch.o +rm /tmp/patch.bin diff --git a/app/src/main/cpp/adrenotools/gen/bcenabler_patch.h b/app/src/main/cpp/adrenotools/gen/bcenabler_patch.h new file mode 100644 index 0000000000..3909a25ca1 --- /dev/null +++ b/app/src/main/cpp/adrenotools/gen/bcenabler_patch.h @@ -0,0 +1,23 @@ +/* Generated by bin2c, do not edit manually */ + +/* Contents of file /tmp/patch.bin */ +const long int PatchRawData_size = 264; +const unsigned char PatchRawData[264] = { + 0x1F, 0x0C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x08, 0x80, 0x52, 0x3E, 0x00, 0x00, 0x14, + 0x1F, 0x14, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x08, 0x80, 0x52, 0x3A, 0x00, 0x00, 0x14, + 0x1F, 0x10, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x09, 0x80, 0x52, 0x36, 0x00, 0x00, 0x14, + 0x1F, 0x18, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x09, 0x80, 0x52, 0x32, 0x00, 0x00, 0x14, + 0x1F, 0x1C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x40, 0x09, 0x80, 0x52, 0x2E, 0x00, 0x00, 0x14, + 0x1F, 0x20, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x09, 0x80, 0x52, 0x2A, 0x00, 0x00, 0x14, + 0x1F, 0x24, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xA0, 0x09, 0x80, 0x52, 0x26, 0x00, 0x00, 0x14, + 0x1F, 0x28, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xC0, 0x09, 0x80, 0x52, 0x22, 0x00, 0x00, 0x14, + 0x1F, 0x2C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x0A, 0x80, 0x52, 0x1E, 0x00, 0x00, 0x14, + 0x1F, 0x30, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x20, 0x0A, 0x80, 0x52, 0x1A, 0x00, 0x00, 0x14, + 0x1F, 0x34, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x0A, 0x80, 0x52, 0x16, 0x00, 0x00, 0x14, + 0x1F, 0x38, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x80, 0x0A, 0x80, 0x52, 0x12, 0x00, 0x00, 0x14, + 0x1F, 0x3C, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0xE0, 0x0B, 0x80, 0x52, 0x0E, 0x00, 0x00, 0x14, + 0x1F, 0x40, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x00, 0x0C, 0x80, 0x52, 0x0A, 0x00, 0x00, 0x14, + 0x1F, 0x44, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x40, 0x0C, 0x80, 0x52, 0x06, 0x00, 0x00, 0x14, + 0x1F, 0x48, 0x02, 0x71, 0x61, 0x00, 0x00, 0x54, 0x60, 0x0C, 0x80, 0x52, 0x02, 0x00, 0x00, 0x14, + 0x00, 0x00, 0x80, 0x52, 0xFF, 0xFF, 0xFF, 0xFF +}; diff --git a/app/src/main/cpp/adrenotools/include/adrenotools/bcenabler.h b/app/src/main/cpp/adrenotools/include/adrenotools/bcenabler.h new file mode 100644 index 0000000000..3d3a76e7d5 --- /dev/null +++ b/app/src/main/cpp/adrenotools/include/adrenotools/bcenabler.h @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#ifdef __cplusplus +extern "C" { +#else +#include +#endif + +#include + +/** + * @brief Describes the level of BCeNabler support for a driver + */ +enum adrenotools_bcn_type { + ADRENOTOOLS_BCN_INCOMPATIBLE, //!< Driver isn't supported by BCeNabler + ADRENOTOOLS_BCN_BLOB, //!< Driver already supports BCn textures so BCeNabler isn't necessary + ADRENOTOOLS_BCN_PATCH //!< Driver can be patched with BCeNabler to support BCn textures +}; + +/** + * @brief Checks the status of BCn support in the supplied driver + * @param major The major part of VkPhysicalDeviceProperties::driverVersion + * @param minor The minor part of VkPhysicalDeviceProperties::driverVersion + * @param vendorId VkPhysicalDeviceProperties::vendorId + */ +enum adrenotools_bcn_type adrenotools_get_bcn_type(uint32_t major, uint32_t minor, uint32_t vendorId); + +/** + * @brief Patches the Adreno graphics driver to enable support for BCn compressed formats + * @note adrenotools_get_bcn_type MUST be checked to equal ADRENOTOOLS_BCN_PATCH before calling this + * @param vkGetPhysicalDeviceFormatPropertiesFn A pointer to vkGetPhysicalDeviceFormatProperties obtained through vkGetInstanceProcAddr. This is used to find the correct function to patch + * @return If the patching succeeded, if false the driver will be in an undefined state + */ +bool adrenotools_patch_bcn(void *vkGetPhysicalDeviceFormatPropertiesFn); + +#ifdef __cplusplus +} +#endif diff --git a/app/src/main/cpp/adrenotools/include/adrenotools/driver.h b/app/src/main/cpp/adrenotools/include/adrenotools/driver.h new file mode 100644 index 0000000000..f81e8fe34d --- /dev/null +++ b/app/src/main/cpp/adrenotools/include/adrenotools/driver.h @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "priv.h" + +/** + * @brief Opens a new libvulkan.so instance according to `flags` + * @remark IMPORTANT: The app MUST be packaged w/ useLegacyPackaging = true. The reason for this is + * that we install the hook in hookLibDir; but this folder won't be set correctly when useLegacyPackaging == false + * because Android expects to read the *.so directly from the apk (instead of decompressing them into nativeLibraryDir). + * @param dlopenMode The dlopen mode to use when opening libvulkan + * @param featureFlags Which adrenotools driver features to enable + * @param tmpLibDir A writable directory to hold patched libraries, only used on api < 29 due to the lack of memfd support. If nullptr is passed and the API version is < 29 memfd usage will be attempted and if unsupported nullptr will be returned + * @param hookLibDir The directory holding the built hooks. + * IMPORTANT: This path MUST point to whatever `getApplicationInfo().nativeLibraryDir` (Kotlin code) returns. + * Failing to do so will result in this function returning a valid ptr but then the hook will fail and either the original driver is loaded as fallback, or vkEnumeratePhysicalDevices returns 0 devices. + * @param customDriverDir The directory to load a custom GPU driver named according to `customDriverName` from. Only used if ADRENOTOOLS_DRIVER_CUSTOM is set in `featureFlags`. + * IMPORTANT: This path MUST NOT be on sdcard/storage. i.e. use ANativeActivity::internalDataPath and often looks like "/data/user/0/com.example.app/files/". + * Otherwise you will get permission denied because dlopen() can't be done on *.so libraries that any random user or application can manipulate (which would be a security risk). + * @param customDriverName The soname of the custom driver to load. Only used if ADRENOTOOLS_DRIVER_CUSTOM is set in `featureFlags` + * @param fileRedirectDir The directory which to redirect all file accesses performed by the driver to. Only used if ADRENOTOOLS_DRIVER_FILE_REDIRECT is set in `featureFlags` + * @param userMappingHandle A pointer to a void* which will be set to the mapping handle if ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT is set in `featureFlags` + */ +void *adrenotools_open_libvulkan(int dlopenMode, int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, const char *customDriverName, const char *fileRedirectDir, void **userMappingHandle); + +/** + * @brief Imports the given CPU mapped memory range into the GSL allocator. This should then be followed by a call to vkAllocateMemory with a matching size which will return a VkDeviceMemory view over the input region + * @param handle Mapping handle that was returned by adrenotools_open_libvulkan + * @param hostPtr The host pointer to import + * @param size The size of the region to import + * @return True on success + */ +bool adrenotools_import_user_mem(void *handle, void *hostPtr, uint64_t size); + +/** + * @brief Maps GPU memory and imports it into the GSL allocator. This should then be followed by a call to adrenotools_mem_cpu_map to map the memory on the CPU, then finally vkAllocateMemory with a matching size + * @param handle Mapping handle that was returned by adrenotools_open_libvulkan + * @param size Pointer to a variable containing the size of the region to import, will be updated to contain the required size of the region to allocate CPU side + * @return true on success + */ +bool adrenotools_mem_gpu_allocate(void *handle, uint64_t *size); + +/** + * @brief Maps the last mapping allocated using adrenotools_mem_gpu_allocate into the given host memory region, such that vkAllocateMemory can then be called + * @param handle Mapping handle that was returned by adrenotools_open_libvulkan + * @param hostPtr A pointer to where the mapping should be mapped + * @param size The size of the mapping. MUST be equal to the size returned by adrenotools_mem_gpu_allocate + */ +bool adrenotools_mem_cpu_map(void *handle, void *hostPtr, uint64_t size); + +/** + * @note This function should be called after adrenotools_open_libvulkan and Vulkan driver init to check if the mapping import hook loaded successfully + * @return True if the mapping was successfully imported (or initialization succeeded) + */ +bool adrenotools_validate_gpu_mapping(void *handle); + +/** + * @brief Provides a way to force the GPU to run at the maximum possible clocks (thermal constraints will still be applied) + */ +void adrenotools_set_turbo(bool turbo); + +#ifdef __cplusplus +} +#endif diff --git a/app/src/main/cpp/adrenotools/include/adrenotools/priv.h b/app/src/main/cpp/adrenotools/include/adrenotools/priv.h new file mode 100644 index 0000000000..742d24f247 --- /dev/null +++ b/app/src/main/cpp/adrenotools/include/adrenotools/priv.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#include + +/** + * @brief Bitfield enum of additional driver features that can be used with adrenotools_open_libvulkan + */ +enum { + ADRENOTOOLS_DRIVER_CUSTOM = 1 << 0, + ADRENOTOOLS_DRIVER_FILE_REDIRECT = 1 << 1, + ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT = 1 << 2, +}; + +#define ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC 0xDEADBEEF + +/** + * @brief A replacement GPU memory mapping for use with ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT + */ +struct adrenotools_gpu_mapping { + void *host_ptr; + uint64_t gpu_addr; //!< The GPU address of the mapping to import, if mapping import/init succeeds this will be set to ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC + uint64_t size; + uint64_t flags; +}; \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/CMakeLists.txt b/app/src/main/cpp/adrenotools/lib/linkernsbypass/CMakeLists.txt new file mode 100644 index 0000000000..c2e92b0422 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.14) + +if(NOT ${CMAKE_ANDROID_ARCH_ABI} STREQUAL arm64-v8a) + message(FATAL_ERROR "Unsupported target architecture: ${CMAKE_ANDROID_ARCH_ABI}. Please make an issue on the repo!") +endif() + +project(linkernsbypass LANGUAGES CXX) + +set(SOURCES android_linker_ns.cpp + android_linker_ns.h + elf_soname_patcher.cpp + elf_soname_patcher.h) + +add_library(linkernsbypass STATIC ${SOURCES}) + + +target_compile_options(linkernsbypass PRIVATE -Wall -Wextra) +target_link_libraries(linkernsbypass android dl) +target_include_directories(linkernsbypass PUBLIC .) diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/LICENSE b/app/src/main/cpp/adrenotools/lib/linkernsbypass/LICENSE new file mode 100644 index 0000000000..a8f664a745 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/LICENSE @@ -0,0 +1,24 @@ +BSD 2-Clause License + +Copyright (c) 2021, Billy Laws + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/README.md b/app/src/main/cpp/adrenotools/lib/linkernsbypass/README.md new file mode 100644 index 0000000000..264f23a39a --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/README.md @@ -0,0 +1,9 @@ +### Android Linker Namespace Bypass Library +Provides access to the hidden linker namespace functionality in Android 9+ and exposes an interface for hooking libraries similar to a runtime equivalent of `LD_PRELOAD`. +See the `android_linker_ns.h` header for an API reference. + +#### Support +Android 9+ +Arm64 + +Android 8 and arm32 could be supported with some trivial changes, feel free to open an issue if you have a use for this library on either of them. diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.cpp b/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.cpp new file mode 100644 index 0000000000..3bd58992c2 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.cpp @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "elf_soname_patcher.h" +#include "android_linker_ns.h" + +using loader_android_create_namespace_t = android_namespace_t *(*)(const char *, const char *, const char *, uint64_t, const char *, android_namespace_t *, const void *); +static loader_android_create_namespace_t loader_android_create_namespace; + +static bool lib_loaded; + + +/* Public API */ +bool linkernsbypass_load_status() { + return lib_loaded; +} + +struct android_namespace_t *android_create_namespace(const char *name, + const char *ld_library_path, + const char *default_library_path, + uint64_t type, + const char *permitted_when_isolated_path, + android_namespace_t *parent_namespace) { + auto caller{__builtin_return_address(0)}; + return loader_android_create_namespace(name, ld_library_path, default_library_path, type, + permitted_when_isolated_path, parent_namespace, caller); +} + +struct android_namespace_t *android_create_namespace_escape(const char *name, + const char *ld_library_path, + const char *default_library_path, + uint64_t type, + const char *permitted_when_isolated_path, + android_namespace_t *parent_namespace) { + auto caller{reinterpret_cast(&dlopen)}; + return loader_android_create_namespace(name, ld_library_path, default_library_path, type, + permitted_when_isolated_path, parent_namespace, caller); +} + +android_get_exported_namespace_t android_get_exported_namespace; + +android_link_namespaces_all_libs_t android_link_namespaces_all_libs; + +android_link_namespaces_t android_link_namespaces; + +bool linkernsbypass_link_namespace_to_default_all_libs(android_namespace_t *to) { + // Creating a shared namespace with the default parent will give a copy of the default namespace that we can actually access + // This is needed since there is no way to access a direct handle to the default namespace as it's not exported + static auto defaultNs{android_create_namespace_escape("default_copy", nullptr, nullptr, ANDROID_NAMESPACE_TYPE_SHARED, nullptr, nullptr)}; + return android_link_namespaces_all_libs(to, defaultNs); +} + +void *linkernsbypass_namespace_dlopen(const char *filename, int flags, android_namespace_t *ns) { + android_dlextinfo extInfo{ + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = ns + }; + + return android_dlopen_ext(filename, flags, &extInfo); +} + +#ifndef __NR_memfd_create + #if defined(__aarch64__) + #define __NR_memfd_create 279 + #else + #error Unsupported target architecture! + #endif +#endif + +void *linkernsbypass_namespace_dlopen_unique(const char *libPath, const char *libTargetDir, int flags, android_namespace_t *ns) { + static std::array PathBuf{}; + + // Used as a unique ID for overwriting soname and creating target lib files + static uint16_t TargetId{}; + + int libTargetFd{[&] () { + if (libTargetDir) { + snprintf(PathBuf.data(), PathBuf.size(), "%s/%d_patched.so", libTargetDir, TargetId); + return open(PathBuf.data(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + } else { + // If memfd isn't supported errno will contain ENOSYS after calling + errno = 0; + int fd{static_cast(syscall(__NR_memfd_create, libPath, 0))}; + if (errno == ENOSYS || fd < 0) + return -1; + else + return fd; + } + }()}; + if (libTargetFd == -1) + return nullptr; + + // Partially overwrite soname with 3 digits (replacing lib...) with to make sure a cached so isn't loaded + std::array sonameOverwrite{}; + snprintf(sonameOverwrite.data(), sonameOverwrite.size(), "%03u", TargetId++); + + if (!elf_soname_patch(libPath, libTargetFd, sonameOverwrite.data())) + return nullptr; + + // Load our patched library into the hook namespace + android_dlextinfo hookExtInfo{ + .flags = ANDROID_DLEXT_USE_NAMESPACE | ANDROID_DLEXT_USE_LIBRARY_FD, + .library_fd = libTargetFd, + .library_namespace = ns + }; + + // Make a path that looks about right + snprintf(PathBuf.data(), PathBuf.size(), "/proc/self/fd/%d", libTargetFd); + + return android_dlopen_ext(PathBuf.data(), flags, &hookExtInfo); +} + +static void *align_ptr(void *ptr) { + return reinterpret_cast(reinterpret_cast(ptr) & ~(getpagesize() - 1)); +} + +/* Private */ +__attribute__((constructor)) static void resolve_linker_symbols() { + using loader_dlopen_t = void *(*)(const char *, int, const void *); + + if (android_get_device_api_level() < 28) + return; + + // ARM64 specific function walking to locate the internal dlopen handler + auto loader_dlopen{[]() { + union BranchLinked { + uint32_t raw; + + struct { + int32_t offset : 26; //!< 26-bit branch offset + uint8_t sig : 6; //!< 6-bit signature + }; + + bool Verify() { + return sig == 0x25; + } + }; + static_assert(sizeof(BranchLinked) == 4, "BranchLinked is wrong size"); + + // Some devices ship with --X mapping for exexecutables so work around that + mprotect(align_ptr(reinterpret_cast(&dlopen)), getpagesize(), PROT_WRITE | PROT_READ | PROT_EXEC); + + // dlopen is just a wrapper for __loader_dlopen that passes the return address as the third arg hence we can just walk it to find __loader_dlopen + auto blInstr{reinterpret_cast(&dlopen)}; + while (!blInstr->Verify()) + blInstr++; + + return reinterpret_cast(blInstr + blInstr->offset); + }()}; + + // Protect the loader_dlopen function to remove the BTI attribute (since this is an internal function that isn't intended to be jumped indirectly to) + mprotect(align_ptr(reinterpret_cast(&loader_dlopen)), getpagesize(), PROT_WRITE | PROT_READ | PROT_EXEC); + + // Passing dlopen as a caller address tricks the linker into using the internal unrestricted namespace letting us access libraries that are normally forbidden in the classloader namespace imposed on apps + auto ldHandle{loader_dlopen("ld-android.so", RTLD_LAZY, reinterpret_cast(&dlopen))}; + if (!ldHandle) + return; + + android_link_namespaces_all_libs = reinterpret_cast(dlsym(ldHandle, "__loader_android_link_namespaces_all_libs")); + if (!android_link_namespaces_all_libs) + return; + + android_link_namespaces = reinterpret_cast(dlsym(ldHandle, "__loader_android_link_namespaces")); + if (!android_link_namespaces) + return; + + auto libdlAndroidHandle{loader_dlopen("libdl_android.so", RTLD_LAZY, reinterpret_cast(&dlopen))}; + if (!libdlAndroidHandle) + return; + + loader_android_create_namespace = reinterpret_cast(dlsym(libdlAndroidHandle, "__loader_android_create_namespace")); + if (!loader_android_create_namespace) + return; + + android_get_exported_namespace = reinterpret_cast(dlsym(libdlAndroidHandle, "__loader_android_get_exported_namespace")); + if (!android_get_exported_namespace) + return; + + // Lib is now safe to use + lib_loaded = true; +} diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.h b/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.h new file mode 100644 index 0000000000..77ec4005a5 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/android_linker_ns.h @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +// https://cs.android.com/android/platform/superproject/+/0a492a4685377d41fef2b12e9af4ebfa6feef9c2:art/libnativeloader/include/nativeloader/dlext_namespaces.h;l=25;bpv=1;bpt=1 +enum { + ANDROID_NAMESPACE_TYPE_REGULAR = 0, + ANDROID_NAMESPACE_TYPE_ISOLATED = 1, + ANDROID_NAMESPACE_TYPE_SHARED = 2, + ANDROID_NAMESPACE_TYPE_EXEMPT_LIST_ENABLED = 0x08000000, + ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS = 0x10000000, + ANDROID_NAMESPACE_TYPE_SHARED_ISOLATED = ANDROID_NAMESPACE_TYPE_SHARED | ANDROID_NAMESPACE_TYPE_ISOLATED, +}; + +/** + * @brief Checks if linkernsbypass loaded successfully and is safe to use + * @note IMPORTANT: This should be called before any calls to the rest of the library are made + * @return true if loading succeeded + */ +bool linkernsbypass_load_status(); + +// https://cs.android.com/android/platform/superproject/+/0a492a4685377d41fef2b12e9af4ebfa6feef9c2:art/libnativeloader/include/nativeloader/dlext_namespaces.h;l=86;bpv=1;bpt=1 +struct android_namespace_t *android_create_namespace(const char *name, + const char *ld_library_path, + const char *default_library_path, + uint64_t type, + const char *permitted_when_isolated_path, + struct android_namespace_t *parent_namespace); + +struct android_namespace_t *android_create_namespace_escape(const char *name, + const char *ld_library_path, + const char *default_library_path, + uint64_t type, + const char *permitted_when_isolated_path, + struct android_namespace_t *parent_namespace); + +// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=3554 +typedef struct android_namespace_t *(*android_get_exported_namespace_t)(const char *); +extern android_get_exported_namespace_t android_get_exported_namespace; + +// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=2499 +typedef bool (*android_link_namespaces_all_libs_t)(struct android_namespace_t *, struct android_namespace_t *); +extern android_link_namespaces_all_libs_t android_link_namespaces_all_libs; + +// https://cs.android.com/android/platform/superproject/+/dcb01ef31026b3b8aeb72dada3370af63fe66bbd:bionic/linker/linker.cpp;l=2473 +typedef bool (*android_link_namespaces_t)(struct android_namespace_t *, struct android_namespace_t *, const char *); +extern android_link_namespaces_t android_link_namespaces; + +/** + * @brief Like android_link_namespaces_all_libs but links from the default namespace + */ +bool linkernsbypass_link_namespace_to_default_all_libs(struct android_namespace_t *to); + +/** + * @brief Loads a library into a namespace + * @note IMPORTANT: If `filename` is compiled with the '-z global' linker flag and RTLD_GLOBAL is supplied in `flags` the library will be added to the namespace's LD_PRELOAD list + * @param filename The name of the library to load + * @param flags The rtld flags for `filename` + * @param ns The namespace to dlopen into + */ +void *linkernsbypass_namespace_dlopen(const char *filename, int flags, struct android_namespace_t *ns); + +/** + * @brief Force loads a unique instance of a library into a namespace + * @param libPath The path to the library to load with hooks applied + * @param libTargetDir A temporary directory to hold the soname patched library at `libPath`, will attempt to use memfd if nullptr + * @param flags The rtld flags for `libName` + * @param ns The namespace to dlopen into + */ +void *linkernsbypass_namespace_dlopen_unique(const char *libPath, const char *libTargetDir, int flags, struct android_namespace_t *ns); + +#ifdef __cplusplus +} +#endif diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.cpp b/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.cpp new file mode 100644 index 0000000000..db619ab534 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.cpp @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "elf_soname_patcher.h" + +bool elf_soname_patch(const char *libPath, int targetFd, const char *sonamePatch) { + struct stat libStat{}; + if (stat(libPath, &libStat)) + return false; + + if (ftruncate(targetFd, libStat.st_size) == -1) + return false; + + // Map the memory so we can read our elf into it + auto mappedLib{reinterpret_cast(mmap(nullptr, libStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, targetFd, 0))}; + if (!mappedLib) + return false; + + int libFd{open(libPath, O_RDONLY)}; + if (libFd == false) + return false; + + // Read lib elf into target file + if (read(libFd, mappedLib, libStat.st_size) != libStat.st_size) + return false; + + // No longer needed + close(libFd); + + auto eHdr{reinterpret_cast(mappedLib)}; + auto sHdrEntries{reinterpret_cast(mappedLib + eHdr->e_shoff)}; + + // Iterate over section headers to find the .dynamic section + for (ElfW(Half) i{}; i < eHdr->e_shnum; i++) { + auto &sHdr{sHdrEntries[i]}; + if (sHdr.sh_type == SHT_DYNAMIC) { + auto strTab{reinterpret_cast(mappedLib + sHdrEntries[sHdr.sh_link].sh_offset)}; + auto dynHdrEntries{reinterpret_cast(mappedLib + sHdr.sh_offset)}; + + // Iterate over .dynamic entries to find DT_SONAME + for (ElfW(Xword) k{}; k < (sHdr.sh_size / sHdr.sh_entsize); k++) { + auto &dynHdrEntry{dynHdrEntries[k]}; + if (dynHdrEntry.d_tag == DT_SONAME) { + char *soname{strTab + dynHdrEntry.d_un.d_val}; + + // Partially replace the old soname with the soname patch + size_t charIdx{}; + for (; soname[charIdx] != 0 && sonamePatch[charIdx] != 0; charIdx++) + soname[charIdx] = sonamePatch[charIdx]; + + return true; + } + } + } + } + + return false; +} diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.h b/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.h new file mode 100644 index 0000000000..0b2c186ffc --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/elf_soname_patcher.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Overwrites a portion of the soname in an elf by loading it into shared memory and modifying .dynstr + * @note IMPORTANT: The supplied soname patch will overwrite the first strlen(sonamePatch) chars of the soname + * @param elfPath Full path to the elf to patch + * @param targetFd FD to use for storing the patched library + * @return True on success + */ +bool elf_soname_patch(const char *elfPath, int targetFd, const char *newSoname); + +#ifdef __cplusplus +} +#endif diff --git a/app/src/main/cpp/adrenotools/lib/linkernsbypass/meson.build b/app/src/main/cpp/adrenotools/lib/linkernsbypass/meson.build new file mode 100644 index 0000000000..e666aff8a7 --- /dev/null +++ b/app/src/main/cpp/adrenotools/lib/linkernsbypass/meson.build @@ -0,0 +1,18 @@ +linkernsbypass_files = files(['android_linker_ns.cpp', 'android_linker_ns.h', 'elf_soname_patcher.cpp', 'elf_soname_patcher.h']) +linkernsbypass_inc = include_directories('.') + +libdl_dep = cpp.find_library('dl') + +linkernsbypass_lib = static_library ( + 'linkernsbypass', + linkernsbypass_files, + c_args: (['-Wall', '-Wextra']), + cpp_args: (['-Wall', '-Wextra']), + include_directories: ([linkernsbypass_inc, adrenotools_inc]), + dependencies: ([libandroid_dep, libdl_dep]) +) + +# linkernsbypass_include = static_library('linkernsbypass', sources) +# target_compile_options(['linkernsbypass', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_libraries(['linkernsbypass', 'android', 'dl']) +# target_include_directories(['linkernsbypass', 'PUBLIC', '.']) diff --git a/app/src/main/cpp/adrenotools/meson.build b/app/src/main/cpp/adrenotools/meson.build new file mode 100644 index 0000000000..bf519bb2ad --- /dev/null +++ b/app/src/main/cpp/adrenotools/meson.build @@ -0,0 +1,50 @@ +project( +'adrenotools', +['cpp', 'c'], +default_options : ['default_library=static'] +) + +cpp = meson.get_compiler('cpp') +c = meson.get_compiler('c') + +adrenotools_inc = include_directories('include') + +libandroid_dep = cpp.find_library('android') +liblog_dep = c.find_library('log') + +subdir('lib/linkernsbypass') + +linkernsbypass_dep = declare_dependency( + include_directories: linkernsbypass_inc, + link_with: linkernsbypass_lib, + link_args: '-Wl,-s,--exclude-libs,liblinkernsbypass.a' +) + +adrenotools_sources = ['src/bcenabler.cpp', 'src/driver.cpp', 'include/adrenotools/bcenabler.h', 'include/adrenotools/driver.h', 'include/adrenotools/priv.h'] + +adrenotools_lib = shared_library( + 'adrenotools', + adrenotools_sources, + c_args: (['-Wall', '-Wextra']), + cpp_args: (['-Wall', '-Wextra']), + include_directories: adrenotools_inc, + dependencies: ([linkernsbypass_dep, libandroid_dep, liblog_dep]), + install: true +) + +subdir('src/hook') + +# target_include_directories(['adrenotools', 'PUBLIC', 'include']) +# target_include_directories(['adrenotools', 'PRIVATE', '.']) +# target_compile_options(['adrenotools', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_libraries(['adrenotools', 'android', 'linkernsbypass']) +# hooks_deb = subproject('src/hook') +# if build_shared_libs + # target_link_options(['adrenotools', 'PRIVATE', '-Wl,-s,--exclude-libs,liblinkernsbypass.a']) +# endif +# if gen_install_target + # configure_file(['adrenotools.pc.in', 'adrenotools.pc', '@ONLY']) + # install(['FILES', cmake_binary_dir, '/adrenotools.pc', 'DESTINATION', 'lib/pkgconfig']) + # install(['TARGETS', 'adrenotools', 'main_hook', 'file_redirect_hook', 'gsl_alloc_hook', 'hook_impl']) + # install(['DIRECTORY', 'include/', 'DESTINATION', 'include', 'FILES_MATCHING', 'PATTERN', '*.h*']) +# endif diff --git a/app/src/main/cpp/adrenotools/src/bcenabler.cpp b/app/src/main/cpp/adrenotools/src/bcenabler.cpp new file mode 100644 index 0000000000..1deb41df40 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/bcenabler.cpp @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#include +#include +#include +#include +#include +#include +#include "gen/bcenabler_patch.h" + +enum adrenotools_bcn_type adrenotools_get_bcn_type(uint32_t major, uint32_t minor, uint32_t vendorId) { + if (vendorId != 0x5143 || major != 512) + return ADRENOTOOLS_BCN_INCOMPATIBLE; + + if (minor >= 514) + return ADRENOTOOLS_BCN_BLOB; + + return ADRENOTOOLS_BCN_PATCH; +} + +// Searches /proc/self/maps for the first free page after the given address +static void *find_free_page(uintptr_t address) { + std::ifstream procMaps("/proc/self/maps"); + + uintptr_t end{}; + + for (std::string line; std::getline(procMaps, line); ) { + std::size_t addressSeparator{line.find('-')}; + uintptr_t start{std::strtoull(line.substr(0, addressSeparator).c_str(), nullptr, 16)}; + + if (end > address && start != end) + return reinterpret_cast(end); + + end = std::strtoull(line.substr(addressSeparator + 1, line.find( ' ')).c_str(), nullptr, 16); + } + + return nullptr; +} + +static void *align_ptr(void *ptr) { + return reinterpret_cast(reinterpret_cast(ptr) & ~(getpagesize() - 1)); +} + +bool adrenotools_patch_bcn(void *vkGetPhysicalDeviceFormatPropertiesFn) { + union Branch { + struct { + int32_t offset : 26; //!< 26-bit branch offset + uint8_t sig : 6; //!< 6-bit signature (0x25 for linked, 0x5 for jump) + }; + + uint32_t raw{}; + }; + static_assert(sizeof(Branch) == 4, "Branch size is invalid"); + + // Find the nearest unmapped page where we can place patch code + void *patchPage{find_free_page(reinterpret_cast(vkGetPhysicalDeviceFormatPropertiesFn))}; + if (!patchPage) + return false; + + // Map patch region + void *ptr{mmap(patchPage, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0)}; + if (ptr != patchPage) + return false; + + // Allow reading from the blob's .text section since some devices enable ---X + // Protect two pages just in case we happen to land on a page boundary + if (mprotect(align_ptr(vkGetPhysicalDeviceFormatPropertiesFn), getpagesize() * 2, PROT_WRITE | PROT_READ | PROT_EXEC)) + return false; + + // First branch in this function is targeted at the function we want to patch + Branch *blInst{reinterpret_cast(vkGetPhysicalDeviceFormatPropertiesFn)}; + + constexpr uint8_t BranchLinkSignature{0x25}; + + // Search for first instruction with the BL signature + while (blInst->sig != BranchLinkSignature) + blInst++; + + // Internal QGL format conversion function that we need to patch + uint32_t *convFormatFn{reinterpret_cast(blInst) + blInst->offset}; + + // See mprotect call above + // This time we also set PROT_WRITE so we can write our patch to the page + if (mprotect(align_ptr(convFormatFn), getpagesize() * 2, PROT_WRITE | PROT_READ | PROT_EXEC)) + return false; + + // This would normally set the default result to 0 (error) in the format not found case + constexpr uint32_t ClearResultSignature{0x2a1f03e0}; + + // We replace it with a branch to our own extended if statement which adds in the extra things for BCn + uint32_t *clearResultPtr{convFormatFn}; + while (*clearResultPtr != ClearResultSignature) + clearResultPtr++; + + // Ensure we don't write out of bounds + if (PatchRawData_size > getpagesize()) + return false; + + // Copy the patch function to our mapped page + memcpy(patchPage, PatchRawData, PatchRawData_size); + + // Fixup the patch code so it correctly returns back to the driver after running + constexpr uint32_t PatchReturnFixupMagic{0xffffffff}; + constexpr uint8_t BranchSignature{0x5}; + + uint32_t *fixupTargetPtr{clearResultPtr + 1}; + auto *fixupPtr{reinterpret_cast(patchPage)}; + for (long unsigned int i{}; i < (PatchRawData_size / sizeof(uint32_t)); i++, fixupPtr++) { + if (*fixupPtr == PatchReturnFixupMagic) { + Branch branchToDriver{ + { + .offset = static_cast((reinterpret_cast(fixupTargetPtr) - reinterpret_cast(fixupPtr)) / sizeof(int32_t)), + .sig = BranchSignature, + } + }; + + *fixupPtr = branchToDriver.raw; + } + } + + Branch branchToPatch{ + { + .offset = static_cast((reinterpret_cast(patchPage) - reinterpret_cast(clearResultPtr)) / sizeof(int32_t)), + .sig = BranchSignature, + } + }; + + *clearResultPtr = branchToPatch.raw; + + asm volatile("ISB"); + + // Done! + return true; +} diff --git a/app/src/main/cpp/adrenotools/src/bcenabler_patch.s b/app/src/main/cpp/adrenotools/src/bcenabler_patch.s new file mode 100644 index 0000000000..8766e7880d --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/bcenabler_patch.s @@ -0,0 +1,83 @@ + cmp w0, 131 + bne .L2 + mov w0, 71 + b .L3 +.L2: + cmp w0, 133 + bne .L4 + mov w0, 71 + b .L3 +.L4: + cmp w0, 132 + bne .L5 + mov w0, 72 + b .L3 +.L5: + cmp w0, 134 + bne .L6 + mov w0, 72 + b .L3 +.L6: + cmp w0, 135 + bne .L7 + mov w0, 74 + b .L3 +.L7: + cmp w0, 136 + bne .L8 + mov w0, 75 + b .L3 +.L8: + cmp w0, 137 + bne .L9 + mov w0, 77 + b .L3 +.L9: + cmp w0, 138 + bne .L10 + mov w0, 78 + b .L3 +.L10: + cmp w0, 139 + bne .L11 + mov w0, 80 + b .L3 +.L11: + cmp w0, 140 + bne .L12 + mov w0, 81 + b .L3 +.L12: + cmp w0, 141 + bne .L13 + mov w0, 83 + b .L3 +.L13: + cmp w0, 142 + bne .L14 + mov w0, 84 + b .L3 +.L14: + cmp w0, 143 + bne .L15 + mov w0, 95 + b .L3 +.L15: + cmp w0, 144 + bne .L16 + mov w0, 96 + b .L3 +.L16: + cmp w0, 145 + bne .L17 + mov w0, 98 + b .L3 +.L17: + cmp w0, 146 + bne .L18 + mov w0, 99 + b .L3 +.L18: + mov w0, 0 +.L3: + .word 0xffffffff // Branch fixup diff --git a/app/src/main/cpp/adrenotools/src/driver.cpp b/app/src/main/cpp/adrenotools/src/driver.cpp new file mode 100644 index 0000000000..581e04a671 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/driver.cpp @@ -0,0 +1,234 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "hook/kgsl.h" +#include "hook/hook_impl_params.h" +#include +#include + +void *adrenotools_open_libvulkan(int dlopenFlags, int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, const char *customDriverName, const char *fileRedirectDir, void **userMappingHandle) { + // Bail out if linkernsbypass failed to load, this probably means we're on api < 28 + if (!linkernsbypass_load_status()) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Could not load linkernsbypass\n"); + return nullptr; + } + + // Use memfd on Q+ since it's guaranteed to work, but only if tmpLibDir wasn't set + if (android_get_device_api_level() >= 29 && !tmpLibDir) + tmpLibDir = nullptr; + + // Verify that params for specific features are only passed if they are enabled + if (!(featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) && fileRedirectDir) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_FILE_REDIRECT present but no file redirect folder found\n"); + return nullptr; + } + + if (!(featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) && (customDriverDir || customDriverName)) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_CUSTOM present but no custom driver name or folder found\n"); + return nullptr; + } + + if (!(featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) && userMappingHandle) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT present but no user mapping handle found\n"); + return nullptr; + } + + // Verify that params for enabled features are correct + struct stat buf{}; + + if (featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) { + if (!customDriverName || !customDriverDir) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_CUSTOM present but no custom driver name or folder parameter was specified\n"); + return nullptr; + } + + if (stat((std::string(customDriverDir) + customDriverName).c_str(), &buf) != 0) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_CUSTOM present but importable driver doesn't exist'\n"); + return nullptr; + } + } + + // Verify that params for enabled features are correct + if (featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) { + if (!fileRedirectDir) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_REDIRECT_DIR present but no folder parameter was found\n"); + return nullptr; + } + + if (stat(fileRedirectDir, &buf) != 0) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "ADRENOTOOLS_DRIVER_REDIRECT_DIR present but specified redirect folder doesn't exist\n"); + return nullptr; + } + } + + // Create a namespace that can isolate our hook from the classloader namespace + auto hookNs{android_create_namespace("adrenotools-libvulkan", hookLibDir, nullptr, ANDROID_NAMESPACE_TYPE_SHARED, nullptr, nullptr)}; + + // Link it to the default namespace so the hook can use libandroid etc + if (!linkernsbypass_link_namespace_to_default_all_libs(hookNs)) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Failed to hook our namespace to the default one\n"); + return nullptr; + } + // Preload the hook implementation, otherwise we get a weird issue where despite being in NEEDED of the hook lib the hook's symbols will overwrite ours and cause an infinite loop + auto hookImpl{linkernsbypass_namespace_dlopen("libhook_impl.so", RTLD_NOW, hookNs)}; + if (!hookImpl) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Couldn't preload the hook implementation\n"); + return nullptr; + } + + // Pass parameters to the hook implementation + auto initHookParam{reinterpret_cast(dlsym(hookImpl, "init_hook_param"))}; + if (!initHookParam) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Couldn't init hook params\n"); + return nullptr; + } + + auto importMapping{[&]() -> adrenotools_gpu_mapping * { + if (featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) { + // This will be leaked, but it's not a big deal since it's only a few bytes + adrenotools_gpu_mapping *mapping{new adrenotools_gpu_mapping{}}; + *userMappingHandle = mapping; + return mapping; + } else { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Memory mapping flag was not specified\n"); + return nullptr; + } + }()}; + + initHookParam(new HookImplParams(featureFlags, tmpLibDir, hookLibDir, customDriverDir, customDriverName, fileRedirectDir, importMapping)); + + // Load the libvulkan hook into the isolated namespace + if (!linkernsbypass_namespace_dlopen("libmain_hook.so", RTLD_GLOBAL, hookNs)) { + __android_log_print( ANDROID_LOG_ERROR, "adrenotools", "Failed to load libvulkan into the isolated namespace\n"); + return nullptr; + } + + return linkernsbypass_namespace_dlopen_unique("/system/lib64/libvulkan.so", tmpLibDir, dlopenFlags, hookNs); +} + + +bool adrenotools_import_user_mem(void *handle, void *hostPtr, uint64_t size) { + auto importMapping{reinterpret_cast(handle)}; + + kgsl_gpuobj_import_useraddr addr{ + .virtaddr = reinterpret_cast(hostPtr), + }; + + kgsl_gpuobj_import userMemImport{ + .priv = reinterpret_cast(&addr), + .priv_len = size, + .flags = KGSL_CACHEMODE_WRITEBACK << KGSL_CACHEMODE_SHIFT | KGSL_MEMFLAGS_IOCOHERENT, + .type = KGSL_USER_MEM_TYPE_ADDR, + + }; + + kgsl_gpuobj_info info{}; + + int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; + if (kgslFd < 0) + return false; + + int ret{ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_IMPORT, &userMemImport)}; + if (ret) + goto err; + + info.id = userMemImport.id; + ret = ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_INFO, &info); + if (ret) + goto err; + + importMapping->host_ptr = hostPtr; + importMapping->gpu_addr = info.gpuaddr; + importMapping->size = size; + importMapping->flags = 0xc2600; //!< Unknown flags, but they are required for the mapping to work + + close(kgslFd); + return true; + +err: + close(kgslFd); + return false; +} + +bool adrenotools_mem_gpu_allocate(void *handle, uint64_t *size) { + auto mapping{reinterpret_cast(handle)}; + + kgsl_gpuobj_alloc gpuobjAlloc{ + .size = *size, + .flags = KGSL_CACHEMODE_WRITEBACK << KGSL_CACHEMODE_SHIFT | KGSL_MEMFLAGS_IOCOHERENT, + }; + + kgsl_gpuobj_info info{}; + + int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; + if (kgslFd < 0) + return false; + + int ret{ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_ALLOC, &gpuobjAlloc)}; + if (ret) + goto err; + + *size = gpuobjAlloc.mmapsize; + + info.id = gpuobjAlloc.id; + + ret = ioctl(kgslFd, IOCTL_KGSL_GPUOBJ_INFO, &info); + if (ret) + goto err; + + mapping->host_ptr = nullptr; + mapping->gpu_addr = info.gpuaddr; + mapping->size = *size; + mapping->flags = 0xc2600; //!< Unknown flags, but they are required for the mapping to work + + close(kgslFd); + return true; + +err: + close(kgslFd); + return false; +} + + +bool adrenotools_mem_cpu_map(void *handle, void *hostPtr, uint64_t size) { + auto mapping{reinterpret_cast(handle)}; + + int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; + if (kgslFd < 0) + return false; + + mapping->host_ptr = mmap(hostPtr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, kgslFd, mapping->gpu_addr); + close(kgslFd); + return mapping->host_ptr != nullptr; +} + +bool adrenotools_validate_gpu_mapping(void *handle) { + auto importMapping{reinterpret_cast(handle)}; + return importMapping->gpu_addr == ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; +} + +void adrenotools_set_turbo(bool turbo) { + uint32_t enable{turbo ? 0U : 1U}; + kgsl_device_getproperty prop{ + .type = KGSL_PROP_PWRCTRL, + .value = reinterpret_cast(&enable), + .sizebytes = sizeof(enable), + }; + + int kgslFd{open("/dev/kgsl-3d0", O_RDWR)}; + if (kgslFd < 0) + return; + + ioctl(kgslFd, IOCTL_KGSL_SETPROPERTY, &prop); + close (kgslFd); +} diff --git a/app/src/main/cpp/adrenotools/src/hook/CMakeLists.txt b/app/src/main/cpp/adrenotools/src/hook/CMakeLists.txt new file mode 100644 index 0000000000..ebff0639d7 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/CMakeLists.txt @@ -0,0 +1,27 @@ +add_library(hook_impl SHARED hook_impl.cpp hook_impl.h hook_impl_params.h) + +target_compile_options(hook_impl PRIVATE -Wall -Wextra) +target_link_libraries(hook_impl linkernsbypass log) +target_include_directories(hook_impl PRIVATE ../../include) +set_target_properties(hook_impl PROPERTIES CXX_VISIBILITY_PRESET hidden) + +add_library(main_hook SHARED main_hook.c) + +target_compile_options(main_hook PRIVATE -Wall -Wextra) +target_link_options(main_hook PRIVATE -z global) +target_link_libraries(main_hook hook_impl) +set_target_properties(main_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) + +add_library(file_redirect_hook SHARED file_redirect_hook.c) + +target_compile_options(file_redirect_hook PRIVATE -Wall -Wextra) +target_link_options(file_redirect_hook PRIVATE -z global) +target_link_libraries(file_redirect_hook hook_impl) +set_target_properties(file_redirect_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) + +add_library(gsl_alloc_hook SHARED gsl_alloc_hook.c) + +target_compile_options(gsl_alloc_hook PRIVATE -Wall -Wextra) +target_link_options(gsl_alloc_hook PRIVATE -z global) +target_link_libraries(gsl_alloc_hook hook_impl) +set_target_properties(gsl_alloc_hook PROPERTIES CXX_VISIBILITY_PRESET hidden) diff --git a/app/src/main/cpp/adrenotools/src/hook/file_redirect_hook.c b/app/src/main/cpp/adrenotools/src/hook/file_redirect_hook.c new file mode 100644 index 0000000000..aa3b6d2f2d --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/file_redirect_hook.c @@ -0,0 +1,5 @@ +#include "hook_impl.h" + +__attribute__((visibility("default"))) FILE *fopen(const char *filename, const char *mode) { + return hook_fopen(filename, mode); +} \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/src/hook/gsl_alloc_hook.c b/app/src/main/cpp/adrenotools/src/hook/gsl_alloc_hook.c new file mode 100644 index 0000000000..07f332d9b5 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/gsl_alloc_hook.c @@ -0,0 +1,13 @@ +#include "hook_impl.h" + +__attribute__((visibility("default"))) int gsl_memory_alloc_pure(uint32_t size, uint32_t flags, void *memDesc) { + return hook_gsl_memory_alloc_pure_64((uint64_t)size, flags, memDesc); +} + +__attribute__((visibility("default"))) int gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { + return hook_gsl_memory_alloc_pure_64(size, flags, memDesc); +} + +__attribute__((visibility("default"))) int gsl_memory_free_pure(void *memDesc) { + return hook_gsl_memory_free_pure(memDesc); +} diff --git a/app/src/main/cpp/adrenotools/src/hook/hook_impl.cpp b/app/src/main/cpp/adrenotools/src/hook/hook_impl.cpp new file mode 100644 index 0000000000..50e79a946b --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/hook_impl.cpp @@ -0,0 +1,229 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "kgsl.h" +#include "hook_impl_params.h" +#include "hook_impl.h" + +#define TAG "hook_impl" +#define LOGI(fmt, ...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##__VA_ARGS__) + +const HookImplParams *hook_params; //!< Bunch of info needed to load/patch the driver +int (*gsl_memory_alloc_pure_sym)(uint32_t, uint32_t, void *); +int (*gsl_memory_alloc_pure_64_sym)(uint64_t, uint32_t, void *); +int (*gsl_memory_free_pure_sym)(void *); +int kgsl_fd; + +using gsl_memory_alloc_pure_t = decltype(gsl_memory_alloc_pure_sym); +using gsl_memory_alloc_pure_64_t = decltype(gsl_memory_alloc_pure_64_sym); +using gsl_memory_free_pure_t = decltype(gsl_memory_free_pure_sym); + +__attribute__((visibility("default"))) void init_hook_param(const void *param) { + hook_params = reinterpret_cast(param); +} + +__attribute__((visibility("default"))) void init_gsl(void *alloc, void *alloc64, void *free) { + gsl_memory_alloc_pure_sym = reinterpret_cast(alloc); + gsl_memory_alloc_pure_64_sym = reinterpret_cast(alloc64); + gsl_memory_free_pure_sym = reinterpret_cast(free); +} + +__attribute__((visibility("default"))) void *hook_android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) { + auto fallback{[&]() { + LOGI("hook_android_dlopen_ext: falling back!"); + return android_dlopen_ext(filename, flags, extinfo); + }}; + + LOGI("hook_android_dlopen_ext: filename: %s", filename); + + // Ignore non-vulkan libraries + if (!strstr(filename, "vulkan.")) + return android_dlopen_ext(filename, flags, extinfo); + + if (extinfo->library_namespace == nullptr || !(extinfo->flags & ANDROID_DLEXT_USE_NAMESPACE)) { + LOGI("hook_android_dlopen_ext: hook failed: namespace not supplied!"); + return fallback(); + } + + // customDriverDir will be empty if ADRENOTOOLS_DRIVER_CUSTOM isn't set therefore it's fine to have either way + auto driverNs{android_create_namespace(filename, hook_params->customDriverDir.c_str(), + hook_params->hookLibDir.c_str(), ANDROID_NAMESPACE_TYPE_SHARED, + nullptr, extinfo->library_namespace)}; + if (!driverNs) { + LOGI("hook_android_dlopen_ext: hook failed: namespace not supplied!"); + return fallback(); + } + + // We depend on libandroid which is unlikely to be in the supplied driver namespace so we have to link it over + android_link_namespaces(driverNs, nullptr, "libandroid.so"); + + // Preload ourself, a new instance will be created since we have different linker ancestory + // If we don't preload we get a weird issue where despite being in NEEDED of the hook lib the hook's symbols will overwrite ours and cause an infinite loop + auto hookImpl{linkernsbypass_namespace_dlopen("libhook_impl.so", RTLD_NOW, driverNs)}; + if (!hookImpl) + return nullptr; + + // Pass parameters to ourself + auto initHookParam{reinterpret_cast(dlsym(hookImpl, "init_hook_param"))}; + if (!initHookParam) + return nullptr; + + initHookParam(hook_params); + + if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_FILE_REDIRECT) { + if (!linkernsbypass_namespace_dlopen("libfile_redirect_hook.so", RTLD_GLOBAL, driverNs)) { + LOGI("hook_android_dlopen_ext: hook failed: failed to apply libfopen_redirect_hook!"); + return fallback(); + } + + LOGI("hook_android_dlopen_ext: applied libfile_redirect_hook"); + } + + // Use our new namespace to load the vulkan driver + auto newExtinfo{*extinfo}; + newExtinfo.library_namespace = driverNs; + + if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_GPU_MAPPING_IMPORT) { + if (!linkernsbypass_namespace_dlopen("libgsl_alloc_hook.so", RTLD_GLOBAL, driverNs)) { + LOGI("hook_android_dlopen_ext: hook failed: failed to apply libgsl_alloc_hook!"); + return fallback(); + } + + auto libgslHandle{android_dlopen_ext("vkbgsl.so", RTLD_NOW, &newExtinfo)}; + if (!libgslHandle) { + libgslHandle = android_dlopen_ext("notgsl.so", RTLD_NOW, &newExtinfo); + if (!libgslHandle) + libgslHandle = android_dlopen_ext("libgsl.so", RTLD_NOW, &newExtinfo); + } + + if (libgslHandle) { + gsl_memory_alloc_pure_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_alloc_pure")); + gsl_memory_alloc_pure_64_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_alloc_pure_64")); + gsl_memory_free_pure_sym = reinterpret_cast(dlsym(libgslHandle, "gsl_memory_free_pure")); + if ((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym) { + auto initGsl{reinterpret_cast(dlsym(hookImpl, "init_gsl"))}; + if (!initGsl) + return fallback(); + + initGsl(gsl_memory_alloc_pure_sym, gsl_memory_alloc_pure_64_sym, gsl_memory_free_pure_sym); + LOGI("hook_android_dlopen_ext: applied libgsl_alloc_hook"); + hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; + } + } + + if (!((gsl_memory_alloc_pure_sym || gsl_memory_alloc_pure_64_sym) && gsl_memory_free_pure_sym)) + LOGI("hook_android_dlopen_ext: hook failed: failed to apply libgsl_alloc_hook!"); + } + + // TODO: If there is already an instance of a Vulkan driver loaded hooks won't be applied, this will only be the case for skiavk generally + // To fix this we would need to search /proc/self/maps for the file to a loaded instance of the library in order to read it to patch the soname and load it uniquely + if (hook_params->featureFlags & ADRENOTOOLS_DRIVER_CUSTOM) { + LOGI("hook_android_dlopen_ext: loading custom driver: %s%s", hook_params->customDriverDir.c_str(), hook_params->customDriverName.c_str()); + void *handle{android_dlopen_ext(hook_params->customDriverName.c_str(), flags, &newExtinfo)}; + if (!handle) { + LOGI("hook_android_dlopen_ext: hook failed: failed to load custom driver: %s!", dlerror()); + return fallback(); + } + + return handle; + } else { + LOGI("hook_android_dlopen_ext: loading default driver: %s", filename); + return android_dlopen_ext(filename, flags, &newExtinfo); + } +} + +__attribute__((visibility("default"))) void *hook_android_load_sphal_library(const char *filename, int flags) { + LOGI("hook_android_load_sphal_library: filename: %s", filename); + + // https://android.googlesource.com/platform/system/core/+/master/libvndksupport/linker.cpp + for (const char *name : {"sphal", "vendor", "default"}) { + if (auto vendorNs{android_get_exported_namespace(name)}) { + android_dlextinfo dlextinfo{ + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = vendorNs, + }; + + return hook_android_dlopen_ext(filename, flags, &dlextinfo); + } + } + + return nullptr; +} + +__attribute__((visibility("default"))) FILE *hook_fopen(const char *filename, const char *mode) { + if (!strncmp("/proc", filename, 5) || !strncmp("/sys", filename, 4)) { + LOGI("hook_fopen: passthrough: %s", filename); + return fopen(filename, mode); + } + + auto replacement{hook_params->fileRedirectDir + filename}; + LOGI("hook_fopen: %s -> %s", filename, replacement.c_str()); + + return fopen(replacement.c_str(), mode); +} + +static constexpr uintptr_t GslMemDescImportedPrivMagic{0xdeadb33f}; +struct GslMemDesc { + void *hostptr; + uint64_t gpuaddr; + uint64_t size; + uint64_t flags; + uintptr_t priv; +}; + +__attribute__((visibility("default"))) int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc) { + auto gslMemDesc{reinterpret_cast(memDesc)}; + if (hook_params->nextGpuMapping && hook_params->nextGpuMapping->size == size && (hook_params->nextGpuMapping->flags & flags) == hook_params->nextGpuMapping->flags) { + auto &nextMapping{*hook_params->nextGpuMapping}; + + gslMemDesc->hostptr = nextMapping.host_ptr; + gslMemDesc->gpuaddr = nextMapping.gpu_addr; + gslMemDesc->size = nextMapping.size; + gslMemDesc->flags = nextMapping.flags; + gslMemDesc->priv = GslMemDescImportedPrivMagic; + hook_params->nextGpuMapping->size = 0; + hook_params->nextGpuMapping->gpu_addr = ADRENOTOOLS_GPU_MAPPING_SUCCEEDED_MAGIC; + return 0; + } else { + if (gsl_memory_alloc_pure_64_sym) + return gsl_memory_alloc_pure_64_sym(size, flags, gslMemDesc); + else + return gsl_memory_alloc_pure_sym((uint32_t)size, flags, gslMemDesc); + } +} + +__attribute__((visibility("default"))) int hook_gsl_memory_free_pure(void *memDesc) { + auto gslMemDesc{reinterpret_cast(memDesc)}; + + if (gslMemDesc->priv == GslMemDescImportedPrivMagic) { + if (!kgsl_fd) + kgsl_fd = open("/dev/kgsl-3d0", O_RDWR); + + kgsl_gpumem_get_info info{ + .gpuaddr = gslMemDesc->gpuaddr + }; + + if (ioctl(kgsl_fd, IOCTL_KGSL_GPUMEM_GET_INFO, &info) < 0) { + LOGI("IOCTL_KGSL_GPUMEM_GET_INFO failed"); + return 0; + } + + kgsl_gpuobj_free args{ + .id = info.id, + }; + + if (ioctl(kgsl_fd, IOCTL_KGSL_GPUOBJ_FREE, &args) < 0) + LOGI("IOCTL_KGSL_GPUOBJ_FREE failed"); + + return 0; + } else { + return gsl_memory_free_pure_sym(memDesc); + } +} diff --git a/app/src/main/cpp/adrenotools/src/hook/hook_impl.h b/app/src/main/cpp/adrenotools/src/hook/hook_impl.h new file mode 100644 index 0000000000..2ce2471e1d --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/hook_impl.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +void init_hook_param(const void *param); + +void init_gsl(void *alloc, void *alloc64, void *free); + +void *hook_android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo); + +void *hook_android_load_sphal_library(const char *filename, int flags); + +FILE *hook_fopen(const char *filename, const char *mode); + +int hook_gsl_memory_alloc_pure_64(uint64_t size, uint32_t flags, void *memDesc); + +int hook_gsl_memory_free_pure(void *memDesc); + +#ifdef __cplusplus +} +#endif + diff --git a/app/src/main/cpp/adrenotools/src/hook/hook_impl_params.h b/app/src/main/cpp/adrenotools/src/hook/hook_impl_params.h new file mode 100644 index 0000000000..8a3bd1673e --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/hook_impl_params.h @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: BSD-2-Clause +// Copyright © 2021 Billy Laws + +#pragma once + +#include +#include + +/** + * @brief Holds the parameters needed for all hooks + * @note See comments for adrenotools_open_libvulkan as a reference for member variables + */ +struct HookImplParams { + int featureFlags; + std::string tmpLibDir; + std::string hookLibDir; + std::string customDriverDir; + std::string customDriverName; + std::string fileRedirectDir; + adrenotools_gpu_mapping *nextGpuMapping; + + HookImplParams(int featureFlags, const char *tmpLibDir, const char *hookLibDir, const char *customDriverDir, + const char *customDriverName, const char *fileRedirectDir, adrenotools_gpu_mapping *nextGpuMapping) + : featureFlags(featureFlags), + tmpLibDir(tmpLibDir ? tmpLibDir : ""), + hookLibDir(hookLibDir), + customDriverDir(customDriverDir ? customDriverDir : ""), + customDriverName(customDriverName ? customDriverName : ""), + fileRedirectDir(fileRedirectDir ? fileRedirectDir : ""), + nextGpuMapping(nextGpuMapping) {} +}; diff --git a/app/src/main/cpp/adrenotools/src/hook/kgsl.h b/app/src/main/cpp/adrenotools/src/hook/kgsl.h new file mode 100644 index 0000000000..6d4d93d6af --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/kgsl.h @@ -0,0 +1,2124 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef _UAPI_MSM_KGSL_H +#define _UAPI_MSM_KGSL_H + +#include +#include + +/* + * The KGSL version has proven not to be very useful in userspace if features + * are cherry picked into other trees out of order so it is frozen as of 3.14. + * It is left here for backwards compatabilty and as a reminder that + * software releases are never linear. Also, I like pie. + */ + +#define KGSL_VERSION_MAJOR 3 +#define KGSL_VERSION_MINOR 14 + +/* + * We have traditionally mixed context and issueibcmds / command batch flags + * together into a big flag stew. This worked fine until we started adding a + * lot more command batch flags and we started running out of bits. Turns out + * we have a bit of room in the context type / priority mask that we could use + * for command batches, but that means we need to split out the flags into two + * coherent sets. + * + * If any future definitions are for both context and cmdbatch add both defines + * and link the cmdbatch to the context define as we do below. Otherwise feel + * free to add exclusive bits to either set. + */ + +/* --- context flags --- */ +#define KGSL_CONTEXT_SAVE_GMEM 0x00000001 +#define KGSL_CONTEXT_NO_GMEM_ALLOC 0x00000002 +/* This is a cmdbatch exclusive flag - use the CMDBATCH equivalent instead */ +#define KGSL_CONTEXT_SUBMIT_IB_LIST 0x00000004 +#define KGSL_CONTEXT_CTX_SWITCH 0x00000008 +#define KGSL_CONTEXT_PREAMBLE 0x00000010 +#define KGSL_CONTEXT_TRASH_STATE 0x00000020 +#define KGSL_CONTEXT_PER_CONTEXT_TS 0x00000040 +#define KGSL_CONTEXT_USER_GENERATED_TS 0x00000080 +/* This is a cmdbatch exclusive flag - use the CMDBATCH equivalent instead */ +#define KGSL_CONTEXT_END_OF_FRAME 0x00000100 +#define KGSL_CONTEXT_NO_FAULT_TOLERANCE 0x00000200 +/* This is a cmdbatch exclusive flag - use the CMDBATCH equivalent instead */ +#define KGSL_CONTEXT_SYNC 0x00000400 +#define KGSL_CONTEXT_PWR_CONSTRAINT 0x00000800 +#define KGSL_CONTEXT_PRIORITY_MASK 0x0000F000 +#define KGSL_CONTEXT_PRIORITY_SHIFT 12 +#define KGSL_CONTEXT_PRIORITY_UNDEF 0 + +#define KGSL_CONTEXT_IFH_NOP 0x00010000 +#define KGSL_CONTEXT_SECURE 0x00020000 +#define KGSL_CONTEXT_NO_SNAPSHOT 0x00040000 +#define KGSL_CONTEXT_SPARSE 0x00080000 + +#define KGSL_CONTEXT_PREEMPT_STYLE_MASK 0x0E000000 +#define KGSL_CONTEXT_PREEMPT_STYLE_SHIFT 25 +#define KGSL_CONTEXT_PREEMPT_STYLE_DEFAULT 0x0 +#define KGSL_CONTEXT_PREEMPT_STYLE_RINGBUFFER 0x1 +#define KGSL_CONTEXT_PREEMPT_STYLE_FINEGRAIN 0x2 + +#define KGSL_CONTEXT_TYPE_MASK 0x01F00000 +#define KGSL_CONTEXT_TYPE_SHIFT 20 +#define KGSL_CONTEXT_TYPE_ANY 0 +#define KGSL_CONTEXT_TYPE_GL 1 +#define KGSL_CONTEXT_TYPE_CL 2 +#define KGSL_CONTEXT_TYPE_C2D 3 +#define KGSL_CONTEXT_TYPE_RS 4 +#define KGSL_CONTEXT_TYPE_VK 5 +#define KGSL_CONTEXT_TYPE_UNKNOWN 0x1E + +#define KGSL_CONTEXT_INVALIDATE_ON_FAULT 0x10000000 +#define KGSL_CONTEXT_LPAC 0x20000000 +#define KGSL_CONTEXT_FAULT_INFO 0x40000000 + +#define KGSL_CONTEXT_INVALID 0xffffffff + +/* + * --- command batch flags --- + * The bits that are linked to a KGSL_CONTEXT equivalent are either legacy + * definitions or bits that are valid for both contexts and cmdbatches. To be + * safe the other 8 bits that are still available in the context field should be + * omitted here in case we need to share - the other bits are available for + * cmdbatch only flags as needed + */ +#define KGSL_CMDBATCH_MEMLIST 0x00000001 +#define KGSL_CMDBATCH_MARKER 0x00000002 +#define KGSL_CMDBATCH_SUBMIT_IB_LIST KGSL_CONTEXT_SUBMIT_IB_LIST /* 0x004 */ +#define KGSL_CMDBATCH_CTX_SWITCH KGSL_CONTEXT_CTX_SWITCH /* 0x008 */ +#define KGSL_CMDBATCH_PROFILING 0x00000010 +/* + * KGSL_CMDBATCH_PROFILING must also be set for KGSL_CMDBATCH_PROFILING_KTIME + * to take effect, as the latter only affects the time data returned. + */ +#define KGSL_CMDBATCH_PROFILING_KTIME 0x00000020 +#define KGSL_CMDBATCH_END_OF_FRAME KGSL_CONTEXT_END_OF_FRAME /* 0x100 */ +#define KGSL_CMDBATCH_SYNC KGSL_CONTEXT_SYNC /* 0x400 */ +#define KGSL_CMDBATCH_PWR_CONSTRAINT KGSL_CONTEXT_PWR_CONSTRAINT /* 0x800 */ +#define KGSL_CMDBATCH_SPARSE 0x1000 /* 0x1000 */ +/* RECURRING bits must be set for LSR workload with IOCTL_KGSL_RECURRING_COMMAND. */ +#define KGSL_CMDBATCH_START_RECURRING 0x00100000 +#define KGSL_CMDBATCH_STOP_RECURRING 0x00200000 + +/* + * Reserve bits [16:19] and bits [28:31] for possible bits shared between + * contexts and command batches. Update this comment as new flags are added. + */ + +/* + * gpu_command_object flags - these flags communicate the type of command or + * memory object being submitted for a GPU command + */ + +/* Flags for GPU command objects */ +#define KGSL_CMDLIST_IB 0x00000001U +#define KGSL_CMDLIST_CTXTSWITCH_PREAMBLE 0x00000002U +#define KGSL_CMDLIST_IB_PREAMBLE 0x00000004U + +/* Flags for GPU command memory objects */ +#define KGSL_OBJLIST_MEMOBJ 0x00000008U +#define KGSL_OBJLIST_PROFILE 0x00000010U + +/* Flags for GPU command sync points */ +#define KGSL_CMD_SYNCPOINT_TYPE_TIMESTAMP 0 +#define KGSL_CMD_SYNCPOINT_TYPE_FENCE 1 +#define KGSL_CMD_SYNCPOINT_TYPE_TIMELINE 2 + +/* --- Memory allocation flags --- */ + +/* General allocation hints */ +#define KGSL_MEMFLAGS_SECURE (1ULL << 3) +#define KGSL_MEMFLAGS_GPUREADONLY (1ULL << 24) +#define KGSL_MEMFLAGS_GPUWRITEONLY (1ULL << 25) +#define KGSL_MEMFLAGS_FORCE_32BIT (1ULL << 32) + +/* Flag for binding all the virt range to single phys data */ +#define KGSL_SPARSE_BIND_MULTIPLE_TO_PHYS 0x400000000ULL +#define KGSL_SPARSE_BIND 0x1ULL +#define KGSL_SPARSE_UNBIND 0x2ULL + +/* Memory caching hints */ +#define KGSL_CACHEMODE_MASK 0x0C000000U +#define KGSL_CACHEMODE_SHIFT 26 + +#define KGSL_CACHEMODE_WRITECOMBINE 0 +#define KGSL_CACHEMODE_UNCACHED 1 +#define KGSL_CACHEMODE_WRITETHROUGH 2 +#define KGSL_CACHEMODE_WRITEBACK 3 + +#define KGSL_MEMFLAGS_USE_CPU_MAP (1ULL << 28) +#define KGSL_MEMFLAGS_SPARSE_PHYS (1ULL << 29) +#define KGSL_MEMFLAGS_SPARSE_VIRT (1ULL << 30) +#define KGSL_MEMFLAGS_IOCOHERENT (1ULL << 31) +#define KGSL_MEMFLAGS_GUARD_PAGE (1ULL << 33) +#define KGSL_MEMFLAGS_VBO (1ULL << 34) + +/* Memory types for which allocations are made */ +#define KGSL_MEMTYPE_MASK 0x0000FF00 +#define KGSL_MEMTYPE_SHIFT 8 + +#define KGSL_MEMTYPE_OBJECTANY 0 +#define KGSL_MEMTYPE_FRAMEBUFFER 1 +#define KGSL_MEMTYPE_RENDERBUFFER 2 +#define KGSL_MEMTYPE_ARRAYBUFFER 3 +#define KGSL_MEMTYPE_ELEMENTARRAYBUFFER 4 +#define KGSL_MEMTYPE_VERTEXARRAYBUFFER 5 +#define KGSL_MEMTYPE_TEXTURE 6 +#define KGSL_MEMTYPE_SURFACE 7 +#define KGSL_MEMTYPE_EGL_SURFACE 8 +#define KGSL_MEMTYPE_GL 9 +#define KGSL_MEMTYPE_CL 10 +#define KGSL_MEMTYPE_CL_BUFFER_MAP 11 +#define KGSL_MEMTYPE_CL_BUFFER_NOMAP 12 +#define KGSL_MEMTYPE_CL_IMAGE_MAP 13 +#define KGSL_MEMTYPE_CL_IMAGE_NOMAP 14 +#define KGSL_MEMTYPE_CL_KERNEL_STACK 15 +#define KGSL_MEMTYPE_COMMAND 16 +#define KGSL_MEMTYPE_2D 17 +#define KGSL_MEMTYPE_EGL_IMAGE 18 +#define KGSL_MEMTYPE_EGL_SHADOW 19 +#define KGSL_MEMTYPE_MULTISAMPLE 20 +#define KGSL_MEMTYPE_KERNEL 255 + +/* + * Alignment hint, passed as the power of 2 exponent. + * i.e 4k (2^12) would be 12, 64k (2^16)would be 16. + */ +#define KGSL_MEMALIGN_MASK 0x00FF0000 +#define KGSL_MEMALIGN_SHIFT 16 + +enum kgsl_user_mem_type { + KGSL_USER_MEM_TYPE_PMEM = 0x00000000, + KGSL_USER_MEM_TYPE_ASHMEM = 0x00000001, + KGSL_USER_MEM_TYPE_ADDR = 0x00000002, + KGSL_USER_MEM_TYPE_ION = 0x00000003, + /* + * ION type is retained for backwards compatibility but Ion buffers are + * dma-bufs so try to use that naming if we can + */ + KGSL_USER_MEM_TYPE_DMABUF = 0x00000003, + KGSL_USER_MEM_TYPE_MAX = 0x00000007, +}; +#define KGSL_MEMFLAGS_USERMEM_MASK 0x000000e0 +#define KGSL_MEMFLAGS_USERMEM_SHIFT 5 + +/* + * Unfortunately, enum kgsl_user_mem_type starts at 0 which does not + * leave a good value for allocated memory. In the flags we use + * 0 to indicate allocated memory and thus need to add 1 to the enum + * values. + */ +#define KGSL_USERMEM_FLAG(x) (((x) + 1) << KGSL_MEMFLAGS_USERMEM_SHIFT) + +#define KGSL_MEMFLAGS_NOT_USERMEM 0 +#define KGSL_MEMFLAGS_USERMEM_PMEM KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_PMEM) +#define KGSL_MEMFLAGS_USERMEM_ASHMEM \ + KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ASHMEM) +#define KGSL_MEMFLAGS_USERMEM_ADDR KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ADDR) +#define KGSL_MEMFLAGS_USERMEM_ION KGSL_USERMEM_FLAG(KGSL_USER_MEM_TYPE_ION) + +/* --- generic KGSL flag values --- */ + +#define KGSL_FLAGS_NORMALMODE 0x00000000 +#define KGSL_FLAGS_SAFEMODE 0x00000001 +#define KGSL_FLAGS_INITIALIZED0 0x00000002 +#define KGSL_FLAGS_INITIALIZED 0x00000004 +#define KGSL_FLAGS_STARTED 0x00000008 +#define KGSL_FLAGS_ACTIVE 0x00000010 +#define KGSL_FLAGS_RESERVED0 0x00000020 +#define KGSL_FLAGS_RESERVED1 0x00000040 +#define KGSL_FLAGS_RESERVED2 0x00000080 +#define KGSL_FLAGS_SOFT_RESET 0x00000100 +#define KGSL_FLAGS_PER_CONTEXT_TIMESTAMPS 0x00000200 + +/* Server Side Sync Timeout in milliseconds */ +#define KGSL_SYNCOBJ_SERVER_TIMEOUT 2000 + +/* UBWC Modes */ +#define KGSL_UBWC_NONE 0 +#define KGSL_UBWC_1_0 1 +#define KGSL_UBWC_2_0 2 +#define KGSL_UBWC_3_0 3 +#define KGSL_UBWC_4_0 4 + +/* + * Reset status values for context + */ +enum kgsl_ctx_reset_stat { + KGSL_CTX_STAT_NO_ERROR = 0x00000000, + KGSL_CTX_STAT_GUILTY_CONTEXT_RESET_EXT = 0x00000001, + KGSL_CTX_STAT_INNOCENT_CONTEXT_RESET_EXT = 0x00000002, + KGSL_CTX_STAT_UNKNOWN_CONTEXT_RESET_EXT = 0x00000003 +}; + +#define KGSL_CONVERT_TO_MBPS(val) \ + (val*1000*1000U) + +struct kgsl_devinfo { + + unsigned int device_id; + /* + * chip revision id + * coreid:8 majorrev:8 minorrev:8 patch:8 + */ + unsigned int chip_id; + unsigned int mmu_enabled; + unsigned long gmem_gpubaseaddr; + /* + * This field contains the adreno revision + * number 200, 205, 220, etc... + */ + unsigned int gpu_id; + __kernel_size_t gmem_sizebytes; +}; + +/* + * struct kgsl_devmemstore - this structure defines the region of memory + * that can be mmap()ed from this driver. The timestamp fields are volatile + * because they are written by the GPU + * @soptimestamp: Start of pipeline timestamp written by GPU before the + * commands in concern are processed + * @sbz: Unused, kept for 8 byte alignment + * @eoptimestamp: End of pipeline timestamp written by GPU after the + * commands in concern are processed + * @sbz2: Unused, kept for 8 byte alignment + * @preempted: Indicates if the context was preempted + * @sbz3: Unused, kept for 8 byte alignment + * @ref_wait_ts: Timestamp on which to generate interrupt, unused now. + * @sbz4: Unused, kept for 8 byte alignment + * @current_context: The current context the GPU is working on + * @sbz5: Unused, kept for 8 byte alignment + */ +struct kgsl_devmemstore { + volatile unsigned int soptimestamp; + unsigned int sbz; + volatile unsigned int eoptimestamp; + unsigned int sbz2; + volatile unsigned int preempted; + unsigned int sbz3; + volatile unsigned int ref_wait_ts; + unsigned int sbz4; + unsigned int current_context; + unsigned int sbz5; +}; + +#define KGSL_MEMSTORE_OFFSET(ctxt_id, field) \ + ((ctxt_id)*sizeof(struct kgsl_devmemstore) + \ + offsetof(struct kgsl_devmemstore, field)) + +/* timestamp id*/ +enum kgsl_timestamp_type { + KGSL_TIMESTAMP_CONSUMED = 0x00000001, /* start-of-pipeline timestamp */ + KGSL_TIMESTAMP_RETIRED = 0x00000002, /* end-of-pipeline timestamp*/ + KGSL_TIMESTAMP_QUEUED = 0x00000003, +}; + +/* property types - used with kgsl_device_getproperty */ +#define KGSL_PROP_DEVICE_INFO 0x1 +#define KGSL_PROP_DEVICE_SHADOW 0x2 +#define KGSL_PROP_DEVICE_POWER 0x3 +#define KGSL_PROP_SHMEM 0x4 +#define KGSL_PROP_SHMEM_APERTURES 0x5 +#define KGSL_PROP_MMU_ENABLE 0x6 +#define KGSL_PROP_INTERRUPT_WAITS 0x7 +#define KGSL_PROP_VERSION 0x8 +#define KGSL_PROP_GPU_RESET_STAT 0x9 +#define KGSL_PROP_PWRCTRL 0xE +#define KGSL_PROP_PWR_CONSTRAINT 0x12 +#define KGSL_PROP_UCHE_GMEM_VADDR 0x13 +#define KGSL_PROP_SP_GENERIC_MEM 0x14 +#define KGSL_PROP_UCODE_VERSION 0x15 +#define KGSL_PROP_GPMU_VERSION 0x16 +#define KGSL_PROP_HIGHEST_BANK_BIT 0x17 +#define KGSL_PROP_DEVICE_BITNESS 0x18 +#define KGSL_PROP_DEVICE_QDSS_STM 0x19 +#define KGSL_PROP_MIN_ACCESS_LENGTH 0x1A +#define KGSL_PROP_UBWC_MODE 0x1B +#define KGSL_PROP_DEVICE_QTIMER 0x20 +#define KGSL_PROP_L3_PWR_CONSTRAINT 0x22 +#define KGSL_PROP_SECURE_BUFFER_ALIGNMENT 0x23 +#define KGSL_PROP_SECURE_CTXT_SUPPORT 0x24 +#define KGSL_PROP_SPEED_BIN 0x25 +#define KGSL_PROP_GAMING_BIN 0x26 +#define KGSL_PROP_QUERY_CAPABILITIES 0x27 +#define KGSL_PROP_CONTEXT_PROPERTY 0x28 +#define KGSL_PROP_GPU_MODEL 0x29 +#define KGSL_PROP_VK_DEVICE_ID 0x2A +#define KGSL_PROP_IS_LPAC_ENABLED 0x2B + +/* + * kgsl_capabilities_properties returns a list of supported properties. + * If the user passes 0 for 'count' the kernel will set it to the number of + * supported properties. The list is expected to be 'count * sizeof(__u32)' + * bytes long. The kernel will return the actual number of entries copied into + * list via 'count'. + */ +struct kgsl_capabilities_properties { + __u64 list; + __u32 count; +}; + +/* + * KGSL_QUERY_CAPS_PROPERTIES returns a list of the valid properties in the + * kernel. The subtype data should be struct kgsl_capabilities_properties + */ +#define KGSL_QUERY_CAPS_PROPERTIES 1 + +/* + * kgsl_capabilities allows the user to query kernel capabilities. The 'data' + * type should be set appropriately for the querytype (see above). Pass 0 to + * 'size' and the kernel will set it to the expected size of 'data' that is + * appropriate for querytype (in bytes). + */ +struct kgsl_capabilities { + __u64 data; + __u64 size; + __u32 querytype; +}; + +struct kgsl_shadowprop { + unsigned long gpuaddr; + __kernel_size_t size; + unsigned int flags; /* contains KGSL_FLAGS_ values */ +}; + +struct kgsl_qdss_stm_prop { + __u64 gpuaddr; + __u64 size; +}; + +struct kgsl_qtimer_prop { + __u64 gpuaddr; + __u64 size; +}; + +struct kgsl_version { + unsigned int drv_major; + unsigned int drv_minor; + unsigned int dev_major; + unsigned int dev_minor; +}; + +struct kgsl_sp_generic_mem { + __u64 local; + __u64 pvt; +}; + +struct kgsl_ucode_version { + unsigned int pfp; + unsigned int pm4; +}; + +struct kgsl_gpmu_version { + unsigned int major; + unsigned int minor; + unsigned int features; +}; + +struct kgsl_context_property { + __u64 data; + __u32 size; + __u32 type; + __u32 contextid; +}; + +struct kgsl_context_property_fault { + __s32 faults; + __u32 timestamp; +}; + +struct kgsl_gpu_model { + char gpu_model[32]; +}; + +/* Context property sub types */ +#define KGSL_CONTEXT_PROP_FAULTS 1 + +/* Performance counter groups */ + +#define KGSL_PERFCOUNTER_GROUP_CP 0x0 +#define KGSL_PERFCOUNTER_GROUP_RBBM 0x1 +#define KGSL_PERFCOUNTER_GROUP_PC 0x2 +#define KGSL_PERFCOUNTER_GROUP_VFD 0x3 +#define KGSL_PERFCOUNTER_GROUP_HLSQ 0x4 +#define KGSL_PERFCOUNTER_GROUP_VPC 0x5 +#define KGSL_PERFCOUNTER_GROUP_TSE 0x6 +#define KGSL_PERFCOUNTER_GROUP_RAS 0x7 +#define KGSL_PERFCOUNTER_GROUP_UCHE 0x8 +#define KGSL_PERFCOUNTER_GROUP_TP 0x9 +#define KGSL_PERFCOUNTER_GROUP_SP 0xA +#define KGSL_PERFCOUNTER_GROUP_RB 0xB +#define KGSL_PERFCOUNTER_GROUP_PWR 0xC +#define KGSL_PERFCOUNTER_GROUP_VBIF 0xD +#define KGSL_PERFCOUNTER_GROUP_VBIF_PWR 0xE +#define KGSL_PERFCOUNTER_GROUP_MH 0xF +#define KGSL_PERFCOUNTER_GROUP_PA_SU 0x10 +#define KGSL_PERFCOUNTER_GROUP_SQ 0x11 +#define KGSL_PERFCOUNTER_GROUP_SX 0x12 +#define KGSL_PERFCOUNTER_GROUP_TCF 0x13 +#define KGSL_PERFCOUNTER_GROUP_TCM 0x14 +#define KGSL_PERFCOUNTER_GROUP_TCR 0x15 +#define KGSL_PERFCOUNTER_GROUP_L2 0x16 +#define KGSL_PERFCOUNTER_GROUP_VSC 0x17 +#define KGSL_PERFCOUNTER_GROUP_CCU 0x18 +#define KGSL_PERFCOUNTER_GROUP_LRZ 0x19 +#define KGSL_PERFCOUNTER_GROUP_CMP 0x1A +#define KGSL_PERFCOUNTER_GROUP_ALWAYSON 0x1B +#define KGSL_PERFCOUNTER_GROUP_SP_PWR 0x1C +#define KGSL_PERFCOUNTER_GROUP_TP_PWR 0x1D +#define KGSL_PERFCOUNTER_GROUP_RB_PWR 0x1E +#define KGSL_PERFCOUNTER_GROUP_CCU_PWR 0x1F +#define KGSL_PERFCOUNTER_GROUP_UCHE_PWR 0x20 +#define KGSL_PERFCOUNTER_GROUP_CP_PWR 0x21 +#define KGSL_PERFCOUNTER_GROUP_GPMU_PWR 0x22 +#define KGSL_PERFCOUNTER_GROUP_ALWAYSON_PWR 0x23 +#define KGSL_PERFCOUNTER_GROUP_GLC 0x24 +#define KGSL_PERFCOUNTER_GROUP_FCHE 0x25 +#define KGSL_PERFCOUNTER_GROUP_MHUB 0x26 +#define KGSL_PERFCOUNTER_GROUP_GMU_XOCLK 0x27 +#define KGSL_PERFCOUNTER_GROUP_GMU_GMUCLK 0x28 +#define KGSL_PERFCOUNTER_GROUP_GMU_PERF 0x29 +#define KGSL_PERFCOUNTER_GROUP_SW 0x2a +#define KGSL_PERFCOUNTER_GROUP_UFC 0x2b +#define KGSL_PERFCOUNTER_GROUP_BV_CP 0x2c +#define KGSL_PERFCOUNTER_GROUP_BV_PC 0x2d +#define KGSL_PERFCOUNTER_GROUP_BV_VFD 0x2e +#define KGSL_PERFCOUNTER_GROUP_BV_VPC 0x2f +#define KGSL_PERFCOUNTER_GROUP_BV_TP 0x30 +#define KGSL_PERFCOUNTER_GROUP_BV_SP 0x31 +#define KGSL_PERFCOUNTER_GROUP_BV_UFC 0x32 +#define KGSL_PERFCOUNTER_GROUP_BV_TSE 0x33 +#define KGSL_PERFCOUNTER_GROUP_BV_RAS 0x34 +#define KGSL_PERFCOUNTER_GROUP_BV_LRZ 0x35 +#define KGSL_PERFCOUNTER_GROUP_BV_HLSQ 0x36 +#define KGSL_PERFCOUNTER_GROUP_MAX 0x37 + +#define KGSL_PERFCOUNTER_NOT_USED 0xFFFFFFFF +#define KGSL_PERFCOUNTER_BROKEN 0xFFFFFFFE + +/* structure holds list of ibs */ +struct kgsl_ibdesc { + unsigned long gpuaddr; + unsigned long __pad; + __kernel_size_t sizedwords; + unsigned int ctrl; +}; + +/** + * struct kgsl_cmdbatch_profiling_buffer + * @wall_clock_s: Ringbuffer submission time (seconds). + * If KGSL_CMDBATCH_PROFILING_KTIME is set, time is provided + * in kernel clocks, otherwise wall clock time is used. + * @wall_clock_ns: Ringbuffer submission time (nanoseconds). + * If KGSL_CMDBATCH_PROFILING_KTIME is set time is provided + * in kernel clocks, otherwise wall clock time is used. + * @gpu_ticks_queued: GPU ticks at ringbuffer submission + * @gpu_ticks_submitted: GPU ticks when starting cmdbatch execution + * @gpu_ticks_retired: GPU ticks when finishing cmdbatch execution + * + * This structure defines the profiling buffer used to measure cmdbatch + * execution time + */ +struct kgsl_cmdbatch_profiling_buffer { + __u64 wall_clock_s; + __u64 wall_clock_ns; + __u64 gpu_ticks_queued; + __u64 gpu_ticks_submitted; + __u64 gpu_ticks_retired; +}; + +/* ioctls */ +#define KGSL_IOC_TYPE 0x09 + +/* + * get misc info about the GPU + * type should be a value from enum kgsl_property_type + * value points to a structure that varies based on type + * sizebytes is sizeof() that structure + * for KGSL_PROP_DEVICE_INFO, use struct kgsl_devinfo + * this structure contaings hardware versioning info. + * for KGSL_PROP_DEVICE_SHADOW, use struct kgsl_shadowprop + * this is used to find mmap() offset and sizes for mapping + * struct kgsl_memstore into userspace. + */ +struct kgsl_device_getproperty { + unsigned int type; + void __user *value; + __kernel_size_t sizebytes; +}; + +#define IOCTL_KGSL_DEVICE_GETPROPERTY \ + _IOWR(KGSL_IOC_TYPE, 0x2, struct kgsl_device_getproperty) + +/* IOCTL_KGSL_DEVICE_READ (0x3) - removed 03/2012 + */ + +/* block until the GPU has executed past a given timestamp + * timeout is in milliseconds. + */ +struct kgsl_device_waittimestamp { + unsigned int timestamp; + unsigned int timeout; +}; + +#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP \ + _IOW(KGSL_IOC_TYPE, 0x6, struct kgsl_device_waittimestamp) + +struct kgsl_device_waittimestamp_ctxtid { + unsigned int context_id; + unsigned int timestamp; + unsigned int timeout; +}; + +#define IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID \ + _IOW(KGSL_IOC_TYPE, 0x7, struct kgsl_device_waittimestamp_ctxtid) + +/* DEPRECATED: issue indirect commands to the GPU. + * drawctxt_id must have been created with IOCTL_KGSL_DRAWCTXT_CREATE + * ibaddr and sizedwords must specify a subset of a buffer created + * with IOCTL_KGSL_SHAREDMEM_FROM_PMEM + * flags may be a mask of KGSL_CONTEXT_ values + * timestamp is a returned counter value which can be passed to + * other ioctls to determine when the commands have been executed by + * the GPU. + * + * This function is deprecated - consider using IOCTL_KGSL_SUBMIT_COMMANDS + * instead + */ +struct kgsl_ringbuffer_issueibcmds { + unsigned int drawctxt_id; + unsigned long ibdesc_addr; + unsigned int numibs; + unsigned int timestamp; /*output param */ + unsigned int flags; +}; + +#define IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS \ + _IOWR(KGSL_IOC_TYPE, 0x10, struct kgsl_ringbuffer_issueibcmds) + +/* read the most recently executed timestamp value + * type should be a value from enum kgsl_timestamp_type + */ +struct kgsl_cmdstream_readtimestamp { + unsigned int type; + unsigned int timestamp; /*output param */ +}; + +#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD \ + _IOR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) + +#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP \ + _IOWR(KGSL_IOC_TYPE, 0x11, struct kgsl_cmdstream_readtimestamp) + +/* free memory when the GPU reaches a given timestamp. + * gpuaddr specify a memory region created by a + * IOCTL_KGSL_SHAREDMEM_FROM_PMEM call + * type should be a value from enum kgsl_timestamp_type + */ +struct kgsl_cmdstream_freememontimestamp { + unsigned long gpuaddr; + unsigned int type; + unsigned int timestamp; +}; + +#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP \ + _IOW(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) + +/* + * Previous versions of this header had incorrectly defined + * IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP as a read-only ioctl instead + * of a write only ioctl. To ensure binary compatibility, the following + * #define will be used to intercept the incorrect ioctl + */ + +#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD \ + _IOR(KGSL_IOC_TYPE, 0x12, struct kgsl_cmdstream_freememontimestamp) + +/* create a draw context, which is used to preserve GPU state. + * The flags field may contain a mask KGSL_CONTEXT_* values + */ +struct kgsl_drawctxt_create { + unsigned int flags; + unsigned int drawctxt_id; /*output param */ +}; + +#define IOCTL_KGSL_DRAWCTXT_CREATE \ + _IOWR(KGSL_IOC_TYPE, 0x13, struct kgsl_drawctxt_create) + +/* destroy a draw context */ +struct kgsl_drawctxt_destroy { + unsigned int drawctxt_id; +}; + +#define IOCTL_KGSL_DRAWCTXT_DESTROY \ + _IOW(KGSL_IOC_TYPE, 0x14, struct kgsl_drawctxt_destroy) + +/* + * add a block of pmem, fb, ashmem or user allocated address + * into the GPU address space + */ +struct kgsl_map_user_mem { + int fd; + unsigned long gpuaddr; /*output param */ + __kernel_size_t len; + __kernel_size_t offset; + unsigned long hostptr; /*input param */ + enum kgsl_user_mem_type memtype; + unsigned int flags; +}; + +#define IOCTL_KGSL_MAP_USER_MEM \ + _IOWR(KGSL_IOC_TYPE, 0x15, struct kgsl_map_user_mem) + +struct kgsl_cmdstream_readtimestamp_ctxtid { + unsigned int context_id; + unsigned int type; + unsigned int timestamp; /*output param */ +}; + +#define IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID \ + _IOWR(KGSL_IOC_TYPE, 0x16, struct kgsl_cmdstream_readtimestamp_ctxtid) + +struct kgsl_cmdstream_freememontimestamp_ctxtid { + unsigned int context_id; + unsigned long gpuaddr; + unsigned int type; + unsigned int timestamp; +}; + +#define IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID \ + _IOW(KGSL_IOC_TYPE, 0x17, \ + struct kgsl_cmdstream_freememontimestamp_ctxtid) + +/* add a block of pmem or fb into the GPU address space */ +struct kgsl_sharedmem_from_pmem { + int pmem_fd; + unsigned long gpuaddr; /*output param */ + unsigned int len; + unsigned int offset; +}; + +#define IOCTL_KGSL_SHAREDMEM_FROM_PMEM \ + _IOWR(KGSL_IOC_TYPE, 0x20, struct kgsl_sharedmem_from_pmem) + +/* remove memory from the GPU's address space */ +struct kgsl_sharedmem_free { + unsigned long gpuaddr; +}; + +#define IOCTL_KGSL_SHAREDMEM_FREE \ + _IOW(KGSL_IOC_TYPE, 0x21, struct kgsl_sharedmem_free) + +struct kgsl_cff_user_event { + unsigned char cff_opcode; + unsigned int op1; + unsigned int op2; + unsigned int op3; + unsigned int op4; + unsigned int op5; + unsigned int __pad[2]; +}; + +#define IOCTL_KGSL_CFF_USER_EVENT \ + _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_cff_user_event) + +struct kgsl_gmem_desc { + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; + unsigned int pitch; +}; + +struct kgsl_buffer_desc { + void *hostptr; + unsigned long gpuaddr; + int size; + unsigned int format; + unsigned int pitch; + unsigned int enabled; +}; + +struct kgsl_bind_gmem_shadow { + unsigned int drawctxt_id; + struct kgsl_gmem_desc gmem_desc; + unsigned int shadow_x; + unsigned int shadow_y; + struct kgsl_buffer_desc shadow_buffer; + unsigned int buffer_id; +}; + +#define IOCTL_KGSL_DRAWCTXT_BIND_GMEM_SHADOW \ + _IOW(KGSL_IOC_TYPE, 0x22, struct kgsl_bind_gmem_shadow) + +/* add a block of memory into the GPU address space */ + +/* + * IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC deprecated 09/2012 + * use IOCTL_KGSL_GPUMEM_ALLOC instead + */ + +struct kgsl_sharedmem_from_vmalloc { + unsigned long gpuaddr; /*output param */ + unsigned int hostptr; + unsigned int flags; +}; + +#define IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC \ + _IOWR(KGSL_IOC_TYPE, 0x23, struct kgsl_sharedmem_from_vmalloc) + +/* + * This is being deprecated in favor of IOCTL_KGSL_GPUMEM_CACHE_SYNC which + * supports both directions (flush and invalidate). This code will still + * work, but by definition it will do a flush of the cache which might not be + * what you want to have happen on a buffer following a GPU operation. It is + * safer to go with IOCTL_KGSL_GPUMEM_CACHE_SYNC + */ + +#define IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE \ + _IOW(KGSL_IOC_TYPE, 0x24, struct kgsl_sharedmem_free) + +struct kgsl_drawctxt_set_bin_base_offset { + unsigned int drawctxt_id; + unsigned int offset; +}; + +#define IOCTL_KGSL_DRAWCTXT_SET_BIN_BASE_OFFSET \ + _IOW(KGSL_IOC_TYPE, 0x25, struct kgsl_drawctxt_set_bin_base_offset) + +enum kgsl_cmdwindow_type { + KGSL_CMDWINDOW_MIN = 0x00000000, + KGSL_CMDWINDOW_2D = 0x00000000, + KGSL_CMDWINDOW_3D = 0x00000001, /* legacy */ + KGSL_CMDWINDOW_MMU = 0x00000002, + KGSL_CMDWINDOW_ARBITER = 0x000000FF, + KGSL_CMDWINDOW_MAX = 0x000000FF, +}; + +/* write to the command window */ +struct kgsl_cmdwindow_write { + enum kgsl_cmdwindow_type target; + unsigned int addr; + unsigned int data; +}; + +#define IOCTL_KGSL_CMDWINDOW_WRITE \ + _IOW(KGSL_IOC_TYPE, 0x2e, struct kgsl_cmdwindow_write) + +struct kgsl_gpumem_alloc { + unsigned long gpuaddr; /* output param */ + __kernel_size_t size; + unsigned int flags; +}; + +#define IOCTL_KGSL_GPUMEM_ALLOC \ + _IOWR(KGSL_IOC_TYPE, 0x2f, struct kgsl_gpumem_alloc) + +struct kgsl_cff_syncmem { + unsigned long gpuaddr; + __kernel_size_t len; + unsigned int __pad[2]; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_CFF_SYNCMEM \ + _IOW(KGSL_IOC_TYPE, 0x30, struct kgsl_cff_syncmem) + +/* + * A timestamp event allows the user space to register an action following an + * expired timestamp. Note IOCTL_KGSL_TIMESTAMP_EVENT has been redefined to + * _IOWR to support fences which need to return a fd for the priv parameter. + */ + +struct kgsl_timestamp_event { + int type; /* Type of event (see list below) */ + unsigned int timestamp; /* Timestamp to trigger event on */ + unsigned int context_id; /* Context for the timestamp */ + void __user *priv; /* Pointer to the event specific blob */ + __kernel_size_t len; /* Size of the event specific blob */ +}; + +#define IOCTL_KGSL_TIMESTAMP_EVENT_OLD \ + _IOW(KGSL_IOC_TYPE, 0x31, struct kgsl_timestamp_event) + +/* A genlock timestamp event releases an existing lock on timestamp expire */ + +#define KGSL_TIMESTAMP_EVENT_GENLOCK 1 + +struct kgsl_timestamp_event_genlock { + int handle; /* Handle of the genlock lock to release */ +}; + +/* A fence timestamp event releases an existing lock on timestamp expire */ + +#define KGSL_TIMESTAMP_EVENT_FENCE 2 + +struct kgsl_timestamp_event_fence { + int fence_fd; /* Fence to signal */ +}; + +/* + * Set a property within the kernel. Uses the same structure as + * IOCTL_KGSL_GETPROPERTY + */ + +#define IOCTL_KGSL_SETPROPERTY \ + _IOW(KGSL_IOC_TYPE, 0x32, struct kgsl_device_getproperty) + +#define IOCTL_KGSL_TIMESTAMP_EVENT \ + _IOWR(KGSL_IOC_TYPE, 0x33, struct kgsl_timestamp_event) + +/** + * struct kgsl_gpumem_alloc_id - argument to IOCTL_KGSL_GPUMEM_ALLOC_ID + * @id: returned id value for this allocation. + * @flags: mask of KGSL_MEM* values requested and actual flags on return. + * @size: requested size of the allocation and actual size on return. + * @mmapsize: returned size to pass to mmap() which may be larger than 'size' + * @gpuaddr: returned GPU address for the allocation + * + * Allocate memory for access by the GPU. The flags and size fields are echoed + * back by the kernel, so that the caller can know if the request was + * adjusted. + * + * Supported flags: + * KGSL_MEMFLAGS_GPUREADONLY: the GPU will be unable to write to the buffer + * KGSL_MEMTYPE*: usage hint for debugging aid + * KGSL_MEMALIGN*: alignment hint, may be ignored or adjusted by the kernel. + * KGSL_MEMFLAGS_USE_CPU_MAP: If set on call and return, the returned GPU + * address will be 0. Calling mmap() will set the GPU address. + */ +struct kgsl_gpumem_alloc_id { + unsigned int id; + unsigned int flags; + __kernel_size_t size; + __kernel_size_t mmapsize; + unsigned long gpuaddr; +/* private: reserved for future use*/ + unsigned long __pad[2]; +}; + +#define IOCTL_KGSL_GPUMEM_ALLOC_ID \ + _IOWR(KGSL_IOC_TYPE, 0x34, struct kgsl_gpumem_alloc_id) + +/** + * struct kgsl_gpumem_free_id - argument to IOCTL_KGSL_GPUMEM_FREE_ID + * @id: GPU allocation id to free + * + * Free an allocation by id, in case a GPU address has not been assigned or + * is unknown. Freeing an allocation by id with this ioctl or by GPU address + * with IOCTL_KGSL_SHAREDMEM_FREE are equivalent. + */ +struct kgsl_gpumem_free_id { + unsigned int id; +/* private: reserved for future use*/ + unsigned int __pad; +}; + +#define IOCTL_KGSL_GPUMEM_FREE_ID \ + _IOWR(KGSL_IOC_TYPE, 0x35, struct kgsl_gpumem_free_id) + +/** + * struct kgsl_gpumem_get_info - argument to IOCTL_KGSL_GPUMEM_GET_INFO + * @gpuaddr: GPU address to query. Also set on return. + * @id: GPU allocation id to query. Also set on return. + * @flags: returned mask of KGSL_MEM* values. + * @size: returned size of the allocation. + * @mmapsize: returned size to pass mmap(), which may be larger than 'size' + * @useraddr: returned address of the userspace mapping for this buffer + * + * This ioctl allows querying of all user visible attributes of an existing + * allocation, by either the GPU address or the id returned by a previous + * call to IOCTL_KGSL_GPUMEM_ALLOC_ID. Legacy allocation ioctls may not + * return all attributes so this ioctl can be used to look them up if needed. + * + */ +struct kgsl_gpumem_get_info { + unsigned long gpuaddr; + unsigned int id; + unsigned int flags; + __kernel_size_t size; + __kernel_size_t mmapsize; + unsigned long useraddr; +/* private: reserved for future use*/ + unsigned long __pad[4]; +}; + +#define IOCTL_KGSL_GPUMEM_GET_INFO\ + _IOWR(KGSL_IOC_TYPE, 0x36, struct kgsl_gpumem_get_info) + +/** + * struct kgsl_gpumem_sync_cache - argument to IOCTL_KGSL_GPUMEM_SYNC_CACHE + * @gpuaddr: GPU address of the buffer to sync. + * @id: id of the buffer to sync. Either gpuaddr or id is sufficient. + * @op: a mask of KGSL_GPUMEM_CACHE_* values + * @offset: offset into the buffer + * @length: number of bytes starting from offset to perform + * the cache operation on + * + * Sync the L2 cache for memory headed to and from the GPU - this replaces + * KGSL_SHAREDMEM_FLUSH_CACHE since it can handle cache management for both + * directions + * + */ +struct kgsl_gpumem_sync_cache { + unsigned long gpuaddr; + unsigned int id; + unsigned int op; + __kernel_size_t offset; + __kernel_size_t length; +}; + +#define KGSL_GPUMEM_CACHE_CLEAN (1 << 0) +#define KGSL_GPUMEM_CACHE_TO_GPU KGSL_GPUMEM_CACHE_CLEAN + +#define KGSL_GPUMEM_CACHE_INV (1 << 1) +#define KGSL_GPUMEM_CACHE_FROM_GPU KGSL_GPUMEM_CACHE_INV + +#define KGSL_GPUMEM_CACHE_FLUSH \ + (KGSL_GPUMEM_CACHE_CLEAN | KGSL_GPUMEM_CACHE_INV) + +/* Flag to ensure backwards compatibility of kgsl_gpumem_sync_cache struct */ +#define KGSL_GPUMEM_CACHE_RANGE (1 << 31U) + +#define IOCTL_KGSL_GPUMEM_SYNC_CACHE \ + _IOW(KGSL_IOC_TYPE, 0x37, struct kgsl_gpumem_sync_cache) + +/** + * struct kgsl_perfcounter_get - argument to IOCTL_KGSL_PERFCOUNTER_GET + * @groupid: Performance counter group ID + * @countable: Countable to select within the group + * @offset: Return offset of the reserved LO counter + * @offset_hi: Return offset of the reserved HI counter + * + * Get an available performance counter from a specified groupid. The offset + * of the performance counter will be returned after successfully assigning + * the countable to the counter for the specified group. An error will be + * returned and an offset of 0 if the groupid is invalid or there are no + * more counters left. After successfully getting a perfcounter, the user + * must call kgsl_perfcounter_put(groupid, contable) when finished with + * the perfcounter to clear up perfcounter resources. + * + */ +struct kgsl_perfcounter_get { + unsigned int groupid; + unsigned int countable; + unsigned int offset; + unsigned int offset_hi; +/* private: reserved for future use */ + unsigned int __pad; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_PERFCOUNTER_GET \ + _IOWR(KGSL_IOC_TYPE, 0x38, struct kgsl_perfcounter_get) + +/** + * struct kgsl_perfcounter_put - argument to IOCTL_KGSL_PERFCOUNTER_PUT + * @groupid: Performance counter group ID + * @countable: Countable to release within the group + * + * Put an allocated performance counter to allow others to have access to the + * resource that was previously taken. This is only to be called after + * successfully getting a performance counter from kgsl_perfcounter_get(). + * + */ +struct kgsl_perfcounter_put { + unsigned int groupid; + unsigned int countable; +/* private: reserved for future use */ + unsigned int __pad[2]; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_PERFCOUNTER_PUT \ + _IOW(KGSL_IOC_TYPE, 0x39, struct kgsl_perfcounter_put) + +/** + * struct kgsl_perfcounter_query - argument to IOCTL_KGSL_PERFCOUNTER_QUERY + * @groupid: Performance counter group ID + * @countable: Return active countables array + * @size: Size of active countables array + * @max_counters: Return total number counters for the group ID + * + * Query the available performance counters given a groupid. The array + * *countables is used to return the current active countables in counters. + * The size of the array is passed in so the kernel will only write at most + * size or counter->size for the group id. The total number of available + * counters for the group ID is returned in max_counters. + * If the array or size passed in are invalid, then only the maximum number + * of counters will be returned, no data will be written to *countables. + * If the groupid is invalid an error code will be returned. + * + */ +struct kgsl_perfcounter_query { + unsigned int groupid; + /* Array to return the current countable for up to size counters */ + unsigned int __user *countables; + unsigned int count; + unsigned int max_counters; +/* private: reserved for future use */ + unsigned int __pad[2]; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_PERFCOUNTER_QUERY \ + _IOWR(KGSL_IOC_TYPE, 0x3A, struct kgsl_perfcounter_query) + +/** + * struct kgsl_perfcounter_query - argument to IOCTL_KGSL_PERFCOUNTER_QUERY + * @groupid: Performance counter group IDs + * @countable: Performance counter countable IDs + * @value: Return performance counter reads + * @size: Size of all arrays (groupid/countable pair and return value) + * + * Read in the current value of a performance counter given by the groupid + * and countable. + * + */ + +struct kgsl_perfcounter_read_group { + unsigned int groupid; + unsigned int countable; + unsigned long long value; +}; + +struct kgsl_perfcounter_read { + struct kgsl_perfcounter_read_group __user *reads; + unsigned int count; +/* private: reserved for future use */ + unsigned int __pad[2]; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_PERFCOUNTER_READ \ + _IOWR(KGSL_IOC_TYPE, 0x3B, struct kgsl_perfcounter_read) +/* + * struct kgsl_gpumem_sync_cache_bulk - argument to + * IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK + * @id_list: list of GPU buffer ids of the buffers to sync + * @count: number of GPU buffer ids in id_list + * @op: a mask of KGSL_GPUMEM_CACHE_* values + * + * Sync the cache for memory headed to and from the GPU. Certain + * optimizations can be made on the cache operation based on the total + * size of the working set of memory to be managed. + */ +struct kgsl_gpumem_sync_cache_bulk { + unsigned int __user *id_list; + unsigned int count; + unsigned int op; +/* private: reserved for future use */ + unsigned int __pad[2]; /* For future binary compatibility */ +}; + +#define IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK \ + _IOWR(KGSL_IOC_TYPE, 0x3C, struct kgsl_gpumem_sync_cache_bulk) + +/* + * struct kgsl_cmd_syncpoint_timestamp + * @context_id: ID of a KGSL context + * @timestamp: GPU timestamp + * + * This structure defines a syncpoint comprising a context/timestamp pair. A + * list of these may be passed by IOCTL_KGSL_SUBMIT_COMMANDS to define + * dependencies that must be met before the command can be submitted to the + * hardware + */ +struct kgsl_cmd_syncpoint_timestamp { + unsigned int context_id; + unsigned int timestamp; +}; + +struct kgsl_cmd_syncpoint_fence { + int fd; +}; + +/* + * struct kgsl_cmd_syncpoint_timeline + * @timelines: Address of an array of &struct kgsl_timeline_val + * @count: Number of entries in @timelines + * @timelines_size: Size of each entry in @timelines + * + * Define a syncpoint for a number of timelines. This syncpoint will + * be satisfied when all of the specified timelines are signaled. + */ +struct kgsl_cmd_syncpoint_timeline { + __u64 timelines; + __u32 count; + __u32 timelines_size; +}; + +/** + * struct kgsl_cmd_syncpoint - Define a sync point for a command batch + * @type: type of sync point defined here + * @priv: Pointer to the type specific buffer + * @size: Size of the type specific buffer + * + * This structure contains pointers defining a specific command sync point. + * The pointer and size should point to a type appropriate structure. + */ +struct kgsl_cmd_syncpoint { + int type; + void __user *priv; + __kernel_size_t size; +}; + +/* Flag to indicate that the cmdlist may contain memlists */ +#define KGSL_IBDESC_MEMLIST 0x1 + +/* Flag to point out the cmdbatch profiling buffer in the memlist */ +#define KGSL_IBDESC_PROFILING_BUFFER 0x2 + +/** + * struct kgsl_submit_commands - Argument to IOCTL_KGSL_SUBMIT_COMMANDS + * @context_id: KGSL context ID that owns the commands + * @flags: + * @cmdlist: User pointer to a list of kgsl_ibdesc structures + * @numcmds: Number of commands listed in cmdlist + * @synclist: User pointer to a list of kgsl_cmd_syncpoint structures + * @numsyncs: Number of sync points listed in synclist + * @timestamp: On entry the a user defined timestamp, on exist the timestamp + * assigned to the command batch + * + * This structure specifies a command to send to the GPU hardware. This is + * similar to kgsl_issueibcmds expect that it doesn't support the legacy way to + * submit IB lists and it adds sync points to block the IB until the + * dependencies are satisified. This entry point is the new and preferred way + * to submit commands to the GPU. The memory list can be used to specify all + * memory that is referrenced in the current set of commands. + */ + +struct kgsl_submit_commands { + unsigned int context_id; + unsigned int flags; + struct kgsl_ibdesc __user *cmdlist; + unsigned int numcmds; + struct kgsl_cmd_syncpoint __user *synclist; + unsigned int numsyncs; + unsigned int timestamp; +/* private: reserved for future use */ + unsigned int __pad[4]; +}; + +#define IOCTL_KGSL_SUBMIT_COMMANDS \ + _IOWR(KGSL_IOC_TYPE, 0x3D, struct kgsl_submit_commands) + +/** + * struct kgsl_device_constraint - device constraint argument + * @context_id: KGSL context ID + * @type: type of constraint i.e pwrlevel/none + * @data: constraint data + * @size: size of the constraint data + */ +struct kgsl_device_constraint { + unsigned int type; + unsigned int context_id; + void __user *data; + __kernel_size_t size; +}; + +/* Constraint Type*/ +#define KGSL_CONSTRAINT_NONE 0 +#define KGSL_CONSTRAINT_PWRLEVEL 1 + +/* L3 constraint Type */ +#define KGSL_CONSTRAINT_L3_NONE 2 +#define KGSL_CONSTRAINT_L3_PWRLEVEL 3 + +/* PWRLEVEL constraint level*/ +/* set to min frequency */ +#define KGSL_CONSTRAINT_PWR_MIN 0 +/* set to max frequency */ +#define KGSL_CONSTRAINT_PWR_MAX 1 + +struct kgsl_device_constraint_pwrlevel { + unsigned int level; +}; + +/** + * struct kgsl_syncsource_create - Argument to IOCTL_KGSL_SYNCSOURCE_CREATE + * @id: returned id for the syncsource that was created. + * + * This ioctl creates a userspace sync timeline. + */ + +struct kgsl_syncsource_create { + unsigned int id; +/* private: reserved for future use */ + unsigned int __pad[3]; +}; + +#define IOCTL_KGSL_SYNCSOURCE_CREATE \ + _IOWR(KGSL_IOC_TYPE, 0x40, struct kgsl_syncsource_create) + +/** + * struct kgsl_syncsource_destroy - Argument to IOCTL_KGSL_SYNCSOURCE_DESTROY + * @id: syncsource id to destroy + * + * This ioctl creates a userspace sync timeline. + */ + +struct kgsl_syncsource_destroy { + unsigned int id; +/* private: reserved for future use */ + unsigned int __pad[3]; +}; + +#define IOCTL_KGSL_SYNCSOURCE_DESTROY \ + _IOWR(KGSL_IOC_TYPE, 0x41, struct kgsl_syncsource_destroy) + +/** + * struct kgsl_syncsource_create_fence - Argument to + * IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE + * @id: syncsource id + * @fence_fd: returned sync_fence fd + * + * Create a fence that may be signaled by userspace by calling + * IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE. There are no order dependencies between + * these fences. + */ +struct kgsl_syncsource_create_fence { + unsigned int id; + int fence_fd; +/* private: reserved for future use */ + unsigned int __pad[4]; +}; + +/** + * struct kgsl_syncsource_signal_fence - Argument to + * IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE + * @id: syncsource id + * @fence_fd: sync_fence fd to signal + * + * Signal a fence that was created by a IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE + * call using the same syncsource id. This allows a fence to be shared + * to other processes but only signaled by the process owning the fd + * used to create the fence. + */ +#define IOCTL_KGSL_SYNCSOURCE_CREATE_FENCE \ + _IOWR(KGSL_IOC_TYPE, 0x42, struct kgsl_syncsource_create_fence) + +struct kgsl_syncsource_signal_fence { + unsigned int id; + int fence_fd; +/* private: reserved for future use */ + unsigned int __pad[4]; +}; + +#define IOCTL_KGSL_SYNCSOURCE_SIGNAL_FENCE \ + _IOWR(KGSL_IOC_TYPE, 0x43, struct kgsl_syncsource_signal_fence) + +/** + * struct kgsl_cff_sync_gpuobj - Argument to IOCTL_KGSL_CFF_SYNC_GPUOBJ + * @offset: Offset into the GPU object to sync + * @length: Number of bytes to sync + * @id: ID of the GPU object to sync + */ +struct kgsl_cff_sync_gpuobj { + __u64 offset; + __u64 length; + unsigned int id; +}; + +#define IOCTL_KGSL_CFF_SYNC_GPUOBJ \ + _IOW(KGSL_IOC_TYPE, 0x44, struct kgsl_cff_sync_gpuobj) + +/** + * struct kgsl_gpuobj_alloc - Argument to IOCTL_KGSL_GPUOBJ_ALLOC + * @size: Size in bytes of the object to allocate + * @flags: mask of KGSL_MEMFLAG_* bits + * @va_len: Size in bytes of the virtual region to allocate + * @mmapsize: Returns the mmap() size of the object + * @id: Returns the GPU object ID of the new object + * @metadata_len: Length of the metdata to copy from the user + * @metadata: Pointer to the user specified metadata to store for the object + */ +struct kgsl_gpuobj_alloc { + __u64 size; + __u64 flags; + __u64 va_len; + __u64 mmapsize; + unsigned int id; + unsigned int metadata_len; + __u64 metadata; +}; + +/* Let the user know that this header supports the gpuobj metadata */ +#define KGSL_GPUOBJ_ALLOC_METADATA_MAX 64 + +#define IOCTL_KGSL_GPUOBJ_ALLOC \ + _IOWR(KGSL_IOC_TYPE, 0x45, struct kgsl_gpuobj_alloc) + +/** + * struct kgsl_gpuobj_free - Argument to IOCTL_KGLS_GPUOBJ_FREE + * @flags: Mask of: KGSL_GUPOBJ_FREE_ON_EVENT + * @priv: Pointer to the private object if KGSL_GPUOBJ_FREE_ON_EVENT is + * specified + * @id: ID of the GPU object to free + * @type: If KGSL_GPUOBJ_FREE_ON_EVENT is specified, the type of asynchronous + * event to free on + * @len: Length of the data passed in priv + */ +struct kgsl_gpuobj_free { + __u64 flags; + __u64 __user priv; + unsigned int id; + unsigned int type; + unsigned int len; +}; + +#define KGSL_GPUOBJ_FREE_ON_EVENT 1 + +#define KGSL_GPU_EVENT_TIMESTAMP 1 +#define KGSL_GPU_EVENT_FENCE 2 + +/** + * struct kgsl_gpu_event_timestamp - Specifies a timestamp event to free a GPU + * object on + * @context_id: ID of the timestamp event to wait for + * @timestamp: Timestamp of the timestamp event to wait for + */ +struct kgsl_gpu_event_timestamp { + unsigned int context_id; + unsigned int timestamp; +}; + +/** + * struct kgsl_gpu_event_fence - Specifies a fence ID to to free a GPU object on + * @fd: File descriptor for the fence + */ +struct kgsl_gpu_event_fence { + int fd; +}; + +#define IOCTL_KGSL_GPUOBJ_FREE \ + _IOW(KGSL_IOC_TYPE, 0x46, struct kgsl_gpuobj_free) + +/** + * struct kgsl_gpuobj_info - argument to IOCTL_KGSL_GPUOBJ_INFO + * @gpuaddr: GPU address of the object + * @flags: Current flags for the object + * @size: Size of the object + * @va_len: VA size of the object + * @va_addr: Virtual address of the object (if it is mapped) + * id - GPU object ID of the object to query + */ +struct kgsl_gpuobj_info { + __u64 gpuaddr; + __u64 flags; + __u64 size; + __u64 va_len; + __u64 va_addr; + unsigned int id; +}; + +#define IOCTL_KGSL_GPUOBJ_INFO \ + _IOWR(KGSL_IOC_TYPE, 0x47, struct kgsl_gpuobj_info) + + +/** + * struct kgsl_gpuobj_import - argument to IOCTL_KGSL_GPUOBJ_IMPORT + * @priv: Pointer to the private data for the import type + * @priv_len: Length of the private data + * @flags: Mask of KGSL_MEMFLAG_ flags + * @type: Type of the import (KGSL_USER_MEM_TYPE_*) + * @id: Returns the ID of the new GPU object + */ +struct kgsl_gpuobj_import { + __u64 __user priv; + __u64 priv_len; + __u64 flags; + unsigned int type; + unsigned int id; +}; + +/** + * struct kgsl_gpuobj_import_dma_buf - import a dmabuf object + * @fd: File descriptor for the dma-buf object + */ +struct kgsl_gpuobj_import_dma_buf { + int fd; +}; + +/** + * struct kgsl_gpuobj_import_useraddr - import an object based on a useraddr + * @virtaddr: Virtual address of the object to import + */ +struct kgsl_gpuobj_import_useraddr { + __u64 virtaddr; +}; + +#define IOCTL_KGSL_GPUOBJ_IMPORT \ + _IOWR(KGSL_IOC_TYPE, 0x48, struct kgsl_gpuobj_import) + +/** + * struct kgsl_gpuobj_sync_obj - Individual GPU object to sync + * @offset: Offset within the GPU object to sync + * @length: Number of bytes to sync + * @id: ID of the GPU object to sync + * @op: Cache operation to execute + */ + +struct kgsl_gpuobj_sync_obj { + __u64 offset; + __u64 length; + unsigned int id; + unsigned int op; +}; + +/** + * struct kgsl_gpuobj_sync - Argument for IOCTL_KGSL_GPUOBJ_SYNC + * @objs: Pointer to an array of kgsl_gpuobj_sync_obj structs + * @obj_len: Size of each item in the array + * @count: Number of items in the array + */ + +struct kgsl_gpuobj_sync { + __u64 __user objs; + unsigned int obj_len; + unsigned int count; +}; + +#define IOCTL_KGSL_GPUOBJ_SYNC \ + _IOW(KGSL_IOC_TYPE, 0x49, struct kgsl_gpuobj_sync) + +/** + * struct kgsl_command_object - GPU command object + * @offset: GPU address offset of the object + * @gpuaddr: GPU address of the object + * @size: Size of the object + * @flags: Current flags for the object + * @id - GPU command object ID + */ +struct kgsl_command_object { + __u64 offset; + __u64 gpuaddr; + __u64 size; + unsigned int flags; + unsigned int id; +}; + +/** + * struct kgsl_command_syncpoint - GPU syncpoint object + * @priv: Pointer to the type specific buffer + * @size: Size of the type specific buffer + * @type: type of sync point defined here + */ +struct kgsl_command_syncpoint { + __u64 __user priv; + __u64 size; + unsigned int type; +}; + +/** + * struct kgsl_command_object - Argument for IOCTL_KGSL_GPU_COMMAND + * @flags: Current flags for the object + * @cmdlist: List of kgsl_command_objects for submission + * @cmd_size: Size of kgsl_command_objects structure + * @numcmds: Number of kgsl_command_objects in command list + * @objlist: List of kgsl_command_objects for tracking + * @obj_size: Size of kgsl_command_objects structure + * @numobjs: Number of kgsl_command_objects in object list + * @synclist: List of kgsl_command_syncpoints + * @sync_size: Size of kgsl_command_syncpoint structure + * @numsyncs: Number of kgsl_command_syncpoints in syncpoint list + * @context_id: Context ID submittin ghte kgsl_gpu_command + * @timestamp: Timestamp for the submitted commands + */ +struct kgsl_gpu_command { + __u64 flags; + __u64 __user cmdlist; + unsigned int cmdsize; + unsigned int numcmds; + __u64 __user objlist; + unsigned int objsize; + unsigned int numobjs; + __u64 __user synclist; + unsigned int syncsize; + unsigned int numsyncs; + unsigned int context_id; + unsigned int timestamp; +}; + +#define IOCTL_KGSL_GPU_COMMAND \ + _IOWR(KGSL_IOC_TYPE, 0x4A, struct kgsl_gpu_command) + +/** + * struct kgsl_preemption_counters_query - argument to + * IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY + * @counters: Return preemption counters array + * @size_user: Size allocated by userspace + * @size_priority_level: Size of preemption counters for each + * priority level + * @max_priority_level: Return max number of priority levels + * + * Query the available preemption counters. The array counters + * is used to return preemption counters. The size of the array + * is passed in so the kernel will only write at most size_user + * or max available preemption counters. The total number of + * preemption counters is returned in max_priority_level. If the + * array or size passed in are invalid, then an error is + * returned back. + */ +struct kgsl_preemption_counters_query { + __u64 __user counters; + unsigned int size_user; + unsigned int size_priority_level; + unsigned int max_priority_level; +}; + +#define IOCTL_KGSL_PREEMPTIONCOUNTER_QUERY \ + _IOWR(KGSL_IOC_TYPE, 0x4B, struct kgsl_preemption_counters_query) + +/** + * struct kgsl_gpuobj_set_info - argument for IOCTL_KGSL_GPUOBJ_SET_INFO + * @flags: Flags to indicate which parameters to change + * @metadata: If KGSL_GPUOBJ_SET_INFO_METADATA is set, a pointer to the new + * metadata + * @id: GPU memory object ID to change + * @metadata_len: If KGSL_GPUOBJ_SET_INFO_METADATA is set, the length of the + * new metadata string + * @type: If KGSL_GPUOBJ_SET_INFO_TYPE is set, the new type of the memory object + */ + +#define KGSL_GPUOBJ_SET_INFO_METADATA (1 << 0) +#define KGSL_GPUOBJ_SET_INFO_TYPE (1 << 1) + +struct kgsl_gpuobj_set_info { + __u64 flags; + __u64 metadata; + unsigned int id; + unsigned int metadata_len; + unsigned int type; +}; + +#define IOCTL_KGSL_GPUOBJ_SET_INFO \ + _IOW(KGSL_IOC_TYPE, 0x4C, struct kgsl_gpuobj_set_info) + +/** + * struct kgsl_sparse_phys_alloc - Argument for IOCTL_KGSL_SPARSE_PHYS_ALLOC + * @size: Size in bytes to back + * @pagesize: Pagesize alignment required + * @flags: Flags for this allocation + * @id: Returned ID for this allocation + */ +struct kgsl_sparse_phys_alloc { + __u64 size; + __u64 pagesize; + __u64 flags; + unsigned int id; +}; + +#define IOCTL_KGSL_SPARSE_PHYS_ALLOC \ + _IOWR(KGSL_IOC_TYPE, 0x50, struct kgsl_sparse_phys_alloc) + +/** + * struct kgsl_sparse_phys_free - Argument for IOCTL_KGSL_SPARSE_PHYS_FREE + * @id: ID to free + */ +struct kgsl_sparse_phys_free { + unsigned int id; +}; + +#define IOCTL_KGSL_SPARSE_PHYS_FREE \ + _IOW(KGSL_IOC_TYPE, 0x51, struct kgsl_sparse_phys_free) + +/** + * struct kgsl_sparse_virt_alloc - Argument for IOCTL_KGSL_SPARSE_VIRT_ALLOC + * @size: Size in bytes to reserve + * @pagesize: Pagesize alignment required + * @flags: Flags for this allocation + * @id: Returned ID for this allocation + * @gpuaddr: Returned GPU address for this allocation + */ +struct kgsl_sparse_virt_alloc { + __u64 size; + __u64 pagesize; + __u64 flags; + __u64 gpuaddr; + unsigned int id; +}; + +#define IOCTL_KGSL_SPARSE_VIRT_ALLOC \ + _IOWR(KGSL_IOC_TYPE, 0x52, struct kgsl_sparse_virt_alloc) + +/** + * struct kgsl_sparse_virt_free - Argument for IOCTL_KGSL_SPARSE_VIRT_FREE + * @id: ID to free + */ +struct kgsl_sparse_virt_free { + unsigned int id; +}; + +#define IOCTL_KGSL_SPARSE_VIRT_FREE \ + _IOW(KGSL_IOC_TYPE, 0x53, struct kgsl_sparse_virt_free) + +/** + * struct kgsl_sparse_binding_object - Argument for kgsl_sparse_bind + * @virtoffset: Offset into the virtual ID + * @physoffset: Offset into the physical ID (bind only) + * @size: Size in bytes to reserve + * @flags: Flags for this kgsl_sparse_binding_object + * @id: Physical ID to bind (bind only) + */ +struct kgsl_sparse_binding_object { + __u64 virtoffset; + __u64 physoffset; + __u64 size; + __u64 flags; + unsigned int id; +}; + +/** + * struct kgsl_sparse_bind - Argument for IOCTL_KGSL_SPARSE_BIND + * @list: List of kgsl_sparse_bind_objects to bind/unbind + * @id: Virtual ID to bind/unbind + * @size: Size of kgsl_sparse_bind_object + * @count: Number of elements in list + * + */ +struct kgsl_sparse_bind { + __u64 __user list; + unsigned int id; + unsigned int size; + unsigned int count; +}; + +#define IOCTL_KGSL_SPARSE_BIND \ + _IOW(KGSL_IOC_TYPE, 0x54, struct kgsl_sparse_bind) + +/** + * struct kgsl_gpu_sparse_command - Argument for + * IOCTL_KGSL_GPU_SPARSE_COMMAND + * @flags: Current flags for the object + * @sparselist: List of kgsl_sparse_binding_object to bind/unbind + * @synclist: List of kgsl_command_syncpoints + * @sparsesize: Size of kgsl_sparse_binding_object + * @numsparse: Number of elements in list + * @sync_size: Size of kgsl_command_syncpoint structure + * @numsyncs: Number of kgsl_command_syncpoints in syncpoint list + * @context_id: Context ID submitting the kgsl_gpu_command + * @timestamp: Timestamp for the submitted commands + * @id: Virtual ID to bind/unbind + */ +struct kgsl_gpu_sparse_command { + __u64 flags; + __u64 __user sparselist; + __u64 __user synclist; + unsigned int sparsesize; + unsigned int numsparse; + unsigned int syncsize; + unsigned int numsyncs; + unsigned int context_id; + unsigned int timestamp; + unsigned int id; +}; + +#define IOCTL_KGSL_GPU_SPARSE_COMMAND \ + _IOWR(KGSL_IOC_TYPE, 0x55, struct kgsl_gpu_sparse_command) + +#define KGSL_GPUMEM_RANGE_OP_BIND 1 +#define KGSL_GPUMEM_RANGE_OP_UNBIND 2 + +/** + * struct kgsl_gpumem_bind_range - specifies a bind operation for a virtual + * buffer object + * @child_offset: Offset to the start of memory within the child buffer object + * (not used for KGSL_GPUMEM_RANGE_OP_UNBIND operations) + * @target_offset: GPU address offset within the target VBO + * @length: Amount of memory to map/unmap (in bytes) + * @child_id: The GPU buffer ID for the child object to map/unmap in the VBO + * @op: One of KGSL_GPUMEM_RANGE_OP_BIND or KGSL_GPUMEM_RANGE_OP_UNBIND + * + * This defines a specific bind operation to a virtual buffer object specified + * in &struct kgsl_gpumem_bind_ranges. When @op is KGSL_GPUMEM_RANGE_OP_BIND the + * physical memory starting at @child_offset in the memory object identified by + * @child_id will be mapped into the target virtual buffer object starting at + * @offset for @length bytes. + * + * When @op is KGSL_GPUMEM_RANGE_OP_UNBIND any entries in the target virtual + * buffer object between @offset and @length that belong to @child_id will be + * removed. + */ +struct kgsl_gpumem_bind_range { + __u64 child_offset; + __u64 target_offset; + __u64 length; + __u32 child_id; + __u32 op; +}; + +#define KGSL_GPUMEM_BIND_ASYNC (1UL << 0) +#define KGSL_GPUMEM_BIND_FENCE_OUT (1UL << 1) + +/** + * struct kgsl_gpumem_bind_ranges - Argument to IOCTL_KGSL_GPUMEM_BIND_RANGES to + * either map or unmap a child buffer object into a virtual buffer object. + * @ranges: User memory pointer to an array of range operations of type &struct + * kgsl_gpumem_bind_range + * @ranges_nents: Number of entries in @ranges + * @ranges_size: Size of each entry in @ranges in bytes + * @id: GPU buffer object identifier for the target virtual buffer object + * @flags: Bitmap of KGSL_GPUMEM_BIND_ASYNC and KGSL_GPUMEM_BIND_FENCE_OUT + * @fence_id: If KGSL_GPUMEM_BIND_FENCE_OUT is set in @flags contains the + * identifier for the sync fence that will be signaled after the operation + * completes + * + * Describes a number of range operations to perform on a virtual buffer object + * identified by @id. Ranges should be a __u64 representation of an array of + * &struct kgsl_gpumem_bind_range entries. @ranges_nents will contain the number + * of entries in the array, and @ranges_size will contain the size of each entry + * in the array. If KGSL_GPUMEM_BIND_ASYNC is set the operation will be + * performed asynchronously and the operation will immediately return to the + * user. Otherwise the calling context will block until the operation has + * completed. + * + * If KGSL_GPUMEM_BIND_ASYNC and KGSL_GPUMEM_BIND_FENCE_OUT are both set a sync + * fence will be created and returned in @fence_id. The fence will be signaled + * when the bind operation has completed. + */ +struct kgsl_gpumem_bind_ranges { + __u64 ranges; + __u32 ranges_nents; + __u32 ranges_size; + __u32 id; + __u32 flags; + int fence_id; + /* private: 64 bit compatibility */ + __u32 padding; +}; + +#define IOCTL_KGSL_GPUMEM_BIND_RANGES \ + _IOWR(KGSL_IOC_TYPE, 0x56, struct kgsl_gpumem_bind_ranges) + +#define KGSL_GPU_AUX_COMMAND_BIND (1 << 0) +#define KGSL_GPU_AUX_COMMAND_TIMELINE (1 << 1) +/* Reuse the same flag that GPU COMMAND uses */ +#define KGSL_GPU_AUX_COMMAND_SYNC KGSL_CMDBATCH_SYNC + +/** + * struct kgsl_gpu_aux_command_bind - Descriptor for a GPU AUX bind command + * @rangeslist: Pointer to a list of &struct kgsl_gpumem_bind_range items + * @numranges Number of entries in @rangeslist + * @rangesize: Size of each entry in @rangeslist + * @target: The GPU memory ID for the target virtual buffer object + * + * Describe a GPU AUX command to bind ranges in a virtual buffer object. + * @rangeslist points to a &struct kgsl_gpumem_bind_ranges which is the same + * struct that is used by IOCTl_KGSL_GPUMEM_BIND_RANGES. @numrages is the size + * of the array in @rangeslist and @rangesize is the size of each entity in + * @rangeslist. @target points to the GPU ID for the target VBO object. + */ +struct kgsl_gpu_aux_command_bind { + __u64 rangeslist; + __u64 numranges; + __u64 rangesize; + __u32 target; +/* private: Padding for 64 bit compatibility */ + __u32 padding; +}; + +/** + * struct kgsl_aux_command_generic - Container for an AUX command + * @priv: Pointer to the type specific buffer + * @size: Size of the type specific buffer + * @type: type of sync point defined here + * + * Describes a generic container for GPU aux commands. @priv is a user pointer + * to the command struct matching @type of size @size. + */ +struct kgsl_gpu_aux_command_generic { + __u64 priv; + __u64 size; + __u32 type; +/* private: Padding for 64 bit compatibility */ + __u32 padding; +}; + +/** + * struct kgsl_gpu_aux_command - Argument for IOCTL_KGSL_GPU_AUX_COMMAND + * @flags: flags for the object + * @cmdlist: List of &struct kgsl_gpu_aux_command_generic objects + * @cmd_size: Size of each entry in @cmdlist + * @numcmds: Number of entries in @cmdlist + * @synclist: List of &struct kgsl_command_syncpoint objects + * @syncsize: Size of each entry in @synclist + * @numsyncs: Number of entries in @synclist + * @context_id: ID of the context submtting the aux command + * @timestamp: Timestamp for the command submission + * + * Describe a GPU auxiliary command. Auxiliary commands are tasks that are not + * performed on hardware but can be queued like normal GPU commands. Like GPU + * commands AUX commands are assigned a timestamp and processed in order in the + * queue. They can also have standard sync objects attached. The only + * difference is that AUX commands usually perform some sort of administrative + * task in the CPU and are retired in the dispatcher. + * + * For bind operations flags must have one of the KGSL_GPU_AUX_COMMAND_* flags + * set. If sync objects are attached KGSL_GPU_AUX_COMMAND_SYNC must be set. + * @cmdlist points to an array of &struct kgsl_gpu_aux_command_generic structs + * which in turn will have a pointer to a specific command type. + * @numcmds is the number of commands in the list and @cmdsize is the size + * of each entity in @cmdlist. + * + * If KGSL_GPU_AUX_COMMAND_SYNC is specified @synclist will point to an array of + * &struct kgsl_command_syncpoint items in the same fashion as a GPU hardware + * command. @numsyncs and @syncsize describe the list. + * + * @context_id is the context that is submitting the command and @timestamp + * contains the timestamp for the operation. + */ +struct kgsl_gpu_aux_command { + __u64 flags; + __u64 cmdlist; + __u32 cmdsize; + __u32 numcmds; + __u64 synclist; + __u32 syncsize; + __u32 numsyncs; + __u32 context_id; + __u32 timestamp; +}; + +#define IOCTL_KGSL_GPU_AUX_COMMAND \ + _IOWR(KGSL_IOC_TYPE, 0x57, struct kgsl_gpu_aux_command) + +/** + * struct kgsl_timeline_create - Argument for IOCTL_KGSL_TIMELINE_CREATE + * @seqno: Initial sequence number for the timeline + * @id: Timeline identifier [out] + * + * Create a new semaphore timeline and return the identifier in @id. + * The identifier is global for the device and can be used to + * identify the timeline in all subsequent commands. + */ +struct kgsl_timeline_create { + __u64 seqno; + __u32 id; +/* private: padding for 64 bit compatibility */ + __u32 padding; +}; + +#define IOCTL_KGSL_TIMELINE_CREATE \ + _IOWR(KGSL_IOC_TYPE, 0x58, struct kgsl_timeline_create) + +/** + * struct kgsl_timeline_val - A container to store a timeline/sequence number + * pair. + * @seqno: Sequence number to signal/query + * @timeline: The timeline identifier to signal/query + * + * A container to store a timeline/seqno pair used by the query and signal + * ioctls. + */ +struct kgsl_timeline_val { + __u64 seqno; + __u32 timeline; +/* private: padding for 64 bit compatibility */ + __u32 padding; +}; + +#define KGSL_TIMELINE_WAIT_ALL 1 +#define KGSL_TIMELINE_WAIT_ANY 2 + +/** + * struct kgsl_timeline_wait - Argument for IOCTL_KGSL_TIMELINE_WAIT + * @tv_sec: Number of seconds to wait for the signal + * @tv_nsec: Number of nanoseconds to wait for the signal + * @timelines: Address of an array of &struct kgsl_timeline_val entries + * @count: Number of entries in @timeline + * @timelines_size: Size of each entry in @timelines + * @flags: One of KGSL_TIMELINE_WAIT_ALL or KGSL_TIMELINE_WAIT_ANY + * + * Wait for the timelines listed in @timelines to be signaled. If @flags is + * equal to KGSL_TIMELINE_WAIT_ALL then wait for all timelines or if + * KGSL_TIMELINE_WAIT_ANY is specified then wait for any of the timelines to + * signal. @tv_sec and @tv_nsec indicates the number of seconds and nanoseconds + * that the process should be blocked waiting for the signal. + */ +struct kgsl_timeline_wait { + __s64 tv_sec; + __s64 tv_nsec; + __u64 timelines; + __u32 count; + __u32 timelines_size; + __u32 flags; +/* private: padding for 64 bit compatibility */ + __u32 padding; +}; + +#define IOCTL_KGSL_TIMELINE_WAIT \ + _IOW(KGSL_IOC_TYPE, 0x59, struct kgsl_timeline_wait) + +#define IOCTL_KGSL_TIMELINE_QUERY \ + _IOWR(KGSL_IOC_TYPE, 0x5A, struct kgsl_timeline_val) + +/** + * struct kgsl_timeline_signal - argument for IOCTL_KGSL_TIMELINE_SIGNAL + * @timelines: Address of an array of &struct kgsl_timeline_val entries + * @count: Number of entries in @timelines + * @timelines_size: Size of each entry in @timelines + * + * Signal an array of timelines of type @struct kgsl_timeline_val. + */ +struct kgsl_timeline_signal { + __u64 timelines; + __u32 count; + __u32 timelines_size; +}; + +#define IOCTL_KGSL_TIMELINE_SIGNAL \ + _IOW(KGSL_IOC_TYPE, 0x5B, struct kgsl_timeline_signal) + +/** + * struct kgsl_timeline_fence_get - argument for IOCTL_KGSL_TIMELINE_FENCE_GET + * @seqno: Sequence number for the fence + * @timeline: Timeline to create the fence on + * @handle: Contains the fence fd for a successful operation [out] + * + * Create a sync file descriptor for the seqnum on the timeline and return it in + * @handle. Can be polled and queried just like any other sync file descriptor + */ +struct kgsl_timeline_fence_get { + __u64 seqno; + __u32 timeline; + int handle; +}; + +#define IOCTL_KGSL_TIMELINE_FENCE_GET \ + _IOWR(KGSL_IOC_TYPE, 0x5C, struct kgsl_timeline_fence_get) +/** + * IOCTL_KGSL_TIMELINE_DESTROY takes a u32 identifier for the timeline to + * destroy + */ +#define IOCTL_KGSL_TIMELINE_DESTROY _IOW(KGSL_IOC_TYPE, 0x5D, __u32) + +/** + * struct kgsl_gpu_aux_command_timeline - An aux command for timeline signals + * @timelines: An array of &struct kgsl_timeline_val elements + * @count: The number of entries in @timelines + * @timelines_size: The size of each element in @timelines + * + * An aux command for timeline signals that can be pointed to by + * &struct kgsl_aux_command_generic when the type is + * KGSL_GPU_AUX_COMMAND_TIMELINE. + */ +struct kgsl_gpu_aux_command_timeline { + __u64 timelines; + __u32 count; + __u32 timelines_size; +}; + +/* Macros for fault type used in kgsl_fault structure */ +#define KGSL_FAULT_TYPE_NO_FAULT 0 +#define KGSL_FAULT_TYPE_PAGEFAULT 1 +#define KGSL_FAULT_TYPE_MAX 2 + +/* Macros to be used in kgsl_pagefault_report structure */ +#define KGSL_PAGEFAULT_TYPE_NONE 0 +#define KGSL_PAGEFAULT_TYPE_READ (1 << 0) +#define KGSL_PAGEFAULT_TYPE_WRITE (1 << 1) +#define KGSL_PAGEFAULT_TYPE_TRANSLATION (1 << 2) +#define KGSL_PAGEFAULT_TYPE_PERMISSION (1 << 3) +#define KGSL_PAGEFAULT_TYPE_EXTERNAL (1 << 4) +#define KGSL_PAGEFAULT_TYPE_TRANSACTION_STALLED (1 << 5) + +/** + * struct kgsl_pagefault_report - Descriptor for each page fault + * @fault_addr: page fault address + * @fault_type: type of page fault + * + * Contains information about supported GPU page fault. + * Supported fault type: KGSL_PAGEFAULT_TYPE_* + */ +struct kgsl_pagefault_report { + __u64 fault_addr; + /* private: reserved for future use */ + __u64 reserved[2]; + __u32 fault_type; + /* private: padding for 64 bit compatibility */ + __u32 __pad; +}; + +/** + * struct kgsl_fault - Descriptor for each GPU fault type + * @fault: User memory pointer to list of specific fault type + * @type: Type of gpu fault + * @count: Number of entries in @fault + * @size: Size of each entry in @fault in bytes + * + * Contains information about each GPU fault type. If user passes 0 for all the fields, KGSL + * will return the @count and @type of fault. Based on this, user can allocate a buffer for + * specific fault type, fill the @fault and specify the structure size of type specific fault + * in @size. User can walk through @fault list to parse the fault type specific information. + * + * Supported type: KGSL_FAULT_TYPE_* + */ +struct kgsl_fault { + __u64 fault; + __u32 type; + __u32 count; + __u32 size; + /* private: padding for 64 bit compatibility */ + __u32 padding; +}; + +/** + * struct kgsl_fault_report - Container for list of GPU faults + * @faultlist: User memory pointer to list of fault descriptor &struct kgsl_fault + * @faultnents: Number of entries in @faultlist. Each entry corresponds to a fault type i.e. + * KGSL_FAULT_TYPE_* + * @faultsize: Size of each entry in @faultlist in bytes + * @context_id: ID of a KGSL context + * + * Returns a list of GPU faults for a context identified by @context_id. If the user specifies + * @context_id only, then KGSL will set the @faultnents to the number of fault types it has + * for that context. + * + * User is expected to allocate an array of @struct kgsl_fault with @faultnents number of entries + * and fill the @faultlist field. On calling @IOCTL_KGSL_GET_FAULT_REPORT, KGSL will return the + * type and count for each fault. Based on this, user needs to update the @kgsl_fault structure. + * Then, it should call the @IOCTL_KGSL_GET_FAULT_REPORT again for kernel to fill the fault + * information. + */ +struct kgsl_fault_report { + __u64 faultlist; + __u32 faultnents; + __u32 faultsize; + __u32 context_id; + /* private: padding for 64 bit compatibility */ + __u32 padding; +}; + +#define IOCTL_KGSL_GET_FAULT_REPORT \ + _IOWR(KGSL_IOC_TYPE, 0x5E, struct kgsl_fault_report) + +/** + * struct kgsl_recurring_object - Argument for IOCTL_KGSL_RECURRING_COMMAND + * @flags: Current flags for the object + * @cmdlist: List of kgsl_command_objects for submission + * @cmd_size: Size of kgsl_command_objects structure + * @numcmds: Number of kgsl_command_objects in command list + * @objlist: List of kgsl_command_objects for tracking + * @obj_size: Size of kgsl_command_objects structure + * @numobjs: Number of kgsl_command_objects in object list + * @context_id: Context ID submitting the kgsl_recurring_command + */ +struct kgsl_recurring_command { + __u64 flags; + __u64 __user cmdlist; + __u32 cmdsize; + __u32 numcmds; + __u64 __user objlist; + __u32 objsize; + __u32 numobjs; + __u32 context_id; + /* private: Padding for 64 bit compatibility */ + __u32 padding; +}; + +#define IOCTL_KGSL_RECURRING_COMMAND \ + _IOWR(KGSL_IOC_TYPE, 0x5F, struct kgsl_recurring_command) + +#endif /* _UAPI_MSM_KGSL_H */ \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/src/hook/main_hook.c b/app/src/main/cpp/adrenotools/src/hook/main_hook.c new file mode 100644 index 0000000000..067537f324 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/main_hook.c @@ -0,0 +1,9 @@ +#include "hook_impl.h" + +__attribute__((visibility("default"))) void *android_dlopen_ext(const char *filename, int flags, const android_dlextinfo *extinfo) { + return hook_android_dlopen_ext(filename, flags, extinfo); +} + +__attribute__((visibility("default"))) void *android_load_sphal_library(const char *filename, int flags) { + return hook_android_load_sphal_library(filename, flags); +} \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/src/hook/meson.build b/app/src/main/cpp/adrenotools/src/hook/meson.build new file mode 100644 index 0000000000..0bb6eb3907 --- /dev/null +++ b/app/src/main/cpp/adrenotools/src/hook/meson.build @@ -0,0 +1,72 @@ +hook_impl_files = files(['hook_impl.cpp', 'hook_impl.h', 'hook_impl_params.h']) +hook_impl_inc = include_directories('../../include') + +# hook_impl_lib = shared_library('hook_impl', 'hook_impl.cpp', 'hook_impl.h', 'hook_impl_params.h') +# target_compile_options(['hook_impl', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_libraries(['hook_impl', 'linkernsbypass', 'log']) +# target_include_directories(['hook_impl', 'PRIVATE', '../../include']) +# set_target_properties(['hook_impl', 'PROPERTIES', 'CXX_VISIBILITY_PRESET', 'hidden']) + +main_hook_files = files(['main_hook.c']) +# main_hook_lib = shared_library('main_hook', 'main_hook.c') +# target_compile_options(['main_hook', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_options(['main_hook', 'PRIVATE', '-z', 'global']) +# target_link_libraries(['main_hook', 'hook_impl']) +# set_target_properties(['main_hook', 'PROPERTIES', 'CXX_VISIBILITY_PRESET', 'hidden']) + +file_redirect_hook_files = files(['file_redirect_hook.c']) +# file_redirect_hook_lib = shared_library('file_redirect_hook', 'file_redirect_hook.c') +# target_compile_options(['file_redirect_hook', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_options(['file_redirect_hook', 'PRIVATE', '-z', 'global']) +# target_link_libraries(['file_redirect_hook', 'hook_impl']) +# set_target_properties(['file_redirect_hook', 'PROPERTIES', 'CXX_VISIBILITY_PRESET', 'hidden']) + +gsl_alloc_hook_files = files(['gsl_alloc_hook.c']) +# gsl_alloc_hook_lib = shared_library('gsl_alloc_hook', 'gsl_alloc_hook.c') +# target_compile_options(['gsl_alloc_hook', 'PRIVATE', '-Wall', '-Wextra']) +# target_link_options(['gsl_alloc_hook', 'PRIVATE', '-z', 'global']) +# target_link_libraries(['gsl_alloc_hook', 'hook_impl']) +# set_target_properties(['gsl_alloc_hook', 'PROPERTIES', 'CXX_VISIBILITY_PRESET', 'hidden']) + +hook_impl_lib = shared_library( + 'hook_impl', + hook_impl_files, + c_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + cpp_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + dependencies: ([linkernsbypass_dep, liblog_dep]), + include_directories: ([hook_impl_inc]), + install: true +) + +hook_impl_dep = declare_dependency( + link_args: (['-z', 'global']), + link_with: ([hook_impl_lib]), + include_directories: hook_impl_inc, +) + +main_hook_lib = shared_library( + 'main_hook', + main_hook_files, + c_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + cpp_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + dependencies: ([hook_impl_dep]), + install: true +) + +file_redirect_hook_lib = shared_library( + 'file_redirect_hook', + file_redirect_hook_files, + c_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + cpp_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + dependencies: ([hook_impl_dep]), + install: true +) + +gsl_alloc_hook_lib = shared_library( + 'gsl_alloc_hook', + gsl_alloc_hook_files, + c_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + cpp_args: (['-fvisibility=hidden', '-Wall', '-Wextra']), + dependencies: ([hook_impl_dep]), + install: true +) \ No newline at end of file diff --git a/app/src/main/cpp/adrenotools/tools/ADPKG.md b/app/src/main/cpp/adrenotools/tools/ADPKG.md new file mode 100644 index 0000000000..ad18f0b663 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/ADPKG.md @@ -0,0 +1,96 @@ +# Android Driver Package Format + +## Contents +- `meta.json` that follows `Schema` +- `.so` main driver shared library +- `*.so` all libraries depended on by the main driver library, these must have their sonames altered if they wish to replace the system version of the library + +## Example +- `meta.json`: +```json +{ + "schemaVersion": 1, + "name": "Qualcomm v615 Vulkan driver", + "description": "Proprietary Vulkan driver for Adreno 6xx and Adreno 7xx", + "author": "ByLaws", + "packageVersion": "2", + "vendor": "Qualcomm", + "driverVersion": "0.615.0", + "minApi": 27, + "libraryName": "vulkan.ad0615.so" +} +``` + +- `vulkan.ad0615.so`: main patched driver +- `notadreno_utils.so`, `notdmabufheap.so`, `notgsl.so`, `notllvm-glnext.so`, `notllvm-qgl.so`: patched-soname versions of libraries specific to each driver version +- `android.hardware.graphics.mappershim.so`, `vendor.qti.hardware.display.mapperextensionsshim.so`, `vendor.qti.hardware.display.mappershim.so`: qtimapper-shim libs + +## Creation +I recommend running blob-patcher.py to patch a set of blobs from a device dump with mapper ver as 5, then copying in the qtimapper-shim files from the adrenotools releases page. +```bash +$ mkdir outpkg +$ patch.py outpkg vulkan.adreno.so vulkan.ad0615.so 1 +$ vim outpkg/meta.json +$ cp qtimapper-shim-rel/* outpkg +``` + +## Schema +```json +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "ADPKG Schema", + "type": "object", + "properties": { + "schemaVersion": { + "type": "number", + "example": 1 + }, + "name": { + "type": "string", + "example": "Qualcomm Adreno Driver" + }, + "vendor": { + "enum": [ + "Qualcomm", + "Mesa" + ], + }, + "driverVersion": { + "type": "string", + "pattern": "^[0-9]+.[0-9]+.[0-9]+(-.+)?$", + "example": "512.604.0" + }, + "author": { + "type": "string", + "example": "Billy Laws" + }, + "description": { + "type": "string", + "description": "Additional description of the driver, this shouldn't contain redundant information that is already covered by the other fields such as the version and only denote details important for the user" + }, + "packageVersion": { + "type": "string", + "example": "3029-bylaws" + }, + "minApi": { + "type": "number", + "description": "The minimum Android API version required by the driver to function correctly", + "example": 27 + }, + "libraryName": { + "type": "string", + "description": "The name of the main shared library object", + "example": "vulkan.adreno.so" + }, + }, + "required": [ + "schemaVersion", + "name", + "author", + "packageVersion", + "vendor", + "driverVersion", + "minApi", + ] +} +``` diff --git a/app/src/main/cpp/adrenotools/tools/README.md b/app/src/main/cpp/adrenotools/tools/README.md new file mode 100644 index 0000000000..5c0be8d36d --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/README.md @@ -0,0 +1,7 @@ +## Tools for working with the Adreno Vulkan blob + +blob-patcher.py is a script for generating adrenotools loadable drivers from an extracted ROM zip +qtimapper-shim allows newer drivers to work on devices that lack support for the new mapper HAL +acc-shim allows for suppling arguments to the underlying LLVM-based shader compiler library + + diff --git a/app/src/main/cpp/adrenotools/tools/acc-shim/README.md b/app/src/main/cpp/adrenotools/tools/acc-shim/README.md new file mode 100644 index 0000000000..ac9d7f2f15 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/acc-shim/README.md @@ -0,0 +1,12 @@ +## Adreno Compiler Collection parameter shim + +### TODO +Make some sort of API for this so parameters can be changed through adrenotools in realtime. + +### Compilation +``` +$ sed -i 's/libllvm-glnext/notreal-glnext/g' libllvm-glnext.so +$ mv libllvm-glnext.so notreal-glnext.so +$ aarch64-linux-android28-clang vk_acc_shim.cpp -o notllvm-glnext.so --shared -fpic +$ sed -i 's/libllvm-glnext/notllvm-glnext/g' vulkan.adreno.so +``` diff --git a/app/src/main/cpp/adrenotools/tools/acc-shim/vk_acc_shim.cpp b/app/src/main/cpp/adrenotools/tools/acc-shim/vk_acc_shim.cpp new file mode 100644 index 0000000000..2bccb05347 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/acc-shim/vk_acc_shim.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include + +thread_local int satisfy_driver_emutls; + +// Check libllvm-glnext.so in older drivers for a full list of these, newer ones are slightly more awkward due to the split +enum class OptionType : uint32_t { + ArgsStringList = 1, + QcArgsString = 4, + OptLevelInt = 0x101, + NoOptsInt = 0x10D, +}; + +struct StringListVal { + uint32_t len; + const char **entry; +}; + +struct Option +{ + OptionType type; + // PAD + union { + bool boolVal; + int intVal; + float floatVal; + StringListVal *strVals; + const char *strVal; + }; +}; + + +struct OptionsSet +{ + Option *options; + uint32_t num; +}; + + +int CompileHook(void *state, OptionsSet *opts); + +decltype(CompileHook) *OrigCompile{}; + +int CompileHook(void *state, OptionsSet *opts) { + constexpr size_t ReplacementOptsNum = 201; + + Option replacementOpts[ReplacementOptsNum]; + uint32_t patchedOptNum{}; + + // Insert your desired args here - results will be written to stderr + const char *argv[] = {"-help", "-help-hidden", "", NULL }; + StringListVal listVal{ + .len = 3, + .entry = argv, + }; + + replacementOpts[patchedOptNum++] = { + .type = OptionType::ArgsStringList, + .strVals = &listVal + }; + + const char *opt ="Verbose=true Quiet=false"; + replacementOpts[patchedOptNum++] = { + .type = OptionType::QcArgsString, + .strVal = opt + }; + + if (opts->num + patchedOptNum > ReplacementOptsNum) + __builtin_trap(); + + memcpy(&replacementOpts[patchedOptNum], opts->options, sizeof(Option) * opts->num); + + OptionsSet optList{ + .options = replacementOpts, + .num = opts->num + patchedOptNum + }; + + return OrigCompile(state, &optList); +} + + +struct LlvmInterface { + uint32_t unk0[3]; + // PAD + void *makeContext; + void *delContext; + decltype(CompileHook) *compile; + void *unk; +}; + +extern "C" int LoadACC(LlvmInterface *impl); + +extern "C" __attribute__((visibility("default"))) int LoadACC(LlvmInterface *impl) { + void *hnd = dlopen("notreal-glnext.so", RTLD_NOW); + + auto origLoadACC = reinterpret_cast(dlsym(hnd, "LoadACC")); + if (!origLoadACC) + __builtin_trap(); + + int ret = origLoadACC(impl); + + OrigCompile = impl->compile; + impl->compile = &CompileHook; + + return ret; +} diff --git a/app/src/main/cpp/adrenotools/tools/blob-patcher.py b/app/src/main/cpp/adrenotools/tools/blob-patcher.py new file mode 100755 index 0000000000..2464d7f234 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/blob-patcher.py @@ -0,0 +1,67 @@ +#!/usr/bin/python3 +import sys, os + +def patch_lib_base(in_dir, out_dir, libs, in_name, out_name): + with open(in_dir + in_name, "rb") as inf: + with open(out_dir + out_name, "wb") as outf: + content = inf.read() + for lib in libs: + print(out_name + ": repl:", lib[0], "->", lib[1]) + content = content.replace(lib[0].encode(), lib[1].encode()) + + content = content.replace(in_name.encode(), out_name.encode()) + outf.write(content); + +def patch_lib(in_dir, out_dir, libs, name): + patch_lib_base(in_dir, out_dir, libs, "lib" + name + ".so", "not" + name + ".so") + +def patch_references(lib_dir, out_dir, vulkan_libname, vulkan_newname, shim_mapper): + try: + os.mkdir(out_dir) + os.mkdir(out_dir + "/hw") + except: + pass + + replacement_list = [("libgsl.so", "notgsl.so"), ("libllvm-glnext.so", "notllvm-glnext.so"), ("libdmabufheap.so", "notdmabufheap.so"), ("libadreno_utils.so", "notadreno_utils.so"), ("libllvm-qgl.so", "notllvm-qgl.so")] + + if (shim_mapper < 2): + replacement_list += [("vendor.qti.hardware.display.mapper@2.0.so", "vendor.qti.hardware.display.mappershim.so"), + ("android.hardware.graphics.mapper@2.0.so", "android.hardware.graphics.mappershim.so"), + ("vendor.qti.hardware.display.mapperextensions@1.0.so", "vendor.qti.hardware.display.mapperextensionsshim.so"), + ("vendor.qti.hardware.display.mapperextensions@1.1.so", "vendor.qti.hardware.display.mapperextensionsshim.so")] + if (shim_mapper < 3): + replacement_list += [("vendor.qti.hardware.display.mapper@3.0.so", "vendor.qti.hardware.display.mappershim.so"), + ("android.hardware.graphics.mapper@3.0.so", "android.hardware.graphics.mappershim.so")] + if (shim_mapper < 4): + replacement_list += [("vendor.qti.hardware.display.mapper@4.0.so", "vendor.qti.hardware.display.mappershim.so"), + ("android.hardware.graphics.mapper@4.0.so", "android.hardware.graphics.mappershim.so")] + + for lib in ["gsl", "llvm-glnext", "dmabufheap", "adreno_utils", "llvm-qgl"]: + try: + patch_lib(lib_dir, out_dir, replacement_list, lib) + except: + pass + + patch_lib_base(lib_dir + "/hw/", out_dir + "/hw/", replacement_list, vulkan_libname, vulkan_newname) + +if (len(sys.argv)!= 6): + print(" ") + sys.exit() + + + +root_path = sys.argv[1] +out_path = sys.argv[2] +vulkan_libname = sys.argv[3] +vulkan_newname = sys.argv[4] +shim_mapper = int(sys.argv[5]) +vendor_path = root_path + "/vendor/" + +if (len(vulkan_newname) != len(vulkan_libname)): + print("Errror") + sys.exit() + +for libdir in ["/lib64/", "/lib/"]: + patch_references(vendor_path + libdir, out_path + libdir, vulkan_libname, vulkan_newname, shim_mapper) +print("done!") + diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/.clang-format b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/.clang-format new file mode 100644 index 0000000000..ede5d7e18b --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Inline +ColumnLimit: 100 +CommentPragmas: NOLINT:.* +DerivePointerAlignment: false +IndentWidth: 2 +PointerAlignment: Left +TabWidth: 2 +UseTab: Never diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/Android.bp b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/Android.bp new file mode 100644 index 0000000000..bc4a66bee0 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/Android.bp @@ -0,0 +1,37 @@ +cc_defaults { + name: "shim_defaults", + + srcs: [ + "shim.cpp", + "ext/gr_utils.cpp", + "ext/gr_adreno_info.cpp", + ], + + shared_libs: [ + "liblog", + "libcutils", + "libhidlbase", + "libhardware", + "libutils", + ], + + cflags: [ + "-Wno-error", + "-Wno-unused-parameter", + ], +} + +cc_library_shared { + name: "vendor.qti.hardware.display.mappershim", + defaults: ["shim_defaults"], +} + +cc_library_shared { + name: "vendor.qti.hardware.display.mapperextensionsshim", + defaults: ["shim_defaults"], +} + +cc_library_shared { + name: "android.hardware.graphics.mappershim", + defaults: ["shim_defaults"], +} diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/README.md b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/README.md new file mode 100644 index 0000000000..6e2489396e --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/README.md @@ -0,0 +1,19 @@ +## QtiMapper-shim + +A shim that translates between the IQtiMapper(2,3,4) API used by newer Adreno graphics drivers and gralloc1, which is the only available gralloc API on sdm845. + +### Method + +Exposes the same ABI as the newer mapper blobs and stubs enough functions to force the HAL to fallback to the 2.0 mapper/mapperextension API which is then shimmed with a passthrough to gralloc1. The blobs can then be patched to load the stub libs instead, see the blob-patcher script. +The code is fairly ugly but functional enough for the purpose, some functions are missing and will need to be implemented in the case that the driver starts using them. + + +### Building + +Chuck into a lineage tree, then: +``` +make vendor.qti.hardware.display.mappershim +make vendor.qti.hardware.display.mapperextensionsshim +make android.hardware.graphics.mappershim +``` +and grab SOs out of outputs dir diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/QtiGrallocDefs.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/QtiGrallocDefs.h new file mode 100644 index 0000000000..e0ccbe1d25 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/QtiGrallocDefs.h @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __QTIGRALLOCDEFS_H__ +#define __QTIGRALLOCDEFS_H__ + +// From gralloc_priv.h + +/* Gralloc usage bits indicating the type of allocation that should be used */ +/* Refer to BufferUsage in hardware/interfaces/graphics/common//types.hal */ + +/* The bits below are in officially defined vendor space + * i.e bits 28-31 and 48-63*/ +/* Non linear, Universal Bandwidth Compression */ +#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC (UINT32_C(1) << 28) + +/* Set this for allocating uncached memory (using O_DSYNC), + * cannot be used with noncontiguous heaps */ +#define GRALLOC_USAGE_PRIVATE_UNCACHED (UINT32_C(1) << 29) + +/* This flag is used to indicate 10 bit format. + * When both GRALLOC_USAGE_PRIVATE_ALLOC_UBWC & GRALLOC_USAGE_PRIVATE_10BIT + * are set then it will indicate UBWC_TP10 format. + * When only GRALLOC_USAGE_PRIVATE_10BIT is set it will indicate linear P010 format. + */ +#define GRALLOC_USAGE_PRIVATE_10BIT (UINT32_C(1) << 30) + +/* This flag is used for SECURE display usecase */ +#define GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY (UINT32_C(1) << 31) + +/* This flag is used to indicate video NV21 format */ +#define GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER 1ULL << 48 + +/* unused legacy flags */ +#define GRALLOC_USAGE_PRIVATE_MM_HEAP 0 +#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP 0 + +/* This flag is set for WFD usecase */ +#define GRALLOC_USAGE_PRIVATE_WFD 1ULL << 51 + +/* This flag is set for HEIF usecase */ +#define GRALLOC_USAGE_PRIVATE_HEIF (UINT32_C(1) << 27) + +/* TODO(user): Remove when clients stop referencing this flag */ +#define GRALLOC_USAGE_PRIVATE_10BIT_TP 0 + +/* This flag indicates PI format is being used */ +#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI 1ULL << 49 + +/* This flag is set while CDSP accesses the buffer */ +#define GRALLOC_USAGE_PRIVATE_CDSP 1ULL << 50 + +// OEM specific HAL formats +#define HAL_PIXEL_FORMAT_RGBA_5551 6 +#define HAL_PIXEL_FORMAT_RGBA_4444 7 +#define HAL_PIXEL_FORMAT_NV12_ENCODEABLE 0x102 +#define HAL_PIXEL_FORMAT_NV21_ENCODEABLE 0x7FA30C00 +#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS 0x7FA30C04 +#define HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED 0x7FA30C03 +#define HAL_PIXEL_FORMAT_YCbCr_420_SP 0x109 +#define HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO 0x7FA30C01 +#define HAL_PIXEL_FORMAT_YCrCb_422_SP 0x10B +#define HAL_PIXEL_FORMAT_R_8 0x10D +#define HAL_PIXEL_FORMAT_RG_88 0x10E +#define HAL_PIXEL_FORMAT_YCbCr_444_SP 0x10F +#define HAL_PIXEL_FORMAT_YCrCb_444_SP 0x110 +#define HAL_PIXEL_FORMAT_YCrCb_422_I 0x111 +#define HAL_PIXEL_FORMAT_BGRX_8888 0x112 +#define HAL_PIXEL_FORMAT_NV21_ZSL 0x113 +#define HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS 0x114 +#define HAL_PIXEL_FORMAT_BGR_565 0x115 +#define HAL_PIXEL_FORMAT_RAW8 0x123 +#define HAL_PIXEL_FORMAT_NV12_HEIF 0x116 + +// 10 bit +#define HAL_PIXEL_FORMAT_ARGB_2101010 0x117 +#define HAL_PIXEL_FORMAT_RGBX_1010102 0x118 +#define HAL_PIXEL_FORMAT_XRGB_2101010 0x119 +#define HAL_PIXEL_FORMAT_BGRA_1010102 0x11A +#define HAL_PIXEL_FORMAT_ABGR_2101010 0x11B +#define HAL_PIXEL_FORMAT_BGRX_1010102 0x11C +#define HAL_PIXEL_FORMAT_XBGR_2101010 0x11D +#define HAL_PIXEL_FORMAT_YCbCr_420_P010 0x36 // HAL_PIXEL_FORMAT_YCBCR_P010 +#define HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC 0x124 +#define HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS 0x7FA30C0A + +#define HAL_PIXEL_FORMAT_CbYCrY_422_I 0x120 +#define HAL_PIXEL_FORMAT_BGR_888 0x121 + +#define HAL_PIXEL_FORMAT_INTERLACE 0x180 + +// Camera utils format +#define HAL_PIXEL_FORMAT_NV12_LINEAR_FLEX 0x125 +#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX 0x126 +#define HAL_PIXEL_FORMAT_MULTIPLANAR_FLEX 0x127 +#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_2_BATCH 0x128 +#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_4_BATCH 0x129 +#define HAL_PIXEL_FORMAT_NV12_UBWC_FLEX_8_BATCH 0x130 + +// FSC Formats +#define HAL_PIXEL_FORMAT_RGB888_UBWC_FSC 0x131 +#define HAL_PIXEL_FORMAT_RGB101010_UBWC_FSC 0x132 + +// v4l2_fourcc('Y', 'U', 'Y', 'L'). 24 bpp YUYV 4:2:2 10 bit per component +#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT 0x4C595559 + +// v4l2_fourcc('Y', 'B', 'W', 'C'). 10 bit per component. This compressed +// format reduces the memory access bandwidth +#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT_COMPRESSED 0x43574259 + +// UBWC aligned Venus format +#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC 0x7FA30C06 +#define HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC 0x7FA30C09 + +// Khronos ASTC formats +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD + +enum { BUFFER_TYPE_UI = 0, BUFFER_TYPE_VIDEO }; + +#endif //__QTIGRALLOCDEFS_H__ diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/common.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/common.h new file mode 100644 index 0000000000..73e80cb1d6 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/common.h @@ -0,0 +1,86 @@ +/* + * Copyright 2022 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 +#include +#include +#include + +#include "types/common.h" + +using namespace android::hardware; +using namespace android; + +/* Simplified version of hidl::base::V1_0::IBase */ +struct IBase : virtual public RefBase { + virtual bool isRemote() const; + + using interfaceChain_cb = std::function& descriptors)>; + virtual Return interfaceChain(interfaceChain_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return debug(const hidl_handle& fd, const hidl_vec& options) { + ALOGE("%s", __func__); + std::terminate(); + } + + using interfaceDescriptor_cb = std::function; + virtual Return interfaceDescriptor(interfaceDescriptor_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using getHashChain_cb = std::function>& hashchain)>; + virtual Return getHashChain(getHashChain_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return setHALInstrumentation() { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return linkToDeath(const sp& recipient, uint64_t cookie) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return ping() { + ALOGE("%s", __func__); + std::terminate(); + } + + using getDebugInfo_cb = std::function; + virtual Return getDebugInfo(getDebugInfo_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return notifySyspropsChanged() { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return unlinkToDeath(const sp& recipient) { + ALOGE("%s", __func__); + std::terminate(); + } +}; diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.cpp b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.cpp new file mode 100644 index 0000000000..30610e810d --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.cpp @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gr_adreno_info.h" + +#include +#include +#include + +#include + +#include "gr_utils.h" +#include "gralloc_priv.h" + +using std::lock_guard; +using std::mutex; + +namespace gralloc { + +AdrenoMemInfo* AdrenoMemInfo::s_instance = nullptr; + +AdrenoMemInfo* AdrenoMemInfo::GetInstance() { + static mutex s_lock; + lock_guard obj(s_lock); + if (!s_instance) { + s_instance = new AdrenoMemInfo(); + } + + return s_instance; +} + +AdrenoMemInfo::AdrenoMemInfo() { + libadreno_utils_ = ::dlopen("libadreno_utils.so", RTLD_NOW); + if (libadreno_utils_) { + *reinterpret_cast(&LINK_adreno_compute_aligned_width_and_height) = + ::dlsym(libadreno_utils_, "compute_aligned_width_and_height"); + *reinterpret_cast(&LINK_adreno_compute_fmt_aligned_width_and_height) = + ::dlsym(libadreno_utils_, "compute_fmt_aligned_width_and_height"); + *reinterpret_cast(&LINK_adreno_compute_padding) = + ::dlsym(libadreno_utils_, "compute_surface_padding"); + *reinterpret_cast(&LINK_adreno_compute_compressedfmt_aligned_width_and_height) = + ::dlsym(libadreno_utils_, "compute_compressedfmt_aligned_width_and_height"); + *reinterpret_cast(&LINK_adreno_isUBWCSupportedByGpu) = + ::dlsym(libadreno_utils_, "isUBWCSupportedByGpu"); + *reinterpret_cast(&LINK_adreno_get_gpu_pixel_alignment) = + ::dlsym(libadreno_utils_, "get_gpu_pixel_alignment"); + *reinterpret_cast(&LINK_adreno_get_metadata_blob_size) = + ::dlsym(libadreno_utils_, "adreno_get_metadata_blob_size"); + *reinterpret_cast(&LINK_adreno_init_memory_layout) = + ::dlsym(libadreno_utils_, "adreno_init_memory_layout"); + *reinterpret_cast(&LINK_adreno_get_aligned_gpu_buffer_size) = + ::dlsym(libadreno_utils_, "adreno_get_aligned_gpu_buffer_size"); + } else { + ALOGE(" Failed to load libadreno_utils.so"); + } + + // Check if the overriding property debug.gralloc.gfx_ubwc_disable + // that disables UBWC allocations for the graphics stack is set + char property[PROPERTY_VALUE_MAX]; + property_get(DISABLE_UBWC_PROP, property, "0"); + if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || + !(strncmp(property, "true", PROPERTY_VALUE_MAX))) { + gfx_ubwc_disable_ = true; + } + + property_get(DISABLE_AHARDWAREBUFFER_PROP, property, "0"); + if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || + !(strncmp(property, "true", PROPERTY_VALUE_MAX))) { + gfx_ahardware_buffer_disable_ = true; + } +} + +AdrenoMemInfo::~AdrenoMemInfo() { + if (libadreno_utils_) { + ::dlclose(libadreno_utils_); + } +} + +void AdrenoMemInfo::AlignUnCompressedRGB(int width, int height, int format, int tile_enabled, + unsigned int* aligned_w, unsigned int* aligned_h) { + *aligned_w = (unsigned int)ALIGN(width, 32); + *aligned_h = (unsigned int)ALIGN(height, 32); + + int bpp = 4; + switch (format) { + case HAL_PIXEL_FORMAT_RGB_888: + case HAL_PIXEL_FORMAT_BGR_888: + bpp = 3; + break; + case HAL_PIXEL_FORMAT_RGB_565: + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + bpp = 2; + break; + default: + break; + } + + int raster_mode = 0; // Adreno unknown raster mode. + int padding_threshold = 512; // Threshold for padding surfaces. + // the function below computes aligned width and aligned height + // based on linear or macro tile mode selected. + if (LINK_adreno_compute_fmt_aligned_width_and_height) { + // We call into adreno_utils only for RGB formats. So plane_id is 0 and + // num_samples is 1 always. We may have to add uitility function to + // find out these if there is a need to call this API for YUV formats. + LINK_adreno_compute_fmt_aligned_width_and_height( + width, height, 0 /*plane_id*/, GetGpuPixelFormat(format), 1 /*num_samples*/, tile_enabled, + raster_mode, padding_threshold, reinterpret_cast(aligned_w), + reinterpret_cast(aligned_h)); + } else if (LINK_adreno_compute_aligned_width_and_height) { + LINK_adreno_compute_aligned_width_and_height( + width, height, bpp, tile_enabled, raster_mode, padding_threshold, + reinterpret_cast(aligned_w), reinterpret_cast(aligned_h)); + } else if (LINK_adreno_compute_padding) { + int surface_tile_height = 1; // Linear surface + *aligned_w = UINT(LINK_adreno_compute_padding(width, bpp, surface_tile_height, raster_mode, + padding_threshold)); + ALOGW("%s: Warning!! Old GFX API is used to calculate stride", __FUNCTION__); + } else { + ALOGW( + "%s: Warning!! Symbols compute_surface_padding and " + "compute_fmt_aligned_width_and_height and " + "compute_aligned_width_and_height not found", + __FUNCTION__); + } +} + +void AdrenoMemInfo::AlignCompressedRGB(int width, int height, int format, unsigned int* aligned_w, + unsigned int* aligned_h) { + if (LINK_adreno_compute_compressedfmt_aligned_width_and_height) { + int bytesPerPixel = 0; + int raster_mode = 0; // Adreno unknown raster mode. + int padding_threshold = 512; // Threshold for padding + // surfaces. + + LINK_adreno_compute_compressedfmt_aligned_width_and_height( + width, height, format, 0, raster_mode, padding_threshold, reinterpret_cast(aligned_w), + reinterpret_cast(aligned_h), &bytesPerPixel); + } else { + *aligned_w = (unsigned int)ALIGN(width, 32); + *aligned_h = (unsigned int)ALIGN(height, 32); + ALOGW("%s: Warning!! compute_compressedfmt_aligned_width_and_height not found", __FUNCTION__); + } +} + +bool AdrenoMemInfo::IsUBWCSupportedByGPU(int format) { + if (!gfx_ubwc_disable_ && LINK_adreno_isUBWCSupportedByGpu) { + ADRENOPIXELFORMAT gpu_format = GetGpuPixelFormat(format); + return LINK_adreno_isUBWCSupportedByGpu(gpu_format); + } + + return false; +} + +uint32_t AdrenoMemInfo::GetGpuPixelAlignment() { + if (LINK_adreno_get_gpu_pixel_alignment) { + return LINK_adreno_get_gpu_pixel_alignment(); + } + + return 1; +} + +ADRENOPIXELFORMAT AdrenoMemInfo::GetGpuPixelFormat(int hal_format) { + switch (hal_format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + return ADRENO_PIXELFORMAT_R8G8B8A8; + case HAL_PIXEL_FORMAT_RGBX_8888: + return ADRENO_PIXELFORMAT_R8G8B8X8; + case HAL_PIXEL_FORMAT_BGRA_8888: + return ADRENO_PIXELFORMAT_B8G8R8A8_UNORM; + case HAL_PIXEL_FORMAT_RGB_888: + return ADRENO_PIXELFORMAT_R8G8B8; + case HAL_PIXEL_FORMAT_RGB_565: + return ADRENO_PIXELFORMAT_B5G6R5; + case HAL_PIXEL_FORMAT_BGR_565: + return ADRENO_PIXELFORMAT_R5G6B5; + case HAL_PIXEL_FORMAT_RGBA_5551: + return ADRENO_PIXELFORMAT_R5G5B5A1; + case HAL_PIXEL_FORMAT_RGBA_4444: + return ADRENO_PIXELFORMAT_R4G4B4A4; + case HAL_PIXEL_FORMAT_RGBA_1010102: + return ADRENO_PIXELFORMAT_R10G10B10A2_UNORM; + case HAL_PIXEL_FORMAT_RGBX_1010102: + return ADRENO_PIXELFORMAT_R10G10B10X2_UNORM; + case HAL_PIXEL_FORMAT_ABGR_2101010: + return ADRENO_PIXELFORMAT_A2B10G10R10_UNORM; + case HAL_PIXEL_FORMAT_RGBA_FP16: + return ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT; + case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: + return ADRENO_PIXELFORMAT_NV12; + case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: + case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: + return ADRENO_PIXELFORMAT_NV12_EXT; + case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: + return ADRENO_PIXELFORMAT_TP10; + case HAL_PIXEL_FORMAT_YCbCr_420_P010: + case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: + case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: + return ADRENO_PIXELFORMAT_P010; + case HAL_PIXEL_FORMAT_DEPTH_16: + return ADRENO_PIXELFORMAT_D16_UNORM; + case HAL_PIXEL_FORMAT_DEPTH_24: + return ADRENO_PIXELFORMAT_D24_UNORM_X8_UINT; + case HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: + return ADRENO_PIXELFORMAT_D24_UNORM_S8_UINT; + case HAL_PIXEL_FORMAT_DEPTH_32F: + return ADRENO_PIXELFORMAT_D32_FLOAT; + case HAL_PIXEL_FORMAT_STENCIL_8: + return ADRENO_PIXELFORMAT_S8_UINT; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR: + return ADRENO_PIXELFORMAT_ASTC_4X4; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: + return ADRENO_PIXELFORMAT_ASTC_4X4_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR: + return ADRENO_PIXELFORMAT_ASTC_5X4; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: + return ADRENO_PIXELFORMAT_ASTC_5X4_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_5X5; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_5X5_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_6X5; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_6X5_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_6X6; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_6X6_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X5; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X5_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X6; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X6_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X8; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: + return ADRENO_PIXELFORMAT_ASTC_8X8_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X5; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X5_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X6; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X6_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X8; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X8_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X10; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: + return ADRENO_PIXELFORMAT_ASTC_10X10_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR: + return ADRENO_PIXELFORMAT_ASTC_12X10; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: + return ADRENO_PIXELFORMAT_ASTC_12X10_SRGB; + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR: + return ADRENO_PIXELFORMAT_ASTC_12X12; + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: + return ADRENO_PIXELFORMAT_ASTC_12X12_SRGB; + default: + ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format); + break; + } + + return ADRENO_PIXELFORMAT_UNKNOWN; +} + +uint32_t AdrenoMemInfo::AdrenoGetMetadataBlobSize() { + if (LINK_adreno_get_metadata_blob_size) { + return LINK_adreno_get_metadata_blob_size(); + } + return 0; +} + +int AdrenoMemInfo::AdrenoInitMemoryLayout(void* metadata_blob, int width, int height, int depth, + int format, int num_samples, int isUBWC, uint64_t usage, + uint32_t num_planes) { + if (LINK_adreno_init_memory_layout) { + surface_tile_mode_t tile_mode = static_cast(isUBWC); + return LINK_adreno_init_memory_layout(metadata_blob, width, height, depth, + GetGpuPixelFormat(format), num_samples, tile_mode, usage, + num_planes); + } + return -1; +} + +uint32_t AdrenoMemInfo::AdrenoGetAlignedGpuBufferSize(void* metadata_blob) { + if (LINK_adreno_get_aligned_gpu_buffer_size) { + return LINK_adreno_get_aligned_gpu_buffer_size(metadata_blob); + } + return -1; +} + +bool AdrenoMemInfo::AdrenoSizeAPIAvaliable() { + if (gfx_ahardware_buffer_disable_) { + return false; + } + + return (LINK_adreno_get_metadata_blob_size && LINK_adreno_init_memory_layout && + LINK_adreno_get_aligned_gpu_buffer_size); +} + +bool AdrenoMemInfo::IsPISupportedByGPU(int format, uint64_t usage) { + if (LINK_adreno_isPISupportedByGpu) { + return LINK_adreno_isPISupportedByGpu(format, usage); + } + return false; +} + +} // namespace gralloc diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.h new file mode 100644 index 0000000000..590d18ba67 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_adreno_info.h @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GR_ADRENO_INFO_H__ +#define __GR_ADRENO_INFO_H__ + +#include +#include + +namespace gralloc { + +// Adreno Pixel Formats +typedef enum { + ADRENO_PIXELFORMAT_UNKNOWN = 0, + ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT = 10, + ADRENO_PIXELFORMAT_R10G10B10A2_UNORM = 24, // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES + ADRENO_PIXELFORMAT_R8G8B8A8 = 28, + ADRENO_PIXELFORMAT_R8G8B8A8_SRGB = 29, + ADRENO_PIXELFORMAT_D32_FLOAT = 40, + ADRENO_PIXELFORMAT_D24_UNORM_S8_UINT = 45, + ADRENO_PIXELFORMAT_D16_UNORM = 55, + ADRENO_PIXELFORMAT_B5G6R5 = 85, + ADRENO_PIXELFORMAT_B5G5R5A1 = 86, + ADRENO_PIXELFORMAT_B8G8R8A8_UNORM = 87, + ADRENO_PIXELFORMAT_B8G8R8A8 = 90, + ADRENO_PIXELFORMAT_B8G8R8A8_SRGB = 91, + ADRENO_PIXELFORMAT_B8G8R8X8_SRGB = 93, + ADRENO_PIXELFORMAT_NV12 = 103, + ADRENO_PIXELFORMAT_P010 = 104, + ADRENO_PIXELFORMAT_YUY2 = 107, + ADRENO_PIXELFORMAT_B4G4R4A4 = 115, + ADRENO_PIXELFORMAT_NV12_EXT = 506, // NV12 with non-std alignment and offsets + ADRENO_PIXELFORMAT_R8G8B8X8 = 507, // GL_RGB8 (Internal) + ADRENO_PIXELFORMAT_R8G8B8 = 508, // GL_RGB8 + ADRENO_PIXELFORMAT_A1B5G5R5 = 519, // GL_RGB5_A1 + ADRENO_PIXELFORMAT_R8G8B8X8_SRGB = 520, // GL_SRGB8 + ADRENO_PIXELFORMAT_R8G8B8_SRGB = 521, // GL_SRGB8 + ADRENO_PIXELFORMAT_A2B10G10R10_UNORM = 532, + // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES + ADRENO_PIXELFORMAT_R10G10B10X2_UNORM = 537, + ADRENO_PIXELFORMAT_D24_UNORM_X8_UINT = 548, + ADRENO_PIXELFORMAT_D24_UNORM = 549, + ADRENO_PIXELFORMAT_D32_FLOAT_X24S8_UINT = 551, + ADRENO_PIXELFORMAT_S8_UINT = 552, + ADRENO_PIXELFORMAT_ASTC_4X4 = 568, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_5X4 = 569, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_5X5 = 570, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_6X5 = 571, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_6X6 = 572, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X5 = 573, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X6 = 574, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X8 = 575, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X5 = 576, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X6 = 577, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X8 = 578, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X10 = 579, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_12X10 = 580, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_12X12 = 581, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_4X4_SRGB = 582, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_5X4_SRGB = 583, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_5X5_SRGB = 584, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_6X5_SRGB = 585, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_6X6_SRGB = 586, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X5_SRGB = 587, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X6_SRGB = 588, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_8X8_SRGB = 589, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X5_SRGB = 590, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X6_SRGB = 591, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X8_SRGB = 592, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_10X10_SRGB = 593, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_12X10_SRGB = 594, // ASTC Compressed + ADRENO_PIXELFORMAT_ASTC_12X12_SRGB = 595, // ASTC Compressed + // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES + ADRENO_PIXELFORMAT_R5G6B5 = 610, // RGBA version of B5G6R5 + ADRENO_PIXELFORMAT_R5G5B5A1 = 611, // RGBA version of B5G5R5A1 + ADRENO_PIXELFORMAT_R4G4B4A4 = 612, // RGBA version of B4G4R4A4 + ADRENO_PIXELFORMAT_UYVY = 614, // YUV 4:2:2 packed progressive (1 plane) + ADRENO_PIXELFORMAT_NV21 = 619, + ADRENO_PIXELFORMAT_Y8U8V8A8 = 620, // YUV 4:4:4 packed (1 plane) + ADRENO_PIXELFORMAT_Y8 = 625, // Single 8-bit luma only channel YUV format + ADRENO_PIXELFORMAT_TP10 = 654, // YUV 4:2:0 planar 10 bits/comp (2 planes) +} ADRENOPIXELFORMAT; + +typedef enum { + SURFACE_TILE_MODE_DISABLE = 0x0, // used for linear surface + SURFACE_TILE_MODE_ENABLE = 0x1 // used for tiled surface +} surface_tile_mode_t; + +class AdrenoMemInfo { + public: + /* + * Function to compute aligned width and aligned height based on + * width, height, format and usage flags. + * + * @return aligned width, aligned height + */ + void GetAlignedWidthAndHeight(int width, int height, int format, int usage, + unsigned int* aligned_w, unsigned int* aligned_h, bool ubwc_enabled, + bool tile_enabled); + + /* + * Function to compute the adreno aligned width and aligned height + * based on the width and format. + * + * @return aligned width, aligned height + */ + void AlignUnCompressedRGB(int width, int height, int format, int tileEnabled, + unsigned int* aligned_w, unsigned int* aligned_h); + + /* + * Function to compute the adreno aligned width and aligned height + * based on the width and format. + * + * @return aligned width, aligned height + */ + void AlignCompressedRGB(int width, int height, int format, unsigned int* aligned_w, + unsigned int* aligned_h); + + /* + * Function to compute the pixel alignment requirement. + * + * @return alignment + */ + uint32_t GetGpuPixelAlignment(); + + /* + * Function to query whether GPU supports UBWC for given HAL format + * @return > 0 : supported + * 0 : not supported + */ + bool IsUBWCSupportedByGPU(int format); + + /* + * Function to check if GPU supports PI or not + */ + bool IsPISupportedByGPU(int format, uint64_t usage); + /* + * Function to get the corresponding Adreno format for given HAL format + */ + ADRENOPIXELFORMAT GetGpuPixelFormat(int hal_format); + + /* + * Function to get graphics metadata blob size + * @return graphics metadata size + */ + uint32_t AdrenoGetMetadataBlobSize(); + + /* + * Function to populate the graphics metadata blob + * @return 1 : Successful + * 2 : Unsuccessful + */ + int AdrenoInitMemoryLayout(void* metadata_blob, int width, int height, int depth, int format, + int num_samples, int isUBWC, uint64_t usage, uint32_t num_planes); + /* + * Function to get buffer size for based on graphcis metadata + * @return buffer size + */ + uint32_t AdrenoGetAlignedGpuBufferSize(void* metadata_blob); + + /* + * Function to check if adreno size calculation APIs are avaliable + * @return true : Avaliable + * false : Unavaliable + */ + bool AdrenoSizeAPIAvaliable(); + + static AdrenoMemInfo* GetInstance(); + + private: + AdrenoMemInfo(); + ~AdrenoMemInfo(); + // link(s)to adreno surface padding library. + int (*LINK_adreno_compute_padding)(int width, int bpp, int surface_tile_height, + int screen_tile_height, int padding_threshold) = NULL; + void (*LINK_adreno_compute_aligned_width_and_height)(int width, int height, int bpp, + int tile_mode, int raster_mode, + int padding_threshold, int* aligned_w, + int* aligned_h) = NULL; + void (*LINK_adreno_compute_fmt_aligned_width_and_height)(int width, int height, int plane_id, + int format, int num_samples, + int tile_mode, int raster_mode, + int padding_threshold, int* aligned_w, + int* aligned_h) = NULL; + void (*LINK_adreno_compute_compressedfmt_aligned_width_and_height)( + int width, int height, int format, int tile_mode, int raster_mode, int padding_threshold, + int* aligned_w, int* aligned_h, int* bpp) = NULL; + int (*LINK_adreno_isUBWCSupportedByGpu)(ADRENOPIXELFORMAT format) = NULL; + unsigned int (*LINK_adreno_get_gpu_pixel_alignment)() = NULL; + + uint32_t (*LINK_adreno_get_metadata_blob_size)() = NULL; + int (*LINK_adreno_init_memory_layout)(void* metadata_blob, int width, int height, int depth, + ADRENOPIXELFORMAT format, int num_samples, + surface_tile_mode_t tile_mode, uint64_t usage, + uint32_t num_planes) = NULL; + uint32_t (*LINK_adreno_get_aligned_gpu_buffer_size)(void* metadata_blob) = NULL; + int (*LINK_adreno_isPISupportedByGpu)(int format, uint64_t usage) = NULL; + + bool gfx_ubwc_disable_ = false; + bool gfx_ahardware_buffer_disable_ = false; + void* libadreno_utils_ = NULL; + + static AdrenoMemInfo* s_instance; +}; + +} // namespace gralloc + +#endif // __GR_ADRENO_INFO_H__ diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_priv_handle.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_priv_handle.h new file mode 100644 index 0000000000..3efbea4b78 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_priv_handle.h @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. + * Not a Contribution + * + * Copyright (C) 2008 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. + */ + +#ifndef __GR_PRIV_HANDLE_H__ +#define __GR_PRIV_HANDLE_H__ + +#include +#include +#include +#ifdef __cplusplus +#include +#endif + +#define GRALLOC1_FUNCTION_PERFORM 0x00001000 + +#define DBG_HANDLE false + +typedef gralloc1_error_t (*GRALLOC1_PFN_PERFORM)(gralloc1_device_t* device, int operation, ...); + +#define PRIV_HANDLE_CONST(exp) static_cast(exp) + +#pragma pack(push, 4) +#ifdef __cplusplus +struct private_handle_t : public native_handle_t { +#else +struct private_handle_t { + native_handle_t nativeHandle; +#endif + enum { + PRIV_FLAGS_FRAMEBUFFER = 0x00000001, + PRIV_FLAGS_USES_ION = 0x00000008, + PRIV_FLAGS_NEEDS_FLUSH = 0x00000020, + PRIV_FLAGS_INTERNAL_ONLY = 0x00000040, + PRIV_FLAGS_NON_CPU_WRITER = 0x00000080, + PRIV_FLAGS_CACHED = 0x00000200, + PRIV_FLAGS_SECURE_BUFFER = 0x00000400, + PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000, + PRIV_FLAGS_PROTECTED_BUFFER = 0x00004000, + PRIV_FLAGS_VIDEO_ENCODER = 0x00010000, + PRIV_FLAGS_CAMERA_WRITE = 0x00020000, + PRIV_FLAGS_CAMERA_READ = 0x00040000, + PRIV_FLAGS_HW_COMPOSER = 0x00080000, + PRIV_FLAGS_HW_TEXTURE = 0x00100000, + PRIV_FLAGS_ITU_R_601 = 0x00200000, // Unused from display + PRIV_FLAGS_ITU_R_601_FR = 0x00400000, // Unused from display + PRIV_FLAGS_ITU_R_709 = 0x00800000, // Unused from display + PRIV_FLAGS_SECURE_DISPLAY = 0x01000000, + PRIV_FLAGS_TILE_RENDERED = 0x02000000, + PRIV_FLAGS_CPU_RENDERED = 0x04000000, + PRIV_FLAGS_UBWC_ALIGNED = 0x08000000, + PRIV_FLAGS_DISP_CONSUMER = 0x10000000, + PRIV_FLAGS_CLIENT_ALLOCATED = 0x20000000, // Ion buffer allocated outside of gralloc + PRIV_FLAGS_UBWC_ALIGNED_PI = 0x40000000, // PI format + }; + + // file-descriptors dup'd over IPC + int fd; + int fd_metadata; + + // values sent over IPC + int magic; + int flags; + int width; // holds width of the actual buffer allocated + int height; // holds height of the actual buffer allocated + int unaligned_width; // holds width client asked to allocate + int unaligned_height; // holds height client asked to allocate + int format; + int buffer_type; + unsigned int layer_count; + uint64_t id; + uint64_t usage; + + unsigned int size; + unsigned int offset; + unsigned int offset_metadata; + uint64_t base; + uint64_t base_metadata; + uint64_t gpuaddr; +#ifdef __cplusplus + static const int kNumFds = 2; + static const int kMagic = 'gmsm'; + + static inline int NumInts() { + return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds; + } + + private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh, + int format, int buf_type, unsigned int size, uint64_t usage = 0) + : fd(fd), + fd_metadata(meta_fd), + magic(kMagic), + flags(flags), + width(width), + height(height), + unaligned_width(uw), + unaligned_height(uh), + format(format), + buffer_type(buf_type), + layer_count(1), + id(0), + usage(usage), + size(size), + offset(0), + offset_metadata(0), + base(0), + base_metadata(0), + gpuaddr(0) { + version = static_cast(sizeof(native_handle)); + numInts = NumInts(); + numFds = kNumFds; + } + + // Legacy constructor used by some clients + private_handle_t(int fd, unsigned int size, int usage, int buf_type, int format, int w, int h) + : private_handle_t(fd, -1, PRIV_FLAGS_CLIENT_ALLOCATED, w, h, 0, 0, format, buf_type, size, + static_cast(usage)) {} + + ~private_handle_t() { + magic = 0; + ALOGE_IF(DBG_HANDLE, "Deleting buffer handle %p", this); + } + + static int validate(const native_handle* h) { + auto* hnd = static_cast(h); + if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() || + h->numFds != kNumFds) { + ALOGE("Invalid gralloc handle (at %p): ver(%d/%zu) ints(%d/%d) fds(%d/%d)", h, + h ? h->version : -1, sizeof(native_handle), h ? h->numInts : -1, NumInts(), + h ? h->numFds : -1, kNumFds); + return -EINVAL; + } + if (hnd->magic != kMagic) { + ALOGE("handle = %p invalid magic(%c%c%c%c/%c%c%c%c)", hnd, + hnd ? (((hnd->magic >> 24) & 0xFF) ? ((hnd->magic >> 24) & 0xFF) : '-') : '?', + hnd ? (((hnd->magic >> 16) & 0xFF) ? ((hnd->magic >> 16) & 0xFF) : '-') : '?', + hnd ? (((hnd->magic >> 8) & 0xFF) ? ((hnd->magic >> 8) & 0xFF) : '-') : '?', + hnd ? (((hnd->magic >> 0) & 0xFF) ? ((hnd->magic >> 0) & 0xFF) : '-') : '?', + (kMagic >> 24) & 0xFF, (kMagic >> 16) & 0xFF, (kMagic >> 8) & 0xFF, + (kMagic >> 0) & 0xFF); + return -EINVAL; + } + + return 0; + } + + static void Dump(const private_handle_t* hnd) { + ALOGD("handle id:%" PRIu64 + " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x " + "usage:0x%" PRIx64 " format:0x%x layer_count: %d", + hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size, + hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count); + } + + int GetUnalignedWidth() const { return unaligned_width; } + + int GetUnalignedHeight() const { return unaligned_height; } + + int GetColorFormat() const { return format; } + + unsigned int GetLayerCount() const { return layer_count; } + + int GetStride() const { + // In handle we currently store aligned width after allocation. + return width; + } + + uint64_t GetUsage() const { return usage; } + + uint64_t GetBackingstore() const { return id; } +#endif +}; +#pragma pack(pop) + +#endif // __GR_PRIV_HANDLE_H__ diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.cpp b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.cpp new file mode 100644 index 0000000000..a83ef20a6b --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.cpp @@ -0,0 +1,662 @@ +/* + * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gr_utils.h" + +#include + +#include "gr_adreno_info.h" + +#define ASTC_BLOCK_SIZE 16 + +#ifndef COLOR_FMT_P010_UBWC +#define COLOR_FMT_P010_UBWC 9 +#endif + +namespace gralloc { + +bool IsUncompressedRGBFormat(int format) { + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_RGB_888: + case HAL_PIXEL_FORMAT_RGB_565: + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + case HAL_PIXEL_FORMAT_R_8: + case HAL_PIXEL_FORMAT_RG_88: + case HAL_PIXEL_FORMAT_BGRX_8888: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_ARGB_2101010: + case HAL_PIXEL_FORMAT_RGBX_1010102: + case HAL_PIXEL_FORMAT_XRGB_2101010: + case HAL_PIXEL_FORMAT_BGRA_1010102: + case HAL_PIXEL_FORMAT_ABGR_2101010: + case HAL_PIXEL_FORMAT_BGRX_1010102: + case HAL_PIXEL_FORMAT_XBGR_2101010: + case HAL_PIXEL_FORMAT_RGBA_FP16: + case HAL_PIXEL_FORMAT_BGR_888: + return true; + default: + break; + } + + return false; +} + +bool IsCompressedRGBFormat(int format) { + switch (format) { + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR: + case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: + return true; + default: + break; + } + + return false; +} + +uint32_t GetBppForUncompressedRGB(int format) { + uint32_t bpp = 0; + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_FP16: + bpp = 8; + break; + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_BGRX_8888: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_ARGB_2101010: + case HAL_PIXEL_FORMAT_RGBX_1010102: + case HAL_PIXEL_FORMAT_XRGB_2101010: + case HAL_PIXEL_FORMAT_BGRA_1010102: + case HAL_PIXEL_FORMAT_ABGR_2101010: + case HAL_PIXEL_FORMAT_BGRX_1010102: + case HAL_PIXEL_FORMAT_XBGR_2101010: + bpp = 4; + break; + case HAL_PIXEL_FORMAT_RGB_888: + case HAL_PIXEL_FORMAT_BGR_888: + bpp = 3; + break; + case HAL_PIXEL_FORMAT_RGB_565: + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + bpp = 2; + break; + default: + ALOGE("Error : %s New format request = 0x%x", __FUNCTION__, format); + break; + } + + return bpp; +} + +bool CpuCanAccess(uint64_t usage) { + return CpuCanRead(usage) || CpuCanWrite(usage); +} + +bool CpuCanRead(uint64_t usage) { + if (usage & BufferUsage::CPU_READ_MASK) { + return true; + } + + return false; +} + +bool CpuCanWrite(uint64_t usage) { + if (usage & BufferUsage::CPU_WRITE_MASK) { + // Application intends to use CPU for rendering + return true; + } + + return false; +} + +uint32_t GetDataAlignment(int format, uint64_t usage) { + uint32_t align = UINT(getpagesize()); + if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { + align = SIZE_8K; + } + + if (usage & BufferUsage::PROTECTED) { + if ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) { + // The alignment here reflects qsee mmu V7L/V8L requirement + align = SZ_2M; + } else { + align = SECURE_ALIGN; + } + } + + return align; +} + +bool IsGPUFlagSupported(uint64_t usage) { + bool ret = true; + if ((usage & BufferUsage::GPU_MIPMAP_COMPLETE)) { + ALOGE("GPU_MIPMAP_COMPLETE not supported"); + ret = false; + } + + if ((usage & BufferUsage::GPU_CUBE_MAP)) { + ALOGE("GPU_CUBE_MAP not supported"); + ret = false; + } + + return ret; +} + +// Returns the final buffer size meant to be allocated with ion +unsigned int GetSize(const BufferInfo& info, unsigned int alignedw, unsigned int alignedh) { + unsigned int size = 0; + int format = info.format; + int width = info.width; + int height = info.height; + uint64_t usage = info.usage; + + if (!IsGPUFlagSupported(usage)) { + ALOGE("Unsupported GPU usage flags present 0x%" PRIx64, usage); + return 0; + } + + if (IsUBwcEnabled(format, usage)) { + size = GetUBwcSize(width, height, format, alignedw, alignedh); + } else if (IsUncompressedRGBFormat(format)) { + uint32_t bpp = GetBppForUncompressedRGB(format); + size = alignedw * alignedh * bpp; + } else if (IsCompressedRGBFormat(format)) { + size = alignedw * alignedh * ASTC_BLOCK_SIZE; + } else { + // Below switch should be for only YUV/custom formats + switch (format) { + case HAL_PIXEL_FORMAT_RAW16: + case HAL_PIXEL_FORMAT_Y16: + size = alignedw * alignedh * 2; + break; + case HAL_PIXEL_FORMAT_RAW10: + case HAL_PIXEL_FORMAT_RAW12: + size = ALIGN(alignedw * alignedh, SIZE_4K); + break; + case HAL_PIXEL_FORMAT_RAW8: + case HAL_PIXEL_FORMAT_Y8: + size = alignedw * alignedh * 1; + break; + // adreno formats + case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21 + size = ALIGN(alignedw * alignedh, SIZE_4K); + size += (unsigned int)ALIGN(2 * ALIGN(width / 2, 32) * ALIGN(height / 2, 32), SIZE_4K); + break; + case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12 + // The chroma plane is subsampled, + // but the pitch in bytes is unchanged + // The GPU needs 4K alignment, but the video decoder needs 8K + size = ALIGN(alignedw * alignedh, SIZE_8K); + size += ALIGN(alignedw * (unsigned int)ALIGN(height / 2, 32), SIZE_8K); + break; + case HAL_PIXEL_FORMAT_YV12: + if ((format == HAL_PIXEL_FORMAT_YV12) && ((width & 1) || (height & 1))) { + ALOGE("w or h is odd for the YV12 format"); + return 0; + } + size = alignedw * alignedh + (ALIGN(alignedw / 2, 16) * (alignedh / 2)) * 2; + size = ALIGN(size, (unsigned int)SIZE_4K); + break; + case HAL_PIXEL_FORMAT_YCbCr_420_SP: + case HAL_PIXEL_FORMAT_YCrCb_420_SP: + size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2 + 1, SIZE_4K); + break; + case HAL_PIXEL_FORMAT_YCbCr_420_P010: + size = ALIGN((alignedw * alignedh * 2) + (alignedw * alignedh) + 1, SIZE_4K); + break; + case HAL_PIXEL_FORMAT_YCbCr_422_SP: + case HAL_PIXEL_FORMAT_YCrCb_422_SP: + case HAL_PIXEL_FORMAT_YCbCr_422_I: + case HAL_PIXEL_FORMAT_YCrCb_422_I: + case HAL_PIXEL_FORMAT_CbYCrY_422_I: + if (width & 1) { + ALOGE("width is odd for the YUV422_SP format"); + return 0; + } + size = ALIGN(alignedw * alignedh * 2, SIZE_4K); + break; + case HAL_PIXEL_FORMAT_BLOB: + case HAL_PIXEL_FORMAT_RAW_OPAQUE: + if (height != 1) { + ALOGE("%s: Buffers with HAL_PIXEL_FORMAT_BLOB must have height 1 ", __FUNCTION__); + return 0; + } + size = (unsigned int)width; + break; + case HAL_PIXEL_FORMAT_NV21_ZSL: + size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2, SIZE_4K); + break; + default: + ALOGE("%s: Unrecognized pixel format: 0x%x", __FUNCTION__, format); + return 0; + } + } + auto align = GetDataAlignment(format, usage); + size = ALIGN(size, align) * info.layer_count; + return size; +} + +// Explicitly defined UBWC formats +bool IsUBwcFormat(int format) { + switch (format) { + case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: + case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: + case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: + return true; + default: + return false; + } +} + +bool IsUBwcSupported(int format) { + // Existing HAL formats with UBWC support + switch (format) { + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: + case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_RGBX_1010102: + case HAL_PIXEL_FORMAT_DEPTH_16: + case HAL_PIXEL_FORMAT_DEPTH_24: + case HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8: + case HAL_PIXEL_FORMAT_DEPTH_32F: + case HAL_PIXEL_FORMAT_STENCIL_8: + return true; + default: + break; + } + + return false; +} + +bool IsUBwcPISupported(int format, uint64_t usage) { + if (usage & BufferUsage::COMPOSER_OVERLAY || !(usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI)) { + return false; + } + + // As of now only two formats + switch (format) { + case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: + case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: { + if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) { + if (AdrenoMemInfo::GetInstance()) { + return AdrenoMemInfo::GetInstance()->IsPISupportedByGPU(format, usage); + } + } else { + return true; + } + } + } + + return false; +} + +bool IsUBwcEnabled(int format, uint64_t usage) { + // Allow UBWC, if client is using an explicitly defined UBWC pixel format. + if (IsUBwcFormat(format)) { + return true; + } + + // Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP + // support the format. OR if a non-OpenGL client like Rotator, sets UBWC + // usage flag and MDP supports the format. + if (((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) || + (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI) || + (usage & BufferUsage::COMPOSER_CLIENT_TARGET)) && + IsUBwcSupported(format)) { + bool enable = true; + // Query GPU for UBWC only if buffer is intended to be used by GPU. + if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) { + if (AdrenoMemInfo::GetInstance()) { + enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format); + } + } + + // Allow UBWC, only if CPU usage flags are not set + if (enable && !(CpuCanAccess(usage))) { + return true; + } + } + + return false; +} + +void GetRgbUBwcBlockSize(uint32_t bpp, int* block_width, int* block_height) { + *block_width = 0; + *block_height = 0; + + switch (bpp) { + case 2: + case 4: + *block_width = 16; + *block_height = 4; + break; + case 8: + *block_width = 8; + *block_height = 4; + break; + case 16: + *block_width = 4; + *block_height = 4; + break; + default: + ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); + break; + } +} + +unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp) { + unsigned int size = 0; + int meta_width, meta_height; + int block_width, block_height; + + GetRgbUBwcBlockSize(bpp, &block_width, &block_height); + if (!block_width || !block_height) { + ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); + return size; + } + + // Align meta buffer height to 16 blocks + meta_height = ALIGN(((height + block_height - 1) / block_height), 16); + + // Align meta buffer width to 64 blocks + meta_width = ALIGN(((width + block_width - 1) / block_width), 64); + + // Align meta buffer size to 4K + size = (unsigned int)ALIGN((meta_width * meta_height), 4096); + + return size; +} + +unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, + unsigned int alignedh) { + unsigned int size = 0; + uint32_t bpp = 0; + switch (format) { + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_RGBX_1010102: + bpp = GetBppForUncompressedRGB(format); + size = alignedw * alignedh * bpp; + size += GetRgbUBwcMetaBufferSize(width, height, bpp); + break; + default: + ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format); + break; + } + + return size; +} + +unsigned int GetRgbMetaSize(int format, uint32_t width, uint32_t height, uint64_t usage) { + unsigned int meta_size = 0; + if (!IsUBwcEnabled(format, usage)) { + return meta_size; + } + uint32_t bpp = GetBppForUncompressedRGB(format); + switch (format) { + case HAL_PIXEL_FORMAT_BGR_565: + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_RGBX_8888: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_RGBX_1010102: + case HAL_PIXEL_FORMAT_RGBA_FP16: + meta_size = GetRgbUBwcMetaBufferSize(width, height, bpp); + break; + default: + ALOGE("%s:Unsupported RGB format: 0x%x", __FUNCTION__, format); + break; + } + return meta_size; +} + +bool CanUseAdrenoForSize(int buffer_type, uint64_t usage) { + if (buffer_type == BUFFER_TYPE_VIDEO || !GetAdrenoSizeAPIStatus()) { + return false; + } + + if ((usage & BufferUsage::PROTECTED) && + ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY))) { + return false; + } + + return true; +} + +bool GetAdrenoSizeAPIStatus() { + AdrenoMemInfo* adreno_mem_info = AdrenoMemInfo::GetInstance(); + if (adreno_mem_info) { + return adreno_mem_info->AdrenoSizeAPIAvaliable(); + } + return false; +} + +bool UseUncached(int format, uint64_t usage) { + if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) { + return true; + } + + // CPU read rarely + if ((usage & BufferUsage::CPU_READ_MASK) == static_cast(BufferUsage::CPU_READ_RARELY)) { + return true; + } + + // CPU write rarely + if ((usage & BufferUsage::CPU_WRITE_MASK) == + static_cast(BufferUsage::CPU_WRITE_RARELY)) { + return true; + } + + if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) { + return true; + } + + if (format && IsUBwcEnabled(format, usage)) { + return true; + } + + return false; +} + +uint64_t GetHandleFlags(int format, uint64_t usage) { + uint64_t priv_flags = 0; + + if (usage & BufferUsage::VIDEO_ENCODER) { + priv_flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER; + } + + if (usage & BufferUsage::CAMERA_OUTPUT) { + priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE; + } + + if (usage & BufferUsage::CAMERA_INPUT) { + priv_flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ; + } + + if (usage & BufferUsage::COMPOSER_OVERLAY) { + priv_flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER; + } + + if (usage & BufferUsage::GPU_TEXTURE) { + priv_flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE; + } + + if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) { + priv_flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY; + } + + if (IsUBwcEnabled(format, usage)) { + if (IsUBwcPISupported(format, usage)) { + priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED_PI; + } else { + priv_flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; + } + } + + if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) { + priv_flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED; + } + + if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER | + BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) { + priv_flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER; + } + + if (!UseUncached(format, usage)) { + priv_flags |= private_handle_t::PRIV_FLAGS_CACHED; + } + + return priv_flags; +} + +int GetImplDefinedFormat(uint64_t usage, int format) { + int gr_format = format; + + // If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on + // the usage bits, gralloc assigns a format. + if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED || + format == HAL_PIXEL_FORMAT_YCbCr_420_888) { + if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC || usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC_PI) && + format != HAL_PIXEL_FORMAT_YCbCr_420_888) { + gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC; + } else if (usage & BufferUsage::VIDEO_ENCODER) { + if (usage & GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER) { + gr_format = HAL_PIXEL_FORMAT_NV21_ENCODEABLE; // NV21 + } else if (usage & GRALLOC_USAGE_PRIVATE_HEIF) { + gr_format = HAL_PIXEL_FORMAT_NV12_HEIF; + } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { + gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; + } else { + gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12 + } + } else if (usage & BufferUsage::CAMERA_INPUT) { + if (usage & BufferUsage::CAMERA_OUTPUT) { + // Assumed ZSL if both producer and consumer camera flags set + gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 + } else { + gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21 + } + } else if (usage & BufferUsage::CAMERA_OUTPUT) { + if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { + gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 + } else { + gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview + } + } else if (usage & BufferUsage::COMPOSER_OVERLAY) { + // XXX: If we still haven't set a format, default to RGBA8888 + gr_format = HAL_PIXEL_FORMAT_RGBA_8888; + } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { + // If no other usage flags are detected, default the + // flexible YUV format to NV21_ZSL + gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; + } + } + + return gr_format; +} + +bool HasAlphaComponent(int32_t format) { + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + case HAL_PIXEL_FORMAT_RGBA_1010102: + case HAL_PIXEL_FORMAT_ARGB_2101010: + case HAL_PIXEL_FORMAT_BGRA_1010102: + case HAL_PIXEL_FORMAT_ABGR_2101010: + case HAL_PIXEL_FORMAT_RGBA_FP16: + return true; + default: + return false; + } +} + +void GetRGBPlaneInfo(const BufferInfo& info, int32_t format, int32_t width, int32_t height, + int32_t /* flags */, int* plane_count, PlaneLayoutInfo* plane_info) { + uint64_t usage = info.usage; + *plane_count = 1; + uint32_t bpp = 0; + if (IsUncompressedRGBFormat(format)) { + bpp = GetBppForUncompressedRGB(format); + } + plane_info->component = + (PlaneComponent)(PLANE_COMPONENT_R | PLANE_COMPONENT_G | PLANE_COMPONENT_B); + if (HasAlphaComponent(format)) { + plane_info->component = (PlaneComponent)(plane_info->component | PLANE_COMPONENT_A); + } + plane_info->size = GetSize(info, width, height); + plane_info->step = bpp; + plane_info->offset = GetRgbMetaSize(format, width, height, usage); + plane_info->h_subsampling = 0; + plane_info->v_subsampling = 0; + plane_info->stride = width; + plane_info->stride_bytes = width * plane_info->step; + plane_info->scanlines = height; +} + +} // namespace gralloc diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.h new file mode 100644 index 0000000000..13b21577c5 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gr_utils.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2011-2016,2018-2019, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GR_UTILS_H__ +#define __GR_UTILS_H__ + +#include "gralloc_priv.h" +#include "types/common.h" + +#define SZ_2M 0x200000 +#define SZ_1M 0x100000 +#define SZ_4K 0x1000 + +#define SIZE_4K 4096 +#define SIZE_8K 8192 + +#ifdef SLAVE_SIDE_CP +#define SECURE_ALIGN SZ_1M +#else // MASTER_SIDE_CP +#define SECURE_ALIGN SZ_4K +#endif + +#define INT(exp) static_cast(exp) +#define UINT(exp) static_cast(exp) + +using android::hardware::graphics::common::V1_1::BufferUsage; + +namespace gralloc { +struct BufferInfo { + BufferInfo(int w, int h, int f, uint64_t usage = 0) + : width(w), height(h), format(f), layer_count(1), usage(usage) {} + int width; + int height; + int format; + int layer_count; + uint64_t usage; +}; + +template +inline Type1 ALIGN(Type1 x, Type2 align) { + return (Type1)((x + (Type1)align - 1) & ~((Type1)align - 1)); +} + +enum PlaneComponent { + /* luma */ + PLANE_COMPONENT_Y = 1 << 0, + /* chroma blue */ + PLANE_COMPONENT_Cb = 1 << 1, + /* chroma red */ + PLANE_COMPONENT_Cr = 1 << 2, + + /* red */ + PLANE_COMPONENT_R = 1 << 10, + /* green */ + PLANE_COMPONENT_G = 1 << 11, + /* blue */ + PLANE_COMPONENT_B = 1 << 12, + + /* alpha */ + PLANE_COMPONENT_A = 1 << 20, + + /* raw data plane */ + PLANE_COMPONENT_RAW = 1 << 30, + + /* meta information plane */ + PLANE_COMPONENT_META = 1 << 31, +}; + +struct PlaneLayoutInfo { + /** Components represented the type of plane. */ + PlaneComponent component; + + /** horizontal subsampling. Must be a positive power of 2. */ + uint32_t h_subsampling; + + /** vertical subsampling. Must be a positive power of 2. */ + uint32_t v_subsampling; + + /** offset to the first byte of the top-left pixel of the plane + * and it is calculated from the start of the buffer. + * Add base of the handle with offset to get the first byte of the plane. + */ + uint32_t offset; + + /** step is the distance in bytes from one pixel value to the next. */ + int32_t step; + + /** stride of the plane in pixels */ + int32_t stride; + + /** stride of the plane in in bytes */ + int32_t stride_bytes; + + /** plane height or vertical stride */ + int32_t scanlines; + + /** size of the plane in bytes */ + uint32_t size; +}; + +bool IsCompressedRGBFormat(int format); +bool IsUncompressedRGBFormat(int format); +uint32_t GetBppForUncompressedRGB(int format); +bool CpuCanAccess(uint64_t usage); +bool CpuCanRead(uint64_t usage); +bool CpuCanWrite(uint64_t usage); +unsigned int GetSize(const BufferInfo& d, unsigned int alignedw, unsigned int alignedh); +void GetRGBPlaneInfo(const BufferInfo& info, int32_t format, int32_t width, int32_t height, + int32_t flags, int* plane_count, PlaneLayoutInfo* plane_info); +unsigned int GetRgbMetaSize(int format, uint32_t width, uint32_t height, uint64_t usage); +bool IsUBwcFormat(int format); +bool IsUBwcSupported(int format); +bool IsUBwcPISupported(int format, uint64_t usage); +bool IsUBwcEnabled(int format, uint64_t usage); +void GetRgbUBwcBlockSize(uint32_t bpp, int* block_width, int* block_height); +unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp); +unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, + unsigned int alignedh); +uint32_t GetDataAlignment(int format, uint64_t usage); +bool CanUseAdrenoForSize(int buffer_type, uint64_t usage); +bool GetAdrenoSizeAPIStatus(); +bool UseUncached(int format, uint64_t usage); +uint64_t GetHandleFlags(int format, uint64_t usage); +int GetImplDefinedFormat(uint64_t usage, int format); +int GetCustomFormatFlags(int format, uint64_t usage, int* custom_format, uint64_t* priv_flags); +bool IsGPUFlagSupported(uint64_t usage); +bool HasAlphaComponent(int32_t format); +} // namespace gralloc + +#endif // __GR_UTILS_H__ diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gralloc_priv.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gralloc_priv.h new file mode 100644 index 0000000000..8a333a6bde --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/gralloc_priv.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2011-2021, The Linux Foundation. All rights reserved. + * Not a Contribution + * + * Copyright (C) 2008 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. + */ + +#ifndef __GRALLOC_PRIV_H__ +#define __GRALLOC_PRIV_H__ + +#include +#include + +#include "QtiGrallocDefs.h" +#include "gr_priv_handle.h" + +//#pragma message "Warning: gralloc_priv.h is deprecated" + +#define GRALLOC_PROP_PREFIX "vendor.gralloc." +#define GRALLOC_PROP(prop_name) GRALLOC_PROP_PREFIX prop_name + +#define DISABLE_UBWC_PROP GRALLOC_PROP("disable_ubwc") +#define DISABLE_AHARDWAREBUFFER_PROP GRALLOC_PROP("disable_ahardware_buffer") +#define ENABLE_FB_UBWC_PROP GRALLOC_PROP("enable_fb_ubwc") +#define MAP_FB_MEMORY_PROP GRALLOC_PROP("map_fb_memory") +#define USE_SYSTEM_HEAP_FOR_SENSORS GRALLOC_PROP("use_system_heap_for_sensors") + +#define ROUND_UP_PAGESIZE(x) roundUpToPageSize(x) +inline int roundUpToPageSize(int x) { + return (x + (getpagesize() - 1)) & ~(getpagesize() - 1); +} + +/* Legacy gralloc1 definitions */ +/* Some clients may still be using the old flags */ +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC_USAGE_PRIVATE_ADSP_HEAP +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC_USAGE_PRIVATE_ALLOC_UBWC +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC_USAGE_PRIVATE_UNCACHED +#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC_USAGE_PRIVATE_MM_HEAP +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT GRALLOC_USAGE_PRIVATE_10BIT +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP +#define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP +#define GRALLOC1_PRODUCER_USAGE_PRIVATE_VIDEO_NV21_ENCODER GRALLOC_USAGE_PRIVATE_VIDEO_NV21_ENCODER + +// for PERFORM API : +#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1 +#define GRALLOC_MODULE_PERFORM_GET_STRIDE 2 +#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE 3 +#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE 4 +#define GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES 5 +#define GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE 6 +#define GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO 7 +#define GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO 8 +#define GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG 9 +#define GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS 10 +#define GRALLOC_MODULE_PERFORM_GET_IGC 11 +#define GRALLOC_MODULE_PERFORM_SET_IGC 12 +#define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13 +#define GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS 14 +#define GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG 15 +#define GRALLOC_MODULE_PERFORM_GET_GRAPHICS_METADATA 16 + +/* possible values for inverse gamma correction */ +#define HAL_IGC_NOT_SPECIFIED 0 +#define HAL_IGC_s_RGB 1 + +/* Color Space: Values maps to ColorSpace_t in qdMetadata.h */ +#define HAL_CSC_ITU_R_601 0 +#define HAL_CSC_ITU_R_601_FR 1 +#define HAL_CSC_ITU_R_709 2 +#define HAL_CSC_ITU_R_709_FR 3 +#define HAL_CSC_ITU_R_2020 4 +#define HAL_CSC_ITU_R_2020_FR 5 + +/* possible formats for 3D content*/ +enum { + HAL_NO_3D = 0x0, + HAL_3D_SIDE_BY_SIDE_L_R = 0x1, + HAL_3D_SIDE_BY_SIDE_R_L = 0x2, + HAL_3D_TOP_BOTTOM = 0x4, + HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, // unused legacy format +}; + +/* Flag to determine interlaced content + * Value maps to Flags presents in types.hal of QtiMapperextensions + */ +enum { + LAYOUT_INTERLACED_FLAG = 1 << 0, +}; + +#endif // __GRALLOC_PRIV_H__ diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapper.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapper.h new file mode 100644 index 0000000000..ae3bdbba9b --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapper.h @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2016-2022, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include "types/mapper.h" + +namespace vendor::qti::hardware::display::mapperextensions::V1_0 { +struct IQtiMapperExtensions; +} + +namespace android::hardware::graphics::mapper { +namespace V2_0 { + +struct IMapper : public IBase { + struct BufferDescriptorInfo final { + uint32_t width __attribute__((aligned(4))); + uint32_t height __attribute__((aligned(4))); + uint32_t layerCount __attribute__((aligned(4))); + graphics::common::V1_0::PixelFormat format __attribute__((aligned(4))); + hidl_bitfield usage __attribute__((aligned(8))); + }; + + struct Rect final { + int32_t left __attribute__((aligned(4))); + int32_t top __attribute__((aligned(4))); + int32_t width __attribute__((aligned(4))); + int32_t height __attribute__((aligned(4))); + }; + + static sp getService(const std::string& /* serviceName */, const bool /* getStub */); +}; + +} // namespace V2_0 +namespace V3_0 { + +struct IMapper : public IBase { + static sp getService(const std::string& /* serviceName */, const bool /* getStub */); +}; + +} // namespace V3_0 +namespace V4_0 { + +struct IMapper : public IBase { + static sp getService(const std::string& /* serviceName */, const bool /* getStub */); +}; + +} // namespace V4_0 +} // namespace android::hardware::graphics::mapper + +namespace vendor::qti::hardware::display::mapper { +namespace V4_0 { + +struct IQtiMapper : public IBase { + static Return> castFrom(const sp& /* parent */, + bool /* emitError */); +}; + +} // namespace V4_0 +namespace V3_0 { + +struct IQtiMapper : public IBase { + static Return> castFrom(const sp& /* parent */, + bool /* emitError */); +}; + +} // namespace V3_0 +namespace V2_0 { + +struct IQtiMapper : public IBase { + using createDescriptor_cb = std::function& descriptor)>; + virtual Return createDescriptor( + const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, + createDescriptor_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using importBuffer_cb = std::function; + virtual Return importBuffer(const hidl_handle& rawHandle, importBuffer_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return freeBuffer(void* buffer) { + ALOGE("%s", __func__); + std::terminate(); + } + + using lock_cb = std::function; + virtual Return lock(void* buffer, + hidl_bitfield cpuUsage, + const graphics::mapper::V2_0::IMapper::Rect& accessRegion, + const hidl_handle& acquireFence, lock_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using lockYCbCr_cb = std::function; + virtual Return lockYCbCr(void* buffer, + hidl_bitfield cpuUsage, + const graphics::mapper::V2_0::IMapper::Rect& accessRegion, + const hidl_handle& acquireFence, lockYCbCr_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using unlock_cb = + std::function; + virtual Return unlock(void* buffer, unlock_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual Return validateBufferSize( + void* buffer, const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, + uint32_t stride) { + ALOGE("%s", __func__); + std::terminate(); + } + + using getTransportSize_cb = + std::function; + virtual Return getTransportSize(void* buffer, getTransportSize_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using createDescriptor_2_1_cb = std::function& descriptor)>; + virtual Return createDescriptor_2_1( + const graphics::mapper::V2_0::IMapper::BufferDescriptorInfo& descriptorInfo, + createDescriptor_2_1_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + using getMapperExtensions_cb = + std::function& extensions)>; + virtual Return getMapperExtensions(getMapperExtensions_cb _hidl_cb); + + static Return> castFrom(const sp& /* parent */, + bool /* emitError */); +}; + +} // namespace V2_0 +} // namespace vendor::qti::hardware::display::mapper diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapperextensions.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapperextensions.h new file mode 100644 index 0000000000..078cb90b26 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/mapperextensions.h @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2016-2022, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include "gralloc_priv.h" +#include "types/mapperextensions.h" + +namespace vendor::qti::hardware::display::mapperextensions { +namespace V1_0 { + +struct IQtiMapperExtensions : public IBase { + IQtiMapperExtensions(){}; +}; + +} // namespace V1_0 +namespace V1_1 { +using Error = V1_0::Error; +using PlaneLayout = V1_0::PlaneLayout; + +struct IQtiMapperExtensions : public IBase { + IQtiMapperExtensions(); + + gralloc1_device_t* gralloc; + GRALLOC1_PFN_PERFORM perform; + + using getMapSecureBufferFlag_cb = std::function; + virtual ::android::hardware::Return getMapSecureBufferFlag( + void* buffer, getMapSecureBufferFlag_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, passthrough + using getInterlacedFlag_cb = std::function; + virtual ::android::hardware::Return getInterlacedFlag(void* buffer, + getInterlacedFlag_cb _hidl_cb); + + using getCustomDimensions_cb = + std::function; + virtual ::android::hardware::Return getCustomDimensions(void* buffer, + getCustomDimensions_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, passthrough + using getRgbDataAddress_cb = std::function; + virtual ::android::hardware::Return getRgbDataAddress(void* buffer, + getRgbDataAddress_cb _hidl_cb); + + using calculateBufferAttributes_cb = + std::function; + virtual ::android::hardware::Return calculateBufferAttributes( + int32_t width, int32_t height, int32_t format, uint64_t usage, + calculateBufferAttributes_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, passhthrough + using getColorSpace_cb = std::function; + virtual ::android::hardware::Return getColorSpace(void* buffer, getColorSpace_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, passthrough with hidl fixups + using getYuvPlaneInfo_cb = std::function& layout)>; + virtual ::android::hardware::Return getYuvPlaneInfo(void* buffer, + getYuvPlaneInfo_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + virtual ::android::hardware::Return< + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error> + setSingleBufferMode(void* buffer, bool enable) { + ALOGE("%s", __func__); + std::terminate(); + } + + using getCustomFormatFlags_cb = + std::function; + virtual ::android::hardware::Return getCustomFormatFlags(int32_t format, uint64_t usage, + getCustomFormatFlags_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, cast private data with no passthrough + using getFd_cb = std::function; + virtual ::android::hardware::Return getFd(void* buffer, getFd_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getWidth_cb = std::function; + virtual ::android::hardware::Return getWidth(void* buffer, getWidth_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getHeight_cb = std::function; + virtual ::android::hardware::Return getHeight(void* buffer, getHeight_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getOffset_cb = std::function; + virtual ::android::hardware::Return getOffset(void* buffer, getOffset_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getSize_cb = std::function; + virtual ::android::hardware::Return getSize(void* buffer, getSize_cb _hidl_cb); + + using getUnalignedWidth_cb = + std::function; + virtual ::android::hardware::Return getUnalignedWidth(void* buffer, + getUnalignedWidth_cb _hidl_cb); + + using getUnalignedHeight_cb = + std::function; + virtual ::android::hardware::Return getUnalignedHeight(void* buffer, + getUnalignedHeight_cb _hidl_cb); + + using getLayerCount_cb = std::function; + virtual ::android::hardware::Return getLayerCount(void* buffer, getLayerCount_cb _hidl_cb); + + using getId_cb = std::function; + virtual ::android::hardware::Return getId(void* buffer, getId_cb _hidl_cb); + + using getUsageFlags_cb = std::function; + virtual ::android::hardware::Return getUsageFlags(void* buffer, getUsageFlags_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getFormat_cb = std::function; + virtual ::android::hardware::Return getFormat(void* buffer, getFormat_cb _hidl_cb); + + // Used, cast private data with no passthrough + using getPrivateFlags_cb = std::function; + virtual ::android::hardware::Return getPrivateFlags(void* buffer, + getPrivateFlags_cb _hidl_cb); + + using getSurfaceMetadata_cb = std::function; + virtual ::android::hardware::Return getSurfaceMetadata(void* buffer, + getSurfaceMetadata_cb _hidl_cb) { + ALOGE("%s", __func__); + std::terminate(); + } + + // Used, PAIN + using getFormatLayout_cb = std::function& plane_info)>; + virtual ::android::hardware::Return getFormatLayout(int32_t format, uint64_t usage, + int32_t flags, int32_t width, + int32_t height, + getFormatLayout_cb _hidl_cb); + + // V1.1, Used, passthrough + virtual ::android::hardware::Return< + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error> + getSurfaceMetadata_V1(void* buffer, void* metadata) { + ALOGE("%s", __func__); + std::terminate(); + } + + static Return> castFrom( + android::sp const& /* parent */, bool /* emitError */); +}; + +} // namespace V1_1 +} // namespace vendor::qti::hardware::display::mapperextensions diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/common.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/common.h new file mode 100644 index 0000000000..6f327baf3b --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/common.h @@ -0,0 +1,6744 @@ +#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H +#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace common { +namespace V1_0 { + +// Forward declaration for forward reference support: +enum class PixelFormat : int32_t; +enum class BufferUsage : uint64_t; +enum class Transform : int32_t; +enum class Dataspace : int32_t; +enum class ColorMode : int32_t; +enum class ColorTransform : int32_t; +enum class Hdr : int32_t; + +/** + * Common enumeration and structure definitions for all graphics HALs. + * + * + * Pixel formats for graphics buffers. + */ +enum class PixelFormat : int32_t { + /** + * 32-bit format that has 8-bit R, G, B, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBA_8888 = 1 /* 0x1 */, + /** + * 32-bit format that has 8-bit R, G, B, and unused components, in that + * order, from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBX_8888 = 2 /* 0x2 */, + /** + * 24-bit format that has 8-bit R, G, and B components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGB_888 = 3 /* 0x3 */, + /** + * 16-bit packed format that has 5-bit R, 6-bit G, and 5-bit B components, + * in that order, from the most-sigfinicant bits to the least-significant + * bits. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGB_565 = 4 /* 0x4 */, + /** + * 32-bit format that has 8-bit B, G, R, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + BGRA_8888 = 5 /* 0x5 */, + /** + * Legacy formats deprecated in favor of YCBCR_420_888. + */ + YCBCR_422_SP = 16 /* 0x10 */, + YCRCB_420_SP = 17 /* 0x11 */, + YCBCR_422_I = 20 /* 0x14 */, + /** + * 64-bit format that has 16-bit R, G, B, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are signed floats, whose interpretation is defined + * by the dataspace. + */ + RGBA_FP16 = 22 /* 0x16 */, + /** + * RAW16 is a single-channel, 16-bit, little endian format, typically + * representing raw Bayer-pattern images from an image sensor, with minimal + * processing. + * + * The exact pixel layout of the data in the buffer is sensor-dependent, and + * needs to be queried from the camera device. + * + * Generally, not all 16 bits are used; more common values are 10 or 12 + * bits. If not all bits are used, the lower-order bits are filled first. + * All parameters to interpret the raw data (black and white points, + * color space, etc) must be queried from the camera device. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * - strides are specified in pixels, not in bytes + * + * size = stride * height * 2 + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW16 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data, layout is as + * | defined above. + * Dataspace::DEPTH | Unprocessed implementation-dependent raw + * | depth measurements, opaque with 16 bit + * | samples. + * Other | Unsupported + */ + RAW16 = 32 /* 0x20 */, + /** + * BLOB is used to carry task-specific data which does not have a standard + * image structure. The details of the format are left to the two + * endpoints. + * + * A typical use case is for transporting JPEG-compressed images from the + * Camera HAL to the framework or to applications. + * + * Buffers of this format must have a height of 1, and width equal to their + * size in bytes. + * + * The mapping of the dataspace to buffer contents for BLOB is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::JFIF | An encoded JPEG image + * Dataspace::DEPTH | An android_depth_points buffer + * Dataspace::SENSOR | Sensor event data. + * Other | Unsupported + */ + BLOB = 33 /* 0x21 */, + /** + * A format indicating that the choice of format is entirely up to the + * allocator. + * + * The allocator should examine the usage bits passed in when allocating a + * buffer with this format, and it should derive the pixel format from + * those usage flags. This format must never be used with any of the + * BufferUsage::CPU_* usage flags. + * + * Even when the internally chosen format has an alpha component, the + * clients must assume the alpha vlaue to be 1.0. + * + * The interpretation of the component values is defined by the dataspace. + */ + IMPLEMENTATION_DEFINED = 34 /* 0x22 */, + /** + * This format allows platforms to use an efficient YCbCr/YCrCb 4:2:0 + * buffer layout, while still describing the general format in a + * layout-independent manner. While called YCbCr, it can be used to + * describe formats with either chromatic ordering, as well as + * whole planar or semiplanar layouts. + * + * This format must be accepted by the allocator when BufferUsage::CPU_* + * are set. + * + * Buffers with this format must be locked with IMapper::lockYCbCr. + * Locking with IMapper::lock must return an error. + * + * The interpretation of the component values is defined by the dataspace. + */ + YCBCR_420_888 = 35 /* 0x23 */, + /** + * RAW_OPAQUE is a format for unprocessed raw image buffers coming from an + * image sensor. The actual structure of buffers of this format is + * implementation-dependent. + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW_OPAQUE is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW_OPAQUE = 36 /* 0x24 */, + /** + * RAW10 is a single-channel, 10-bit per pixel, densely packed in each row, + * unprocessed format, usually representing raw Bayer-pattern images coming from + * an image sensor. + * + * In an image buffer with this format, starting from the first pixel of each + * row, each 4 consecutive pixels are packed into 5 bytes (40 bits). Each one + * of the first 4 bytes contains the top 8 bits of each pixel, The fifth byte + * contains the 2 least significant bits of the 4 pixels, the exact layout data + * for each 4 consecutive pixels is illustrated below (Pi[j] stands for the jth + * bit of the ith pixel): + * + * bit 7 bit 0 + * =====|=====|=====|=====|=====|=====|=====|=====| + * Byte 0: |P0[9]|P0[8]|P0[7]|P0[6]|P0[5]|P0[4]|P0[3]|P0[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 1: |P1[9]|P1[8]|P1[7]|P1[6]|P1[5]|P1[4]|P1[3]|P1[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 2: |P2[9]|P2[8]|P2[7]|P2[6]|P2[5]|P2[4]|P2[3]|P2[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 3: |P3[9]|P3[8]|P3[7]|P3[6]|P3[5]|P3[4]|P3[3]|P3[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 4: |P3[1]|P3[0]|P2[1]|P2[0]|P1[1]|P1[0]|P0[1]|P0[0]| + * =============================================== + * + * This format assumes + * - a width multiple of 4 pixels + * - an even height + * - a vertical stride equal to the height + * - strides are specified in bytes, not in pixels + * + * size = stride * height + * + * When stride is equal to width * (10 / 8), there will be no padding bytes at + * the end of each row, the entire image data is densely packed. When stride is + * larger than width * (10 / 8), padding bytes will be present at the end of each + * row (including the last row). + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW10 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW10 = 37 /* 0x25 */, + /** + * RAW12 is a single-channel, 12-bit per pixel, densely packed in each row, + * unprocessed format, usually representing raw Bayer-pattern images coming from + * an image sensor. + * + * In an image buffer with this format, starting from the first pixel of each + * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first + * and second byte contains the top 8 bits of first and second pixel. The third + * byte contains the 4 least significant bits of the two pixels, the exact layout + * data for each two consecutive pixels is illustrated below (Pi[j] stands for + * the jth bit of the ith pixel): + * + * bit 7 bit 0 + * ======|======|======|======|======|======|======|======| + * Byte 0: |P0[11]|P0[10]|P0[ 9]|P0[ 8]|P0[ 7]|P0[ 6]|P0[ 5]|P0[ 4]| + * |------|------|------|------|------|------|------|------| + * Byte 1: |P1[11]|P1[10]|P1[ 9]|P1[ 8]|P1[ 7]|P1[ 6]|P1[ 5]|P1[ 4]| + * |------|------|------|------|------|------|------|------| + * Byte 2: |P1[ 3]|P1[ 2]|P1[ 1]|P1[ 0]|P0[ 3]|P0[ 2]|P0[ 1]|P0[ 0]| + * ======================================================= + * + * This format assumes: + * - a width multiple of 4 pixels + * - an even height + * - a vertical stride equal to the height + * - strides are specified in bytes, not in pixels + * + * size = stride * height + * + * When stride is equal to width * (12 / 8), there will be no padding bytes at + * the end of each row, the entire image data is densely packed. When stride is + * larger than width * (12 / 8), padding bytes will be present at the end of + * each row (including the last row). + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW12 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW12 = 38 /* 0x26 */, + /** + * 0x27 to 0x2A are reserved for flexible formats + * + * + * 32-bit packed format that has 2-bit A, 10-bit B, G, and R components, + * in that order, from the most-sigfinicant bits to the least-significant + * bits. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBA_1010102 = 43 /* 0x2B */, + /** + * 0x100 - 0x1FF + * + * This range is reserved for vendor extensions. Formats in this range + * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not + * have an alpha component. + * + * + * Y8 is a YUV planar format comprised of a WxH Y plane, with each pixel + * being represented by 8 bits. It is equivalent to just the Y plane from + * YV12. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * + * size = stride * height + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + Y8 = 538982489 /* 0x20203859 */, + /** + * Y16 is a YUV planar format comprised of a WxH Y plane, with each pixel + * being represented by 16 bits. It is just like Y8, but has double the + * bits per pixel (little endian). + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * - strides are specified in pixels, not in bytes + * + * size = stride * height * 2 + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. When the dataspace is + * Dataspace::DEPTH, each pixel is a distance value measured by a depth + * camera, plus an associated confidence value. + */ + Y16 = 540422489 /* 0x20363159 */, + /** + * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed + * by (W/2) x (H/2) Cr and Cb planes. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * + * y_size = stride * height + * c_stride = ALIGN(stride/2, 16) + * c_size = c_stride * height/2 + * size = y_size + c_size * 2 + * cr_offset = y_size + * cb_offset = y_size + c_size + * + * This range is reserved for vendor extensions. Formats in this range + * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not + * have an alpha component. + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::GPU_TEXTURE + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + YV12 = 842094169 /* 0x32315659 */, +}; + +/** + * Buffer usage definitions. + */ +enum class BufferUsage : uint64_t { + /** + * bit 0-3 is an enum + */ + CPU_READ_MASK = 15ull /* 0xfULL */, + /** + * buffer is never read by CPU + */ + CPU_READ_NEVER = 0ull, + /** + * buffer is rarely read by CPU + */ + CPU_READ_RARELY = 2ull, + /** + * buffer is often read by CPU + */ + CPU_READ_OFTEN = 3ull, + /** + * bit 4-7 is an enum + */ + CPU_WRITE_MASK = 240ull /* (0xfULL << 4) */, + /** + * buffer is never written by CPU + */ + CPU_WRITE_NEVER = 0ull /* (0 << 4) */, + /** + * buffer is rarely written by CPU + */ + CPU_WRITE_RARELY = 32ull /* (2 << 4) */, + /** + * buffer is often written by CPU + */ + CPU_WRITE_OFTEN = 48ull /* (3 << 4) */, + /** + * buffer is used as a GPU texture + */ + GPU_TEXTURE = 256ull /* (1ULL << 8) */, + /** + * buffer is used as a GPU render target + */ + GPU_RENDER_TARGET = 512ull /* (1ULL << 9) */, + /** + * bit 10 must be zero + * + * + * buffer is used as a composer HAL overlay layer + */ + COMPOSER_OVERLAY = 2048ull /* (1ULL << 11) */, + /** + * buffer is used as a composer HAL client target + */ + COMPOSER_CLIENT_TARGET = 4096ull /* (1ULL << 12) */, + /** + * bit 13 must be zero + * + * + * Buffer is allocated with hardware-level protection against copying the + * contents (or information derived from the contents) into unprotected + * memory. + */ + PROTECTED = 16384ull /* (1ULL << 14) */, + /** + * buffer is used as a hwcomposer HAL cursor layer + */ + COMPOSER_CURSOR = 32768ull /* (1ULL << 15) */, + /** + * buffer is used as a video encoder input + */ + VIDEO_ENCODER = 65536ull /* (1ULL << 16) */, + /** + * buffer is used as a camera HAL output + */ + CAMERA_OUTPUT = 131072ull /* (1ULL << 17) */, + /** + * buffer is used as a camera HAL input + */ + CAMERA_INPUT = 262144ull /* (1ULL << 18) */, + /** + * bit 19 must be zero + * + * + * buffer is used as a renderscript allocation + */ + RENDERSCRIPT = 1048576ull /* (1ULL << 20) */, + /** + * bit 21 must be zero + * + * + * buffer is used as a video decoder output + */ + VIDEO_DECODER = 4194304ull /* (1ULL << 22) */, + /** + * buffer is used as a sensor direct report output + */ + SENSOR_DIRECT_DATA = 8388608ull /* (1ULL << 23) */, + /** + * buffer is used as as an OpenGL shader storage or uniform + * buffer object + */ + GPU_DATA_BUFFER = 16777216ull /* (1ULL << 24) */, + /** + * bits 25-27 must be zero and are reserved for future versions + * + * + * bits 28-31 are reserved for vendor extensions + */ + VENDOR_MASK = 4026531840ull /* (0xfULL << 28) */, + /** + * bits 32-47 must be zero and are reserved for future versions + * + * + * bits 48-63 are reserved for vendor extensions + */ + VENDOR_MASK_HI = 18446462598732840960ull /* (0xffffULL << 48) */, +}; + +/** + * Transformation definitions + */ +enum class Transform : int32_t { + /** + * Horizontal flip. FLIP_H/FLIP_V is applied before ROT_90. + */ + FLIP_H = 1 /* (1 << 0) */, + /** + * Vertical flip. FLIP_H/FLIP_V is applied before ROT_90. + */ + FLIP_V = 2 /* (1 << 1) */, + /** + * 90 degree clockwise rotation. FLIP_H/FLIP_V is applied before ROT_90. + */ + ROT_90 = 4 /* (1 << 2) */, + /** + * Commonly used combinations. + */ + ROT_180 = 3 /* (FLIP_H | FLIP_V) */, + ROT_270 = 7 /* ((FLIP_H | FLIP_V) | ROT_90) */, +}; + +/** + * Dataspace Definitions + * ====================== + * + * Dataspace is the definition of how pixel values should be interpreted. + * + * For many formats, this is the colorspace of the image data, which includes + * primaries (including white point) and the transfer characteristic function, + * which describes both gamma curve and numeric range (within the bit depth). + * + * Other dataspaces include depth measurement data from a depth camera. + * + * A dataspace is comprised of a number of fields. + * + * Version + * -------- + * The top 2 bits represent the revision of the field specification. This is + * currently always 0. + * + * + * bits 31-30 29 - 0 + * +-----+----------------------------------------------------+ + * fields | Rev | Revision specific fields | + * +-----+----------------------------------------------------+ + * + * Field layout for version = 0: + * ---------------------------- + * + * A dataspace is comprised of the following fields: + * Standard + * Transfer function + * Range + * + * bits 31-30 29-27 26 - 22 21 - 16 15 - 0 + * +-----+-----+--------+--------+----------------------------+ + * fields | 0 |Range|Transfer|Standard| Legacy and custom | + * +-----+-----+--------+--------+----------------------------+ + * VV RRR TTTTT SSSSSS LLLLLLLL LLLLLLLL + * + * If range, transfer and standard fields are all 0 (e.g. top 16 bits are + * all zeroes), the bottom 16 bits contain either a legacy dataspace value, + * or a custom value. + */ +enum class Dataspace : int32_t { + /** + * Default-assumption data space, when not explicitly specified. + * + * It is safest to assume the buffer is an image with sRGB primaries and + * encoding ranges, but the consumer and/or the producer of the data may + * simply be using defaults. No automatic gamma transform should be + * expected, except for a possible display gamma transform when drawn to a + * screen. + */ + UNKNOWN = 0 /* 0x0 */, + /** + * Arbitrary dataspace with manually defined characteristics. Definition + * for colorspaces or other meaning must be communicated separately. + * + * This is used when specifying primaries, transfer characteristics, + * etc. separately. + * + * A typical use case is in video encoding parameters (e.g. for H.264), + * where a colorspace can have separately defined primaries, transfer + * characteristics, etc. + */ + ARBITRARY = 1 /* 0x1 */, + /** + * Color-description aspects + * + * The following aspects define various characteristics of the color + * specification. These represent bitfields, so that a data space value + * can specify each of them independently. + */ + STANDARD_SHIFT = 16, + /** + * Standard aspect + * + * Defines the chromaticity coordinates of the source primaries in terms of + * the CIE 1931 definition of x and y specified in ISO 11664-1. + */ + STANDARD_MASK = 4128768 /* (63 << STANDARD_SHIFT) */, + /** + * Chromacity coordinates are unknown or are determined by the application. + * Implementations shall use the following suggested standards: + * + * All YCbCr formats: BT709 if size is 720p or larger (since most video + * content is letterboxed this corresponds to width is + * 1280 or greater, or height is 720 or greater). + * BT601_625 if size is smaller than 720p or is JPEG. + * All RGB formats: BT709. + * + * For all other formats standard is undefined, and implementations should use + * an appropriate standard for the data represented. + */ + STANDARD_UNSPECIFIED = 0 /* (0 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2126, KB = 0.0722 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT709 = 65536 /* (1 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + */ + STANDARD_BT601_625 = 131072 /* (2 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT601_625_UNADJUSTED = 196608 /* (3 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + */ + STANDARD_BT601_525 = 262144 /* (4 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation + * for RGB conversion (as in SMPTE 240M). + */ + STANDARD_BT601_525_UNADJUSTED = 327680 /* (5 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT2020 = 393216 /* (6 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation + * for RGB conversion using the linear domain. + */ + STANDARD_BT2020_CONSTANT_LUMINANCE = 458752 /* (7 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.21 0.71 + * blue 0.14 0.08 + * red 0.67 0.33 + * white (C) 0.310 0.316 + * + * Use the unadjusted KR = 0.30, KB = 0.11 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT470M = 524288 /* (8 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.243 0.692 + * blue 0.145 0.049 + * red 0.681 0.319 + * white (C) 0.310 0.316 + * + * Use the unadjusted KR = 0.254, KB = 0.068 luminance interpretation + * for RGB conversion. + */ + STANDARD_FILM = 589824 /* (9 << STANDARD_SHIFT) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. (DCI-P3) + * Primaries: x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + */ + STANDARD_DCI_P3 = 655360 /* (10 << STANDARD_SHIFT) */, + /** + * Adobe RGB + * Primaries: x y + * green 0.210 0.710 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + */ + STANDARD_ADOBE_RGB = 720896 /* (11 << STANDARD_SHIFT) */, + TRANSFER_SHIFT = 22, + /** + * Transfer aspect + * + * Transfer characteristics are the opto-electronic transfer characteristic + * at the source as a function of linear optical intensity (luminance). + * + * For digital signals, E corresponds to the recorded value. Normally, the + * transfer function is applied in RGB space to each of the R, G and B + * components independently. This may result in color shift that can be + * minized by applying the transfer function in Lab space only for the L + * component. Implementation may apply the transfer function in RGB space + * for all pixel formats if desired. + */ + TRANSFER_MASK = 130023424 /* (31 << TRANSFER_SHIFT) */, + /** + * Transfer characteristics are unknown or are determined by the + * application. + * + * Implementations should use the following transfer functions: + * + * For YCbCr formats: use TRANSFER_SMPTE_170M + * For RGB formats: use TRANSFER_SRGB + * + * For all other formats transfer function is undefined, and implementations + * should use an appropriate standard for the data represented. + */ + TRANSFER_UNSPECIFIED = 0 /* (0 << TRANSFER_SHIFT) */, + /** + * Transfer characteristic curve: + * E = L + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_LINEAR = 4194304 /* (1 << TRANSFER_SHIFT) */, + /** + * Transfer characteristic curve: + * + * E = 1.055 * L^(1/2.4) - 0.055 for 0.0031308 <= L <= 1 + * = 12.92 * L for 0 <= L < 0.0031308 + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_SRGB = 8388608 /* (2 << TRANSFER_SHIFT) */, + /** + * BT.601 525, BT.601 625, BT.709, BT.2020 + * + * Transfer characteristic curve: + * E = 1.099 * L ^ 0.45 - 0.099 for 0.018 <= L <= 1 + * = 4.500 * L for 0 <= L < 0.018 + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_SMPTE_170M = 12582912 /* (3 << TRANSFER_SHIFT) */, + /** + * Assumed display gamma 2.2. + * + * Transfer characteristic curve: + * E = L ^ (1/2.2) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_2 = 16777216 /* (4 << TRANSFER_SHIFT) */, + /** + * display gamma 2.6. + * + * Transfer characteristic curve: + * E = L ^ (1/2.6) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_6 = 20971520 /* (5 << TRANSFER_SHIFT) */, + /** + * display gamma 2.8. + * + * Transfer characteristic curve: + * E = L ^ (1/2.8) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_8 = 25165824 /* (6 << TRANSFER_SHIFT) */, + /** + * SMPTE ST 2084 (Dolby Perceptual Quantizer) + * + * Transfer characteristic curve: + * E = ((c1 + c2 * L^n) / (1 + c3 * L^n)) ^ m + * c1 = c3 - c2 + 1 = 3424 / 4096 = 0.8359375 + * c2 = 32 * 2413 / 4096 = 18.8515625 + * c3 = 32 * 2392 / 4096 = 18.6875 + * m = 128 * 2523 / 4096 = 78.84375 + * n = 0.25 * 2610 / 4096 = 0.1593017578125 + * L - luminance of image 0 <= L <= 1 for HDR colorimetry. + * L = 1 corresponds to 10000 cd/m2 + * E - corresponding electrical signal + */ + TRANSFER_ST2084 = 29360128 /* (7 << TRANSFER_SHIFT) */, + /** + * ARIB STD-B67 Hybrid Log Gamma + * + * Transfer characteristic curve: + * E = r * L^0.5 for 0 <= L <= 1 + * = a * ln(L - b) + c for 1 < L + * a = 0.17883277 + * b = 0.28466892 + * c = 0.55991073 + * r = 0.5 + * L - luminance of image 0 <= L for HDR colorimetry. L = 1 corresponds + * to reference white level of 100 cd/m2 + * E - corresponding electrical signal + */ + TRANSFER_HLG = 33554432 /* (8 << TRANSFER_SHIFT) */, + RANGE_SHIFT = 27, + /** + * Range aspect + * + * Defines the range of values corresponding to the unit range of 0-1. + * This is defined for YCbCr only, but can be expanded to RGB space. + */ + RANGE_MASK = 939524096 /* (7 << RANGE_SHIFT) */, + /** + * Range is unknown or are determined by the application. Implementations + * shall use the following suggested ranges: + * + * All YCbCr formats: limited range. + * All RGB or RGBA formats (including RAW and Bayer): full range. + * All Y formats: full range + * + * For all other formats range is undefined, and implementations should use + * an appropriate range for the data represented. + */ + RANGE_UNSPECIFIED = 0 /* (0 << RANGE_SHIFT) */, + /** + * Full range uses all values for Y, Cb and Cr from + * 0 to 2^b-1, where b is the bit depth of the color format. + */ + RANGE_FULL = 134217728 /* (1 << RANGE_SHIFT) */, + /** + * Limited range uses values 16/256*2^b to 235/256*2^b for Y, and + * 1/16*2^b to 15/16*2^b for Cb, Cr, R, G and B, where b is the bit depth of + * the color format. + * + * E.g. For 8-bit-depth formats: + * Luma (Y) samples should range from 16 to 235, inclusive + * Chroma (Cb, Cr) samples should range from 16 to 240, inclusive + * + * For 10-bit-depth formats: + * Luma (Y) samples should range from 64 to 940, inclusive + * Chroma (Cb, Cr) samples should range from 64 to 960, inclusive + */ + RANGE_LIMITED = 268435456 /* (2 << RANGE_SHIFT) */, + /** + * Extended range is used for scRGB. Intended for use with + * floating point pixel formats. [0.0 - 1.0] is the standard + * sRGB space. Values outside the range 0.0 - 1.0 can encode + * color outside the sRGB gamut. + * Used to blend / merge multiple dataspaces on a single display. + */ + RANGE_EXTENDED = 402653184 /* (3 << RANGE_SHIFT) */, + /** + * Legacy dataspaces + * + * + * sRGB linear encoding: + * + * The red, green, and blue components are stored in sRGB space, but + * are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are encoded using the full range ([0,255] for 8-bit) for all + * components. + */ + SRGB_LINEAR = 512 /* 0x200 */, + V0_SRGB_LINEAR = 138477568 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * scRGB linear encoding: + * + * The red, green, and blue components are stored in extended sRGB space, + * but are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are floating point. + * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits. + * Values beyond the range [0.0 - 1.0] would correspond to other colors + * spaces and/or HDR content. + */ + V0_SCRGB_LINEAR = 406913024 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_EXTENDED) */, + /** + * sRGB gamma encoding: + * + * The red, green and blue components are stored in sRGB space, and + * converted to linear space when read, using the SRGB transfer function + * for each of the R, G and B components. When written, the inverse + * transformation is performed. + * + * The alpha component, if present, is always stored in linear space and + * is left unmodified when read or written. + * + * Use full range and BT.709 standard. + */ + SRGB = 513 /* 0x201 */, + V0_SRGB = 142671872 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_FULL) */, + /** + * scRGB: + * + * The red, green, and blue components are stored in extended sRGB space, + * but are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are floating point. + * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits. + * Values beyond the range [0.0 - 1.0] would correspond to other colors + * spaces and/or HDR content. + */ + V0_SCRGB = 411107328 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_EXTENDED) */, + /** + * YCbCr Colorspaces + * ----------------- + * + * Primaries are given using (x,y) coordinates in the CIE 1931 definition + * of x and y specified by ISO 11664-1. + * + * Transfer characteristics are the opto-electronic transfer characteristic + * at the source as a function of linear optical intensity (luminance). + * + * + * JPEG File Interchange Format (JFIF) + * + * Same model as BT.601-625, but all values (Y, Cb, Cr) range from 0 to 255 + * + * Use full range, BT.601 transfer and BT.601_625 standard. + */ + JFIF = 257 /* 0x101 */, + V0_JFIF = 146931712 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_FULL) */, + /** + * ITU-R Recommendation 601 (BT.601) - 625-line + * + * Standard-definition television, 625 Lines (PAL) + * + * Use limited range, BT.601 transfer and BT.601_625 standard. + */ + BT601_625 = 258 /* 0x102 */, + V0_BT601_625 = 281149440 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * ITU-R Recommendation 601 (BT.601) - 525-line + * + * Standard-definition television, 525 Lines (NTSC) + * + * Use limited range, BT.601 transfer and BT.601_525 standard. + */ + BT601_525 = 259 /* 0x103 */, + V0_BT601_525 = 281280512 /* ((STANDARD_BT601_525 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * ITU-R Recommendation 709 (BT.709) + * + * High-definition television + * + * Use limited range, BT.709 transfer and BT.709 standard. + */ + BT709 = 260 /* 0x104 */, + V0_BT709 = 281083904 /* ((STANDARD_BT709 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. + * + * Digital Cinema DCI-P3 + * + * Use full range, linear transfer and D65 DCI-P3 standard + */ + DCI_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. + * + * Digital Cinema DCI-P3 + * + * Use full range, gamma 2.6 transfer and D65 DCI-P3 standard + * Note: Application is responsible for gamma encoding the data as + * a 2.6 gamma encoding is not supported in HW. + */ + DCI_P3 = 155844608 /* ((STANDARD_DCI_P3 | TRANSFER_GAMMA2_6) | RANGE_FULL) */, + /** + * Display P3 + * + * Display P3 uses same primaries and white-point as DCI-P3 + * linear transfer function makes this the same as DCI_P3_LINEAR. + */ + DISPLAY_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * Display P3 + * + * Use same primaries and white-point as DCI-P3 + * but sRGB transfer function. + */ + DISPLAY_P3 = 143261696 /* ((STANDARD_DCI_P3 | TRANSFER_SRGB) | RANGE_FULL) */, + /** + * Adobe RGB + * + * Use full range, gamma 2.2 transfer and Adobe RGB primaries + * Note: Application is responsible for gamma encoding the data as + * a 2.2 gamma encoding is not supported in HW. + */ + ADOBE_RGB = 151715840 /* ((STANDARD_ADOBE_RGB | TRANSFER_GAMMA2_2) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, linear transfer and BT2020 standard + */ + BT2020_LINEAR = 138805248 /* ((STANDARD_BT2020 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, BT.709 transfer and BT2020 standard + */ + BT2020 = 147193856 /* ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, SMPTE 2084 (PQ) transfer and BT2020 standard + */ + BT2020_PQ = 163971072 /* ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_FULL) */, + /** + * Data spaces for non-color formats + * + * + * The buffer contains depth ranging measurements from a depth camera. + * This value is valid with formats: + * HAL_PIXEL_FORMAT_Y16: 16-bit samples, consisting of a depth measurement + * and an associated confidence value. The 3 MSBs of the sample make + * up the confidence value, and the low 13 LSBs of the sample make up + * the depth measurement. + * For the confidence section, 0 means 100% confidence, 1 means 0% + * confidence. The mapping to a linear float confidence value between + * 0.f and 1.f can be obtained with + * float confidence = (((depthSample >> 13) - 1) & 0x7) / 7.0f; + * The depth measurement can be extracted simply with + * uint16_t range = (depthSample & 0x1FFF); + * HAL_PIXEL_FORMAT_BLOB: A depth point cloud, as + * a variable-length float (x,y,z, confidence) coordinate point list. + * The point cloud will be represented with the android_depth_points + * structure. + */ + DEPTH = 4096 /* 0x1000 */, + /** + * The buffer contains sensor events from sensor direct report. + * This value is valid with formats: + * HAL_PIXEL_FORMAT_BLOB: an array of sensor event structure that forms + * a lock free queue. Format of sensor event structure is specified + * in Sensors HAL. + */ + SENSOR = 4097 /* 0x1001 */, +}; + +/** + * Color modes that may be supported by a display. + * + * Definitions: + * Rendering intent generally defines the goal in mapping a source (input) + * color to a destination device color for a given color mode. + * + * It is important to keep in mind three cases where mapping may be applied: + * 1. The source gamut is much smaller than the destination (display) gamut + * 2. The source gamut is much larger than the destination gamut (this will + * ordinarily be handled using colorimetric rendering, below) + * 3. The source and destination gamuts are roughly equal, although not + * completely overlapping + * Also, a common requirement for mappings is that skin tones should be + * preserved, or at least remain natural in appearance. + * + * Colorimetric Rendering Intent (All cases): + * Colorimetric indicates that colors should be preserved. In the case + * that the source gamut lies wholly within the destination gamut or is + * about the same (#1, #3), this will simply mean that no manipulations + * (no saturation boost, for example) are applied. In the case where some + * source colors lie outside the destination gamut (#2, #3), those will + * need to be mapped to colors that are within the destination gamut, + * while the already in-gamut colors remain unchanged. + * + * Non-colorimetric transforms can take many forms. There are no hard + * rules and it's left to the implementation to define. + * Two common intents are described below. + * + * Stretched-Gamut Enhancement Intent (Source < Destination): + * When the destination gamut is much larger than the source gamut (#1), the + * source primaries may be redefined to reflect the full extent of the + * destination space, or to reflect an intermediate gamut. + * Skin-tone preservation would likely be applied. An example might be sRGB + * input displayed on a DCI-P3 capable device, with skin-tone preservation. + * + * Within-Gamut Enhancement Intent (Source >= Destination): + * When the device (destination) gamut is not larger than the source gamut + * (#2 or #3), but the appearance of a larger gamut is desired, techniques + * such as saturation boost may be applied to the source colors. Skin-tone + * preservation may be applied. There is no unique method for within-gamut + * enhancement; it would be defined within a flexible color mode. + * + */ +enum class ColorMode : int32_t { + /** + * DEFAULT is the "native" gamut of the display. + * White Point: Vendor/OEM defined + * Panel Gamma: Vendor/OEM defined (typically 2.2) + * Rendering Intent: Vendor/OEM defined (typically 'enhanced') + */ + NATIVE = 0, + /** + * STANDARD_BT601_625 corresponds with display + * settings that implement the ITU-R Recommendation BT.601 + * or Rec 601. Using 625 line version + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_625 = 1, + /** + * Primaries: + * x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation + * for RGB conversion. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_625_UNADJUSTED = 2, + /** + * Primaries: + * x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_525 = 3, + /** + * Primaries: + * x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation + * for RGB conversion (as in SMPTE 240M). + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_525_UNADJUSTED = 4, + /** + * REC709 corresponds with display settings that implement + * the ITU-R Recommendation BT.709 / Rec. 709 for high-definition television. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * HDTV REC709 Inverse Gamma Correction (IGC): V represents normalized + * (with [0 to 1] range) value of R, G, or B. + * + * if Vnonlinear < 0.081 + * Vlinear = Vnonlinear / 4.5 + * else + * Vlinear = ((Vnonlinear + 0.099) / 1.099) ^ (1/0.45) + * + * HDTV REC709 Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.5 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear) ^ 0.45 – 0.099 + */ + STANDARD_BT709 = 5, + /** + * DCI_P3 corresponds with display settings that implement + * SMPTE EG 432-1 and SMPTE RP 431-2 + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + * + * Gamma: 2.6 + */ + DCI_P3 = 6, + /** + * SRGB corresponds with display settings that implement + * the sRGB color space. Uses the same primaries as ITU-R Recommendation + * BT.709 + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * PC/Internet (sRGB) Inverse Gamma Correction (IGC): + * + * if Vnonlinear ≤ 0.03928 + * Vlinear = Vnonlinear / 12.92 + * else + * Vlinear = ((Vnonlinear + 0.055)/1.055) ^ 2.4 + * + * PC/Internet (sRGB) Gamma Correction (GC): + * + * if Vlinear ≤ 0.0031308 + * Vnonlinear = 12.92 * Vlinear + * else + * Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055 + */ + SRGB = 7, + /** + * ADOBE_RGB corresponds with the RGB color space developed + * by Adobe Systems, Inc. in 1998. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.210 0.710 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Gamma: 2.2 + */ + ADOBE_RGB = 8, + /** + * DISPLAY_P3 is a color space that uses the DCI_P3 primaries, + * the D65 white point and the SRGB transfer functions. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + * + * PC/Internet (sRGB) Gamma Correction (GC): + * + * if Vlinear ≤ 0.0030186 + * Vnonlinear = 12.92 * Vlinear + * else + * Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055 + * + * Note: In most cases sRGB transfer function will be fine. + */ + DISPLAY_P3 = 9, +}; + +/** + * Color transforms that may be applied by hardware composer to the whole + * display. + */ +enum class ColorTransform : int32_t { + /** + * Applies no transform to the output color + */ + IDENTITY = 0, + /** + * Applies an arbitrary transform defined by a 4x4 affine matrix + */ + ARBITRARY_MATRIX = 1, + /** + * Applies a transform that inverts the value or luminance of the color, but + * does not modify hue or saturation + */ + VALUE_INVERSE = 2, + /** + * Applies a transform that maps all colors to shades of gray + */ + GRAYSCALE = 3, + /** + * Applies a transform which corrects for protanopic color blindness + */ + CORRECT_PROTANOPIA = 4, + /** + * Applies a transform which corrects for deuteranopic color blindness + */ + CORRECT_DEUTERANOPIA = 5, + /** + * Applies a transform which corrects for tritanopic color blindness + */ + CORRECT_TRITANOPIA = 6, +}; + +/** + * Supported HDR formats. Must be kept in sync with equivalents in Display.java. + */ +enum class Hdr : int32_t { + /** + * Device supports Dolby Vision HDR + */ + DOLBY_VISION = 1, + /** + * Device supports HDR10 + */ + HDR10 = 2, + /** + * Device supports hybrid log-gamma HDR + */ + HLG = 3, +}; + +// +// type declarations for package +// + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::PixelFormat o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, + const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, + const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::PixelFormat e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::PixelFormat e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(uint64_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::BufferUsage o); + +constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, + const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr uint64_t operator|(const uint64_t lhs, + const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, + const uint64_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, + const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr uint64_t operator&(const uint64_t lhs, + const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, + const uint64_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr uint64_t& operator|=(uint64_t& v, + const ::android::hardware::graphics::common::V1_0::BufferUsage e) { + v |= static_cast(e); + return v; +} +constexpr uint64_t& operator&=(uint64_t& v, + const ::android::hardware::graphics::common::V1_0::BufferUsage e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::Transform o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Transform lhs, + const ::android::hardware::graphics::common::V1_0::Transform rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Transform rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Transform lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Transform lhs, + const ::android::hardware::graphics::common::V1_0::Transform rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Transform rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Transform lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Transform e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Transform e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::Dataspace o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, + const ::android::hardware::graphics::common::V1_0::Dataspace rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Dataspace rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, + const ::android::hardware::graphics::common::V1_0::Dataspace rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Dataspace rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Dataspace e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Dataspace e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorMode o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, + const ::android::hardware::graphics::common::V1_0::ColorMode rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::ColorMode rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, + const ::android::hardware::graphics::common::V1_0::ColorMode rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::ColorMode rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::ColorMode e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::ColorMode e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorTransform o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, + const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, + const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::ColorTransform e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::ColorTransform e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_0::Hdr o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Hdr lhs, + const ::android::hardware::graphics::common::V1_0::Hdr rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Hdr rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Hdr lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Hdr lhs, + const ::android::hardware::graphics::common::V1_0::Hdr rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_0::Hdr rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Hdr lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Hdr e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_0::Hdr e) { + v &= static_cast(e); + return v; +} + +// +// type header definitions for package +// + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::PixelFormat>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::PixelFormat> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888)) { + os += (first ? "" : " | "); + os += "RGBA_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888)) { + os += (first ? "" : " | "); + os += "RGBX_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888)) { + os += (first ? "" : " | "); + os += "RGB_888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565)) { + os += (first ? "" : " | "); + os += "RGB_565"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888)) { + os += (first ? "" : " | "); + os += "BGRA_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP) == + static_cast( + ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP)) { + os += (first ? "" : " | "); + os += "YCBCR_422_SP"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP) == + static_cast( + ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP)) { + os += (first ? "" : " | "); + os += "YCRCB_420_SP"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I)) { + os += (first ? "" : " | "); + os += "YCBCR_422_I"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16)) { + os += (first ? "" : " | "); + os += "RGBA_FP16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RAW16)) { + os += (first ? "" : " | "); + os += "RAW16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::BLOB)) { + os += (first ? "" : " | "); + os += "BLOB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED) == + static_cast( + ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED)) { + os += (first ? "" : " | "); + os += "IMPLEMENTATION_DEFINED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888) == + static_cast( + ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888)) { + os += (first ? "" : " | "); + os += "YCBCR_420_888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE)) { + os += (first ? "" : " | "); + os += "RAW_OPAQUE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RAW10)) { + os += (first ? "" : " | "); + os += "RAW10"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::RAW12)) { + os += (first ? "" : " | "); + os += "RAW12"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102) == + static_cast( + ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102)) { + os += (first ? "" : " | "); + os += "RGBA_1010102"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::Y8) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::Y8)) { + os += (first ? "" : " | "); + os += "Y8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::Y8; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::Y16) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::Y16)) { + os += (first ? "" : " | "); + os += "Y16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::Y16; + } + if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YV12) == + static_cast(::android::hardware::graphics::common::V1_0::PixelFormat::YV12)) { + os += (first ? "" : " | "); + os += "YV12"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YV12; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::PixelFormat o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888) { + return "RGBA_8888"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888) { + return "RGBX_8888"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888) { + return "RGB_888"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565) { + return "RGB_565"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888) { + return "BGRA_8888"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP) { + return "YCBCR_422_SP"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP) { + return "YCRCB_420_SP"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I) { + return "YCBCR_422_I"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16) { + return "RGBA_FP16"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16) { + return "RAW16"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB) { + return "BLOB"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED) { + return "IMPLEMENTATION_DEFINED"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888) { + return "YCBCR_420_888"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE) { + return "RAW_OPAQUE"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10) { + return "RAW10"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12) { + return "RAW12"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102) { + return "RGBA_1010102"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::Y8) { + return "Y8"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::Y16) { + return "Y16"; + } + if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YV12) { + return "YV12"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::BufferUsage>(uint64_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::BufferUsage> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK)) { + os += (first ? "" : " | "); + os += "CPU_READ_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER)) { + os += (first ? "" : " | "); + os += "CPU_READ_NEVER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY)) { + os += (first ? "" : " | "); + os += "CPU_READ_RARELY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN)) { + os += (first ? "" : " | "); + os += "CPU_READ_OFTEN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_NEVER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_RARELY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_OFTEN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE)) { + os += (first ? "" : " | "); + os += "GPU_TEXTURE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET)) { + os += (first ? "" : " | "); + os += "GPU_RENDER_TARGET"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY)) { + os += (first ? "" : " | "); + os += "COMPOSER_OVERLAY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET)) { + os += (first ? "" : " | "); + os += "COMPOSER_CLIENT_TARGET"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED) == + static_cast(::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED)) { + os += (first ? "" : " | "); + os += "PROTECTED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR)) { + os += (first ? "" : " | "); + os += "COMPOSER_CURSOR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER)) { + os += (first ? "" : " | "); + os += "VIDEO_ENCODER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT)) { + os += (first ? "" : " | "); + os += "CAMERA_OUTPUT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT)) { + os += (first ? "" : " | "); + os += "CAMERA_INPUT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT)) { + os += (first ? "" : " | "); + os += "RENDERSCRIPT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER)) { + os += (first ? "" : " | "); + os += "VIDEO_DECODER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA)) { + os += (first ? "" : " | "); + os += "SENSOR_DIRECT_DATA"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER)) { + os += (first ? "" : " | "); + os += "GPU_DATA_BUFFER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK)) { + os += (first ? "" : " | "); + os += "VENDOR_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI) == + static_cast( + ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI)) { + os += (first ? "" : " | "); + os += "VENDOR_MASK_HI"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::BufferUsage o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK) { + return "CPU_READ_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER) { + return "CPU_READ_NEVER"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY) { + return "CPU_READ_RARELY"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN) { + return "CPU_READ_OFTEN"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK) { + return "CPU_WRITE_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER) { + return "CPU_WRITE_NEVER"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY) { + return "CPU_WRITE_RARELY"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN) { + return "CPU_WRITE_OFTEN"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE) { + return "GPU_TEXTURE"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET) { + return "GPU_RENDER_TARGET"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY) { + return "COMPOSER_OVERLAY"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET) { + return "COMPOSER_CLIENT_TARGET"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED) { + return "PROTECTED"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR) { + return "COMPOSER_CURSOR"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER) { + return "VIDEO_ENCODER"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT) { + return "CAMERA_OUTPUT"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT) { + return "CAMERA_INPUT"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT) { + return "RENDERSCRIPT"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER) { + return "VIDEO_DECODER"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA) { + return "SENSOR_DIRECT_DATA"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER) { + return "GPU_DATA_BUFFER"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK) { + return "VENDOR_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI) { + return "VENDOR_MASK_HI"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::Transform>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Transform> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::Transform::FLIP_H) == + static_cast(::android::hardware::graphics::common::V1_0::Transform::FLIP_H)) { + os += (first ? "" : " | "); + os += "FLIP_H"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Transform::FLIP_H; + } + if ((o & ::android::hardware::graphics::common::V1_0::Transform::FLIP_V) == + static_cast(::android::hardware::graphics::common::V1_0::Transform::FLIP_V)) { + os += (first ? "" : " | "); + os += "FLIP_V"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Transform::FLIP_V; + } + if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_90) == + static_cast(::android::hardware::graphics::common::V1_0::Transform::ROT_90)) { + os += (first ? "" : " | "); + os += "ROT_90"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_90; + } + if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_180) == + static_cast(::android::hardware::graphics::common::V1_0::Transform::ROT_180)) { + os += (first ? "" : " | "); + os += "ROT_180"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_180; + } + if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_270) == + static_cast(::android::hardware::graphics::common::V1_0::Transform::ROT_270)) { + os += (first ? "" : " | "); + os += "ROT_270"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_270; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::Transform o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::Transform::FLIP_H) { + return "FLIP_H"; + } + if (o == ::android::hardware::graphics::common::V1_0::Transform::FLIP_V) { + return "FLIP_V"; + } + if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_90) { + return "ROT_90"; + } + if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_180) { + return "ROT_180"; + } + if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_270) { + return "ROT_270"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::Dataspace>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Dataspace> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN)) { + os += (first ? "" : " | "); + os += "UNKNOWN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY)) { + os += (first ? "" : " | "); + os += "ARBITRARY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT)) { + os += (first ? "" : " | "); + os += "STANDARD_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK)) { + os += (first ? "" : " | "); + os += "STANDARD_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "STANDARD_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709)) { + os += (first ? "" : " | "); + os += "STANDARD_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020)) { + os += (first ? "" : " | "); + os += "STANDARD_BT2020"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace:: + STANDARD_BT2020_CONSTANT_LUMINANCE) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace:: + STANDARD_BT2020_CONSTANT_LUMINANCE)) { + os += (first ? "" : " | "); + os += "STANDARD_BT2020_CONSTANT_LUMINANCE"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M)) { + os += (first ? "" : " | "); + os += "STANDARD_BT470M"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM)) { + os += (first ? "" : " | "); + os += "STANDARD_FILM"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3)) { + os += (first ? "" : " | "); + os += "STANDARD_DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "STANDARD_ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT)) { + os += (first ? "" : " | "); + os += "TRANSFER_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK)) { + os += (first ? "" : " | "); + os += "TRANSFER_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "TRANSFER_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR)) { + os += (first ? "" : " | "); + os += "TRANSFER_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB)) { + os += (first ? "" : " | "); + os += "TRANSFER_SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M)) { + os += (first ? "" : " | "); + os += "TRANSFER_SMPTE_170M"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_2"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_6"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084)) { + os += (first ? "" : " | "); + os += "TRANSFER_ST2084"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG)) { + os += (first ? "" : " | "); + os += "TRANSFER_HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT)) { + os += (first ? "" : " | "); + os += "RANGE_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK)) { + os += (first ? "" : " | "); + os += "RANGE_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "RANGE_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL)) { + os += (first ? "" : " | "); + os += "RANGE_FULL"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED)) { + os += (first ? "" : " | "); + os += "RANGE_LIMITED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED)) { + os += (first ? "" : " | "); + os += "RANGE_EXTENDED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "SRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "V0_SRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "V0_SCRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SRGB) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::SRGB)) { + os += (first ? "" : " | "); + os += "SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB)) { + os += (first ? "" : " | "); + os += "V0_SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB)) { + os += (first ? "" : " | "); + os += "V0_SCRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::JFIF) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::JFIF)) { + os += (first ? "" : " | "); + os += "JFIF"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::JFIF; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF)) { + os += (first ? "" : " | "); + os += "V0_JFIF"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT601_625)) { + os += (first ? "" : " | "); + os += "BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625)) { + os += (first ? "" : " | "); + os += "V0_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT601_525)) { + os += (first ? "" : " | "); + os += "BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525)) { + os += (first ? "" : " | "); + os += "V0_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT709) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT709)) { + os += (first ? "" : " | "); + os += "BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT709; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709)) { + os += (first ? "" : " | "); + os += "V0_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR)) { + os += (first ? "" : " | "); + os += "DCI_P3_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3)) { + os += (first ? "" : " | "); + os += "DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR)) { + os += (first ? "" : " | "); + os += "BT2020_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT2020)) { + os += (first ? "" : " | "); + os += "BT2020"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ)) { + os += (first ? "" : " | "); + os += "BT2020_PQ"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::DEPTH)) { + os += (first ? "" : " | "); + os += "DEPTH"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH; + } + if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR) == + static_cast(::android::hardware::graphics::common::V1_0::Dataspace::SENSOR)) { + os += (first ? "" : " | "); + os += "SENSOR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::Dataspace o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN) { + return "UNKNOWN"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY) { + return "ARBITRARY"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT) { + return "STANDARD_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK) { + return "STANDARD_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED) { + return "STANDARD_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709) { + return "STANDARD_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625) { + return "STANDARD_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED) { + return "STANDARD_BT601_625_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525) { + return "STANDARD_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED) { + return "STANDARD_BT601_525_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020) { + return "STANDARD_BT2020"; + } + if (o == + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE) { + return "STANDARD_BT2020_CONSTANT_LUMINANCE"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M) { + return "STANDARD_BT470M"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM) { + return "STANDARD_FILM"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3) { + return "STANDARD_DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB) { + return "STANDARD_ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT) { + return "TRANSFER_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK) { + return "TRANSFER_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED) { + return "TRANSFER_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR) { + return "TRANSFER_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB) { + return "TRANSFER_SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M) { + return "TRANSFER_SMPTE_170M"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2) { + return "TRANSFER_GAMMA2_2"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6) { + return "TRANSFER_GAMMA2_6"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8) { + return "TRANSFER_GAMMA2_8"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084) { + return "TRANSFER_ST2084"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG) { + return "TRANSFER_HLG"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT) { + return "RANGE_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK) { + return "RANGE_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED) { + return "RANGE_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL) { + return "RANGE_FULL"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED) { + return "RANGE_LIMITED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED) { + return "RANGE_EXTENDED"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR) { + return "SRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR) { + return "V0_SRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR) { + return "V0_SCRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SRGB) { + return "SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB) { + return "V0_SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB) { + return "V0_SCRGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::JFIF) { + return "JFIF"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF) { + return "V0_JFIF"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625) { + return "BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625) { + return "V0_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525) { + return "BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525) { + return "V0_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT709) { + return "BT709"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709) { + return "V0_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR) { + return "DCI_P3_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3) { + return "DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR) { + return "DISPLAY_P3_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3) { + return "DISPLAY_P3"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB) { + return "ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR) { + return "BT2020_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020) { + return "BT2020"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ) { + return "BT2020_PQ"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH) { + return "DEPTH"; + } + if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR) { + return "SENSOR"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::ColorMode>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::ColorMode> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE) == + static_cast(::android::hardware::graphics::common::V1_0::ColorMode::NATIVE)) { + os += (first ? "" : " | "); + os += "NATIVE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709)) { + os += (first ? "" : " | "); + os += "STANDARD_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3) == + static_cast(::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3)) { + os += (first ? "" : " | "); + os += "DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::SRGB) == + static_cast(::android::hardware::graphics::common::V1_0::ColorMode::SRGB)) { + os += (first ? "" : " | "); + os += "SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB) == + static_cast(::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3) == + static_cast(::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorMode o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE) { + return "NATIVE"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625) { + return "STANDARD_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED) { + return "STANDARD_BT601_625_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525) { + return "STANDARD_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED) { + return "STANDARD_BT601_525_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709) { + return "STANDARD_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3) { + return "DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::SRGB) { + return "SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB) { + return "ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3) { + return "DISPLAY_P3"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::ColorTransform>( + int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::ColorTransform> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY) == + static_cast(::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY)) { + os += (first ? "" : " | "); + os += "IDENTITY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX)) { + os += (first ? "" : " | "); + os += "ARBITRARY_MATRIX"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE)) { + os += (first ? "" : " | "); + os += "VALUE_INVERSE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE)) { + os += (first ? "" : " | "); + os += "GRAYSCALE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA)) { + os += (first ? "" : " | "); + os += "CORRECT_PROTANOPIA"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA)) { + os += (first ? "" : " | "); + os += "CORRECT_DEUTERANOPIA"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA; + } + if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA) == + static_cast( + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA)) { + os += (first ? "" : " | "); + os += "CORRECT_TRITANOPIA"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorTransform o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY) { + return "IDENTITY"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX) { + return "ARBITRARY_MATRIX"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE) { + return "VALUE_INVERSE"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE) { + return "GRAYSCALE"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA) { + return "CORRECT_PROTANOPIA"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA) { + return "CORRECT_DEUTERANOPIA"; + } + if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA) { + return "CORRECT_TRITANOPIA"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_0::Hdr>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Hdr> flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION) == + static_cast(::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION)) { + os += (first ? "" : " | "); + os += "DOLBY_VISION"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION; + } + if ((o & ::android::hardware::graphics::common::V1_0::Hdr::HDR10) == + static_cast(::android::hardware::graphics::common::V1_0::Hdr::HDR10)) { + os += (first ? "" : " | "); + os += "HDR10"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Hdr::HDR10; + } + if ((o & ::android::hardware::graphics::common::V1_0::Hdr::HLG) == + static_cast(::android::hardware::graphics::common::V1_0::Hdr::HLG)) { + os += (first ? "" : " | "); + os += "HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_0::Hdr::HLG; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_0::Hdr o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION) { + return "DOLBY_VISION"; + } + if (o == ::android::hardware::graphics::common::V1_0::Hdr::HDR10) { + return "HDR10"; + } + if (o == ::android::hardware::graphics::common::V1_0::Hdr::HLG) { + return "HLG"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +} // namespace V1_0 +} // namespace common +} // namespace graphics +} // namespace hardware +} // namespace android + +// +// global type declarations for package +// + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::PixelFormat, 20> + hidl_enum_values<::android::hardware::graphics::common::V1_0::PixelFormat> = { + ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888, + ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888, + ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888, + ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565, + ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888, + ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP, + ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP, + ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I, + ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16, + ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16, + ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB, + ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED, + ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888, + ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE, + ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10, + ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12, + ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102, + ::android::hardware::graphics::common::V1_0::PixelFormat::Y8, + ::android::hardware::graphics::common::V1_0::PixelFormat::Y16, + ::android::hardware::graphics::common::V1_0::PixelFormat::YV12, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::BufferUsage, 23> + hidl_enum_values<::android::hardware::graphics::common::V1_0::BufferUsage> = { + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY, + ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN, + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE, + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET, + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY, + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET, + ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED, + ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR, + ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER, + ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT, + ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT, + ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT, + ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER, + ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA, + ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER, + ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK, + ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::Transform, 5> + hidl_enum_values<::android::hardware::graphics::common::V1_0::Transform> = { + ::android::hardware::graphics::common::V1_0::Transform::FLIP_H, + ::android::hardware::graphics::common::V1_0::Transform::FLIP_V, + ::android::hardware::graphics::common::V1_0::Transform::ROT_90, + ::android::hardware::graphics::common::V1_0::Transform::ROT_180, + ::android::hardware::graphics::common::V1_0::Transform::ROT_270, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::Dataspace, 57> + hidl_enum_values<::android::hardware::graphics::common::V1_0::Dataspace> = { + ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN, + ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3, + ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084, + ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED, + ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED, + ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::SRGB, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB, + ::android::hardware::graphics::common::V1_0::Dataspace::JFIF, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF, + ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625, + ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525, + ::android::hardware::graphics::common::V1_0::Dataspace::BT709, + ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709, + ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3, + ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3, + ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB, + ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR, + ::android::hardware::graphics::common::V1_0::Dataspace::BT2020, + ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ, + ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH, + ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::ColorMode, 10> + hidl_enum_values<::android::hardware::graphics::common::V1_0::ColorMode> = { + ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE, + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625, + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED, + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525, + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED, + ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709, + ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3, + ::android::hardware::graphics::common::V1_0::ColorMode::SRGB, + ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB, + ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::ColorTransform, 7> + hidl_enum_values<::android::hardware::graphics::common::V1_0::ColorTransform> = { + ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY, + ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX, + ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE, + ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE, + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA, + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA, + ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_0::Hdr, 3> + hidl_enum_values<::android::hardware::graphics::common::V1_0::Hdr> = { + ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION, + ::android::hardware::graphics::common::V1_0::Hdr::HDR10, + ::android::hardware::graphics::common::V1_0::Hdr::HLG, +}; +} // namespace details +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H + +#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_TYPES_H +#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_TYPES_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace common { +namespace V1_1 { + +// Forward declaration for forward reference support: +enum class PixelFormat : int32_t; +enum class BufferUsage : uint64_t; +enum class Dataspace : int32_t; +enum class ColorMode : int32_t; +enum class RenderIntent : int32_t; + +/** + * Pixel formats for graphics buffers. + */ +enum class PixelFormat : int32_t { + /** + * 32-bit format that has 8-bit R, G, B, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBA_8888 = 1 /* 0x1 */, + /** + * 32-bit format that has 8-bit R, G, B, and unused components, in that + * order, from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBX_8888 = 2 /* 0x2 */, + /** + * 24-bit format that has 8-bit R, G, and B components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGB_888 = 3 /* 0x3 */, + /** + * 16-bit packed format that has 5-bit R, 6-bit G, and 5-bit B components, + * in that order, from the most-sigfinicant bits to the least-significant + * bits. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGB_565 = 4 /* 0x4 */, + /** + * 32-bit format that has 8-bit B, G, R, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + BGRA_8888 = 5 /* 0x5 */, + /** + * Legacy formats deprecated in favor of YCBCR_420_888. + */ + YCBCR_422_SP = 16 /* 0x10 */, + YCRCB_420_SP = 17 /* 0x11 */, + YCBCR_422_I = 20 /* 0x14 */, + /** + * 64-bit format that has 16-bit R, G, B, and A components, in that order, + * from the lowest memory address to the highest memory address. + * + * The component values are signed floats, whose interpretation is defined + * by the dataspace. + */ + RGBA_FP16 = 22 /* 0x16 */, + /** + * RAW16 is a single-channel, 16-bit, little endian format, typically + * representing raw Bayer-pattern images from an image sensor, with minimal + * processing. + * + * The exact pixel layout of the data in the buffer is sensor-dependent, and + * needs to be queried from the camera device. + * + * Generally, not all 16 bits are used; more common values are 10 or 12 + * bits. If not all bits are used, the lower-order bits are filled first. + * All parameters to interpret the raw data (black and white points, + * color space, etc) must be queried from the camera device. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * - strides are specified in pixels, not in bytes + * + * size = stride * height * 2 + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW16 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data, layout is as + * | defined above. + * Dataspace::DEPTH | Unprocessed implementation-dependent raw + * | depth measurements, opaque with 16 bit + * | samples. + * Other | Unsupported + */ + RAW16 = 32 /* 0x20 */, + /** + * BLOB is used to carry task-specific data which does not have a standard + * image structure. The details of the format are left to the two + * endpoints. + * + * A typical use case is for transporting JPEG-compressed images from the + * Camera HAL to the framework or to applications. + * + * Buffers of this format must have a height of 1, and width equal to their + * size in bytes. + * + * The mapping of the dataspace to buffer contents for BLOB is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::JFIF | An encoded JPEG image + * Dataspace::DEPTH | An android_depth_points buffer + * Dataspace::SENSOR | Sensor event data. + * Other | Unsupported + */ + BLOB = 33 /* 0x21 */, + /** + * A format indicating that the choice of format is entirely up to the + * allocator. + * + * The allocator should examine the usage bits passed in when allocating a + * buffer with this format, and it should derive the pixel format from + * those usage flags. This format must never be used with any of the + * BufferUsage::CPU_* usage flags. + * + * Even when the internally chosen format has an alpha component, the + * clients must assume the alpha vlaue to be 1.0. + * + * The interpretation of the component values is defined by the dataspace. + */ + IMPLEMENTATION_DEFINED = 34 /* 0x22 */, + /** + * This format allows platforms to use an efficient YCbCr/YCrCb 4:2:0 + * buffer layout, while still describing the general format in a + * layout-independent manner. While called YCbCr, it can be used to + * describe formats with either chromatic ordering, as well as + * whole planar or semiplanar layouts. + * + * This format must be accepted by the allocator when BufferUsage::CPU_* + * are set. + * + * Buffers with this format must be locked with IMapper::lockYCbCr. + * Locking with IMapper::lock must return an error. + * + * The interpretation of the component values is defined by the dataspace. + */ + YCBCR_420_888 = 35 /* 0x23 */, + /** + * RAW_OPAQUE is a format for unprocessed raw image buffers coming from an + * image sensor. The actual structure of buffers of this format is + * implementation-dependent. + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW_OPAQUE is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW_OPAQUE = 36 /* 0x24 */, + /** + * RAW10 is a single-channel, 10-bit per pixel, densely packed in each row, + * unprocessed format, usually representing raw Bayer-pattern images coming from + * an image sensor. + * + * In an image buffer with this format, starting from the first pixel of each + * row, each 4 consecutive pixels are packed into 5 bytes (40 bits). Each one + * of the first 4 bytes contains the top 8 bits of each pixel, The fifth byte + * contains the 2 least significant bits of the 4 pixels, the exact layout data + * for each 4 consecutive pixels is illustrated below (Pi[j] stands for the jth + * bit of the ith pixel): + * + * bit 7 bit 0 + * =====|=====|=====|=====|=====|=====|=====|=====| + * Byte 0: |P0[9]|P0[8]|P0[7]|P0[6]|P0[5]|P0[4]|P0[3]|P0[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 1: |P1[9]|P1[8]|P1[7]|P1[6]|P1[5]|P1[4]|P1[3]|P1[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 2: |P2[9]|P2[8]|P2[7]|P2[6]|P2[5]|P2[4]|P2[3]|P2[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 3: |P3[9]|P3[8]|P3[7]|P3[6]|P3[5]|P3[4]|P3[3]|P3[2]| + * |-----|-----|-----|-----|-----|-----|-----|-----| + * Byte 4: |P3[1]|P3[0]|P2[1]|P2[0]|P1[1]|P1[0]|P0[1]|P0[0]| + * =============================================== + * + * This format assumes + * - a width multiple of 4 pixels + * - an even height + * - a vertical stride equal to the height + * - strides are specified in bytes, not in pixels + * + * size = stride * height + * + * When stride is equal to width * (10 / 8), there will be no padding bytes at + * the end of each row, the entire image data is densely packed. When stride is + * larger than width * (10 / 8), padding bytes will be present at the end of each + * row (including the last row). + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW10 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW10 = 37 /* 0x25 */, + /** + * RAW12 is a single-channel, 12-bit per pixel, densely packed in each row, + * unprocessed format, usually representing raw Bayer-pattern images coming from + * an image sensor. + * + * In an image buffer with this format, starting from the first pixel of each + * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first + * and second byte contains the top 8 bits of first and second pixel. The third + * byte contains the 4 least significant bits of the two pixels, the exact layout + * data for each two consecutive pixels is illustrated below (Pi[j] stands for + * the jth bit of the ith pixel): + * + * bit 7 bit 0 + * ======|======|======|======|======|======|======|======| + * Byte 0: |P0[11]|P0[10]|P0[ 9]|P0[ 8]|P0[ 7]|P0[ 6]|P0[ 5]|P0[ 4]| + * |------|------|------|------|------|------|------|------| + * Byte 1: |P1[11]|P1[10]|P1[ 9]|P1[ 8]|P1[ 7]|P1[ 6]|P1[ 5]|P1[ 4]| + * |------|------|------|------|------|------|------|------| + * Byte 2: |P1[ 3]|P1[ 2]|P1[ 1]|P1[ 0]|P0[ 3]|P0[ 2]|P0[ 1]|P0[ 0]| + * ======================================================= + * + * This format assumes: + * - a width multiple of 4 pixels + * - an even height + * - a vertical stride equal to the height + * - strides are specified in bytes, not in pixels + * + * size = stride * height + * + * When stride is equal to width * (12 / 8), there will be no padding bytes at + * the end of each row, the entire image data is densely packed. When stride is + * larger than width * (12 / 8), padding bytes will be present at the end of + * each row (including the last row). + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::RENDERSCRIPT + * + * The mapping of the dataspace to buffer contents for RAW12 is as + * follows: + * + * Dataspace value | Buffer contents + * -------------------------------+----------------------------------------- + * Dataspace::ARBITRARY | Raw image sensor data. + * Other | Unsupported + */ + RAW12 = 38 /* 0x26 */, + /** + * 0x27 to 0x2A are reserved for flexible formats + * + * + * 32-bit packed format that has 2-bit A, 10-bit B, G, and R components, + * in that order, from the most-sigfinicant bits to the least-significant + * bits. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + RGBA_1010102 = 43 /* 0x2B */, + /** + * 0x100 - 0x1FF + * + * This range is reserved for vendor extensions. Formats in this range + * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not + * have an alpha component. + * + * + * Y8 is a YUV planar format comprised of a WxH Y plane, with each pixel + * being represented by 8 bits. It is equivalent to just the Y plane from + * YV12. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * + * size = stride * height + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + Y8 = 538982489 /* 0x20203859 */, + /** + * Y16 is a YUV planar format comprised of a WxH Y plane, with each pixel + * being represented by 16 bits. It is just like Y8, but has double the + * bits per pixel (little endian). + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * - strides are specified in pixels, not in bytes + * + * size = stride * height * 2 + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. When the dataspace is + * Dataspace::DEPTH, each pixel is a distance value measured by a depth + * camera, plus an associated confidence value. + */ + Y16 = 540422489 /* 0x20363159 */, + /** + * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed + * by (W/2) x (H/2) Cr and Cb planes. + * + * This format assumes + * - an even width + * - an even height + * - a horizontal stride multiple of 16 pixels + * - a vertical stride equal to the height + * + * y_size = stride * height + * c_stride = ALIGN(stride/2, 16) + * c_size = c_stride * height/2 + * size = y_size + c_size * 2 + * cr_offset = y_size + * cb_offset = y_size + c_size + * + * This range is reserved for vendor extensions. Formats in this range + * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not + * have an alpha component. + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::CAMERA_* + * - BufferUsage::CPU_* + * - BufferUsage::GPU_TEXTURE + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + YV12 = 842094169 /* 0x32315659 */, + /** + * 16-bit format that has a single 16-bit depth component. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + DEPTH_16 = 48 /* 0x30 */, + /** + * 32-bit format that has a single 24-bit depth component and, optionally, + * 8 bits that are unused. + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + */ + DEPTH_24 = 49 /* 0x31 */, + /** + * 32-bit format that has a 24-bit depth component and an 8-bit stencil + * component packed into 32-bits. + * + * The depth component values are unsigned normalized to the range [0, 1], + * whose interpretation is defined by the dataspace. The stencil values are + * unsigned integers, whose interpretation is defined by the dataspace. + */ + DEPTH_24_STENCIL_8 = 50 /* 0x32 */, + /** + * 32-bit format that has a single 32-bit depth component. + * + * The component values are signed floats, whose interpretation is defined + * by the dataspace. + */ + DEPTH_32F = 51 /* 0x33 */, + /** + * Two-component format that has a 32-bit depth component, an 8-bit stencil + * component, and optionally 24-bits unused. + * + * The depth component values are signed floats, whose interpretation is + * defined by the dataspace. The stencil bits are unsigned integers, whose + * interpretation is defined by the dataspace. + */ + DEPTH_32F_STENCIL_8 = 52 /* 0x34 */, + /** + * 8-bit format that has a single 8-bit stencil component. + * + * The component values are unsigned integers, whose interpretation is + * defined by the dataspace. + */ + STENCIL_8 = 53 /* 0x35 */, + /** + * P010 is a 4:2:0 YCbCr semiplanar format comprised of a WxH Y plane + * followed immediately by a Wx(H/2) CbCr plane. Each sample is + * represented by a 16-bit little-endian value, with the lower 6 bits set + * to zero. + * + * This format assumes + * - an even height + * - a vertical stride equal to the height + * + * stride_in_bytes = stride * 2 + * y_size = stride_in_bytes * height + * cbcr_size = stride_in_bytes * (height / 2) + * cb_offset = y_size + * cr_offset = cb_offset + 2 + * + * This format must be accepted by the allocator when used with the + * following usage flags: + * + * - BufferUsage::VIDEO_* + * - BufferUsage::CPU_* + * - BufferUsage::GPU_TEXTURE + * + * The component values are unsigned normalized to the range [0, 1], whose + * interpretation is defined by the dataspace. + * + * This format is appropriate for 10bit video content. + * + * Buffers with this format must be locked with IMapper::lockYCbCr + * or with IMapper::lock. + */ + YCBCR_P010 = 54 /* 0x36 */, +}; + +/** + * Buffer usage definitions. + */ +enum class BufferUsage : uint64_t { + /** + * bit 0-3 is an enum + */ + CPU_READ_MASK = 15ull /* 0xfULL */, + /** + * buffer is never read by CPU + */ + CPU_READ_NEVER = 0ull, + /** + * buffer is rarely read by CPU + */ + CPU_READ_RARELY = 2ull, + /** + * buffer is often read by CPU + */ + CPU_READ_OFTEN = 3ull, + /** + * bit 4-7 is an enum + */ + CPU_WRITE_MASK = 240ull /* (0xfULL << 4) */, + /** + * buffer is never written by CPU + */ + CPU_WRITE_NEVER = 0ull /* (0 << 4) */, + /** + * buffer is rarely written by CPU + */ + CPU_WRITE_RARELY = 32ull /* (2 << 4) */, + /** + * buffer is often written by CPU + */ + CPU_WRITE_OFTEN = 48ull /* (3 << 4) */, + /** + * buffer is used as a GPU texture + */ + GPU_TEXTURE = 256ull /* (1ULL << 8) */, + /** + * buffer is used as a GPU render target + */ + GPU_RENDER_TARGET = 512ull /* (1ULL << 9) */, + /** + * bit 10 must be zero + * + * + * buffer is used as a composer HAL overlay layer + */ + COMPOSER_OVERLAY = 2048ull /* (1ULL << 11) */, + /** + * buffer is used as a composer HAL client target + */ + COMPOSER_CLIENT_TARGET = 4096ull /* (1ULL << 12) */, + /** + * bit 13 must be zero + * + * + * Buffer is allocated with hardware-level protection against copying the + * contents (or information derived from the contents) into unprotected + * memory. + */ + PROTECTED = 16384ull /* (1ULL << 14) */, + /** + * buffer is used as a hwcomposer HAL cursor layer + */ + COMPOSER_CURSOR = 32768ull /* (1ULL << 15) */, + /** + * buffer is used as a video encoder input + */ + VIDEO_ENCODER = 65536ull /* (1ULL << 16) */, + /** + * buffer is used as a camera HAL output + */ + CAMERA_OUTPUT = 131072ull /* (1ULL << 17) */, + /** + * buffer is used as a camera HAL input + */ + CAMERA_INPUT = 262144ull /* (1ULL << 18) */, + /** + * bit 19 must be zero + * + * + * buffer is used as a renderscript allocation + */ + RENDERSCRIPT = 1048576ull /* (1ULL << 20) */, + /** + * bit 21 must be zero + * + * + * buffer is used as a video decoder output + */ + VIDEO_DECODER = 4194304ull /* (1ULL << 22) */, + /** + * buffer is used as a sensor direct report output + */ + SENSOR_DIRECT_DATA = 8388608ull /* (1ULL << 23) */, + /** + * buffer is used as as an OpenGL shader storage or uniform + * buffer object + */ + GPU_DATA_BUFFER = 16777216ull /* (1ULL << 24) */, + /** + * bits 25-27 must be zero and are reserved for future versions + * + * + * bits 28-31 are reserved for vendor extensions + */ + VENDOR_MASK = 4026531840ull /* (0xfULL << 28) */, + /** + * bits 32-47 must be zero and are reserved for future versions + * + * + * bits 48-63 are reserved for vendor extensions + */ + VENDOR_MASK_HI = 18446462598732840960ull /* (0xffffULL << 48) */, + /** + * buffer is used as a cube map texture + */ + GPU_CUBE_MAP = 33554432ull /* (1ULL << 25) */, + /** + * buffer contains a complete mipmap hierarchy + */ + GPU_MIPMAP_COMPLETE = 67108864ull /* (1ULL << 26) */, +}; + +enum class Dataspace : int32_t { + /** + * Default-assumption data space, when not explicitly specified. + * + * It is safest to assume the buffer is an image with sRGB primaries and + * encoding ranges, but the consumer and/or the producer of the data may + * simply be using defaults. No automatic gamma transform should be + * expected, except for a possible display gamma transform when drawn to a + * screen. + */ + UNKNOWN = 0 /* 0x0 */, + /** + * Arbitrary dataspace with manually defined characteristics. Definition + * for colorspaces or other meaning must be communicated separately. + * + * This is used when specifying primaries, transfer characteristics, + * etc. separately. + * + * A typical use case is in video encoding parameters (e.g. for H.264), + * where a colorspace can have separately defined primaries, transfer + * characteristics, etc. + */ + ARBITRARY = 1 /* 0x1 */, + /** + * Color-description aspects + * + * The following aspects define various characteristics of the color + * specification. These represent bitfields, so that a data space value + * can specify each of them independently. + */ + STANDARD_SHIFT = 16, + /** + * Standard aspect + * + * Defines the chromaticity coordinates of the source primaries in terms of + * the CIE 1931 definition of x and y specified in ISO 11664-1. + */ + STANDARD_MASK = 4128768 /* (63 << STANDARD_SHIFT) */, + /** + * Chromacity coordinates are unknown or are determined by the application. + * Implementations shall use the following suggested standards: + * + * All YCbCr formats: BT709 if size is 720p or larger (since most video + * content is letterboxed this corresponds to width is + * 1280 or greater, or height is 720 or greater). + * BT601_625 if size is smaller than 720p or is JPEG. + * All RGB formats: BT709. + * + * For all other formats standard is undefined, and implementations should use + * an appropriate standard for the data represented. + */ + STANDARD_UNSPECIFIED = 0 /* (0 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2126, KB = 0.0722 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT709 = 65536 /* (1 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + */ + STANDARD_BT601_625 = 131072 /* (2 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT601_625_UNADJUSTED = 196608 /* (3 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + */ + STANDARD_BT601_525 = 262144 /* (4 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation + * for RGB conversion (as in SMPTE 240M). + */ + STANDARD_BT601_525_UNADJUSTED = 327680 /* (5 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT2020 = 393216 /* (6 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation + * for RGB conversion using the linear domain. + */ + STANDARD_BT2020_CONSTANT_LUMINANCE = 458752 /* (7 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.21 0.71 + * blue 0.14 0.08 + * red 0.67 0.33 + * white (C) 0.310 0.316 + * + * Use the unadjusted KR = 0.30, KB = 0.11 luminance interpretation + * for RGB conversion. + */ + STANDARD_BT470M = 524288 /* (8 << STANDARD_SHIFT) */, + /** + * Primaries: x y + * green 0.243 0.692 + * blue 0.145 0.049 + * red 0.681 0.319 + * white (C) 0.310 0.316 + * + * Use the unadjusted KR = 0.254, KB = 0.068 luminance interpretation + * for RGB conversion. + */ + STANDARD_FILM = 589824 /* (9 << STANDARD_SHIFT) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. (DCI-P3) + * Primaries: x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + */ + STANDARD_DCI_P3 = 655360 /* (10 << STANDARD_SHIFT) */, + /** + * Adobe RGB + * Primaries: x y + * green 0.210 0.710 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + */ + STANDARD_ADOBE_RGB = 720896 /* (11 << STANDARD_SHIFT) */, + TRANSFER_SHIFT = 22, + /** + * Transfer aspect + * + * Transfer characteristics are the opto-electronic transfer characteristic + * at the source as a function of linear optical intensity (luminance). + * + * For digital signals, E corresponds to the recorded value. Normally, the + * transfer function is applied in RGB space to each of the R, G and B + * components independently. This may result in color shift that can be + * minized by applying the transfer function in Lab space only for the L + * component. Implementation may apply the transfer function in RGB space + * for all pixel formats if desired. + */ + TRANSFER_MASK = 130023424 /* (31 << TRANSFER_SHIFT) */, + /** + * Transfer characteristics are unknown or are determined by the + * application. + * + * Implementations should use the following transfer functions: + * + * For YCbCr formats: use TRANSFER_SMPTE_170M + * For RGB formats: use TRANSFER_SRGB + * + * For all other formats transfer function is undefined, and implementations + * should use an appropriate standard for the data represented. + */ + TRANSFER_UNSPECIFIED = 0 /* (0 << TRANSFER_SHIFT) */, + /** + * Transfer characteristic curve: + * E = L + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_LINEAR = 4194304 /* (1 << TRANSFER_SHIFT) */, + /** + * Transfer characteristic curve: + * + * E = 1.055 * L^(1/2.4) - 0.055 for 0.0031308 <= L <= 1 + * = 12.92 * L for 0 <= L < 0.0031308 + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_SRGB = 8388608 /* (2 << TRANSFER_SHIFT) */, + /** + * BT.601 525, BT.601 625, BT.709, BT.2020 + * + * Transfer characteristic curve: + * E = 1.099 * L ^ 0.45 - 0.099 for 0.018 <= L <= 1 + * = 4.500 * L for 0 <= L < 0.018 + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_SMPTE_170M = 12582912 /* (3 << TRANSFER_SHIFT) */, + /** + * Assumed display gamma 2.2. + * + * Transfer characteristic curve: + * E = L ^ (1/2.2) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_2 = 16777216 /* (4 << TRANSFER_SHIFT) */, + /** + * display gamma 2.6. + * + * Transfer characteristic curve: + * E = L ^ (1/2.6) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_6 = 20971520 /* (5 << TRANSFER_SHIFT) */, + /** + * display gamma 2.8. + * + * Transfer characteristic curve: + * E = L ^ (1/2.8) + * L - luminance of image 0 <= L <= 1 for conventional colorimetry + * E - corresponding electrical signal + */ + TRANSFER_GAMMA2_8 = 25165824 /* (6 << TRANSFER_SHIFT) */, + /** + * SMPTE ST 2084 (Dolby Perceptual Quantizer) + * + * Transfer characteristic curve: + * E = ((c1 + c2 * L^n) / (1 + c3 * L^n)) ^ m + * c1 = c3 - c2 + 1 = 3424 / 4096 = 0.8359375 + * c2 = 32 * 2413 / 4096 = 18.8515625 + * c3 = 32 * 2392 / 4096 = 18.6875 + * m = 128 * 2523 / 4096 = 78.84375 + * n = 0.25 * 2610 / 4096 = 0.1593017578125 + * L - luminance of image 0 <= L <= 1 for HDR colorimetry. + * L = 1 corresponds to 10000 cd/m2 + * E - corresponding electrical signal + */ + TRANSFER_ST2084 = 29360128 /* (7 << TRANSFER_SHIFT) */, + /** + * ARIB STD-B67 Hybrid Log Gamma + * + * Transfer characteristic curve: + * E = r * L^0.5 for 0 <= L <= 1 + * = a * ln(L - b) + c for 1 < L + * a = 0.17883277 + * b = 0.28466892 + * c = 0.55991073 + * r = 0.5 + * L - luminance of image 0 <= L for HDR colorimetry. L = 1 corresponds + * to reference white level of 100 cd/m2 + * E - corresponding electrical signal + */ + TRANSFER_HLG = 33554432 /* (8 << TRANSFER_SHIFT) */, + RANGE_SHIFT = 27, + /** + * Range aspect + * + * Defines the range of values corresponding to the unit range of 0-1. + * This is defined for YCbCr only, but can be expanded to RGB space. + */ + RANGE_MASK = 939524096 /* (7 << RANGE_SHIFT) */, + /** + * Range is unknown or are determined by the application. Implementations + * shall use the following suggested ranges: + * + * All YCbCr formats: limited range. + * All RGB or RGBA formats (including RAW and Bayer): full range. + * All Y formats: full range + * + * For all other formats range is undefined, and implementations should use + * an appropriate range for the data represented. + */ + RANGE_UNSPECIFIED = 0 /* (0 << RANGE_SHIFT) */, + /** + * Full range uses all values for Y, Cb and Cr from + * 0 to 2^b-1, where b is the bit depth of the color format. + */ + RANGE_FULL = 134217728 /* (1 << RANGE_SHIFT) */, + /** + * Limited range uses values 16/256*2^b to 235/256*2^b for Y, and + * 1/16*2^b to 15/16*2^b for Cb, Cr, R, G and B, where b is the bit depth of + * the color format. + * + * E.g. For 8-bit-depth formats: + * Luma (Y) samples should range from 16 to 235, inclusive + * Chroma (Cb, Cr) samples should range from 16 to 240, inclusive + * + * For 10-bit-depth formats: + * Luma (Y) samples should range from 64 to 940, inclusive + * Chroma (Cb, Cr) samples should range from 64 to 960, inclusive + */ + RANGE_LIMITED = 268435456 /* (2 << RANGE_SHIFT) */, + /** + * Extended range is used for scRGB. Intended for use with + * floating point pixel formats. [0.0 - 1.0] is the standard + * sRGB space. Values outside the range 0.0 - 1.0 can encode + * color outside the sRGB gamut. + * Used to blend / merge multiple dataspaces on a single display. + */ + RANGE_EXTENDED = 402653184 /* (3 << RANGE_SHIFT) */, + /** + * Legacy dataspaces + * + * + * sRGB linear encoding: + * + * The red, green, and blue components are stored in sRGB space, but + * are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are encoded using the full range ([0,255] for 8-bit) for all + * components. + */ + SRGB_LINEAR = 512 /* 0x200 */, + V0_SRGB_LINEAR = 138477568 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * scRGB linear encoding: + * + * The red, green, and blue components are stored in extended sRGB space, + * but are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are floating point. + * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits. + * Values beyond the range [0.0 - 1.0] would correspond to other colors + * spaces and/or HDR content. + */ + V0_SCRGB_LINEAR = 406913024 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_EXTENDED) */, + /** + * sRGB gamma encoding: + * + * The red, green and blue components are stored in sRGB space, and + * converted to linear space when read, using the SRGB transfer function + * for each of the R, G and B components. When written, the inverse + * transformation is performed. + * + * The alpha component, if present, is always stored in linear space and + * is left unmodified when read or written. + * + * Use full range and BT.709 standard. + */ + SRGB = 513 /* 0x201 */, + V0_SRGB = 142671872 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_FULL) */, + /** + * scRGB: + * + * The red, green, and blue components are stored in extended sRGB space, + * but are linear, not gamma-encoded. + * The RGB primaries and the white point are the same as BT.709. + * + * The values are floating point. + * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits. + * Values beyond the range [0.0 - 1.0] would correspond to other colors + * spaces and/or HDR content. + */ + V0_SCRGB = 411107328 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_EXTENDED) */, + /** + * YCbCr Colorspaces + * ----------------- + * + * Primaries are given using (x,y) coordinates in the CIE 1931 definition + * of x and y specified by ISO 11664-1. + * + * Transfer characteristics are the opto-electronic transfer characteristic + * at the source as a function of linear optical intensity (luminance). + * + * + * JPEG File Interchange Format (JFIF) + * + * Same model as BT.601-625, but all values (Y, Cb, Cr) range from 0 to 255 + * + * Use full range, BT.601 transfer and BT.601_625 standard. + */ + JFIF = 257 /* 0x101 */, + V0_JFIF = 146931712 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_FULL) */, + /** + * ITU-R Recommendation 601 (BT.601) - 625-line + * + * Standard-definition television, 625 Lines (PAL) + * + * Use limited range, BT.601 transfer and BT.601_625 standard. + */ + BT601_625 = 258 /* 0x102 */, + V0_BT601_625 = 281149440 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * ITU-R Recommendation 601 (BT.601) - 525-line + * + * Standard-definition television, 525 Lines (NTSC) + * + * Use limited range, BT.601 transfer and BT.601_525 standard. + */ + BT601_525 = 259 /* 0x103 */, + V0_BT601_525 = 281280512 /* ((STANDARD_BT601_525 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * ITU-R Recommendation 709 (BT.709) + * + * High-definition television + * + * Use limited range, BT.709 transfer and BT.709 standard. + */ + BT709 = 260 /* 0x104 */, + V0_BT709 = 281083904 /* ((STANDARD_BT709 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. + * + * Digital Cinema DCI-P3 + * + * Use full range, linear transfer and D65 DCI-P3 standard + */ + DCI_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * SMPTE EG 432-1 and SMPTE RP 431-2. + * + * Digital Cinema DCI-P3 + * + * Use full range, gamma 2.6 transfer and D65 DCI-P3 standard + * Note: Application is responsible for gamma encoding the data as + * a 2.6 gamma encoding is not supported in HW. + */ + DCI_P3 = 155844608 /* ((STANDARD_DCI_P3 | TRANSFER_GAMMA2_6) | RANGE_FULL) */, + /** + * Display P3 + * + * Display P3 uses same primaries and white-point as DCI-P3 + * linear transfer function makes this the same as DCI_P3_LINEAR. + */ + DISPLAY_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * Display P3 + * + * Use same primaries and white-point as DCI-P3 + * but sRGB transfer function. + */ + DISPLAY_P3 = 143261696 /* ((STANDARD_DCI_P3 | TRANSFER_SRGB) | RANGE_FULL) */, + /** + * Adobe RGB + * + * Use full range, gamma 2.2 transfer and Adobe RGB primaries + * Note: Application is responsible for gamma encoding the data as + * a 2.2 gamma encoding is not supported in HW. + */ + ADOBE_RGB = 151715840 /* ((STANDARD_ADOBE_RGB | TRANSFER_GAMMA2_2) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, linear transfer and BT2020 standard + */ + BT2020_LINEAR = 138805248 /* ((STANDARD_BT2020 | TRANSFER_LINEAR) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, BT.709 transfer and BT2020 standard + */ + BT2020 = 147193856 /* ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_FULL) */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use full range, SMPTE 2084 (PQ) transfer and BT2020 standard + */ + BT2020_PQ = 163971072 /* ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_FULL) */, + /** + * Data spaces for non-color formats + * + * + * The buffer contains depth ranging measurements from a depth camera. + * This value is valid with formats: + * HAL_PIXEL_FORMAT_Y16: 16-bit samples, consisting of a depth measurement + * and an associated confidence value. The 3 MSBs of the sample make + * up the confidence value, and the low 13 LSBs of the sample make up + * the depth measurement. + * For the confidence section, 0 means 100% confidence, 1 means 0% + * confidence. The mapping to a linear float confidence value between + * 0.f and 1.f can be obtained with + * float confidence = (((depthSample >> 13) - 1) & 0x7) / 7.0f; + * The depth measurement can be extracted simply with + * uint16_t range = (depthSample & 0x1FFF); + * HAL_PIXEL_FORMAT_BLOB: A depth point cloud, as + * a variable-length float (x,y,z, confidence) coordinate point list. + * The point cloud will be represented with the android_depth_points + * structure. + */ + DEPTH = 4096 /* 0x1000 */, + /** + * The buffer contains sensor events from sensor direct report. + * This value is valid with formats: + * HAL_PIXEL_FORMAT_BLOB: an array of sensor event structure that forms + * a lock free queue. Format of sensor event structure is specified + * in Sensors HAL. + */ + SENSOR = 4097 /* 0x1001 */, + /** + * ITU-R Recommendation 2020 (BT.2020) + * + * Ultra High-definition television + * + * Use limited range, BT.709 transfer and BT2020 standard + */ + BT2020_ITU = 281411584 /* ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */, + /** + * ITU-R Recommendation 2100 (BT.2100) + * + * High dynamic range television + * + * Use limited/full range, PQ/HLG transfer, and BT2020 standard + * limited range is the preferred / normative definition for BT.2100 + */ + BT2020_ITU_PQ = 298188800 /* ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_LIMITED) */, + BT2020_ITU_HLG = 302383104 /* ((STANDARD_BT2020 | TRANSFER_HLG) | RANGE_LIMITED) */, + BT2020_HLG = 168165376 /* ((STANDARD_BT2020 | TRANSFER_HLG) | RANGE_FULL) */, +}; + +enum class ColorMode : int32_t { + /** + * DEFAULT is the "native" gamut of the display. + * White Point: Vendor/OEM defined + * Panel Gamma: Vendor/OEM defined (typically 2.2) + * Rendering Intent: Vendor/OEM defined (typically 'enhanced') + */ + NATIVE = 0, + /** + * STANDARD_BT601_625 corresponds with display + * settings that implement the ITU-R Recommendation BT.601 + * or Rec 601. Using 625 line version + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_625 = 1, + /** + * Primaries: + * x y + * green 0.290 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation + * for RGB conversion. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_625_UNADJUSTED = 2, + /** + * Primaries: + * x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * KR = 0.299, KB = 0.114. This adjusts the luminance interpretation + * for RGB conversion from the one purely determined by the primaries + * to minimize the color shift into RGB space that uses BT.709 + * primaries. + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_525 = 3, + /** + * Primaries: + * x y + * green 0.310 0.595 + * blue 0.155 0.070 + * red 0.630 0.340 + * white (D65) 0.3127 0.3290 + * + * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation + * for RGB conversion (as in SMPTE 240M). + * + * Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.500 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099 + */ + STANDARD_BT601_525_UNADJUSTED = 4, + /** + * REC709 corresponds with display settings that implement + * the ITU-R Recommendation BT.709 / Rec. 709 for high-definition television. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * HDTV REC709 Inverse Gamma Correction (IGC): V represents normalized + * (with [0 to 1] range) value of R, G, or B. + * + * if Vnonlinear < 0.081 + * Vlinear = Vnonlinear / 4.5 + * else + * Vlinear = ((Vnonlinear + 0.099) / 1.099) ^ (1/0.45) + * + * HDTV REC709 Gamma Correction (GC): + * + * if Vlinear < 0.018 + * Vnonlinear = 4.5 * Vlinear + * else + * Vnonlinear = 1.099 * (Vlinear) ^ 0.45 – 0.099 + */ + STANDARD_BT709 = 5, + /** + * DCI_P3 corresponds with display settings that implement + * SMPTE EG 432-1 and SMPTE RP 431-2 + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + * + * Gamma: 2.6 + */ + DCI_P3 = 6, + /** + * SRGB corresponds with display settings that implement + * the sRGB color space. Uses the same primaries as ITU-R Recommendation + * BT.709 + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.300 0.600 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * PC/Internet (sRGB) Inverse Gamma Correction (IGC): + * + * if Vnonlinear ≤ 0.03928 + * Vlinear = Vnonlinear / 12.92 + * else + * Vlinear = ((Vnonlinear + 0.055)/1.055) ^ 2.4 + * + * PC/Internet (sRGB) Gamma Correction (GC): + * + * if Vlinear ≤ 0.0031308 + * Vnonlinear = 12.92 * Vlinear + * else + * Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055 + */ + SRGB = 7, + /** + * ADOBE_RGB corresponds with the RGB color space developed + * by Adobe Systems, Inc. in 1998. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.210 0.710 + * blue 0.150 0.060 + * red 0.640 0.330 + * white (D65) 0.3127 0.3290 + * + * Gamma: 2.2 + */ + ADOBE_RGB = 8, + /** + * DISPLAY_P3 is a color space that uses the DCI_P3 primaries, + * the D65 white point and the SRGB transfer functions. + * Rendering Intent: Colorimetric + * Primaries: + * x y + * green 0.265 0.690 + * blue 0.150 0.060 + * red 0.680 0.320 + * white (D65) 0.3127 0.3290 + * + * PC/Internet (sRGB) Gamma Correction (GC): + * + * if Vlinear ≤ 0.0030186 + * Vnonlinear = 12.92 * Vlinear + * else + * Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055 + * + * Note: In most cases sRGB transfer function will be fine. + */ + DISPLAY_P3 = 9, + /** + * BT2020 corresponds with display settings that implement the ITU-R + * Recommendation BT.2020 / Rec. 2020 for UHDTV. + * + * Primaries: + * x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * Inverse Gamma Correction (IGC): V represents normalized (with [0 to 1] + * range) value of R, G, or B. + * + * if Vnonlinear < b * 4.5 + * Vlinear = Vnonlinear / 4.5 + * else + * Vlinear = ((Vnonlinear + (a - 1)) / a) ^ (1/0.45) + * + * Gamma Correction (GC): + * + * if Vlinear < b + * Vnonlinear = 4.5 * Vlinear + * else + * Vnonlinear = a * Vlinear ^ 0.45 - (a - 1) + * + * where + * + * a = 1.09929682680944, b = 0.018053968510807 + * + * For practical purposes, these a/b values can be used instead + * + * a = 1.099, b = 0.018 for 10-bit display systems + * a = 1.0993, b = 0.0181 for 12-bit display systems + */ + BT2020 = 10, + /** + * BT2100_PQ and BT2100_HLG correspond with display settings that + * implement the ITU-R Recommendation BT.2100 / Rec. 2100 for HDR TV. + * + * Primaries: + * x y + * green 0.170 0.797 + * blue 0.131 0.046 + * red 0.708 0.292 + * white (D65) 0.3127 0.3290 + * + * For BT2100_PQ, the transfer function is Perceptual Quantizer (PQ). For + * BT2100_HLG, the transfer function is Hybrid Log-Gamma (HLG). + */ + BT2100_PQ = 11, + BT2100_HLG = 12, +}; + +/** + * RenderIntent defines the mapping from color mode colors to display colors. + * + * A render intent must not change how it maps colors when the color mode + * changes. That is to say that when a render intent maps color C to color C', + * the fact that color C can have different pixel values in different color + * modes should not affect the mapping. + * + * RenderIntent overrides the render intents defined for individual color + * modes. It is ignored when the color mode is ColorMode::NATIVE, because + * ColorMode::NATIVE colors are already display colors. + */ +enum class RenderIntent : int32_t { + /** + * Colors in the display gamut are unchanged. Colors out of the display + * gamut are hard-clipped. + * + * This implies that the display must have been calibrated unless + * ColorMode::NATIVE is the only supported color mode. + */ + COLORIMETRIC = 0, + /** + * Enhance colors that are in the display gamut. Colors out of the display + * gamut are hard-clipped. + * + * The enhancement typically picks the biggest standard color space (e.g. + * DCI-P3) that is narrower than the display gamut and stretches it to the + * display gamut. The stretching is recommended to preserve skin tones. + */ + ENHANCE = 1, + /** + * Tone map high-dynamic-range colors to the display's dynamic range. The + * dynamic range of the colors are communicated separately. After tone + * mapping, the mapping to the display gamut is as defined in + * COLORIMETRIC. + */ + TONE_MAP_COLORIMETRIC = 2, + /** + * Tone map high-dynamic-range colors to the display's dynamic range. The + * dynamic range of the colors are communicated separately. After tone + * mapping, the mapping to the display gamut is as defined in ENHANCE. + * + * The tone mapping step and the enhancing step must match + * TONE_MAP_COLORIMETRIC and ENHANCE respectively when they are also + * supported. + */ + TONE_MAP_ENHANCE = 3, +}; + +// +// type declarations for package +// + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_1::PixelFormat o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::PixelFormat lhs, + const ::android::hardware::graphics::common::V1_1::PixelFormat rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::PixelFormat rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::PixelFormat lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::PixelFormat lhs, + const ::android::hardware::graphics::common::V1_1::PixelFormat rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::PixelFormat rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::PixelFormat lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::PixelFormat e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::PixelFormat e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(uint64_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_1::BufferUsage o); + +constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_1::BufferUsage lhs, + const ::android::hardware::graphics::common::V1_1::BufferUsage rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr uint64_t operator|(const uint64_t lhs, + const ::android::hardware::graphics::common::V1_1::BufferUsage rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_1::BufferUsage lhs, + const uint64_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_1::BufferUsage lhs, + const ::android::hardware::graphics::common::V1_1::BufferUsage rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr uint64_t operator&(const uint64_t lhs, + const ::android::hardware::graphics::common::V1_1::BufferUsage rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_1::BufferUsage lhs, + const uint64_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr uint64_t& operator|=(uint64_t& v, + const ::android::hardware::graphics::common::V1_1::BufferUsage e) { + v |= static_cast(e); + return v; +} +constexpr uint64_t& operator&=(uint64_t& v, + const ::android::hardware::graphics::common::V1_1::BufferUsage e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_1::Dataspace o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::Dataspace lhs, + const ::android::hardware::graphics::common::V1_1::Dataspace rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::Dataspace rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::Dataspace lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::Dataspace lhs, + const ::android::hardware::graphics::common::V1_1::Dataspace rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::Dataspace rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::Dataspace lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::Dataspace e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::Dataspace e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_1::ColorMode o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::ColorMode lhs, + const ::android::hardware::graphics::common::V1_1::ColorMode rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::ColorMode rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::ColorMode lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::ColorMode lhs, + const ::android::hardware::graphics::common::V1_1::ColorMode rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::ColorMode rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::ColorMode lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::ColorMode e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::ColorMode e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::common::V1_1::RenderIntent o); + +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::RenderIntent lhs, + const ::android::hardware::graphics::common::V1_1::RenderIntent rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::RenderIntent rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_1::RenderIntent lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::RenderIntent lhs, + const ::android::hardware::graphics::common::V1_1::RenderIntent rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::common::V1_1::RenderIntent rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_1::RenderIntent lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::RenderIntent e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::common::V1_1::RenderIntent e) { + v &= static_cast(e); + return v; +} + +// +// type header definitions for package +// + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_1::PixelFormat>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_1::PixelFormat> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_8888) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_8888)) { + os += (first ? "" : " | "); + os += "RGBA_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_8888; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGBX_8888) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RGBX_8888)) { + os += (first ? "" : " | "); + os += "RGBX_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGBX_8888; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_888) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RGB_888)) { + os += (first ? "" : " | "); + os += "RGB_888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_888; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_565) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RGB_565)) { + os += (first ? "" : " | "); + os += "RGB_565"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_565; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::BGRA_8888) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::BGRA_8888)) { + os += (first ? "" : " | "); + os += "BGRA_8888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::BGRA_8888; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_SP) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_SP)) { + os += (first ? "" : " | "); + os += "YCBCR_422_SP"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_SP; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YCRCB_420_SP) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::YCRCB_420_SP)) { + os += (first ? "" : " | "); + os += "YCRCB_420_SP"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YCRCB_420_SP; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_I) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_I)) { + os += (first ? "" : " | "); + os += "YCBCR_422_I"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_I; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_FP16) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_FP16)) { + os += (first ? "" : " | "); + os += "RGBA_FP16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_FP16; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RAW16) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RAW16)) { + os += (first ? "" : " | "); + os += "RAW16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RAW16; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::BLOB) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::BLOB)) { + os += (first ? "" : " | "); + os += "BLOB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::BLOB; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::IMPLEMENTATION_DEFINED) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::IMPLEMENTATION_DEFINED)) { + os += (first ? "" : " | "); + os += "IMPLEMENTATION_DEFINED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::IMPLEMENTATION_DEFINED; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_420_888) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_420_888)) { + os += (first ? "" : " | "); + os += "YCBCR_420_888"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_420_888; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RAW_OPAQUE) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RAW_OPAQUE)) { + os += (first ? "" : " | "); + os += "RAW_OPAQUE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RAW_OPAQUE; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RAW10) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RAW10)) { + os += (first ? "" : " | "); + os += "RAW10"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RAW10; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RAW12) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::RAW12)) { + os += (first ? "" : " | "); + os += "RAW12"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RAW12; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_1010102) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_1010102)) { + os += (first ? "" : " | "); + os += "RGBA_1010102"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_1010102; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::Y8) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::Y8)) { + os += (first ? "" : " | "); + os += "Y8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::Y8; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::Y16) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::Y16)) { + os += (first ? "" : " | "); + os += "Y16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::Y16; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YV12) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::YV12)) { + os += (first ? "" : " | "); + os += "YV12"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YV12; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_16) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_16)) { + os += (first ? "" : " | "); + os += "DEPTH_16"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_16; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24)) { + os += (first ? "" : " | "); + os += "DEPTH_24"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24_STENCIL_8) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24_STENCIL_8)) { + os += (first ? "" : " | "); + os += "DEPTH_24_STENCIL_8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24_STENCIL_8; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F)) { + os += (first ? "" : " | "); + os += "DEPTH_32F"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F_STENCIL_8) == + static_cast( + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F_STENCIL_8)) { + os += (first ? "" : " | "); + os += "DEPTH_32F_STENCIL_8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F_STENCIL_8; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::STENCIL_8) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::STENCIL_8)) { + os += (first ? "" : " | "); + os += "STENCIL_8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::STENCIL_8; + } + if ((o & ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_P010) == + static_cast(::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_P010)) { + os += (first ? "" : " | "); + os += "YCBCR_P010"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_P010; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_1::PixelFormat o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_8888) { + return "RGBA_8888"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGBX_8888) { + return "RGBX_8888"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_888) { + return "RGB_888"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_565) { + return "RGB_565"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::BGRA_8888) { + return "BGRA_8888"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_SP) { + return "YCBCR_422_SP"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YCRCB_420_SP) { + return "YCRCB_420_SP"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_I) { + return "YCBCR_422_I"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_FP16) { + return "RGBA_FP16"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RAW16) { + return "RAW16"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::BLOB) { + return "BLOB"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::IMPLEMENTATION_DEFINED) { + return "IMPLEMENTATION_DEFINED"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_420_888) { + return "YCBCR_420_888"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RAW_OPAQUE) { + return "RAW_OPAQUE"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RAW10) { + return "RAW10"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RAW12) { + return "RAW12"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_1010102) { + return "RGBA_1010102"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::Y8) { + return "Y8"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::Y16) { + return "Y16"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YV12) { + return "YV12"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_16) { + return "DEPTH_16"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24) { + return "DEPTH_24"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24_STENCIL_8) { + return "DEPTH_24_STENCIL_8"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F) { + return "DEPTH_32F"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F_STENCIL_8) { + return "DEPTH_32F_STENCIL_8"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::STENCIL_8) { + return "STENCIL_8"; + } + if (o == ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_P010) { + return "YCBCR_P010"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_1::BufferUsage>(uint64_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_1::BufferUsage> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_MASK)) { + os += (first ? "" : " | "); + os += "CPU_READ_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_NEVER) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_NEVER)) { + os += (first ? "" : " | "); + os += "CPU_READ_NEVER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_NEVER; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_RARELY) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_RARELY)) { + os += (first ? "" : " | "); + os += "CPU_READ_RARELY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_RARELY; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_OFTEN) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_OFTEN)) { + os += (first ? "" : " | "); + os += "CPU_READ_OFTEN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_OFTEN; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_MASK)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_NEVER) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_NEVER)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_NEVER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_NEVER; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_RARELY) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_RARELY)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_RARELY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_RARELY; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_OFTEN) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_OFTEN)) { + os += (first ? "" : " | "); + os += "CPU_WRITE_OFTEN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_OFTEN; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_TEXTURE) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_TEXTURE)) { + os += (first ? "" : " | "); + os += "GPU_TEXTURE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_TEXTURE; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_RENDER_TARGET) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_RENDER_TARGET)) { + os += (first ? "" : " | "); + os += "GPU_RENDER_TARGET"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_RENDER_TARGET; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_OVERLAY) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_OVERLAY)) { + os += (first ? "" : " | "); + os += "COMPOSER_OVERLAY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_OVERLAY; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CLIENT_TARGET) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CLIENT_TARGET)) { + os += (first ? "" : " | "); + os += "COMPOSER_CLIENT_TARGET"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CLIENT_TARGET; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::PROTECTED) == + static_cast(::android::hardware::graphics::common::V1_1::BufferUsage::PROTECTED)) { + os += (first ? "" : " | "); + os += "PROTECTED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::PROTECTED; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CURSOR) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CURSOR)) { + os += (first ? "" : " | "); + os += "COMPOSER_CURSOR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CURSOR; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_ENCODER) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_ENCODER)) { + os += (first ? "" : " | "); + os += "VIDEO_ENCODER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_ENCODER; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_OUTPUT) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_OUTPUT)) { + os += (first ? "" : " | "); + os += "CAMERA_OUTPUT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_OUTPUT; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_INPUT) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_INPUT)) { + os += (first ? "" : " | "); + os += "CAMERA_INPUT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_INPUT; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::RENDERSCRIPT) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::RENDERSCRIPT)) { + os += (first ? "" : " | "); + os += "RENDERSCRIPT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::RENDERSCRIPT; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_DECODER) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_DECODER)) { + os += (first ? "" : " | "); + os += "VIDEO_DECODER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_DECODER; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::SENSOR_DIRECT_DATA) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::SENSOR_DIRECT_DATA)) { + os += (first ? "" : " | "); + os += "SENSOR_DIRECT_DATA"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::SENSOR_DIRECT_DATA; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_DATA_BUFFER) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_DATA_BUFFER)) { + os += (first ? "" : " | "); + os += "GPU_DATA_BUFFER"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_DATA_BUFFER; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK)) { + os += (first ? "" : " | "); + os += "VENDOR_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK_HI) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK_HI)) { + os += (first ? "" : " | "); + os += "VENDOR_MASK_HI"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK_HI; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_CUBE_MAP) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_CUBE_MAP)) { + os += (first ? "" : " | "); + os += "GPU_CUBE_MAP"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_CUBE_MAP; + } + if ((o & ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_MIPMAP_COMPLETE) == + static_cast( + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_MIPMAP_COMPLETE)) { + os += (first ? "" : " | "); + os += "GPU_MIPMAP_COMPLETE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_MIPMAP_COMPLETE; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_1::BufferUsage o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_MASK) { + return "CPU_READ_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_NEVER) { + return "CPU_READ_NEVER"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_RARELY) { + return "CPU_READ_RARELY"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_OFTEN) { + return "CPU_READ_OFTEN"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_MASK) { + return "CPU_WRITE_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_NEVER) { + return "CPU_WRITE_NEVER"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_RARELY) { + return "CPU_WRITE_RARELY"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_OFTEN) { + return "CPU_WRITE_OFTEN"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_TEXTURE) { + return "GPU_TEXTURE"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_RENDER_TARGET) { + return "GPU_RENDER_TARGET"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_OVERLAY) { + return "COMPOSER_OVERLAY"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CLIENT_TARGET) { + return "COMPOSER_CLIENT_TARGET"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::PROTECTED) { + return "PROTECTED"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CURSOR) { + return "COMPOSER_CURSOR"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_ENCODER) { + return "VIDEO_ENCODER"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_OUTPUT) { + return "CAMERA_OUTPUT"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_INPUT) { + return "CAMERA_INPUT"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::RENDERSCRIPT) { + return "RENDERSCRIPT"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_DECODER) { + return "VIDEO_DECODER"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::SENSOR_DIRECT_DATA) { + return "SENSOR_DIRECT_DATA"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_DATA_BUFFER) { + return "GPU_DATA_BUFFER"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK) { + return "VENDOR_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK_HI) { + return "VENDOR_MASK_HI"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_CUBE_MAP) { + return "GPU_CUBE_MAP"; + } + if (o == ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_MIPMAP_COMPLETE) { + return "GPU_MIPMAP_COMPLETE"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_1::Dataspace>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_1::Dataspace> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::UNKNOWN) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::UNKNOWN)) { + os += (first ? "" : " | "); + os += "UNKNOWN"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::UNKNOWN; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::ARBITRARY) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::ARBITRARY)) { + os += (first ? "" : " | "); + os += "ARBITRARY"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::ARBITRARY; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_SHIFT) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_SHIFT)) { + os += (first ? "" : " | "); + os += "STANDARD_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_MASK) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_MASK)) { + os += (first ? "" : " | "); + os += "STANDARD_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "STANDARD_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT709) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT709)) { + os += (first ? "" : " | "); + os += "STANDARD_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020)) { + os += (first ? "" : " | "); + os += "STANDARD_BT2020"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace:: + STANDARD_BT2020_CONSTANT_LUMINANCE) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace:: + STANDARD_BT2020_CONSTANT_LUMINANCE)) { + os += (first ? "" : " | "); + os += "STANDARD_BT2020_CONSTANT_LUMINANCE"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT470M) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT470M)) { + os += (first ? "" : " | "); + os += "STANDARD_BT470M"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT470M; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_FILM) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_FILM)) { + os += (first ? "" : " | "); + os += "STANDARD_FILM"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_FILM; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_DCI_P3) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_DCI_P3)) { + os += (first ? "" : " | "); + os += "STANDARD_DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_ADOBE_RGB) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "STANDARD_ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SHIFT) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SHIFT)) { + os += (first ? "" : " | "); + os += "TRANSFER_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_MASK) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_MASK)) { + os += (first ? "" : " | "); + os += "TRANSFER_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "TRANSFER_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_LINEAR)) { + os += (first ? "" : " | "); + os += "TRANSFER_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SRGB) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SRGB)) { + os += (first ? "" : " | "); + os += "TRANSFER_SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SMPTE_170M) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SMPTE_170M)) { + os += (first ? "" : " | "); + os += "TRANSFER_SMPTE_170M"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SMPTE_170M; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_2) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_2)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_2"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_2; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_6) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_6)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_6"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_6; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_8) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_8)) { + os += (first ? "" : " | "); + os += "TRANSFER_GAMMA2_8"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_8; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_ST2084) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_ST2084)) { + os += (first ? "" : " | "); + os += "TRANSFER_ST2084"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_ST2084; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_HLG) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_HLG)) { + os += (first ? "" : " | "); + os += "TRANSFER_HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_HLG; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_SHIFT) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::RANGE_SHIFT)) { + os += (first ? "" : " | "); + os += "RANGE_SHIFT"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_SHIFT; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_MASK) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::RANGE_MASK)) { + os += (first ? "" : " | "); + os += "RANGE_MASK"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_MASK; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_UNSPECIFIED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_UNSPECIFIED)) { + os += (first ? "" : " | "); + os += "RANGE_UNSPECIFIED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_UNSPECIFIED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_FULL) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::RANGE_FULL)) { + os += (first ? "" : " | "); + os += "RANGE_FULL"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_FULL; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_LIMITED) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::RANGE_LIMITED)) { + os += (first ? "" : " | "); + os += "RANGE_LIMITED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_LIMITED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_EXTENDED) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_EXTENDED)) { + os += (first ? "" : " | "); + os += "RANGE_EXTENDED"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_EXTENDED; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::SRGB_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::SRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "SRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::SRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "V0_SRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB_LINEAR)) { + os += (first ? "" : " | "); + os += "V0_SCRGB_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::SRGB) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::SRGB)) { + os += (first ? "" : " | "); + os += "SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB)) { + os += (first ? "" : " | "); + os += "V0_SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB)) { + os += (first ? "" : " | "); + os += "V0_SCRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::JFIF) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::JFIF)) { + os += (first ? "" : " | "); + os += "JFIF"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::JFIF; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_JFIF) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_JFIF)) { + os += (first ? "" : " | "); + os += "V0_JFIF"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_JFIF; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT601_625) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT601_625)) { + os += (first ? "" : " | "); + os += "BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_625) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_625)) { + os += (first ? "" : " | "); + os += "V0_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT601_525) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT601_525)) { + os += (first ? "" : " | "); + os += "BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_525) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_525)) { + os += (first ? "" : " | "); + os += "V0_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT709) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT709)) { + os += (first ? "" : " | "); + os += "BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT709; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT709) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::V0_BT709)) { + os += (first ? "" : " | "); + os += "V0_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3_LINEAR)) { + os += (first ? "" : " | "); + os += "DCI_P3_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3)) { + os += (first ? "" : " | "); + os += "DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3_LINEAR) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3_LINEAR)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::ADOBE_RGB) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_LINEAR) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020_LINEAR)) { + os += (first ? "" : " | "); + os += "BT2020_LINEAR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_LINEAR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020)) { + os += (first ? "" : " | "); + os += "BT2020"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_PQ) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020_PQ)) { + os += (first ? "" : " | "); + os += "BT2020_PQ"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_PQ; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::DEPTH) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::DEPTH)) { + os += (first ? "" : " | "); + os += "DEPTH"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::DEPTH; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::SENSOR) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::SENSOR)) { + os += (first ? "" : " | "); + os += "SENSOR"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::SENSOR; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU)) { + os += (first ? "" : " | "); + os += "BT2020_ITU"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_PQ) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_PQ)) { + os += (first ? "" : " | "); + os += "BT2020_ITU_PQ"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_PQ; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_HLG) == + static_cast( + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_HLG)) { + os += (first ? "" : " | "); + os += "BT2020_ITU_HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_HLG; + } + if ((o & ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_HLG) == + static_cast(::android::hardware::graphics::common::V1_1::Dataspace::BT2020_HLG)) { + os += (first ? "" : " | "); + os += "BT2020_HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_HLG; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_1::Dataspace o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::UNKNOWN) { + return "UNKNOWN"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::ARBITRARY) { + return "ARBITRARY"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_SHIFT) { + return "STANDARD_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_MASK) { + return "STANDARD_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_UNSPECIFIED) { + return "STANDARD_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT709) { + return "STANDARD_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625) { + return "STANDARD_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625_UNADJUSTED) { + return "STANDARD_BT601_625_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525) { + return "STANDARD_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525_UNADJUSTED) { + return "STANDARD_BT601_525_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020) { + return "STANDARD_BT2020"; + } + if (o == + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE) { + return "STANDARD_BT2020_CONSTANT_LUMINANCE"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT470M) { + return "STANDARD_BT470M"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_FILM) { + return "STANDARD_FILM"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_DCI_P3) { + return "STANDARD_DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_ADOBE_RGB) { + return "STANDARD_ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SHIFT) { + return "TRANSFER_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_MASK) { + return "TRANSFER_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_UNSPECIFIED) { + return "TRANSFER_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_LINEAR) { + return "TRANSFER_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SRGB) { + return "TRANSFER_SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SMPTE_170M) { + return "TRANSFER_SMPTE_170M"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_2) { + return "TRANSFER_GAMMA2_2"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_6) { + return "TRANSFER_GAMMA2_6"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_8) { + return "TRANSFER_GAMMA2_8"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_ST2084) { + return "TRANSFER_ST2084"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_HLG) { + return "TRANSFER_HLG"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_SHIFT) { + return "RANGE_SHIFT"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_MASK) { + return "RANGE_MASK"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_UNSPECIFIED) { + return "RANGE_UNSPECIFIED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_FULL) { + return "RANGE_FULL"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_LIMITED) { + return "RANGE_LIMITED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_EXTENDED) { + return "RANGE_EXTENDED"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::SRGB_LINEAR) { + return "SRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB_LINEAR) { + return "V0_SRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB_LINEAR) { + return "V0_SCRGB_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::SRGB) { + return "SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB) { + return "V0_SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB) { + return "V0_SCRGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::JFIF) { + return "JFIF"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_JFIF) { + return "V0_JFIF"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT601_625) { + return "BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_625) { + return "V0_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT601_525) { + return "BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_525) { + return "V0_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT709) { + return "BT709"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT709) { + return "V0_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3_LINEAR) { + return "DCI_P3_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3) { + return "DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3_LINEAR) { + return "DISPLAY_P3_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3) { + return "DISPLAY_P3"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::ADOBE_RGB) { + return "ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_LINEAR) { + return "BT2020_LINEAR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020) { + return "BT2020"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_PQ) { + return "BT2020_PQ"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::DEPTH) { + return "DEPTH"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::SENSOR) { + return "SENSOR"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU) { + return "BT2020_ITU"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_PQ) { + return "BT2020_ITU_PQ"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_HLG) { + return "BT2020_ITU_HLG"; + } + if (o == ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_HLG) { + return "BT2020_HLG"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_1::ColorMode>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_1::ColorMode> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::NATIVE) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::NATIVE)) { + os += (first ? "" : " | "); + os += "NATIVE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::NATIVE; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625) == + static_cast( + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_625_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525) == + static_cast( + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525_UNADJUSTED) == + static_cast( + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525_UNADJUSTED)) { + os += (first ? "" : " | "); + os += "STANDARD_BT601_525_UNADJUSTED"; + first = false; + flipped |= + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525_UNADJUSTED; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT709) == + static_cast( + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT709)) { + os += (first ? "" : " | "); + os += "STANDARD_BT709"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT709; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::DCI_P3) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::DCI_P3)) { + os += (first ? "" : " | "); + os += "DCI_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::DCI_P3; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::SRGB) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::SRGB)) { + os += (first ? "" : " | "); + os += "SRGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::SRGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::ADOBE_RGB) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::ADOBE_RGB)) { + os += (first ? "" : " | "); + os += "ADOBE_RGB"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::ADOBE_RGB; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::DISPLAY_P3) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::DISPLAY_P3)) { + os += (first ? "" : " | "); + os += "DISPLAY_P3"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::DISPLAY_P3; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::BT2020) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::BT2020)) { + os += (first ? "" : " | "); + os += "BT2020"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::BT2020; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_PQ) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::BT2100_PQ)) { + os += (first ? "" : " | "); + os += "BT2100_PQ"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_PQ; + } + if ((o & ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_HLG) == + static_cast(::android::hardware::graphics::common::V1_1::ColorMode::BT2100_HLG)) { + os += (first ? "" : " | "); + os += "BT2100_HLG"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_HLG; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_1::ColorMode o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::NATIVE) { + return "NATIVE"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625) { + return "STANDARD_BT601_625"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625_UNADJUSTED) { + return "STANDARD_BT601_625_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525) { + return "STANDARD_BT601_525"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525_UNADJUSTED) { + return "STANDARD_BT601_525_UNADJUSTED"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT709) { + return "STANDARD_BT709"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::DCI_P3) { + return "DCI_P3"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::SRGB) { + return "SRGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::ADOBE_RGB) { + return "ADOBE_RGB"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::DISPLAY_P3) { + return "DISPLAY_P3"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::BT2020) { + return "BT2020"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_PQ) { + return "BT2100_PQ"; + } + if (o == ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_HLG) { + return "BT2100_HLG"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::android::hardware::graphics::common::V1_1::RenderIntent>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_1::RenderIntent> + flipped = 0; + bool first = true; + if ((o & ::android::hardware::graphics::common::V1_1::RenderIntent::COLORIMETRIC) == + static_cast( + ::android::hardware::graphics::common::V1_1::RenderIntent::COLORIMETRIC)) { + os += (first ? "" : " | "); + os += "COLORIMETRIC"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::RenderIntent::COLORIMETRIC; + } + if ((o & ::android::hardware::graphics::common::V1_1::RenderIntent::ENHANCE) == + static_cast(::android::hardware::graphics::common::V1_1::RenderIntent::ENHANCE)) { + os += (first ? "" : " | "); + os += "ENHANCE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::RenderIntent::ENHANCE; + } + if ((o & ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_COLORIMETRIC) == + static_cast( + ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_COLORIMETRIC)) { + os += (first ? "" : " | "); + os += "TONE_MAP_COLORIMETRIC"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_COLORIMETRIC; + } + if ((o & ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_ENHANCE) == + static_cast( + ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_ENHANCE)) { + os += (first ? "" : " | "); + os += "TONE_MAP_ENHANCE"; + first = false; + flipped |= ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_ENHANCE; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::common::V1_1::RenderIntent o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::common::V1_1::RenderIntent::COLORIMETRIC) { + return "COLORIMETRIC"; + } + if (o == ::android::hardware::graphics::common::V1_1::RenderIntent::ENHANCE) { + return "ENHANCE"; + } + if (o == ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_COLORIMETRIC) { + return "TONE_MAP_COLORIMETRIC"; + } + if (o == ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_ENHANCE) { + return "TONE_MAP_ENHANCE"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +} // namespace V1_1 +} // namespace common +} // namespace graphics +} // namespace hardware +} // namespace android + +// +// global type declarations for package +// + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_1::PixelFormat, 27> + hidl_enum_values<::android::hardware::graphics::common::V1_1::PixelFormat> = { + ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_8888, + ::android::hardware::graphics::common::V1_1::PixelFormat::RGBX_8888, + ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_888, + ::android::hardware::graphics::common::V1_1::PixelFormat::RGB_565, + ::android::hardware::graphics::common::V1_1::PixelFormat::BGRA_8888, + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_SP, + ::android::hardware::graphics::common::V1_1::PixelFormat::YCRCB_420_SP, + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_422_I, + ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_FP16, + ::android::hardware::graphics::common::V1_1::PixelFormat::RAW16, + ::android::hardware::graphics::common::V1_1::PixelFormat::BLOB, + ::android::hardware::graphics::common::V1_1::PixelFormat::IMPLEMENTATION_DEFINED, + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_420_888, + ::android::hardware::graphics::common::V1_1::PixelFormat::RAW_OPAQUE, + ::android::hardware::graphics::common::V1_1::PixelFormat::RAW10, + ::android::hardware::graphics::common::V1_1::PixelFormat::RAW12, + ::android::hardware::graphics::common::V1_1::PixelFormat::RGBA_1010102, + ::android::hardware::graphics::common::V1_1::PixelFormat::Y8, + ::android::hardware::graphics::common::V1_1::PixelFormat::Y16, + ::android::hardware::graphics::common::V1_1::PixelFormat::YV12, + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_16, + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24, + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_24_STENCIL_8, + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F, + ::android::hardware::graphics::common::V1_1::PixelFormat::DEPTH_32F_STENCIL_8, + ::android::hardware::graphics::common::V1_1::PixelFormat::STENCIL_8, + ::android::hardware::graphics::common::V1_1::PixelFormat::YCBCR_P010, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_1::BufferUsage, 25> + hidl_enum_values<::android::hardware::graphics::common::V1_1::BufferUsage> = { + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_MASK, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_NEVER, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_RARELY, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_READ_OFTEN, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_MASK, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_NEVER, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_RARELY, + ::android::hardware::graphics::common::V1_1::BufferUsage::CPU_WRITE_OFTEN, + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_TEXTURE, + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_RENDER_TARGET, + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_OVERLAY, + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CLIENT_TARGET, + ::android::hardware::graphics::common::V1_1::BufferUsage::PROTECTED, + ::android::hardware::graphics::common::V1_1::BufferUsage::COMPOSER_CURSOR, + ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_ENCODER, + ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_OUTPUT, + ::android::hardware::graphics::common::V1_1::BufferUsage::CAMERA_INPUT, + ::android::hardware::graphics::common::V1_1::BufferUsage::RENDERSCRIPT, + ::android::hardware::graphics::common::V1_1::BufferUsage::VIDEO_DECODER, + ::android::hardware::graphics::common::V1_1::BufferUsage::SENSOR_DIRECT_DATA, + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_DATA_BUFFER, + ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK, + ::android::hardware::graphics::common::V1_1::BufferUsage::VENDOR_MASK_HI, + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_CUBE_MAP, + ::android::hardware::graphics::common::V1_1::BufferUsage::GPU_MIPMAP_COMPLETE, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_1::Dataspace, 61> + hidl_enum_values<::android::hardware::graphics::common::V1_1::Dataspace> = { + ::android::hardware::graphics::common::V1_1::Dataspace::UNKNOWN, + ::android::hardware::graphics::common::V1_1::Dataspace::ARBITRARY, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_SHIFT, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_MASK, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_UNSPECIFIED, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT709, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_625_UNADJUSTED, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT601_525_UNADJUSTED, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_BT470M, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_FILM, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_DCI_P3, + ::android::hardware::graphics::common::V1_1::Dataspace::STANDARD_ADOBE_RGB, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SHIFT, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_MASK, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_UNSPECIFIED, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SRGB, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_SMPTE_170M, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_2, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_6, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_GAMMA2_8, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_ST2084, + ::android::hardware::graphics::common::V1_1::Dataspace::TRANSFER_HLG, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_SHIFT, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_MASK, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_UNSPECIFIED, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_FULL, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_LIMITED, + ::android::hardware::graphics::common::V1_1::Dataspace::RANGE_EXTENDED, + ::android::hardware::graphics::common::V1_1::Dataspace::SRGB_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::SRGB, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SRGB, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_SCRGB, + ::android::hardware::graphics::common::V1_1::Dataspace::JFIF, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_JFIF, + ::android::hardware::graphics::common::V1_1::Dataspace::BT601_625, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_625, + ::android::hardware::graphics::common::V1_1::Dataspace::BT601_525, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT601_525, + ::android::hardware::graphics::common::V1_1::Dataspace::BT709, + ::android::hardware::graphics::common::V1_1::Dataspace::V0_BT709, + ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::DCI_P3, + ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::DISPLAY_P3, + ::android::hardware::graphics::common::V1_1::Dataspace::ADOBE_RGB, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_LINEAR, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_PQ, + ::android::hardware::graphics::common::V1_1::Dataspace::DEPTH, + ::android::hardware::graphics::common::V1_1::Dataspace::SENSOR, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_PQ, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_ITU_HLG, + ::android::hardware::graphics::common::V1_1::Dataspace::BT2020_HLG, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_1::ColorMode, 13> + hidl_enum_values<::android::hardware::graphics::common::V1_1::ColorMode> = { + ::android::hardware::graphics::common::V1_1::ColorMode::NATIVE, + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625, + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_625_UNADJUSTED, + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525, + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT601_525_UNADJUSTED, + ::android::hardware::graphics::common::V1_1::ColorMode::STANDARD_BT709, + ::android::hardware::graphics::common::V1_1::ColorMode::DCI_P3, + ::android::hardware::graphics::common::V1_1::ColorMode::SRGB, + ::android::hardware::graphics::common::V1_1::ColorMode::ADOBE_RGB, + ::android::hardware::graphics::common::V1_1::ColorMode::DISPLAY_P3, + ::android::hardware::graphics::common::V1_1::ColorMode::BT2020, + ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_PQ, + ::android::hardware::graphics::common::V1_1::ColorMode::BT2100_HLG, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::common::V1_1::RenderIntent, 4> + hidl_enum_values<::android::hardware::graphics::common::V1_1::RenderIntent> = { + ::android::hardware::graphics::common::V1_1::RenderIntent::COLORIMETRIC, + ::android::hardware::graphics::common::V1_1::RenderIntent::ENHANCE, + ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_COLORIMETRIC, + ::android::hardware::graphics::common::V1_1::RenderIntent::TONE_MAP_ENHANCE, +}; +} // namespace details +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_TYPES_H diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapper.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapper.h new file mode 100644 index 0000000000..ce126427de --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapper.h @@ -0,0 +1,250 @@ +#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H +#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace mapper { +namespace V2_0 { + +// Forward declaration for forward reference support: +enum class Error : int32_t; +struct YCbCrLayout; + +enum class Error : int32_t { + NONE = 0, + BAD_DESCRIPTOR = 1, + BAD_BUFFER = 2, + BAD_VALUE = 3, + NO_RESOURCES = 5, + UNSUPPORTED = 7, +}; + +/** + * A buffer descriptor is an implementation-defined opaque data returned by + * createDescriptor. It describes the properties of a buffer and is consumed + * by the allocator. + */ +typedef ::android::hardware::hidl_vec BufferDescriptor; + +/** + * Structure for describing YCbCr formats for consumption by applications. + * This is used with PixelFormat::YCBCR_*_888. + * + * Buffer chroma subsampling is defined in the format. + * e.g. PixelFormat::YCBCR_420_888 has subsampling 4:2:0. + * + * Buffers must have a 8 bit depth. + * + * y, cb, and cr point to the first byte of their respective planes. + * + * Stride describes the distance in bytes from the first value of one row of + * the image to the first value of the next row. It includes the width of the + * image plus padding. + * yStride is the stride of the luma plane. + * cStride is the stride of the chroma planes. + * + * chromaStep is the distance in bytes from one chroma pixel value to the + * next. This is 2 bytes for semiplanar (because chroma values are interleaved + * and each chroma value is one byte) and 1 for planar. + */ +struct YCbCrLayout final { + void* y; + void* cb; + void* cr; + uint32_t yStride; + uint32_t cStride; + uint32_t chromaStep; +}; + +// +// type declarations for package +// + +template +static inline std::string toString(int32_t o); +static inline std::string toString(::android::hardware::graphics::mapper::V2_0::Error o); + +constexpr int32_t operator|(const ::android::hardware::graphics::mapper::V2_0::Error lhs, + const ::android::hardware::graphics::mapper::V2_0::Error rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|(const int32_t lhs, + const ::android::hardware::graphics::mapper::V2_0::Error rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|(const ::android::hardware::graphics::mapper::V2_0::Error lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&(const ::android::hardware::graphics::mapper::V2_0::Error lhs, + const ::android::hardware::graphics::mapper::V2_0::Error rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&(const int32_t lhs, + const ::android::hardware::graphics::mapper::V2_0::Error rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&(const ::android::hardware::graphics::mapper::V2_0::Error lhs, + const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=(int32_t& v, + const ::android::hardware::graphics::mapper::V2_0::Error e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=(int32_t& v, + const ::android::hardware::graphics::mapper::V2_0::Error e) { + v &= static_cast(e); + return v; +} + +static inline std::string toString( + const ::android::hardware::graphics::mapper::V2_0::YCbCrLayout& o); +// operator== and operator!= are not generated for YCbCrLayout + +// +// type header definitions for package +// + +template <> +inline std::string toString<::android::hardware::graphics::mapper::V2_0::Error>(int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield<::android::hardware::graphics::mapper::V2_0::Error> flipped = + 0; + bool first = true; + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::NONE) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::NONE)) { + os += (first ? "" : " | "); + os += "NONE"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::NONE; + } + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR)) { + os += (first ? "" : " | "); + os += "BAD_DESCRIPTOR"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR; + } + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER)) { + os += (first ? "" : " | "); + os += "BAD_BUFFER"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER; + } + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE)) { + os += (first ? "" : " | "); + os += "BAD_VALUE"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE; + } + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES)) { + os += (first ? "" : " | "); + os += "NO_RESOURCES"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES; + } + if ((o & ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED) == + static_cast(::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED)) { + os += (first ? "" : " | "); + os += "UNSUPPORTED"; + first = false; + flipped |= ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString(::android::hardware::graphics::mapper::V2_0::Error o) { + using ::android::hardware::details::toHexString; + if (o == ::android::hardware::graphics::mapper::V2_0::Error::NONE) { + return "NONE"; + } + if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR) { + return "BAD_DESCRIPTOR"; + } + if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER) { + return "BAD_BUFFER"; + } + if (o == ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE) { + return "BAD_VALUE"; + } + if (o == ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES) { + return "NO_RESOURCES"; + } + if (o == ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED) { + return "UNSUPPORTED"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +static inline std::string toString( + const ::android::hardware::graphics::mapper::V2_0::YCbCrLayout& o) { + using ::android::hardware::toString; + std::string os; + os += "{"; + os += ".y = "; + os += ::android::hardware::toString(o.y); + os += ", .cb = "; + os += ::android::hardware::toString(o.cb); + os += ", .cr = "; + os += ::android::hardware::toString(o.cr); + os += ", .yStride = "; + os += ::android::hardware::toString(o.yStride); + os += ", .cStride = "; + os += ::android::hardware::toString(o.cStride); + os += ", .chromaStep = "; + os += ::android::hardware::toString(o.chromaStep); + os += "}"; + return os; +} + +// operator== and operator!= are not generated for YCbCrLayout + +} // namespace V2_0 +} // namespace mapper +} // namespace graphics +} // namespace hardware +} // namespace android + +// +// global type declarations for package +// + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::android::hardware::graphics::mapper::V2_0::Error, 6> + hidl_enum_values<::android::hardware::graphics::mapper::V2_0::Error> = { + ::android::hardware::graphics::mapper::V2_0::Error::NONE, + ::android::hardware::graphics::mapper::V2_0::Error::BAD_DESCRIPTOR, + ::android::hardware::graphics::mapper::V2_0::Error::BAD_BUFFER, + ::android::hardware::graphics::mapper::V2_0::Error::BAD_VALUE, + ::android::hardware::graphics::mapper::V2_0::Error::NO_RESOURCES, + ::android::hardware::graphics::mapper::V2_0::Error::UNSUPPORTED, +}; +} // namespace details +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapperextensions.h b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapperextensions.h new file mode 100644 index 0000000000..79fddd18e4 --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/ext/types/mapperextensions.h @@ -0,0 +1,707 @@ +#ifndef HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H +#define HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H + +#include +#include +#include +#include + +namespace vendor { +namespace qti { +namespace hardware { +namespace display { +namespace mapperextensions { +namespace V1_0 { + +// Forward declaration for forward reference support: +enum class Error : int32_t; +struct YCbCrLayout; +enum class PlaneComponent : uint32_t; +enum class Flags : int32_t; +struct PlaneLayout; + +enum class Error : int32_t { + NONE = 0, + BAD_BUFFER = 2, + NO_RESOURCES = 5, + UNSUPPORTED = 7, +}; + +struct YCbCrLayout final { + void* y; + void* cb; + void* cr; + uint32_t yStride; + uint32_t cStride; + uint32_t chromaStep; +}; + +/** + * Plane Component type definitions. + */ +enum class PlaneComponent : uint32_t { + PLANE_COMPONENT_Y = 1u /* (1 << 0) */, + PLANE_COMPONENT_Cb = 2u /* (1 << 1) */, + PLANE_COMPONENT_Cr = 4u /* (1 << 2) */, + PLANE_COMPONENT_R = 1024u /* (1 << 10) */, + PLANE_COMPONENT_G = 2048u /* (1 << 11) */, + PLANE_COMPONENT_B = 4096u /* (1 << 12) */, + PLANE_COMPONENT_A = 1048576u /* (1 << 20) */, + PLANE_COMPONENT_RAW = 1073741824u /* (1 << 30) */, + PLANE_COMPONENT_META = 2147483648u /* (1 << 31) */, +}; + +/** + * Flags to send with getFormatLayout for extra information for e.g. interlaced, + * otherwise send 0. + */ +enum class Flags : int32_t { + LAYOUT_INTERLACED_FLAG = 1 /* (1 << 0) */, +}; + +/** + * Structure for describing plane layout information for YUVA/RGBA/RAW formats + * YUV formats can be planar or semi-planar. + * + * This layout structure is used with any pixel format that can be + * represented by it, such as: + * - HAL_PIXEL_FORMAT_YCbCr_* + * - HAL_PIXEL_FORMAT_RGB*_* + * - even implementation defined formats that can be represented by + * the structures + * + * Each plane can be made up of one or more PlaneComponents depending on + * the format. + * + * Each plane can be subsampled either vertically or horizontally by + * a power-of-two factor. + * + * Pixel increment describes the distance in bytes from one pixel to the + * next pixel (to the right) on the same row for the component plane. + * This can be negative. + * + * Stride is provided in both pixels and bytes. + * Stride_bytes describes the distance in bytes from the first pixel of + * one row to the first pixel of the next row (below) for the component plane. + * This can be negative. + * + * Scanlines describes the height of the plane in terms of number of rows. + * + * Size of plane is stride_bytes * scanlines + any padding required for + * alignment as per format specification. + * + */ +struct PlaneLayout final { + ::android::hardware::hidl_bitfield< + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> + component __attribute__((aligned(4))); + uint32_t h_subsampling __attribute__((aligned(4))); + uint32_t v_subsampling __attribute__((aligned(4))); + uint32_t offset __attribute__((aligned(4))); + int32_t pixel_increment __attribute__((aligned(4))); + int32_t stride __attribute__((aligned(4))); + int32_t stride_bytes __attribute__((aligned(4))); + int32_t scanlines __attribute__((aligned(4))); + uint32_t size __attribute__((aligned(4))); +}; + +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + component) == 0, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + h_subsampling) == 4, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + v_subsampling) == 8, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + offset) == 12, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + pixel_increment) == 16, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + stride) == 20, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + stride_bytes) == 24, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + scanlines) == 28, + "wrong offset"); +static_assert(offsetof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout, + size) == 32, + "wrong offset"); +static_assert(sizeof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout) == 36, + "wrong size"); +static_assert(__alignof(::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout) == 4, + "wrong alignment"); + +// +// type declarations for package +// + +template +static inline std::string toString(int32_t o); +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error o); + +constexpr int32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|( + const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&( + const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error lhs, const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=( + int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=( + int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Error e) { + v &= static_cast(e); + return v; +} + +static inline std::string toString( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::YCbCrLayout& o); +// operator== and operator!= are not generated for YCbCrLayout + +template +static inline std::string toString(uint32_t o); +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent o); + +constexpr uint32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr uint32_t operator|( + const uint32_t lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr uint32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, + const uint32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr uint32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr uint32_t operator&( + const uint32_t lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr uint32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent lhs, + const uint32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr uint32_t& operator|=( + uint32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent e) { + v |= static_cast(e); + return v; +} +constexpr uint32_t& operator&=( + uint32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent e) { + v &= static_cast(e); + return v; +} + +template +static inline std::string toString(int32_t o); +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags o); + +constexpr int32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { + return static_cast(static_cast(lhs) | static_cast(rhs)); +} +constexpr int32_t operator|( + const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { + return static_cast(lhs | static_cast(rhs)); +} +constexpr int32_t operator|( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, const int32_t rhs) { + return static_cast(static_cast(lhs) | rhs); +} +constexpr int32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { + return static_cast(static_cast(lhs) & static_cast(rhs)); +} +constexpr int32_t operator&( + const int32_t lhs, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags rhs) { + return static_cast(lhs & static_cast(rhs)); +} +constexpr int32_t operator&( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags lhs, const int32_t rhs) { + return static_cast(static_cast(lhs) & rhs); +} +constexpr int32_t& operator|=( + int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags e) { + v |= static_cast(e); + return v; +} +constexpr int32_t& operator&=( + int32_t& v, const ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags e) { + v &= static_cast(e); + return v; +} + +static inline std::string toString( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& o); +static inline bool operator==( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs); +static inline bool operator!=( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs); + +// +// type header definitions for package +// + +template <> +inline std::string toString<::vendor::qti::hardware::display::mapperextensions::V1_0::Error>( + int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield< + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error> + flipped = 0; + bool first = true; + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE)) { + os += (first ? "" : " | "); + os += "NONE"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER) == + static_cast( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER)) { + os += (first ? "" : " | "); + os += "BAD_BUFFER"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES) == + static_cast( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES)) { + os += (first ? "" : " | "); + os += "NO_RESOURCES"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED) == + static_cast( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED)) { + os += (first ? "" : " | "); + os += "UNSUPPORTED"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error o) { + using ::android::hardware::details::toHexString; + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE) { + return "NONE"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER) { + return "BAD_BUFFER"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES) { + return "NO_RESOURCES"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED) { + return "UNSUPPORTED"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +static inline std::string toString( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::YCbCrLayout& o) { + using ::android::hardware::toString; + std::string os; + os += "{"; + os += ".y = "; + os += ::android::hardware::toString(o.y); + os += ", .cb = "; + os += ::android::hardware::toString(o.cb); + os += ", .cr = "; + os += ::android::hardware::toString(o.cr); + os += ", .yStride = "; + os += ::android::hardware::toString(o.yStride); + os += ", .cStride = "; + os += ::android::hardware::toString(o.cStride); + os += ", .chromaStep = "; + os += ::android::hardware::toString(o.chromaStep); + os += "}"; + return os; +} + +// operator== and operator!= are not generated for YCbCrLayout + +template <> +inline std::string +toString<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent>(uint32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield< + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> + flipped = 0; + bool first = true; + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Y) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_Y)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_Y"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cb) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_Cb)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_Cb"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cb; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cr) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_Cr)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_Cr"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cr; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_R) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_R)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_R"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_G) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_G)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_G"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_B) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_B)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_B"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_A) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_A)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_A"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_RAW) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_RAW)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_RAW"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_RAW; + } + if ((o & ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_META) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0:: + PlaneComponent::PLANE_COMPONENT_META)) { + os += (first ? "" : " | "); + os += "PLANE_COMPONENT_META"; + first = false; + flipped |= ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_META; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent o) { + using ::android::hardware::details::toHexString; + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y) { + return "PLANE_COMPONENT_Y"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cb) { + return "PLANE_COMPONENT_Cb"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cr) { + return "PLANE_COMPONENT_Cr"; + } + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R) { + return "PLANE_COMPONENT_R"; + } + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G) { + return "PLANE_COMPONENT_G"; + } + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B) { + return "PLANE_COMPONENT_B"; + } + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A) { + return "PLANE_COMPONENT_A"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_RAW) { + return "PLANE_COMPONENT_RAW"; + } + if (o == ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_META) { + return "PLANE_COMPONENT_META"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +template <> +inline std::string toString<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags>( + int32_t o) { + using ::android::hardware::details::toHexString; + std::string os; + ::android::hardware::hidl_bitfield< + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags> + flipped = 0; + bool first = true; + if ((o & + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG) == + static_cast(::vendor::qti::hardware::display::mapperextensions::V1_0::Flags:: + LAYOUT_INTERLACED_FLAG)) { + os += (first ? "" : " | "); + os += "LAYOUT_INTERLACED_FLAG"; + first = false; + flipped |= + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG; + } + if (o != flipped) { + os += (first ? "" : " | "); + os += toHexString(o & (~flipped)); + } + os += " ("; + os += toHexString(o); + os += ")"; + return os; +} + +static inline std::string toString( + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags o) { + using ::android::hardware::details::toHexString; + if (o == + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG) { + return "LAYOUT_INTERLACED_FLAG"; + } + std::string os; + os += toHexString(static_cast(o)); + return os; +} + +static inline std::string toString( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& o) { + using ::android::hardware::toString; + std::string os; + os += "{"; + os += ".component = "; + os += ::vendor::qti::hardware::display::mapperextensions::V1_0::toString< + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent>(o.component); + os += ", .h_subsampling = "; + os += ::android::hardware::toString(o.h_subsampling); + os += ", .v_subsampling = "; + os += ::android::hardware::toString(o.v_subsampling); + os += ", .offset = "; + os += ::android::hardware::toString(o.offset); + os += ", .pixel_increment = "; + os += ::android::hardware::toString(o.pixel_increment); + os += ", .stride = "; + os += ::android::hardware::toString(o.stride); + os += ", .stride_bytes = "; + os += ::android::hardware::toString(o.stride_bytes); + os += ", .scanlines = "; + os += ::android::hardware::toString(o.scanlines); + os += ", .size = "; + os += ::android::hardware::toString(o.size); + os += "}"; + return os; +} + +static inline bool operator==( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs) { + if (lhs.component != rhs.component) { + return false; + } + if (lhs.h_subsampling != rhs.h_subsampling) { + return false; + } + if (lhs.v_subsampling != rhs.v_subsampling) { + return false; + } + if (lhs.offset != rhs.offset) { + return false; + } + if (lhs.pixel_increment != rhs.pixel_increment) { + return false; + } + if (lhs.stride != rhs.stride) { + return false; + } + if (lhs.stride_bytes != rhs.stride_bytes) { + return false; + } + if (lhs.scanlines != rhs.scanlines) { + return false; + } + if (lhs.size != rhs.size) { + return false; + } + return true; +} + +static inline bool operator!=( + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& lhs, + const ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneLayout& rhs) { + return !(lhs == rhs); +} + +} // namespace V1_0 +} // namespace mapperextensions +} // namespace display +} // namespace hardware +} // namespace qti +} // namespace vendor + +// +// global type declarations for package +// + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::Error, 4> + hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::Error> = { + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NONE, + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::BAD_BUFFER, + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::NO_RESOURCES, + ::vendor::qti::hardware::display::mapperextensions::V1_0::Error::UNSUPPORTED, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent, 9> + hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent> = { + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_Y, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cb, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_Cr, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_R, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_G, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_B, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent::PLANE_COMPONENT_A, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_RAW, + ::vendor::qti::hardware::display::mapperextensions::V1_0::PlaneComponent:: + PLANE_COMPONENT_META, +}; +} // namespace details +} // namespace hardware +} // namespace android + +namespace android { +namespace hardware { +namespace details { +template <> +constexpr std::array<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags, 1> + hidl_enum_values<::vendor::qti::hardware::display::mapperextensions::V1_0::Flags> = { + ::vendor::qti::hardware::display::mapperextensions::V1_0::Flags::LAYOUT_INTERLACED_FLAG, +}; +} // namespace details +} // namespace hardware +} // namespace android + +#endif // HIDL_GENERATED_VENDOR_QTI_HARDWARE_DISPLAY_MAPPEREXTENSIONS_V1_0_TYPES_H diff --git a/app/src/main/cpp/adrenotools/tools/qtimapper-shim/shim.cpp b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/shim.cpp new file mode 100644 index 0000000000..34dd68296c --- /dev/null +++ b/app/src/main/cpp/adrenotools/tools/qtimapper-shim/shim.cpp @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2016-2022, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "qtimapper-shim" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ext/common.h" +#include "ext/gr_utils.h" +#include "ext/mapper.h" +#include "ext/mapperextensions.h" + +using namespace android::hardware; +using namespace android; + +// These two functions are used by the blob and aren't present on Q so weakly stub them +extern "C" uint64_t __attribute__((weak)) atrace_get_enabled_tags() { + return 0; +} + +namespace android::hardware::details { +void __attribute__((weak)) return_status::onValueRetrieval() const {} +} // namespace android::hardware::details + +bool IBase::isRemote() const { + return false; +} + +sp (*Mapper20GetService)(const std::string&, const bool); +sp (*Mapper30GetService)(const std::string&, const bool); +sp (*Mapper40GetService)(const std::string&, const bool); + +Return> (*QtiMapper20CastFrom)( + const sp&, bool); +Return> (*QtiMapper30CastFrom)( + const sp&, bool); +Return> (*QtiMapper40CastFrom)( + const sp&, bool); + +Return> ( + *MapperExtensions11CastFrom)( + const sp&, bool); + +__attribute__((constructor)) static void initShim() { + void* qtiMapper40Hnd = + dlopen("vendor.qti.hardware.display.mapper@4.0.so", RTLD_LAZY | RTLD_LOCAL); + if (qtiMapper40Hnd) { + void* mapper40Hnd = dlopen("android.hardware.graphics.mapper@4.0.so", RTLD_LAZY | RTLD_LOCAL); + if (mapper40Hnd) { + Mapper40GetService = reinterpret_cast( + dlsym(mapper40Hnd, + "_ZN7android8hardware8graphics6mapper4V4_07IMapper10getServiceERKNSt3__112basic_" + "stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); + QtiMapper40CastFrom = reinterpret_cast(dlsym( + qtiMapper40Hnd, + "_ZN6vendor3qti8hardware7display6mapper4V4_010IQtiMapper8castFromERKN7android2spINS6_" + "8hardware8graphics6mapper4V4_07IMapperEEEb")); + + ALOGD("%s: Mapper 4.0 present", __func__); + } + } + + void* qtiMapper30Hnd = + dlopen("vendor.qti.hardware.display.mapper@3.0.so", RTLD_LAZY | RTLD_LOCAL); + if (qtiMapper30Hnd) { + void* mapper30Hnd = dlopen("android.hardware.graphics.mapper@3.0.so", RTLD_LAZY | RTLD_LOCAL); + if (mapper30Hnd) { + Mapper30GetService = reinterpret_cast( + dlsym(mapper30Hnd, + "_ZN7android8hardware8graphics6mapper4V3_07IMapper10getServiceERKNSt3__112basic_" + "stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); + QtiMapper30CastFrom = reinterpret_cast(dlsym( + qtiMapper30Hnd, + "_ZN6vendor3qti8hardware7display6mapper4V3_010IQtiMapper8castFromERKN7android2spINS6_" + "8hardware8graphics6mapper4V3_07IMapperEEEb")); + ALOGD("%s: Mapper 3.0 present", __func__); + } + } + + void* qtiMapper20Hnd = + dlopen("vendor.qti.hardware.display.mapper@2.0.so", RTLD_LAZY | RTLD_LOCAL); + if (qtiMapper20Hnd) { + void* mapper20Hnd = dlopen("android.hardware.graphics.mapper@2.0.so", RTLD_LAZY | RTLD_LOCAL); + if (mapper20Hnd) { + Mapper20GetService = reinterpret_cast( + dlsym(mapper20Hnd, + "_ZN7android8hardware8graphics6mapper4V2_07IMapper10getServiceERKNSt3__112basic_" + "stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEb")); + QtiMapper20CastFrom = reinterpret_cast(dlsym( + qtiMapper20Hnd, + "_ZN6vendor3qti8hardware7display6mapper4V2_010IQtiMapper8castFromERKN7android2spINS6_" + "8hardware8graphics6mapper4V2_07IMapperEEEb")); + ALOGD("%s: Mapper 2.0 present", __func__); + } + } + + void* mapperExtensions11Hnd = + dlopen("vendor.qti.hardware.display.mapperextensions@1.1.so", RTLD_LAZY | RTLD_LOCAL); + if (mapperExtensions11Hnd) { + MapperExtensions11CastFrom = reinterpret_cast(dlsym( + mapperExtensions11Hnd, + "_ZN6vendor3qti8hardware7display16mapperextensions4V1_" + "120IQtiMapperExtensions8castFromERKN7android2spINS3_4V1_020IQtiMapperExtensionsEEEb")); + ALOGD("%s: Mapper Extensions 1.1 present", __func__); + } +} + +namespace android::hardware::graphics::mapper { +namespace V2_0 { + +sp IMapper::getService(const std::string& serviceName, const bool getStub) { + if (Mapper20GetService) return Mapper20GetService(serviceName, getStub); + return nullptr; +} + +} // namespace V2_0 +namespace V3_0 { + +sp IMapper::getService(const std::string& serviceName, const bool getStub) { + if (Mapper30GetService) return Mapper30GetService(serviceName, getStub); + return nullptr; +} + +} // namespace V3_0 +namespace V4_0 { + +sp IMapper::getService(const std::string& serviceName, const bool getStub) { + if (Mapper40GetService) return Mapper40GetService(serviceName, getStub); + return nullptr; +} + +} // namespace V4_0 +} // namespace android::hardware::graphics::mapper +namespace vendor::qti::hardware::display { +namespace mapper { +namespace V4_0 { + +Return> IQtiMapper::castFrom(const sp& parent, + bool emitError) { + if (QtiMapper40CastFrom) return QtiMapper40CastFrom(parent, emitError); + return nullptr; +} + +} // namespace V4_0 +namespace V3_0 { + +Return> IQtiMapper::castFrom(const sp& parent, + bool emitError) { + if (QtiMapper30CastFrom) return QtiMapper30CastFrom(parent, emitError); + return nullptr; +} + +} // namespace V3_0 +namespace V2_0 { + +Return> IQtiMapper::castFrom(const sp& parent, + bool emitError) { + if (QtiMapper20CastFrom) return QtiMapper20CastFrom(parent, emitError); + + return new IQtiMapper(); +} + +Return IQtiMapper::getMapperExtensions(getMapperExtensions_cb _hidl_cb) { + sp ext{ + new mapperextensions::V1_0::IQtiMapperExtensions()}; + _hidl_cb(graphics::mapper::V2_0::Error::NONE, ext); + return Void(); +} + +} // namespace V2_0 +} // namespace mapper +namespace mapperextensions { +namespace V1_1 { + +IQtiMapperExtensions::IQtiMapperExtensions() { + ALOGI("IQtiMapperExtensions shim active"); + + hw_module_t const* module; + if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) { + ALOGE("Failed to open gralloc module!"); + std::terminate(); + } + + if (gralloc1_open(module, &gralloc)) { + ALOGE("Failed to open gralloc HAL!"); + std::terminate(); + } + + perform = reinterpret_cast( + gralloc->getFunction(gralloc, GRALLOC1_FUNCTION_PERFORM)); + if (!perform) { + ALOGE("Failed to get gralloc perform helper!"); + std::terminate(); + } + + ALOGD("Opened gralloc1 HAL"); +} + +Return> IQtiMapperExtensions::castFrom( + android::sp const& parent, bool emitError) { + if (MapperExtensions11CastFrom) return MapperExtensions11CastFrom(parent, emitError); + return new IQtiMapperExtensions(); +} + +Return IQtiMapperExtensions::getRgbDataAddress(void* buffer, getRgbDataAddress_cb _hidl_cb) { + void* rgb_data = nullptr; + + auto err = perform(gralloc, GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS, buffer, &rgb_data) + ? Error::BAD_BUFFER + : Error::NONE; + _hidl_cb(err, rgb_data); + + ALOGV("%s: err: %d rgb_data: %p", __func__, err, rgb_data); + return Void(); +} + +Return IQtiMapperExtensions::getInterlacedFlag(void* buffer, getInterlacedFlag_cb _hidl_cb) { + int flag = 0; + auto perform = reinterpret_cast( + gralloc->getFunction(gralloc, GRALLOC1_FUNCTION_PERFORM)); + auto err = perform(gralloc, GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG, buffer, &flag) + ? Error::BAD_BUFFER + : Error::NONE; + _hidl_cb(err, flag); + ALOGV("%s: err: %d flag: %d", __func__, err, flag); + return Void(); +} +Return IQtiMapperExtensions::getFd(void* buffer, getFd_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int fd = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + fd = hnd->fd; + } + hidl_cb(err, fd); + ALOGV("%s: fd: %d", __func__, fd); + return Void(); +} + +Return IQtiMapperExtensions::getWidth(void* buffer, getWidth_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int width = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + width = hnd->width; + } + hidl_cb(err, width); + ALOGV("%s: width: %d", __func__, width); + return Void(); +} + +Return IQtiMapperExtensions::getHeight(void* buffer, getHeight_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int height = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + height = hnd->height; + } + hidl_cb(err, height); + ALOGV("%s: height: %d", __func__, height); + return Void(); +} + +Return IQtiMapperExtensions::getFormat(void* buffer, getFormat_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int format = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + format = hnd->format; + } + hidl_cb(err, format); + + ALOGV("%s: format: %d", __func__, format); + return Void(); +} + +Return IQtiMapperExtensions::getPrivateFlags(void* buffer, getPrivateFlags_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int flags = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + flags = hnd->flags; + } + hidl_cb(err, flags); + ALOGV("%s: flags: %d", __func__, flags); + return Void(); +} + +Return IQtiMapperExtensions::getUnalignedWidth(void* buffer, getUnalignedWidth_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int unaligned_width = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + unaligned_width = hnd->unaligned_width; + } + hidl_cb(err, unaligned_width); + + ALOGV("%s: unaligned_width: %u", __func__, unaligned_width); + return Void(); +} + +Return IQtiMapperExtensions::getUnalignedHeight(void* buffer, getUnalignedHeight_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + int unaligned_height = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + unaligned_height = hnd->unaligned_height; + } + hidl_cb(err, unaligned_height); + ALOGV("%s: unaligned_height: %u", __func__, unaligned_height); + return Void(); +} + +Return IQtiMapperExtensions::getLayerCount(void* buffer, getLayerCount_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + unsigned int layer_count = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + layer_count = hnd->layer_count; + } + hidl_cb(err, layer_count); + ALOGV("%s: layer_count: %u", __func__, layer_count); + return Void(); +} + +Return IQtiMapperExtensions::getId(void* buffer, getId_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + uint64_t id = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + id = hnd->id; + } + hidl_cb(err, id); + ALOGV("%s: id: %" PRIu64, __func__, id); + return Void(); +} + +Return IQtiMapperExtensions::getUsageFlags(void* buffer, getUsageFlags_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + uint64_t usage = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + usage = hnd->usage; + } + hidl_cb(err, usage); + ALOGV("%s: usage: %" PRIu64, __func__, usage); + + return Void(); +} + +Return IQtiMapperExtensions::getSize(void* buffer, getSize_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + unsigned int size = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + size = hnd->size; + } + hidl_cb(err, size); + ALOGV("%s: size: %u", __func__, size); + return Void(); +} + +Return IQtiMapperExtensions::getOffset(void* buffer, getOffset_cb hidl_cb) { + auto err = Error::BAD_BUFFER; + unsigned int offset = 0; + auto hnd = static_cast(buffer); + if (buffer != nullptr && private_handle_t::validate(hnd) == 0) { + err = Error::NONE; + offset = hnd->offset; + } + hidl_cb(err, offset); + ALOGV("%s: offset: %u", __func__, offset); + return Void(); +} + +Return IQtiMapperExtensions::getFormatLayout(int32_t format, uint64_t usage, int32_t flags, + int32_t width, int32_t height, + getFormatLayout_cb _hidl_cb) { + hidl_vec plane_info; + unsigned int alignedw = 0, alignedh = 0, tile_enabled = 0; + int plane_count = 0; + uint64_t size = 0; + int custom_format = gralloc::GetImplDefinedFormat(usage, format); + gralloc::BufferInfo info(width, height, custom_format, usage); + + auto err = perform(gralloc, GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES, width, height, custom_format, + usage, usage, &alignedw, &alignedh, &tile_enabled) + ? Error::BAD_BUFFER + : Error::NONE; + if (err != Error::NONE) { + _hidl_cb(err, 0, plane_info); + return Void(); + } + + size = gralloc::GetSize(info, alignedw, alignedh); + gralloc::PlaneLayoutInfo plane_layout[8] = {}; + + if (gralloc::IsUncompressedRGBFormat(custom_format) || + gralloc::IsCompressedRGBFormat(custom_format)) { + gralloc::GetRGBPlaneInfo(info, custom_format, alignedw, alignedh, flags, &plane_count, + plane_layout); + } else { + ALOGE("%s: unsupported format %d", __func__, format); + err = Error::BAD_BUFFER; + _hidl_cb(err, size, plane_info); + return Void(); + } + + plane_info.resize(plane_count); + for (int i = 0; i < plane_count; i++) { + plane_info[i].component = plane_layout[i].component; + plane_info[i].h_subsampling = plane_layout[i].h_subsampling; + plane_info[i].v_subsampling = plane_layout[i].v_subsampling; + plane_info[i].offset = plane_layout[i].offset; + plane_info[i].pixel_increment = plane_layout[i].step; + plane_info[i].stride = plane_layout[i].stride; + plane_info[i].stride_bytes = plane_layout[i].stride_bytes; + plane_info[i].scanlines = plane_layout[i].scanlines; + plane_info[i].size = plane_layout[i].size; + } + + _hidl_cb(err, size, plane_info); + return Void(); +} + +} // namespace V1_1 +} // namespace mapperextensions +} // namespace vendor::qti::hardware::display diff --git a/app/src/main/cpp/fakeinput.cpp b/app/src/main/cpp/fakeinput.cpp new file mode 100644 index 0000000000..439903bef1 --- /dev/null +++ b/app/src/main/cpp/fakeinput.cpp @@ -0,0 +1,1701 @@ +/* + * The fake evdev layer. Taken from WinNative (maxjivi05, main 0cfc070b + feature/wayland-gamescope + * through f1f34cd7, 2026-09-14..19), GPL-3.0: the locking, the fork handlers, the shared device + * table, the Steam virtual-gamepad identity and the Z/RZ trigger placement are that author's. + * Added here: an opt-in Xbox 360 identity (FAKE_EVDEV_IDENTITY=xbox360), which is what gets SDL's + * built-in mapping applied with no configuration when the pad is read by the Steam client itself. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define EXPORT __attribute__((visibility("default"))) extern "C" + +// glibc declares the request as unsigned long; bionic as int. The same source also serves the +// Linux runtime's preload (tools/linuxfs), where Steam and SDL run against glibc. +#ifdef __GLIBC__ +typedef unsigned long ioctl_request_t; +#else +typedef int ioctl_request_t; +#endif + +static constexpr uint16_t GAMEPAD_VENDOR_ID_BASE = 0x1234; +static constexpr uint16_t GAMEPAD_PRODUCT_ID_BASE = 0x5678; +static constexpr uint16_t GAMEPAD_VERSION = 0x0110; +static constexpr const char *GAMEPAD_NAME_TEMPLATE = "Generic HID Gamepad %d"; +// The gamepad Steam Input presents to a game, and the name SDL reads its slot from. +static constexpr uint16_t STEAM_VIRTUAL_VENDOR_ID = 0x28de; +static constexpr uint16_t STEAM_VIRTUAL_PRODUCT_ID = 0x11ff; +static constexpr const char *STEAM_VIRTUAL_NAME_TEMPLATE = "Microsoft X-Box 360 pad %d"; +// Opt-in identity for the process that reads the pad directly (the Steam client): SDL keys its +// mapping database on bus+vendor+product, and 045E:028E is the most widely mapped id there is. +// Not offset per slot: a real pad reports the same ids on every port. +static constexpr uint16_t X360_VENDOR_ID = 0x045E; +static constexpr uint16_t X360_PRODUCT_ID = 0x028E; +static constexpr const char *X360_NAME_TEMPLATE = "Xbox 360 Controller (%d)"; +static constexpr const char *GAMEPAD_PHYS_TEMPLATE = "usb-fakeinput/input%d"; +static constexpr const char *GAMEPAD_UNIQ_TEMPLATE = "0000000000%02d"; +static constexpr uint8_t GAMEPAD_AXIS_COUNT = 8; +static constexpr uint8_t GAMEPAD_BUTTON_COUNT = 11; +static constexpr uint32_t FAKE_INPUT_RING_MAGIC = 0x46494252; +static constexpr uint32_t FAKE_INPUT_RING_VERSION = 2; +static constexpr uint32_t FAKE_INPUT_EVENT_SIZE = sizeof(struct input_event); +static constexpr uint32_t FAKE_INPUT_RING_CAPACITY = 4096; +static constexpr unsigned int FAKE_INPUT_MAJOR = 13; +static constexpr unsigned int FAKE_INPUT_EVENT_MINOR_BASE = 64; +static constexpr unsigned int FAKE_INPUT_JS_MINOR_BASE = 0; + +struct FakeInputRingHeader { + uint32_t magic; // 0 + uint32_t version; // 4 + uint32_t event_size; // 8 + uint32_t capacity; // 12 + uint64_t write_seq; // 16 + uint64_t generation; // 24 + // Authoritative absolute-state snapshot, published by the writer under a + // seqlock (odd snapshot_seq = write in progress). The reader replays it as a + // full keyframe whenever the delta stream could have desynced (open, ring + // overflow) so dropped events can recover without periodic duplicate input. + uint64_t snapshot_seq; // 32 + uint32_t snapshot_buttons; // 40 bit i -> kSnapshotButtons[i] pressed + int16_t snapshot_axes[8]; // 44 values in kSnapshotAxisCodes order + uint32_t resync_seq; // 60 +}; + +static_assert(sizeof(FakeInputRingHeader) == 64, + "fake input ring header must stay ABI-stable"); + +static constexpr size_t FAKE_INPUT_RING_HEADER_SIZE = + sizeof(FakeInputRingHeader); +static constexpr size_t FAKE_INPUT_RING_SIZE = + FAKE_INPUT_RING_HEADER_SIZE + + (FAKE_INPUT_RING_CAPACITY * FAKE_INPUT_EVENT_SIZE); + +struct FakeController { + char *event = nullptr; + int slot = -1; + FakeInputRingHeader *ring = nullptr; + uint64_t read_seq = 0; + uint64_t generation = 0; + uint32_t resync_seq = 0; + size_t mapping_size = 0; + bool closed = false; + bool needs_keyframe = true; + + ~FakeController() { + if (ring) munmap(ring, mapping_size); + free(event); + } + // Pending keyframe (full absolute-state baseline) currently streaming to the + // guest. The axis/button values are captured from the snapshot when the + // keyframe starts so the frame stays consistent across multi-read delivery. + size_t keyframe_remaining = 0; + int32_t keyframe_axes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + uint32_t keyframe_buttons = 0; +}; + +struct NeutralEventSpec { + uint16_t type; + uint16_t code; +}; + +// Event template for a full keyframe: every button, every axis/hat, then a +// SYN_REPORT, in this fixed order. The value carried by each event is filled +// from the authoritative snapshot (see keyframe_value); an all-zero snapshot +// yields the neutral baseline. Replayed on open and ring overflow so dropped +// events cannot leave a guest stuck. +static const NeutralEventSpec kNeutralEvents[] = { + {EV_KEY, BTN_A}, {EV_KEY, BTN_B}, {EV_KEY, BTN_X}, + {EV_KEY, BTN_Y}, {EV_KEY, BTN_TL}, {EV_KEY, BTN_TR}, + {EV_KEY, BTN_SELECT}, {EV_KEY, BTN_START}, {EV_KEY, BTN_MODE}, + {EV_KEY, BTN_THUMBL}, {EV_KEY, BTN_THUMBR}, {EV_ABS, ABS_X}, + {EV_ABS, ABS_Y}, {EV_ABS, ABS_RX}, {EV_ABS, ABS_RY}, + {EV_ABS, ABS_GAS}, {EV_ABS, ABS_BRAKE}, {EV_ABS, ABS_HAT0X}, + {EV_ABS, ABS_HAT0Y}, {EV_SYN, SYN_REPORT}, +}; +static constexpr size_t kNeutralEventCount = + sizeof(kNeutralEvents) / sizeof(kNeutralEvents[0]); + +// Axis layout of FakeInputRingHeader::snapshot_axes (mirrors the Java writer). +static const uint16_t kSnapshotAxisCodes[8] = { + ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y}; +// Bit i of FakeInputRingHeader::snapshot_buttons maps to this button code. +static const uint16_t kSnapshotButtons[11] = { + BTN_A, BTN_B, BTN_X, BTN_Y, BTN_TL, BTN_TR, + BTN_SELECT, BTN_START, BTN_THUMBL, BTN_THUMBR, + // Bit 10 is the Steam button: the client's in-game menu is bound to it, and SDL reports it + // as button 8 from this position in the key bits. + BTN_MODE}; +static constexpr size_t kSnapshotButtonCount = + sizeof(kSnapshotButtons) / sizeof(kSnapshotButtons[0]); + +// An LD_PRELOAD interposer is called outside its own lifetime. The loader initialises libraries +// in dependency order, and the hooks below belong to whichever library gets there first: on the +// Linux runtime, libpython's initialiser runs before ours and calls close() and read(), so a hook +// fires before this library has been initialised at all. A file-scope std::unordered_map or +// std::recursive_mutex has no object yet at that moment - touching one is undefined behaviour, +// and in practice the process dies before main(). The same window reopens at exit, after static +// destructors have run. (Proton is a Python script, so this killed every game launched from the +// native Steam client, and the compatibility-tool registrar with it.) +// +// So everything with a constructor lives behind an accessor that builds it on first use and +// never destroys it. The leak is deliberate and bounded: one map or mutex for the process. +namespace Logger { +void init(); +} + +static void controller_fork_prepare(); +static void controller_fork_parent(); +static void controller_fork_child(); + +struct FakeConfig { + const char *hook_dir; + const char *udev_data_dir; + bool vibration_enabled; + bool xbox360_identity; +}; + +static FakeConfig &config() { + static FakeConfig *cfg = [] { + auto *c = new FakeConfig(); + const char *dir = getenv("FAKE_EVDEV_DIR"); + c->hook_dir = dir ? dir : "/data/data/com.termux/files/home/fake-input"; + c->udev_data_dir = getenv("FAKE_UDEV_DATA_DIR"); + c->vibration_enabled = + getenv("FAKE_EVDEV_VIBRATION") && atoi(getenv("FAKE_EVDEV_VIBRATION")); + const char *identity = getenv("FAKE_EVDEV_IDENTITY"); + c->xbox360_identity = identity && !strcmp(identity, "xbox360"); + pthread_atfork(controller_fork_prepare, controller_fork_parent, + controller_fork_child); + Logger::init(); + return c; + }(); + return *cfg; +} + +static std::recursive_mutex &controller_mutex() { + static auto *mutex = new std::recursive_mutex(); + return *mutex; +} + +static std::unordered_map> &controller_map() { + static auto *map = new std::unordered_map>(); + return *map; +} + +static std::unordered_map &ring_paths() { + static auto *map = new std::unordered_map(); + return *map; +} + +static std::unordered_map &ff_effects() { + static auto *map = new std::unordered_map(); + return *map; +} + +static const char *fake_hook_dir() { return config().hook_dir; } +static const char *fake_udev_data_dir() { return config().udev_data_dir; } +static bool fake_vibration_enabled() { return config().vibration_enabled; } +static bool fake_xbox360_identity() { return config().xbox360_identity; } + +static bool ring_paths_loaded = false; +static int next_ff_id = 0; + +// fork() carries over only the calling thread, so a lock another thread was holding at that +// instant stays held in the child by a thread that is not there to release it. Every hook below +// takes controller_mutex, and the Steam client forks while its other threads are inside them, so +// the child blocked on its first open() and never reached exec: the spawn never completed, the +// client's main loop stalled past its own watchdog and it tore the session down. +// +// Taking the lock before the fork is what makes the copy consistent - no thread is part way +// through the tables it guards. The parent then unlocks it. The child cannot: a recursive mutex +// records the owning thread, the child's one thread has a new id, and unlocking one it does not +// own is refused, which would leave the lock held for good. It gets a fresh mutex instead, which +// is sound precisely because the fork was taken with the lock held. +static void controller_fork_prepare() { controller_mutex().lock(); } +static void controller_fork_parent() { controller_mutex().unlock(); } + +static void controller_fork_child() { + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(controller_mutex().native_handle(), &attr); + pthread_mutexattr_destroy(&attr); +} + +namespace Logger { +int log_enabled; + +void init() { + log_enabled = getenv("FAKE_EVDEV_LOG") && atoi(getenv("FAKE_EVDEV_LOG")); +} + +void log(const char *message, ...) { + if (!log_enabled) + return; + + va_list args; + va_start(args, message); + vfprintf(stderr, message, args); + va_end(args); + + std::cerr.flush(); +} +} // namespace Logger + +__attribute__((constructor)) static void library_init() { + // Warming the lazily built state, not owning it: when the loader runs this before anything + // calls a hook - the ordinary case - the first hook finds everything already there. Nothing + // below depends on it having run, which is the whole point. + config(); + controller_mutex(); + controller_map(); +} + +__attribute__((visibility("hidden"))) static void +send_vibration(int strong, int weak, uint16_t duration_ms, uint16_t slot) { + if (!fake_vibration_enabled()) + return; + + // Rumble is best effort. A full Android listener backlog must never park + // winebus (or every input hook through controller_mutex()), and a closing + // listener must not terminate the guest with SIGPIPE. + int sock = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); + if (sock < 0) + return; + + struct sockaddr_un addr = {}; + addr.sun_family = AF_UNIX; + const char *name = "winlator_vibration"; + memcpy(addr.sun_path + 1, name, strlen(name)); + socklen_t addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(name); + + if (connect(sock, reinterpret_cast(&addr), addrlen) < 0) { + syscall(SYS_close, sock); + return; + } + + uint16_t data[4]; + data[0] = static_cast(strong); + data[1] = static_cast(weak); + data[2] = duration_ms; + data[3] = slot; + send(sock, data, sizeof(data), MSG_DONTWAIT | MSG_NOSIGNAL); + syscall(SYS_close, sock); +} + +__attribute__((visibility("hidden"))) static void +check_ff_event(const struct input_event *ev, uint16_t slot) { + if (ev->type != EV_FF) + return; + + int id = ev->code; + if (ev->value > 0) { + auto it = ff_effects().find(id); + if (it == ff_effects().end()) + return; + + uint16_t duration = it->second.replay.length; + if (it->second.type == FF_RUMBLE) { + send_vibration(it->second.u.rumble.strong_magnitude, + it->second.u.rumble.weak_magnitude, duration, slot); + } else if (it->second.type == FF_PERIODIC) { + send_vibration(it->second.u.periodic.magnitude, + it->second.u.periodic.magnitude, duration, slot); + } + } else { + send_vibration(0, 0, 0, slot); + } +} + +__attribute__((visibility("hidden"))) char * +from_real_to_fake_path(const char *pathname) { + const char *event = strrchr(pathname, '/') + 1; + char *fake_path = nullptr; + if (asprintf(&fake_path, "%s/%s", fake_hook_dir(), event) < 0) + fake_path = nullptr; + return fake_path; +} + +__attribute__((visibility("hidden"))) static bool path_exists(const char *path) { + return path && faccessat(AT_FDCWD, path, F_OK, 0) == 0; +} + +__attribute__((visibility("hidden"))) static bool +is_fake_input_node_path(const char *pathname) { + return pathname && (!strncmp(pathname, "/dev/input/event", 16) || + !strncmp(pathname, "/dev/input/js", 13)); +} + +__attribute__((visibility("hidden"))) static bool +is_fake_udev_data_path(const char *pathname) { + return pathname && fake_udev_data_dir() && *fake_udev_data_dir() && + !strncmp(pathname, "/run/udev/data/c13:", 19); +} + +__attribute__((visibility("hidden"))) char * +from_real_to_fake_udev_data_path(const char *pathname) { + const char *name = strrchr(pathname, '/') + 1; + char *fake_path = nullptr; + if (asprintf(&fake_path, "%s/%s", fake_udev_data_dir(), name) < 0) + fake_path = nullptr; + return fake_path; +} + +__attribute__((visibility("hidden"))) const char * +get_event(const char *pathname) { + const char *event = strrchr(pathname, '/') + 1; + return event; +} + +__attribute__((visibility("hidden"))) int get_event_number(const char *event) { + if (!event) + return -1; + + const char *digits = event; + while (*digits && (*digits < '0' || *digits > '9')) + digits++; + + return *digits ? atoi(digits) : -1; +} + +__attribute__((visibility("hidden"))) static dev_t +get_fake_input_rdev(const char *event) { + int event_number = get_event_number(event); + if (event_number < 0) + return makedev(FAKE_INPUT_MAJOR, 0); + + if (!strncmp(event, "event", 5)) + return makedev(FAKE_INPUT_MAJOR, FAKE_INPUT_EVENT_MINOR_BASE + event_number); + if (!strncmp(event, "js", 2)) + return makedev(FAKE_INPUT_MAJOR, FAKE_INPUT_JS_MINOR_BASE + event_number); + + return makedev(FAKE_INPUT_MAJOR, event_number); +} + +__attribute__((visibility("hidden"))) static void load_ring_paths() { + std::lock_guard guard(controller_mutex()); + if (ring_paths_loaded) + return; + + const char *spec = getenv("FAKE_EVDEV_MEMFD_PATHS"); + if (!spec || !*spec) { + ring_paths_loaded = true; + return; + } + + char *copy = strdup(spec); + if (!copy) + return; + + char *saveptr = nullptr; + for (char *token = strtok_r(copy, ";", &saveptr); token; + token = strtok_r(nullptr, ";", &saveptr)) { + char *equals = strchr(token, '='); + if (!equals) + continue; + *equals = '\0'; + int slot = atoi(token); + const char *path = equals + 1; + if (slot >= 0 && *path) + ring_paths()[slot] = path; + } + + free(copy); + ring_paths_loaded = true; +} + +__attribute__((visibility("hidden"))) static std::string +get_ring_path_for_slot(int slot) { + std::lock_guard guard(controller_mutex()); + load_ring_paths(); + auto it = ring_paths().find(slot); + return it == ring_paths().end() ? std::string() : it->second; +} + +__attribute__((visibility("hidden"))) static uint64_t +ring_write_seq(const FakeInputRingHeader *ring) { + return __atomic_load_n(&ring->write_seq, __ATOMIC_ACQUIRE); +} + +__attribute__((visibility("hidden"))) static uint64_t +ring_generation(const FakeInputRingHeader *ring) { + return __atomic_load_n(&ring->generation, __ATOMIC_ACQUIRE); +} + +__attribute__((visibility("hidden"))) static uint32_t +ring_resync_seq(const FakeInputRingHeader *ring) { + return __atomic_load_n(&ring->resync_seq, __ATOMIC_ACQUIRE); +} + +__attribute__((visibility("hidden"))) static bool +ring_header_is_valid(const FakeInputRingHeader *ring) { + return ring && ring->magic == FAKE_INPUT_RING_MAGIC && + ring->version == FAKE_INPUT_RING_VERSION && + ring->event_size == FAKE_INPUT_EVENT_SIZE && + ring->capacity == FAKE_INPUT_RING_CAPACITY; +} + +struct SnapshotState { + uint64_t sequence = 0; + uint64_t write_seq = 0; + uint64_t generation = 0; + uint32_t resync_seq = 0; + uint32_t buttons = 0; + int32_t axes[8] = {}; +}; + +static long long monotonic_ms(); + +// The writer protects the events, cursor and snapshot in one publication. +// A busy writer is retried later; inventing a neutral state would lose holds. +__attribute__((visibility("hidden"))) static bool +read_snapshot(const FakeInputRingHeader *ring, SnapshotState &out) { + for (int attempt = 0; attempt < 8; attempt++) { + uint64_t sequence = __atomic_load_n(&ring->snapshot_seq, __ATOMIC_ACQUIRE); + if (sequence & 1ULL) continue; + out.sequence = sequence; + out.write_seq = ring_write_seq(ring); + out.generation = ring_generation(ring); + out.resync_seq = ring_resync_seq(ring); + out.buttons = __atomic_load_n(&ring->snapshot_buttons, __ATOMIC_RELAXED); + for (int i = 0; i < 8; i++) + out.axes[i] = __atomic_load_n(&ring->snapshot_axes[i], __ATOMIC_RELAXED); + __atomic_thread_fence(__ATOMIC_ACQUIRE); + if (sequence == __atomic_load_n(&ring->snapshot_seq, __ATOMIC_RELAXED)) + return true; + } + return false; +} + +// This baseline supersedes all deltas through its cursor. Replaying older +// deltas after it can reassert a control that the snapshot already released. +__attribute__((visibility("hidden"))) static void +capture_keyframe(FakeController &fake, const SnapshotState &snap) { + fake.keyframe_buttons = snap.buttons; + for (int i = 0; i < 8; i++) fake.keyframe_axes[i] = snap.axes[i]; + fake.keyframe_remaining = kNeutralEventCount; + fake.read_seq = snap.write_seq; + fake.resync_seq = snap.resync_seq; + fake.needs_keyframe = false; +} + +// Resolve the value a keyframe event should carry from the captured snapshot. +__attribute__((visibility("hidden"))) static int32_t +keyframe_value(const FakeController &fake, uint16_t type, uint16_t code) { + if (type == EV_KEY) { + for (size_t i = 0; i < kSnapshotButtonCount; i++) + if (kSnapshotButtons[i] == code) + return (fake.keyframe_buttons >> i) & 1u; + return 0; // a code the snapshot word does not carry + } + if (type == EV_ABS) { + for (int i = 0; i < 8; i++) + if (kSnapshotAxisCodes[i] == code) + return fake.keyframe_axes[i]; + } + return 0; // SYN / unknown +} + +__attribute__((visibility("hidden"))) static int +open_fake_input_ring(const char *event, int flags) { + int slot = get_event_number(event); + std::string ring_path = get_ring_path_for_slot(slot); + if (ring_path.empty()) { + Logger::log("No input ring is configured for %s (slot %d)\n", event, slot); + errno = ENODEV; + return -1; + } + + static auto my_open = reinterpret_cast(dlsym(RTLD_NEXT, "open")); + + int fd = my_open(ring_path.c_str(), O_RDWR | (flags & (O_NONBLOCK | O_CLOEXEC))); + if (fd < 0) + return -1; + + void *mapping = + mmap(nullptr, FAKE_INPUT_RING_SIZE, PROT_READ, MAP_SHARED, fd, 0); + if (mapping == MAP_FAILED) { + int saved_errno = errno; + syscall(SYS_close, fd); + errno = saved_errno; + return -1; + } + + FakeInputRingHeader *ring = + reinterpret_cast(mapping); + if (!ring_header_is_valid(ring)) { + Logger::log("Input ring %s has no valid header\n", ring_path.c_str()); + munmap(mapping, FAKE_INPUT_RING_SIZE); + syscall(SYS_close, fd); + errno = ENODEV; + return -1; + } + + auto controller = std::make_shared(); + controller->event = strdup(event); + controller->slot = slot; + controller->ring = ring; + controller->mapping_size = FAKE_INPUT_RING_SIZE; + controller->generation = ring_generation(ring); + // Establish the cursor at open so taps arriving before the first read stay + // queued. If publication is busy, read() will finish establishing it later. + SnapshotState snap; + if (read_snapshot(ring, snap) && snap.generation == controller->generation) + capture_keyframe(*controller, snap); + { + std::lock_guard guard(controller_mutex()); + controller_map()[fd] = controller; + } + + Logger::log("Adding ring-backed controller, fd %d event %s slot %d\n", fd, + event, slot); + return fd; +} + +// Under the Steam client a pad it manages is hidden from the game: the client lists it in +// SDL_GAMECONTROLLER_IGNORE_DEVICES, its overlay refuses the game's open() of the node, and the +// game is meant to see Steam Input's virtual gamepad instead. That one is a uinput device, which +// does not exist here, so the game was left with no controller at all. With +// FAKE_EVDEV_STEAM_VIRTUAL set the pad carries the virtual gamepad's identity for every process +// but the client's own, which must keep seeing the pad as the physical one it reads. +__attribute__((visibility("hidden"))) static bool presents_steam_virtual() { + static int known; + if (known == 0) { + const char *enabled = getenv("FAKE_EVDEV_STEAM_VIRTUAL"); + char exe[PATH_MAX]; + ssize_t length = enabled && atoi(enabled) ? readlink("/proc/self/exe", exe, sizeof(exe) - 1) : -1; + bool client = false; + if (length > 0) { + exe[length] = '\0'; + const char *name = strrchr(exe, '/'); + client = !strncmp(name ? name + 1 : exe, "steam", 5); + } + known = length > 0 && !client ? 1 : -1; + } + return known == 1; +} + +// The virtual gamepad is an X-Box 360 pad, whose triggers are ABS_Z and ABS_RZ. Wine places a +// gamepad's axes by their position among the ones it advertises, so the triggers have to sit +// where that pad has them: as ABS_GAS and ABS_BRAKE they follow the sticks, the right stick +// lands on the left trigger, and a released right trigger reads as the right stick held up. +__attribute__((visibility("hidden"))) static uint16_t presented_abs_code(uint16_t code) { + if (!presents_steam_virtual()) return code; + if (code == ABS_BRAKE) return ABS_Z; + if (code == ABS_GAS) return ABS_RZ; + return code; +} + +__attribute__((visibility("hidden"))) static uint16_t ring_abs_code(uint16_t code) { + if (!presents_steam_virtual()) return code; + if (code == ABS_Z) return ABS_BRAKE; + if (code == ABS_RZ) return ABS_GAS; + return code; +} + +__attribute__((visibility("hidden"))) static void +copy_slot_ioctl_string(int op, void *argp, const char *format, int event_number) { + size_t size = _IOC_SIZE(op); + if (!argp || size == 0) + return; + + snprintf(static_cast(argp), size, format, event_number); +} + +__attribute__((visibility("hidden"))) static bool is_fake_input_fd(int fd) { + std::lock_guard guard(controller_mutex()); + return controller_map().find(fd) != controller_map().end(); +} + +__attribute__((visibility("hidden"))) static bool fake_fd_is_stale(int fd) { + std::lock_guard guard(controller_mutex()); + auto controller = controller_map().find(fd); + return controller != controller_map().end() && + ring_generation(controller->second->ring) != controller->second->generation; +} + +// Caller holds controller_mutex(). +static bool fake_has_unread_data(const FakeController &fake) { + if (ring_generation(fake.ring) != fake.generation) + return false; + // Readiness never consumes resync requests or changes the read cursor. + // Do not spin a nonblocking guest on a producer's unfinished publication. + if (fake.keyframe_remaining > 0) return true; + uint64_t sequence = __atomic_load_n(&fake.ring->snapshot_seq, __ATOMIC_ACQUIRE); + if (sequence & 1ULL) return false; + bool ready = fake.needs_keyframe || + ring_resync_seq(fake.ring) != fake.resync_seq || + ring_write_seq(fake.ring) != fake.read_seq; + __atomic_thread_fence(__ATOMIC_ACQUIRE); + return ready && sequence == __atomic_load_n(&fake.ring->snapshot_seq, __ATOMIC_RELAXED); +} + +static bool fake_fd_has_unread_data(int fd) { + std::lock_guard guard(controller_mutex()); + auto it = controller_map().find(fd); + return it != controller_map().end() && fake_has_unread_data(*it->second); +} + +static short fake_poll_revents(const std::shared_ptr &fake, short events) { + std::lock_guard guard(controller_mutex()); + if (fake->closed) return POLLNVAL; + if (ring_generation(fake->ring) != fake->generation) return POLLHUP; + short ready = events & (POLLOUT | POLLWRNORM); + if ((events & (POLLIN | POLLRDNORM)) && fake_has_unread_data(*fake)) + ready |= events & (POLLIN | POLLRDNORM); + return ready; +} + +__attribute__((visibility("hidden"))) static long long +timespec_to_ms(const struct timespec *timeout) { + if (!timeout) + return -1; + return static_cast(timeout->tv_sec) * 1000LL + + timeout->tv_nsec / 1000000LL; +} + +__attribute__((visibility("hidden"))) static long long +timeval_to_ms(const struct timeval *timeout) { + if (!timeout) + return -1; + return static_cast(timeout->tv_sec) * 1000LL + + timeout->tv_usec / 1000LL; +} + +__attribute__((visibility("hidden"))) static long long monotonic_ms() { + struct timespec now = {}; + clock_gettime(CLOCK_MONOTONIC, &now); + return static_cast(now.tv_sec) * 1000LL + now.tv_nsec / 1000000LL; +} + +EXPORT int open(const char *pathname, int flags, ...) { + va_list va; + mode_t mode; + int fd; + bool hasMode; + + va_start(va, flags); + + hasMode = flags & O_CREAT; + + if (hasMode) { + mode = va_arg(va, mode_t); + } + + va_end(va); + + static auto my_open = reinterpret_cast(dlsym(RTLD_NEXT, "open")); + + char *fake_path = nullptr; + const char *event = nullptr; + if (pathname) { + if (is_fake_input_node_path(pathname)) { + event = get_event(pathname); + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + if (path_exists(fake_path)) { + fd = open_fake_input_ring(event, flags); + if (fd >= 0) { + free(fake_path); + return fd; + } + int saved_errno = errno; + free(fake_path); + errno = saved_errno; + return -1; + } + pathname = fake_path; + } else if (is_fake_udev_data_path(pathname)) { + fake_path = from_real_to_fake_udev_data_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + if (hasMode) + fd = my_open(pathname, flags, mode); + else + fd = my_open(pathname, flags); + + if (fake_path) + free(fake_path); + + return fd; +} + +EXPORT int openat(int dirfd, const char *pathname, int flags, ...) { + va_list va; + mode_t mode; + int fd; + bool hasMode; + + va_start(va, flags); + + hasMode = flags & O_CREAT; + + if (hasMode) { + mode = va_arg(va, mode_t); + } + + va_end(va); + + static auto my_openat = reinterpret_cast(dlsym(RTLD_NEXT, "openat")); + + char *fake_path = nullptr; + const char *event = nullptr; + if (pathname) { + if (is_fake_input_node_path(pathname)) { + event = get_event(pathname); + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + if (path_exists(fake_path)) { + fd = open_fake_input_ring(event, flags); + if (fd >= 0) { + free(fake_path); + return fd; + } + int saved_errno = errno; + free(fake_path); + errno = saved_errno; + return -1; + } + pathname = fake_path; + } else if (is_fake_udev_data_path(pathname)) { + fake_path = from_real_to_fake_udev_data_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + if (hasMode) + fd = my_openat(dirfd, pathname, flags, mode); + else + fd = my_openat(dirfd, pathname, flags); + + if (fake_path) + free(fake_path); + + return fd; +} + +EXPORT int stat(const char *pathname, struct stat *statbuf) { + static auto my_stat = reinterpret_cast(dlsym(RTLD_NEXT, "stat")); + + const char *event = nullptr; + char *fake_path = nullptr; + + if (pathname) { + if (is_fake_input_node_path(pathname)) { + event = get_event(pathname); + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (is_fake_udev_data_path(pathname)) { + fake_path = from_real_to_fake_udev_data_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + int ret = my_stat(pathname, statbuf); + + if (ret == 0 && event && get_event_number(event) >= 0) { + statbuf->st_mode = (statbuf->st_mode & ~S_IFMT) | S_IFCHR; + statbuf->st_rdev = get_fake_input_rdev(event); + } + + if (fake_path) + free(fake_path); + + return ret; +} + +EXPORT int fstat(int fd, struct stat *buf) { + static auto my_fstat = reinterpret_cast(dlsym(RTLD_NEXT, "fstat")); + + int ret = my_fstat(fd, buf); + + std::lock_guard guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (ret == 0 && controller != controller_map().end()) { + buf->st_mode = (buf->st_mode & ~S_IFMT) | S_IFCHR; + buf->st_rdev = get_fake_input_rdev(controller->second->event); + } + + return ret; +} + +EXPORT int access(const char *pathname, int mode) { + static auto my_access = reinterpret_cast(dlsym(RTLD_NEXT, "access")); + + char *fake_path = nullptr; + if (pathname) { + if (is_fake_input_node_path(pathname)) { + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (is_fake_udev_data_path(pathname)) { + fake_path = from_real_to_fake_udev_data_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + int ret = my_access(pathname, mode); + if (fake_path) + free(fake_path); + return ret; +} + +EXPORT int faccessat(int dirfd, const char *pathname, int mode, int flags) { + static auto my_faccessat = reinterpret_cast(dlsym(RTLD_NEXT, "faccessat")); + + char *fake_path = nullptr; + if (pathname) { + if (is_fake_input_node_path(pathname)) { + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (is_fake_udev_data_path(pathname)) { + fake_path = from_real_to_fake_udev_data_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + int ret = my_faccessat(dirfd, pathname, mode, flags); + if (fake_path) + free(fake_path); + return ret; +} + +EXPORT int scandir(const char *dirp, struct dirent ***namelist, + int (*filter)(const struct dirent *), + int (*compar)(const struct dirent **, + const struct dirent **)) { + static auto my_scandir = reinterpret_cast(dlsym(RTLD_NEXT, "scandir")); + + if (dirp) { + if (!strcmp(dirp, "/dev/input")) { + dirp = fake_hook_dir(); + } else if (fake_udev_data_dir() && !strcmp(dirp, "/run/udev/data")) { + dirp = fake_udev_data_dir(); + } + } + + return my_scandir(dirp, namelist, filter, compar); +} + +EXPORT int inotify_add_watch(int fd, const char *pathname, uint32_t mask) { + static auto my_inotify_add_watch = reinterpret_cast(dlsym(RTLD_NEXT, "inotify_add_watch")); + + char *fake_path = nullptr; + if (pathname) { + if (is_fake_input_node_path(pathname)) { + fake_path = from_real_to_fake_path(pathname); + if (!fake_path) { + errno = ENOMEM; + return -1; + } + pathname = fake_path; + } else if (!strcmp(pathname, "/dev/input")) { + pathname = fake_hook_dir(); + } + } + + int ret = my_inotify_add_watch(fd, pathname, mask); + if (fake_path) + free(fake_path); + return ret; +} + +template +static int copy_ioctl_bits(int op, void *destination, const unsigned char (&bits)[N]) { + size_t size = std::min(_IOC_SIZE(op), N); + if (size) memcpy(destination, bits, size); + return static_cast(size); +} + +static bool wait_snapshot(std::shared_ptr fake, + std::unique_lock &guard, + SnapshotState &snap) { + for (;;) { + if (fake->closed) { + errno = EBADF; + return false; + } + if (ring_generation(fake->ring) != fake->generation) { + errno = ENODEV; + return false; + } + if (read_snapshot(fake->ring, snap)) return true; + // Enumeration queries must not fail merely because Android is publishing + // an input frame. Other hooks (including Binder) can proceed while we wait. + guard.unlock(); + struct timespec wait = {0, 1000000}; + int result = nanosleep(&wait, nullptr); + int saved_errno = errno; + guard.lock(); + if (result < 0) { + errno = saved_errno; + return false; + } + } +} + +EXPORT int ioctl(int fd, ioctl_request_t op, ...) { + va_list va; + void *argp; + + va_start(va, op); + argp = va_arg(va, void *); + va_end(va); + + // The lock must not be held across the passthrough: binder's transport is a + // blocking ioctl(BINDER_WRITE_READ), so a parked binder pool thread would own + // controller_mutex() for as long as it waits and deadlock every other ioctl. + std::unique_lock guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (controller == controller_map().end()) { + guard.unlock(); + return syscall(SYS_ioctl, fd, op, argp); + } + + int type = (op >> 8 & 0xFF); + int number = (op >> 0 & 0xFF); + const char *event = controller->second->event ? controller->second->event : "event0"; + int event_number = controller->second->slot; + + if (type == 0x45 && number == 0x1) { + Logger::log("Hooking ioctl EVIOCGVERSION for event %s\n", event); + int version = 65536; + memcpy(argp, (void *)&version, sizeof(int)); + return 0; + } else if (type == 0x45 && number == 0x2) { + Logger::log("Hooking ioctl EVIOCGID for event %s\n", event); + struct input_id id; + memset(&id, 0, sizeof(id)); + id.bustype = 0x03; + if (presents_steam_virtual()) { + id.vendor = STEAM_VIRTUAL_VENDOR_ID; + id.product = STEAM_VIRTUAL_PRODUCT_ID; + } else if (fake_xbox360_identity()) { + id.vendor = X360_VENDOR_ID; + id.product = X360_PRODUCT_ID; + } else { + id.vendor = static_cast(GAMEPAD_VENDOR_ID_BASE + event_number); + id.product = static_cast(GAMEPAD_PRODUCT_ID_BASE + event_number); + } + id.version = GAMEPAD_VERSION; + memcpy(argp, (void *)&id, sizeof(id)); + return 0; + } else if (type == 0x45 && number == 0x6) { + Logger::log("Hooking ioctl EVIOCGNAME for event %s\n", event); + copy_slot_ioctl_string(op, argp, + presents_steam_virtual() ? STEAM_VIRTUAL_NAME_TEMPLATE + : (fake_xbox360_identity() ? X360_NAME_TEMPLATE : GAMEPAD_NAME_TEMPLATE), + event_number); + return 0; + } else if (type == 0x45 && number == 0x7) { + Logger::log("Hooking ioctl EVIOCGPHYS for event %s\n", event); + copy_slot_ioctl_string(op, argp, GAMEPAD_PHYS_TEMPLATE, event_number); + return 0; + } else if (type == 0x45 && number == 0x8) { + Logger::log("Hooking ioctl EVIOCGUNIQ for event %s\n", event); + copy_slot_ioctl_string(op, argp, GAMEPAD_UNIQ_TEMPLATE, event_number); + return 0; + } else if (type == 0x45 && number == 0x9) { + unsigned char bitmask[(INPUT_PROP_MAX + 8) / 8] = {}; + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x18) { + SnapshotState snap; + if (!wait_snapshot(controller->second, guard, snap)) return -1; + unsigned char bitmask[(KEY_MAX + 8) / 8] = {}; + for (size_t i = 0; i < kSnapshotButtonCount; ++i) { + if (snap.buttons & (1u << i)) + bitmask[kSnapshotButtons[i] / 8] |= 1u << (kSnapshotButtons[i] % 8); + } + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x20) { + Logger::log("Hooking ioctl EVIOCGBIT(0, len) for event %s\n", event); + unsigned char bitmask[(EV_MAX + 8) / 8] = {}; + bitmask[EV_SYN / 8] |= (1 << (EV_SYN % 8)); + bitmask[EV_KEY / 8] |= (1 << (EV_KEY % 8)); + bitmask[EV_ABS / 8] |= (1 << (EV_ABS % 8)); + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x21) { + Logger::log("Hooking ioctl EVIOCGBIT(EV_KEY, len) for event %s\n", event); + unsigned char bitmask[(KEY_MAX + 8) / 8] = {}; + const int xbox_buttons[] = {BTN_A, BTN_B, BTN_X, BTN_Y, + BTN_TL, BTN_TR, BTN_SELECT, BTN_START, + BTN_MODE, BTN_THUMBL, BTN_THUMBR}; + for (int button : xbox_buttons) + bitmask[button / 8] |= (1 << (button % 8)); + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x22) { + Logger::log("Hooking ioctl EVIOCGBIT(EV_REL, len) for event %s\n", event); + unsigned char bitmask[(REL_MAX + 8) / 8] = {}; + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x23) { + Logger::log("Hooking ioctl EVIOCGBIT(EV_ABS, len) for event %s\n", event); + unsigned char bitmask[(ABS_MAX + 8) / 8] = {}; + bitmask[ABS_X / 8] |= (1 << (ABS_X % 8)); + bitmask[ABS_Y / 8] |= (1 << (ABS_Y % 8)); + bitmask[ABS_RX / 8] |= (1 << (ABS_RX % 8)); + bitmask[ABS_RY / 8] |= (1 << (ABS_RY % 8)); + for (uint16_t trigger : {ABS_GAS, ABS_BRAKE}) { + uint16_t code = presented_abs_code(trigger); + bitmask[code / 8] |= (1 << (code % 8)); + } + bitmask[ABS_HAT0X / 8] |= (1 << (ABS_HAT0X % 8)); + bitmask[ABS_HAT0Y / 8] |= (1 << (ABS_HAT0Y % 8)); + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x35) { + Logger::log("Hooking ioctl EVIOCGBIT(EV_FF, len) for event %s\n", event); + unsigned char bitmask[(FF_MAX + 8) / 8] = {}; + bitmask[FF_RUMBLE / 8] |= (1 << (FF_RUMBLE % 8)); + bitmask[FF_PERIODIC / 8] |= (1 << (FF_PERIODIC % 8)); + return copy_ioctl_bits(op, argp, bitmask); + } else if (type == 0x45 && number == 0x80) { + struct ff_effect *effect = static_cast(argp); + if (effect->id == -1) + effect->id = next_ff_id++; + ff_effects()[effect->id] = *effect; + + uint16_t duration = effect->replay.length; + uint16_t slot = static_cast(event_number); + if (effect->type == FF_RUMBLE) { + send_vibration(effect->u.rumble.strong_magnitude, + effect->u.rumble.weak_magnitude, duration, slot); + } else if (effect->type == FF_PERIODIC) { + send_vibration(effect->u.periodic.magnitude, effect->u.periodic.magnitude, + duration, slot); + } + return 0; + } else if (type == 0x45 && number == 0x81) { + int id = (intptr_t)argp; + ff_effects().erase(id); + return 0; + } else if (type == 0x45 && number == 0x84) { + int max_effects = 16; + memcpy(argp, &max_effects, sizeof(int)); + return 0; + } else if (type == 0x45 && number >= 0x40 && number <= 0x51) { + Logger::log("Hooking ioctl EVIOCGABS(ABS) for event %s\n", event); + struct input_absinfo abs_info; + memset(&abs_info, 0, sizeof(abs_info)); + uint16_t code = ring_abs_code(number - 0x40); + if (code == ABS_GAS || code == ABS_BRAKE) { + abs_info.value = 0; + abs_info.minimum = 0; + abs_info.maximum = 255; + } else if (code <= ABS_RY) { + abs_info.value = 0; + abs_info.minimum = -32768; + abs_info.maximum = 32767; + } else if (code == ABS_HAT0X || code == ABS_HAT0Y) { + abs_info.value = 0; + abs_info.minimum = -1; + abs_info.maximum = 1; + } + SnapshotState snap; + if (!wait_snapshot(controller->second, guard, snap)) return -1; + for (int i = 0; i < 8; ++i) + if (kSnapshotAxisCodes[i] == code) abs_info.value = snap.axes[i]; + memcpy(argp, &abs_info, std::min(_IOC_SIZE(op), sizeof(abs_info))); + return 0; + } else if (type == 0x45 && number == 0x90) { + Logger::log("Hooking ioctl EVIOCGRAB for event %s\n", event); + return 0; + } else if (type == 0x6A && number == 0x1) { + Logger::log("Hooking ioctl JSIOCGVERSION for event %s\n", event); + int version = JS_VERSION; + memcpy(argp, (void *)&version, sizeof(version)); + return 0; + } else if (type == 0x6A && number == 0x11) { + Logger::log("Hooking ioctl JSIOCGAXES for event %s\n", event); + uint8_t axes = GAMEPAD_AXIS_COUNT; + memcpy(argp, (void *)&axes, sizeof(axes)); + return 0; + } else if (type == 0x6A && number == 0x12) { + Logger::log("Hooking ioctl JSIOCGBUTTONS for event %s\n", event); + uint8_t buttons = GAMEPAD_BUTTON_COUNT; + memcpy(argp, (void *)&buttons, sizeof(buttons)); + return 0; + } else if (type == 0x6A && number == 0x13) { + Logger::log("Hooking ioctl JSIOCGNAME(len) for event %s\n", event); + copy_slot_ioctl_string(op, argp, + presents_steam_virtual() ? STEAM_VIRTUAL_NAME_TEMPLATE + : (fake_xbox360_identity() ? X360_NAME_TEMPLATE : GAMEPAD_NAME_TEMPLATE), + event_number); + return 0; + } else { + Logger::log("Unhandled evdev ioctl, type %d number %d\n", type, number); + guard.unlock(); + return syscall(SYS_ioctl, fd, op, argp); + } +} + +EXPORT int close(int fd) { + static auto my_close = reinterpret_cast(dlsym(RTLD_NEXT, "close")); + + std::unique_lock guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (controller != controller_map().end()) { + Logger::log("Removing controller, fd %d event %s\n", controller->first, + controller->second->event ? controller->second->event : "(unknown)"); + controller->second->closed = true; + controller_map().erase(fd); + } + guard.unlock(); + + return my_close(fd); +} + +EXPORT ssize_t read(int fd, void *buf, size_t count) { + std::unique_lock guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (controller == controller_map().end()) { + guard.unlock(); + return syscall(SYS_read, fd, buf, count); + } + // Keep the mapping alive across waits, even if close() removes the fd and + // another open reuses its number. Every state access still holds the lock. + auto handle = controller->second; + FakeController &fake = *handle; + if (count < FAKE_INPUT_EVENT_SIZE) { + errno = EINVAL; + return -1; + } + int flags = fcntl(fd, F_GETFL); + bool nonblock = flags >= 0 && (flags & O_NONBLOCK); + long backoff_ns = 1000 * 1000; + + for (;;) { + if (fake.closed) { + errno = EBADF; + return -1; + } + if (ring_generation(fake.ring) != fake.generation) { + errno = ENODEV; + return -1; + } + for (int attempt = 0; attempt < 8; ++attempt) { + size_t requested = count / FAKE_INPUT_EVENT_SIZE; + if (fake.keyframe_remaining == 0) { + SnapshotState snap; + if (!read_snapshot(fake.ring, snap)) break; + if (snap.generation != fake.generation) { + errno = ENODEV; + return -1; + } + if (fake.needs_keyframe || snap.resync_seq != fake.resync_seq || + snap.write_seq < fake.read_seq || + snap.write_seq - fake.read_seq > FAKE_INPUT_RING_CAPACITY) { + capture_keyframe(fake, snap); + } else { + size_t events = std::min(requested, snap.write_seq - fake.read_seq); + if (events == 0) break; + const uint8_t *ring_events = reinterpret_cast(fake.ring) + + FAKE_INPUT_RING_HEADER_SIZE; + for (size_t i = 0; i < events; ++i) { + size_t index = (fake.read_seq + i) % FAKE_INPUT_RING_CAPACITY; + struct input_event ev; + memcpy(&ev, ring_events + index * FAKE_INPUT_EVENT_SIZE, FAKE_INPUT_EVENT_SIZE); + if (ev.type == EV_ABS) ev.code = presented_abs_code(ev.code); + memcpy(static_cast(buf) + i * FAKE_INPUT_EVENT_SIZE, &ev, + FAKE_INPUT_EVENT_SIZE); + } + // A producer can lap the reader while it copies. Discard that copy + // instead of delivering torn/overwritten events or losing a release. + __atomic_thread_fence(__ATOMIC_ACQUIRE); + if (snap.sequence != __atomic_load_n(&fake.ring->snapshot_seq, __ATOMIC_RELAXED)) + continue; + fake.read_seq += events; + return static_cast(events * FAKE_INPUT_EVENT_SIZE); + } + } + + // Finish a captured frame before handling a newer resync. Its counter is + // acknowledged only when that newer snapshot is actually captured. + size_t events = std::min(requested, fake.keyframe_remaining); + struct timeval now = {}; + gettimeofday(&now, nullptr); + for (size_t i = 0; i < events; ++i) { + size_t index = kNeutralEventCount - fake.keyframe_remaining; + struct input_event ev = {}; + ev.time = now; + ev.type = kNeutralEvents[index].type; + ev.code = kNeutralEvents[index].code; + ev.value = keyframe_value(fake, ev.type, ev.code); + if (ev.type == EV_ABS) ev.code = presented_abs_code(ev.code); + memcpy(static_cast(buf) + i * FAKE_INPUT_EVENT_SIZE, + &ev, FAKE_INPUT_EVENT_SIZE); + --fake.keyframe_remaining; + } + return static_cast(events * FAKE_INPUT_EVENT_SIZE); + } + if (nonblock) { + errno = EAGAIN; + return -1; + } + guard.unlock(); + struct timespec sleep_time = {0, backoff_ns}; + int result = nanosleep(&sleep_time, nullptr); + guard.lock(); + if (result < 0) return -1; + if (backoff_ns < 16 * 1000 * 1000) backoff_ns *= 2; + } +} + +EXPORT ssize_t write(int fd, const void *buf, size_t count) { + static auto my_write = reinterpret_cast(dlsym(RTLD_NEXT, "write")); + + std::unique_lock guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (controller != controller_map().end()) { + if (fake_fd_is_stale(fd)) { + errno = ENODEV; + return -1; + } + + const struct input_event *ev = nullptr; + uint16_t slot = static_cast(controller->second->slot); + if (count == sizeof(struct input_event)) { + ev = static_cast(buf); + check_ff_event(ev, slot); + } + + return static_cast(count); + } + guard.unlock(); + return my_write(fd, buf, count); +} + +EXPORT ssize_t writev(int fd, const struct iovec *iov, int iovcnt) { + std::unique_lock guard(controller_mutex()); + auto controller = controller_map().find(fd); + if (controller != controller_map().end()) { + if (fake_fd_is_stale(fd)) { + errno = ENODEV; + return -1; + } + + uint16_t slot = static_cast(controller->second->slot); + ssize_t total = 0; + for (int i = 0; i < iovcnt; i++) { + if (iov[i].iov_len == sizeof(struct input_event)) { + const struct input_event *ev = + static_cast(iov[i].iov_base); + check_ff_event(ev, slot); + } + total += static_cast(iov[i].iov_len); + } + return total; + } + guard.unlock(); + return syscall(SYS_writev, fd, iov, iovcnt); +} + +static int poll_fake(struct pollfd *fds, nfds_t nfds, int timeout, + const sigset_t *sigmask) { + static auto my_poll = reinterpret_cast(dlsym(RTLD_NEXT, "poll")); + static auto my_ppoll = reinterpret_cast(dlsym(RTLD_NEXT, "ppoll")); + + bool has_fake_fds = false; + std::vector real_fds; + real_fds.reserve(nfds); + std::vector> fake_fds(nfds); + { + std::lock_guard guard(controller_mutex()); + for (nfds_t i = 0; i < nfds; i++) { + real_fds.push_back(fds[i]); + auto it = controller_map().find(fds[i].fd); + if (it != controller_map().end()) { + fake_fds[i] = it->second; + has_fake_fds = true; + real_fds[i].fd = -1; + real_fds[i].revents = 0; + } + } + } + + if (!has_fake_fds) { + if (sigmask) { + struct timespec wait = {timeout / 1000, (timeout % 1000) * 1000000L}; + return my_ppoll(fds, nfds, timeout < 0 ? nullptr : &wait, sigmask); + } + return my_poll(fds, nfds, timeout); + } + + const long long deadline_ms = timeout < 0 ? -1 : monotonic_ms() + timeout; + int backoff_ms = 1; + + while (true) { + int ready = 0; + + for (nfds_t i = 0; i < nfds; i++) + fds[i].revents = 0; + + for (nfds_t i = 0; i < nfds; i++) { + if (!fake_fds[i]) continue; + short revents = fake_poll_revents(fake_fds[i], fds[i].events); + fds[i].revents = revents; + if (revents) + ready++; + } + + int real_timeout = ready > 0 ? 0 : [&] { + if (timeout == 0) return 0; + int remaining = deadline_ms < 0 + ? backoff_ms + : std::min(backoff_ms, (int)(deadline_ms - monotonic_ms())); + return std::max(remaining, 0); + }(); + + int real_ready; + if (sigmask) { + struct timespec wait = {real_timeout / 1000, (real_timeout % 1000) * 1000000L}; + real_ready = my_ppoll(real_fds.data(), nfds, &wait, sigmask); + } else { + real_ready = my_poll(real_fds.data(), nfds, real_timeout); + } + if (real_ready < 0) return -1; + if (real_ready > 0) { + for (nfds_t i = 0; i < nfds; i++) { + if (!fake_fds[i]) { + fds[i].revents = real_fds[i].revents; + if (fds[i].revents) + ready++; + } + } + } + + if (ready == 0 && real_timeout > 0) { + for (nfds_t i = 0; i < nfds; i++) { + if (!fake_fds[i]) continue; + short revents = fake_poll_revents(fake_fds[i], fds[i].events); + fds[i].revents = revents; + if (revents) + ready++; + } + } + + if (ready > 0) + return ready; + + if (timeout == 0) + return 0; + + if (deadline_ms >= 0 && monotonic_ms() >= deadline_ms) + return 0; + + if (backoff_ms < 16) + backoff_ms *= 2; + } +} + +EXPORT int poll(struct pollfd *fds, nfds_t nfds, int timeout) { + return poll_fake(fds, nfds, timeout, nullptr); +} + +EXPORT int ppoll(struct pollfd *fds, nfds_t nfds, + const struct timespec *timeout, const sigset_t *sigmask) { + static auto my_ppoll = reinterpret_cast(dlsym(RTLD_NEXT, "ppoll")); + if (timeout && (timeout->tv_sec < 0 || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000L)) { + errno = EINVAL; + return -1; + } + for (nfds_t i = 0; i < nfds; ++i) { + if (!is_fake_input_fd(fds[i].fd)) continue; + if (!sigmask) + return poll_fake(fds, nfds, static_cast(timespec_to_ms(timeout)), nullptr); + // Keep signals pending between polling slices. Each kernel ppoll applies + // the requested mask atomically with its wait, just like a single ppoll. + sigset_t all_signals, original_mask; + sigfillset(&all_signals); + int error = pthread_sigmask(SIG_SETMASK, &all_signals, &original_mask); + if (error) { + errno = error; + return -1; + } + int result = poll_fake(fds, nfds, static_cast(timespec_to_ms(timeout)), sigmask); + int saved_errno = errno; + pthread_sigmask(SIG_SETMASK, &original_mask, nullptr); + errno = saved_errno; + return result; + } + return my_ppoll(fds, nfds, timeout, sigmask); +} + +EXPORT int select(int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout) { + static auto my_select = reinterpret_cast(dlsym(RTLD_NEXT, "select")); + + fd_set original_readfds; + fd_set original_writefds; + fd_set original_exceptfds; + fd_set real_readfds; + fd_set real_writefds; + fd_set real_exceptfds; + bool has_fake_fds = false; + + if (readfds) { + original_readfds = *readfds; + real_readfds = *readfds; + } else { + FD_ZERO(&original_readfds); + FD_ZERO(&real_readfds); + } + if (writefds) { + original_writefds = *writefds; + real_writefds = *writefds; + } else { + FD_ZERO(&original_writefds); + FD_ZERO(&real_writefds); + } + if (exceptfds) { + original_exceptfds = *exceptfds; + real_exceptfds = *exceptfds; + } else { + FD_ZERO(&original_exceptfds); + FD_ZERO(&real_exceptfds); + } + + for (int fd = 0; fd < nfds; fd++) { + if (!is_fake_input_fd(fd)) + continue; + has_fake_fds = true; + FD_CLR(fd, &real_readfds); + FD_CLR(fd, &real_writefds); + FD_CLR(fd, &real_exceptfds); + } + + if (!has_fake_fds) + return my_select ? my_select(nfds, readfds, writefds, exceptfds, timeout) + : -1; + + const long long timeout_ms = timeval_to_ms(timeout); + const long long deadline_ms = + timeout_ms < 0 ? -1 : monotonic_ms() + timeout_ms; + int backoff_ms = 1; + + while (true) { + int ready = 0; + + if (readfds) + FD_ZERO(readfds); + if (writefds) + FD_ZERO(writefds); + if (exceptfds) + FD_ZERO(exceptfds); + + for (int fd = 0; fd < nfds; fd++) { + if (!is_fake_input_fd(fd)) + continue; + if (readfds && FD_ISSET(fd, &original_readfds) && fake_fd_is_stale(fd)) { + FD_SET(fd, readfds); + ready++; + } else if (readfds && FD_ISSET(fd, &original_readfds) && + fake_fd_has_unread_data(fd)) { + FD_SET(fd, readfds); + ready++; + } + } + + int wait_ms = ready > 0 ? 0 : [&] { + if (timeout_ms == 0) return 0; + int remaining = deadline_ms < 0 + ? backoff_ms + : std::min(backoff_ms, (int)(deadline_ms - monotonic_ms())); + return std::max(remaining, 0); + }(); + struct timeval wait_tv = {wait_ms / 1000, (wait_ms % 1000) * 1000}; + + fd_set iter_readfds = real_readfds; + fd_set iter_writefds = real_writefds; + fd_set iter_exceptfds = real_exceptfds; + + int real_ready = + my_select + ? my_select(nfds, readfds ? &iter_readfds : nullptr, + writefds ? &iter_writefds : nullptr, + exceptfds ? &iter_exceptfds : nullptr, &wait_tv) + : 0; + + if (real_ready < 0) return -1; + if (real_ready > 0) { + for (int fd = 0; fd < nfds; fd++) { + if (readfds && FD_ISSET(fd, &iter_readfds)) { + FD_SET(fd, readfds); + ready++; + } + if (writefds && FD_ISSET(fd, &iter_writefds)) { + FD_SET(fd, writefds); + ready++; + } + if (exceptfds && FD_ISSET(fd, &iter_exceptfds)) { + FD_SET(fd, exceptfds); + ready++; + } + } + } + + if (ready == 0 && wait_ms > 0) { + for (int fd = 0; fd < nfds; fd++) { + if (!is_fake_input_fd(fd)) + continue; + if (readfds && FD_ISSET(fd, &original_readfds) && fake_fd_is_stale(fd)) { + FD_SET(fd, readfds); + ready++; + } else if (readfds && FD_ISSET(fd, &original_readfds) && + fake_fd_has_unread_data(fd)) { + FD_SET(fd, readfds); + ready++; + } + } + } + + if (ready > 0) + return ready; + + if (timeout_ms == 0) + return 0; + + if (deadline_ms >= 0 && monotonic_ms() >= deadline_ms) + return 0; + + if (backoff_ms < 16) + backoff_ms *= 2; + } +} + +#ifdef __GLIBC__ +// Steam's binaries were linked against an older glibc and reach the calls above through these +// names instead. +static mode_t open_mode(int flags, va_list va) { + return (flags & (O_CREAT | O_TMPFILE)) ? va_arg(va, mode_t) : 0; +} + +EXPORT int open64(const char *pathname, int flags, ...) { + va_list va; + va_start(va, flags); + mode_t mode = open_mode(flags, va); + va_end(va); + return open(pathname, flags, mode); +} + +EXPORT int openat64(int dirfd, const char *pathname, int flags, ...) { + va_list va; + va_start(va, flags); + mode_t mode = open_mode(flags, va); + va_end(va); + return openat(dirfd, pathname, flags, mode); +} + +EXPORT int stat64(const char *pathname, struct stat64 *statbuf) { + return stat(pathname, reinterpret_cast(statbuf)); +} + +EXPORT int fstat64(int fd, struct stat64 *buf) { + return fstat(fd, reinterpret_cast(buf)); +} + +EXPORT int __xstat(int version, const char *pathname, struct stat *statbuf) { + (void)version; + return stat(pathname, statbuf); +} + +EXPORT int __xstat64(int version, const char *pathname, struct stat64 *statbuf) { + (void)version; + return stat(pathname, reinterpret_cast(statbuf)); +} + +EXPORT int __fxstat(int version, int fd, struct stat *buf) { + (void)version; + return fstat(fd, buf); +} + +EXPORT int __fxstat64(int version, int fd, struct stat64 *buf) { + (void)version; + return fstat(fd, reinterpret_cast(buf)); +} +#endif diff --git a/app/src/main/cpp/sdnative/sdnative.c b/app/src/main/cpp/sdnative/sdnative.c new file mode 100644 index 0000000000..323c890a79 --- /dev/null +++ b/app/src/main/cpp/sdnative/sdnative.c @@ -0,0 +1,17 @@ +/* + * One function: the release fence the fake-input ring writer needs. + * + * FakeInputWriter publishes events into a shared-memory ring that libfakeinput.so reads from + * another process. Java's memory model says nothing about what a foreign reader sees, so the + * writer calls this between filling the events and advancing the sequence counter: everything + * written before it is visible to the reader before the counter moves. + */ +#include +#include + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_input_FakeInputWriter_nativeStoreFence(JNIEnv *env, jclass clazz) { + (void)env; + (void)clazz; + atomic_thread_fence(memory_order_release); +} diff --git a/app/src/main/cpp/shaders/cas_frag.h b/app/src/main/cpp/shaders/cas_frag.h new file mode 100644 index 0000000000..21347e38d1 --- /dev/null +++ b/app/src/main/cpp/shaders/cas_frag.h @@ -0,0 +1,181 @@ + // 1116.2.0 + #pragma once +const uint32_t cas_code[] = { + 0x07230203,0x00010000,0x0008000b,0x000000f3,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x000000ed,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00030005,0x00000009,0x00007675,0x00060005,0x0000000b,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00030005,0x0000000d,0x00007870,0x00030005,0x00000010,0x00004350, + 0x00040006,0x00000010,0x00000000,0x0063646e,0x00060006,0x00000010,0x00000001,0x6f736572, + 0x6974756c,0x00006e6f,0x00060006,0x00000010,0x00000002,0x72616873,0x73656e70,0x00000073, + 0x00030005,0x00000012,0x00006370,0x00050005,0x0000001b,0x52414853,0x53454e50,0x00000053, + 0x00030005,0x00000022,0x00000061,0x00060005,0x00000026,0x75706e49,0x78655474,0x65727574, + 0x00000000,0x00030005,0x00000036,0x00000062,0x00030005,0x00000041,0x00000063,0x00030005, + 0x0000004d,0x00000064,0x00030005,0x00000057,0x00000065,0x00030005,0x0000005c,0x00000066, + 0x00030005,0x00000065,0x00000067,0x00030005,0x00000071,0x00000068,0x00030005,0x0000007a, + 0x00000069,0x00040005,0x00000085,0x47526e6d,0x00000042,0x00040005,0x0000008f,0x47526e6d, + 0x00003242,0x00040005,0x0000009c,0x4752786d,0x00000042,0x00040005,0x000000a6,0x4752786d, + 0x00003242,0x00050005,0x000000b3,0x4d706372,0x42475278,0x00000000,0x00040005,0x000000b7, + 0x52706d61,0x00004247,0x00040005,0x000000c5,0x6b616570,0x00000000,0x00040005,0x000000cb, + 0x42475277,0x00000000,0x00060005,0x000000d2,0x57706372,0x68676965,0x42475274,0x00000000, + 0x00040005,0x000000d9,0x646e6977,0x0000776f,0x00030005,0x000000e1,0x006c6f63,0x00050005, + 0x000000ed,0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x0000000b,0x0000001e,0x00000000, + 0x00030047,0x00000010,0x00000002,0x00050048,0x00000010,0x00000000,0x00000023,0x00000000, + 0x00050048,0x00000010,0x00000001,0x00000023,0x00000010,0x00050048,0x00000010,0x00000002, + 0x00000023,0x00000018,0x00040047,0x00000026,0x00000021,0x00000000,0x00040047,0x00000026, + 0x00000022,0x00000000,0x00040047,0x000000ed,0x0000001e,0x00000000,0x00020013,0x00000002, + 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007, + 0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00040020,0x0000000a, + 0x00000001,0x00000007,0x0004003b,0x0000000a,0x0000000b,0x00000001,0x0004002b,0x00000006, + 0x0000000e,0x3f800000,0x00040017,0x0000000f,0x00000006,0x00000004,0x0005001e,0x00000010, + 0x0000000f,0x00000007,0x00000006,0x00040020,0x00000011,0x00000009,0x00000010,0x0004003b, + 0x00000011,0x00000012,0x00000009,0x00040015,0x00000013,0x00000020,0x00000001,0x0004002b, + 0x00000013,0x00000014,0x00000001,0x00040020,0x00000015,0x00000009,0x00000007,0x00040020, + 0x0000001a,0x00000007,0x00000006,0x0004002b,0x00000013,0x0000001c,0x00000002,0x00040020, + 0x0000001d,0x00000009,0x00000006,0x00040017,0x00000020,0x00000006,0x00000003,0x00040020, + 0x00000021,0x00000007,0x00000020,0x00090019,0x00000023,0x00000006,0x00000001,0x00000000, + 0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000024,0x00000023,0x00040020, + 0x00000025,0x00000000,0x00000024,0x0004003b,0x00000025,0x00000026,0x00000000,0x00040015, + 0x00000029,0x00000020,0x00000000,0x0004002b,0x00000029,0x0000002a,0x00000000,0x0004002b, + 0x00000029,0x0000002e,0x00000001,0x0004002b,0x00000006,0x00000039,0x00000000,0x0006002c, + 0x00000020,0x000000b4,0x0000000e,0x0000000e,0x0000000e,0x0004002b,0x00000006,0x000000b9, + 0x40000000,0x0004002b,0x00000006,0x000000c6,0x41000000,0x0004002b,0x00000006,0x000000c7, + 0x40400000,0x0004002b,0x00000006,0x000000cc,0xbf800000,0x0006002c,0x00000020,0x000000cd, + 0x000000cc,0x000000cc,0x000000cc,0x0004002b,0x00000006,0x000000d3,0x40800000,0x00040020, + 0x000000ec,0x00000003,0x0000000f,0x0004003b,0x000000ec,0x000000ed,0x00000003,0x00050036, + 0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000008, + 0x00000009,0x00000007,0x0004003b,0x00000008,0x0000000d,0x00000007,0x0004003b,0x0000001a, + 0x0000001b,0x00000007,0x0004003b,0x00000021,0x00000022,0x00000007,0x0004003b,0x00000021, + 0x00000036,0x00000007,0x0004003b,0x00000021,0x00000041,0x00000007,0x0004003b,0x00000021, + 0x0000004d,0x00000007,0x0004003b,0x00000021,0x00000057,0x00000007,0x0004003b,0x00000021, + 0x0000005c,0x00000007,0x0004003b,0x00000021,0x00000065,0x00000007,0x0004003b,0x00000021, + 0x00000071,0x00000007,0x0004003b,0x00000021,0x0000007a,0x00000007,0x0004003b,0x00000021, + 0x00000085,0x00000007,0x0004003b,0x00000021,0x0000008f,0x00000007,0x0004003b,0x00000021, + 0x0000009c,0x00000007,0x0004003b,0x00000021,0x000000a6,0x00000007,0x0004003b,0x00000021, + 0x000000b3,0x00000007,0x0004003b,0x00000021,0x000000b7,0x00000007,0x0004003b,0x0000001a, + 0x000000c5,0x00000007,0x0004003b,0x00000021,0x000000cb,0x00000007,0x0004003b,0x00000021, + 0x000000d2,0x00000007,0x0004003b,0x00000021,0x000000d9,0x00000007,0x0004003b,0x00000021, + 0x000000e1,0x00000007,0x0004003d,0x00000007,0x0000000c,0x0000000b,0x0003003e,0x00000009, + 0x0000000c,0x00050041,0x00000015,0x00000016,0x00000012,0x00000014,0x0004003d,0x00000007, + 0x00000017,0x00000016,0x00050050,0x00000007,0x00000018,0x0000000e,0x0000000e,0x00050088, + 0x00000007,0x00000019,0x00000018,0x00000017,0x0003003e,0x0000000d,0x00000019,0x00050041, + 0x0000001d,0x0000001e,0x00000012,0x0000001c,0x0004003d,0x00000006,0x0000001f,0x0000001e, + 0x0003003e,0x0000001b,0x0000001f,0x0004003d,0x00000024,0x00000027,0x00000026,0x0004003d, + 0x00000007,0x00000028,0x00000009,0x00050041,0x0000001a,0x0000002b,0x0000000d,0x0000002a, + 0x0004003d,0x00000006,0x0000002c,0x0000002b,0x0004007f,0x00000006,0x0000002d,0x0000002c, + 0x00050041,0x0000001a,0x0000002f,0x0000000d,0x0000002e,0x0004003d,0x00000006,0x00000030, + 0x0000002f,0x0004007f,0x00000006,0x00000031,0x00000030,0x00050050,0x00000007,0x00000032, + 0x0000002d,0x00000031,0x00050081,0x00000007,0x00000033,0x00000028,0x00000032,0x00050057, + 0x0000000f,0x00000034,0x00000027,0x00000033,0x0008004f,0x00000020,0x00000035,0x00000034, + 0x00000034,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000022,0x00000035,0x0004003d, + 0x00000024,0x00000037,0x00000026,0x0004003d,0x00000007,0x00000038,0x00000009,0x00050041, + 0x0000001a,0x0000003a,0x0000000d,0x0000002e,0x0004003d,0x00000006,0x0000003b,0x0000003a, + 0x0004007f,0x00000006,0x0000003c,0x0000003b,0x00050050,0x00000007,0x0000003d,0x00000039, + 0x0000003c,0x00050081,0x00000007,0x0000003e,0x00000038,0x0000003d,0x00050057,0x0000000f, + 0x0000003f,0x00000037,0x0000003e,0x0008004f,0x00000020,0x00000040,0x0000003f,0x0000003f, + 0x00000000,0x00000001,0x00000002,0x0003003e,0x00000036,0x00000040,0x0004003d,0x00000024, + 0x00000042,0x00000026,0x0004003d,0x00000007,0x00000043,0x00000009,0x00050041,0x0000001a, + 0x00000044,0x0000000d,0x0000002a,0x0004003d,0x00000006,0x00000045,0x00000044,0x00050041, + 0x0000001a,0x00000046,0x0000000d,0x0000002e,0x0004003d,0x00000006,0x00000047,0x00000046, + 0x0004007f,0x00000006,0x00000048,0x00000047,0x00050050,0x00000007,0x00000049,0x00000045, + 0x00000048,0x00050081,0x00000007,0x0000004a,0x00000043,0x00000049,0x00050057,0x0000000f, + 0x0000004b,0x00000042,0x0000004a,0x0008004f,0x00000020,0x0000004c,0x0000004b,0x0000004b, + 0x00000000,0x00000001,0x00000002,0x0003003e,0x00000041,0x0000004c,0x0004003d,0x00000024, + 0x0000004e,0x00000026,0x0004003d,0x00000007,0x0000004f,0x00000009,0x00050041,0x0000001a, + 0x00000050,0x0000000d,0x0000002a,0x0004003d,0x00000006,0x00000051,0x00000050,0x0004007f, + 0x00000006,0x00000052,0x00000051,0x00050050,0x00000007,0x00000053,0x00000052,0x00000039, + 0x00050081,0x00000007,0x00000054,0x0000004f,0x00000053,0x00050057,0x0000000f,0x00000055, + 0x0000004e,0x00000054,0x0008004f,0x00000020,0x00000056,0x00000055,0x00000055,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x0000004d,0x00000056,0x0004003d,0x00000024,0x00000058, + 0x00000026,0x0004003d,0x00000007,0x00000059,0x00000009,0x00050057,0x0000000f,0x0000005a, + 0x00000058,0x00000059,0x0008004f,0x00000020,0x0000005b,0x0000005a,0x0000005a,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x00000057,0x0000005b,0x0004003d,0x00000024,0x0000005d, + 0x00000026,0x0004003d,0x00000007,0x0000005e,0x00000009,0x00050041,0x0000001a,0x0000005f, + 0x0000000d,0x0000002a,0x0004003d,0x00000006,0x00000060,0x0000005f,0x00050050,0x00000007, + 0x00000061,0x00000060,0x00000039,0x00050081,0x00000007,0x00000062,0x0000005e,0x00000061, + 0x00050057,0x0000000f,0x00000063,0x0000005d,0x00000062,0x0008004f,0x00000020,0x00000064, + 0x00000063,0x00000063,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000005c,0x00000064, + 0x0004003d,0x00000024,0x00000066,0x00000026,0x0004003d,0x00000007,0x00000067,0x00000009, + 0x00050041,0x0000001a,0x00000068,0x0000000d,0x0000002a,0x0004003d,0x00000006,0x00000069, + 0x00000068,0x0004007f,0x00000006,0x0000006a,0x00000069,0x00050041,0x0000001a,0x0000006b, + 0x0000000d,0x0000002e,0x0004003d,0x00000006,0x0000006c,0x0000006b,0x00050050,0x00000007, + 0x0000006d,0x0000006a,0x0000006c,0x00050081,0x00000007,0x0000006e,0x00000067,0x0000006d, + 0x00050057,0x0000000f,0x0000006f,0x00000066,0x0000006e,0x0008004f,0x00000020,0x00000070, + 0x0000006f,0x0000006f,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000065,0x00000070, + 0x0004003d,0x00000024,0x00000072,0x00000026,0x0004003d,0x00000007,0x00000073,0x00000009, + 0x00050041,0x0000001a,0x00000074,0x0000000d,0x0000002e,0x0004003d,0x00000006,0x00000075, + 0x00000074,0x00050050,0x00000007,0x00000076,0x00000039,0x00000075,0x00050081,0x00000007, + 0x00000077,0x00000073,0x00000076,0x00050057,0x0000000f,0x00000078,0x00000072,0x00000077, + 0x0008004f,0x00000020,0x00000079,0x00000078,0x00000078,0x00000000,0x00000001,0x00000002, + 0x0003003e,0x00000071,0x00000079,0x0004003d,0x00000024,0x0000007b,0x00000026,0x0004003d, + 0x00000007,0x0000007c,0x00000009,0x00050041,0x0000001a,0x0000007d,0x0000000d,0x0000002a, + 0x0004003d,0x00000006,0x0000007e,0x0000007d,0x00050041,0x0000001a,0x0000007f,0x0000000d, + 0x0000002e,0x0004003d,0x00000006,0x00000080,0x0000007f,0x00050050,0x00000007,0x00000081, + 0x0000007e,0x00000080,0x00050081,0x00000007,0x00000082,0x0000007c,0x00000081,0x00050057, + 0x0000000f,0x00000083,0x0000007b,0x00000082,0x0008004f,0x00000020,0x00000084,0x00000083, + 0x00000083,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000007a,0x00000084,0x0004003d, + 0x00000020,0x00000086,0x0000004d,0x0004003d,0x00000020,0x00000087,0x00000057,0x0007000c, + 0x00000020,0x00000088,0x00000001,0x00000025,0x00000086,0x00000087,0x0004003d,0x00000020, + 0x00000089,0x0000005c,0x0004003d,0x00000020,0x0000008a,0x00000036,0x0007000c,0x00000020, + 0x0000008b,0x00000001,0x00000025,0x00000089,0x0000008a,0x0007000c,0x00000020,0x0000008c, + 0x00000001,0x00000025,0x00000088,0x0000008b,0x0004003d,0x00000020,0x0000008d,0x00000071, + 0x0007000c,0x00000020,0x0000008e,0x00000001,0x00000025,0x0000008c,0x0000008d,0x0003003e, + 0x00000085,0x0000008e,0x0004003d,0x00000020,0x00000090,0x00000085,0x0004003d,0x00000020, + 0x00000091,0x00000022,0x0007000c,0x00000020,0x00000092,0x00000001,0x00000025,0x00000090, + 0x00000091,0x0004003d,0x00000020,0x00000093,0x00000065,0x0004003d,0x00000020,0x00000094, + 0x00000041,0x0007000c,0x00000020,0x00000095,0x00000001,0x00000025,0x00000093,0x00000094, + 0x0007000c,0x00000020,0x00000096,0x00000001,0x00000025,0x00000092,0x00000095,0x0004003d, + 0x00000020,0x00000097,0x0000007a,0x0007000c,0x00000020,0x00000098,0x00000001,0x00000025, + 0x00000096,0x00000097,0x0003003e,0x0000008f,0x00000098,0x0004003d,0x00000020,0x00000099, + 0x0000008f,0x0004003d,0x00000020,0x0000009a,0x00000085,0x00050081,0x00000020,0x0000009b, + 0x0000009a,0x00000099,0x0003003e,0x00000085,0x0000009b,0x0004003d,0x00000020,0x0000009d, + 0x0000004d,0x0004003d,0x00000020,0x0000009e,0x00000057,0x0007000c,0x00000020,0x0000009f, + 0x00000001,0x00000028,0x0000009d,0x0000009e,0x0004003d,0x00000020,0x000000a0,0x0000005c, + 0x0004003d,0x00000020,0x000000a1,0x00000036,0x0007000c,0x00000020,0x000000a2,0x00000001, + 0x00000028,0x000000a0,0x000000a1,0x0007000c,0x00000020,0x000000a3,0x00000001,0x00000028, + 0x0000009f,0x000000a2,0x0004003d,0x00000020,0x000000a4,0x00000071,0x0007000c,0x00000020, + 0x000000a5,0x00000001,0x00000028,0x000000a3,0x000000a4,0x0003003e,0x0000009c,0x000000a5, + 0x0004003d,0x00000020,0x000000a7,0x0000009c,0x0004003d,0x00000020,0x000000a8,0x00000022, + 0x0007000c,0x00000020,0x000000a9,0x00000001,0x00000028,0x000000a7,0x000000a8,0x0004003d, + 0x00000020,0x000000aa,0x00000065,0x0004003d,0x00000020,0x000000ab,0x00000041,0x0007000c, + 0x00000020,0x000000ac,0x00000001,0x00000028,0x000000aa,0x000000ab,0x0007000c,0x00000020, + 0x000000ad,0x00000001,0x00000028,0x000000a9,0x000000ac,0x0004003d,0x00000020,0x000000ae, + 0x0000007a,0x0007000c,0x00000020,0x000000af,0x00000001,0x00000028,0x000000ad,0x000000ae, + 0x0003003e,0x000000a6,0x000000af,0x0004003d,0x00000020,0x000000b0,0x000000a6,0x0004003d, + 0x00000020,0x000000b1,0x0000009c,0x00050081,0x00000020,0x000000b2,0x000000b1,0x000000b0, + 0x0003003e,0x0000009c,0x000000b2,0x0004003d,0x00000020,0x000000b5,0x0000009c,0x00050088, + 0x00000020,0x000000b6,0x000000b4,0x000000b5,0x0003003e,0x000000b3,0x000000b6,0x0004003d, + 0x00000020,0x000000b8,0x00000085,0x0004003d,0x00000020,0x000000ba,0x0000009c,0x00060050, + 0x00000020,0x000000bb,0x000000b9,0x000000b9,0x000000b9,0x00050083,0x00000020,0x000000bc, + 0x000000bb,0x000000ba,0x0007000c,0x00000020,0x000000bd,0x00000001,0x00000025,0x000000b8, + 0x000000bc,0x0004003d,0x00000020,0x000000be,0x000000b3,0x00050085,0x00000020,0x000000bf, + 0x000000bd,0x000000be,0x00060050,0x00000020,0x000000c0,0x00000039,0x00000039,0x00000039, + 0x00060050,0x00000020,0x000000c1,0x0000000e,0x0000000e,0x0000000e,0x0008000c,0x00000020, + 0x000000c2,0x00000001,0x0000002b,0x000000bf,0x000000c0,0x000000c1,0x0003003e,0x000000b7, + 0x000000c2,0x0004003d,0x00000020,0x000000c3,0x000000b7,0x0006000c,0x00000020,0x000000c4, + 0x00000001,0x00000020,0x000000c3,0x0003003e,0x000000b7,0x000000c4,0x0004003d,0x00000006, + 0x000000c8,0x0000001b,0x00050085,0x00000006,0x000000c9,0x000000c7,0x000000c8,0x00050083, + 0x00000006,0x000000ca,0x000000c6,0x000000c9,0x0003003e,0x000000c5,0x000000ca,0x0004003d, + 0x00000020,0x000000ce,0x000000b7,0x0004003d,0x00000006,0x000000cf,0x000000c5,0x0005008e, + 0x00000020,0x000000d0,0x000000ce,0x000000cf,0x00050088,0x00000020,0x000000d1,0x000000cd, + 0x000000d0,0x0003003e,0x000000cb,0x000000d1,0x0004003d,0x00000020,0x000000d4,0x000000cb, + 0x0005008e,0x00000020,0x000000d5,0x000000d4,0x000000d3,0x00060050,0x00000020,0x000000d6, + 0x0000000e,0x0000000e,0x0000000e,0x00050081,0x00000020,0x000000d7,0x000000d6,0x000000d5, + 0x00050088,0x00000020,0x000000d8,0x000000b4,0x000000d7,0x0003003e,0x000000d2,0x000000d8, + 0x0004003d,0x00000020,0x000000da,0x00000036,0x0004003d,0x00000020,0x000000db,0x0000004d, + 0x00050081,0x00000020,0x000000dc,0x000000da,0x000000db,0x0004003d,0x00000020,0x000000dd, + 0x0000005c,0x0004003d,0x00000020,0x000000de,0x00000071,0x00050081,0x00000020,0x000000df, + 0x000000dd,0x000000de,0x00050081,0x00000020,0x000000e0,0x000000dc,0x000000df,0x0003003e, + 0x000000d9,0x000000e0,0x0004003d,0x00000020,0x000000e2,0x000000d9,0x0004003d,0x00000020, + 0x000000e3,0x000000cb,0x00050085,0x00000020,0x000000e4,0x000000e2,0x000000e3,0x0004003d, + 0x00000020,0x000000e5,0x00000057,0x00050081,0x00000020,0x000000e6,0x000000e4,0x000000e5, + 0x0004003d,0x00000020,0x000000e7,0x000000d2,0x00050085,0x00000020,0x000000e8,0x000000e6, + 0x000000e7,0x00060050,0x00000020,0x000000e9,0x00000039,0x00000039,0x00000039,0x00060050, + 0x00000020,0x000000ea,0x0000000e,0x0000000e,0x0000000e,0x0008000c,0x00000020,0x000000eb, + 0x00000001,0x0000002b,0x000000e8,0x000000e9,0x000000ea,0x0003003e,0x000000e1,0x000000eb, + 0x0004003d,0x00000020,0x000000ee,0x000000e1,0x00050051,0x00000006,0x000000ef,0x000000ee, + 0x00000000,0x00050051,0x00000006,0x000000f0,0x000000ee,0x00000001,0x00050051,0x00000006, + 0x000000f1,0x000000ee,0x00000002,0x00070050,0x0000000f,0x000000f2,0x000000ef,0x000000f0, + 0x000000f1,0x0000000e,0x0003003e,0x000000ed,0x000000f2,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/color_frag.h b/app/src/main/cpp/shaders/color_frag.h new file mode 100644 index 0000000000..bde543ab47 --- /dev/null +++ b/app/src/main/cpp/shaders/color_frag.h @@ -0,0 +1,76 @@ + // 1116.5.0 + #pragma once +const uint32_t color_code[] = { + 0x07230203,0x00010000,0x0008000b,0x00000059,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000011,0x0000004e,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00050005,0x00000009,0x65786574,0x6c6f436c,0x0000726f,0x00060005,0x0000000d, + 0x75706e49,0x78655474,0x65727574,0x00000000,0x00060005,0x00000011,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00040005,0x00000016,0x6f6c6f63,0x00000072,0x00030005,0x0000001a, + 0x00004350,0x00040006,0x0000001a,0x00000000,0x0063646e,0x00060006,0x0000001a,0x00000001, + 0x67697262,0x656e7468,0x00007373,0x00060006,0x0000001a,0x00000002,0x746e6f63,0x74736172, + 0x00000000,0x00050006,0x0000001a,0x00000003,0x6d6d6167,0x00000061,0x00060006,0x0000001a, + 0x00000004,0x75746173,0x69746172,0x00006e6f,0x00030005,0x0000001c,0x00006370,0x00040005, + 0x00000036,0x79657267,0x00000000,0x00050005,0x0000004e,0x4374756f,0x726f6c6f,0x00000000, + 0x00040047,0x0000000d,0x00000021,0x00000000,0x00040047,0x0000000d,0x00000022,0x00000000, + 0x00040047,0x00000011,0x0000001e,0x00000000,0x00030047,0x0000001a,0x00000002,0x00050048, + 0x0000001a,0x00000000,0x00000023,0x00000000,0x00050048,0x0000001a,0x00000001,0x00000023, + 0x00000010,0x00050048,0x0000001a,0x00000002,0x00000023,0x00000014,0x00050048,0x0000001a, + 0x00000003,0x00000023,0x00000018,0x00050048,0x0000001a,0x00000004,0x00000023,0x0000001c, + 0x00040047,0x0000004e,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003, + 0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004, + 0x00040020,0x00000008,0x00000007,0x00000007,0x00090019,0x0000000a,0x00000006,0x00000001, + 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x0000000b,0x0000000a, + 0x00040020,0x0000000c,0x00000000,0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000000, + 0x00040017,0x0000000f,0x00000006,0x00000002,0x00040020,0x00000010,0x00000001,0x0000000f, + 0x0004003b,0x00000010,0x00000011,0x00000001,0x00040017,0x00000014,0x00000006,0x00000003, + 0x00040020,0x00000015,0x00000007,0x00000014,0x0007001e,0x0000001a,0x00000007,0x00000006, + 0x00000006,0x00000006,0x00000006,0x00040020,0x0000001b,0x00000009,0x0000001a,0x0004003b, + 0x0000001b,0x0000001c,0x00000009,0x00040015,0x0000001d,0x00000020,0x00000001,0x0004002b, + 0x0000001d,0x0000001e,0x00000001,0x00040020,0x0000001f,0x00000009,0x00000006,0x0004002b, + 0x00000006,0x00000024,0x00000000,0x0004002b,0x00000006,0x00000025,0x3f800000,0x0004002b, + 0x00000006,0x0000002a,0x3f000000,0x0004002b,0x0000001d,0x0000002d,0x00000002,0x0004002b, + 0x00000006,0x00000031,0x40000000,0x0004002b,0x00000006,0x00000038,0x3e59b3d0,0x0004002b, + 0x00000006,0x00000039,0x3f371759,0x0004002b,0x00000006,0x0000003a,0x3d93dd98,0x0006002c, + 0x00000014,0x0000003b,0x00000038,0x00000039,0x0000003a,0x0004002b,0x0000001d,0x00000040, + 0x00000004,0x0004002b,0x0000001d,0x00000047,0x00000003,0x00040020,0x0000004d,0x00000003, + 0x00000007,0x0004003b,0x0000004d,0x0000004e,0x00000003,0x00040015,0x00000050,0x00000020, + 0x00000000,0x0004002b,0x00000050,0x00000051,0x00000003,0x00040020,0x00000052,0x00000007, + 0x00000006,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005, + 0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x00000015,0x00000016,0x00000007, + 0x0004003b,0x00000015,0x00000036,0x00000007,0x0004003d,0x0000000b,0x0000000e,0x0000000d, + 0x0004003d,0x0000000f,0x00000012,0x00000011,0x00050057,0x00000007,0x00000013,0x0000000e, + 0x00000012,0x0003003e,0x00000009,0x00000013,0x0004003d,0x00000007,0x00000017,0x00000009, + 0x0008004f,0x00000014,0x00000018,0x00000017,0x00000017,0x00000000,0x00000001,0x00000002, + 0x0003003e,0x00000016,0x00000018,0x0004003d,0x00000014,0x00000019,0x00000016,0x00050041, + 0x0000001f,0x00000020,0x0000001c,0x0000001e,0x0004003d,0x00000006,0x00000021,0x00000020, + 0x00060050,0x00000014,0x00000022,0x00000021,0x00000021,0x00000021,0x00050081,0x00000014, + 0x00000023,0x00000019,0x00000022,0x00060050,0x00000014,0x00000026,0x00000024,0x00000024, + 0x00000024,0x00060050,0x00000014,0x00000027,0x00000025,0x00000025,0x00000025,0x0008000c, + 0x00000014,0x00000028,0x00000001,0x0000002b,0x00000023,0x00000026,0x00000027,0x0003003e, + 0x00000016,0x00000028,0x0004003d,0x00000014,0x00000029,0x00000016,0x00060050,0x00000014, + 0x0000002b,0x0000002a,0x0000002a,0x0000002a,0x00050083,0x00000014,0x0000002c,0x00000029, + 0x0000002b,0x00050041,0x0000001f,0x0000002e,0x0000001c,0x0000002d,0x0004003d,0x00000006, + 0x0000002f,0x0000002e,0x00050081,0x00000006,0x00000030,0x0000002f,0x00000025,0x0008000c, + 0x00000006,0x00000032,0x00000001,0x0000002b,0x00000030,0x0000002a,0x00000031,0x0005008e, + 0x00000014,0x00000033,0x0000002c,0x00000032,0x00060050,0x00000014,0x00000034,0x0000002a, + 0x0000002a,0x0000002a,0x00050081,0x00000014,0x00000035,0x00000033,0x00000034,0x0003003e, + 0x00000016,0x00000035,0x0004003d,0x00000014,0x00000037,0x00000016,0x00050094,0x00000006, + 0x0000003c,0x00000037,0x0000003b,0x00060050,0x00000014,0x0000003d,0x0000003c,0x0000003c, + 0x0000003c,0x0003003e,0x00000036,0x0000003d,0x0004003d,0x00000014,0x0000003e,0x00000036, + 0x0004003d,0x00000014,0x0000003f,0x00000016,0x00050041,0x0000001f,0x00000041,0x0000001c, + 0x00000040,0x0004003d,0x00000006,0x00000042,0x00000041,0x0008000c,0x00000006,0x00000043, + 0x00000001,0x0000002b,0x00000042,0x00000024,0x00000031,0x00060050,0x00000014,0x00000044, + 0x00000043,0x00000043,0x00000043,0x0008000c,0x00000014,0x00000045,0x00000001,0x0000002e, + 0x0000003e,0x0000003f,0x00000044,0x0003003e,0x00000016,0x00000045,0x0004003d,0x00000014, + 0x00000046,0x00000016,0x00050041,0x0000001f,0x00000048,0x0000001c,0x00000047,0x0004003d, + 0x00000006,0x00000049,0x00000048,0x00050088,0x00000006,0x0000004a,0x00000025,0x00000049, + 0x00060050,0x00000014,0x0000004b,0x0000004a,0x0000004a,0x0000004a,0x0007000c,0x00000014, + 0x0000004c,0x00000001,0x0000001a,0x00000046,0x0000004b,0x0003003e,0x00000016,0x0000004c, + 0x0004003d,0x00000014,0x0000004f,0x00000016,0x00050041,0x00000052,0x00000053,0x00000009, + 0x00000051,0x0004003d,0x00000006,0x00000054,0x00000053,0x00050051,0x00000006,0x00000055, + 0x0000004f,0x00000000,0x00050051,0x00000006,0x00000056,0x0000004f,0x00000001,0x00050051, + 0x00000006,0x00000057,0x0000004f,0x00000002,0x00070050,0x00000007,0x00000058,0x00000055, + 0x00000056,0x00000057,0x00000054,0x0003003e,0x0000004e,0x00000058,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/crt_frag.h b/app/src/main/cpp/shaders/crt_frag.h new file mode 100644 index 0000000000..2239f22748 --- /dev/null +++ b/app/src/main/cpp/shaders/crt_frag.h @@ -0,0 +1,78 @@ + // 1116.2.0 + #pragma once +const uint32_t crt_code[] = { + 0x07230203,0x00010000,0x0008000b,0x00000063,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000004f,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00030005,0x00000009,0x00565576,0x00060005,0x0000000b,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00050005,0x0000000f,0x616e6966,0x6c6f436c,0x0000726f,0x00060005, + 0x00000013,0x75706e49,0x78655474,0x65727574,0x00000000,0x00050005,0x0000003b,0x6e616373, + 0x656e696c,0x00000058,0x00050005,0x00000045,0x6e616373,0x656e696c,0x00000059,0x00050005, + 0x0000004f,0x4374756f,0x726f6c6f,0x00000000,0x00030005,0x00000060,0x00004350,0x00040006, + 0x00000060,0x00000000,0x0063646e,0x00060006,0x00000060,0x00000001,0x6f736572,0x6974756c, + 0x00006e6f,0x00030005,0x00000062,0x00006370,0x00040047,0x0000000b,0x0000001e,0x00000000, + 0x00040047,0x00000013,0x00000021,0x00000000,0x00040047,0x00000013,0x00000022,0x00000000, + 0x00040047,0x0000004f,0x0000001e,0x00000000,0x00030047,0x00000060,0x00000002,0x00050048, + 0x00000060,0x00000000,0x00000023,0x00000000,0x00050048,0x00000060,0x00000001,0x00000023, + 0x00000010,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006, + 0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007, + 0x00000007,0x00040020,0x0000000a,0x00000001,0x00000007,0x0004003b,0x0000000a,0x0000000b, + 0x00000001,0x00040017,0x0000000d,0x00000006,0x00000004,0x00040020,0x0000000e,0x00000007, + 0x0000000d,0x00090019,0x00000010,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, + 0x00000001,0x00000000,0x0003001b,0x00000011,0x00000010,0x00040020,0x00000012,0x00000000, + 0x00000011,0x0004003b,0x00000012,0x00000013,0x00000000,0x0004002b,0x00000006,0x00000019, + 0x3f000000,0x0004002b,0x00000006,0x0000001c,0x3f8051ec,0x00040015,0x00000021,0x00000020, + 0x00000000,0x0004002b,0x00000021,0x00000022,0x00000000,0x0004002b,0x00000021,0x00000024, + 0x00000001,0x00040020,0x00000025,0x00000007,0x00000006,0x0004002b,0x00000021,0x00000031, + 0x00000002,0x00040017,0x00000033,0x00000006,0x00000003,0x0004002b,0x00000006,0x0000003e, + 0x44800000,0x0004002b,0x00000006,0x00000042,0x3e000000,0x0004002b,0x00000006,0x0000004b, + 0x3ec00000,0x00040020,0x0000004e,0x00000003,0x0000000d,0x0004003b,0x0000004e,0x0000004f, + 0x00000003,0x0004002b,0x00000006,0x00000052,0x00000000,0x0006002c,0x00000033,0x00000053, + 0x00000052,0x00000052,0x00000052,0x0004002b,0x00000021,0x00000059,0x00000003,0x0004001e, + 0x00000060,0x0000000d,0x00000007,0x00040020,0x00000061,0x00000009,0x00000060,0x0004003b, + 0x00000061,0x00000062,0x00000009,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003, + 0x000200f8,0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x0000000e, + 0x0000000f,0x00000007,0x0004003b,0x00000025,0x0000003b,0x00000007,0x0004003b,0x00000025, + 0x00000045,0x00000007,0x0004003d,0x00000007,0x0000000c,0x0000000b,0x0003003e,0x00000009, + 0x0000000c,0x0004003d,0x00000011,0x00000014,0x00000013,0x0004003d,0x00000007,0x00000015, + 0x00000009,0x00050057,0x0000000d,0x00000016,0x00000014,0x00000015,0x0003003e,0x0000000f, + 0x00000016,0x0004003d,0x00000011,0x00000017,0x00000013,0x0004003d,0x00000007,0x00000018, + 0x00000009,0x00050050,0x00000007,0x0000001a,0x00000019,0x00000019,0x00050083,0x00000007, + 0x0000001b,0x00000018,0x0000001a,0x0005008e,0x00000007,0x0000001d,0x0000001b,0x0000001c, + 0x00050050,0x00000007,0x0000001e,0x00000019,0x00000019,0x00050081,0x00000007,0x0000001f, + 0x0000001d,0x0000001e,0x00050057,0x0000000d,0x00000020,0x00000017,0x0000001f,0x00050051, + 0x00000006,0x00000023,0x00000020,0x00000000,0x00050041,0x00000025,0x00000026,0x0000000f, + 0x00000024,0x0004003d,0x00000006,0x00000027,0x00000026,0x0004003d,0x00000011,0x00000028, + 0x00000013,0x0004003d,0x00000007,0x00000029,0x00000009,0x00050050,0x00000007,0x0000002a, + 0x00000019,0x00000019,0x00050083,0x00000007,0x0000002b,0x00000029,0x0000002a,0x00050050, + 0x00000007,0x0000002c,0x0000001c,0x0000001c,0x00050088,0x00000007,0x0000002d,0x0000002b, + 0x0000002c,0x00050050,0x00000007,0x0000002e,0x00000019,0x00000019,0x00050081,0x00000007, + 0x0000002f,0x0000002d,0x0000002e,0x00050057,0x0000000d,0x00000030,0x00000028,0x0000002f, + 0x00050051,0x00000006,0x00000032,0x00000030,0x00000002,0x00060050,0x00000033,0x00000034, + 0x00000023,0x00000027,0x00000032,0x00050041,0x00000025,0x00000035,0x0000000f,0x00000022, + 0x00050051,0x00000006,0x00000036,0x00000034,0x00000000,0x0003003e,0x00000035,0x00000036, + 0x00050041,0x00000025,0x00000037,0x0000000f,0x00000024,0x00050051,0x00000006,0x00000038, + 0x00000034,0x00000001,0x0003003e,0x00000037,0x00000038,0x00050041,0x00000025,0x00000039, + 0x0000000f,0x00000031,0x00050051,0x00000006,0x0000003a,0x00000034,0x00000002,0x0003003e, + 0x00000039,0x0000003a,0x00050041,0x00000025,0x0000003c,0x00000009,0x00000022,0x0004003d, + 0x00000006,0x0000003d,0x0000003c,0x00050085,0x00000006,0x0000003f,0x0000003d,0x0000003e, + 0x0006000c,0x00000006,0x00000040,0x00000001,0x0000000d,0x0000003f,0x00050085,0x00000006, + 0x00000041,0x00000040,0x00000019,0x00050085,0x00000006,0x00000043,0x00000041,0x00000042, + 0x0006000c,0x00000006,0x00000044,0x00000001,0x00000004,0x00000043,0x0003003e,0x0000003b, + 0x00000044,0x00050041,0x00000025,0x00000046,0x00000009,0x00000024,0x0004003d,0x00000006, + 0x00000047,0x00000046,0x00050085,0x00000006,0x00000048,0x00000047,0x0000003e,0x0006000c, + 0x00000006,0x00000049,0x00000001,0x0000000d,0x00000048,0x00050085,0x00000006,0x0000004a, + 0x00000049,0x00000019,0x00050085,0x00000006,0x0000004c,0x0000004a,0x0000004b,0x0006000c, + 0x00000006,0x0000004d,0x00000001,0x00000004,0x0000004c,0x0003003e,0x00000045,0x0000004d, + 0x0004003d,0x0000000d,0x00000050,0x0000000f,0x0008004f,0x00000033,0x00000051,0x00000050, + 0x00000050,0x00000000,0x00000001,0x00000002,0x0004003d,0x00000006,0x00000054,0x0000003b, + 0x0004003d,0x00000006,0x00000055,0x00000045,0x00050081,0x00000006,0x00000056,0x00000054, + 0x00000055,0x00060050,0x00000033,0x00000057,0x00000056,0x00000056,0x00000056,0x0008000c, + 0x00000033,0x00000058,0x00000001,0x0000002e,0x00000051,0x00000053,0x00000057,0x00050041, + 0x00000025,0x0000005a,0x0000000f,0x00000059,0x0004003d,0x00000006,0x0000005b,0x0000005a, + 0x00050051,0x00000006,0x0000005c,0x00000058,0x00000000,0x00050051,0x00000006,0x0000005d, + 0x00000058,0x00000001,0x00050051,0x00000006,0x0000005e,0x00000058,0x00000002,0x00070050, + 0x0000000d,0x0000005f,0x0000005c,0x0000005d,0x0000005e,0x0000005b,0x0003003e,0x0000004f, + 0x0000005f,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/fsr_easu_frag.h b/app/src/main/cpp/shaders/fsr_easu_frag.h new file mode 100644 index 0000000000..eb6d36af4c --- /dev/null +++ b/app/src/main/cpp/shaders/fsr_easu_frag.h @@ -0,0 +1,907 @@ + // 1116.2.0 + #pragma once +const uint32_t fsr_easu_code[] = { + 0x07230203,0x00010000,0x0008000b,0x0000046e,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000447,0x00000468,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00050005,0x0000000a,0x70635241,0x66283146,0x00003b31,0x00030005,0x00000009, + 0x00000078,0x00060005,0x0000000d,0x78725041,0x63526f4c,0x28314670,0x003b3166,0x00030005, + 0x0000000c,0x00000078,0x00060005,0x00000010,0x78725041,0x73526f4c,0x28314671,0x003b3166, + 0x00030005,0x0000000f,0x00000078,0x00050005,0x00000013,0x74615341,0x66283146,0x00003b31, + 0x00030005,0x00000012,0x00000078,0x00080005,0x0000001b,0x6e694d41,0x28334633,0x3b336676, + 0x3b336676,0x3b336676,0x00000000,0x00030005,0x00000018,0x00000061,0x00030005,0x00000019, + 0x00000062,0x00030005,0x0000001a,0x00000063,0x00080005,0x00000020,0x78614d41,0x28334633, + 0x3b336676,0x3b336676,0x3b336676,0x00000000,0x00030005,0x0000001d,0x00000061,0x00030005, + 0x0000001e,0x00000062,0x00030005,0x0000001f,0x00000063,0x00060005,0x00000027,0x45727346, + 0x52757361,0x66762846,0x00003b32,0x00030005,0x00000026,0x00000070,0x00060005,0x0000002a, + 0x45727346,0x47757361,0x66762846,0x00003b32,0x00030005,0x00000029,0x00000070,0x00060005, + 0x0000002d,0x45727346,0x42757361,0x66762846,0x00003b32,0x00030005,0x0000002c,0x00000070, + 0x000d0005,0x00000038,0x45727346,0x54757361,0x28467061,0x3b336676,0x763b3166,0x763b3266, + 0x763b3266,0x663b3266,0x31663b31,0x3366763b,0x0000003b,0x00030005,0x00000030,0x00004361, + 0x00030005,0x00000031,0x00005761,0x00030005,0x00000032,0x0066666f,0x00030005,0x00000033, + 0x00726964,0x00030005,0x00000034,0x006e656c,0x00030005,0x00000035,0x00626f6c,0x00030005, + 0x00000036,0x00706c63,0x00030005,0x00000037,0x00000063,0x000f0005,0x00000049,0x45727346, + 0x53757361,0x28467465,0x3b326676,0x763b3166,0x623b3266,0x31623b31,0x3b31623b,0x663b3162, + 0x31663b31,0x3b31663b,0x663b3166,0x00003b31,0x00030005,0x0000003d,0x00726964,0x00030005, + 0x0000003e,0x006e656c,0x00030005,0x0000003f,0x00007070,0x00030005,0x00000040,0x00536962, + 0x00030005,0x00000041,0x00546962,0x00030005,0x00000042,0x00556962,0x00030005,0x00000043, + 0x00566962,0x00030005,0x00000044,0x0000416c,0x00030005,0x00000045,0x0000426c,0x00030005, + 0x00000046,0x0000436c,0x00030005,0x00000047,0x0000446c,0x00030005,0x00000048,0x0000456c, + 0x000b0005,0x00000057,0x45727346,0x46757361,0x33667628,0x3275763b,0x3475763b,0x3475763b, + 0x3475763b,0x3475763b,0x0000003b,0x00030005,0x00000051,0x00786970,0x00030005,0x00000052, + 0x00007069,0x00040005,0x00000053,0x306e6f63,0x00000000,0x00040005,0x00000054,0x316e6f63, + 0x00000000,0x00040005,0x00000055,0x326e6f63,0x00000000,0x00040005,0x00000056,0x336e6f63, + 0x00000000,0x00060005,0x0000007c,0x75706e49,0x78655474,0x65727574,0x00000000,0x00030005, + 0x00000090,0x00000076,0x00030005,0x000000af,0x00003264,0x00030005,0x000000be,0x00004277, + 0x00030005,0x000000c4,0x00004177,0x00030005,0x000000d4,0x00000077,0x00030005,0x000000e0, + 0x00000077,0x00030005,0x00000105,0x00006364,0x00030005,0x00000109,0x00006263,0x00040005, + 0x0000010d,0x586e656c,0x00000000,0x00040005,0x00000113,0x61726170,0x0000006d,0x00040005, + 0x00000116,0x58726964,0x00000000,0x00040005,0x00000125,0x61726170,0x0000006d,0x00030005, + 0x0000012f,0x00006365,0x00030005,0x00000133,0x00006163,0x00040005,0x00000137,0x596e656c, + 0x00000000,0x00040005,0x0000013d,0x61726170,0x0000006d,0x00040005,0x00000140,0x59726964, + 0x00000000,0x00040005,0x0000014f,0x61726170,0x0000006d,0x00030005,0x00000159,0x00007070, + 0x00030005,0x00000164,0x00007066,0x00030005,0x0000016a,0x00003070,0x00030005,0x00000174, + 0x00003170,0x00030005,0x0000017a,0x00003270,0x00030005,0x00000180,0x00003370,0x00040005, + 0x00000187,0x7a7a6362,0x00000052,0x00040005,0x00000188,0x61726170,0x0000006d,0x00040005, + 0x0000018b,0x7a7a6362,0x00000047,0x00040005,0x0000018c,0x61726170,0x0000006d,0x00040005, + 0x0000018f,0x7a7a6362,0x00000042,0x00040005,0x00000190,0x61726170,0x0000006d,0x00040005, + 0x00000193,0x65666a69,0x00000052,0x00040005,0x00000194,0x61726170,0x0000006d,0x00040005, + 0x00000197,0x65666a69,0x00000047,0x00040005,0x00000198,0x61726170,0x0000006d,0x00040005, + 0x0000019b,0x65666a69,0x00000042,0x00040005,0x0000019c,0x61726170,0x0000006d,0x00040005, + 0x0000019f,0x67686c6b,0x00000052,0x00040005,0x000001a0,0x61726170,0x0000006d,0x00040005, + 0x000001a3,0x67686c6b,0x00000047,0x00040005,0x000001a4,0x61726170,0x0000006d,0x00040005, + 0x000001a7,0x67686c6b,0x00000042,0x00040005,0x000001a8,0x61726170,0x0000006d,0x00040005, + 0x000001ab,0x6e6f7a7a,0x00000052,0x00040005,0x000001ac,0x61726170,0x0000006d,0x00040005, + 0x000001af,0x6e6f7a7a,0x00000047,0x00040005,0x000001b0,0x61726170,0x0000006d,0x00040005, + 0x000001b3,0x6e6f7a7a,0x00000042,0x00040005,0x000001b4,0x61726170,0x0000006d,0x00040005, + 0x000001b7,0x7a7a6362,0x0000004c,0x00040005,0x000001c1,0x65666a69,0x0000004c,0x00040005, + 0x000001c9,0x67686c6b,0x0000004c,0x00040005,0x000001d1,0x6e6f7a7a,0x0000004c,0x00030005, + 0x000001d9,0x00004c62,0x00030005,0x000001dc,0x00004c63,0x00030005,0x000001df,0x00004c69, + 0x00030005,0x000001e2,0x00004c6a,0x00030005,0x000001e5,0x00004c66,0x00030005,0x000001e9, + 0x00004c65,0x00030005,0x000001ed,0x00004c6b,0x00030005,0x000001f0,0x00004c6c,0x00030005, + 0x000001f3,0x00004c68,0x00030005,0x000001f6,0x00004c67,0x00030005,0x000001f9,0x00004c6f, + 0x00030005,0x000001fc,0x00004c6e,0x00030005,0x000001ff,0x00726964,0x00030005,0x00000201, + 0x006e656c,0x00040005,0x00000204,0x61726170,0x0000006d,0x00040005,0x00000206,0x61726170, + 0x0000006d,0x00040005,0x00000208,0x61726170,0x0000006d,0x00040005,0x0000020a,0x61726170, + 0x0000006d,0x00040005,0x0000020b,0x61726170,0x0000006d,0x00040005,0x0000020c,0x61726170, + 0x0000006d,0x00040005,0x0000020d,0x61726170,0x0000006d,0x00040005,0x0000020e,0x61726170, + 0x0000006d,0x00040005,0x00000210,0x61726170,0x0000006d,0x00040005,0x00000212,0x61726170, + 0x0000006d,0x00040005,0x00000214,0x61726170,0x0000006d,0x00040005,0x00000216,0x61726170, + 0x0000006d,0x00040005,0x0000021b,0x61726170,0x0000006d,0x00040005,0x0000021d,0x61726170, + 0x0000006d,0x00040005,0x0000021f,0x61726170,0x0000006d,0x00040005,0x00000221,0x61726170, + 0x0000006d,0x00040005,0x00000222,0x61726170,0x0000006d,0x00040005,0x00000223,0x61726170, + 0x0000006d,0x00040005,0x00000224,0x61726170,0x0000006d,0x00040005,0x00000225,0x61726170, + 0x0000006d,0x00040005,0x00000227,0x61726170,0x0000006d,0x00040005,0x00000229,0x61726170, + 0x0000006d,0x00040005,0x0000022b,0x61726170,0x0000006d,0x00040005,0x0000022d,0x61726170, + 0x0000006d,0x00040005,0x00000232,0x61726170,0x0000006d,0x00040005,0x00000234,0x61726170, + 0x0000006d,0x00040005,0x00000236,0x61726170,0x0000006d,0x00040005,0x00000238,0x61726170, + 0x0000006d,0x00040005,0x00000239,0x61726170,0x0000006d,0x00040005,0x0000023a,0x61726170, + 0x0000006d,0x00040005,0x0000023b,0x61726170,0x0000006d,0x00040005,0x0000023c,0x61726170, + 0x0000006d,0x00040005,0x0000023e,0x61726170,0x0000006d,0x00040005,0x00000240,0x61726170, + 0x0000006d,0x00040005,0x00000242,0x61726170,0x0000006d,0x00040005,0x00000244,0x61726170, + 0x0000006d,0x00040005,0x00000249,0x61726170,0x0000006d,0x00040005,0x0000024b,0x61726170, + 0x0000006d,0x00040005,0x0000024d,0x61726170,0x0000006d,0x00040005,0x0000024f,0x61726170, + 0x0000006d,0x00040005,0x00000250,0x61726170,0x0000006d,0x00040005,0x00000251,0x61726170, + 0x0000006d,0x00040005,0x00000252,0x61726170,0x0000006d,0x00040005,0x00000253,0x61726170, + 0x0000006d,0x00040005,0x00000255,0x61726170,0x0000006d,0x00040005,0x00000257,0x61726170, + 0x0000006d,0x00040005,0x00000259,0x61726170,0x0000006d,0x00040005,0x0000025b,0x61726170, + 0x0000006d,0x00040005,0x00000260,0x32726964,0x00000000,0x00040005,0x00000264,0x52726964, + 0x00000000,0x00030005,0x0000026a,0x006f727a,0x00040005,0x0000026e,0x61726170,0x0000006d, + 0x00040005,0x00000286,0x65727473,0x00686374,0x00040005,0x00000299,0x61726170,0x0000006d, + 0x00040005,0x0000029c,0x326e656c,0x00000000,0x00030005,0x000002a7,0x00626f6c,0x00030005, + 0x000002ac,0x00706c63,0x00040005,0x000002ad,0x61726170,0x0000006d,0x00040005,0x000002b0, + 0x346e696d,0x00000000,0x00040005,0x000002c6,0x61726170,0x0000006d,0x00040005,0x000002c7, + 0x61726170,0x0000006d,0x00040005,0x000002c8,0x61726170,0x0000006d,0x00040005,0x000002d2, + 0x3478616d,0x00000000,0x00040005,0x000002e8,0x61726170,0x0000006d,0x00040005,0x000002e9, + 0x61726170,0x0000006d,0x00040005,0x000002ea,0x61726170,0x0000006d,0x00030005,0x000002f4, + 0x00004361,0x00030005,0x000002f6,0x00005761,0x00040005,0x00000301,0x61726170,0x0000006d, + 0x00040005,0x00000303,0x61726170,0x0000006d,0x00040005,0x00000305,0x61726170,0x0000006d, + 0x00040005,0x00000306,0x61726170,0x0000006d,0x00040005,0x00000308,0x61726170,0x0000006d, + 0x00040005,0x0000030a,0x61726170,0x0000006d,0x00040005,0x0000030c,0x61726170,0x0000006d, + 0x00040005,0x0000030e,0x61726170,0x0000006d,0x00040005,0x0000031c,0x61726170,0x0000006d, + 0x00040005,0x0000031e,0x61726170,0x0000006d,0x00040005,0x00000320,0x61726170,0x0000006d, + 0x00040005,0x00000321,0x61726170,0x0000006d,0x00040005,0x00000323,0x61726170,0x0000006d, + 0x00040005,0x00000325,0x61726170,0x0000006d,0x00040005,0x00000327,0x61726170,0x0000006d, + 0x00040005,0x00000329,0x61726170,0x0000006d,0x00040005,0x00000337,0x61726170,0x0000006d, + 0x00040005,0x00000339,0x61726170,0x0000006d,0x00040005,0x0000033b,0x61726170,0x0000006d, + 0x00040005,0x0000033c,0x61726170,0x0000006d,0x00040005,0x0000033e,0x61726170,0x0000006d, + 0x00040005,0x00000340,0x61726170,0x0000006d,0x00040005,0x00000342,0x61726170,0x0000006d, + 0x00040005,0x00000344,0x61726170,0x0000006d,0x00040005,0x00000352,0x61726170,0x0000006d, + 0x00040005,0x00000354,0x61726170,0x0000006d,0x00040005,0x00000356,0x61726170,0x0000006d, + 0x00040005,0x00000357,0x61726170,0x0000006d,0x00040005,0x00000359,0x61726170,0x0000006d, + 0x00040005,0x0000035b,0x61726170,0x0000006d,0x00040005,0x0000035d,0x61726170,0x0000006d, + 0x00040005,0x0000035f,0x61726170,0x0000006d,0x00040005,0x0000036c,0x61726170,0x0000006d, + 0x00040005,0x0000036e,0x61726170,0x0000006d,0x00040005,0x00000370,0x61726170,0x0000006d, + 0x00040005,0x00000371,0x61726170,0x0000006d,0x00040005,0x00000373,0x61726170,0x0000006d, + 0x00040005,0x00000375,0x61726170,0x0000006d,0x00040005,0x00000377,0x61726170,0x0000006d, + 0x00040005,0x00000379,0x61726170,0x0000006d,0x00040005,0x00000387,0x61726170,0x0000006d, + 0x00040005,0x00000389,0x61726170,0x0000006d,0x00040005,0x0000038b,0x61726170,0x0000006d, + 0x00040005,0x0000038c,0x61726170,0x0000006d,0x00040005,0x0000038e,0x61726170,0x0000006d, + 0x00040005,0x00000390,0x61726170,0x0000006d,0x00040005,0x00000392,0x61726170,0x0000006d, + 0x00040005,0x00000394,0x61726170,0x0000006d,0x00040005,0x000003a2,0x61726170,0x0000006d, + 0x00040005,0x000003a4,0x61726170,0x0000006d,0x00040005,0x000003a6,0x61726170,0x0000006d, + 0x00040005,0x000003a7,0x61726170,0x0000006d,0x00040005,0x000003a9,0x61726170,0x0000006d, + 0x00040005,0x000003ab,0x61726170,0x0000006d,0x00040005,0x000003ad,0x61726170,0x0000006d, + 0x00040005,0x000003af,0x61726170,0x0000006d,0x00040005,0x000003be,0x61726170,0x0000006d, + 0x00040005,0x000003c0,0x61726170,0x0000006d,0x00040005,0x000003c2,0x61726170,0x0000006d, + 0x00040005,0x000003c3,0x61726170,0x0000006d,0x00040005,0x000003c5,0x61726170,0x0000006d, + 0x00040005,0x000003c7,0x61726170,0x0000006d,0x00040005,0x000003c9,0x61726170,0x0000006d, + 0x00040005,0x000003cb,0x61726170,0x0000006d,0x00040005,0x000003d9,0x61726170,0x0000006d, + 0x00040005,0x000003db,0x61726170,0x0000006d,0x00040005,0x000003dd,0x61726170,0x0000006d, + 0x00040005,0x000003de,0x61726170,0x0000006d,0x00040005,0x000003e0,0x61726170,0x0000006d, + 0x00040005,0x000003e2,0x61726170,0x0000006d,0x00040005,0x000003e4,0x61726170,0x0000006d, + 0x00040005,0x000003e6,0x61726170,0x0000006d,0x00040005,0x000003f4,0x61726170,0x0000006d, + 0x00040005,0x000003f6,0x61726170,0x0000006d,0x00040005,0x000003f8,0x61726170,0x0000006d, + 0x00040005,0x000003f9,0x61726170,0x0000006d,0x00040005,0x000003fb,0x61726170,0x0000006d, + 0x00040005,0x000003fd,0x61726170,0x0000006d,0x00040005,0x000003ff,0x61726170,0x0000006d, + 0x00040005,0x00000401,0x61726170,0x0000006d,0x00040005,0x0000040f,0x61726170,0x0000006d, + 0x00040005,0x00000411,0x61726170,0x0000006d,0x00040005,0x00000413,0x61726170,0x0000006d, + 0x00040005,0x00000414,0x61726170,0x0000006d,0x00040005,0x00000416,0x61726170,0x0000006d, + 0x00040005,0x00000418,0x61726170,0x0000006d,0x00040005,0x0000041a,0x61726170,0x0000006d, + 0x00040005,0x0000041c,0x61726170,0x0000006d,0x00040005,0x0000042a,0x61726170,0x0000006d, + 0x00040005,0x0000042c,0x61726170,0x0000006d,0x00040005,0x0000042e,0x61726170,0x0000006d, + 0x00040005,0x0000042f,0x61726170,0x0000006d,0x00040005,0x00000431,0x61726170,0x0000006d, + 0x00040005,0x00000433,0x61726170,0x0000006d,0x00040005,0x00000435,0x61726170,0x0000006d, + 0x00040005,0x00000437,0x61726170,0x0000006d,0x00040005,0x0000043e,0x61726170,0x0000006d, + 0x00030005,0x00000445,0x00007069,0x00060005,0x00000447,0x67617266,0x43786554,0x64726f6f, + 0x00000000,0x00030005,0x00000449,0x00004350,0x00040006,0x00000449,0x00000000,0x0063646e, + 0x00050006,0x00000449,0x00000001,0x306e6f63,0x00000000,0x00050006,0x00000449,0x00000002, + 0x316e6f63,0x00000000,0x00050006,0x00000449,0x00000003,0x326e6f63,0x00000000,0x00050006, + 0x00000449,0x00000004,0x336e6f63,0x00000000,0x00060006,0x00000449,0x00000005,0x7074756f, + 0x69537475,0x0000657a,0x00030005,0x0000044b,0x00006370,0x00030005,0x00000452,0x00000063, + 0x00040005,0x00000455,0x61726170,0x0000006d,0x00040005,0x00000456,0x61726170,0x0000006d, + 0x00040005,0x00000458,0x61726170,0x0000006d,0x00040005,0x0000045c,0x61726170,0x0000006d, + 0x00040005,0x0000045f,0x61726170,0x0000006d,0x00040005,0x00000462,0x61726170,0x0000006d, + 0x00050005,0x00000468,0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x0000007c,0x00000021, + 0x00000000,0x00040047,0x0000007c,0x00000022,0x00000000,0x00040047,0x00000447,0x0000001e, + 0x00000000,0x00030047,0x00000449,0x00000002,0x00050048,0x00000449,0x00000000,0x00000023, + 0x00000000,0x00050048,0x00000449,0x00000001,0x00000023,0x00000010,0x00050048,0x00000449, + 0x00000002,0x00000023,0x00000020,0x00050048,0x00000449,0x00000003,0x00000023,0x00000030, + 0x00050048,0x00000449,0x00000004,0x00000023,0x00000040,0x00050048,0x00000449,0x00000005, + 0x00000023,0x00000050,0x00040047,0x00000468,0x0000001e,0x00000000,0x00020013,0x00000002, + 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040020,0x00000007, + 0x00000007,0x00000006,0x00040021,0x00000008,0x00000006,0x00000007,0x00040017,0x00000015, + 0x00000006,0x00000003,0x00040020,0x00000016,0x00000007,0x00000015,0x00060021,0x00000017, + 0x00000015,0x00000016,0x00000016,0x00000016,0x00040017,0x00000022,0x00000006,0x00000002, + 0x00040020,0x00000023,0x00000007,0x00000022,0x00040017,0x00000024,0x00000006,0x00000004, + 0x00040021,0x00000025,0x00000024,0x00000023,0x000b0021,0x0000002f,0x00000002,0x00000016, + 0x00000007,0x00000023,0x00000023,0x00000023,0x00000007,0x00000007,0x00000016,0x00020014, + 0x0000003a,0x00040020,0x0000003b,0x00000007,0x0000003a,0x000f0021,0x0000003c,0x00000002, + 0x00000023,0x00000007,0x00000023,0x0000003b,0x0000003b,0x0000003b,0x0000003b,0x00000007, + 0x00000007,0x00000007,0x00000007,0x00000007,0x00040015,0x0000004b,0x00000020,0x00000000, + 0x00040017,0x0000004c,0x0000004b,0x00000002,0x00040020,0x0000004d,0x00000007,0x0000004c, + 0x00040017,0x0000004e,0x0000004b,0x00000004,0x00040020,0x0000004f,0x00000007,0x0000004e, + 0x00090021,0x00000050,0x00000002,0x00000016,0x0000004d,0x0000004f,0x0000004f,0x0000004f, + 0x0000004f,0x0004002b,0x00000006,0x00000059,0x3f800000,0x0004002b,0x00000006,0x00000067, + 0x00000000,0x00090019,0x00000079,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000, + 0x00000001,0x00000000,0x0003001b,0x0000007a,0x00000079,0x00040020,0x0000007b,0x00000000, + 0x0000007a,0x0004003b,0x0000007b,0x0000007c,0x00000000,0x00040015,0x0000007f,0x00000020, + 0x00000001,0x0004002b,0x0000007f,0x00000080,0x00000000,0x0004002b,0x0000007f,0x00000086, + 0x00000001,0x0004002b,0x0000007f,0x0000008c,0x00000002,0x0004002b,0x0000004b,0x00000091, + 0x00000000,0x0004002b,0x0000004b,0x00000097,0x00000001,0x0004002b,0x00000006,0x000000bf, + 0x3ecccccd,0x0004002b,0x00000006,0x000000c2,0xbf800000,0x0004002b,0x00000006,0x000000cf, + 0x3fc80000,0x0004002b,0x00000006,0x000000d2,0xbf100000,0x00040020,0x00000186,0x00000007, + 0x00000024,0x0004002b,0x00000006,0x000001b9,0x3f000000,0x0007002c,0x00000024,0x000001ba, + 0x000001b9,0x000001b9,0x000001b9,0x000001b9,0x0004002b,0x0000004b,0x000001e6,0x00000002, + 0x0004002b,0x0000004b,0x000001ea,0x00000003,0x0005002c,0x00000022,0x00000200,0x00000067, + 0x00000067,0x00030029,0x0000003a,0x00000202,0x0003002a,0x0000003a,0x00000203,0x0004002b, + 0x00000006,0x0000026c,0x38000000,0x0004002b,0x00000006,0x000002a2,0xbf000000,0x0004002b, + 0x00000006,0x000002a8,0xbe947ae1,0x0006002c,0x00000015,0x000002f5,0x00000067,0x00000067, + 0x00000067,0x0005002c,0x00000022,0x000002f7,0x00000067,0x000000c2,0x0005002c,0x00000022, + 0x00000312,0x00000059,0x000000c2,0x0005002c,0x00000022,0x0000032d,0x000000c2,0x00000059, + 0x0005002c,0x00000022,0x00000348,0x00000067,0x00000059,0x0005002c,0x00000022,0x0000037d, + 0x000000c2,0x00000067,0x0005002c,0x00000022,0x00000398,0x00000059,0x00000059,0x0004002b, + 0x00000006,0x000003b3,0x40000000,0x0005002c,0x00000022,0x000003b4,0x000003b3,0x00000059, + 0x0005002c,0x00000022,0x000003cf,0x000003b3,0x00000067,0x0005002c,0x00000022,0x000003ea, + 0x00000059,0x00000067,0x0005002c,0x00000022,0x00000405,0x00000059,0x000003b3,0x0005002c, + 0x00000022,0x00000420,0x00000067,0x000003b3,0x00040020,0x00000446,0x00000001,0x00000022, + 0x0004003b,0x00000446,0x00000447,0x00000001,0x0008001e,0x00000449,0x00000024,0x0000004e, + 0x0000004e,0x0000004e,0x0000004e,0x00000022,0x00040020,0x0000044a,0x00000009,0x00000449, + 0x0004003b,0x0000044a,0x0000044b,0x00000009,0x0004002b,0x0000007f,0x0000044c,0x00000005, + 0x00040020,0x0000044d,0x00000009,0x00000022,0x0004002b,0x0000007f,0x00000453,0x00000003, + 0x0004002b,0x0000007f,0x00000454,0x00000004,0x00040020,0x00000459,0x00000009,0x0000004e, + 0x00040020,0x00000467,0x00000003,0x00000024,0x0004003b,0x00000467,0x00000468,0x00000003, + 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b, + 0x0000004d,0x00000445,0x00000007,0x0004003b,0x00000016,0x00000452,0x00000007,0x0004003b, + 0x00000016,0x00000455,0x00000007,0x0004003b,0x0000004d,0x00000456,0x00000007,0x0004003b, + 0x0000004f,0x00000458,0x00000007,0x0004003b,0x0000004f,0x0000045c,0x00000007,0x0004003b, + 0x0000004f,0x0000045f,0x00000007,0x0004003b,0x0000004f,0x00000462,0x00000007,0x0004003d, + 0x00000022,0x00000448,0x00000447,0x00050041,0x0000044d,0x0000044e,0x0000044b,0x0000044c, + 0x0004003d,0x00000022,0x0000044f,0x0000044e,0x00050085,0x00000022,0x00000450,0x00000448, + 0x0000044f,0x0004006d,0x0000004c,0x00000451,0x00000450,0x0003003e,0x00000445,0x00000451, + 0x0004003d,0x0000004c,0x00000457,0x00000445,0x0003003e,0x00000456,0x00000457,0x00050041, + 0x00000459,0x0000045a,0x0000044b,0x00000086,0x0004003d,0x0000004e,0x0000045b,0x0000045a, + 0x0003003e,0x00000458,0x0000045b,0x00050041,0x00000459,0x0000045d,0x0000044b,0x0000008c, + 0x0004003d,0x0000004e,0x0000045e,0x0000045d,0x0003003e,0x0000045c,0x0000045e,0x00050041, + 0x00000459,0x00000460,0x0000044b,0x00000453,0x0004003d,0x0000004e,0x00000461,0x00000460, + 0x0003003e,0x0000045f,0x00000461,0x00050041,0x00000459,0x00000463,0x0000044b,0x00000454, + 0x0004003d,0x0000004e,0x00000464,0x00000463,0x0003003e,0x00000462,0x00000464,0x000a0039, + 0x00000002,0x00000465,0x00000057,0x00000455,0x00000456,0x00000458,0x0000045c,0x0000045f, + 0x00000462,0x0004003d,0x00000015,0x00000466,0x00000455,0x0003003e,0x00000452,0x00000466, + 0x0004003d,0x00000015,0x00000469,0x00000452,0x00050051,0x00000006,0x0000046a,0x00000469, + 0x00000000,0x00050051,0x00000006,0x0000046b,0x00000469,0x00000001,0x00050051,0x00000006, + 0x0000046c,0x00000469,0x00000002,0x00070050,0x00000024,0x0000046d,0x0000046a,0x0000046b, + 0x0000046c,0x00000059,0x0003003e,0x00000468,0x0000046d,0x000100fd,0x00010038,0x00050036, + 0x00000006,0x0000000a,0x00000000,0x00000008,0x00030037,0x00000007,0x00000009,0x000200f8, + 0x0000000b,0x0004003d,0x00000006,0x0000005a,0x00000009,0x00050088,0x00000006,0x0000005b, + 0x00000059,0x0000005a,0x000200fe,0x0000005b,0x00010038,0x00050036,0x00000006,0x0000000d, + 0x00000000,0x00000008,0x00030037,0x00000007,0x0000000c,0x000200f8,0x0000000e,0x0004003d, + 0x00000006,0x0000005e,0x0000000c,0x00050088,0x00000006,0x0000005f,0x00000059,0x0000005e, + 0x000200fe,0x0000005f,0x00010038,0x00050036,0x00000006,0x00000010,0x00000000,0x00000008, + 0x00030037,0x00000007,0x0000000f,0x000200f8,0x00000011,0x0004003d,0x00000006,0x00000062, + 0x0000000f,0x0006000c,0x00000006,0x00000063,0x00000001,0x00000020,0x00000062,0x000200fe, + 0x00000063,0x00010038,0x00050036,0x00000006,0x00000013,0x00000000,0x00000008,0x00030037, + 0x00000007,0x00000012,0x000200f8,0x00000014,0x0004003d,0x00000006,0x00000066,0x00000012, + 0x0008000c,0x00000006,0x00000068,0x00000001,0x0000002b,0x00000066,0x00000067,0x00000059, + 0x000200fe,0x00000068,0x00010038,0x00050036,0x00000015,0x0000001b,0x00000000,0x00000017, + 0x00030037,0x00000016,0x00000018,0x00030037,0x00000016,0x00000019,0x00030037,0x00000016, + 0x0000001a,0x000200f8,0x0000001c,0x0004003d,0x00000015,0x0000006b,0x00000018,0x0004003d, + 0x00000015,0x0000006c,0x00000019,0x0004003d,0x00000015,0x0000006d,0x0000001a,0x0007000c, + 0x00000015,0x0000006e,0x00000001,0x00000025,0x0000006c,0x0000006d,0x0007000c,0x00000015, + 0x0000006f,0x00000001,0x00000025,0x0000006b,0x0000006e,0x000200fe,0x0000006f,0x00010038, + 0x00050036,0x00000015,0x00000020,0x00000000,0x00000017,0x00030037,0x00000016,0x0000001d, + 0x00030037,0x00000016,0x0000001e,0x00030037,0x00000016,0x0000001f,0x000200f8,0x00000021, + 0x0004003d,0x00000015,0x00000072,0x0000001d,0x0004003d,0x00000015,0x00000073,0x0000001e, + 0x0004003d,0x00000015,0x00000074,0x0000001f,0x0007000c,0x00000015,0x00000075,0x00000001, + 0x00000028,0x00000073,0x00000074,0x0007000c,0x00000015,0x00000076,0x00000001,0x00000028, + 0x00000072,0x00000075,0x000200fe,0x00000076,0x00010038,0x00050036,0x00000024,0x00000027, + 0x00000000,0x00000025,0x00030037,0x00000023,0x00000026,0x000200f8,0x00000028,0x0004003d, + 0x0000007a,0x0000007d,0x0000007c,0x0004003d,0x00000022,0x0000007e,0x00000026,0x00060060, + 0x00000024,0x00000081,0x0000007d,0x0000007e,0x00000080,0x000200fe,0x00000081,0x00010038, + 0x00050036,0x00000024,0x0000002a,0x00000000,0x00000025,0x00030037,0x00000023,0x00000029, + 0x000200f8,0x0000002b,0x0004003d,0x0000007a,0x00000084,0x0000007c,0x0004003d,0x00000022, + 0x00000085,0x00000029,0x00060060,0x00000024,0x00000087,0x00000084,0x00000085,0x00000086, + 0x000200fe,0x00000087,0x00010038,0x00050036,0x00000024,0x0000002d,0x00000000,0x00000025, + 0x00030037,0x00000023,0x0000002c,0x000200f8,0x0000002e,0x0004003d,0x0000007a,0x0000008a, + 0x0000007c,0x0004003d,0x00000022,0x0000008b,0x0000002c,0x00060060,0x00000024,0x0000008d, + 0x0000008a,0x0000008b,0x0000008c,0x000200fe,0x0000008d,0x00010038,0x00050036,0x00000002, + 0x00000038,0x00000000,0x0000002f,0x00030037,0x00000016,0x00000030,0x00030037,0x00000007, + 0x00000031,0x00030037,0x00000023,0x00000032,0x00030037,0x00000023,0x00000033,0x00030037, + 0x00000023,0x00000034,0x00030037,0x00000007,0x00000035,0x00030037,0x00000007,0x00000036, + 0x00030037,0x00000016,0x00000037,0x000200f8,0x00000039,0x0004003b,0x00000023,0x00000090, + 0x00000007,0x0004003b,0x00000007,0x000000af,0x00000007,0x0004003b,0x00000007,0x000000be, + 0x00000007,0x0004003b,0x00000007,0x000000c4,0x00000007,0x0004003b,0x00000007,0x000000d4, + 0x00000007,0x00050041,0x00000007,0x00000092,0x00000032,0x00000091,0x0004003d,0x00000006, + 0x00000093,0x00000092,0x00050041,0x00000007,0x00000094,0x00000033,0x00000091,0x0004003d, + 0x00000006,0x00000095,0x00000094,0x00050085,0x00000006,0x00000096,0x00000093,0x00000095, + 0x00050041,0x00000007,0x00000098,0x00000032,0x00000097,0x0004003d,0x00000006,0x00000099, + 0x00000098,0x00050041,0x00000007,0x0000009a,0x00000033,0x00000097,0x0004003d,0x00000006, + 0x0000009b,0x0000009a,0x00050085,0x00000006,0x0000009c,0x00000099,0x0000009b,0x00050081, + 0x00000006,0x0000009d,0x00000096,0x0000009c,0x00050041,0x00000007,0x0000009e,0x00000090, + 0x00000091,0x0003003e,0x0000009e,0x0000009d,0x00050041,0x00000007,0x0000009f,0x00000032, + 0x00000091,0x0004003d,0x00000006,0x000000a0,0x0000009f,0x00050041,0x00000007,0x000000a1, + 0x00000033,0x00000097,0x0004003d,0x00000006,0x000000a2,0x000000a1,0x0004007f,0x00000006, + 0x000000a3,0x000000a2,0x00050085,0x00000006,0x000000a4,0x000000a0,0x000000a3,0x00050041, + 0x00000007,0x000000a5,0x00000032,0x00000097,0x0004003d,0x00000006,0x000000a6,0x000000a5, + 0x00050041,0x00000007,0x000000a7,0x00000033,0x00000091,0x0004003d,0x00000006,0x000000a8, + 0x000000a7,0x00050085,0x00000006,0x000000a9,0x000000a6,0x000000a8,0x00050081,0x00000006, + 0x000000aa,0x000000a4,0x000000a9,0x00050041,0x00000007,0x000000ab,0x00000090,0x00000097, + 0x0003003e,0x000000ab,0x000000aa,0x0004003d,0x00000022,0x000000ac,0x00000034,0x0004003d, + 0x00000022,0x000000ad,0x00000090,0x00050085,0x00000022,0x000000ae,0x000000ad,0x000000ac, + 0x0003003e,0x00000090,0x000000ae,0x00050041,0x00000007,0x000000b0,0x00000090,0x00000091, + 0x0004003d,0x00000006,0x000000b1,0x000000b0,0x00050041,0x00000007,0x000000b2,0x00000090, + 0x00000091,0x0004003d,0x00000006,0x000000b3,0x000000b2,0x00050085,0x00000006,0x000000b4, + 0x000000b1,0x000000b3,0x00050041,0x00000007,0x000000b5,0x00000090,0x00000097,0x0004003d, + 0x00000006,0x000000b6,0x000000b5,0x00050041,0x00000007,0x000000b7,0x00000090,0x00000097, + 0x0004003d,0x00000006,0x000000b8,0x000000b7,0x00050085,0x00000006,0x000000b9,0x000000b6, + 0x000000b8,0x00050081,0x00000006,0x000000ba,0x000000b4,0x000000b9,0x0003003e,0x000000af, + 0x000000ba,0x0004003d,0x00000006,0x000000bb,0x000000af,0x0004003d,0x00000006,0x000000bc, + 0x00000036,0x0007000c,0x00000006,0x000000bd,0x00000001,0x00000025,0x000000bb,0x000000bc, + 0x0003003e,0x000000af,0x000000bd,0x0004003d,0x00000006,0x000000c0,0x000000af,0x00050085, + 0x00000006,0x000000c1,0x000000bf,0x000000c0,0x00050081,0x00000006,0x000000c3,0x000000c1, + 0x000000c2,0x0003003e,0x000000be,0x000000c3,0x0004003d,0x00000006,0x000000c5,0x00000035, + 0x0004003d,0x00000006,0x000000c6,0x000000af,0x00050085,0x00000006,0x000000c7,0x000000c5, + 0x000000c6,0x00050081,0x00000006,0x000000c8,0x000000c7,0x000000c2,0x0003003e,0x000000c4, + 0x000000c8,0x0004003d,0x00000006,0x000000c9,0x000000be,0x0004003d,0x00000006,0x000000ca, + 0x000000be,0x00050085,0x00000006,0x000000cb,0x000000ca,0x000000c9,0x0003003e,0x000000be, + 0x000000cb,0x0004003d,0x00000006,0x000000cc,0x000000c4,0x0004003d,0x00000006,0x000000cd, + 0x000000c4,0x00050085,0x00000006,0x000000ce,0x000000cd,0x000000cc,0x0003003e,0x000000c4, + 0x000000ce,0x0004003d,0x00000006,0x000000d0,0x000000be,0x00050085,0x00000006,0x000000d1, + 0x000000cf,0x000000d0,0x00050081,0x00000006,0x000000d3,0x000000d1,0x000000d2,0x0003003e, + 0x000000be,0x000000d3,0x0004003d,0x00000006,0x000000d5,0x000000be,0x0004003d,0x00000006, + 0x000000d6,0x000000c4,0x00050085,0x00000006,0x000000d7,0x000000d5,0x000000d6,0x0003003e, + 0x000000d4,0x000000d7,0x0004003d,0x00000015,0x000000d8,0x00000037,0x0004003d,0x00000006, + 0x000000d9,0x000000d4,0x0005008e,0x00000015,0x000000da,0x000000d8,0x000000d9,0x0004003d, + 0x00000015,0x000000db,0x00000030,0x00050081,0x00000015,0x000000dc,0x000000db,0x000000da, + 0x0003003e,0x00000030,0x000000dc,0x0004003d,0x00000006,0x000000dd,0x000000d4,0x0004003d, + 0x00000006,0x000000de,0x00000031,0x00050081,0x00000006,0x000000df,0x000000de,0x000000dd, + 0x0003003e,0x00000031,0x000000df,0x000100fd,0x00010038,0x00050036,0x00000002,0x00000049, + 0x00000000,0x0000003c,0x00030037,0x00000023,0x0000003d,0x00030037,0x00000007,0x0000003e, + 0x00030037,0x00000023,0x0000003f,0x00030037,0x0000003b,0x00000040,0x00030037,0x0000003b, + 0x00000041,0x00030037,0x0000003b,0x00000042,0x00030037,0x0000003b,0x00000043,0x00030037, + 0x00000007,0x00000044,0x00030037,0x00000007,0x00000045,0x00030037,0x00000007,0x00000046, + 0x00030037,0x00000007,0x00000047,0x00030037,0x00000007,0x00000048,0x000200f8,0x0000004a, + 0x0004003b,0x00000007,0x000000e0,0x00000007,0x0004003b,0x00000007,0x00000105,0x00000007, + 0x0004003b,0x00000007,0x00000109,0x00000007,0x0004003b,0x00000007,0x0000010d,0x00000007, + 0x0004003b,0x00000007,0x00000113,0x00000007,0x0004003b,0x00000007,0x00000116,0x00000007, + 0x0004003b,0x00000007,0x00000125,0x00000007,0x0004003b,0x00000007,0x0000012f,0x00000007, + 0x0004003b,0x00000007,0x00000133,0x00000007,0x0004003b,0x00000007,0x00000137,0x00000007, + 0x0004003b,0x00000007,0x0000013d,0x00000007,0x0004003b,0x00000007,0x00000140,0x00000007, + 0x0004003b,0x00000007,0x0000014f,0x00000007,0x0003003e,0x000000e0,0x00000067,0x0004003d, + 0x0000003a,0x000000e1,0x00000040,0x000300f7,0x000000e3,0x00000000,0x000400fa,0x000000e1, + 0x000000e2,0x000000e3,0x000200f8,0x000000e2,0x00050041,0x00000007,0x000000e4,0x0000003f, + 0x00000091,0x0004003d,0x00000006,0x000000e5,0x000000e4,0x00050083,0x00000006,0x000000e6, + 0x00000059,0x000000e5,0x00050041,0x00000007,0x000000e7,0x0000003f,0x00000097,0x0004003d, + 0x00000006,0x000000e8,0x000000e7,0x00050083,0x00000006,0x000000e9,0x00000059,0x000000e8, + 0x00050085,0x00000006,0x000000ea,0x000000e6,0x000000e9,0x0003003e,0x000000e0,0x000000ea, + 0x000200f9,0x000000e3,0x000200f8,0x000000e3,0x0004003d,0x0000003a,0x000000eb,0x00000041, + 0x000300f7,0x000000ed,0x00000000,0x000400fa,0x000000eb,0x000000ec,0x000000ed,0x000200f8, + 0x000000ec,0x00050041,0x00000007,0x000000ee,0x0000003f,0x00000091,0x0004003d,0x00000006, + 0x000000ef,0x000000ee,0x00050041,0x00000007,0x000000f0,0x0000003f,0x00000097,0x0004003d, + 0x00000006,0x000000f1,0x000000f0,0x00050083,0x00000006,0x000000f2,0x00000059,0x000000f1, + 0x00050085,0x00000006,0x000000f3,0x000000ef,0x000000f2,0x0003003e,0x000000e0,0x000000f3, + 0x000200f9,0x000000ed,0x000200f8,0x000000ed,0x0004003d,0x0000003a,0x000000f4,0x00000042, + 0x000300f7,0x000000f6,0x00000000,0x000400fa,0x000000f4,0x000000f5,0x000000f6,0x000200f8, + 0x000000f5,0x00050041,0x00000007,0x000000f7,0x0000003f,0x00000091,0x0004003d,0x00000006, + 0x000000f8,0x000000f7,0x00050083,0x00000006,0x000000f9,0x00000059,0x000000f8,0x00050041, + 0x00000007,0x000000fa,0x0000003f,0x00000097,0x0004003d,0x00000006,0x000000fb,0x000000fa, + 0x00050085,0x00000006,0x000000fc,0x000000f9,0x000000fb,0x0003003e,0x000000e0,0x000000fc, + 0x000200f9,0x000000f6,0x000200f8,0x000000f6,0x0004003d,0x0000003a,0x000000fd,0x00000043, + 0x000300f7,0x000000ff,0x00000000,0x000400fa,0x000000fd,0x000000fe,0x000000ff,0x000200f8, + 0x000000fe,0x00050041,0x00000007,0x00000100,0x0000003f,0x00000091,0x0004003d,0x00000006, + 0x00000101,0x00000100,0x00050041,0x00000007,0x00000102,0x0000003f,0x00000097,0x0004003d, + 0x00000006,0x00000103,0x00000102,0x00050085,0x00000006,0x00000104,0x00000101,0x00000103, + 0x0003003e,0x000000e0,0x00000104,0x000200f9,0x000000ff,0x000200f8,0x000000ff,0x0004003d, + 0x00000006,0x00000106,0x00000047,0x0004003d,0x00000006,0x00000107,0x00000046,0x00050083, + 0x00000006,0x00000108,0x00000106,0x00000107,0x0003003e,0x00000105,0x00000108,0x0004003d, + 0x00000006,0x0000010a,0x00000046,0x0004003d,0x00000006,0x0000010b,0x00000045,0x00050083, + 0x00000006,0x0000010c,0x0000010a,0x0000010b,0x0003003e,0x00000109,0x0000010c,0x0004003d, + 0x00000006,0x0000010e,0x00000105,0x0006000c,0x00000006,0x0000010f,0x00000001,0x00000004, + 0x0000010e,0x0004003d,0x00000006,0x00000110,0x00000109,0x0006000c,0x00000006,0x00000111, + 0x00000001,0x00000004,0x00000110,0x0007000c,0x00000006,0x00000112,0x00000001,0x00000028, + 0x0000010f,0x00000111,0x0003003e,0x0000010d,0x00000112,0x0004003d,0x00000006,0x00000114, + 0x0000010d,0x0003003e,0x00000113,0x00000114,0x00050039,0x00000006,0x00000115,0x0000000d, + 0x00000113,0x0003003e,0x0000010d,0x00000115,0x0004003d,0x00000006,0x00000117,0x00000047, + 0x0004003d,0x00000006,0x00000118,0x00000045,0x00050083,0x00000006,0x00000119,0x00000117, + 0x00000118,0x0003003e,0x00000116,0x00000119,0x0004003d,0x00000006,0x0000011a,0x00000116, + 0x0004003d,0x00000006,0x0000011b,0x000000e0,0x00050085,0x00000006,0x0000011c,0x0000011a, + 0x0000011b,0x00050041,0x00000007,0x0000011d,0x0000003d,0x00000091,0x0004003d,0x00000006, + 0x0000011e,0x0000011d,0x00050081,0x00000006,0x0000011f,0x0000011e,0x0000011c,0x00050041, + 0x00000007,0x00000120,0x0000003d,0x00000091,0x0003003e,0x00000120,0x0000011f,0x0004003d, + 0x00000006,0x00000121,0x00000116,0x0006000c,0x00000006,0x00000122,0x00000001,0x00000004, + 0x00000121,0x0004003d,0x00000006,0x00000123,0x0000010d,0x00050085,0x00000006,0x00000124, + 0x00000122,0x00000123,0x0003003e,0x00000125,0x00000124,0x00050039,0x00000006,0x00000126, + 0x00000013,0x00000125,0x0003003e,0x0000010d,0x00000126,0x0004003d,0x00000006,0x00000127, + 0x0000010d,0x0004003d,0x00000006,0x00000128,0x0000010d,0x00050085,0x00000006,0x00000129, + 0x00000128,0x00000127,0x0003003e,0x0000010d,0x00000129,0x0004003d,0x00000006,0x0000012a, + 0x0000010d,0x0004003d,0x00000006,0x0000012b,0x000000e0,0x00050085,0x00000006,0x0000012c, + 0x0000012a,0x0000012b,0x0004003d,0x00000006,0x0000012d,0x0000003e,0x00050081,0x00000006, + 0x0000012e,0x0000012d,0x0000012c,0x0003003e,0x0000003e,0x0000012e,0x0004003d,0x00000006, + 0x00000130,0x00000048,0x0004003d,0x00000006,0x00000131,0x00000046,0x00050083,0x00000006, + 0x00000132,0x00000130,0x00000131,0x0003003e,0x0000012f,0x00000132,0x0004003d,0x00000006, + 0x00000134,0x00000046,0x0004003d,0x00000006,0x00000135,0x00000044,0x00050083,0x00000006, + 0x00000136,0x00000134,0x00000135,0x0003003e,0x00000133,0x00000136,0x0004003d,0x00000006, + 0x00000138,0x0000012f,0x0006000c,0x00000006,0x00000139,0x00000001,0x00000004,0x00000138, + 0x0004003d,0x00000006,0x0000013a,0x00000133,0x0006000c,0x00000006,0x0000013b,0x00000001, + 0x00000004,0x0000013a,0x0007000c,0x00000006,0x0000013c,0x00000001,0x00000028,0x00000139, + 0x0000013b,0x0003003e,0x00000137,0x0000013c,0x0004003d,0x00000006,0x0000013e,0x00000137, + 0x0003003e,0x0000013d,0x0000013e,0x00050039,0x00000006,0x0000013f,0x0000000d,0x0000013d, + 0x0003003e,0x00000137,0x0000013f,0x0004003d,0x00000006,0x00000141,0x00000048,0x0004003d, + 0x00000006,0x00000142,0x00000044,0x00050083,0x00000006,0x00000143,0x00000141,0x00000142, + 0x0003003e,0x00000140,0x00000143,0x0004003d,0x00000006,0x00000144,0x00000140,0x0004003d, + 0x00000006,0x00000145,0x000000e0,0x00050085,0x00000006,0x00000146,0x00000144,0x00000145, + 0x00050041,0x00000007,0x00000147,0x0000003d,0x00000097,0x0004003d,0x00000006,0x00000148, + 0x00000147,0x00050081,0x00000006,0x00000149,0x00000148,0x00000146,0x00050041,0x00000007, + 0x0000014a,0x0000003d,0x00000097,0x0003003e,0x0000014a,0x00000149,0x0004003d,0x00000006, + 0x0000014b,0x00000140,0x0006000c,0x00000006,0x0000014c,0x00000001,0x00000004,0x0000014b, + 0x0004003d,0x00000006,0x0000014d,0x00000137,0x00050085,0x00000006,0x0000014e,0x0000014c, + 0x0000014d,0x0003003e,0x0000014f,0x0000014e,0x00050039,0x00000006,0x00000150,0x00000013, + 0x0000014f,0x0003003e,0x00000137,0x00000150,0x0004003d,0x00000006,0x00000151,0x00000137, + 0x0004003d,0x00000006,0x00000152,0x00000137,0x00050085,0x00000006,0x00000153,0x00000152, + 0x00000151,0x0003003e,0x00000137,0x00000153,0x0004003d,0x00000006,0x00000154,0x00000137, + 0x0004003d,0x00000006,0x00000155,0x000000e0,0x00050085,0x00000006,0x00000156,0x00000154, + 0x00000155,0x0004003d,0x00000006,0x00000157,0x0000003e,0x00050081,0x00000006,0x00000158, + 0x00000157,0x00000156,0x0003003e,0x0000003e,0x00000158,0x000100fd,0x00010038,0x00050036, + 0x00000002,0x00000057,0x00000000,0x00000050,0x00030037,0x00000016,0x00000051,0x00030037, + 0x0000004d,0x00000052,0x00030037,0x0000004f,0x00000053,0x00030037,0x0000004f,0x00000054, + 0x00030037,0x0000004f,0x00000055,0x00030037,0x0000004f,0x00000056,0x000200f8,0x00000058, + 0x0004003b,0x00000023,0x00000159,0x00000007,0x0004003b,0x00000023,0x00000164,0x00000007, + 0x0004003b,0x00000023,0x0000016a,0x00000007,0x0004003b,0x00000023,0x00000174,0x00000007, + 0x0004003b,0x00000023,0x0000017a,0x00000007,0x0004003b,0x00000023,0x00000180,0x00000007, + 0x0004003b,0x00000186,0x00000187,0x00000007,0x0004003b,0x00000023,0x00000188,0x00000007, + 0x0004003b,0x00000186,0x0000018b,0x00000007,0x0004003b,0x00000023,0x0000018c,0x00000007, + 0x0004003b,0x00000186,0x0000018f,0x00000007,0x0004003b,0x00000023,0x00000190,0x00000007, + 0x0004003b,0x00000186,0x00000193,0x00000007,0x0004003b,0x00000023,0x00000194,0x00000007, + 0x0004003b,0x00000186,0x00000197,0x00000007,0x0004003b,0x00000023,0x00000198,0x00000007, + 0x0004003b,0x00000186,0x0000019b,0x00000007,0x0004003b,0x00000023,0x0000019c,0x00000007, + 0x0004003b,0x00000186,0x0000019f,0x00000007,0x0004003b,0x00000023,0x000001a0,0x00000007, + 0x0004003b,0x00000186,0x000001a3,0x00000007,0x0004003b,0x00000023,0x000001a4,0x00000007, + 0x0004003b,0x00000186,0x000001a7,0x00000007,0x0004003b,0x00000023,0x000001a8,0x00000007, + 0x0004003b,0x00000186,0x000001ab,0x00000007,0x0004003b,0x00000023,0x000001ac,0x00000007, + 0x0004003b,0x00000186,0x000001af,0x00000007,0x0004003b,0x00000023,0x000001b0,0x00000007, + 0x0004003b,0x00000186,0x000001b3,0x00000007,0x0004003b,0x00000023,0x000001b4,0x00000007, + 0x0004003b,0x00000186,0x000001b7,0x00000007,0x0004003b,0x00000186,0x000001c1,0x00000007, + 0x0004003b,0x00000186,0x000001c9,0x00000007,0x0004003b,0x00000186,0x000001d1,0x00000007, + 0x0004003b,0x00000007,0x000001d9,0x00000007,0x0004003b,0x00000007,0x000001dc,0x00000007, + 0x0004003b,0x00000007,0x000001df,0x00000007,0x0004003b,0x00000007,0x000001e2,0x00000007, + 0x0004003b,0x00000007,0x000001e5,0x00000007,0x0004003b,0x00000007,0x000001e9,0x00000007, + 0x0004003b,0x00000007,0x000001ed,0x00000007,0x0004003b,0x00000007,0x000001f0,0x00000007, + 0x0004003b,0x00000007,0x000001f3,0x00000007,0x0004003b,0x00000007,0x000001f6,0x00000007, + 0x0004003b,0x00000007,0x000001f9,0x00000007,0x0004003b,0x00000007,0x000001fc,0x00000007, + 0x0004003b,0x00000023,0x000001ff,0x00000007,0x0004003b,0x00000007,0x00000201,0x00000007, + 0x0004003b,0x00000023,0x00000204,0x00000007,0x0004003b,0x00000007,0x00000206,0x00000007, + 0x0004003b,0x00000023,0x00000208,0x00000007,0x0004003b,0x0000003b,0x0000020a,0x00000007, + 0x0004003b,0x0000003b,0x0000020b,0x00000007,0x0004003b,0x0000003b,0x0000020c,0x00000007, + 0x0004003b,0x0000003b,0x0000020d,0x00000007,0x0004003b,0x00000007,0x0000020e,0x00000007, + 0x0004003b,0x00000007,0x00000210,0x00000007,0x0004003b,0x00000007,0x00000212,0x00000007, + 0x0004003b,0x00000007,0x00000214,0x00000007,0x0004003b,0x00000007,0x00000216,0x00000007, + 0x0004003b,0x00000023,0x0000021b,0x00000007,0x0004003b,0x00000007,0x0000021d,0x00000007, + 0x0004003b,0x00000023,0x0000021f,0x00000007,0x0004003b,0x0000003b,0x00000221,0x00000007, + 0x0004003b,0x0000003b,0x00000222,0x00000007,0x0004003b,0x0000003b,0x00000223,0x00000007, + 0x0004003b,0x0000003b,0x00000224,0x00000007,0x0004003b,0x00000007,0x00000225,0x00000007, + 0x0004003b,0x00000007,0x00000227,0x00000007,0x0004003b,0x00000007,0x00000229,0x00000007, + 0x0004003b,0x00000007,0x0000022b,0x00000007,0x0004003b,0x00000007,0x0000022d,0x00000007, + 0x0004003b,0x00000023,0x00000232,0x00000007,0x0004003b,0x00000007,0x00000234,0x00000007, + 0x0004003b,0x00000023,0x00000236,0x00000007,0x0004003b,0x0000003b,0x00000238,0x00000007, + 0x0004003b,0x0000003b,0x00000239,0x00000007,0x0004003b,0x0000003b,0x0000023a,0x00000007, + 0x0004003b,0x0000003b,0x0000023b,0x00000007,0x0004003b,0x00000007,0x0000023c,0x00000007, + 0x0004003b,0x00000007,0x0000023e,0x00000007,0x0004003b,0x00000007,0x00000240,0x00000007, + 0x0004003b,0x00000007,0x00000242,0x00000007,0x0004003b,0x00000007,0x00000244,0x00000007, + 0x0004003b,0x00000023,0x00000249,0x00000007,0x0004003b,0x00000007,0x0000024b,0x00000007, + 0x0004003b,0x00000023,0x0000024d,0x00000007,0x0004003b,0x0000003b,0x0000024f,0x00000007, + 0x0004003b,0x0000003b,0x00000250,0x00000007,0x0004003b,0x0000003b,0x00000251,0x00000007, + 0x0004003b,0x0000003b,0x00000252,0x00000007,0x0004003b,0x00000007,0x00000253,0x00000007, + 0x0004003b,0x00000007,0x00000255,0x00000007,0x0004003b,0x00000007,0x00000257,0x00000007, + 0x0004003b,0x00000007,0x00000259,0x00000007,0x0004003b,0x00000007,0x0000025b,0x00000007, + 0x0004003b,0x00000023,0x00000260,0x00000007,0x0004003b,0x00000007,0x00000264,0x00000007, + 0x0004003b,0x0000003b,0x0000026a,0x00000007,0x0004003b,0x00000007,0x0000026e,0x00000007, + 0x0004003b,0x00000007,0x00000275,0x00000007,0x0004003b,0x00000007,0x00000286,0x00000007, + 0x0004003b,0x00000007,0x00000299,0x00000007,0x0004003b,0x00000023,0x0000029c,0x00000007, + 0x0004003b,0x00000007,0x000002a7,0x00000007,0x0004003b,0x00000007,0x000002ac,0x00000007, + 0x0004003b,0x00000007,0x000002ad,0x00000007,0x0004003b,0x00000016,0x000002b0,0x00000007, + 0x0004003b,0x00000016,0x000002c6,0x00000007,0x0004003b,0x00000016,0x000002c7,0x00000007, + 0x0004003b,0x00000016,0x000002c8,0x00000007,0x0004003b,0x00000016,0x000002d2,0x00000007, + 0x0004003b,0x00000016,0x000002e8,0x00000007,0x0004003b,0x00000016,0x000002e9,0x00000007, + 0x0004003b,0x00000016,0x000002ea,0x00000007,0x0004003b,0x00000016,0x000002f4,0x00000007, + 0x0004003b,0x00000007,0x000002f6,0x00000007,0x0004003b,0x00000016,0x00000301,0x00000007, + 0x0004003b,0x00000007,0x00000303,0x00000007,0x0004003b,0x00000023,0x00000305,0x00000007, + 0x0004003b,0x00000023,0x00000306,0x00000007,0x0004003b,0x00000023,0x00000308,0x00000007, + 0x0004003b,0x00000007,0x0000030a,0x00000007,0x0004003b,0x00000007,0x0000030c,0x00000007, + 0x0004003b,0x00000016,0x0000030e,0x00000007,0x0004003b,0x00000016,0x0000031c,0x00000007, + 0x0004003b,0x00000007,0x0000031e,0x00000007,0x0004003b,0x00000023,0x00000320,0x00000007, + 0x0004003b,0x00000023,0x00000321,0x00000007,0x0004003b,0x00000023,0x00000323,0x00000007, + 0x0004003b,0x00000007,0x00000325,0x00000007,0x0004003b,0x00000007,0x00000327,0x00000007, + 0x0004003b,0x00000016,0x00000329,0x00000007,0x0004003b,0x00000016,0x00000337,0x00000007, + 0x0004003b,0x00000007,0x00000339,0x00000007,0x0004003b,0x00000023,0x0000033b,0x00000007, + 0x0004003b,0x00000023,0x0000033c,0x00000007,0x0004003b,0x00000023,0x0000033e,0x00000007, + 0x0004003b,0x00000007,0x00000340,0x00000007,0x0004003b,0x00000007,0x00000342,0x00000007, + 0x0004003b,0x00000016,0x00000344,0x00000007,0x0004003b,0x00000016,0x00000352,0x00000007, + 0x0004003b,0x00000007,0x00000354,0x00000007,0x0004003b,0x00000023,0x00000356,0x00000007, + 0x0004003b,0x00000023,0x00000357,0x00000007,0x0004003b,0x00000023,0x00000359,0x00000007, + 0x0004003b,0x00000007,0x0000035b,0x00000007,0x0004003b,0x00000007,0x0000035d,0x00000007, + 0x0004003b,0x00000016,0x0000035f,0x00000007,0x0004003b,0x00000016,0x0000036c,0x00000007, + 0x0004003b,0x00000007,0x0000036e,0x00000007,0x0004003b,0x00000023,0x00000370,0x00000007, + 0x0004003b,0x00000023,0x00000371,0x00000007,0x0004003b,0x00000023,0x00000373,0x00000007, + 0x0004003b,0x00000007,0x00000375,0x00000007,0x0004003b,0x00000007,0x00000377,0x00000007, + 0x0004003b,0x00000016,0x00000379,0x00000007,0x0004003b,0x00000016,0x00000387,0x00000007, + 0x0004003b,0x00000007,0x00000389,0x00000007,0x0004003b,0x00000023,0x0000038b,0x00000007, + 0x0004003b,0x00000023,0x0000038c,0x00000007,0x0004003b,0x00000023,0x0000038e,0x00000007, + 0x0004003b,0x00000007,0x00000390,0x00000007,0x0004003b,0x00000007,0x00000392,0x00000007, + 0x0004003b,0x00000016,0x00000394,0x00000007,0x0004003b,0x00000016,0x000003a2,0x00000007, + 0x0004003b,0x00000007,0x000003a4,0x00000007,0x0004003b,0x00000023,0x000003a6,0x00000007, + 0x0004003b,0x00000023,0x000003a7,0x00000007,0x0004003b,0x00000023,0x000003a9,0x00000007, + 0x0004003b,0x00000007,0x000003ab,0x00000007,0x0004003b,0x00000007,0x000003ad,0x00000007, + 0x0004003b,0x00000016,0x000003af,0x00000007,0x0004003b,0x00000016,0x000003be,0x00000007, + 0x0004003b,0x00000007,0x000003c0,0x00000007,0x0004003b,0x00000023,0x000003c2,0x00000007, + 0x0004003b,0x00000023,0x000003c3,0x00000007,0x0004003b,0x00000023,0x000003c5,0x00000007, + 0x0004003b,0x00000007,0x000003c7,0x00000007,0x0004003b,0x00000007,0x000003c9,0x00000007, + 0x0004003b,0x00000016,0x000003cb,0x00000007,0x0004003b,0x00000016,0x000003d9,0x00000007, + 0x0004003b,0x00000007,0x000003db,0x00000007,0x0004003b,0x00000023,0x000003dd,0x00000007, + 0x0004003b,0x00000023,0x000003de,0x00000007,0x0004003b,0x00000023,0x000003e0,0x00000007, + 0x0004003b,0x00000007,0x000003e2,0x00000007,0x0004003b,0x00000007,0x000003e4,0x00000007, + 0x0004003b,0x00000016,0x000003e6,0x00000007,0x0004003b,0x00000016,0x000003f4,0x00000007, + 0x0004003b,0x00000007,0x000003f6,0x00000007,0x0004003b,0x00000023,0x000003f8,0x00000007, + 0x0004003b,0x00000023,0x000003f9,0x00000007,0x0004003b,0x00000023,0x000003fb,0x00000007, + 0x0004003b,0x00000007,0x000003fd,0x00000007,0x0004003b,0x00000007,0x000003ff,0x00000007, + 0x0004003b,0x00000016,0x00000401,0x00000007,0x0004003b,0x00000016,0x0000040f,0x00000007, + 0x0004003b,0x00000007,0x00000411,0x00000007,0x0004003b,0x00000023,0x00000413,0x00000007, + 0x0004003b,0x00000023,0x00000414,0x00000007,0x0004003b,0x00000023,0x00000416,0x00000007, + 0x0004003b,0x00000007,0x00000418,0x00000007,0x0004003b,0x00000007,0x0000041a,0x00000007, + 0x0004003b,0x00000016,0x0000041c,0x00000007,0x0004003b,0x00000016,0x0000042a,0x00000007, + 0x0004003b,0x00000007,0x0000042c,0x00000007,0x0004003b,0x00000023,0x0000042e,0x00000007, + 0x0004003b,0x00000023,0x0000042f,0x00000007,0x0004003b,0x00000023,0x00000431,0x00000007, + 0x0004003b,0x00000007,0x00000433,0x00000007,0x0004003b,0x00000007,0x00000435,0x00000007, + 0x0004003b,0x00000016,0x00000437,0x00000007,0x0004003b,0x00000007,0x0000043e,0x00000007, + 0x0004003d,0x0000004c,0x0000015a,0x00000052,0x00040070,0x00000022,0x0000015b,0x0000015a, + 0x0004003d,0x0000004e,0x0000015c,0x00000053,0x0007004f,0x0000004c,0x0000015d,0x0000015c, + 0x0000015c,0x00000000,0x00000001,0x0004007c,0x00000022,0x0000015e,0x0000015d,0x00050085, + 0x00000022,0x0000015f,0x0000015b,0x0000015e,0x0004003d,0x0000004e,0x00000160,0x00000053, + 0x0007004f,0x0000004c,0x00000161,0x00000160,0x00000160,0x00000002,0x00000003,0x0004007c, + 0x00000022,0x00000162,0x00000161,0x00050081,0x00000022,0x00000163,0x0000015f,0x00000162, + 0x0003003e,0x00000159,0x00000163,0x0004003d,0x00000022,0x00000165,0x00000159,0x0006000c, + 0x00000022,0x00000166,0x00000001,0x00000008,0x00000165,0x0003003e,0x00000164,0x00000166, + 0x0004003d,0x00000022,0x00000167,0x00000164,0x0004003d,0x00000022,0x00000168,0x00000159, + 0x00050083,0x00000022,0x00000169,0x00000168,0x00000167,0x0003003e,0x00000159,0x00000169, + 0x0004003d,0x00000022,0x0000016b,0x00000164,0x0004003d,0x0000004e,0x0000016c,0x00000054, + 0x0007004f,0x0000004c,0x0000016d,0x0000016c,0x0000016c,0x00000000,0x00000001,0x0004007c, + 0x00000022,0x0000016e,0x0000016d,0x00050085,0x00000022,0x0000016f,0x0000016b,0x0000016e, + 0x0004003d,0x0000004e,0x00000170,0x00000054,0x0007004f,0x0000004c,0x00000171,0x00000170, + 0x00000170,0x00000002,0x00000003,0x0004007c,0x00000022,0x00000172,0x00000171,0x00050081, + 0x00000022,0x00000173,0x0000016f,0x00000172,0x0003003e,0x0000016a,0x00000173,0x0004003d, + 0x00000022,0x00000175,0x0000016a,0x0004003d,0x0000004e,0x00000176,0x00000055,0x0007004f, + 0x0000004c,0x00000177,0x00000176,0x00000176,0x00000000,0x00000001,0x0004007c,0x00000022, + 0x00000178,0x00000177,0x00050081,0x00000022,0x00000179,0x00000175,0x00000178,0x0003003e, + 0x00000174,0x00000179,0x0004003d,0x00000022,0x0000017b,0x0000016a,0x0004003d,0x0000004e, + 0x0000017c,0x00000055,0x0007004f,0x0000004c,0x0000017d,0x0000017c,0x0000017c,0x00000002, + 0x00000003,0x0004007c,0x00000022,0x0000017e,0x0000017d,0x00050081,0x00000022,0x0000017f, + 0x0000017b,0x0000017e,0x0003003e,0x0000017a,0x0000017f,0x0004003d,0x00000022,0x00000181, + 0x0000016a,0x0004003d,0x0000004e,0x00000182,0x00000056,0x0007004f,0x0000004c,0x00000183, + 0x00000182,0x00000182,0x00000000,0x00000001,0x0004007c,0x00000022,0x00000184,0x00000183, + 0x00050081,0x00000022,0x00000185,0x00000181,0x00000184,0x0003003e,0x00000180,0x00000185, + 0x0004003d,0x00000022,0x00000189,0x0000016a,0x0003003e,0x00000188,0x00000189,0x00050039, + 0x00000024,0x0000018a,0x00000027,0x00000188,0x0003003e,0x00000187,0x0000018a,0x0004003d, + 0x00000022,0x0000018d,0x0000016a,0x0003003e,0x0000018c,0x0000018d,0x00050039,0x00000024, + 0x0000018e,0x0000002a,0x0000018c,0x0003003e,0x0000018b,0x0000018e,0x0004003d,0x00000022, + 0x00000191,0x0000016a,0x0003003e,0x00000190,0x00000191,0x00050039,0x00000024,0x00000192, + 0x0000002d,0x00000190,0x0003003e,0x0000018f,0x00000192,0x0004003d,0x00000022,0x00000195, + 0x00000174,0x0003003e,0x00000194,0x00000195,0x00050039,0x00000024,0x00000196,0x00000027, + 0x00000194,0x0003003e,0x00000193,0x00000196,0x0004003d,0x00000022,0x00000199,0x00000174, + 0x0003003e,0x00000198,0x00000199,0x00050039,0x00000024,0x0000019a,0x0000002a,0x00000198, + 0x0003003e,0x00000197,0x0000019a,0x0004003d,0x00000022,0x0000019d,0x00000174,0x0003003e, + 0x0000019c,0x0000019d,0x00050039,0x00000024,0x0000019e,0x0000002d,0x0000019c,0x0003003e, + 0x0000019b,0x0000019e,0x0004003d,0x00000022,0x000001a1,0x0000017a,0x0003003e,0x000001a0, + 0x000001a1,0x00050039,0x00000024,0x000001a2,0x00000027,0x000001a0,0x0003003e,0x0000019f, + 0x000001a2,0x0004003d,0x00000022,0x000001a5,0x0000017a,0x0003003e,0x000001a4,0x000001a5, + 0x00050039,0x00000024,0x000001a6,0x0000002a,0x000001a4,0x0003003e,0x000001a3,0x000001a6, + 0x0004003d,0x00000022,0x000001a9,0x0000017a,0x0003003e,0x000001a8,0x000001a9,0x00050039, + 0x00000024,0x000001aa,0x0000002d,0x000001a8,0x0003003e,0x000001a7,0x000001aa,0x0004003d, + 0x00000022,0x000001ad,0x00000180,0x0003003e,0x000001ac,0x000001ad,0x00050039,0x00000024, + 0x000001ae,0x00000027,0x000001ac,0x0003003e,0x000001ab,0x000001ae,0x0004003d,0x00000022, + 0x000001b1,0x00000180,0x0003003e,0x000001b0,0x000001b1,0x00050039,0x00000024,0x000001b2, + 0x0000002a,0x000001b0,0x0003003e,0x000001af,0x000001b2,0x0004003d,0x00000022,0x000001b5, + 0x00000180,0x0003003e,0x000001b4,0x000001b5,0x00050039,0x00000024,0x000001b6,0x0000002d, + 0x000001b4,0x0003003e,0x000001b3,0x000001b6,0x0004003d,0x00000024,0x000001b8,0x0000018f, + 0x00050085,0x00000024,0x000001bb,0x000001b8,0x000001ba,0x0004003d,0x00000024,0x000001bc, + 0x00000187,0x00050085,0x00000024,0x000001bd,0x000001bc,0x000001ba,0x0004003d,0x00000024, + 0x000001be,0x0000018b,0x00050081,0x00000024,0x000001bf,0x000001bd,0x000001be,0x00050081, + 0x00000024,0x000001c0,0x000001bb,0x000001bf,0x0003003e,0x000001b7,0x000001c0,0x0004003d, + 0x00000024,0x000001c2,0x0000019b,0x00050085,0x00000024,0x000001c3,0x000001c2,0x000001ba, + 0x0004003d,0x00000024,0x000001c4,0x00000193,0x00050085,0x00000024,0x000001c5,0x000001c4, + 0x000001ba,0x0004003d,0x00000024,0x000001c6,0x00000197,0x00050081,0x00000024,0x000001c7, + 0x000001c5,0x000001c6,0x00050081,0x00000024,0x000001c8,0x000001c3,0x000001c7,0x0003003e, + 0x000001c1,0x000001c8,0x0004003d,0x00000024,0x000001ca,0x000001a7,0x00050085,0x00000024, + 0x000001cb,0x000001ca,0x000001ba,0x0004003d,0x00000024,0x000001cc,0x0000019f,0x00050085, + 0x00000024,0x000001cd,0x000001cc,0x000001ba,0x0004003d,0x00000024,0x000001ce,0x000001a3, + 0x00050081,0x00000024,0x000001cf,0x000001cd,0x000001ce,0x00050081,0x00000024,0x000001d0, + 0x000001cb,0x000001cf,0x0003003e,0x000001c9,0x000001d0,0x0004003d,0x00000024,0x000001d2, + 0x000001b3,0x00050085,0x00000024,0x000001d3,0x000001d2,0x000001ba,0x0004003d,0x00000024, + 0x000001d4,0x000001ab,0x00050085,0x00000024,0x000001d5,0x000001d4,0x000001ba,0x0004003d, + 0x00000024,0x000001d6,0x000001af,0x00050081,0x00000024,0x000001d7,0x000001d5,0x000001d6, + 0x00050081,0x00000024,0x000001d8,0x000001d3,0x000001d7,0x0003003e,0x000001d1,0x000001d8, + 0x00050041,0x00000007,0x000001da,0x000001b7,0x00000091,0x0004003d,0x00000006,0x000001db, + 0x000001da,0x0003003e,0x000001d9,0x000001db,0x00050041,0x00000007,0x000001dd,0x000001b7, + 0x00000097,0x0004003d,0x00000006,0x000001de,0x000001dd,0x0003003e,0x000001dc,0x000001de, + 0x00050041,0x00000007,0x000001e0,0x000001c1,0x00000091,0x0004003d,0x00000006,0x000001e1, + 0x000001e0,0x0003003e,0x000001df,0x000001e1,0x00050041,0x00000007,0x000001e3,0x000001c1, + 0x00000097,0x0004003d,0x00000006,0x000001e4,0x000001e3,0x0003003e,0x000001e2,0x000001e4, + 0x00050041,0x00000007,0x000001e7,0x000001c1,0x000001e6,0x0004003d,0x00000006,0x000001e8, + 0x000001e7,0x0003003e,0x000001e5,0x000001e8,0x00050041,0x00000007,0x000001eb,0x000001c1, + 0x000001ea,0x0004003d,0x00000006,0x000001ec,0x000001eb,0x0003003e,0x000001e9,0x000001ec, + 0x00050041,0x00000007,0x000001ee,0x000001c9,0x00000091,0x0004003d,0x00000006,0x000001ef, + 0x000001ee,0x0003003e,0x000001ed,0x000001ef,0x00050041,0x00000007,0x000001f1,0x000001c9, + 0x00000097,0x0004003d,0x00000006,0x000001f2,0x000001f1,0x0003003e,0x000001f0,0x000001f2, + 0x00050041,0x00000007,0x000001f4,0x000001c9,0x000001e6,0x0004003d,0x00000006,0x000001f5, + 0x000001f4,0x0003003e,0x000001f3,0x000001f5,0x00050041,0x00000007,0x000001f7,0x000001c9, + 0x000001ea,0x0004003d,0x00000006,0x000001f8,0x000001f7,0x0003003e,0x000001f6,0x000001f8, + 0x00050041,0x00000007,0x000001fa,0x000001d1,0x000001e6,0x0004003d,0x00000006,0x000001fb, + 0x000001fa,0x0003003e,0x000001f9,0x000001fb,0x00050041,0x00000007,0x000001fd,0x000001d1, + 0x000001ea,0x0004003d,0x00000006,0x000001fe,0x000001fd,0x0003003e,0x000001fc,0x000001fe, + 0x0003003e,0x000001ff,0x00000200,0x0003003e,0x00000201,0x00000067,0x0004003d,0x00000022, + 0x00000205,0x000001ff,0x0003003e,0x00000204,0x00000205,0x0004003d,0x00000006,0x00000207, + 0x00000201,0x0003003e,0x00000206,0x00000207,0x0004003d,0x00000022,0x00000209,0x00000159, + 0x0003003e,0x00000208,0x00000209,0x0003003e,0x0000020a,0x00000202,0x0003003e,0x0000020b, + 0x00000203,0x0003003e,0x0000020c,0x00000203,0x0003003e,0x0000020d,0x00000203,0x0004003d, + 0x00000006,0x0000020f,0x000001d9,0x0003003e,0x0000020e,0x0000020f,0x0004003d,0x00000006, + 0x00000211,0x000001e9,0x0003003e,0x00000210,0x00000211,0x0004003d,0x00000006,0x00000213, + 0x000001e5,0x0003003e,0x00000212,0x00000213,0x0004003d,0x00000006,0x00000215,0x000001f6, + 0x0003003e,0x00000214,0x00000215,0x0004003d,0x00000006,0x00000217,0x000001e2,0x0003003e, + 0x00000216,0x00000217,0x00100039,0x00000002,0x00000218,0x00000049,0x00000204,0x00000206, + 0x00000208,0x0000020a,0x0000020b,0x0000020c,0x0000020d,0x0000020e,0x00000210,0x00000212, + 0x00000214,0x00000216,0x0004003d,0x00000022,0x00000219,0x00000204,0x0003003e,0x000001ff, + 0x00000219,0x0004003d,0x00000006,0x0000021a,0x00000206,0x0003003e,0x00000201,0x0000021a, + 0x0004003d,0x00000022,0x0000021c,0x000001ff,0x0003003e,0x0000021b,0x0000021c,0x0004003d, + 0x00000006,0x0000021e,0x00000201,0x0003003e,0x0000021d,0x0000021e,0x0004003d,0x00000022, + 0x00000220,0x00000159,0x0003003e,0x0000021f,0x00000220,0x0003003e,0x00000221,0x00000203, + 0x0003003e,0x00000222,0x00000202,0x0003003e,0x00000223,0x00000203,0x0003003e,0x00000224, + 0x00000203,0x0004003d,0x00000006,0x00000226,0x000001dc,0x0003003e,0x00000225,0x00000226, + 0x0004003d,0x00000006,0x00000228,0x000001e5,0x0003003e,0x00000227,0x00000228,0x0004003d, + 0x00000006,0x0000022a,0x000001f6,0x0003003e,0x00000229,0x0000022a,0x0004003d,0x00000006, + 0x0000022c,0x000001f3,0x0003003e,0x0000022b,0x0000022c,0x0004003d,0x00000006,0x0000022e, + 0x000001ed,0x0003003e,0x0000022d,0x0000022e,0x00100039,0x00000002,0x0000022f,0x00000049, + 0x0000021b,0x0000021d,0x0000021f,0x00000221,0x00000222,0x00000223,0x00000224,0x00000225, + 0x00000227,0x00000229,0x0000022b,0x0000022d,0x0004003d,0x00000022,0x00000230,0x0000021b, + 0x0003003e,0x000001ff,0x00000230,0x0004003d,0x00000006,0x00000231,0x0000021d,0x0003003e, + 0x00000201,0x00000231,0x0004003d,0x00000022,0x00000233,0x000001ff,0x0003003e,0x00000232, + 0x00000233,0x0004003d,0x00000006,0x00000235,0x00000201,0x0003003e,0x00000234,0x00000235, + 0x0004003d,0x00000022,0x00000237,0x00000159,0x0003003e,0x00000236,0x00000237,0x0003003e, + 0x00000238,0x00000203,0x0003003e,0x00000239,0x00000203,0x0003003e,0x0000023a,0x00000202, + 0x0003003e,0x0000023b,0x00000203,0x0004003d,0x00000006,0x0000023d,0x000001e5,0x0003003e, + 0x0000023c,0x0000023d,0x0004003d,0x00000006,0x0000023f,0x000001df,0x0003003e,0x0000023e, + 0x0000023f,0x0004003d,0x00000006,0x00000241,0x000001e2,0x0003003e,0x00000240,0x00000241, + 0x0004003d,0x00000006,0x00000243,0x000001ed,0x0003003e,0x00000242,0x00000243,0x0004003d, + 0x00000006,0x00000245,0x000001fc,0x0003003e,0x00000244,0x00000245,0x00100039,0x00000002, + 0x00000246,0x00000049,0x00000232,0x00000234,0x00000236,0x00000238,0x00000239,0x0000023a, + 0x0000023b,0x0000023c,0x0000023e,0x00000240,0x00000242,0x00000244,0x0004003d,0x00000022, + 0x00000247,0x00000232,0x0003003e,0x000001ff,0x00000247,0x0004003d,0x00000006,0x00000248, + 0x00000234,0x0003003e,0x00000201,0x00000248,0x0004003d,0x00000022,0x0000024a,0x000001ff, + 0x0003003e,0x00000249,0x0000024a,0x0004003d,0x00000006,0x0000024c,0x00000201,0x0003003e, + 0x0000024b,0x0000024c,0x0004003d,0x00000022,0x0000024e,0x00000159,0x0003003e,0x0000024d, + 0x0000024e,0x0003003e,0x0000024f,0x00000203,0x0003003e,0x00000250,0x00000203,0x0003003e, + 0x00000251,0x00000203,0x0003003e,0x00000252,0x00000202,0x0004003d,0x00000006,0x00000254, + 0x000001f6,0x0003003e,0x00000253,0x00000254,0x0004003d,0x00000006,0x00000256,0x000001e2, + 0x0003003e,0x00000255,0x00000256,0x0004003d,0x00000006,0x00000258,0x000001ed,0x0003003e, + 0x00000257,0x00000258,0x0004003d,0x00000006,0x0000025a,0x000001f0,0x0003003e,0x00000259, + 0x0000025a,0x0004003d,0x00000006,0x0000025c,0x000001f9,0x0003003e,0x0000025b,0x0000025c, + 0x00100039,0x00000002,0x0000025d,0x00000049,0x00000249,0x0000024b,0x0000024d,0x0000024f, + 0x00000250,0x00000251,0x00000252,0x00000253,0x00000255,0x00000257,0x00000259,0x0000025b, + 0x0004003d,0x00000022,0x0000025e,0x00000249,0x0003003e,0x000001ff,0x0000025e,0x0004003d, + 0x00000006,0x0000025f,0x0000024b,0x0003003e,0x00000201,0x0000025f,0x0004003d,0x00000022, + 0x00000261,0x000001ff,0x0004003d,0x00000022,0x00000262,0x000001ff,0x00050085,0x00000022, + 0x00000263,0x00000261,0x00000262,0x0003003e,0x00000260,0x00000263,0x00050041,0x00000007, + 0x00000265,0x00000260,0x00000091,0x0004003d,0x00000006,0x00000266,0x00000265,0x00050041, + 0x00000007,0x00000267,0x00000260,0x00000097,0x0004003d,0x00000006,0x00000268,0x00000267, + 0x00050081,0x00000006,0x00000269,0x00000266,0x00000268,0x0003003e,0x00000264,0x00000269, + 0x0004003d,0x00000006,0x0000026b,0x00000264,0x000500b8,0x0000003a,0x0000026d,0x0000026b, + 0x0000026c,0x0003003e,0x0000026a,0x0000026d,0x0004003d,0x00000006,0x0000026f,0x00000264, + 0x0003003e,0x0000026e,0x0000026f,0x00050039,0x00000006,0x00000270,0x00000010,0x0000026e, + 0x0003003e,0x00000264,0x00000270,0x0004003d,0x0000003a,0x00000271,0x0000026a,0x0004003d, + 0x00000006,0x00000272,0x00000264,0x000600a9,0x00000006,0x00000273,0x00000271,0x00000059, + 0x00000272,0x0003003e,0x00000264,0x00000273,0x0004003d,0x0000003a,0x00000274,0x0000026a, + 0x000300f7,0x00000277,0x00000000,0x000400fa,0x00000274,0x00000276,0x00000278,0x000200f8, + 0x00000276,0x0003003e,0x00000275,0x00000059,0x000200f9,0x00000277,0x000200f8,0x00000278, + 0x00050041,0x00000007,0x00000279,0x000001ff,0x00000091,0x0004003d,0x00000006,0x0000027a, + 0x00000279,0x0003003e,0x00000275,0x0000027a,0x000200f9,0x00000277,0x000200f8,0x00000277, + 0x0004003d,0x00000006,0x0000027b,0x00000275,0x00050041,0x00000007,0x0000027c,0x000001ff, + 0x00000091,0x0003003e,0x0000027c,0x0000027b,0x0004003d,0x00000006,0x0000027d,0x00000264, + 0x00050050,0x00000022,0x0000027e,0x0000027d,0x0000027d,0x0004003d,0x00000022,0x0000027f, + 0x000001ff,0x00050085,0x00000022,0x00000280,0x0000027f,0x0000027e,0x0003003e,0x000001ff, + 0x00000280,0x0004003d,0x00000006,0x00000281,0x00000201,0x00050085,0x00000006,0x00000282, + 0x00000281,0x000001b9,0x0003003e,0x00000201,0x00000282,0x0004003d,0x00000006,0x00000283, + 0x00000201,0x0004003d,0x00000006,0x00000284,0x00000201,0x00050085,0x00000006,0x00000285, + 0x00000284,0x00000283,0x0003003e,0x00000201,0x00000285,0x00050041,0x00000007,0x00000287, + 0x000001ff,0x00000091,0x0004003d,0x00000006,0x00000288,0x00000287,0x00050041,0x00000007, + 0x00000289,0x000001ff,0x00000091,0x0004003d,0x00000006,0x0000028a,0x00000289,0x00050085, + 0x00000006,0x0000028b,0x00000288,0x0000028a,0x00050041,0x00000007,0x0000028c,0x000001ff, + 0x00000097,0x0004003d,0x00000006,0x0000028d,0x0000028c,0x00050041,0x00000007,0x0000028e, + 0x000001ff,0x00000097,0x0004003d,0x00000006,0x0000028f,0x0000028e,0x00050085,0x00000006, + 0x00000290,0x0000028d,0x0000028f,0x00050081,0x00000006,0x00000291,0x0000028b,0x00000290, + 0x00050041,0x00000007,0x00000292,0x000001ff,0x00000091,0x0004003d,0x00000006,0x00000293, + 0x00000292,0x0006000c,0x00000006,0x00000294,0x00000001,0x00000004,0x00000293,0x00050041, + 0x00000007,0x00000295,0x000001ff,0x00000097,0x0004003d,0x00000006,0x00000296,0x00000295, + 0x0006000c,0x00000006,0x00000297,0x00000001,0x00000004,0x00000296,0x0007000c,0x00000006, + 0x00000298,0x00000001,0x00000028,0x00000294,0x00000297,0x0003003e,0x00000299,0x00000298, + 0x00050039,0x00000006,0x0000029a,0x0000000d,0x00000299,0x00050085,0x00000006,0x0000029b, + 0x00000291,0x0000029a,0x0003003e,0x00000286,0x0000029b,0x0004003d,0x00000006,0x0000029d, + 0x00000286,0x00050083,0x00000006,0x0000029e,0x0000029d,0x00000059,0x0004003d,0x00000006, + 0x0000029f,0x00000201,0x00050085,0x00000006,0x000002a0,0x0000029e,0x0000029f,0x00050081, + 0x00000006,0x000002a1,0x00000059,0x000002a0,0x0004003d,0x00000006,0x000002a3,0x00000201, + 0x00050085,0x00000006,0x000002a4,0x000002a2,0x000002a3,0x00050081,0x00000006,0x000002a5, + 0x00000059,0x000002a4,0x00050050,0x00000022,0x000002a6,0x000002a1,0x000002a5,0x0003003e, + 0x0000029c,0x000002a6,0x0004003d,0x00000006,0x000002a9,0x00000201,0x00050085,0x00000006, + 0x000002aa,0x000002a8,0x000002a9,0x00050081,0x00000006,0x000002ab,0x000001b9,0x000002aa, + 0x0003003e,0x000002a7,0x000002ab,0x0004003d,0x00000006,0x000002ae,0x000002a7,0x0003003e, + 0x000002ad,0x000002ae,0x00050039,0x00000006,0x000002af,0x0000000d,0x000002ad,0x0003003e, + 0x000002ac,0x000002af,0x00050041,0x00000007,0x000002b1,0x00000193,0x000001e6,0x0004003d, + 0x00000006,0x000002b2,0x000002b1,0x00050041,0x00000007,0x000002b3,0x00000197,0x000001e6, + 0x0004003d,0x00000006,0x000002b4,0x000002b3,0x00050041,0x00000007,0x000002b5,0x0000019b, + 0x000001e6,0x0004003d,0x00000006,0x000002b6,0x000002b5,0x00060050,0x00000015,0x000002b7, + 0x000002b2,0x000002b4,0x000002b6,0x00050041,0x00000007,0x000002b8,0x0000019f,0x000001ea, + 0x0004003d,0x00000006,0x000002b9,0x000002b8,0x00050041,0x00000007,0x000002ba,0x000001a3, + 0x000001ea,0x0004003d,0x00000006,0x000002bb,0x000002ba,0x00050041,0x00000007,0x000002bc, + 0x000001a7,0x000001ea,0x0004003d,0x00000006,0x000002bd,0x000002bc,0x00060050,0x00000015, + 0x000002be,0x000002b9,0x000002bb,0x000002bd,0x00050041,0x00000007,0x000002bf,0x00000193, + 0x00000097,0x0004003d,0x00000006,0x000002c0,0x000002bf,0x00050041,0x00000007,0x000002c1, + 0x00000197,0x00000097,0x0004003d,0x00000006,0x000002c2,0x000002c1,0x00050041,0x00000007, + 0x000002c3,0x0000019b,0x00000097,0x0004003d,0x00000006,0x000002c4,0x000002c3,0x00060050, + 0x00000015,0x000002c5,0x000002c0,0x000002c2,0x000002c4,0x0003003e,0x000002c6,0x000002b7, + 0x0003003e,0x000002c7,0x000002be,0x0003003e,0x000002c8,0x000002c5,0x00070039,0x00000015, + 0x000002c9,0x0000001b,0x000002c6,0x000002c7,0x000002c8,0x00050041,0x00000007,0x000002ca, + 0x0000019f,0x00000091,0x0004003d,0x00000006,0x000002cb,0x000002ca,0x00050041,0x00000007, + 0x000002cc,0x000001a3,0x00000091,0x0004003d,0x00000006,0x000002cd,0x000002cc,0x00050041, + 0x00000007,0x000002ce,0x000001a7,0x00000091,0x0004003d,0x00000006,0x000002cf,0x000002ce, + 0x00060050,0x00000015,0x000002d0,0x000002cb,0x000002cd,0x000002cf,0x0007000c,0x00000015, + 0x000002d1,0x00000001,0x00000025,0x000002c9,0x000002d0,0x0003003e,0x000002b0,0x000002d1, + 0x00050041,0x00000007,0x000002d3,0x00000193,0x000001e6,0x0004003d,0x00000006,0x000002d4, + 0x000002d3,0x00050041,0x00000007,0x000002d5,0x00000197,0x000001e6,0x0004003d,0x00000006, + 0x000002d6,0x000002d5,0x00050041,0x00000007,0x000002d7,0x0000019b,0x000001e6,0x0004003d, + 0x00000006,0x000002d8,0x000002d7,0x00060050,0x00000015,0x000002d9,0x000002d4,0x000002d6, + 0x000002d8,0x00050041,0x00000007,0x000002da,0x0000019f,0x000001ea,0x0004003d,0x00000006, + 0x000002db,0x000002da,0x00050041,0x00000007,0x000002dc,0x000001a3,0x000001ea,0x0004003d, + 0x00000006,0x000002dd,0x000002dc,0x00050041,0x00000007,0x000002de,0x000001a7,0x000001ea, + 0x0004003d,0x00000006,0x000002df,0x000002de,0x00060050,0x00000015,0x000002e0,0x000002db, + 0x000002dd,0x000002df,0x00050041,0x00000007,0x000002e1,0x00000193,0x00000097,0x0004003d, + 0x00000006,0x000002e2,0x000002e1,0x00050041,0x00000007,0x000002e3,0x00000197,0x00000097, + 0x0004003d,0x00000006,0x000002e4,0x000002e3,0x00050041,0x00000007,0x000002e5,0x0000019b, + 0x00000097,0x0004003d,0x00000006,0x000002e6,0x000002e5,0x00060050,0x00000015,0x000002e7, + 0x000002e2,0x000002e4,0x000002e6,0x0003003e,0x000002e8,0x000002d9,0x0003003e,0x000002e9, + 0x000002e0,0x0003003e,0x000002ea,0x000002e7,0x00070039,0x00000015,0x000002eb,0x00000020, + 0x000002e8,0x000002e9,0x000002ea,0x00050041,0x00000007,0x000002ec,0x0000019f,0x00000091, + 0x0004003d,0x00000006,0x000002ed,0x000002ec,0x00050041,0x00000007,0x000002ee,0x000001a3, + 0x00000091,0x0004003d,0x00000006,0x000002ef,0x000002ee,0x00050041,0x00000007,0x000002f0, + 0x000001a7,0x00000091,0x0004003d,0x00000006,0x000002f1,0x000002f0,0x00060050,0x00000015, + 0x000002f2,0x000002ed,0x000002ef,0x000002f1,0x0007000c,0x00000015,0x000002f3,0x00000001, + 0x00000028,0x000002eb,0x000002f2,0x0003003e,0x000002d2,0x000002f3,0x0003003e,0x000002f4, + 0x000002f5,0x0003003e,0x000002f6,0x00000067,0x0004003d,0x00000022,0x000002f8,0x00000159, + 0x00050083,0x00000022,0x000002f9,0x000002f7,0x000002f8,0x00050041,0x00000007,0x000002fa, + 0x00000187,0x00000091,0x0004003d,0x00000006,0x000002fb,0x000002fa,0x00050041,0x00000007, + 0x000002fc,0x0000018b,0x00000091,0x0004003d,0x00000006,0x000002fd,0x000002fc,0x00050041, + 0x00000007,0x000002fe,0x0000018f,0x00000091,0x0004003d,0x00000006,0x000002ff,0x000002fe, + 0x00060050,0x00000015,0x00000300,0x000002fb,0x000002fd,0x000002ff,0x0004003d,0x00000015, + 0x00000302,0x000002f4,0x0003003e,0x00000301,0x00000302,0x0004003d,0x00000006,0x00000304, + 0x000002f6,0x0003003e,0x00000303,0x00000304,0x0003003e,0x00000305,0x000002f9,0x0004003d, + 0x00000022,0x00000307,0x000001ff,0x0003003e,0x00000306,0x00000307,0x0004003d,0x00000022, + 0x00000309,0x0000029c,0x0003003e,0x00000308,0x00000309,0x0004003d,0x00000006,0x0000030b, + 0x000002a7,0x0003003e,0x0000030a,0x0000030b,0x0004003d,0x00000006,0x0000030d,0x000002ac, + 0x0003003e,0x0000030c,0x0000030d,0x0003003e,0x0000030e,0x00000300,0x000c0039,0x00000002, + 0x0000030f,0x00000038,0x00000301,0x00000303,0x00000305,0x00000306,0x00000308,0x0000030a, + 0x0000030c,0x0000030e,0x0004003d,0x00000015,0x00000310,0x00000301,0x0003003e,0x000002f4, + 0x00000310,0x0004003d,0x00000006,0x00000311,0x00000303,0x0003003e,0x000002f6,0x00000311, + 0x0004003d,0x00000022,0x00000313,0x00000159,0x00050083,0x00000022,0x00000314,0x00000312, + 0x00000313,0x00050041,0x00000007,0x00000315,0x00000187,0x00000097,0x0004003d,0x00000006, + 0x00000316,0x00000315,0x00050041,0x00000007,0x00000317,0x0000018b,0x00000097,0x0004003d, + 0x00000006,0x00000318,0x00000317,0x00050041,0x00000007,0x00000319,0x0000018f,0x00000097, + 0x0004003d,0x00000006,0x0000031a,0x00000319,0x00060050,0x00000015,0x0000031b,0x00000316, + 0x00000318,0x0000031a,0x0004003d,0x00000015,0x0000031d,0x000002f4,0x0003003e,0x0000031c, + 0x0000031d,0x0004003d,0x00000006,0x0000031f,0x000002f6,0x0003003e,0x0000031e,0x0000031f, + 0x0003003e,0x00000320,0x00000314,0x0004003d,0x00000022,0x00000322,0x000001ff,0x0003003e, + 0x00000321,0x00000322,0x0004003d,0x00000022,0x00000324,0x0000029c,0x0003003e,0x00000323, + 0x00000324,0x0004003d,0x00000006,0x00000326,0x000002a7,0x0003003e,0x00000325,0x00000326, + 0x0004003d,0x00000006,0x00000328,0x000002ac,0x0003003e,0x00000327,0x00000328,0x0003003e, + 0x00000329,0x0000031b,0x000c0039,0x00000002,0x0000032a,0x00000038,0x0000031c,0x0000031e, + 0x00000320,0x00000321,0x00000323,0x00000325,0x00000327,0x00000329,0x0004003d,0x00000015, + 0x0000032b,0x0000031c,0x0003003e,0x000002f4,0x0000032b,0x0004003d,0x00000006,0x0000032c, + 0x0000031e,0x0003003e,0x000002f6,0x0000032c,0x0004003d,0x00000022,0x0000032e,0x00000159, + 0x00050083,0x00000022,0x0000032f,0x0000032d,0x0000032e,0x00050041,0x00000007,0x00000330, + 0x00000193,0x00000091,0x0004003d,0x00000006,0x00000331,0x00000330,0x00050041,0x00000007, + 0x00000332,0x00000197,0x00000091,0x0004003d,0x00000006,0x00000333,0x00000332,0x00050041, + 0x00000007,0x00000334,0x0000019b,0x00000091,0x0004003d,0x00000006,0x00000335,0x00000334, + 0x00060050,0x00000015,0x00000336,0x00000331,0x00000333,0x00000335,0x0004003d,0x00000015, + 0x00000338,0x000002f4,0x0003003e,0x00000337,0x00000338,0x0004003d,0x00000006,0x0000033a, + 0x000002f6,0x0003003e,0x00000339,0x0000033a,0x0003003e,0x0000033b,0x0000032f,0x0004003d, + 0x00000022,0x0000033d,0x000001ff,0x0003003e,0x0000033c,0x0000033d,0x0004003d,0x00000022, + 0x0000033f,0x0000029c,0x0003003e,0x0000033e,0x0000033f,0x0004003d,0x00000006,0x00000341, + 0x000002a7,0x0003003e,0x00000340,0x00000341,0x0004003d,0x00000006,0x00000343,0x000002ac, + 0x0003003e,0x00000342,0x00000343,0x0003003e,0x00000344,0x00000336,0x000c0039,0x00000002, + 0x00000345,0x00000038,0x00000337,0x00000339,0x0000033b,0x0000033c,0x0000033e,0x00000340, + 0x00000342,0x00000344,0x0004003d,0x00000015,0x00000346,0x00000337,0x0003003e,0x000002f4, + 0x00000346,0x0004003d,0x00000006,0x00000347,0x00000339,0x0003003e,0x000002f6,0x00000347, + 0x0004003d,0x00000022,0x00000349,0x00000159,0x00050083,0x00000022,0x0000034a,0x00000348, + 0x00000349,0x00050041,0x00000007,0x0000034b,0x00000193,0x00000097,0x0004003d,0x00000006, + 0x0000034c,0x0000034b,0x00050041,0x00000007,0x0000034d,0x00000197,0x00000097,0x0004003d, + 0x00000006,0x0000034e,0x0000034d,0x00050041,0x00000007,0x0000034f,0x0000019b,0x00000097, + 0x0004003d,0x00000006,0x00000350,0x0000034f,0x00060050,0x00000015,0x00000351,0x0000034c, + 0x0000034e,0x00000350,0x0004003d,0x00000015,0x00000353,0x000002f4,0x0003003e,0x00000352, + 0x00000353,0x0004003d,0x00000006,0x00000355,0x000002f6,0x0003003e,0x00000354,0x00000355, + 0x0003003e,0x00000356,0x0000034a,0x0004003d,0x00000022,0x00000358,0x000001ff,0x0003003e, + 0x00000357,0x00000358,0x0004003d,0x00000022,0x0000035a,0x0000029c,0x0003003e,0x00000359, + 0x0000035a,0x0004003d,0x00000006,0x0000035c,0x000002a7,0x0003003e,0x0000035b,0x0000035c, + 0x0004003d,0x00000006,0x0000035e,0x000002ac,0x0003003e,0x0000035d,0x0000035e,0x0003003e, + 0x0000035f,0x00000351,0x000c0039,0x00000002,0x00000360,0x00000038,0x00000352,0x00000354, + 0x00000356,0x00000357,0x00000359,0x0000035b,0x0000035d,0x0000035f,0x0004003d,0x00000015, + 0x00000361,0x00000352,0x0003003e,0x000002f4,0x00000361,0x0004003d,0x00000006,0x00000362, + 0x00000354,0x0003003e,0x000002f6,0x00000362,0x0004003d,0x00000022,0x00000363,0x00000159, + 0x00050083,0x00000022,0x00000364,0x00000200,0x00000363,0x00050041,0x00000007,0x00000365, + 0x00000193,0x000001e6,0x0004003d,0x00000006,0x00000366,0x00000365,0x00050041,0x00000007, + 0x00000367,0x00000197,0x000001e6,0x0004003d,0x00000006,0x00000368,0x00000367,0x00050041, + 0x00000007,0x00000369,0x0000019b,0x000001e6,0x0004003d,0x00000006,0x0000036a,0x00000369, + 0x00060050,0x00000015,0x0000036b,0x00000366,0x00000368,0x0000036a,0x0004003d,0x00000015, + 0x0000036d,0x000002f4,0x0003003e,0x0000036c,0x0000036d,0x0004003d,0x00000006,0x0000036f, + 0x000002f6,0x0003003e,0x0000036e,0x0000036f,0x0003003e,0x00000370,0x00000364,0x0004003d, + 0x00000022,0x00000372,0x000001ff,0x0003003e,0x00000371,0x00000372,0x0004003d,0x00000022, + 0x00000374,0x0000029c,0x0003003e,0x00000373,0x00000374,0x0004003d,0x00000006,0x00000376, + 0x000002a7,0x0003003e,0x00000375,0x00000376,0x0004003d,0x00000006,0x00000378,0x000002ac, + 0x0003003e,0x00000377,0x00000378,0x0003003e,0x00000379,0x0000036b,0x000c0039,0x00000002, + 0x0000037a,0x00000038,0x0000036c,0x0000036e,0x00000370,0x00000371,0x00000373,0x00000375, + 0x00000377,0x00000379,0x0004003d,0x00000015,0x0000037b,0x0000036c,0x0003003e,0x000002f4, + 0x0000037b,0x0004003d,0x00000006,0x0000037c,0x0000036e,0x0003003e,0x000002f6,0x0000037c, + 0x0004003d,0x00000022,0x0000037e,0x00000159,0x00050083,0x00000022,0x0000037f,0x0000037d, + 0x0000037e,0x00050041,0x00000007,0x00000380,0x00000193,0x000001ea,0x0004003d,0x00000006, + 0x00000381,0x00000380,0x00050041,0x00000007,0x00000382,0x00000197,0x000001ea,0x0004003d, + 0x00000006,0x00000383,0x00000382,0x00050041,0x00000007,0x00000384,0x0000019b,0x000001ea, + 0x0004003d,0x00000006,0x00000385,0x00000384,0x00060050,0x00000015,0x00000386,0x00000381, + 0x00000383,0x00000385,0x0004003d,0x00000015,0x00000388,0x000002f4,0x0003003e,0x00000387, + 0x00000388,0x0004003d,0x00000006,0x0000038a,0x000002f6,0x0003003e,0x00000389,0x0000038a, + 0x0003003e,0x0000038b,0x0000037f,0x0004003d,0x00000022,0x0000038d,0x000001ff,0x0003003e, + 0x0000038c,0x0000038d,0x0004003d,0x00000022,0x0000038f,0x0000029c,0x0003003e,0x0000038e, + 0x0000038f,0x0004003d,0x00000006,0x00000391,0x000002a7,0x0003003e,0x00000390,0x00000391, + 0x0004003d,0x00000006,0x00000393,0x000002ac,0x0003003e,0x00000392,0x00000393,0x0003003e, + 0x00000394,0x00000386,0x000c0039,0x00000002,0x00000395,0x00000038,0x00000387,0x00000389, + 0x0000038b,0x0000038c,0x0000038e,0x00000390,0x00000392,0x00000394,0x0004003d,0x00000015, + 0x00000396,0x00000387,0x0003003e,0x000002f4,0x00000396,0x0004003d,0x00000006,0x00000397, + 0x00000389,0x0003003e,0x000002f6,0x00000397,0x0004003d,0x00000022,0x00000399,0x00000159, + 0x00050083,0x00000022,0x0000039a,0x00000398,0x00000399,0x00050041,0x00000007,0x0000039b, + 0x0000019f,0x00000091,0x0004003d,0x00000006,0x0000039c,0x0000039b,0x00050041,0x00000007, + 0x0000039d,0x000001a3,0x00000091,0x0004003d,0x00000006,0x0000039e,0x0000039d,0x00050041, + 0x00000007,0x0000039f,0x000001a7,0x00000091,0x0004003d,0x00000006,0x000003a0,0x0000039f, + 0x00060050,0x00000015,0x000003a1,0x0000039c,0x0000039e,0x000003a0,0x0004003d,0x00000015, + 0x000003a3,0x000002f4,0x0003003e,0x000003a2,0x000003a3,0x0004003d,0x00000006,0x000003a5, + 0x000002f6,0x0003003e,0x000003a4,0x000003a5,0x0003003e,0x000003a6,0x0000039a,0x0004003d, + 0x00000022,0x000003a8,0x000001ff,0x0003003e,0x000003a7,0x000003a8,0x0004003d,0x00000022, + 0x000003aa,0x0000029c,0x0003003e,0x000003a9,0x000003aa,0x0004003d,0x00000006,0x000003ac, + 0x000002a7,0x0003003e,0x000003ab,0x000003ac,0x0004003d,0x00000006,0x000003ae,0x000002ac, + 0x0003003e,0x000003ad,0x000003ae,0x0003003e,0x000003af,0x000003a1,0x000c0039,0x00000002, + 0x000003b0,0x00000038,0x000003a2,0x000003a4,0x000003a6,0x000003a7,0x000003a9,0x000003ab, + 0x000003ad,0x000003af,0x0004003d,0x00000015,0x000003b1,0x000003a2,0x0003003e,0x000002f4, + 0x000003b1,0x0004003d,0x00000006,0x000003b2,0x000003a4,0x0003003e,0x000002f6,0x000003b2, + 0x0004003d,0x00000022,0x000003b5,0x00000159,0x00050083,0x00000022,0x000003b6,0x000003b4, + 0x000003b5,0x00050041,0x00000007,0x000003b7,0x0000019f,0x00000097,0x0004003d,0x00000006, + 0x000003b8,0x000003b7,0x00050041,0x00000007,0x000003b9,0x000001a3,0x00000097,0x0004003d, + 0x00000006,0x000003ba,0x000003b9,0x00050041,0x00000007,0x000003bb,0x000001a7,0x00000097, + 0x0004003d,0x00000006,0x000003bc,0x000003bb,0x00060050,0x00000015,0x000003bd,0x000003b8, + 0x000003ba,0x000003bc,0x0004003d,0x00000015,0x000003bf,0x000002f4,0x0003003e,0x000003be, + 0x000003bf,0x0004003d,0x00000006,0x000003c1,0x000002f6,0x0003003e,0x000003c0,0x000003c1, + 0x0003003e,0x000003c2,0x000003b6,0x0004003d,0x00000022,0x000003c4,0x000001ff,0x0003003e, + 0x000003c3,0x000003c4,0x0004003d,0x00000022,0x000003c6,0x0000029c,0x0003003e,0x000003c5, + 0x000003c6,0x0004003d,0x00000006,0x000003c8,0x000002a7,0x0003003e,0x000003c7,0x000003c8, + 0x0004003d,0x00000006,0x000003ca,0x000002ac,0x0003003e,0x000003c9,0x000003ca,0x0003003e, + 0x000003cb,0x000003bd,0x000c0039,0x00000002,0x000003cc,0x00000038,0x000003be,0x000003c0, + 0x000003c2,0x000003c3,0x000003c5,0x000003c7,0x000003c9,0x000003cb,0x0004003d,0x00000015, + 0x000003cd,0x000003be,0x0003003e,0x000002f4,0x000003cd,0x0004003d,0x00000006,0x000003ce, + 0x000003c0,0x0003003e,0x000002f6,0x000003ce,0x0004003d,0x00000022,0x000003d0,0x00000159, + 0x00050083,0x00000022,0x000003d1,0x000003cf,0x000003d0,0x00050041,0x00000007,0x000003d2, + 0x0000019f,0x000001e6,0x0004003d,0x00000006,0x000003d3,0x000003d2,0x00050041,0x00000007, + 0x000003d4,0x000001a3,0x000001e6,0x0004003d,0x00000006,0x000003d5,0x000003d4,0x00050041, + 0x00000007,0x000003d6,0x000001a7,0x000001e6,0x0004003d,0x00000006,0x000003d7,0x000003d6, + 0x00060050,0x00000015,0x000003d8,0x000003d3,0x000003d5,0x000003d7,0x0004003d,0x00000015, + 0x000003da,0x000002f4,0x0003003e,0x000003d9,0x000003da,0x0004003d,0x00000006,0x000003dc, + 0x000002f6,0x0003003e,0x000003db,0x000003dc,0x0003003e,0x000003dd,0x000003d1,0x0004003d, + 0x00000022,0x000003df,0x000001ff,0x0003003e,0x000003de,0x000003df,0x0004003d,0x00000022, + 0x000003e1,0x0000029c,0x0003003e,0x000003e0,0x000003e1,0x0004003d,0x00000006,0x000003e3, + 0x000002a7,0x0003003e,0x000003e2,0x000003e3,0x0004003d,0x00000006,0x000003e5,0x000002ac, + 0x0003003e,0x000003e4,0x000003e5,0x0003003e,0x000003e6,0x000003d8,0x000c0039,0x00000002, + 0x000003e7,0x00000038,0x000003d9,0x000003db,0x000003dd,0x000003de,0x000003e0,0x000003e2, + 0x000003e4,0x000003e6,0x0004003d,0x00000015,0x000003e8,0x000003d9,0x0003003e,0x000002f4, + 0x000003e8,0x0004003d,0x00000006,0x000003e9,0x000003db,0x0003003e,0x000002f6,0x000003e9, + 0x0004003d,0x00000022,0x000003eb,0x00000159,0x00050083,0x00000022,0x000003ec,0x000003ea, + 0x000003eb,0x00050041,0x00000007,0x000003ed,0x0000019f,0x000001ea,0x0004003d,0x00000006, + 0x000003ee,0x000003ed,0x00050041,0x00000007,0x000003ef,0x000001a3,0x000001ea,0x0004003d, + 0x00000006,0x000003f0,0x000003ef,0x00050041,0x00000007,0x000003f1,0x000001a7,0x000001ea, + 0x0004003d,0x00000006,0x000003f2,0x000003f1,0x00060050,0x00000015,0x000003f3,0x000003ee, + 0x000003f0,0x000003f2,0x0004003d,0x00000015,0x000003f5,0x000002f4,0x0003003e,0x000003f4, + 0x000003f5,0x0004003d,0x00000006,0x000003f7,0x000002f6,0x0003003e,0x000003f6,0x000003f7, + 0x0003003e,0x000003f8,0x000003ec,0x0004003d,0x00000022,0x000003fa,0x000001ff,0x0003003e, + 0x000003f9,0x000003fa,0x0004003d,0x00000022,0x000003fc,0x0000029c,0x0003003e,0x000003fb, + 0x000003fc,0x0004003d,0x00000006,0x000003fe,0x000002a7,0x0003003e,0x000003fd,0x000003fe, + 0x0004003d,0x00000006,0x00000400,0x000002ac,0x0003003e,0x000003ff,0x00000400,0x0003003e, + 0x00000401,0x000003f3,0x000c0039,0x00000002,0x00000402,0x00000038,0x000003f4,0x000003f6, + 0x000003f8,0x000003f9,0x000003fb,0x000003fd,0x000003ff,0x00000401,0x0004003d,0x00000015, + 0x00000403,0x000003f4,0x0003003e,0x000002f4,0x00000403,0x0004003d,0x00000006,0x00000404, + 0x000003f6,0x0003003e,0x000002f6,0x00000404,0x0004003d,0x00000022,0x00000406,0x00000159, + 0x00050083,0x00000022,0x00000407,0x00000405,0x00000406,0x00050041,0x00000007,0x00000408, + 0x000001ab,0x000001e6,0x0004003d,0x00000006,0x00000409,0x00000408,0x00050041,0x00000007, + 0x0000040a,0x000001af,0x000001e6,0x0004003d,0x00000006,0x0000040b,0x0000040a,0x00050041, + 0x00000007,0x0000040c,0x000001b3,0x000001e6,0x0004003d,0x00000006,0x0000040d,0x0000040c, + 0x00060050,0x00000015,0x0000040e,0x00000409,0x0000040b,0x0000040d,0x0004003d,0x00000015, + 0x00000410,0x000002f4,0x0003003e,0x0000040f,0x00000410,0x0004003d,0x00000006,0x00000412, + 0x000002f6,0x0003003e,0x00000411,0x00000412,0x0003003e,0x00000413,0x00000407,0x0004003d, + 0x00000022,0x00000415,0x000001ff,0x0003003e,0x00000414,0x00000415,0x0004003d,0x00000022, + 0x00000417,0x0000029c,0x0003003e,0x00000416,0x00000417,0x0004003d,0x00000006,0x00000419, + 0x000002a7,0x0003003e,0x00000418,0x00000419,0x0004003d,0x00000006,0x0000041b,0x000002ac, + 0x0003003e,0x0000041a,0x0000041b,0x0003003e,0x0000041c,0x0000040e,0x000c0039,0x00000002, + 0x0000041d,0x00000038,0x0000040f,0x00000411,0x00000413,0x00000414,0x00000416,0x00000418, + 0x0000041a,0x0000041c,0x0004003d,0x00000015,0x0000041e,0x0000040f,0x0003003e,0x000002f4, + 0x0000041e,0x0004003d,0x00000006,0x0000041f,0x00000411,0x0003003e,0x000002f6,0x0000041f, + 0x0004003d,0x00000022,0x00000421,0x00000159,0x00050083,0x00000022,0x00000422,0x00000420, + 0x00000421,0x00050041,0x00000007,0x00000423,0x000001ab,0x000001ea,0x0004003d,0x00000006, + 0x00000424,0x00000423,0x00050041,0x00000007,0x00000425,0x000001af,0x000001ea,0x0004003d, + 0x00000006,0x00000426,0x00000425,0x00050041,0x00000007,0x00000427,0x000001b3,0x000001ea, + 0x0004003d,0x00000006,0x00000428,0x00000427,0x00060050,0x00000015,0x00000429,0x00000424, + 0x00000426,0x00000428,0x0004003d,0x00000015,0x0000042b,0x000002f4,0x0003003e,0x0000042a, + 0x0000042b,0x0004003d,0x00000006,0x0000042d,0x000002f6,0x0003003e,0x0000042c,0x0000042d, + 0x0003003e,0x0000042e,0x00000422,0x0004003d,0x00000022,0x00000430,0x000001ff,0x0003003e, + 0x0000042f,0x00000430,0x0004003d,0x00000022,0x00000432,0x0000029c,0x0003003e,0x00000431, + 0x00000432,0x0004003d,0x00000006,0x00000434,0x000002a7,0x0003003e,0x00000433,0x00000434, + 0x0004003d,0x00000006,0x00000436,0x000002ac,0x0003003e,0x00000435,0x00000436,0x0003003e, + 0x00000437,0x00000429,0x000c0039,0x00000002,0x00000438,0x00000038,0x0000042a,0x0000042c, + 0x0000042e,0x0000042f,0x00000431,0x00000433,0x00000435,0x00000437,0x0004003d,0x00000015, + 0x00000439,0x0000042a,0x0003003e,0x000002f4,0x00000439,0x0004003d,0x00000006,0x0000043a, + 0x0000042c,0x0003003e,0x000002f6,0x0000043a,0x0004003d,0x00000015,0x0000043b,0x000002d2, + 0x0004003d,0x00000015,0x0000043c,0x000002b0,0x0004003d,0x00000015,0x0000043d,0x000002f4, + 0x0004003d,0x00000006,0x0000043f,0x000002f6,0x0003003e,0x0000043e,0x0000043f,0x00050039, + 0x00000006,0x00000440,0x0000000a,0x0000043e,0x00060050,0x00000015,0x00000441,0x00000440, + 0x00000440,0x00000440,0x00050085,0x00000015,0x00000442,0x0000043d,0x00000441,0x0007000c, + 0x00000015,0x00000443,0x00000001,0x00000028,0x0000043c,0x00000442,0x0007000c,0x00000015, + 0x00000444,0x00000001,0x00000025,0x0000043b,0x00000443,0x0003003e,0x00000051,0x00000444, + 0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/fsr_rcas_frag.h b/app/src/main/cpp/shaders/fsr_rcas_frag.h new file mode 100644 index 0000000000..066d125dd6 --- /dev/null +++ b/app/src/main/cpp/shaders/fsr_rcas_frag.h @@ -0,0 +1,469 @@ + // 1116.2.0 + #pragma once +const uint32_t fsr_rcas_code[] = { + 0x07230203,0x00010000,0x0008000b,0x0000025e,0x00000000,0x00020011,0x00000001,0x00020011, + 0x00000032,0x0006000b,0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e, + 0x00000000,0x00000001,0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000023b, + 0x00000258,0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005, + 0x00000004,0x6e69616d,0x00000000,0x00050005,0x0000000a,0x70635241,0x66283146,0x00003b31, + 0x00030005,0x00000009,0x00000078,0x00070005,0x0000000d,0x78725041,0x5264654d,0x31467063, + 0x3b316628,0x00000000,0x00030005,0x0000000c,0x00000078,0x00050005,0x00000010,0x74615341, + 0x66283146,0x00003b31,0x00030005,0x0000000f,0x00000078,0x00070005,0x00000016,0x6e694d41, + 0x28314633,0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000013,0x00000061,0x00030005, + 0x00000014,0x00000062,0x00030005,0x00000015,0x00000063,0x00070005,0x0000001b,0x78614d41, + 0x28314633,0x663b3166,0x31663b31,0x0000003b,0x00030005,0x00000018,0x00000061,0x00030005, + 0x00000019,0x00000062,0x00030005,0x0000001a,0x00000063,0x00070005,0x00000023,0x52727346, + 0x4c736163,0x4664616f,0x32697628,0x0000003b,0x00030005,0x00000022,0x00000070,0x00080005, + 0x00000029,0x52727346,0x49736163,0x7475706e,0x31662846,0x3b31663b,0x003b3166,0x00030005, + 0x00000026,0x00000072,0x00030005,0x00000027,0x00000067,0x00030005,0x00000028,0x00000062, + 0x00090005,0x00000036,0x52727346,0x46736163,0x3b316628,0x663b3166,0x75763b31,0x75763b32, + 0x00003b34,0x00040005,0x00000031,0x52786970,0x00000000,0x00040005,0x00000032,0x47786970, + 0x00000000,0x00040005,0x00000033,0x42786970,0x00000000,0x00030005,0x00000034,0x00007069, + 0x00030005,0x00000035,0x006e6f63,0x00030005,0x00000054,0x00007a73,0x00060005,0x00000058, + 0x75706e49,0x78655474,0x65727574,0x00000000,0x00030005,0x00000069,0x00007073,0x00030005, + 0x0000006e,0x00000062,0x00040005,0x00000073,0x61726170,0x0000006d,0x00030005,0x00000076, + 0x00000064,0x00040005,0x0000007a,0x61726170,0x0000006d,0x00030005,0x0000007d,0x00000065, + 0x00040005,0x0000007e,0x61726170,0x0000006d,0x00030005,0x00000082,0x00000066,0x00040005, + 0x00000086,0x61726170,0x0000006d,0x00030005,0x00000089,0x00000068,0x00040005,0x0000008d, + 0x61726170,0x0000006d,0x00030005,0x00000090,0x00005262,0x00030005,0x00000094,0x00004762, + 0x00030005,0x00000098,0x00004262,0x00030005,0x0000009c,0x00005264,0x00030005,0x0000009f, + 0x00004764,0x00030005,0x000000a2,0x00004264,0x00030005,0x000000a5,0x00005265,0x00030005, + 0x000000a8,0x00004765,0x00030005,0x000000ab,0x00004265,0x00030005,0x000000ae,0x00005266, + 0x00030005,0x000000b1,0x00004766,0x00030005,0x000000b4,0x00004266,0x00030005,0x000000b7, + 0x00005268,0x00030005,0x000000ba,0x00004768,0x00030005,0x000000bd,0x00004268,0x00040005, + 0x000000c0,0x61726170,0x0000006d,0x00040005,0x000000c2,0x61726170,0x0000006d,0x00040005, + 0x000000c4,0x61726170,0x0000006d,0x00040005,0x000000ca,0x61726170,0x0000006d,0x00040005, + 0x000000cc,0x61726170,0x0000006d,0x00040005,0x000000ce,0x61726170,0x0000006d,0x00040005, + 0x000000d4,0x61726170,0x0000006d,0x00040005,0x000000d6,0x61726170,0x0000006d,0x00040005, + 0x000000d8,0x61726170,0x0000006d,0x00040005,0x000000de,0x61726170,0x0000006d,0x00040005, + 0x000000e0,0x61726170,0x0000006d,0x00040005,0x000000e2,0x61726170,0x0000006d,0x00040005, + 0x000000e8,0x61726170,0x0000006d,0x00040005,0x000000ea,0x61726170,0x0000006d,0x00040005, + 0x000000ec,0x61726170,0x0000006d,0x00030005,0x000000f2,0x00004c62,0x00030005,0x000000fb, + 0x00004c64,0x00030005,0x00000103,0x00004c65,0x00030005,0x0000010b,0x00004c66,0x00030005, + 0x00000113,0x00004c68,0x00030005,0x0000011b,0x00007a6e,0x00040005,0x0000012c,0x61726170, + 0x0000006d,0x00040005,0x0000012e,0x61726170,0x0000006d,0x00040005,0x00000130,0x61726170, + 0x0000006d,0x00040005,0x00000133,0x61726170,0x0000006d,0x00040005,0x00000134,0x61726170, + 0x0000006d,0x00040005,0x00000136,0x61726170,0x0000006d,0x00040005,0x00000139,0x61726170, + 0x0000006d,0x00040005,0x0000013b,0x61726170,0x0000006d,0x00040005,0x0000013d,0x61726170, + 0x0000006d,0x00040005,0x00000140,0x61726170,0x0000006d,0x00040005,0x00000141,0x61726170, + 0x0000006d,0x00040005,0x00000143,0x61726170,0x0000006d,0x00040005,0x00000147,0x61726170, + 0x0000006d,0x00040005,0x0000014a,0x61726170,0x0000006d,0x00040005,0x00000150,0x52346e6d, + 0x00000000,0x00040005,0x00000151,0x61726170,0x0000006d,0x00040005,0x00000153,0x61726170, + 0x0000006d,0x00040005,0x00000155,0x61726170,0x0000006d,0x00040005,0x0000015a,0x47346e6d, + 0x00000000,0x00040005,0x0000015b,0x61726170,0x0000006d,0x00040005,0x0000015d,0x61726170, + 0x0000006d,0x00040005,0x0000015f,0x61726170,0x0000006d,0x00040005,0x00000164,0x42346e6d, + 0x00000000,0x00040005,0x00000165,0x61726170,0x0000006d,0x00040005,0x00000167,0x61726170, + 0x0000006d,0x00040005,0x00000169,0x61726170,0x0000006d,0x00040005,0x0000016e,0x5234786d, + 0x00000000,0x00040005,0x0000016f,0x61726170,0x0000006d,0x00040005,0x00000171,0x61726170, + 0x0000006d,0x00040005,0x00000173,0x61726170,0x0000006d,0x00040005,0x00000178,0x4734786d, + 0x00000000,0x00040005,0x00000179,0x61726170,0x0000006d,0x00040005,0x0000017b,0x61726170, + 0x0000006d,0x00040005,0x0000017d,0x61726170,0x0000006d,0x00040005,0x00000182,0x4234786d, + 0x00000000,0x00040005,0x00000183,0x61726170,0x0000006d,0x00040005,0x00000185,0x61726170, + 0x0000006d,0x00040005,0x00000187,0x61726170,0x0000006d,0x00040005,0x0000018e,0x6b616570, + 0x00000043,0x00040005,0x00000191,0x4d746968,0x00526e69,0x00040005,0x00000198,0x61726170, + 0x0000006d,0x00040005,0x0000019b,0x4d746968,0x00476e69,0x00040005,0x000001a1,0x61726170, + 0x0000006d,0x00040005,0x000001a4,0x4d746968,0x00426e69,0x00040005,0x000001aa,0x61726170, + 0x0000006d,0x00040005,0x000001ad,0x4d746968,0x00527861,0x00040005,0x000001b9,0x61726170, + 0x0000006d,0x00040005,0x000001bc,0x4d746968,0x00477861,0x00040005,0x000001c8,0x61726170, + 0x0000006d,0x00040005,0x000001cb,0x4d746968,0x00427861,0x00040005,0x000001d7,0x61726170, + 0x0000006d,0x00040005,0x000001da,0x65626f6c,0x00000052,0x00040005,0x000001df,0x65626f6c, + 0x00000047,0x00040005,0x000001e4,0x65626f6c,0x00000042,0x00040005,0x000001e9,0x65626f6c, + 0x00000000,0x00040005,0x000001eb,0x61726170,0x0000006d,0x00040005,0x000001ed,0x61726170, + 0x0000006d,0x00040005,0x000001ef,0x61726170,0x0000006d,0x00040005,0x000001f9,0x4c706372, + 0x00000000,0x00040005,0x000001fd,0x61726170,0x0000006d,0x00030005,0x00000239,0x00007069, + 0x00060005,0x0000023b,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x0000023d, + 0x00004350,0x00040006,0x0000023d,0x00000000,0x0063646e,0x00040006,0x0000023d,0x00000001, + 0x006e6f63,0x00060006,0x0000023d,0x00000002,0x7074756f,0x69537475,0x0000657a,0x00030005, + 0x0000023f,0x00006370,0x00030005,0x00000246,0x00000063,0x00040005,0x00000247,0x61726170, + 0x0000006d,0x00040005,0x00000248,0x61726170,0x0000006d,0x00040005,0x00000249,0x61726170, + 0x0000006d,0x00040005,0x0000024a,0x61726170,0x0000006d,0x00040005,0x0000024c,0x61726170, + 0x0000006d,0x00050005,0x00000258,0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x00000058, + 0x00000021,0x00000000,0x00040047,0x00000058,0x00000022,0x00000000,0x00040047,0x0000023b, + 0x0000001e,0x00000000,0x00030047,0x0000023d,0x00000002,0x00050048,0x0000023d,0x00000000, + 0x00000023,0x00000000,0x00050048,0x0000023d,0x00000001,0x00000023,0x00000010,0x00050048, + 0x0000023d,0x00000002,0x00000023,0x00000020,0x00040047,0x00000258,0x0000001e,0x00000000, + 0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020, + 0x00040020,0x00000007,0x00000007,0x00000006,0x00040021,0x00000008,0x00000006,0x00000007, + 0x00060021,0x00000012,0x00000006,0x00000007,0x00000007,0x00000007,0x00040015,0x0000001d, + 0x00000020,0x00000001,0x00040017,0x0000001e,0x0000001d,0x00000002,0x00040020,0x0000001f, + 0x00000007,0x0000001e,0x00040017,0x00000020,0x00000006,0x00000004,0x00040021,0x00000021, + 0x00000020,0x0000001f,0x00060021,0x00000025,0x00000002,0x00000007,0x00000007,0x00000007, + 0x00040015,0x0000002b,0x00000020,0x00000000,0x00040017,0x0000002c,0x0000002b,0x00000002, + 0x00040020,0x0000002d,0x00000007,0x0000002c,0x00040017,0x0000002e,0x0000002b,0x00000004, + 0x00040020,0x0000002f,0x00000007,0x0000002e,0x00080021,0x00000030,0x00000002,0x00000007, + 0x00000007,0x00000007,0x0000002d,0x0000002f,0x0004002b,0x00000006,0x00000038,0x3f800000, + 0x0004002b,0x00000006,0x00000042,0x00000000,0x00090019,0x00000055,0x00000006,0x00000001, + 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000056,0x00000055, + 0x00040020,0x00000057,0x00000000,0x00000056,0x0004003b,0x00000057,0x00000058,0x00000000, + 0x0004002b,0x0000001d,0x0000005a,0x00000000,0x0005002c,0x0000001e,0x0000005f,0x0000005a, + 0x0000005a,0x0004002b,0x0000001d,0x00000061,0x00000001,0x0005002c,0x0000001e,0x00000062, + 0x00000061,0x00000061,0x00040017,0x0000006c,0x00000006,0x00000003,0x00040020,0x0000006d, + 0x00000007,0x0000006c,0x0004002b,0x0000001d,0x00000070,0xffffffff,0x0005002c,0x0000001e, + 0x00000071,0x0000005a,0x00000070,0x0005002c,0x0000001e,0x00000078,0x00000070,0x0000005a, + 0x0005002c,0x0000001e,0x00000084,0x00000061,0x0000005a,0x0005002c,0x0000001e,0x0000008b, + 0x0000005a,0x00000061,0x0004002b,0x0000002b,0x00000091,0x00000000,0x0004002b,0x0000002b, + 0x00000095,0x00000001,0x0004002b,0x0000002b,0x00000099,0x00000002,0x0004002b,0x00000006, + 0x000000f4,0x3f000000,0x0004002b,0x00000006,0x0000011c,0x3e800000,0x0004002b,0x00000006, + 0x0000014c,0xbf000000,0x00040017,0x0000018c,0x00000006,0x00000002,0x00040020,0x0000018d, + 0x00000007,0x0000018c,0x0004002b,0x00000006,0x0000018f,0xc0800000,0x0005002c,0x0000018c, + 0x00000190,0x00000038,0x0000018f,0x0004002b,0x00000006,0x00000195,0x40800000,0x0004002b, + 0x00000006,0x000001ea,0xbe400000,0x00040020,0x000001f4,0x00000007,0x0000002b,0x00040020, + 0x0000023a,0x00000001,0x0000018c,0x0004003b,0x0000023a,0x0000023b,0x00000001,0x0005001e, + 0x0000023d,0x00000020,0x0000002e,0x0000018c,0x00040020,0x0000023e,0x00000009,0x0000023d, + 0x0004003b,0x0000023e,0x0000023f,0x00000009,0x0004002b,0x0000001d,0x00000240,0x00000002, + 0x00040020,0x00000241,0x00000009,0x0000018c,0x00040020,0x0000024d,0x00000009,0x0000002e, + 0x00040020,0x00000257,0x00000003,0x00000020,0x0004003b,0x00000257,0x00000258,0x00000003, + 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b, + 0x0000002d,0x00000239,0x00000007,0x0004003b,0x0000006d,0x00000246,0x00000007,0x0004003b, + 0x00000007,0x00000247,0x00000007,0x0004003b,0x00000007,0x00000248,0x00000007,0x0004003b, + 0x00000007,0x00000249,0x00000007,0x0004003b,0x0000002d,0x0000024a,0x00000007,0x0004003b, + 0x0000002f,0x0000024c,0x00000007,0x0004003d,0x0000018c,0x0000023c,0x0000023b,0x00050041, + 0x00000241,0x00000242,0x0000023f,0x00000240,0x0004003d,0x0000018c,0x00000243,0x00000242, + 0x00050085,0x0000018c,0x00000244,0x0000023c,0x00000243,0x0004006d,0x0000002c,0x00000245, + 0x00000244,0x0003003e,0x00000239,0x00000245,0x0004003d,0x0000002c,0x0000024b,0x00000239, + 0x0003003e,0x0000024a,0x0000024b,0x00050041,0x0000024d,0x0000024e,0x0000023f,0x00000061, + 0x0004003d,0x0000002e,0x0000024f,0x0000024e,0x0003003e,0x0000024c,0x0000024f,0x00090039, + 0x00000002,0x00000250,0x00000036,0x00000247,0x00000248,0x00000249,0x0000024a,0x0000024c, + 0x0004003d,0x00000006,0x00000251,0x00000247,0x00050041,0x00000007,0x00000252,0x00000246, + 0x00000091,0x0003003e,0x00000252,0x00000251,0x0004003d,0x00000006,0x00000253,0x00000248, + 0x00050041,0x00000007,0x00000254,0x00000246,0x00000095,0x0003003e,0x00000254,0x00000253, + 0x0004003d,0x00000006,0x00000255,0x00000249,0x00050041,0x00000007,0x00000256,0x00000246, + 0x00000099,0x0003003e,0x00000256,0x00000255,0x0004003d,0x0000006c,0x00000259,0x00000246, + 0x00050051,0x00000006,0x0000025a,0x00000259,0x00000000,0x00050051,0x00000006,0x0000025b, + 0x00000259,0x00000001,0x00050051,0x00000006,0x0000025c,0x00000259,0x00000002,0x00070050, + 0x00000020,0x0000025d,0x0000025a,0x0000025b,0x0000025c,0x00000038,0x0003003e,0x00000258, + 0x0000025d,0x000100fd,0x00010038,0x00050036,0x00000006,0x0000000a,0x00000000,0x00000008, + 0x00030037,0x00000007,0x00000009,0x000200f8,0x0000000b,0x0004003d,0x00000006,0x00000039, + 0x00000009,0x00050088,0x00000006,0x0000003a,0x00000038,0x00000039,0x000200fe,0x0000003a, + 0x00010038,0x00050036,0x00000006,0x0000000d,0x00000000,0x00000008,0x00030037,0x00000007, + 0x0000000c,0x000200f8,0x0000000e,0x0004003d,0x00000006,0x0000003d,0x0000000c,0x00050088, + 0x00000006,0x0000003e,0x00000038,0x0000003d,0x000200fe,0x0000003e,0x00010038,0x00050036, + 0x00000006,0x00000010,0x00000000,0x00000008,0x00030037,0x00000007,0x0000000f,0x000200f8, + 0x00000011,0x0004003d,0x00000006,0x00000041,0x0000000f,0x0008000c,0x00000006,0x00000043, + 0x00000001,0x0000002b,0x00000041,0x00000042,0x00000038,0x000200fe,0x00000043,0x00010038, + 0x00050036,0x00000006,0x00000016,0x00000000,0x00000012,0x00030037,0x00000007,0x00000013, + 0x00030037,0x00000007,0x00000014,0x00030037,0x00000007,0x00000015,0x000200f8,0x00000017, + 0x0004003d,0x00000006,0x00000046,0x00000013,0x0004003d,0x00000006,0x00000047,0x00000014, + 0x0004003d,0x00000006,0x00000048,0x00000015,0x0007000c,0x00000006,0x00000049,0x00000001, + 0x00000025,0x00000047,0x00000048,0x0007000c,0x00000006,0x0000004a,0x00000001,0x00000025, + 0x00000046,0x00000049,0x000200fe,0x0000004a,0x00010038,0x00050036,0x00000006,0x0000001b, + 0x00000000,0x00000012,0x00030037,0x00000007,0x00000018,0x00030037,0x00000007,0x00000019, + 0x00030037,0x00000007,0x0000001a,0x000200f8,0x0000001c,0x0004003d,0x00000006,0x0000004d, + 0x00000018,0x0004003d,0x00000006,0x0000004e,0x00000019,0x0004003d,0x00000006,0x0000004f, + 0x0000001a,0x0007000c,0x00000006,0x00000050,0x00000001,0x00000028,0x0000004e,0x0000004f, + 0x0007000c,0x00000006,0x00000051,0x00000001,0x00000028,0x0000004d,0x00000050,0x000200fe, + 0x00000051,0x00010038,0x00050036,0x00000020,0x00000023,0x00000000,0x00000021,0x00030037, + 0x0000001f,0x00000022,0x000200f8,0x00000024,0x0004003b,0x0000001f,0x00000054,0x00000007, + 0x0004003d,0x00000056,0x00000059,0x00000058,0x00040064,0x00000055,0x0000005b,0x00000059, + 0x00050067,0x0000001e,0x0000005c,0x0000005b,0x0000005a,0x0003003e,0x00000054,0x0000005c, + 0x0004003d,0x00000056,0x0000005d,0x00000058,0x0004003d,0x0000001e,0x0000005e,0x00000022, + 0x0004003d,0x0000001e,0x00000060,0x00000054,0x00050082,0x0000001e,0x00000063,0x00000060, + 0x00000062,0x0008000c,0x0000001e,0x00000064,0x00000001,0x0000002d,0x0000005e,0x0000005f, + 0x00000063,0x00040064,0x00000055,0x00000065,0x0000005d,0x0007005f,0x00000020,0x00000066, + 0x00000065,0x00000064,0x00000002,0x0000005a,0x000200fe,0x00000066,0x00010038,0x00050036, + 0x00000002,0x00000029,0x00000000,0x00000025,0x00030037,0x00000007,0x00000026,0x00030037, + 0x00000007,0x00000027,0x00030037,0x00000007,0x00000028,0x000200f8,0x0000002a,0x000100fd, + 0x00010038,0x00050036,0x00000002,0x00000036,0x00000000,0x00000030,0x00030037,0x00000007, + 0x00000031,0x00030037,0x00000007,0x00000032,0x00030037,0x00000007,0x00000033,0x00030037, + 0x0000002d,0x00000034,0x00030037,0x0000002f,0x00000035,0x000200f8,0x00000037,0x0004003b, + 0x0000001f,0x00000069,0x00000007,0x0004003b,0x0000006d,0x0000006e,0x00000007,0x0004003b, + 0x0000001f,0x00000073,0x00000007,0x0004003b,0x0000006d,0x00000076,0x00000007,0x0004003b, + 0x0000001f,0x0000007a,0x00000007,0x0004003b,0x0000006d,0x0000007d,0x00000007,0x0004003b, + 0x0000001f,0x0000007e,0x00000007,0x0004003b,0x0000006d,0x00000082,0x00000007,0x0004003b, + 0x0000001f,0x00000086,0x00000007,0x0004003b,0x0000006d,0x00000089,0x00000007,0x0004003b, + 0x0000001f,0x0000008d,0x00000007,0x0004003b,0x00000007,0x00000090,0x00000007,0x0004003b, + 0x00000007,0x00000094,0x00000007,0x0004003b,0x00000007,0x00000098,0x00000007,0x0004003b, + 0x00000007,0x0000009c,0x00000007,0x0004003b,0x00000007,0x0000009f,0x00000007,0x0004003b, + 0x00000007,0x000000a2,0x00000007,0x0004003b,0x00000007,0x000000a5,0x00000007,0x0004003b, + 0x00000007,0x000000a8,0x00000007,0x0004003b,0x00000007,0x000000ab,0x00000007,0x0004003b, + 0x00000007,0x000000ae,0x00000007,0x0004003b,0x00000007,0x000000b1,0x00000007,0x0004003b, + 0x00000007,0x000000b4,0x00000007,0x0004003b,0x00000007,0x000000b7,0x00000007,0x0004003b, + 0x00000007,0x000000ba,0x00000007,0x0004003b,0x00000007,0x000000bd,0x00000007,0x0004003b, + 0x00000007,0x000000c0,0x00000007,0x0004003b,0x00000007,0x000000c2,0x00000007,0x0004003b, + 0x00000007,0x000000c4,0x00000007,0x0004003b,0x00000007,0x000000ca,0x00000007,0x0004003b, + 0x00000007,0x000000cc,0x00000007,0x0004003b,0x00000007,0x000000ce,0x00000007,0x0004003b, + 0x00000007,0x000000d4,0x00000007,0x0004003b,0x00000007,0x000000d6,0x00000007,0x0004003b, + 0x00000007,0x000000d8,0x00000007,0x0004003b,0x00000007,0x000000de,0x00000007,0x0004003b, + 0x00000007,0x000000e0,0x00000007,0x0004003b,0x00000007,0x000000e2,0x00000007,0x0004003b, + 0x00000007,0x000000e8,0x00000007,0x0004003b,0x00000007,0x000000ea,0x00000007,0x0004003b, + 0x00000007,0x000000ec,0x00000007,0x0004003b,0x00000007,0x000000f2,0x00000007,0x0004003b, + 0x00000007,0x000000fb,0x00000007,0x0004003b,0x00000007,0x00000103,0x00000007,0x0004003b, + 0x00000007,0x0000010b,0x00000007,0x0004003b,0x00000007,0x00000113,0x00000007,0x0004003b, + 0x00000007,0x0000011b,0x00000007,0x0004003b,0x00000007,0x0000012c,0x00000007,0x0004003b, + 0x00000007,0x0000012e,0x00000007,0x0004003b,0x00000007,0x00000130,0x00000007,0x0004003b, + 0x00000007,0x00000133,0x00000007,0x0004003b,0x00000007,0x00000134,0x00000007,0x0004003b, + 0x00000007,0x00000136,0x00000007,0x0004003b,0x00000007,0x00000139,0x00000007,0x0004003b, + 0x00000007,0x0000013b,0x00000007,0x0004003b,0x00000007,0x0000013d,0x00000007,0x0004003b, + 0x00000007,0x00000140,0x00000007,0x0004003b,0x00000007,0x00000141,0x00000007,0x0004003b, + 0x00000007,0x00000143,0x00000007,0x0004003b,0x00000007,0x00000147,0x00000007,0x0004003b, + 0x00000007,0x0000014a,0x00000007,0x0004003b,0x00000007,0x00000150,0x00000007,0x0004003b, + 0x00000007,0x00000151,0x00000007,0x0004003b,0x00000007,0x00000153,0x00000007,0x0004003b, + 0x00000007,0x00000155,0x00000007,0x0004003b,0x00000007,0x0000015a,0x00000007,0x0004003b, + 0x00000007,0x0000015b,0x00000007,0x0004003b,0x00000007,0x0000015d,0x00000007,0x0004003b, + 0x00000007,0x0000015f,0x00000007,0x0004003b,0x00000007,0x00000164,0x00000007,0x0004003b, + 0x00000007,0x00000165,0x00000007,0x0004003b,0x00000007,0x00000167,0x00000007,0x0004003b, + 0x00000007,0x00000169,0x00000007,0x0004003b,0x00000007,0x0000016e,0x00000007,0x0004003b, + 0x00000007,0x0000016f,0x00000007,0x0004003b,0x00000007,0x00000171,0x00000007,0x0004003b, + 0x00000007,0x00000173,0x00000007,0x0004003b,0x00000007,0x00000178,0x00000007,0x0004003b, + 0x00000007,0x00000179,0x00000007,0x0004003b,0x00000007,0x0000017b,0x00000007,0x0004003b, + 0x00000007,0x0000017d,0x00000007,0x0004003b,0x00000007,0x00000182,0x00000007,0x0004003b, + 0x00000007,0x00000183,0x00000007,0x0004003b,0x00000007,0x00000185,0x00000007,0x0004003b, + 0x00000007,0x00000187,0x00000007,0x0004003b,0x0000018d,0x0000018e,0x00000007,0x0004003b, + 0x00000007,0x00000191,0x00000007,0x0004003b,0x00000007,0x00000198,0x00000007,0x0004003b, + 0x00000007,0x0000019b,0x00000007,0x0004003b,0x00000007,0x000001a1,0x00000007,0x0004003b, + 0x00000007,0x000001a4,0x00000007,0x0004003b,0x00000007,0x000001aa,0x00000007,0x0004003b, + 0x00000007,0x000001ad,0x00000007,0x0004003b,0x00000007,0x000001b9,0x00000007,0x0004003b, + 0x00000007,0x000001bc,0x00000007,0x0004003b,0x00000007,0x000001c8,0x00000007,0x0004003b, + 0x00000007,0x000001cb,0x00000007,0x0004003b,0x00000007,0x000001d7,0x00000007,0x0004003b, + 0x00000007,0x000001da,0x00000007,0x0004003b,0x00000007,0x000001df,0x00000007,0x0004003b, + 0x00000007,0x000001e4,0x00000007,0x0004003b,0x00000007,0x000001e9,0x00000007,0x0004003b, + 0x00000007,0x000001eb,0x00000007,0x0004003b,0x00000007,0x000001ed,0x00000007,0x0004003b, + 0x00000007,0x000001ef,0x00000007,0x0004003b,0x00000007,0x000001f9,0x00000007,0x0004003b, + 0x00000007,0x000001fd,0x00000007,0x0004003d,0x0000002c,0x0000006a,0x00000034,0x0004007c, + 0x0000001e,0x0000006b,0x0000006a,0x0003003e,0x00000069,0x0000006b,0x0004003d,0x0000001e, + 0x0000006f,0x00000069,0x00050080,0x0000001e,0x00000072,0x0000006f,0x00000071,0x0003003e, + 0x00000073,0x00000072,0x00050039,0x00000020,0x00000074,0x00000023,0x00000073,0x0008004f, + 0x0000006c,0x00000075,0x00000074,0x00000074,0x00000000,0x00000001,0x00000002,0x0003003e, + 0x0000006e,0x00000075,0x0004003d,0x0000001e,0x00000077,0x00000069,0x00050080,0x0000001e, + 0x00000079,0x00000077,0x00000078,0x0003003e,0x0000007a,0x00000079,0x00050039,0x00000020, + 0x0000007b,0x00000023,0x0000007a,0x0008004f,0x0000006c,0x0000007c,0x0000007b,0x0000007b, + 0x00000000,0x00000001,0x00000002,0x0003003e,0x00000076,0x0000007c,0x0004003d,0x0000001e, + 0x0000007f,0x00000069,0x0003003e,0x0000007e,0x0000007f,0x00050039,0x00000020,0x00000080, + 0x00000023,0x0000007e,0x0008004f,0x0000006c,0x00000081,0x00000080,0x00000080,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x0000007d,0x00000081,0x0004003d,0x0000001e,0x00000083, + 0x00000069,0x00050080,0x0000001e,0x00000085,0x00000083,0x00000084,0x0003003e,0x00000086, + 0x00000085,0x00050039,0x00000020,0x00000087,0x00000023,0x00000086,0x0008004f,0x0000006c, + 0x00000088,0x00000087,0x00000087,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000082, + 0x00000088,0x0004003d,0x0000001e,0x0000008a,0x00000069,0x00050080,0x0000001e,0x0000008c, + 0x0000008a,0x0000008b,0x0003003e,0x0000008d,0x0000008c,0x00050039,0x00000020,0x0000008e, + 0x00000023,0x0000008d,0x0008004f,0x0000006c,0x0000008f,0x0000008e,0x0000008e,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x00000089,0x0000008f,0x00050041,0x00000007,0x00000092, + 0x0000006e,0x00000091,0x0004003d,0x00000006,0x00000093,0x00000092,0x0003003e,0x00000090, + 0x00000093,0x00050041,0x00000007,0x00000096,0x0000006e,0x00000095,0x0004003d,0x00000006, + 0x00000097,0x00000096,0x0003003e,0x00000094,0x00000097,0x00050041,0x00000007,0x0000009a, + 0x0000006e,0x00000099,0x0004003d,0x00000006,0x0000009b,0x0000009a,0x0003003e,0x00000098, + 0x0000009b,0x00050041,0x00000007,0x0000009d,0x00000076,0x00000091,0x0004003d,0x00000006, + 0x0000009e,0x0000009d,0x0003003e,0x0000009c,0x0000009e,0x00050041,0x00000007,0x000000a0, + 0x00000076,0x00000095,0x0004003d,0x00000006,0x000000a1,0x000000a0,0x0003003e,0x0000009f, + 0x000000a1,0x00050041,0x00000007,0x000000a3,0x00000076,0x00000099,0x0004003d,0x00000006, + 0x000000a4,0x000000a3,0x0003003e,0x000000a2,0x000000a4,0x00050041,0x00000007,0x000000a6, + 0x0000007d,0x00000091,0x0004003d,0x00000006,0x000000a7,0x000000a6,0x0003003e,0x000000a5, + 0x000000a7,0x00050041,0x00000007,0x000000a9,0x0000007d,0x00000095,0x0004003d,0x00000006, + 0x000000aa,0x000000a9,0x0003003e,0x000000a8,0x000000aa,0x00050041,0x00000007,0x000000ac, + 0x0000007d,0x00000099,0x0004003d,0x00000006,0x000000ad,0x000000ac,0x0003003e,0x000000ab, + 0x000000ad,0x00050041,0x00000007,0x000000af,0x00000082,0x00000091,0x0004003d,0x00000006, + 0x000000b0,0x000000af,0x0003003e,0x000000ae,0x000000b0,0x00050041,0x00000007,0x000000b2, + 0x00000082,0x00000095,0x0004003d,0x00000006,0x000000b3,0x000000b2,0x0003003e,0x000000b1, + 0x000000b3,0x00050041,0x00000007,0x000000b5,0x00000082,0x00000099,0x0004003d,0x00000006, + 0x000000b6,0x000000b5,0x0003003e,0x000000b4,0x000000b6,0x00050041,0x00000007,0x000000b8, + 0x00000089,0x00000091,0x0004003d,0x00000006,0x000000b9,0x000000b8,0x0003003e,0x000000b7, + 0x000000b9,0x00050041,0x00000007,0x000000bb,0x00000089,0x00000095,0x0004003d,0x00000006, + 0x000000bc,0x000000bb,0x0003003e,0x000000ba,0x000000bc,0x00050041,0x00000007,0x000000be, + 0x00000089,0x00000099,0x0004003d,0x00000006,0x000000bf,0x000000be,0x0003003e,0x000000bd, + 0x000000bf,0x0004003d,0x00000006,0x000000c1,0x00000090,0x0003003e,0x000000c0,0x000000c1, + 0x0004003d,0x00000006,0x000000c3,0x00000094,0x0003003e,0x000000c2,0x000000c3,0x0004003d, + 0x00000006,0x000000c5,0x00000098,0x0003003e,0x000000c4,0x000000c5,0x00070039,0x00000002, + 0x000000c6,0x00000029,0x000000c0,0x000000c2,0x000000c4,0x0004003d,0x00000006,0x000000c7, + 0x000000c0,0x0003003e,0x00000090,0x000000c7,0x0004003d,0x00000006,0x000000c8,0x000000c2, + 0x0003003e,0x00000094,0x000000c8,0x0004003d,0x00000006,0x000000c9,0x000000c4,0x0003003e, + 0x00000098,0x000000c9,0x0004003d,0x00000006,0x000000cb,0x0000009c,0x0003003e,0x000000ca, + 0x000000cb,0x0004003d,0x00000006,0x000000cd,0x0000009f,0x0003003e,0x000000cc,0x000000cd, + 0x0004003d,0x00000006,0x000000cf,0x000000a2,0x0003003e,0x000000ce,0x000000cf,0x00070039, + 0x00000002,0x000000d0,0x00000029,0x000000ca,0x000000cc,0x000000ce,0x0004003d,0x00000006, + 0x000000d1,0x000000ca,0x0003003e,0x0000009c,0x000000d1,0x0004003d,0x00000006,0x000000d2, + 0x000000cc,0x0003003e,0x0000009f,0x000000d2,0x0004003d,0x00000006,0x000000d3,0x000000ce, + 0x0003003e,0x000000a2,0x000000d3,0x0004003d,0x00000006,0x000000d5,0x000000a5,0x0003003e, + 0x000000d4,0x000000d5,0x0004003d,0x00000006,0x000000d7,0x000000a8,0x0003003e,0x000000d6, + 0x000000d7,0x0004003d,0x00000006,0x000000d9,0x000000ab,0x0003003e,0x000000d8,0x000000d9, + 0x00070039,0x00000002,0x000000da,0x00000029,0x000000d4,0x000000d6,0x000000d8,0x0004003d, + 0x00000006,0x000000db,0x000000d4,0x0003003e,0x000000a5,0x000000db,0x0004003d,0x00000006, + 0x000000dc,0x000000d6,0x0003003e,0x000000a8,0x000000dc,0x0004003d,0x00000006,0x000000dd, + 0x000000d8,0x0003003e,0x000000ab,0x000000dd,0x0004003d,0x00000006,0x000000df,0x000000ae, + 0x0003003e,0x000000de,0x000000df,0x0004003d,0x00000006,0x000000e1,0x000000b1,0x0003003e, + 0x000000e0,0x000000e1,0x0004003d,0x00000006,0x000000e3,0x000000b4,0x0003003e,0x000000e2, + 0x000000e3,0x00070039,0x00000002,0x000000e4,0x00000029,0x000000de,0x000000e0,0x000000e2, + 0x0004003d,0x00000006,0x000000e5,0x000000de,0x0003003e,0x000000ae,0x000000e5,0x0004003d, + 0x00000006,0x000000e6,0x000000e0,0x0003003e,0x000000b1,0x000000e6,0x0004003d,0x00000006, + 0x000000e7,0x000000e2,0x0003003e,0x000000b4,0x000000e7,0x0004003d,0x00000006,0x000000e9, + 0x000000b7,0x0003003e,0x000000e8,0x000000e9,0x0004003d,0x00000006,0x000000eb,0x000000ba, + 0x0003003e,0x000000ea,0x000000eb,0x0004003d,0x00000006,0x000000ed,0x000000bd,0x0003003e, + 0x000000ec,0x000000ed,0x00070039,0x00000002,0x000000ee,0x00000029,0x000000e8,0x000000ea, + 0x000000ec,0x0004003d,0x00000006,0x000000ef,0x000000e8,0x0003003e,0x000000b7,0x000000ef, + 0x0004003d,0x00000006,0x000000f0,0x000000ea,0x0003003e,0x000000ba,0x000000f0,0x0004003d, + 0x00000006,0x000000f1,0x000000ec,0x0003003e,0x000000bd,0x000000f1,0x0004003d,0x00000006, + 0x000000f3,0x00000098,0x00050085,0x00000006,0x000000f5,0x000000f3,0x000000f4,0x0004003d, + 0x00000006,0x000000f6,0x00000090,0x00050085,0x00000006,0x000000f7,0x000000f6,0x000000f4, + 0x0004003d,0x00000006,0x000000f8,0x00000094,0x00050081,0x00000006,0x000000f9,0x000000f7, + 0x000000f8,0x00050081,0x00000006,0x000000fa,0x000000f5,0x000000f9,0x0003003e,0x000000f2, + 0x000000fa,0x0004003d,0x00000006,0x000000fc,0x000000a2,0x00050085,0x00000006,0x000000fd, + 0x000000fc,0x000000f4,0x0004003d,0x00000006,0x000000fe,0x0000009c,0x00050085,0x00000006, + 0x000000ff,0x000000fe,0x000000f4,0x0004003d,0x00000006,0x00000100,0x0000009f,0x00050081, + 0x00000006,0x00000101,0x000000ff,0x00000100,0x00050081,0x00000006,0x00000102,0x000000fd, + 0x00000101,0x0003003e,0x000000fb,0x00000102,0x0004003d,0x00000006,0x00000104,0x000000ab, + 0x00050085,0x00000006,0x00000105,0x00000104,0x000000f4,0x0004003d,0x00000006,0x00000106, + 0x000000a5,0x00050085,0x00000006,0x00000107,0x00000106,0x000000f4,0x0004003d,0x00000006, + 0x00000108,0x000000a8,0x00050081,0x00000006,0x00000109,0x00000107,0x00000108,0x00050081, + 0x00000006,0x0000010a,0x00000105,0x00000109,0x0003003e,0x00000103,0x0000010a,0x0004003d, + 0x00000006,0x0000010c,0x000000b4,0x00050085,0x00000006,0x0000010d,0x0000010c,0x000000f4, + 0x0004003d,0x00000006,0x0000010e,0x000000ae,0x00050085,0x00000006,0x0000010f,0x0000010e, + 0x000000f4,0x0004003d,0x00000006,0x00000110,0x000000b1,0x00050081,0x00000006,0x00000111, + 0x0000010f,0x00000110,0x00050081,0x00000006,0x00000112,0x0000010d,0x00000111,0x0003003e, + 0x0000010b,0x00000112,0x0004003d,0x00000006,0x00000114,0x000000bd,0x00050085,0x00000006, + 0x00000115,0x00000114,0x000000f4,0x0004003d,0x00000006,0x00000116,0x000000b7,0x00050085, + 0x00000006,0x00000117,0x00000116,0x000000f4,0x0004003d,0x00000006,0x00000118,0x000000ba, + 0x00050081,0x00000006,0x00000119,0x00000117,0x00000118,0x00050081,0x00000006,0x0000011a, + 0x00000115,0x00000119,0x0003003e,0x00000113,0x0000011a,0x0004003d,0x00000006,0x0000011d, + 0x000000f2,0x00050085,0x00000006,0x0000011e,0x0000011c,0x0000011d,0x0004003d,0x00000006, + 0x0000011f,0x000000fb,0x00050085,0x00000006,0x00000120,0x0000011c,0x0000011f,0x00050081, + 0x00000006,0x00000121,0x0000011e,0x00000120,0x0004003d,0x00000006,0x00000122,0x0000010b, + 0x00050085,0x00000006,0x00000123,0x0000011c,0x00000122,0x00050081,0x00000006,0x00000124, + 0x00000121,0x00000123,0x0004003d,0x00000006,0x00000125,0x00000113,0x00050085,0x00000006, + 0x00000126,0x0000011c,0x00000125,0x00050081,0x00000006,0x00000127,0x00000124,0x00000126, + 0x0004003d,0x00000006,0x00000128,0x00000103,0x00050083,0x00000006,0x00000129,0x00000127, + 0x00000128,0x0003003e,0x0000011b,0x00000129,0x0004003d,0x00000006,0x0000012a,0x0000011b, + 0x0006000c,0x00000006,0x0000012b,0x00000001,0x00000004,0x0000012a,0x0004003d,0x00000006, + 0x0000012d,0x000000f2,0x0003003e,0x0000012c,0x0000012d,0x0004003d,0x00000006,0x0000012f, + 0x000000fb,0x0003003e,0x0000012e,0x0000012f,0x0004003d,0x00000006,0x00000131,0x00000103, + 0x0003003e,0x00000130,0x00000131,0x00070039,0x00000006,0x00000132,0x0000001b,0x0000012c, + 0x0000012e,0x00000130,0x0003003e,0x00000133,0x00000132,0x0004003d,0x00000006,0x00000135, + 0x0000010b,0x0003003e,0x00000134,0x00000135,0x0004003d,0x00000006,0x00000137,0x00000113, + 0x0003003e,0x00000136,0x00000137,0x00070039,0x00000006,0x00000138,0x0000001b,0x00000133, + 0x00000134,0x00000136,0x0004003d,0x00000006,0x0000013a,0x000000f2,0x0003003e,0x00000139, + 0x0000013a,0x0004003d,0x00000006,0x0000013c,0x000000fb,0x0003003e,0x0000013b,0x0000013c, + 0x0004003d,0x00000006,0x0000013e,0x00000103,0x0003003e,0x0000013d,0x0000013e,0x00070039, + 0x00000006,0x0000013f,0x00000016,0x00000139,0x0000013b,0x0000013d,0x0003003e,0x00000140, + 0x0000013f,0x0004003d,0x00000006,0x00000142,0x0000010b,0x0003003e,0x00000141,0x00000142, + 0x0004003d,0x00000006,0x00000144,0x00000113,0x0003003e,0x00000143,0x00000144,0x00070039, + 0x00000006,0x00000145,0x00000016,0x00000140,0x00000141,0x00000143,0x00050083,0x00000006, + 0x00000146,0x00000138,0x00000145,0x0003003e,0x00000147,0x00000146,0x00050039,0x00000006, + 0x00000148,0x0000000d,0x00000147,0x00050085,0x00000006,0x00000149,0x0000012b,0x00000148, + 0x0003003e,0x0000014a,0x00000149,0x00050039,0x00000006,0x0000014b,0x00000010,0x0000014a, + 0x0003003e,0x0000011b,0x0000014b,0x0004003d,0x00000006,0x0000014d,0x0000011b,0x00050085, + 0x00000006,0x0000014e,0x0000014c,0x0000014d,0x00050081,0x00000006,0x0000014f,0x0000014e, + 0x00000038,0x0003003e,0x0000011b,0x0000014f,0x0004003d,0x00000006,0x00000152,0x00000090, + 0x0003003e,0x00000151,0x00000152,0x0004003d,0x00000006,0x00000154,0x0000009c,0x0003003e, + 0x00000153,0x00000154,0x0004003d,0x00000006,0x00000156,0x000000ae,0x0003003e,0x00000155, + 0x00000156,0x00070039,0x00000006,0x00000157,0x00000016,0x00000151,0x00000153,0x00000155, + 0x0004003d,0x00000006,0x00000158,0x000000b7,0x0007000c,0x00000006,0x00000159,0x00000001, + 0x00000025,0x00000157,0x00000158,0x0003003e,0x00000150,0x00000159,0x0004003d,0x00000006, + 0x0000015c,0x00000094,0x0003003e,0x0000015b,0x0000015c,0x0004003d,0x00000006,0x0000015e, + 0x0000009f,0x0003003e,0x0000015d,0x0000015e,0x0004003d,0x00000006,0x00000160,0x000000b1, + 0x0003003e,0x0000015f,0x00000160,0x00070039,0x00000006,0x00000161,0x00000016,0x0000015b, + 0x0000015d,0x0000015f,0x0004003d,0x00000006,0x00000162,0x000000ba,0x0007000c,0x00000006, + 0x00000163,0x00000001,0x00000025,0x00000161,0x00000162,0x0003003e,0x0000015a,0x00000163, + 0x0004003d,0x00000006,0x00000166,0x00000098,0x0003003e,0x00000165,0x00000166,0x0004003d, + 0x00000006,0x00000168,0x000000a2,0x0003003e,0x00000167,0x00000168,0x0004003d,0x00000006, + 0x0000016a,0x000000b4,0x0003003e,0x00000169,0x0000016a,0x00070039,0x00000006,0x0000016b, + 0x00000016,0x00000165,0x00000167,0x00000169,0x0004003d,0x00000006,0x0000016c,0x000000bd, + 0x0007000c,0x00000006,0x0000016d,0x00000001,0x00000025,0x0000016b,0x0000016c,0x0003003e, + 0x00000164,0x0000016d,0x0004003d,0x00000006,0x00000170,0x00000090,0x0003003e,0x0000016f, + 0x00000170,0x0004003d,0x00000006,0x00000172,0x0000009c,0x0003003e,0x00000171,0x00000172, + 0x0004003d,0x00000006,0x00000174,0x000000ae,0x0003003e,0x00000173,0x00000174,0x00070039, + 0x00000006,0x00000175,0x0000001b,0x0000016f,0x00000171,0x00000173,0x0004003d,0x00000006, + 0x00000176,0x000000b7,0x0007000c,0x00000006,0x00000177,0x00000001,0x00000028,0x00000175, + 0x00000176,0x0003003e,0x0000016e,0x00000177,0x0004003d,0x00000006,0x0000017a,0x00000094, + 0x0003003e,0x00000179,0x0000017a,0x0004003d,0x00000006,0x0000017c,0x0000009f,0x0003003e, + 0x0000017b,0x0000017c,0x0004003d,0x00000006,0x0000017e,0x000000b1,0x0003003e,0x0000017d, + 0x0000017e,0x00070039,0x00000006,0x0000017f,0x0000001b,0x00000179,0x0000017b,0x0000017d, + 0x0004003d,0x00000006,0x00000180,0x000000ba,0x0007000c,0x00000006,0x00000181,0x00000001, + 0x00000028,0x0000017f,0x00000180,0x0003003e,0x00000178,0x00000181,0x0004003d,0x00000006, + 0x00000184,0x00000098,0x0003003e,0x00000183,0x00000184,0x0004003d,0x00000006,0x00000186, + 0x000000a2,0x0003003e,0x00000185,0x00000186,0x0004003d,0x00000006,0x00000188,0x000000b4, + 0x0003003e,0x00000187,0x00000188,0x00070039,0x00000006,0x00000189,0x0000001b,0x00000183, + 0x00000185,0x00000187,0x0004003d,0x00000006,0x0000018a,0x000000bd,0x0007000c,0x00000006, + 0x0000018b,0x00000001,0x00000028,0x00000189,0x0000018a,0x0003003e,0x00000182,0x0000018b, + 0x0003003e,0x0000018e,0x00000190,0x0004003d,0x00000006,0x00000192,0x00000150,0x0004003d, + 0x00000006,0x00000193,0x000000a5,0x0007000c,0x00000006,0x00000194,0x00000001,0x00000025, + 0x00000192,0x00000193,0x0004003d,0x00000006,0x00000196,0x0000016e,0x00050085,0x00000006, + 0x00000197,0x00000195,0x00000196,0x0003003e,0x00000198,0x00000197,0x00050039,0x00000006, + 0x00000199,0x0000000a,0x00000198,0x00050085,0x00000006,0x0000019a,0x00000194,0x00000199, + 0x0003003e,0x00000191,0x0000019a,0x0004003d,0x00000006,0x0000019c,0x0000015a,0x0004003d, + 0x00000006,0x0000019d,0x000000a8,0x0007000c,0x00000006,0x0000019e,0x00000001,0x00000025, + 0x0000019c,0x0000019d,0x0004003d,0x00000006,0x0000019f,0x00000178,0x00050085,0x00000006, + 0x000001a0,0x00000195,0x0000019f,0x0003003e,0x000001a1,0x000001a0,0x00050039,0x00000006, + 0x000001a2,0x0000000a,0x000001a1,0x00050085,0x00000006,0x000001a3,0x0000019e,0x000001a2, + 0x0003003e,0x0000019b,0x000001a3,0x0004003d,0x00000006,0x000001a5,0x00000164,0x0004003d, + 0x00000006,0x000001a6,0x000000ab,0x0007000c,0x00000006,0x000001a7,0x00000001,0x00000025, + 0x000001a5,0x000001a6,0x0004003d,0x00000006,0x000001a8,0x00000182,0x00050085,0x00000006, + 0x000001a9,0x00000195,0x000001a8,0x0003003e,0x000001aa,0x000001a9,0x00050039,0x00000006, + 0x000001ab,0x0000000a,0x000001aa,0x00050085,0x00000006,0x000001ac,0x000001a7,0x000001ab, + 0x0003003e,0x000001a4,0x000001ac,0x00050041,0x00000007,0x000001ae,0x0000018e,0x00000091, + 0x0004003d,0x00000006,0x000001af,0x000001ae,0x0004003d,0x00000006,0x000001b0,0x0000016e, + 0x0004003d,0x00000006,0x000001b1,0x000000a5,0x0007000c,0x00000006,0x000001b2,0x00000001, + 0x00000028,0x000001b0,0x000001b1,0x00050083,0x00000006,0x000001b3,0x000001af,0x000001b2, + 0x0004003d,0x00000006,0x000001b4,0x00000150,0x00050085,0x00000006,0x000001b5,0x00000195, + 0x000001b4,0x00050041,0x00000007,0x000001b6,0x0000018e,0x00000095,0x0004003d,0x00000006, + 0x000001b7,0x000001b6,0x00050081,0x00000006,0x000001b8,0x000001b5,0x000001b7,0x0003003e, + 0x000001b9,0x000001b8,0x00050039,0x00000006,0x000001ba,0x0000000a,0x000001b9,0x00050085, + 0x00000006,0x000001bb,0x000001b3,0x000001ba,0x0003003e,0x000001ad,0x000001bb,0x00050041, + 0x00000007,0x000001bd,0x0000018e,0x00000091,0x0004003d,0x00000006,0x000001be,0x000001bd, + 0x0004003d,0x00000006,0x000001bf,0x00000178,0x0004003d,0x00000006,0x000001c0,0x000000a8, + 0x0007000c,0x00000006,0x000001c1,0x00000001,0x00000028,0x000001bf,0x000001c0,0x00050083, + 0x00000006,0x000001c2,0x000001be,0x000001c1,0x0004003d,0x00000006,0x000001c3,0x0000015a, + 0x00050085,0x00000006,0x000001c4,0x00000195,0x000001c3,0x00050041,0x00000007,0x000001c5, + 0x0000018e,0x00000095,0x0004003d,0x00000006,0x000001c6,0x000001c5,0x00050081,0x00000006, + 0x000001c7,0x000001c4,0x000001c6,0x0003003e,0x000001c8,0x000001c7,0x00050039,0x00000006, + 0x000001c9,0x0000000a,0x000001c8,0x00050085,0x00000006,0x000001ca,0x000001c2,0x000001c9, + 0x0003003e,0x000001bc,0x000001ca,0x00050041,0x00000007,0x000001cc,0x0000018e,0x00000091, + 0x0004003d,0x00000006,0x000001cd,0x000001cc,0x0004003d,0x00000006,0x000001ce,0x00000182, + 0x0004003d,0x00000006,0x000001cf,0x000000ab,0x0007000c,0x00000006,0x000001d0,0x00000001, + 0x00000028,0x000001ce,0x000001cf,0x00050083,0x00000006,0x000001d1,0x000001cd,0x000001d0, + 0x0004003d,0x00000006,0x000001d2,0x00000164,0x00050085,0x00000006,0x000001d3,0x00000195, + 0x000001d2,0x00050041,0x00000007,0x000001d4,0x0000018e,0x00000095,0x0004003d,0x00000006, + 0x000001d5,0x000001d4,0x00050081,0x00000006,0x000001d6,0x000001d3,0x000001d5,0x0003003e, + 0x000001d7,0x000001d6,0x00050039,0x00000006,0x000001d8,0x0000000a,0x000001d7,0x00050085, + 0x00000006,0x000001d9,0x000001d1,0x000001d8,0x0003003e,0x000001cb,0x000001d9,0x0004003d, + 0x00000006,0x000001db,0x00000191,0x0004007f,0x00000006,0x000001dc,0x000001db,0x0004003d, + 0x00000006,0x000001dd,0x000001ad,0x0007000c,0x00000006,0x000001de,0x00000001,0x00000028, + 0x000001dc,0x000001dd,0x0003003e,0x000001da,0x000001de,0x0004003d,0x00000006,0x000001e0, + 0x0000019b,0x0004007f,0x00000006,0x000001e1,0x000001e0,0x0004003d,0x00000006,0x000001e2, + 0x000001bc,0x0007000c,0x00000006,0x000001e3,0x00000001,0x00000028,0x000001e1,0x000001e2, + 0x0003003e,0x000001df,0x000001e3,0x0004003d,0x00000006,0x000001e5,0x000001a4,0x0004007f, + 0x00000006,0x000001e6,0x000001e5,0x0004003d,0x00000006,0x000001e7,0x000001cb,0x0007000c, + 0x00000006,0x000001e8,0x00000001,0x00000028,0x000001e6,0x000001e7,0x0003003e,0x000001e4, + 0x000001e8,0x0004003d,0x00000006,0x000001ec,0x000001da,0x0003003e,0x000001eb,0x000001ec, + 0x0004003d,0x00000006,0x000001ee,0x000001df,0x0003003e,0x000001ed,0x000001ee,0x0004003d, + 0x00000006,0x000001f0,0x000001e4,0x0003003e,0x000001ef,0x000001f0,0x00070039,0x00000006, + 0x000001f1,0x0000001b,0x000001eb,0x000001ed,0x000001ef,0x0007000c,0x00000006,0x000001f2, + 0x00000001,0x00000025,0x000001f1,0x00000042,0x0007000c,0x00000006,0x000001f3,0x00000001, + 0x00000028,0x000001ea,0x000001f2,0x00050041,0x000001f4,0x000001f5,0x00000035,0x00000091, + 0x0004003d,0x0000002b,0x000001f6,0x000001f5,0x0004007c,0x00000006,0x000001f7,0x000001f6, + 0x00050085,0x00000006,0x000001f8,0x000001f3,0x000001f7,0x0003003e,0x000001e9,0x000001f8, + 0x0004003d,0x00000006,0x000001fa,0x000001e9,0x00050085,0x00000006,0x000001fb,0x00000195, + 0x000001fa,0x00050081,0x00000006,0x000001fc,0x000001fb,0x00000038,0x0003003e,0x000001fd, + 0x000001fc,0x00050039,0x00000006,0x000001fe,0x0000000d,0x000001fd,0x0003003e,0x000001f9, + 0x000001fe,0x0004003d,0x00000006,0x000001ff,0x000001e9,0x0004003d,0x00000006,0x00000200, + 0x00000090,0x00050085,0x00000006,0x00000201,0x000001ff,0x00000200,0x0004003d,0x00000006, + 0x00000202,0x000001e9,0x0004003d,0x00000006,0x00000203,0x0000009c,0x00050085,0x00000006, + 0x00000204,0x00000202,0x00000203,0x00050081,0x00000006,0x00000205,0x00000201,0x00000204, + 0x0004003d,0x00000006,0x00000206,0x000001e9,0x0004003d,0x00000006,0x00000207,0x000000b7, + 0x00050085,0x00000006,0x00000208,0x00000206,0x00000207,0x00050081,0x00000006,0x00000209, + 0x00000205,0x00000208,0x0004003d,0x00000006,0x0000020a,0x000001e9,0x0004003d,0x00000006, + 0x0000020b,0x000000ae,0x00050085,0x00000006,0x0000020c,0x0000020a,0x0000020b,0x00050081, + 0x00000006,0x0000020d,0x00000209,0x0000020c,0x0004003d,0x00000006,0x0000020e,0x000000a5, + 0x00050081,0x00000006,0x0000020f,0x0000020d,0x0000020e,0x0004003d,0x00000006,0x00000210, + 0x000001f9,0x00050085,0x00000006,0x00000211,0x0000020f,0x00000210,0x0003003e,0x00000031, + 0x00000211,0x0004003d,0x00000006,0x00000212,0x000001e9,0x0004003d,0x00000006,0x00000213, + 0x00000094,0x00050085,0x00000006,0x00000214,0x00000212,0x00000213,0x0004003d,0x00000006, + 0x00000215,0x000001e9,0x0004003d,0x00000006,0x00000216,0x0000009f,0x00050085,0x00000006, + 0x00000217,0x00000215,0x00000216,0x00050081,0x00000006,0x00000218,0x00000214,0x00000217, + 0x0004003d,0x00000006,0x00000219,0x000001e9,0x0004003d,0x00000006,0x0000021a,0x000000ba, + 0x00050085,0x00000006,0x0000021b,0x00000219,0x0000021a,0x00050081,0x00000006,0x0000021c, + 0x00000218,0x0000021b,0x0004003d,0x00000006,0x0000021d,0x000001e9,0x0004003d,0x00000006, + 0x0000021e,0x000000b1,0x00050085,0x00000006,0x0000021f,0x0000021d,0x0000021e,0x00050081, + 0x00000006,0x00000220,0x0000021c,0x0000021f,0x0004003d,0x00000006,0x00000221,0x000000a8, + 0x00050081,0x00000006,0x00000222,0x00000220,0x00000221,0x0004003d,0x00000006,0x00000223, + 0x000001f9,0x00050085,0x00000006,0x00000224,0x00000222,0x00000223,0x0003003e,0x00000032, + 0x00000224,0x0004003d,0x00000006,0x00000225,0x000001e9,0x0004003d,0x00000006,0x00000226, + 0x00000098,0x00050085,0x00000006,0x00000227,0x00000225,0x00000226,0x0004003d,0x00000006, + 0x00000228,0x000001e9,0x0004003d,0x00000006,0x00000229,0x000000a2,0x00050085,0x00000006, + 0x0000022a,0x00000228,0x00000229,0x00050081,0x00000006,0x0000022b,0x00000227,0x0000022a, + 0x0004003d,0x00000006,0x0000022c,0x000001e9,0x0004003d,0x00000006,0x0000022d,0x000000bd, + 0x00050085,0x00000006,0x0000022e,0x0000022c,0x0000022d,0x00050081,0x00000006,0x0000022f, + 0x0000022b,0x0000022e,0x0004003d,0x00000006,0x00000230,0x000001e9,0x0004003d,0x00000006, + 0x00000231,0x000000b4,0x00050085,0x00000006,0x00000232,0x00000230,0x00000231,0x00050081, + 0x00000006,0x00000233,0x0000022f,0x00000232,0x0004003d,0x00000006,0x00000234,0x000000ab, + 0x00050081,0x00000006,0x00000235,0x00000233,0x00000234,0x0004003d,0x00000006,0x00000236, + 0x000001f9,0x00050085,0x00000006,0x00000237,0x00000235,0x00000236,0x0003003e,0x00000033, + 0x00000237,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/fxaa_frag.h b/app/src/main/cpp/shaders/fxaa_frag.h new file mode 100644 index 0000000000..6b7be374bf --- /dev/null +++ b/app/src/main/cpp/shaders/fxaa_frag.h @@ -0,0 +1,165 @@ + // 1116.2.0 + #pragma once +const uint32_t fxaa_code[] = { + 0x07230203,0x00010000,0x0008000b,0x000000e4,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000018,0x000000d6,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00060005,0x00000009,0x52766e69,0x6c6f7365,0x6f697475,0x0000006e,0x00030005, + 0x0000000c,0x00004350,0x00040006,0x0000000c,0x00000000,0x0063646e,0x00060006,0x0000000c, + 0x00000001,0x6f736572,0x6974756c,0x00006e6f,0x00030005,0x0000000e,0x00006370,0x00030005, + 0x00000016,0x00007675,0x00060005,0x00000018,0x67617266,0x43786554,0x64726f6f,0x00000000, + 0x00040005,0x0000001c,0x4e626772,0x00000057,0x00060005,0x00000020,0x75706e49,0x78655474, + 0x65727574,0x00000000,0x00040005,0x0000002a,0x4e626772,0x00000045,0x00040005,0x00000033, + 0x53626772,0x00000057,0x00040005,0x0000003c,0x53626772,0x00000045,0x00040005,0x00000045, + 0x4d626772,0x00000000,0x00040005,0x0000004b,0x616d756c,0x0000574e,0x00040005,0x00000052, + 0x616d756c,0x0000454e,0x00040005,0x00000055,0x616d756c,0x00005753,0x00040005,0x00000058, + 0x616d756c,0x00004553,0x00040005,0x0000005b,0x616d756c,0x0000004d,0x00040005,0x0000005e, + 0x616d756c,0x006e694d,0x00040005,0x00000068,0x616d756c,0x0078614d,0x00030005,0x00000072, + 0x00726964,0x00050005,0x00000087,0x52726964,0x63756465,0x00000065,0x00060005,0x00000095, + 0x446e696d,0x61467269,0x726f7463,0x00000000,0x00040005,0x000000ab,0x41626772,0x00000000, + 0x00040005,0x000000bd,0x42626772,0x00000000,0x00040005,0x000000d0,0x616d756c,0x00000042, + 0x00050005,0x000000d6,0x4374756f,0x726f6c6f,0x00000000,0x00030047,0x0000000c,0x00000002, + 0x00050048,0x0000000c,0x00000000,0x00000023,0x00000000,0x00050048,0x0000000c,0x00000001, + 0x00000023,0x00000010,0x00040047,0x00000018,0x0000001e,0x00000000,0x00040047,0x00000020, + 0x00000021,0x00000000,0x00040047,0x00000020,0x00000022,0x00000000,0x00040047,0x000000d6, + 0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016, + 0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008, + 0x00000007,0x00000007,0x0004002b,0x00000006,0x0000000a,0x3f800000,0x00040017,0x0000000b, + 0x00000006,0x00000004,0x0004001e,0x0000000c,0x0000000b,0x00000007,0x00040020,0x0000000d, + 0x00000009,0x0000000c,0x0004003b,0x0000000d,0x0000000e,0x00000009,0x00040015,0x0000000f, + 0x00000020,0x00000001,0x0004002b,0x0000000f,0x00000010,0x00000001,0x00040020,0x00000011, + 0x00000009,0x00000007,0x00040020,0x00000017,0x00000001,0x00000007,0x0004003b,0x00000017, + 0x00000018,0x00000001,0x00040017,0x0000001a,0x00000006,0x00000003,0x00040020,0x0000001b, + 0x00000007,0x0000001a,0x00090019,0x0000001d,0x00000006,0x00000001,0x00000000,0x00000000, + 0x00000000,0x00000001,0x00000000,0x0003001b,0x0000001e,0x0000001d,0x00040020,0x0000001f, + 0x00000000,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000000,0x0004002b,0x00000006, + 0x00000023,0xbf800000,0x0005002c,0x00000007,0x00000024,0x00000023,0x00000023,0x0005002c, + 0x00000007,0x0000002d,0x0000000a,0x00000023,0x0005002c,0x00000007,0x00000036,0x00000023, + 0x0000000a,0x0005002c,0x00000007,0x0000003f,0x0000000a,0x0000000a,0x00040020,0x0000004a, + 0x00000007,0x00000006,0x0004002b,0x00000006,0x0000004d,0x3e991687,0x0004002b,0x00000006, + 0x0000004e,0x3f1645a2,0x0004002b,0x00000006,0x0000004f,0x3de978d5,0x0006002c,0x0000001a, + 0x00000050,0x0000004d,0x0000004e,0x0000004f,0x00040015,0x0000007b,0x00000020,0x00000000, + 0x0004002b,0x0000007b,0x0000007c,0x00000000,0x0004002b,0x0000007b,0x00000085,0x00000001, + 0x0004002b,0x00000006,0x0000008f,0x3e800000,0x0004002b,0x00000006,0x00000091,0x3e000000, + 0x0004002b,0x00000006,0x00000093,0x3c000000,0x0004002b,0x00000006,0x000000a3,0xc1000000, + 0x0005002c,0x00000007,0x000000a4,0x000000a3,0x000000a3,0x0004002b,0x00000006,0x000000a5, + 0x41000000,0x0005002c,0x00000007,0x000000a6,0x000000a5,0x000000a5,0x00040020,0x000000aa, + 0x00000007,0x0000000b,0x0004002b,0x00000006,0x000000ac,0x3f000000,0x0004002b,0x00000006, + 0x000000b0,0xbe2aaaab,0x0004002b,0x00000006,0x000000b7,0x3e2aaaab,0x0004002b,0x00000006, + 0x000000c3,0xbf000000,0x0004002b,0x00000006,0x000000d2,0x00000000,0x0007002c,0x0000000b, + 0x000000d3,0x0000004d,0x0000004e,0x0000004f,0x000000d2,0x00040020,0x000000d5,0x00000003, + 0x0000000b,0x0004003b,0x000000d5,0x000000d6,0x00000003,0x00020014,0x000000d9,0x00040017, + 0x000000e1,0x000000d9,0x00000004,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003, + 0x000200f8,0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x00000008, + 0x00000016,0x00000007,0x0004003b,0x0000001b,0x0000001c,0x00000007,0x0004003b,0x0000001b, + 0x0000002a,0x00000007,0x0004003b,0x0000001b,0x00000033,0x00000007,0x0004003b,0x0000001b, + 0x0000003c,0x00000007,0x0004003b,0x0000001b,0x00000045,0x00000007,0x0004003b,0x0000004a, + 0x0000004b,0x00000007,0x0004003b,0x0000004a,0x00000052,0x00000007,0x0004003b,0x0000004a, + 0x00000055,0x00000007,0x0004003b,0x0000004a,0x00000058,0x00000007,0x0004003b,0x0000004a, + 0x0000005b,0x00000007,0x0004003b,0x0000004a,0x0000005e,0x00000007,0x0004003b,0x0000004a, + 0x00000068,0x00000007,0x0004003b,0x00000008,0x00000072,0x00000007,0x0004003b,0x0000004a, + 0x00000087,0x00000007,0x0004003b,0x0000004a,0x00000095,0x00000007,0x0004003b,0x000000aa, + 0x000000ab,0x00000007,0x0004003b,0x000000aa,0x000000bd,0x00000007,0x0004003b,0x0000004a, + 0x000000d0,0x00000007,0x00050041,0x00000011,0x00000012,0x0000000e,0x00000010,0x0004003d, + 0x00000007,0x00000013,0x00000012,0x00050050,0x00000007,0x00000014,0x0000000a,0x0000000a, + 0x00050088,0x00000007,0x00000015,0x00000014,0x00000013,0x0003003e,0x00000009,0x00000015, + 0x0004003d,0x00000007,0x00000019,0x00000018,0x0003003e,0x00000016,0x00000019,0x0004003d, + 0x0000001e,0x00000021,0x00000020,0x0004003d,0x00000007,0x00000022,0x00000016,0x0004003d, + 0x00000007,0x00000025,0x00000009,0x00050085,0x00000007,0x00000026,0x00000024,0x00000025, + 0x00050081,0x00000007,0x00000027,0x00000022,0x00000026,0x00050057,0x0000000b,0x00000028, + 0x00000021,0x00000027,0x0008004f,0x0000001a,0x00000029,0x00000028,0x00000028,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x0000001c,0x00000029,0x0004003d,0x0000001e,0x0000002b, + 0x00000020,0x0004003d,0x00000007,0x0000002c,0x00000016,0x0004003d,0x00000007,0x0000002e, + 0x00000009,0x00050085,0x00000007,0x0000002f,0x0000002d,0x0000002e,0x00050081,0x00000007, + 0x00000030,0x0000002c,0x0000002f,0x00050057,0x0000000b,0x00000031,0x0000002b,0x00000030, + 0x0008004f,0x0000001a,0x00000032,0x00000031,0x00000031,0x00000000,0x00000001,0x00000002, + 0x0003003e,0x0000002a,0x00000032,0x0004003d,0x0000001e,0x00000034,0x00000020,0x0004003d, + 0x00000007,0x00000035,0x00000016,0x0004003d,0x00000007,0x00000037,0x00000009,0x00050085, + 0x00000007,0x00000038,0x00000036,0x00000037,0x00050081,0x00000007,0x00000039,0x00000035, + 0x00000038,0x00050057,0x0000000b,0x0000003a,0x00000034,0x00000039,0x0008004f,0x0000001a, + 0x0000003b,0x0000003a,0x0000003a,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000033, + 0x0000003b,0x0004003d,0x0000001e,0x0000003d,0x00000020,0x0004003d,0x00000007,0x0000003e, + 0x00000016,0x0004003d,0x00000007,0x00000040,0x00000009,0x00050085,0x00000007,0x00000041, + 0x0000003f,0x00000040,0x00050081,0x00000007,0x00000042,0x0000003e,0x00000041,0x00050057, + 0x0000000b,0x00000043,0x0000003d,0x00000042,0x0008004f,0x0000001a,0x00000044,0x00000043, + 0x00000043,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000003c,0x00000044,0x0004003d, + 0x0000001e,0x00000046,0x00000020,0x0004003d,0x00000007,0x00000047,0x00000016,0x00050057, + 0x0000000b,0x00000048,0x00000046,0x00000047,0x0008004f,0x0000001a,0x00000049,0x00000048, + 0x00000048,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000045,0x00000049,0x0004003d, + 0x0000001a,0x0000004c,0x0000001c,0x00050094,0x00000006,0x00000051,0x0000004c,0x00000050, + 0x0003003e,0x0000004b,0x00000051,0x0004003d,0x0000001a,0x00000053,0x0000002a,0x00050094, + 0x00000006,0x00000054,0x00000053,0x00000050,0x0003003e,0x00000052,0x00000054,0x0004003d, + 0x0000001a,0x00000056,0x00000033,0x00050094,0x00000006,0x00000057,0x00000056,0x00000050, + 0x0003003e,0x00000055,0x00000057,0x0004003d,0x0000001a,0x00000059,0x0000003c,0x00050094, + 0x00000006,0x0000005a,0x00000059,0x00000050,0x0003003e,0x00000058,0x0000005a,0x0004003d, + 0x0000001a,0x0000005c,0x00000045,0x00050094,0x00000006,0x0000005d,0x0000005c,0x00000050, + 0x0003003e,0x0000005b,0x0000005d,0x0004003d,0x00000006,0x0000005f,0x0000005b,0x0004003d, + 0x00000006,0x00000060,0x0000004b,0x0004003d,0x00000006,0x00000061,0x00000052,0x0007000c, + 0x00000006,0x00000062,0x00000001,0x00000025,0x00000060,0x00000061,0x0004003d,0x00000006, + 0x00000063,0x00000055,0x0004003d,0x00000006,0x00000064,0x00000058,0x0007000c,0x00000006, + 0x00000065,0x00000001,0x00000025,0x00000063,0x00000064,0x0007000c,0x00000006,0x00000066, + 0x00000001,0x00000025,0x00000062,0x00000065,0x0007000c,0x00000006,0x00000067,0x00000001, + 0x00000025,0x0000005f,0x00000066,0x0003003e,0x0000005e,0x00000067,0x0004003d,0x00000006, + 0x00000069,0x0000005b,0x0004003d,0x00000006,0x0000006a,0x0000004b,0x0004003d,0x00000006, + 0x0000006b,0x00000052,0x0007000c,0x00000006,0x0000006c,0x00000001,0x00000028,0x0000006a, + 0x0000006b,0x0004003d,0x00000006,0x0000006d,0x00000055,0x0004003d,0x00000006,0x0000006e, + 0x00000058,0x0007000c,0x00000006,0x0000006f,0x00000001,0x00000028,0x0000006d,0x0000006e, + 0x0007000c,0x00000006,0x00000070,0x00000001,0x00000028,0x0000006c,0x0000006f,0x0007000c, + 0x00000006,0x00000071,0x00000001,0x00000028,0x00000069,0x00000070,0x0003003e,0x00000068, + 0x00000071,0x0004003d,0x00000006,0x00000073,0x0000004b,0x0004003d,0x00000006,0x00000074, + 0x00000052,0x00050081,0x00000006,0x00000075,0x00000073,0x00000074,0x0004003d,0x00000006, + 0x00000076,0x00000055,0x0004003d,0x00000006,0x00000077,0x00000058,0x00050081,0x00000006, + 0x00000078,0x00000076,0x00000077,0x00050083,0x00000006,0x00000079,0x00000075,0x00000078, + 0x0004007f,0x00000006,0x0000007a,0x00000079,0x00050041,0x0000004a,0x0000007d,0x00000072, + 0x0000007c,0x0003003e,0x0000007d,0x0000007a,0x0004003d,0x00000006,0x0000007e,0x0000004b, + 0x0004003d,0x00000006,0x0000007f,0x00000055,0x00050081,0x00000006,0x00000080,0x0000007e, + 0x0000007f,0x0004003d,0x00000006,0x00000081,0x00000052,0x0004003d,0x00000006,0x00000082, + 0x00000058,0x00050081,0x00000006,0x00000083,0x00000081,0x00000082,0x00050083,0x00000006, + 0x00000084,0x00000080,0x00000083,0x00050041,0x0000004a,0x00000086,0x00000072,0x00000085, + 0x0003003e,0x00000086,0x00000084,0x0004003d,0x00000006,0x00000088,0x0000004b,0x0004003d, + 0x00000006,0x00000089,0x00000052,0x00050081,0x00000006,0x0000008a,0x00000088,0x00000089, + 0x0004003d,0x00000006,0x0000008b,0x00000055,0x00050081,0x00000006,0x0000008c,0x0000008a, + 0x0000008b,0x0004003d,0x00000006,0x0000008d,0x00000058,0x00050081,0x00000006,0x0000008e, + 0x0000008c,0x0000008d,0x00050085,0x00000006,0x00000090,0x0000008e,0x0000008f,0x00050085, + 0x00000006,0x00000092,0x00000090,0x00000091,0x0007000c,0x00000006,0x00000094,0x00000001, + 0x00000028,0x00000092,0x00000093,0x0003003e,0x00000087,0x00000094,0x00050041,0x0000004a, + 0x00000096,0x00000072,0x0000007c,0x0004003d,0x00000006,0x00000097,0x00000096,0x0006000c, + 0x00000006,0x00000098,0x00000001,0x00000004,0x00000097,0x00050041,0x0000004a,0x00000099, + 0x00000072,0x00000085,0x0004003d,0x00000006,0x0000009a,0x00000099,0x0006000c,0x00000006, + 0x0000009b,0x00000001,0x00000004,0x0000009a,0x0007000c,0x00000006,0x0000009c,0x00000001, + 0x00000025,0x00000098,0x0000009b,0x0004003d,0x00000006,0x0000009d,0x00000087,0x00050081, + 0x00000006,0x0000009e,0x0000009c,0x0000009d,0x00050088,0x00000006,0x0000009f,0x0000000a, + 0x0000009e,0x0003003e,0x00000095,0x0000009f,0x0004003d,0x00000007,0x000000a0,0x00000072, + 0x0004003d,0x00000006,0x000000a1,0x00000095,0x0005008e,0x00000007,0x000000a2,0x000000a0, + 0x000000a1,0x0008000c,0x00000007,0x000000a7,0x00000001,0x0000002b,0x000000a2,0x000000a4, + 0x000000a6,0x0004003d,0x00000007,0x000000a8,0x00000009,0x00050085,0x00000007,0x000000a9, + 0x000000a7,0x000000a8,0x0003003e,0x00000072,0x000000a9,0x0004003d,0x0000001e,0x000000ad, + 0x00000020,0x0004003d,0x00000007,0x000000ae,0x00000016,0x0004003d,0x00000007,0x000000af, + 0x00000072,0x0005008e,0x00000007,0x000000b1,0x000000af,0x000000b0,0x00050081,0x00000007, + 0x000000b2,0x000000ae,0x000000b1,0x00050057,0x0000000b,0x000000b3,0x000000ad,0x000000b2, + 0x0004003d,0x0000001e,0x000000b4,0x00000020,0x0004003d,0x00000007,0x000000b5,0x00000016, + 0x0004003d,0x00000007,0x000000b6,0x00000072,0x0005008e,0x00000007,0x000000b8,0x000000b6, + 0x000000b7,0x00050081,0x00000007,0x000000b9,0x000000b5,0x000000b8,0x00050057,0x0000000b, + 0x000000ba,0x000000b4,0x000000b9,0x00050081,0x0000000b,0x000000bb,0x000000b3,0x000000ba, + 0x0005008e,0x0000000b,0x000000bc,0x000000bb,0x000000ac,0x0003003e,0x000000ab,0x000000bc, + 0x0004003d,0x0000000b,0x000000be,0x000000ab,0x0005008e,0x0000000b,0x000000bf,0x000000be, + 0x000000ac,0x0004003d,0x0000001e,0x000000c0,0x00000020,0x0004003d,0x00000007,0x000000c1, + 0x00000016,0x0004003d,0x00000007,0x000000c2,0x00000072,0x0005008e,0x00000007,0x000000c4, + 0x000000c2,0x000000c3,0x00050081,0x00000007,0x000000c5,0x000000c1,0x000000c4,0x00050057, + 0x0000000b,0x000000c6,0x000000c0,0x000000c5,0x0004003d,0x0000001e,0x000000c7,0x00000020, + 0x0004003d,0x00000007,0x000000c8,0x00000016,0x0004003d,0x00000007,0x000000c9,0x00000072, + 0x0005008e,0x00000007,0x000000ca,0x000000c9,0x000000ac,0x00050081,0x00000007,0x000000cb, + 0x000000c8,0x000000ca,0x00050057,0x0000000b,0x000000cc,0x000000c7,0x000000cb,0x00050081, + 0x0000000b,0x000000cd,0x000000c6,0x000000cc,0x0005008e,0x0000000b,0x000000ce,0x000000cd, + 0x0000008f,0x00050081,0x0000000b,0x000000cf,0x000000bf,0x000000ce,0x0003003e,0x000000bd, + 0x000000cf,0x0004003d,0x0000000b,0x000000d1,0x000000bd,0x00050094,0x00000006,0x000000d4, + 0x000000d1,0x000000d3,0x0003003e,0x000000d0,0x000000d4,0x0004003d,0x00000006,0x000000d7, + 0x000000d0,0x0004003d,0x00000006,0x000000d8,0x0000005e,0x000500b8,0x000000d9,0x000000da, + 0x000000d7,0x000000d8,0x0004003d,0x00000006,0x000000db,0x000000d0,0x0004003d,0x00000006, + 0x000000dc,0x00000068,0x000500ba,0x000000d9,0x000000dd,0x000000db,0x000000dc,0x000500a6, + 0x000000d9,0x000000de,0x000000da,0x000000dd,0x0004003d,0x0000000b,0x000000df,0x000000ab, + 0x0004003d,0x0000000b,0x000000e0,0x000000bd,0x00070050,0x000000e1,0x000000e2,0x000000de, + 0x000000de,0x000000de,0x000000de,0x000600a9,0x0000000b,0x000000e3,0x000000e2,0x000000df, + 0x000000e0,0x0003003e,0x000000d6,0x000000e3,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/hdr_frag.h b/app/src/main/cpp/shaders/hdr_frag.h new file mode 100644 index 0000000000..37e5783aa5 --- /dev/null +++ b/app/src/main/cpp/shaders/hdr_frag.h @@ -0,0 +1,174 @@ + // 1116.2.0 + #pragma once +const uint32_t hdr_code[] = { + 0x07230203,0x00010000,0x0008000b,0x000000f4,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x000000e9,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00050005,0x00000009,0x63786574,0x64726f6f,0x00000000,0x00060005,0x0000000b, + 0x67617266,0x43786554,0x64726f6f,0x00000000,0x00030005,0x0000000d,0x00007870,0x00030005, + 0x00000010,0x00004350,0x00040006,0x00000010,0x00000000,0x0063646e,0x00060006,0x00000010, + 0x00000001,0x6f736572,0x6974756c,0x00006e6f,0x00030005,0x00000012,0x00006370,0x00040005, + 0x0000001c,0x6f6c6f63,0x00000072,0x00060005,0x00000020,0x75706e49,0x78655474,0x65727574, + 0x00000000,0x00050005,0x00000025,0x6f6f6c62,0x75735f6d,0x0000316d,0x00050005,0x0000007c, + 0x6f6f6c62,0x75735f6d,0x0000326d,0x00040005,0x000000d3,0x74736964,0x00000000,0x00030005, + 0x000000d5,0x00524448,0x00040005,0x000000dd,0x6e656c62,0x00000064,0x00050005,0x000000e9, + 0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x0000000b,0x0000001e,0x00000000,0x00030047, + 0x00000010,0x00000002,0x00050048,0x00000010,0x00000000,0x00000023,0x00000000,0x00050048, + 0x00000010,0x00000001,0x00000023,0x00000010,0x00040047,0x00000020,0x00000021,0x00000000, + 0x00040047,0x00000020,0x00000022,0x00000000,0x00040047,0x000000e9,0x0000001e,0x00000000, + 0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020, + 0x00040017,0x00000007,0x00000006,0x00000002,0x00040020,0x00000008,0x00000007,0x00000007, + 0x00040020,0x0000000a,0x00000001,0x00000007,0x0004003b,0x0000000a,0x0000000b,0x00000001, + 0x0004002b,0x00000006,0x0000000e,0x3f800000,0x00040017,0x0000000f,0x00000006,0x00000004, + 0x0004001e,0x00000010,0x0000000f,0x00000007,0x00040020,0x00000011,0x00000009,0x00000010, + 0x0004003b,0x00000011,0x00000012,0x00000009,0x00040015,0x00000013,0x00000020,0x00000001, + 0x0004002b,0x00000013,0x00000014,0x00000001,0x00040020,0x00000015,0x00000009,0x00000007, + 0x00040017,0x0000001a,0x00000006,0x00000003,0x00040020,0x0000001b,0x00000007,0x0000001a, + 0x00090019,0x0000001d,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, + 0x00000000,0x0003001b,0x0000001e,0x0000001d,0x00040020,0x0000001f,0x00000000,0x0000001e, + 0x0004003b,0x0000001f,0x00000020,0x00000000,0x0004002b,0x00000006,0x00000028,0x3f984189, + 0x0004002b,0x00000006,0x00000029,0xbf984189,0x0005002c,0x00000007,0x0000002a,0x00000028, + 0x00000029,0x0005002c,0x00000007,0x00000032,0x00000029,0x00000029,0x0005002c,0x00000007, + 0x0000003c,0x00000028,0x00000028,0x0005002c,0x00000007,0x00000046,0x00000029,0x00000028, + 0x0004002b,0x00000006,0x00000050,0x00000000,0x0004002b,0x00000006,0x00000051,0xbffdc28f, + 0x0005002c,0x00000007,0x00000052,0x00000050,0x00000051,0x0004002b,0x00000006,0x0000005c, + 0x3ffdc28f,0x0005002c,0x00000007,0x0000005d,0x00000050,0x0000005c,0x0005002c,0x00000007, + 0x00000067,0x00000051,0x00000050,0x0005002c,0x00000007,0x00000071,0x0000005c,0x00000050, + 0x0004002b,0x00000006,0x00000079,0x3ba3d70a,0x0004002b,0x00000006,0x0000007f,0x3fa70a3d, + 0x0004002b,0x00000006,0x00000080,0xbfa70a3d,0x0005002c,0x00000007,0x00000081,0x0000007f, + 0x00000080,0x0005002c,0x00000007,0x00000089,0x00000080,0x00000080,0x0005002c,0x00000007, + 0x00000093,0x0000007f,0x0000007f,0x0005002c,0x00000007,0x0000009d,0x00000080,0x0000007f, + 0x0004002b,0x00000006,0x000000a7,0xc00b3333,0x0005002c,0x00000007,0x000000a8,0x00000050, + 0x000000a7,0x0004002b,0x00000006,0x000000b2,0x400b3333,0x0005002c,0x00000007,0x000000b3, + 0x00000050,0x000000b2,0x0005002c,0x00000007,0x000000bd,0x000000a7,0x00000050,0x0005002c, + 0x00000007,0x000000c7,0x000000b2,0x00000050,0x0004002b,0x00000006,0x000000cf,0x3c23d70a, + 0x00040020,0x000000d2,0x00000007,0x00000006,0x0004002b,0x00000006,0x000000d4,0x3d9db22d, + 0x0004002b,0x00000006,0x000000e3,0x3fa66666,0x0006002c,0x0000001a,0x000000e4,0x000000e3, + 0x000000e3,0x000000e3,0x00040020,0x000000e8,0x00000003,0x0000000f,0x0004003b,0x000000e8, + 0x000000e9,0x00000003,0x0004002b,0x00000006,0x000000f2,0x3f4b020c,0x0004002b,0x00000006, + 0x000000f3,0x3f5eb852,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, + 0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x00000008,0x0000000d, + 0x00000007,0x0004003b,0x0000001b,0x0000001c,0x00000007,0x0004003b,0x0000001b,0x00000025, + 0x00000007,0x0004003b,0x0000001b,0x0000007c,0x00000007,0x0004003b,0x000000d2,0x000000d3, + 0x00000007,0x0004003b,0x0000001b,0x000000d5,0x00000007,0x0004003b,0x0000001b,0x000000dd, + 0x00000007,0x0004003d,0x00000007,0x0000000c,0x0000000b,0x0003003e,0x00000009,0x0000000c, + 0x00050041,0x00000015,0x00000016,0x00000012,0x00000014,0x0004003d,0x00000007,0x00000017, + 0x00000016,0x00050050,0x00000007,0x00000018,0x0000000e,0x0000000e,0x00050088,0x00000007, + 0x00000019,0x00000018,0x00000017,0x0003003e,0x0000000d,0x00000019,0x0004003d,0x0000001e, + 0x00000021,0x00000020,0x0004003d,0x00000007,0x00000022,0x00000009,0x00050057,0x0000000f, + 0x00000023,0x00000021,0x00000022,0x0008004f,0x0000001a,0x00000024,0x00000023,0x00000023, + 0x00000000,0x00000001,0x00000002,0x0003003e,0x0000001c,0x00000024,0x0004003d,0x0000001e, + 0x00000026,0x00000020,0x0004003d,0x00000007,0x00000027,0x00000009,0x0004003d,0x00000007, + 0x0000002b,0x0000000d,0x00050085,0x00000007,0x0000002c,0x0000002a,0x0000002b,0x00050081, + 0x00000007,0x0000002d,0x00000027,0x0000002c,0x00050057,0x0000000f,0x0000002e,0x00000026, + 0x0000002d,0x0008004f,0x0000001a,0x0000002f,0x0000002e,0x0000002e,0x00000000,0x00000001, + 0x00000002,0x0003003e,0x00000025,0x0000002f,0x0004003d,0x0000001e,0x00000030,0x00000020, + 0x0004003d,0x00000007,0x00000031,0x00000009,0x0004003d,0x00000007,0x00000033,0x0000000d, + 0x00050085,0x00000007,0x00000034,0x00000032,0x00000033,0x00050081,0x00000007,0x00000035, + 0x00000031,0x00000034,0x00050057,0x0000000f,0x00000036,0x00000030,0x00000035,0x0008004f, + 0x0000001a,0x00000037,0x00000036,0x00000036,0x00000000,0x00000001,0x00000002,0x0004003d, + 0x0000001a,0x00000038,0x00000025,0x00050081,0x0000001a,0x00000039,0x00000038,0x00000037, + 0x0003003e,0x00000025,0x00000039,0x0004003d,0x0000001e,0x0000003a,0x00000020,0x0004003d, + 0x00000007,0x0000003b,0x00000009,0x0004003d,0x00000007,0x0000003d,0x0000000d,0x00050085, + 0x00000007,0x0000003e,0x0000003c,0x0000003d,0x00050081,0x00000007,0x0000003f,0x0000003b, + 0x0000003e,0x00050057,0x0000000f,0x00000040,0x0000003a,0x0000003f,0x0008004f,0x0000001a, + 0x00000041,0x00000040,0x00000040,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a, + 0x00000042,0x00000025,0x00050081,0x0000001a,0x00000043,0x00000042,0x00000041,0x0003003e, + 0x00000025,0x00000043,0x0004003d,0x0000001e,0x00000044,0x00000020,0x0004003d,0x00000007, + 0x00000045,0x00000009,0x0004003d,0x00000007,0x00000047,0x0000000d,0x00050085,0x00000007, + 0x00000048,0x00000046,0x00000047,0x00050081,0x00000007,0x00000049,0x00000045,0x00000048, + 0x00050057,0x0000000f,0x0000004a,0x00000044,0x00000049,0x0008004f,0x0000001a,0x0000004b, + 0x0000004a,0x0000004a,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a,0x0000004c, + 0x00000025,0x00050081,0x0000001a,0x0000004d,0x0000004c,0x0000004b,0x0003003e,0x00000025, + 0x0000004d,0x0004003d,0x0000001e,0x0000004e,0x00000020,0x0004003d,0x00000007,0x0000004f, + 0x00000009,0x0004003d,0x00000007,0x00000053,0x0000000d,0x00050085,0x00000007,0x00000054, + 0x00000052,0x00000053,0x00050081,0x00000007,0x00000055,0x0000004f,0x00000054,0x00050057, + 0x0000000f,0x00000056,0x0000004e,0x00000055,0x0008004f,0x0000001a,0x00000057,0x00000056, + 0x00000056,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a,0x00000058,0x00000025, + 0x00050081,0x0000001a,0x00000059,0x00000058,0x00000057,0x0003003e,0x00000025,0x00000059, + 0x0004003d,0x0000001e,0x0000005a,0x00000020,0x0004003d,0x00000007,0x0000005b,0x00000009, + 0x0004003d,0x00000007,0x0000005e,0x0000000d,0x00050085,0x00000007,0x0000005f,0x0000005d, + 0x0000005e,0x00050081,0x00000007,0x00000060,0x0000005b,0x0000005f,0x00050057,0x0000000f, + 0x00000061,0x0000005a,0x00000060,0x0008004f,0x0000001a,0x00000062,0x00000061,0x00000061, + 0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a,0x00000063,0x00000025,0x00050081, + 0x0000001a,0x00000064,0x00000063,0x00000062,0x0003003e,0x00000025,0x00000064,0x0004003d, + 0x0000001e,0x00000065,0x00000020,0x0004003d,0x00000007,0x00000066,0x00000009,0x0004003d, + 0x00000007,0x00000068,0x0000000d,0x00050085,0x00000007,0x00000069,0x00000067,0x00000068, + 0x00050081,0x00000007,0x0000006a,0x00000066,0x00000069,0x00050057,0x0000000f,0x0000006b, + 0x00000065,0x0000006a,0x0008004f,0x0000001a,0x0000006c,0x0000006b,0x0000006b,0x00000000, + 0x00000001,0x00000002,0x0004003d,0x0000001a,0x0000006d,0x00000025,0x00050081,0x0000001a, + 0x0000006e,0x0000006d,0x0000006c,0x0003003e,0x00000025,0x0000006e,0x0004003d,0x0000001e, + 0x0000006f,0x00000020,0x0004003d,0x00000007,0x00000070,0x00000009,0x0004003d,0x00000007, + 0x00000072,0x0000000d,0x00050085,0x00000007,0x00000073,0x00000071,0x00000072,0x00050081, + 0x00000007,0x00000074,0x00000070,0x00000073,0x00050057,0x0000000f,0x00000075,0x0000006f, + 0x00000074,0x0008004f,0x0000001a,0x00000076,0x00000075,0x00000075,0x00000000,0x00000001, + 0x00000002,0x0004003d,0x0000001a,0x00000077,0x00000025,0x00050081,0x0000001a,0x00000078, + 0x00000077,0x00000076,0x0003003e,0x00000025,0x00000078,0x0004003d,0x0000001a,0x0000007a, + 0x00000025,0x0005008e,0x0000001a,0x0000007b,0x0000007a,0x00000079,0x0003003e,0x00000025, + 0x0000007b,0x0004003d,0x0000001e,0x0000007d,0x00000020,0x0004003d,0x00000007,0x0000007e, + 0x00000009,0x0004003d,0x00000007,0x00000082,0x0000000d,0x00050085,0x00000007,0x00000083, + 0x00000081,0x00000082,0x00050081,0x00000007,0x00000084,0x0000007e,0x00000083,0x00050057, + 0x0000000f,0x00000085,0x0000007d,0x00000084,0x0008004f,0x0000001a,0x00000086,0x00000085, + 0x00000085,0x00000000,0x00000001,0x00000002,0x0003003e,0x0000007c,0x00000086,0x0004003d, + 0x0000001e,0x00000087,0x00000020,0x0004003d,0x00000007,0x00000088,0x00000009,0x0004003d, + 0x00000007,0x0000008a,0x0000000d,0x00050085,0x00000007,0x0000008b,0x00000089,0x0000008a, + 0x00050081,0x00000007,0x0000008c,0x00000088,0x0000008b,0x00050057,0x0000000f,0x0000008d, + 0x00000087,0x0000008c,0x0008004f,0x0000001a,0x0000008e,0x0000008d,0x0000008d,0x00000000, + 0x00000001,0x00000002,0x0004003d,0x0000001a,0x0000008f,0x0000007c,0x00050081,0x0000001a, + 0x00000090,0x0000008f,0x0000008e,0x0003003e,0x0000007c,0x00000090,0x0004003d,0x0000001e, + 0x00000091,0x00000020,0x0004003d,0x00000007,0x00000092,0x00000009,0x0004003d,0x00000007, + 0x00000094,0x0000000d,0x00050085,0x00000007,0x00000095,0x00000093,0x00000094,0x00050081, + 0x00000007,0x00000096,0x00000092,0x00000095,0x00050057,0x0000000f,0x00000097,0x00000091, + 0x00000096,0x0008004f,0x0000001a,0x00000098,0x00000097,0x00000097,0x00000000,0x00000001, + 0x00000002,0x0004003d,0x0000001a,0x00000099,0x0000007c,0x00050081,0x0000001a,0x0000009a, + 0x00000099,0x00000098,0x0003003e,0x0000007c,0x0000009a,0x0004003d,0x0000001e,0x0000009b, + 0x00000020,0x0004003d,0x00000007,0x0000009c,0x00000009,0x0004003d,0x00000007,0x0000009e, + 0x0000000d,0x00050085,0x00000007,0x0000009f,0x0000009d,0x0000009e,0x00050081,0x00000007, + 0x000000a0,0x0000009c,0x0000009f,0x00050057,0x0000000f,0x000000a1,0x0000009b,0x000000a0, + 0x0008004f,0x0000001a,0x000000a2,0x000000a1,0x000000a1,0x00000000,0x00000001,0x00000002, + 0x0004003d,0x0000001a,0x000000a3,0x0000007c,0x00050081,0x0000001a,0x000000a4,0x000000a3, + 0x000000a2,0x0003003e,0x0000007c,0x000000a4,0x0004003d,0x0000001e,0x000000a5,0x00000020, + 0x0004003d,0x00000007,0x000000a6,0x00000009,0x0004003d,0x00000007,0x000000a9,0x0000000d, + 0x00050085,0x00000007,0x000000aa,0x000000a8,0x000000a9,0x00050081,0x00000007,0x000000ab, + 0x000000a6,0x000000aa,0x00050057,0x0000000f,0x000000ac,0x000000a5,0x000000ab,0x0008004f, + 0x0000001a,0x000000ad,0x000000ac,0x000000ac,0x00000000,0x00000001,0x00000002,0x0004003d, + 0x0000001a,0x000000ae,0x0000007c,0x00050081,0x0000001a,0x000000af,0x000000ae,0x000000ad, + 0x0003003e,0x0000007c,0x000000af,0x0004003d,0x0000001e,0x000000b0,0x00000020,0x0004003d, + 0x00000007,0x000000b1,0x00000009,0x0004003d,0x00000007,0x000000b4,0x0000000d,0x00050085, + 0x00000007,0x000000b5,0x000000b3,0x000000b4,0x00050081,0x00000007,0x000000b6,0x000000b1, + 0x000000b5,0x00050057,0x0000000f,0x000000b7,0x000000b0,0x000000b6,0x0008004f,0x0000001a, + 0x000000b8,0x000000b7,0x000000b7,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a, + 0x000000b9,0x0000007c,0x00050081,0x0000001a,0x000000ba,0x000000b9,0x000000b8,0x0003003e, + 0x0000007c,0x000000ba,0x0004003d,0x0000001e,0x000000bb,0x00000020,0x0004003d,0x00000007, + 0x000000bc,0x00000009,0x0004003d,0x00000007,0x000000be,0x0000000d,0x00050085,0x00000007, + 0x000000bf,0x000000bd,0x000000be,0x00050081,0x00000007,0x000000c0,0x000000bc,0x000000bf, + 0x00050057,0x0000000f,0x000000c1,0x000000bb,0x000000c0,0x0008004f,0x0000001a,0x000000c2, + 0x000000c1,0x000000c1,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a,0x000000c3, + 0x0000007c,0x00050081,0x0000001a,0x000000c4,0x000000c3,0x000000c2,0x0003003e,0x0000007c, + 0x000000c4,0x0004003d,0x0000001e,0x000000c5,0x00000020,0x0004003d,0x00000007,0x000000c6, + 0x00000009,0x0004003d,0x00000007,0x000000c8,0x0000000d,0x00050085,0x00000007,0x000000c9, + 0x000000c7,0x000000c8,0x00050081,0x00000007,0x000000ca,0x000000c6,0x000000c9,0x00050057, + 0x0000000f,0x000000cb,0x000000c5,0x000000ca,0x0008004f,0x0000001a,0x000000cc,0x000000cb, + 0x000000cb,0x00000000,0x00000001,0x00000002,0x0004003d,0x0000001a,0x000000cd,0x0000007c, + 0x00050081,0x0000001a,0x000000ce,0x000000cd,0x000000cc,0x0003003e,0x0000007c,0x000000ce, + 0x0004003d,0x0000001a,0x000000d0,0x0000007c,0x0005008e,0x0000001a,0x000000d1,0x000000d0, + 0x000000cf,0x0003003e,0x0000007c,0x000000d1,0x0003003e,0x000000d3,0x000000d4,0x0004003d, + 0x0000001a,0x000000d6,0x0000001c,0x0004003d,0x0000001a,0x000000d7,0x0000007c,0x0004003d, + 0x0000001a,0x000000d8,0x00000025,0x00050083,0x0000001a,0x000000d9,0x000000d7,0x000000d8, + 0x00050081,0x0000001a,0x000000da,0x000000d6,0x000000d9,0x0004003d,0x00000006,0x000000db, + 0x000000d3,0x0005008e,0x0000001a,0x000000dc,0x000000da,0x000000db,0x0003003e,0x000000d5, + 0x000000dc,0x0004003d,0x0000001a,0x000000de,0x000000d5,0x0004003d,0x0000001a,0x000000df, + 0x0000001c,0x00050081,0x0000001a,0x000000e0,0x000000de,0x000000df,0x0003003e,0x000000dd, + 0x000000e0,0x0004003d,0x0000001a,0x000000e1,0x000000dd,0x0006000c,0x0000001a,0x000000e2, + 0x00000001,0x00000004,0x000000e1,0x0007000c,0x0000001a,0x000000e5,0x00000001,0x0000001a, + 0x000000e2,0x000000e4,0x0004003d,0x0000001a,0x000000e6,0x000000d5,0x00050081,0x0000001a, + 0x000000e7,0x000000e5,0x000000e6,0x0003003e,0x0000001c,0x000000e7,0x0004003d,0x0000001a, + 0x000000ea,0x0000001c,0x00060050,0x0000001a,0x000000eb,0x00000050,0x00000050,0x00000050, + 0x00060050,0x0000001a,0x000000ec,0x0000000e,0x0000000e,0x0000000e,0x0008000c,0x0000001a, + 0x000000ed,0x00000001,0x0000002b,0x000000ea,0x000000eb,0x000000ec,0x00050051,0x00000006, + 0x000000ee,0x000000ed,0x00000000,0x00050051,0x00000006,0x000000ef,0x000000ed,0x00000001, + 0x00050051,0x00000006,0x000000f0,0x000000ed,0x00000002,0x00070050,0x0000000f,0x000000f1, + 0x000000ee,0x000000ef,0x000000f0,0x0000000e,0x0003003e,0x000000e9,0x000000f1,0x000100fd, + 0x00010038 +}; diff --git a/app/src/main/cpp/shaders/nis_frag.h b/app/src/main/cpp/shaders/nis_frag.h new file mode 100644 index 0000000000..468283d7f5 --- /dev/null +++ b/app/src/main/cpp/shaders/nis_frag.h @@ -0,0 +1,1222 @@ + // 1116.2.0 + #pragma once +const uint32_t nis_code[] = { + 0x07230203,0x00010000,0x0008000b,0x00000644,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000051f,0x00000637,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00050005,0x0000000b,0x59746567,0x33667628,0x0000003b,0x00030005,0x0000000a, + 0x00626772,0x000b0005,0x00000019,0x65676465,0x66287441,0x31663b31,0x3b31663b,0x663b3166, + 0x31663b31,0x3b31663b,0x663b3166,0x00003b31,0x00030005,0x00000010,0x00303070,0x00030005, + 0x00000011,0x00313070,0x00030005,0x00000012,0x00323070,0x00030005,0x00000013,0x00303170, + 0x00030005,0x00000014,0x00313170,0x00030005,0x00000015,0x00323170,0x00030005,0x00000016, + 0x00303270,0x00030005,0x00000017,0x00313270,0x00030005,0x00000018,0x00323270,0x000c0005, + 0x00000023,0x49746567,0x7265746e,0x67644570,0x70614d65,0x34667628,0x3466763b,0x3466763b, + 0x3466763b,0x3b31663b,0x003b3166,0x00030005,0x0000001d,0x00303065,0x00030005,0x0000001e, + 0x00313065,0x00030005,0x0000001f,0x00303165,0x00030005,0x00000020,0x00313165,0x00030005, + 0x00000021,0x00007866,0x00030005,0x00000022,0x00007966,0x000a0005,0x0000002f,0x636c6163, + 0x2849544c,0x663b3166,0x31663b31,0x3b31663b,0x663b3166,0x31693b31,0x0000003b,0x00030005, + 0x00000028,0x00003070,0x00030005,0x00000029,0x00003170,0x00030005,0x0000002a,0x00003270, + 0x00030005,0x0000002b,0x00003370,0x00030005,0x0000002c,0x00003470,0x00030005,0x0000002d, + 0x00003570,0x00050005,0x0000002e,0x73616870,0x6e695f65,0x00786564,0x00070005,0x00000038, + 0x6c617665,0x796c6f50,0x31662836,0x3b5d365b,0x003b3169,0x00030005,0x00000036,0x006c7870, + 0x00050005,0x00000037,0x73616870,0x6e695f65,0x00000074,0x000a0005,0x00000040,0x746c6966, + 0x6f4e7265,0x6c616d72,0x5b316628,0x365b5d36,0x31693b5d,0x3b31693b,0x00000000,0x00030005, + 0x0000003d,0x00000070,0x00050005,0x0000003e,0x73616870,0x5f785f65,0x00746e69,0x00050005, + 0x0000003f,0x73616870,0x5f795f65,0x00746e69,0x000c0005,0x00000049,0x44646461,0x69467269, + 0x7265746c,0x31662873,0x5b5d365b,0x663b5d36,0x31663b31,0x3b31693b,0x763b3169,0x003b3466, + 0x00030005,0x00000043,0x00000070,0x00060005,0x00000044,0x73616870,0x5f785f65,0x63617266, + 0x00000000,0x00060005,0x00000045,0x73616870,0x5f795f65,0x63617266,0x00000000,0x00070005, + 0x00000046,0x73616870,0x5f785f65,0x63617266,0x746e695f,0x00000000,0x00070005,0x00000047, + 0x73616870,0x5f795f65,0x63617266,0x746e695f,0x00000000,0x00030005,0x00000048,0x00000077, + 0x00030005,0x0000005e,0x00305f67,0x00040005,0x0000006b,0x35345f67,0x00000000,0x00040005, + 0x00000078,0x30395f67,0x00000000,0x00040005,0x00000085,0x33315f67,0x00000035,0x00050005, + 0x00000092,0x5f305f67,0x6d5f3039,0x00007861,0x00050005,0x00000096,0x5f305f67,0x6d5f3039, + 0x00006e69,0x00060005,0x0000009a,0x35345f67,0x3533315f,0x78616d5f,0x00000000,0x00060005, + 0x0000009e,0x35345f67,0x3533315f,0x6e696d5f,0x00000000,0x00040005,0x000000ac,0x5f305f65, + 0x00003039,0x00050005,0x000000b4,0x35345f65,0x3533315f,0x00000000,0x00040005,0x000000b8, + 0x5f305f63,0x00003039,0x00050005,0x000000c6,0x35345f63,0x3533315f,0x00000000,0x00050005, + 0x000000d2,0x5f675f63,0x30395f30,0x00000000,0x00050005,0x000000d6,0x5f675f63,0x315f3534, + 0x00003533,0x00050005,0x000000da,0x5f655f66,0x30395f30,0x00000000,0x00050005,0x000000e0, + 0x5f655f66,0x315f3534,0x00003533,0x00030005,0x000000e6,0x00003077,0x00030005,0x000000ec, + 0x00303977,0x00030005,0x000000f3,0x00353477,0x00040005,0x000000f9,0x35333177,0x00000000, + 0x00030005,0x00000107,0x00003068,0x00030005,0x0000010d,0x00003168,0x00050005,0x0000011a, + 0x656c6573,0x726f7463,0x00000000,0x00030005,0x0000011e,0x006c6573,0x00040005,0x00000123, + 0x696d5f61,0x0000006e,0x00040005,0x00000129,0x616d5f61,0x00000078,0x00040005,0x00000133, + 0x696d5f62,0x0000006e,0x00040005,0x00000139,0x616d5f62,0x00000078,0x00040005,0x0000013f, + 0x6f635f61,0x0000746e,0x00040005,0x00000143,0x6f635f62,0x0000746e,0x00050005,0x00000147, + 0x746e6f63,0x7461725f,0x00006f69,0x00030005,0x0000015f,0x00000079,0x00030005,0x00000160, + 0x00000069,0x00050005,0x00000215,0x65646e69,0x6c626178,0x00000065,0x00040005,0x00000221, + 0x73755f79,0x0000006d,0x00030005,0x00000222,0x00000069,0x00050005,0x000002b0,0x65646e69, + 0x6c626178,0x00000065,0x00040005,0x000002bb,0x63735f79,0x00656c61,0x00050005,0x000002c3, + 0x68735f79,0x6e707261,0x00737365,0x00070005,0x000002c6,0x61685367,0x74537072,0x676e6572, + 0x63536874,0x00656c61,0x00070005,0x000002c9,0x61685367,0x74537072,0x676e6572,0x694d6874, + 0x0000006e,0x00070005,0x000002cf,0x68735f79,0x6e707261,0x5f737365,0x696d696c,0x00000074, + 0x00070005,0x000002d1,0x61685367,0x694c7072,0x5374696d,0x656c6163,0x00000000,0x00060005, + 0x000002d4,0x61685367,0x694c7072,0x4d74696d,0x00006e69,0x00040005,0x000002e3,0x61726170, + 0x0000006d,0x00040005,0x000002e6,0x61726170,0x0000006d,0x00040005,0x000002e9,0x61726170, + 0x0000006d,0x00040005,0x000002ec,0x61726170,0x0000006d,0x00040005,0x000002ef,0x61726170, + 0x0000006d,0x00040005,0x000002f2,0x61726170,0x0000006d,0x00040005,0x000002f5,0x61726170, + 0x0000006d,0x00040005,0x00000303,0x63615f68,0x00000063,0x00030005,0x00000304,0x0000006a, + 0x00040005,0x0000030c,0x63615f76,0x00000063,0x00030005,0x0000030d,0x00000069,0x00050005, + 0x0000031d,0x65646e69,0x6c626178,0x00000065,0x00050005,0x0000032a,0x65646e69,0x6c626178, + 0x00000065,0x00030005,0x00000335,0x00000066,0x00030005,0x0000033b,0x00000069,0x00050005, + 0x00000343,0x65746e69,0x44307072,0x00006765,0x00040005,0x00000350,0x61726170,0x0000006d, + 0x00040005,0x00000352,0x61726170,0x0000006d,0x00030005,0x0000035f,0x00000069,0x00050005, + 0x00000367,0x65746e69,0x30397072,0x00676544,0x00040005,0x00000374,0x61726170,0x0000006d, + 0x00040005,0x00000376,0x61726170,0x0000006d,0x00050005,0x00000383,0x61687070,0x625f6573, + 0x00003534,0x00070005,0x0000038d,0x706d6574,0x746e695f,0x34707265,0x67654435,0x00000000, + 0x00030005,0x000003a5,0x00000061,0x00030005,0x000003b1,0x00000062,0x00030005,0x000003bd, + 0x00000063,0x00030005,0x000003c9,0x00000064,0x00050005,0x000003f1,0x61687070,0x705f6573, + 0x00003534,0x00030005,0x000003f9,0x00000069,0x00050005,0x00000401,0x65746e69,0x35347072, + 0x00676544,0x00030005,0x0000040d,0x00000069,0x00040005,0x00000420,0x61726170,0x0000006d, + 0x00040005,0x00000422,0x61726170,0x0000006d,0x00050005,0x0000042f,0x61687070,0x625f6573, + 0x00353331,0x00070005,0x00000434,0x706d6574,0x746e695f,0x31707265,0x65443533,0x00000067, + 0x00030005,0x0000044c,0x00000061,0x00030005,0x00000458,0x00000062,0x00030005,0x00000464, + 0x00000063,0x00030005,0x00000470,0x00000064,0x00050005,0x00000498,0x61687070,0x705f6573, + 0x00353331,0x00030005,0x000004a1,0x00000069,0x00060005,0x000004a9,0x65746e69,0x33317072, + 0x67654435,0x00000000,0x00030005,0x000004b5,0x00000069,0x00040005,0x000004c7,0x61726170, + 0x0000006d,0x00040005,0x000004c9,0x61726170,0x0000006d,0x00050005,0x000004d3,0x72616873, + 0x73656e70,0x00000073,0x00030005,0x000004d4,0x00004350,0x00040006,0x000004d4,0x00000000, + 0x0063646e,0x00070006,0x000004d4,0x00000001,0x77656956,0x74726f70,0x6f666e49,0x00000000, + 0x00060006,0x000004d4,0x00000002,0x72616873,0x73656e70,0x00000073,0x00030005,0x000004d6, + 0x00006370,0x00060005,0x000004db,0x72616873,0x5f6e6570,0x64696c73,0x00007265,0x00050005, + 0x000004de,0x5378614d,0x656c6163,0x00000000,0x00050005,0x000004e4,0x536e694d,0x656c6163, + 0x00000000,0x00050005,0x000004e8,0x696d694c,0x61635374,0x0000656c,0x00070005,0x000004f4, + 0x72616873,0x72745370,0x74676e65,0x78614d68,0x00000000,0x00060005,0x00000508,0x72616873, + 0x6d694c70,0x614d7469,0x00000078,0x00040005,0x00000514,0x69536e69,0x0000657a,0x00040005, + 0x00000519,0x49766e69,0x0000006e,0x00040005,0x0000051d,0x58637273,0x00000000,0x00060005, + 0x0000051f,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040005,0x00000527,0x59637273, + 0x00000000,0x00030005,0x0000052e,0x00787366,0x00030005,0x00000531,0x00797366,0x00030005, + 0x00000534,0x00007866,0x00030005,0x00000538,0x00007966,0x00040005,0x0000053c,0x695f7866, + 0x0000746e,0x00040005,0x00000540,0x695f7966,0x0000746e,0x00030005,0x00000544,0x00000069, + 0x00030005,0x0000054c,0x0000006a,0x00030005,0x00000554,0x00006374,0x00030005,0x00000564, + 0x00000070,0x00060005,0x0000056a,0x75706e49,0x78655474,0x65727574,0x00000000,0x00040005, + 0x0000056e,0x61726170,0x0000006d,0x00030005,0x00000576,0x00303065,0x00040005,0x00000577, + 0x61726170,0x0000006d,0x00040005,0x0000057a,0x61726170,0x0000006d,0x00040005,0x0000057d, + 0x61726170,0x0000006d,0x00040005,0x00000580,0x61726170,0x0000006d,0x00040005,0x00000583, + 0x61726170,0x0000006d,0x00040005,0x00000586,0x61726170,0x0000006d,0x00040005,0x00000589, + 0x61726170,0x0000006d,0x00040005,0x0000058c,0x61726170,0x0000006d,0x00040005,0x0000058f, + 0x61726170,0x0000006d,0x00030005,0x00000593,0x00313065,0x00040005,0x00000594,0x61726170, + 0x0000006d,0x00040005,0x00000597,0x61726170,0x0000006d,0x00040005,0x0000059a,0x61726170, + 0x0000006d,0x00040005,0x0000059d,0x61726170,0x0000006d,0x00040005,0x000005a0,0x61726170, + 0x0000006d,0x00040005,0x000005a3,0x61726170,0x0000006d,0x00040005,0x000005a6,0x61726170, + 0x0000006d,0x00040005,0x000005a9,0x61726170,0x0000006d,0x00040005,0x000005ac,0x61726170, + 0x0000006d,0x00030005,0x000005b0,0x00303165,0x00040005,0x000005b1,0x61726170,0x0000006d, + 0x00040005,0x000005b4,0x61726170,0x0000006d,0x00040005,0x000005b7,0x61726170,0x0000006d, + 0x00040005,0x000005ba,0x61726170,0x0000006d,0x00040005,0x000005bd,0x61726170,0x0000006d, + 0x00040005,0x000005c0,0x61726170,0x0000006d,0x00040005,0x000005c3,0x61726170,0x0000006d, + 0x00040005,0x000005c6,0x61726170,0x0000006d,0x00040005,0x000005c9,0x61726170,0x0000006d, + 0x00030005,0x000005cd,0x00313165,0x00040005,0x000005ce,0x61726170,0x0000006d,0x00040005, + 0x000005d1,0x61726170,0x0000006d,0x00040005,0x000005d4,0x61726170,0x0000006d,0x00040005, + 0x000005d7,0x61726170,0x0000006d,0x00040005,0x000005da,0x61726170,0x0000006d,0x00040005, + 0x000005dd,0x61726170,0x0000006d,0x00040005,0x000005e0,0x61726170,0x0000006d,0x00040005, + 0x000005e3,0x61726170,0x0000006d,0x00040005,0x000005e6,0x61726170,0x0000006d,0x00030005, + 0x000005ea,0x00000077,0x00040005,0x000005eb,0x61726170,0x0000006d,0x00040005,0x000005ed, + 0x61726170,0x0000006d,0x00040005,0x000005ef,0x61726170,0x0000006d,0x00040005,0x000005f1, + 0x61726170,0x0000006d,0x00040005,0x000005f3,0x61726170,0x0000006d,0x00040005,0x000005f5, + 0x61726170,0x0000006d,0x00050005,0x000005f8,0x65736162,0x67696557,0x00007468,0x00030005, + 0x00000605,0x0059706f,0x00040005,0x00000606,0x61726170,0x0000006d,0x00040005,0x00000608, + 0x61726170,0x0000006d,0x00040005,0x0000060a,0x61726170,0x0000006d,0x00040005,0x0000060f, + 0x61726170,0x0000006d,0x00040005,0x00000611,0x61726170,0x0000006d,0x00040005,0x00000613, + 0x61726170,0x0000006d,0x00040005,0x00000615,0x61726170,0x0000006d,0x00040005,0x00000617, + 0x61726170,0x0000006d,0x00040005,0x00000619,0x61726170,0x0000006d,0x00030005,0x0000061e, + 0x0000706f,0x00030005,0x00000622,0x00000079,0x00040005,0x00000623,0x61726170,0x0000006d, + 0x00040005,0x00000627,0x72726f63,0x00000000,0x00050005,0x00000637,0x4374756f,0x726f6c6f, + 0x00000000,0x00030047,0x000004d4,0x00000002,0x00050048,0x000004d4,0x00000000,0x00000023, + 0x00000000,0x00050048,0x000004d4,0x00000001,0x00000023,0x00000010,0x00050048,0x000004d4, + 0x00000002,0x00000023,0x00000020,0x00040047,0x0000051f,0x0000001e,0x00000000,0x00040047, + 0x0000056a,0x00000021,0x00000000,0x00040047,0x0000056a,0x00000022,0x00000000,0x00040047, + 0x00000637,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002, + 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000003,0x00040020, + 0x00000008,0x00000007,0x00000007,0x00040021,0x00000009,0x00000006,0x00000008,0x00040020, + 0x0000000d,0x00000007,0x00000006,0x00040017,0x0000000e,0x00000006,0x00000004,0x000c0021, + 0x0000000f,0x0000000e,0x0000000d,0x0000000d,0x0000000d,0x0000000d,0x0000000d,0x0000000d, + 0x0000000d,0x0000000d,0x0000000d,0x00040020,0x0000001b,0x00000007,0x0000000e,0x00090021, + 0x0000001c,0x0000000e,0x0000001b,0x0000001b,0x0000001b,0x0000001b,0x0000000d,0x0000000d, + 0x00040015,0x00000025,0x00000020,0x00000001,0x00040020,0x00000026,0x00000007,0x00000025, + 0x000a0021,0x00000027,0x00000006,0x0000000d,0x0000000d,0x0000000d,0x0000000d,0x0000000d, + 0x0000000d,0x00000026,0x00040015,0x00000031,0x00000020,0x00000000,0x0004002b,0x00000031, + 0x00000032,0x00000006,0x0004001c,0x00000033,0x00000006,0x00000032,0x00040020,0x00000034, + 0x00000007,0x00000033,0x00050021,0x00000035,0x00000006,0x00000034,0x00000026,0x0004001c, + 0x0000003a,0x00000033,0x00000032,0x00040020,0x0000003b,0x00000007,0x0000003a,0x00060021, + 0x0000003c,0x00000006,0x0000003b,0x00000026,0x00000026,0x00090021,0x00000042,0x00000006, + 0x0000003b,0x0000000d,0x0000000d,0x00000026,0x00000026,0x0000001b,0x0004002b,0x00000006, + 0x0000004b,0x3e59b3d0,0x0004002b,0x00000031,0x0000004c,0x00000000,0x0004002b,0x00000006, + 0x00000050,0x3f371759,0x0004002b,0x00000031,0x00000051,0x00000001,0x0004002b,0x00000006, + 0x00000056,0x3d93dd98,0x0004002b,0x00000031,0x00000057,0x00000002,0x0004002b,0x00000006, + 0x000000a5,0x00000000,0x00020014,0x000000a6,0x0007002c,0x0000000e,0x000000aa,0x000000a5, + 0x000000a5,0x000000a5,0x000000a5,0x0004002b,0x00000006,0x000000b2,0x3f800000,0x00040020, + 0x000000b7,0x00000007,0x000000a6,0x0004002b,0x00000006,0x000000bb,0x400ce000,0x0004002b, + 0x00000006,0x000000bf,0x3d800000,0x0004002b,0x00000025,0x0000011c,0x00000020,0x0004002b, + 0x00000006,0x0000014e,0x3b808081,0x0004002b,0x00000006,0x00000152,0x40000000,0x0004002b, + 0x00000006,0x00000154,0x3e000000,0x0004002b,0x00000025,0x0000015c,0x00000000,0x0004002b, + 0x00000025,0x0000015d,0x0000003f,0x0004002b,0x00000025,0x00000167,0x00000006,0x0004002b, + 0x00000031,0x00000169,0x00000180,0x0004001c,0x0000016a,0x00000006,0x00000169,0x0004002b, + 0x00000006,0x0000016b,0x3b3e0ded,0x0004002b,0x00000006,0x0000016c,0xbc5013a9,0x0004002b, + 0x00000006,0x0000016d,0x3c5844d0,0x0004002b,0x00000006,0x0000016e,0xbb5ed289,0x0004002b, + 0x00000006,0x0000016f,0x3bce703b,0x0004002b,0x00000006,0x00000170,0xbccbfb16,0x0004002b, + 0x00000006,0x00000171,0x3f7f9db2,0x0004002b,0x00000006,0x00000172,0x3cdc5d64,0x0004002b, + 0x00000006,0x00000173,0xbbded289,0x0004002b,0x00000006,0x00000174,0x3c102de0,0x0004002b, + 0x00000006,0x00000175,0xbd13dd98,0x0004002b,0x00000006,0x00000176,0x3f7edfa4,0x0004002b, + 0x00000006,0x00000177,0x3d29fbe7,0x0004002b,0x00000006,0x00000178,0xbc28c155,0x0004002b, + 0x00000006,0x00000179,0x3a03126f,0x0004002b,0x00000006,0x0000017a,0x3c3fb15b,0x0004002b, + 0x00000006,0x0000017b,0xbd422681,0x0004002b,0x00000006,0x0000017c,0x3f7e425b,0x0004002b, + 0x00000006,0x0000017d,0x3d6631f9,0x0004002b,0x00000006,0x0000017e,0xbc68a71e,0x0004002b, + 0x00000006,0x0000017f,0x3c68a71e,0x0004002b,0x00000006,0x00000180,0xbd6bedfa,0x0004002b, + 0x00000006,0x00000181,0x3f7d5cfb,0x0004002b,0x00000006,0x00000182,0x3d9205bc,0x0004002b, + 0x00000006,0x00000183,0xbc944674,0x0004002b,0x00000006,0x00000184,0x3c87fcb9,0x0004002b, + 0x00000006,0x00000185,0xbd8a0903,0x0004002b,0x00000006,0x00000186,0x3f7c01a3,0x0004002b, + 0x00000006,0x00000187,0x3db2fec5,0x0004002b,0x00000006,0x00000188,0xbcb43958,0x0004002b, + 0x00000006,0x00000189,0x3a83126f,0x0004002b,0x00000006,0x0000018a,0x3c985f07,0x0004002b, + 0x00000006,0x0000018b,0xbd9c0ebf,0x0004002b,0x00000006,0x0000018c,0x3f7a7efa,0x0004002b, + 0x00000006,0x0000018d,0x3dd4fdf4,0x0004002b,0x00000006,0x0000018e,0xbcd844d0,0x0004002b, + 0x00000006,0x0000018f,0x3ac49ba6,0x0004002b,0x00000006,0x00000190,0x3ca7ef9e,0x0004002b, + 0x00000006,0x00000191,0xbdae147b,0x0004002b,0x00000006,0x00000192,0x3f7902de,0x0004002b, + 0x00000006,0x00000193,0x3df6fd22,0x0004002b,0x00000006,0x00000194,0xbcfc5048,0x0004002b, + 0x00000006,0x00000195,0x3b03126f,0x0004002b,0x00000006,0x00000196,0x3cb851ec,0x0004002b, + 0x00000006,0x00000197,0xbdbe0ded,0x0004002b,0x00000006,0x00000198,0x3f76fd22,0x0004002b, + 0x00000006,0x00000199,0x3e0d844d,0x0004002b,0x00000006,0x0000019a,0xbd102de0,0x0004002b, + 0x00000006,0x0000019b,0x3b1d4952,0x0004002b,0x00000006,0x0000019c,0x3cc3c9ef,0x0004002b, + 0x00000006,0x0000019d,0xbdce075f,0x0004002b,0x00000006,0x0000019e,0x3f751eb8,0x0004002b, + 0x00000006,0x0000019f,0x3e1f8a09,0x0004002b,0x00000006,0x000001a0,0xbd22339c,0x0004002b, + 0x00000006,0x000001a1,0x3cd013a9,0x0004002b,0x00000006,0x000001a2,0xbddbf488,0x0004002b, + 0x00000006,0x000001a3,0x3f72de01,0x0004002b,0x00000006,0x000001a4,0x3e31f8a1,0x0004002b, + 0x00000006,0x000001a5,0xbd33d07d,0x0004002b,0x00000006,0x000001a6,0x3b5ed289,0x0004002b, + 0x00000006,0x000001a7,0x3cd844d0,0x0004002b,0x00000006,0x000001a8,0xbde90ff9,0x0004002b, + 0x00000006,0x000001a9,0x3f70624e,0x0004002b,0x00000006,0x000001aa,0x3e458794,0x0004002b, + 0x00000006,0x000001ab,0xbd47e282,0x0004002b,0x00000006,0x000001ac,0x3b902de0,0x0004002b, + 0x00000006,0x000001ad,0x3ce3bcd3,0x0004002b,0x00000006,0x000001ae,0xbdf3eab3,0x0004002b, + 0x00000006,0x000001af,0x3f6d9e84,0x0004002b,0x00000006,0x000001b0,0x3e58fc50,0x0004002b, + 0x00000006,0x000001b1,0xbd5bf488,0x0004002b,0x00000006,0x000001b2,0x3ba0902e,0x0004002b, + 0x00000006,0x000001b3,0x3cebedfa,0x0004002b,0x00000006,0x000001b4,0xbdfef9db,0x0004002b, + 0x00000006,0x000001b5,0x3f6ac083,0x0004002b,0x00000006,0x000001b6,0x3e6c8b44,0x0004002b, + 0x00000006,0x000001b7,0xbd6dfa44,0x0004002b,0x00000006,0x000001b8,0x3bc154ca,0x0004002b, + 0x00000006,0x000001b9,0x3cf0068e,0x0004002b,0x00000006,0x000001ba,0xbe04816f,0x0004002b, + 0x00000006,0x000001bb,0x3f67e282,0x0004002b,0x00000006,0x000001bc,0x3e808312,0x0004002b, + 0x00000006,0x000001bd,0xbd810625,0x0004002b,0x00000006,0x000001be,0x3cf837b5,0x0004002b, + 0x00000006,0x000001bf,0xbe087fcc,0x0004002b,0x00000006,0x000001c0,0x3f64816f,0x0004002b, + 0x00000006,0x000001c1,0x3e8ac083,0x0004002b,0x00000006,0x000001c2,0xbd8b0f28,0x0004002b, + 0x00000006,0x000001c3,0x3bef34d7,0x0004002b,0x00000006,0x000001c4,0x3cfc5048,0x0004002b, + 0x00000006,0x000001c5,0xbe0bfb16,0x0004002b,0x00000006,0x000001c6,0x3f60ff97,0x0004002b, + 0x00000006,0x000001c7,0x3e953f7d,0x0004002b,0x00000006,0x000001c8,0xbd95182b,0x0004002b, + 0x00000006,0x000001c9,0x3c07fcb9,0x0004002b,0x00000006,0x000001ca,0xbe0f7660,0x0004002b, + 0x00000006,0x000001cb,0x3f5d9e84,0x0004002b,0x00000006,0x000001cc,0x3e9fbe77,0x0004002b, + 0x00000006,0x000001cd,0xbd9eecc0,0x0004002b,0x00000006,0x000001ce,0x3c185f07,0x0004002b, + 0x00000006,0x000001cf,0x3d00346e,0x0004002b,0x00000006,0x000001d0,0xbe1205bc,0x0004002b, + 0x00000006,0x000001d1,0x3f59c0ec,0x0004002b,0x00000006,0x000001d2,0x3eaa7efa,0x0004002b, + 0x00000006,0x000001d3,0xbda8f5c3,0x0004002b,0x00000006,0x000001d4,0x3c28c155,0x0004002b, + 0x00000006,0x000001d5,0xbe13f7cf,0x0004002b,0x00000006,0x000001d6,0x3f55dcc6,0x0004002b, + 0x00000006,0x000001d7,0x3eb53f7d,0x0004002b,0x00000006,0x000001d8,0xbdb2fec5,0x0004002b, + 0x00000006,0x000001d9,0x3c378034,0x0004002b,0x00000006,0x000001da,0xbe158106,0x0004002b, + 0x00000006,0x000001db,0x3f51bda5,0x0004002b,0x00000006,0x000001dc,0x3ec04189,0x0004002b, + 0x00000006,0x000001dd,0xbdbd07c8,0x0004002b,0x00000006,0x000001de,0x3c47e282,0x0004002b, + 0x00000006,0x000001df,0xbe16872b,0x0004002b,0x00000006,0x000001e0,0x3f4d5cfb,0x0004002b, + 0x00000006,0x000001e1,0x3ecb020c,0x0004002b,0x00000006,0x000001e2,0xbdc60aa6,0x0004002b, + 0x00000006,0x000001e3,0x3c6075f7,0x0004002b,0x00000006,0x000001e4,0xbe177319,0x0004002b, + 0x00000006,0x000001e5,0x3f491d15,0x0004002b,0x00000006,0x000001e6,0x3ed645a2,0x0004002b, + 0x00000006,0x000001e7,0xbdd013a9,0x0004002b,0x00000006,0x000001e8,0x3c6f34d7,0x0004002b, + 0x00000006,0x000001e9,0x3f44a234,0x0004002b,0x00000006,0x000001ea,0x3ee13a93,0x0004002b, + 0x00000006,0x000001eb,0xbdd91687,0x0004002b,0x00000006,0x000001ec,0x3c7f9724,0x0004002b, + 0x00000006,0x000001ed,0x3cf41f21,0x0004002b,0x00000006,0x000001ee,0x3f4020c5,0x0004002b, + 0x00000006,0x000001ef,0x3eec3c9f,0x0004002b,0x00000006,0x000001f0,0xbde21965,0x0004002b, + 0x00000006,0x000001f1,0x3f3b3d08,0x0004002b,0x00000006,0x000001f2,0x3ef73eab,0x0004002b, + 0x00000006,0x000001f3,0xbdeae7d5,0x0004002b,0x00000006,0x000001f4,0x3c944674,0x0004002b, + 0x00000006,0x000001f5,0x3f363f14,0x0004002b,0x00000006,0x000001f6,0x3f014120,0x0004002b, + 0x00000006,0x000001f7,0xbdf318fc,0x0004002b,0x00000006,0x000001f8,0x3c9ba5e3,0x0004002b, + 0x00000006,0x000001f9,0x3f3161e5,0x0004002b,0x00000006,0x000001fa,0x3f06c227,0x0004002b, + 0x00000006,0x000001fb,0xbdfb15b5,0x0004002b,0x00000006,0x000001fc,0x3ca3d70a,0x0004002b, + 0x00000006,0x000001fd,0x3cdfa440,0x0004002b,0x00000006,0x000001fe,0xbe1288ce,0x0004002b, + 0x00000006,0x000001ff,0x3f2c2268,0x0004002b,0x00000006,0x00000200,0x3f0c432d,0x0004002b, + 0x00000006,0x00000201,0xbe010625,0x0004002b,0x00000006,0x00000202,0x3cb020c5,0x0004002b, + 0x00000006,0x00000203,0xbe107c85,0x0004002b,0x00000006,0x00000204,0x3f271de7,0x0004002b, + 0x00000006,0x00000205,0x3f11bda5,0x0004002b,0x00000006,0x00000206,0xbe050481,0x0004002b, + 0x00000006,0x00000207,0xbe0e075f,0x0004002b,0x00000006,0x00000208,0x3f21de6a,0x0004002b, + 0x00000006,0x00000209,0x3f171de7,0x0004002b,0x00000006,0x0000020a,0xbe07fcb9,0x0004002b, + 0x00000006,0x0000020b,0x3cbfb15b,0x0004002b,0x00000006,0x0000020c,0x3cc7e282,0x0004002b, + 0x00000006,0x0000020d,0xbe0af4f1,0x0004002b,0x00000006,0x0000020e,0x3f1c7e28,0x0183002c, + 0x0000016a,0x0000020f,0x000000a5,0x000000a5,0x000000b2,0x000000a5,0x000000a5,0x000000a5, + 0x0000016b,0x0000016c,0x000000b2,0x0000016d,0x0000016e,0x000000a5,0x0000016f,0x00000170, + 0x00000171,0x00000172,0x00000173,0x000000a5,0x00000174,0x00000175,0x00000176,0x00000177, + 0x00000178,0x00000179,0x0000017a,0x0000017b,0x0000017c,0x0000017d,0x0000017e,0x00000179, + 0x0000017f,0x00000180,0x00000181,0x00000182,0x00000183,0x00000179,0x00000184,0x00000185, + 0x00000186,0x00000187,0x00000188,0x00000189,0x0000018a,0x0000018b,0x0000018c,0x0000018d, + 0x0000018e,0x0000018f,0x00000190,0x00000191,0x00000192,0x00000193,0x00000194,0x00000195, + 0x00000196,0x00000197,0x00000198,0x00000199,0x0000019a,0x0000019b,0x0000019c,0x0000019d, + 0x0000019e,0x0000019f,0x000001a0,0x0000016b,0x000001a1,0x000001a2,0x000001a3,0x000001a4, + 0x000001a5,0x000001a6,0x000001a7,0x000001a8,0x000001a9,0x000001aa,0x000001ab,0x000001ac, + 0x000001ad,0x000001ae,0x000001af,0x000001b0,0x000001b1,0x000001b2,0x000001b3,0x000001b4, + 0x000001b5,0x000001b6,0x000001b7,0x000001b8,0x000001b9,0x000001ba,0x000001bb,0x000001bc, + 0x000001bd,0x0000016f,0x000001be,0x000001bf,0x000001c0,0x000001c1,0x000001c2,0x000001c3, + 0x000001c4,0x000001c5,0x000001c6,0x000001c7,0x000001c8,0x000001c9,0x000001c4,0x000001ca, + 0x000001cb,0x000001cc,0x000001cd,0x000001ce,0x000001cf,0x000001d0,0x000001d1,0x000001d2, + 0x000001d3,0x000001d4,0x000001cf,0x000001d5,0x000001d6,0x000001d7,0x000001d8,0x000001d9, + 0x000001cf,0x000001da,0x000001db,0x000001dc,0x000001dd,0x000001de,0x000001cf,0x000001df, + 0x000001e0,0x000001e1,0x000001e2,0x000001e3,0x000001c4,0x000001e4,0x000001e5,0x000001e6, + 0x000001e7,0x000001e8,0x000001be,0x000001e4,0x000001e9,0x000001ea,0x000001eb,0x000001ec, + 0x000001ed,0x000001e4,0x000001ee,0x000001ef,0x000001f0,0x00000184,0x000001b9,0x000001df, + 0x000001f1,0x000001f2,0x000001f3,0x000001f4,0x000001b3,0x000001da,0x000001f5,0x000001f6, + 0x000001f7,0x000001f8,0x000001ad,0x000001d5,0x000001f9,0x000001fa,0x000001fb,0x000001fc, + 0x000001fd,0x000001fe,0x000001ff,0x00000200,0x00000201,0x00000202,0x000001a7,0x00000203, + 0x00000204,0x00000205,0x00000206,0x00000196,0x000001a1,0x00000207,0x00000208,0x00000209, + 0x0000020a,0x0000020b,0x0000020c,0x0000020d,0x0000020e,0x0000020e,0x0000020d,0x0000020c, + 0x0000020b,0x0000020a,0x00000209,0x00000208,0x00000207,0x000001a1,0x00000196,0x00000206, + 0x00000205,0x00000204,0x00000203,0x000001a7,0x00000202,0x00000201,0x00000200,0x000001ff, + 0x000001fe,0x000001fd,0x000001fc,0x000001fb,0x000001fa,0x000001f9,0x000001d5,0x000001ad, + 0x000001f8,0x000001f7,0x000001f6,0x000001f5,0x000001da,0x000001b3,0x000001f4,0x000001f3, + 0x000001f2,0x000001f1,0x000001df,0x000001b9,0x00000184,0x000001f0,0x000001ef,0x000001ee, + 0x000001e4,0x000001ed,0x000001ec,0x000001eb,0x000001ea,0x000001e9,0x000001e4,0x000001be, + 0x000001e8,0x000001e7,0x000001e6,0x000001e5,0x000001e4,0x000001c4,0x000001e3,0x000001e2, + 0x000001e1,0x000001e0,0x000001df,0x000001cf,0x000001de,0x000001dd,0x000001dc,0x000001db, + 0x000001da,0x000001cf,0x000001d9,0x000001d8,0x000001d7,0x000001d6,0x000001d5,0x000001cf, + 0x000001d4,0x000001d3,0x000001d2,0x000001d1,0x000001d0,0x000001cf,0x000001ce,0x000001cd, + 0x000001cc,0x000001cb,0x000001ca,0x000001c4,0x000001c9,0x000001c8,0x000001c7,0x000001c6, + 0x000001c5,0x000001c4,0x000001c3,0x000001c2,0x000001c1,0x000001c0,0x000001bf,0x000001be, + 0x0000016f,0x000001bd,0x000001bc,0x000001bb,0x000001ba,0x000001b9,0x000001b8,0x000001b7, + 0x000001b6,0x000001b5,0x000001b4,0x000001b3,0x000001b2,0x000001b1,0x000001b0,0x000001af, + 0x000001ae,0x000001ad,0x000001ac,0x000001ab,0x000001aa,0x000001a9,0x000001a8,0x000001a7, + 0x000001a6,0x000001a5,0x000001a4,0x000001a3,0x000001a2,0x000001a1,0x0000016b,0x000001a0, + 0x0000019f,0x0000019e,0x0000019d,0x0000019c,0x0000019b,0x0000019a,0x00000199,0x00000198, + 0x00000197,0x00000196,0x00000195,0x00000194,0x00000193,0x00000192,0x00000191,0x00000190, + 0x0000018f,0x0000018e,0x0000018d,0x0000018c,0x0000018b,0x0000018a,0x00000189,0x00000188, + 0x00000187,0x00000186,0x00000185,0x00000184,0x00000179,0x00000183,0x00000182,0x00000181, + 0x00000180,0x0000017f,0x00000179,0x0000017e,0x0000017d,0x0000017c,0x0000017b,0x0000017a, + 0x00000179,0x00000178,0x00000177,0x00000176,0x00000175,0x00000174,0x000000a5,0x00000173, + 0x00000172,0x00000171,0x00000170,0x0000016f,0x000000a5,0x0000016e,0x0000016d,0x000000b2, + 0x0000016c,0x0000016b,0x00040020,0x00000214,0x00000007,0x0000016a,0x0004002b,0x00000025, + 0x0000021f,0x00000001,0x0004002b,0x00000006,0x0000022a,0xbf19a027,0x0004002b,0x00000006, + 0x0000022b,0x3f99a027,0x0004002b,0x00000006,0x0000022c,0xbf1bc01a,0x0004002b,0x00000006, + 0x0000022d,0x3f996f00,0x0004002b,0x00000006,0x0000022e,0xbf171de7,0x0004002b,0x00000006, + 0x0000022f,0xbb3e0ded,0x0004002b,0x00000006,0x00000230,0xbf1d5cfb,0x0004002b,0x00000006, + 0x00000231,0x3f990ff9,0x0004002b,0x00000006,0x00000232,0xbf143fe6,0x0004002b,0x00000006, + 0x00000233,0xbf1e9e1b,0x0004002b,0x00000006,0x00000234,0x3f983127,0x0004002b,0x00000006, + 0x00000235,0xbf10ded3,0x0004002b,0x00000006,0x00000236,0xbf1f9db2,0x0004002b,0x00000006, + 0x00000237,0x3f9710cb,0x0004002b,0x00000006,0x00000238,0xbf0d21ff,0x0004002b,0x00000006, + 0x00000239,0xbc7765fe,0x0004002b,0x00000006,0x0000023a,0xbf20624e,0x0004002b,0x00000006, + 0x0000023b,0x3f95bf48,0x0004002b,0x00000006,0x0000023c,0xbf0902de,0x0004002b,0x00000006, + 0x0000023d,0xbc9fbe77,0x0004002b,0x00000006,0x0000023e,0xbf208312,0x0004002b,0x00000006, + 0x0000023f,0x3f943fe6,0x0004002b,0x00000006,0x00000240,0xbf04a234,0x0004002b,0x00000006, + 0x00000241,0xbcd42c3d,0x0004002b,0x00000006,0x00000242,0xbf20ded3,0x0004002b,0x00000006, + 0x00000243,0x3f929fbe,0x0004002b,0x00000006,0x00000244,0xbf0020c5,0x0004002b,0x00000006, + 0x00000245,0xbd01d7dc,0x0004002b,0x00000006,0x00000246,0x3f904ea5,0x0004002b,0x00000006, + 0x00000247,0xbef53f7d,0x0004002b,0x00000006,0x00000248,0xbd1e1b09,0x0004002b,0x00000006, + 0x00000249,0x3f8df06f,0x0004002b,0x00000006,0x0000024a,0xbee9fbe7,0x0004002b,0x00000006, + 0x0000024b,0xbd39f55a,0x0004002b,0x00000006,0x0000024c,0x3c902de0,0x0004002b,0x00000006, + 0x0000024d,0xbf1e6320,0x0004002b,0x00000006,0x0000024e,0x3f8b404f,0x0004002b,0x00000006, + 0x0000024f,0xbede83e4,0x0004002b,0x00000006,0x00000250,0xbd59e83e,0x0004002b,0x00000006, + 0x00000251,0xbf1d21ff,0x0004002b,0x00000006,0x00000252,0x3f886f69,0x0004002b,0x00000006, + 0x00000253,0xbed205bc,0x0004002b,0x00000006,0x00000254,0xbd7be76d,0x0004002b,0x00000006, + 0x00000255,0xbf1b5dcc,0x0004002b,0x00000006,0x00000256,0x3f852f1b,0x0004002b,0x00000006, + 0x00000257,0xbec4c2f8,0x0004002b,0x00000006,0x00000258,0xbd8ef34d,0x0004002b,0x00000006, + 0x00000259,0x3c9fbe77,0x0004002b,0x00000006,0x0000025a,0xbf19c0ec,0x0004002b,0x00000006, + 0x0000025b,0x3f820f91,0x0004002b,0x00000006,0x0000025c,0xbeb6fd22,0x0004002b,0x00000006, + 0x0000025d,0xbda30553,0x0004002b,0x00000006,0x0000025e,0xbf17c1be,0x0004002b,0x00000006, + 0x0000025f,0x3f7d42c4,0x0004002b,0x00000006,0x00000260,0xbea83e42,0x0004002b,0x00000006, + 0x00000261,0xbdb7e910,0x0004002b,0x00000006,0x00000262,0xbf14fdf4,0x0004002b,0x00000006, + 0x00000263,0x3f753f7d,0x0004002b,0x00000006,0x00000264,0xbe98fc50,0x0004002b,0x00000006, + 0x00000265,0xbdcd013b,0x0004002b,0x00000006,0x00000266,0xbf12a305,0x0004002b,0x00000006, + 0x00000267,0x3f6de00d,0x0004002b,0x00000006,0x00000268,0xbe89ba5e,0x0004002b,0x00000006, + 0x00000269,0xbf0fdf3b,0x0004002b,0x00000006,0x0000026a,0x3f65c28f,0x0004002b,0x00000006, + 0x0000026b,0xbe727bb3,0x0004002b,0x00000006,0x0000026c,0x3b7f9724,0x0004002b,0x00000006, + 0x0000026d,0xbf0cbfb1,0x0004002b,0x00000006,0x0000026e,0x3f5d42c4,0x0004002b,0x00000006, + 0x0000026f,0xbe5182aa,0x0004002b,0x00000006,0x00000270,0xbe0985f0,0x0004002b,0x00000006, + 0x00000271,0xbf097f63,0x0004002b,0x00000006,0x00000272,0x3f54816f,0x0004002b,0x00000006, + 0x00000273,0xbe2f0069,0x0004002b,0x00000006,0x00000274,0xbe160419,0x0004002b,0x00000006, + 0x00000275,0xbf061e4f,0x0004002b,0x00000006,0x00000276,0x3f4b5dcc,0x0004002b,0x00000006, + 0x00000277,0xbe228241,0x0004002b,0x00000006,0x00000278,0x3bb0f27c,0x0004002b,0x00000006, + 0x00000279,0xbf02bd3c,0x0004002b,0x00000006,0x0000027a,0x3f428241,0x0004002b,0x00000006, + 0x0000027b,0xbdd119ce,0x0004002b,0x00000006,0x0000027c,0xbe3089a0,0x0004002b,0x00000006, + 0x0000027d,0xbefe425b,0x0004002b,0x00000006,0x0000027e,0x3f391d15,0x0004002b,0x00000006, + 0x0000027f,0xbd84ea4b,0x0004002b,0x00000006,0x00000280,0xbe3ef9db,0x0004002b,0x00000006, + 0x00000281,0xbef6bb99,0x0004002b,0x00000006,0x00000282,0x3f2f41f2,0x0004002b,0x00000006, + 0x00000283,0xbcebedfa,0x0004002b,0x00000006,0x00000284,0xbe4c7e28,0x0004002b,0x00000006, + 0x00000285,0x3bded289,0x0004002b,0x00000006,0x00000286,0xbeef0069,0x0004002b,0x00000006, + 0x00000287,0x3f256042,0x0004002b,0x00000006,0x00000288,0xbe5b8bac,0x0004002b,0x00000006, + 0x00000289,0xbee6c227,0x0004002b,0x00000006,0x0000028a,0x3f1b020c,0x0004002b,0x00000006, + 0x0000028b,0x3d4432ca,0x0004002b,0x00000006,0x0000028c,0xbe6a7efa,0x0004002b,0x00000006, + 0x0000028d,0x3c8c154d,0x0004002b,0x00000006,0x0000028e,0xbedfbe77,0x0004002b,0x00000006, + 0x0000028f,0x3dafec57,0x0004002b,0x00000006,0x00000290,0xbe7a786c,0x0004002b,0x00000006, + 0x00000291,0x3c83e426,0x0004002b,0x00000006,0x00000292,0xbed6fd22,0x0004002b,0x00000006, + 0x00000293,0x3f073eab,0x0004002b,0x00000006,0x00000294,0x3e008312,0x0004002b,0x00000006, + 0x00000295,0xbe850481,0x0004002b,0x00000006,0x00000296,0x3c20902e,0x0004002b,0x00000006, + 0x00000297,0xbecf41f2,0x0004002b,0x00000006,0x00000298,0x3efa0275,0x0004002b,0x00000006, + 0x00000299,0x3e2978d5,0x0004002b,0x00000006,0x0000029a,0xbe8d013b,0x0004002b,0x00000006, + 0x0000029b,0x3c7765fe,0x0004002b,0x00000006,0x0000029c,0xbec703b0,0x0004002b,0x00000006, + 0x0000029d,0x3ee63f14,0x0004002b,0x00000006,0x0000029e,0x3e50ff97,0x0004002b,0x00000006, + 0x0000029f,0xbe94fdf4,0x0004002b,0x00000006,0x000002a0,0x3c2f4f0e,0x0004002b,0x00000006, + 0x000002a1,0xbebe00d2,0x0004002b,0x00000006,0x000002a2,0x3ed07c85,0x0004002b,0x00000006, + 0x000002a3,0x3e7a786c,0x0004002b,0x00000006,0x000002a4,0xbe9cfaad,0x0004002b,0x00000006, + 0x000002a5,0xbeb60419,0x0004002b,0x00000006,0x000002a6,0x3ebc01a3,0x0004002b,0x00000006, + 0x000002a7,0x3e9205bc,0x0004002b,0x00000006,0x000002a8,0xbea5460b,0x0004002b,0x00000006, + 0x000002a9,0xbeadc5d6,0x0004002b,0x00000006,0x000002aa,0x3ea703b0,0x0183002c,0x0000016a, + 0x000002ab,0x000000a5,0x0000022a,0x0000022b,0x0000022a,0x000000a5,0x000000a5,0x0000016b, + 0x0000022c,0x0000022d,0x0000022e,0x0000022f,0x000000a5,0x000001b2,0x00000230,0x00000231, + 0x00000232,0x00000173,0x00000179,0x000001c3,0x00000233,0x00000234,0x00000235,0x00000178, + 0x000000a5,0x000001ce,0x00000236,0x00000237,0x00000238,0x00000239,0x000000a5,0x000001d9, + 0x0000023a,0x0000023b,0x0000023c,0x0000023d,0x00000179,0x000001de,0x0000023e,0x0000023f, + 0x00000240,0x00000241,0x00000179,0x0000017f,0x00000242,0x00000243,0x00000244,0x00000245, + 0x00000179,0x000001ec,0x0000023a,0x00000246,0x00000247,0x00000248,0x00000179,0x00000184, + 0x00000236,0x00000249,0x0000024a,0x0000024b,0x00000189,0x0000024c,0x0000024d,0x0000024e, + 0x0000024f,0x00000250,0x00000189,0x000001f4,0x00000251,0x00000252,0x00000253,0x00000254, + 0x0000018f,0x000001f8,0x00000255,0x00000256,0x00000257,0x00000258,0x0000018f,0x00000259, + 0x0000025a,0x0000025b,0x0000025c,0x0000025d,0x00000195,0x000001fc,0x0000025e,0x0000025f, + 0x00000260,0x00000261,0x0000019b,0x000001fc,0x00000262,0x00000263,0x00000264,0x00000265, + 0x0000016b,0x000001fc,0x00000266,0x00000267,0x00000268,0x000001f0,0x000001a6,0x000001fc, + 0x00000269,0x0000026a,0x0000026b,0x000001fb,0x0000026c,0x00000190,0x0000026d,0x0000026e, + 0x0000026f,0x00000270,0x000001ac,0x000001fc,0x00000271,0x00000272,0x00000273,0x00000274, + 0x000001b2,0x00000259,0x00000275,0x00000276,0x000001c5,0x00000277,0x00000278,0x00000259, + 0x00000279,0x0000027a,0x0000027b,0x0000027c,0x000001b8,0x000001f8,0x0000027d,0x0000027e, + 0x0000027f,0x00000280,0x0000016f,0x0000018a,0x00000281,0x00000282,0x00000283,0x00000284, + 0x00000285,0x0000018a,0x00000286,0x00000287,0x000001ce,0x00000288,0x000001c3,0x0000024c, + 0x00000289,0x0000028a,0x0000028b,0x0000028c,0x000001c9,0x0000028d,0x0000028e,0x00000205, + 0x0000028f,0x00000290,0x00000174,0x00000291,0x00000292,0x00000293,0x00000294,0x00000295, + 0x00000296,0x00000291,0x00000297,0x00000298,0x00000299,0x0000029a,0x000001d4,0x0000029b, + 0x0000029c,0x0000029d,0x0000029e,0x0000029f,0x000002a0,0x0000017f,0x000002a1,0x000002a2, + 0x000002a3,0x000002a4,0x0000017a,0x000001e3,0x000002a5,0x000002a6,0x000002a7,0x000002a8, + 0x000001de,0x0000016d,0x000002a9,0x000002aa,0x000002aa,0x000002a9,0x0000016d,0x000001de, + 0x000002a8,0x000002a7,0x000002a6,0x000002a5,0x000001e3,0x0000017a,0x000002a4,0x000002a3, + 0x000002a2,0x000002a1,0x0000017f,0x000002a0,0x0000029f,0x0000029e,0x0000029d,0x0000029c, + 0x0000029b,0x000001d4,0x0000029a,0x00000299,0x00000298,0x00000297,0x00000291,0x00000296, + 0x00000295,0x00000294,0x00000293,0x00000292,0x00000291,0x00000174,0x00000290,0x0000028f, + 0x00000205,0x0000028e,0x0000028d,0x000001c9,0x0000028c,0x0000028b,0x0000028a,0x00000289, + 0x0000024c,0x000001c3,0x00000288,0x000001ce,0x00000287,0x00000286,0x0000018a,0x00000285, + 0x00000284,0x00000283,0x00000282,0x00000281,0x0000018a,0x0000016f,0x00000280,0x0000027f, + 0x0000027e,0x0000027d,0x000001f8,0x000001b8,0x0000027c,0x0000027b,0x0000027a,0x00000279, + 0x00000259,0x00000278,0x00000277,0x000001c5,0x00000276,0x00000275,0x00000259,0x000001b2, + 0x00000274,0x00000273,0x00000272,0x00000271,0x000001fc,0x000001ac,0x00000270,0x0000026f, + 0x0000026e,0x0000026d,0x00000190,0x0000026c,0x000001fb,0x0000026b,0x0000026a,0x00000269, + 0x000001fc,0x000001a6,0x000001f0,0x00000268,0x00000267,0x00000266,0x000001fc,0x0000016b, + 0x00000265,0x00000264,0x00000263,0x00000262,0x000001fc,0x0000019b,0x00000261,0x00000260, + 0x0000025f,0x0000025e,0x000001fc,0x00000195,0x0000025d,0x0000025c,0x0000025b,0x0000025a, + 0x00000259,0x0000018f,0x00000258,0x00000257,0x00000256,0x00000255,0x000001f8,0x0000018f, + 0x00000254,0x00000253,0x00000252,0x00000251,0x000001f4,0x00000189,0x00000250,0x0000024f, + 0x0000024e,0x0000024d,0x0000024c,0x00000189,0x0000024b,0x0000024a,0x00000249,0x00000236, + 0x00000184,0x00000179,0x00000248,0x00000247,0x00000246,0x0000023a,0x000001ec,0x00000179, + 0x00000245,0x00000244,0x00000243,0x00000242,0x0000017f,0x00000179,0x00000241,0x00000240, + 0x0000023f,0x0000023e,0x000001de,0x00000179,0x0000023d,0x0000023c,0x0000023b,0x0000023a, + 0x000001d9,0x000000a5,0x00000239,0x00000238,0x00000237,0x00000236,0x000001ce,0x000000a5, + 0x00000178,0x00000235,0x00000234,0x00000233,0x000001c3,0x00000179,0x00000173,0x00000232, + 0x00000231,0x00000230,0x000001b2,0x000000a5,0x0000022f,0x0000022e,0x0000022d,0x0000022c, + 0x0000016b,0x0004002b,0x00000006,0x000002bd,0x3ee66666,0x0004002b,0x00000006,0x000002bf, + 0x400e38e4,0x00040020,0x000002c5,0x00000006,0x00000006,0x0004003b,0x000002c5,0x000002c6, + 0x00000006,0x0004003b,0x000002c5,0x000002c9,0x00000006,0x0004003b,0x000002c5,0x000002d1, + 0x00000006,0x0004003b,0x000002c5,0x000002d4,0x00000006,0x0004002b,0x00000025,0x000002df, + 0x00000002,0x0004002b,0x00000025,0x000002e0,0x00000003,0x0004002b,0x00000025,0x000002e1, + 0x00000004,0x0004002b,0x00000025,0x000002e2,0x00000005,0x0004002b,0x00000006,0x00000384, + 0x3f000000,0x0004002b,0x00000031,0x0000038a,0x00000007,0x0004001c,0x0000038b,0x00000006, + 0x0000038a,0x00040020,0x0000038c,0x00000007,0x0000038b,0x0004002b,0x00000006,0x0000041d, + 0x42800000,0x0004002b,0x00000031,0x00000429,0x00000003,0x0005001e,0x000004d4,0x0000000e, + 0x0000000e,0x00000006,0x00040020,0x000004d5,0x00000009,0x000004d4,0x0004003b,0x000004d5, + 0x000004d6,0x00000009,0x00040020,0x000004d7,0x00000009,0x00000006,0x0004002b,0x00000006, + 0x000004e1,0x3fa00000,0x0004002b,0x00000006,0x000004e2,0x3fe00000,0x0004002b,0x00000006, + 0x000004ec,0x3ecccccd,0x0004002b,0x00000006,0x000004f0,0x3f99999a,0x0004002b,0x00000006, + 0x000004f5,0x3fcccccd,0x0004002b,0x00000006,0x000004f9,0x3fe66666,0x0004002b,0x00000006, + 0x000004ff,0x3dcccccd,0x0004002b,0x00000006,0x00000500,0x3e0f5c29,0x0004002b,0x00000006, + 0x00000504,0x3ea3d70a,0x0004002b,0x00000006,0x0000050c,0x3f19999a,0x00040017,0x00000512, + 0x00000006,0x00000002,0x00040020,0x00000513,0x00000007,0x00000512,0x00040020,0x00000515, + 0x00000009,0x0000000e,0x00040020,0x0000051e,0x00000001,0x00000512,0x0004003b,0x0000051e, + 0x0000051f,0x00000001,0x00040020,0x00000520,0x00000001,0x00000006,0x00090019,0x00000567, + 0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b, + 0x00000568,0x00000567,0x00040020,0x00000569,0x00000000,0x00000568,0x0004003b,0x00000569, + 0x0000056a,0x00000000,0x00040020,0x00000636,0x00000003,0x0000000e,0x0004003b,0x00000636, + 0x00000637,0x00000003,0x0004002b,0x00000006,0x00000641,0x41200000,0x0004002b,0x00000006, + 0x00000642,0x3f666666,0x0004002b,0x00000025,0x00000643,0x00000040,0x00050036,0x00000002, + 0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000000d,0x000004d3, + 0x00000007,0x0004003b,0x0000000d,0x000004db,0x00000007,0x0004003b,0x0000000d,0x000004de, + 0x00000007,0x0004003b,0x0000000d,0x000004e4,0x00000007,0x0004003b,0x0000000d,0x000004e8, + 0x00000007,0x0004003b,0x0000000d,0x000004f4,0x00000007,0x0004003b,0x0000000d,0x00000508, + 0x00000007,0x0004003b,0x00000513,0x00000514,0x00000007,0x0004003b,0x00000513,0x00000519, + 0x00000007,0x0004003b,0x0000000d,0x0000051d,0x00000007,0x0004003b,0x0000000d,0x00000527, + 0x00000007,0x0004003b,0x0000000d,0x0000052e,0x00000007,0x0004003b,0x0000000d,0x00000531, + 0x00000007,0x0004003b,0x0000000d,0x00000534,0x00000007,0x0004003b,0x0000000d,0x00000538, + 0x00000007,0x0004003b,0x00000026,0x0000053c,0x00000007,0x0004003b,0x00000026,0x00000540, + 0x00000007,0x0004003b,0x00000026,0x00000544,0x00000007,0x0004003b,0x00000026,0x0000054c, + 0x00000007,0x0004003b,0x00000513,0x00000554,0x00000007,0x0004003b,0x0000003b,0x00000564, + 0x00000007,0x0004003b,0x00000008,0x0000056e,0x00000007,0x0004003b,0x0000001b,0x00000576, + 0x00000007,0x0004003b,0x0000000d,0x00000577,0x00000007,0x0004003b,0x0000000d,0x0000057a, + 0x00000007,0x0004003b,0x0000000d,0x0000057d,0x00000007,0x0004003b,0x0000000d,0x00000580, + 0x00000007,0x0004003b,0x0000000d,0x00000583,0x00000007,0x0004003b,0x0000000d,0x00000586, + 0x00000007,0x0004003b,0x0000000d,0x00000589,0x00000007,0x0004003b,0x0000000d,0x0000058c, + 0x00000007,0x0004003b,0x0000000d,0x0000058f,0x00000007,0x0004003b,0x0000001b,0x00000593, + 0x00000007,0x0004003b,0x0000000d,0x00000594,0x00000007,0x0004003b,0x0000000d,0x00000597, + 0x00000007,0x0004003b,0x0000000d,0x0000059a,0x00000007,0x0004003b,0x0000000d,0x0000059d, + 0x00000007,0x0004003b,0x0000000d,0x000005a0,0x00000007,0x0004003b,0x0000000d,0x000005a3, + 0x00000007,0x0004003b,0x0000000d,0x000005a6,0x00000007,0x0004003b,0x0000000d,0x000005a9, + 0x00000007,0x0004003b,0x0000000d,0x000005ac,0x00000007,0x0004003b,0x0000001b,0x000005b0, + 0x00000007,0x0004003b,0x0000000d,0x000005b1,0x00000007,0x0004003b,0x0000000d,0x000005b4, + 0x00000007,0x0004003b,0x0000000d,0x000005b7,0x00000007,0x0004003b,0x0000000d,0x000005ba, + 0x00000007,0x0004003b,0x0000000d,0x000005bd,0x00000007,0x0004003b,0x0000000d,0x000005c0, + 0x00000007,0x0004003b,0x0000000d,0x000005c3,0x00000007,0x0004003b,0x0000000d,0x000005c6, + 0x00000007,0x0004003b,0x0000000d,0x000005c9,0x00000007,0x0004003b,0x0000001b,0x000005cd, + 0x00000007,0x0004003b,0x0000000d,0x000005ce,0x00000007,0x0004003b,0x0000000d,0x000005d1, + 0x00000007,0x0004003b,0x0000000d,0x000005d4,0x00000007,0x0004003b,0x0000000d,0x000005d7, + 0x00000007,0x0004003b,0x0000000d,0x000005da,0x00000007,0x0004003b,0x0000000d,0x000005dd, + 0x00000007,0x0004003b,0x0000000d,0x000005e0,0x00000007,0x0004003b,0x0000000d,0x000005e3, + 0x00000007,0x0004003b,0x0000000d,0x000005e6,0x00000007,0x0004003b,0x0000001b,0x000005ea, + 0x00000007,0x0004003b,0x0000001b,0x000005eb,0x00000007,0x0004003b,0x0000001b,0x000005ed, + 0x00000007,0x0004003b,0x0000001b,0x000005ef,0x00000007,0x0004003b,0x0000001b,0x000005f1, + 0x00000007,0x0004003b,0x0000000d,0x000005f3,0x00000007,0x0004003b,0x0000000d,0x000005f5, + 0x00000007,0x0004003b,0x0000000d,0x000005f8,0x00000007,0x0004003b,0x0000000d,0x00000605, + 0x00000007,0x0004003b,0x0000003b,0x00000606,0x00000007,0x0004003b,0x00000026,0x00000608, + 0x00000007,0x0004003b,0x00000026,0x0000060a,0x00000007,0x0004003b,0x0000003b,0x0000060f, + 0x00000007,0x0004003b,0x0000000d,0x00000611,0x00000007,0x0004003b,0x0000000d,0x00000613, + 0x00000007,0x0004003b,0x00000026,0x00000615,0x00000007,0x0004003b,0x00000026,0x00000617, + 0x00000007,0x0004003b,0x0000001b,0x00000619,0x00000007,0x0004003b,0x0000001b,0x0000061e, + 0x00000007,0x0004003b,0x0000000d,0x00000622,0x00000007,0x0004003b,0x00000008,0x00000623, + 0x00000007,0x0004003b,0x0000000d,0x00000627,0x00000007,0x00050041,0x000004d7,0x000004d8, + 0x000004d6,0x000002df,0x0004003d,0x00000006,0x000004d9,0x000004d8,0x0008000c,0x00000006, + 0x000004da,0x00000001,0x0000002b,0x000004d9,0x000000a5,0x000000b2,0x0003003e,0x000004d3, + 0x000004da,0x0004003d,0x00000006,0x000004dc,0x000004d3,0x00050083,0x00000006,0x000004dd, + 0x000004dc,0x00000384,0x0003003e,0x000004db,0x000004dd,0x0004003d,0x00000006,0x000004df, + 0x000004db,0x000500be,0x000000a6,0x000004e0,0x000004df,0x000000a5,0x000600a9,0x00000006, + 0x000004e3,0x000004e0,0x000004e1,0x000004e2,0x0003003e,0x000004de,0x000004e3,0x0004003d, + 0x00000006,0x000004e5,0x000004db,0x000500be,0x000000a6,0x000004e6,0x000004e5,0x000000a5, + 0x000600a9,0x00000006,0x000004e7,0x000004e6,0x000004e1,0x000000b2,0x0003003e,0x000004e4, + 0x000004e7,0x0004003d,0x00000006,0x000004e9,0x000004db,0x000500be,0x000000a6,0x000004ea, + 0x000004e9,0x000000a5,0x000600a9,0x00000006,0x000004eb,0x000004ea,0x000004e1,0x000000b2, + 0x0003003e,0x000004e8,0x000004eb,0x0004003d,0x00000006,0x000004ed,0x000004db,0x0004003d, + 0x00000006,0x000004ee,0x000004e4,0x00050085,0x00000006,0x000004ef,0x000004ed,0x000004ee, + 0x00050085,0x00000006,0x000004f1,0x000004ef,0x000004f0,0x00050081,0x00000006,0x000004f2, + 0x000004ec,0x000004f1,0x0007000c,0x00000006,0x000004f3,0x00000001,0x00000028,0x000000a5, + 0x000004f2,0x0003003e,0x000002c9,0x000004f3,0x0004003d,0x00000006,0x000004f6,0x000004db, + 0x0004003d,0x00000006,0x000004f7,0x000004de,0x00050085,0x00000006,0x000004f8,0x000004f6, + 0x000004f7,0x00050085,0x00000006,0x000004fa,0x000004f8,0x000004f9,0x00050081,0x00000006, + 0x000004fb,0x000004f5,0x000004fa,0x0003003e,0x000004f4,0x000004fb,0x0004003d,0x00000006, + 0x000004fc,0x000004f4,0x0004003d,0x00000006,0x000004fd,0x000002c9,0x00050083,0x00000006, + 0x000004fe,0x000004fc,0x000004fd,0x0003003e,0x000002c6,0x000004fe,0x0004003d,0x00000006, + 0x00000501,0x000004db,0x0004003d,0x00000006,0x00000502,0x000004e8,0x00050085,0x00000006, + 0x00000503,0x00000501,0x00000502,0x00050085,0x00000006,0x00000505,0x00000503,0x00000504, + 0x00050081,0x00000006,0x00000506,0x00000500,0x00000505,0x0007000c,0x00000006,0x00000507, + 0x00000001,0x00000028,0x000004ff,0x00000506,0x0003003e,0x000002d4,0x00000507,0x0004003d, + 0x00000006,0x00000509,0x000004db,0x0004003d,0x00000006,0x0000050a,0x000004e8,0x00050085, + 0x00000006,0x0000050b,0x00000509,0x0000050a,0x00050085,0x00000006,0x0000050d,0x0000050b, + 0x0000050c,0x00050081,0x00000006,0x0000050e,0x00000384,0x0000050d,0x0003003e,0x00000508, + 0x0000050e,0x0004003d,0x00000006,0x0000050f,0x00000508,0x0004003d,0x00000006,0x00000510, + 0x000002d4,0x00050083,0x00000006,0x00000511,0x0000050f,0x00000510,0x0003003e,0x000002d1, + 0x00000511,0x00050041,0x00000515,0x00000516,0x000004d6,0x0000021f,0x0004003d,0x0000000e, + 0x00000517,0x00000516,0x0007004f,0x00000512,0x00000518,0x00000517,0x00000517,0x00000002, + 0x00000003,0x0003003e,0x00000514,0x00000518,0x00050041,0x00000515,0x0000051a,0x000004d6, + 0x0000021f,0x0004003d,0x0000000e,0x0000051b,0x0000051a,0x0007004f,0x00000512,0x0000051c, + 0x0000051b,0x0000051b,0x00000000,0x00000001,0x0003003e,0x00000519,0x0000051c,0x00050041, + 0x00000520,0x00000521,0x0000051f,0x0000004c,0x0004003d,0x00000006,0x00000522,0x00000521, + 0x00050041,0x0000000d,0x00000523,0x00000514,0x0000004c,0x0004003d,0x00000006,0x00000524, + 0x00000523,0x00050085,0x00000006,0x00000525,0x00000522,0x00000524,0x00050083,0x00000006, + 0x00000526,0x00000525,0x00000384,0x0003003e,0x0000051d,0x00000526,0x00050041,0x00000520, + 0x00000528,0x0000051f,0x00000051,0x0004003d,0x00000006,0x00000529,0x00000528,0x00050041, + 0x0000000d,0x0000052a,0x00000514,0x00000051,0x0004003d,0x00000006,0x0000052b,0x0000052a, + 0x00050085,0x00000006,0x0000052c,0x00000529,0x0000052b,0x00050083,0x00000006,0x0000052d, + 0x0000052c,0x00000384,0x0003003e,0x00000527,0x0000052d,0x0004003d,0x00000006,0x0000052f, + 0x0000051d,0x0006000c,0x00000006,0x00000530,0x00000001,0x00000008,0x0000052f,0x0003003e, + 0x0000052e,0x00000530,0x0004003d,0x00000006,0x00000532,0x00000527,0x0006000c,0x00000006, + 0x00000533,0x00000001,0x00000008,0x00000532,0x0003003e,0x00000531,0x00000533,0x0004003d, + 0x00000006,0x00000535,0x0000051d,0x0004003d,0x00000006,0x00000536,0x0000052e,0x00050083, + 0x00000006,0x00000537,0x00000535,0x00000536,0x0003003e,0x00000534,0x00000537,0x0004003d, + 0x00000006,0x00000539,0x00000527,0x0004003d,0x00000006,0x0000053a,0x00000531,0x00050083, + 0x00000006,0x0000053b,0x00000539,0x0000053a,0x0003003e,0x00000538,0x0000053b,0x0004003d, + 0x00000006,0x0000053d,0x00000534,0x00050085,0x00000006,0x0000053e,0x0000053d,0x0000041d, + 0x0004006e,0x00000025,0x0000053f,0x0000053e,0x0003003e,0x0000053c,0x0000053f,0x0004003d, + 0x00000006,0x00000541,0x00000538,0x00050085,0x00000006,0x00000542,0x00000541,0x0000041d, + 0x0004006e,0x00000025,0x00000543,0x00000542,0x0003003e,0x00000540,0x00000543,0x0003003e, + 0x00000544,0x0000015c,0x000200f9,0x00000545,0x000200f8,0x00000545,0x000400f6,0x00000547, + 0x00000548,0x00000000,0x000200f9,0x00000549,0x000200f8,0x00000549,0x0004003d,0x00000025, + 0x0000054a,0x00000544,0x000500b1,0x000000a6,0x0000054b,0x0000054a,0x00000167,0x000400fa, + 0x0000054b,0x00000546,0x00000547,0x000200f8,0x00000546,0x0003003e,0x0000054c,0x0000015c, + 0x000200f9,0x0000054d,0x000200f8,0x0000054d,0x000400f6,0x0000054f,0x00000550,0x00000000, + 0x000200f9,0x00000551,0x000200f8,0x00000551,0x0004003d,0x00000025,0x00000552,0x0000054c, + 0x000500b1,0x000000a6,0x00000553,0x00000552,0x00000167,0x000400fa,0x00000553,0x0000054e, + 0x0000054f,0x000200f8,0x0000054e,0x0004003d,0x00000006,0x00000555,0x0000052e,0x0004003d, + 0x00000025,0x00000556,0x0000054c,0x0004006f,0x00000006,0x00000557,0x00000556,0x00050081, + 0x00000006,0x00000558,0x00000555,0x00000557,0x00050083,0x00000006,0x00000559,0x00000558, + 0x00000152,0x0004003d,0x00000006,0x0000055a,0x00000531,0x0004003d,0x00000025,0x0000055b, + 0x00000544,0x0004006f,0x00000006,0x0000055c,0x0000055b,0x00050081,0x00000006,0x0000055d, + 0x0000055a,0x0000055c,0x00050083,0x00000006,0x0000055e,0x0000055d,0x00000152,0x00050050, + 0x00000512,0x0000055f,0x00000559,0x0000055e,0x00050050,0x00000512,0x00000560,0x00000384, + 0x00000384,0x00050081,0x00000512,0x00000561,0x0000055f,0x00000560,0x0004003d,0x00000512, + 0x00000562,0x00000519,0x00050085,0x00000512,0x00000563,0x00000561,0x00000562,0x0003003e, + 0x00000554,0x00000563,0x0004003d,0x00000025,0x00000565,0x00000544,0x0004003d,0x00000025, + 0x00000566,0x0000054c,0x0004003d,0x00000568,0x0000056b,0x0000056a,0x0004003d,0x00000512, + 0x0000056c,0x00000554,0x00070058,0x0000000e,0x0000056d,0x0000056b,0x0000056c,0x00000002, + 0x000000a5,0x0008004f,0x00000007,0x0000056f,0x0000056d,0x0000056d,0x00000000,0x00000001, + 0x00000002,0x0003003e,0x0000056e,0x0000056f,0x00050039,0x00000006,0x00000570,0x0000000b, + 0x0000056e,0x00060041,0x0000000d,0x00000571,0x00000564,0x00000565,0x00000566,0x0003003e, + 0x00000571,0x00000570,0x000200f9,0x00000550,0x000200f8,0x00000550,0x0004003d,0x00000025, + 0x00000572,0x0000054c,0x00050080,0x00000025,0x00000573,0x00000572,0x0000021f,0x0003003e, + 0x0000054c,0x00000573,0x000200f9,0x0000054d,0x000200f8,0x0000054f,0x000200f9,0x00000548, + 0x000200f8,0x00000548,0x0004003d,0x00000025,0x00000574,0x00000544,0x00050080,0x00000025, + 0x00000575,0x00000574,0x0000021f,0x0003003e,0x00000544,0x00000575,0x000200f9,0x00000545, + 0x000200f8,0x00000547,0x00060041,0x0000000d,0x00000578,0x00000564,0x0000021f,0x0000021f, + 0x0004003d,0x00000006,0x00000579,0x00000578,0x0003003e,0x00000577,0x00000579,0x00060041, + 0x0000000d,0x0000057b,0x00000564,0x0000021f,0x000002df,0x0004003d,0x00000006,0x0000057c, + 0x0000057b,0x0003003e,0x0000057a,0x0000057c,0x00060041,0x0000000d,0x0000057e,0x00000564, + 0x0000021f,0x000002e0,0x0004003d,0x00000006,0x0000057f,0x0000057e,0x0003003e,0x0000057d, + 0x0000057f,0x00060041,0x0000000d,0x00000581,0x00000564,0x000002df,0x0000021f,0x0004003d, + 0x00000006,0x00000582,0x00000581,0x0003003e,0x00000580,0x00000582,0x00060041,0x0000000d, + 0x00000584,0x00000564,0x000002df,0x000002df,0x0004003d,0x00000006,0x00000585,0x00000584, + 0x0003003e,0x00000583,0x00000585,0x00060041,0x0000000d,0x00000587,0x00000564,0x000002df, + 0x000002e0,0x0004003d,0x00000006,0x00000588,0x00000587,0x0003003e,0x00000586,0x00000588, + 0x00060041,0x0000000d,0x0000058a,0x00000564,0x000002e0,0x0000021f,0x0004003d,0x00000006, + 0x0000058b,0x0000058a,0x0003003e,0x00000589,0x0000058b,0x00060041,0x0000000d,0x0000058d, + 0x00000564,0x000002e0,0x000002df,0x0004003d,0x00000006,0x0000058e,0x0000058d,0x0003003e, + 0x0000058c,0x0000058e,0x00060041,0x0000000d,0x00000590,0x00000564,0x000002e0,0x000002e0, + 0x0004003d,0x00000006,0x00000591,0x00000590,0x0003003e,0x0000058f,0x00000591,0x000d0039, + 0x0000000e,0x00000592,0x00000019,0x00000577,0x0000057a,0x0000057d,0x00000580,0x00000583, + 0x00000586,0x00000589,0x0000058c,0x0000058f,0x0003003e,0x00000576,0x00000592,0x00060041, + 0x0000000d,0x00000595,0x00000564,0x0000021f,0x000002df,0x0004003d,0x00000006,0x00000596, + 0x00000595,0x0003003e,0x00000594,0x00000596,0x00060041,0x0000000d,0x00000598,0x00000564, + 0x0000021f,0x000002e0,0x0004003d,0x00000006,0x00000599,0x00000598,0x0003003e,0x00000597, + 0x00000599,0x00060041,0x0000000d,0x0000059b,0x00000564,0x0000021f,0x000002e1,0x0004003d, + 0x00000006,0x0000059c,0x0000059b,0x0003003e,0x0000059a,0x0000059c,0x00060041,0x0000000d, + 0x0000059e,0x00000564,0x000002df,0x000002df,0x0004003d,0x00000006,0x0000059f,0x0000059e, + 0x0003003e,0x0000059d,0x0000059f,0x00060041,0x0000000d,0x000005a1,0x00000564,0x000002df, + 0x000002e0,0x0004003d,0x00000006,0x000005a2,0x000005a1,0x0003003e,0x000005a0,0x000005a2, + 0x00060041,0x0000000d,0x000005a4,0x00000564,0x000002df,0x000002e1,0x0004003d,0x00000006, + 0x000005a5,0x000005a4,0x0003003e,0x000005a3,0x000005a5,0x00060041,0x0000000d,0x000005a7, + 0x00000564,0x000002e0,0x000002df,0x0004003d,0x00000006,0x000005a8,0x000005a7,0x0003003e, + 0x000005a6,0x000005a8,0x00060041,0x0000000d,0x000005aa,0x00000564,0x000002e0,0x000002e0, + 0x0004003d,0x00000006,0x000005ab,0x000005aa,0x0003003e,0x000005a9,0x000005ab,0x00060041, + 0x0000000d,0x000005ad,0x00000564,0x000002e0,0x000002e1,0x0004003d,0x00000006,0x000005ae, + 0x000005ad,0x0003003e,0x000005ac,0x000005ae,0x000d0039,0x0000000e,0x000005af,0x00000019, + 0x00000594,0x00000597,0x0000059a,0x0000059d,0x000005a0,0x000005a3,0x000005a6,0x000005a9, + 0x000005ac,0x0003003e,0x00000593,0x000005af,0x00060041,0x0000000d,0x000005b2,0x00000564, + 0x000002df,0x0000021f,0x0004003d,0x00000006,0x000005b3,0x000005b2,0x0003003e,0x000005b1, + 0x000005b3,0x00060041,0x0000000d,0x000005b5,0x00000564,0x000002df,0x000002df,0x0004003d, + 0x00000006,0x000005b6,0x000005b5,0x0003003e,0x000005b4,0x000005b6,0x00060041,0x0000000d, + 0x000005b8,0x00000564,0x000002df,0x000002e0,0x0004003d,0x00000006,0x000005b9,0x000005b8, + 0x0003003e,0x000005b7,0x000005b9,0x00060041,0x0000000d,0x000005bb,0x00000564,0x000002e0, + 0x0000021f,0x0004003d,0x00000006,0x000005bc,0x000005bb,0x0003003e,0x000005ba,0x000005bc, + 0x00060041,0x0000000d,0x000005be,0x00000564,0x000002e0,0x000002df,0x0004003d,0x00000006, + 0x000005bf,0x000005be,0x0003003e,0x000005bd,0x000005bf,0x00060041,0x0000000d,0x000005c1, + 0x00000564,0x000002e0,0x000002e0,0x0004003d,0x00000006,0x000005c2,0x000005c1,0x0003003e, + 0x000005c0,0x000005c2,0x00060041,0x0000000d,0x000005c4,0x00000564,0x000002e1,0x0000021f, + 0x0004003d,0x00000006,0x000005c5,0x000005c4,0x0003003e,0x000005c3,0x000005c5,0x00060041, + 0x0000000d,0x000005c7,0x00000564,0x000002e1,0x000002df,0x0004003d,0x00000006,0x000005c8, + 0x000005c7,0x0003003e,0x000005c6,0x000005c8,0x00060041,0x0000000d,0x000005ca,0x00000564, + 0x000002e1,0x000002e0,0x0004003d,0x00000006,0x000005cb,0x000005ca,0x0003003e,0x000005c9, + 0x000005cb,0x000d0039,0x0000000e,0x000005cc,0x00000019,0x000005b1,0x000005b4,0x000005b7, + 0x000005ba,0x000005bd,0x000005c0,0x000005c3,0x000005c6,0x000005c9,0x0003003e,0x000005b0, + 0x000005cc,0x00060041,0x0000000d,0x000005cf,0x00000564,0x000002df,0x000002df,0x0004003d, + 0x00000006,0x000005d0,0x000005cf,0x0003003e,0x000005ce,0x000005d0,0x00060041,0x0000000d, + 0x000005d2,0x00000564,0x000002df,0x000002e0,0x0004003d,0x00000006,0x000005d3,0x000005d2, + 0x0003003e,0x000005d1,0x000005d3,0x00060041,0x0000000d,0x000005d5,0x00000564,0x000002df, + 0x000002e1,0x0004003d,0x00000006,0x000005d6,0x000005d5,0x0003003e,0x000005d4,0x000005d6, + 0x00060041,0x0000000d,0x000005d8,0x00000564,0x000002e0,0x000002df,0x0004003d,0x00000006, + 0x000005d9,0x000005d8,0x0003003e,0x000005d7,0x000005d9,0x00060041,0x0000000d,0x000005db, + 0x00000564,0x000002e0,0x000002e0,0x0004003d,0x00000006,0x000005dc,0x000005db,0x0003003e, + 0x000005da,0x000005dc,0x00060041,0x0000000d,0x000005de,0x00000564,0x000002e0,0x000002e1, + 0x0004003d,0x00000006,0x000005df,0x000005de,0x0003003e,0x000005dd,0x000005df,0x00060041, + 0x0000000d,0x000005e1,0x00000564,0x000002e1,0x000002df,0x0004003d,0x00000006,0x000005e2, + 0x000005e1,0x0003003e,0x000005e0,0x000005e2,0x00060041,0x0000000d,0x000005e4,0x00000564, + 0x000002e1,0x000002e0,0x0004003d,0x00000006,0x000005e5,0x000005e4,0x0003003e,0x000005e3, + 0x000005e5,0x00060041,0x0000000d,0x000005e7,0x00000564,0x000002e1,0x000002e1,0x0004003d, + 0x00000006,0x000005e8,0x000005e7,0x0003003e,0x000005e6,0x000005e8,0x000d0039,0x0000000e, + 0x000005e9,0x00000019,0x000005ce,0x000005d1,0x000005d4,0x000005d7,0x000005da,0x000005dd, + 0x000005e0,0x000005e3,0x000005e6,0x0003003e,0x000005cd,0x000005e9,0x0004003d,0x0000000e, + 0x000005ec,0x00000576,0x0003003e,0x000005eb,0x000005ec,0x0004003d,0x0000000e,0x000005ee, + 0x00000593,0x0003003e,0x000005ed,0x000005ee,0x0004003d,0x0000000e,0x000005f0,0x000005b0, + 0x0003003e,0x000005ef,0x000005f0,0x0004003d,0x0000000e,0x000005f2,0x000005cd,0x0003003e, + 0x000005f1,0x000005f2,0x0004003d,0x00000006,0x000005f4,0x00000534,0x0003003e,0x000005f3, + 0x000005f4,0x0004003d,0x00000006,0x000005f6,0x00000538,0x0003003e,0x000005f5,0x000005f6, + 0x000a0039,0x0000000e,0x000005f7,0x00000023,0x000005eb,0x000005ed,0x000005ef,0x000005f1, + 0x000005f3,0x000005f5,0x0003003e,0x000005ea,0x000005f7,0x00050041,0x0000000d,0x000005f9, + 0x000005ea,0x0000004c,0x0004003d,0x00000006,0x000005fa,0x000005f9,0x00050083,0x00000006, + 0x000005fb,0x000000b2,0x000005fa,0x00050041,0x0000000d,0x000005fc,0x000005ea,0x00000051, + 0x0004003d,0x00000006,0x000005fd,0x000005fc,0x00050083,0x00000006,0x000005fe,0x000005fb, + 0x000005fd,0x00050041,0x0000000d,0x000005ff,0x000005ea,0x00000057,0x0004003d,0x00000006, + 0x00000600,0x000005ff,0x00050083,0x00000006,0x00000601,0x000005fe,0x00000600,0x00050041, + 0x0000000d,0x00000602,0x000005ea,0x00000429,0x0004003d,0x00000006,0x00000603,0x00000602, + 0x00050083,0x00000006,0x00000604,0x00000601,0x00000603,0x0003003e,0x000005f8,0x00000604, + 0x0004003d,0x0000003a,0x00000607,0x00000564,0x0003003e,0x00000606,0x00000607,0x0004003d, + 0x00000025,0x00000609,0x0000053c,0x0003003e,0x00000608,0x00000609,0x0004003d,0x00000025, + 0x0000060b,0x00000540,0x0003003e,0x0000060a,0x0000060b,0x00070039,0x00000006,0x0000060c, + 0x00000040,0x00000606,0x00000608,0x0000060a,0x0004003d,0x00000006,0x0000060d,0x000005f8, + 0x00050085,0x00000006,0x0000060e,0x0000060c,0x0000060d,0x0003003e,0x00000605,0x0000060e, + 0x0004003d,0x0000003a,0x00000610,0x00000564,0x0003003e,0x0000060f,0x00000610,0x0004003d, + 0x00000006,0x00000612,0x00000534,0x0003003e,0x00000611,0x00000612,0x0004003d,0x00000006, + 0x00000614,0x00000538,0x0003003e,0x00000613,0x00000614,0x0004003d,0x00000025,0x00000616, + 0x0000053c,0x0003003e,0x00000615,0x00000616,0x0004003d,0x00000025,0x00000618,0x00000540, + 0x0003003e,0x00000617,0x00000618,0x0004003d,0x0000000e,0x0000061a,0x000005ea,0x0003003e, + 0x00000619,0x0000061a,0x000a0039,0x00000006,0x0000061b,0x00000049,0x0000060f,0x00000611, + 0x00000613,0x00000615,0x00000617,0x00000619,0x0004003d,0x00000006,0x0000061c,0x00000605, + 0x00050081,0x00000006,0x0000061d,0x0000061c,0x0000061b,0x0003003e,0x00000605,0x0000061d, + 0x0004003d,0x00000568,0x0000061f,0x0000056a,0x0004003d,0x00000512,0x00000620,0x0000051f, + 0x00050057,0x0000000e,0x00000621,0x0000061f,0x00000620,0x0003003e,0x0000061e,0x00000621, + 0x0004003d,0x0000000e,0x00000624,0x0000061e,0x0008004f,0x00000007,0x00000625,0x00000624, + 0x00000624,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000623,0x00000625,0x00050039, + 0x00000006,0x00000626,0x0000000b,0x00000623,0x0003003e,0x00000622,0x00000626,0x0004003d, + 0x00000006,0x00000628,0x00000605,0x0004003d,0x00000006,0x00000629,0x00000622,0x00050083, + 0x00000006,0x0000062a,0x00000628,0x00000629,0x0003003e,0x00000627,0x0000062a,0x0004003d, + 0x00000006,0x0000062b,0x00000627,0x00060050,0x00000007,0x0000062c,0x0000062b,0x0000062b, + 0x0000062b,0x0004003d,0x0000000e,0x0000062d,0x0000061e,0x0008004f,0x00000007,0x0000062e, + 0x0000062d,0x0000062d,0x00000000,0x00000001,0x00000002,0x00050081,0x00000007,0x0000062f, + 0x0000062e,0x0000062c,0x00050041,0x0000000d,0x00000630,0x0000061e,0x0000004c,0x00050051, + 0x00000006,0x00000631,0x0000062f,0x00000000,0x0003003e,0x00000630,0x00000631,0x00050041, + 0x0000000d,0x00000632,0x0000061e,0x00000051,0x00050051,0x00000006,0x00000633,0x0000062f, + 0x00000001,0x0003003e,0x00000632,0x00000633,0x00050041,0x0000000d,0x00000634,0x0000061e, + 0x00000057,0x00050051,0x00000006,0x00000635,0x0000062f,0x00000002,0x0003003e,0x00000634, + 0x00000635,0x0004003d,0x0000000e,0x00000638,0x0000061e,0x0008004f,0x00000007,0x00000639, + 0x00000638,0x00000638,0x00000000,0x00000001,0x00000002,0x00060050,0x00000007,0x0000063a, + 0x000000a5,0x000000a5,0x000000a5,0x00060050,0x00000007,0x0000063b,0x000000b2,0x000000b2, + 0x000000b2,0x0008000c,0x00000007,0x0000063c,0x00000001,0x0000002b,0x00000639,0x0000063a, + 0x0000063b,0x00050051,0x00000006,0x0000063d,0x0000063c,0x00000000,0x00050051,0x00000006, + 0x0000063e,0x0000063c,0x00000001,0x00050051,0x00000006,0x0000063f,0x0000063c,0x00000002, + 0x00070050,0x0000000e,0x00000640,0x0000063d,0x0000063e,0x0000063f,0x000000b2,0x0003003e, + 0x00000637,0x00000640,0x000100fd,0x00010038,0x00050036,0x00000006,0x0000000b,0x00000000, + 0x00000009,0x00030037,0x00000008,0x0000000a,0x000200f8,0x0000000c,0x00050041,0x0000000d, + 0x0000004d,0x0000000a,0x0000004c,0x0004003d,0x00000006,0x0000004e,0x0000004d,0x00050085, + 0x00000006,0x0000004f,0x0000004b,0x0000004e,0x00050041,0x0000000d,0x00000052,0x0000000a, + 0x00000051,0x0004003d,0x00000006,0x00000053,0x00000052,0x00050085,0x00000006,0x00000054, + 0x00000050,0x00000053,0x00050081,0x00000006,0x00000055,0x0000004f,0x00000054,0x00050041, + 0x0000000d,0x00000058,0x0000000a,0x00000057,0x0004003d,0x00000006,0x00000059,0x00000058, + 0x00050085,0x00000006,0x0000005a,0x00000056,0x00000059,0x00050081,0x00000006,0x0000005b, + 0x00000055,0x0000005a,0x000200fe,0x0000005b,0x00010038,0x00050036,0x0000000e,0x00000019, + 0x00000000,0x0000000f,0x00030037,0x0000000d,0x00000010,0x00030037,0x0000000d,0x00000011, + 0x00030037,0x0000000d,0x00000012,0x00030037,0x0000000d,0x00000013,0x00030037,0x0000000d, + 0x00000014,0x00030037,0x0000000d,0x00000015,0x00030037,0x0000000d,0x00000016,0x00030037, + 0x0000000d,0x00000017,0x00030037,0x0000000d,0x00000018,0x000200f8,0x0000001a,0x0004003b, + 0x0000000d,0x0000005e,0x00000007,0x0004003b,0x0000000d,0x0000006b,0x00000007,0x0004003b, + 0x0000000d,0x00000078,0x00000007,0x0004003b,0x0000000d,0x00000085,0x00000007,0x0004003b, + 0x0000000d,0x00000092,0x00000007,0x0004003b,0x0000000d,0x00000096,0x00000007,0x0004003b, + 0x0000000d,0x0000009a,0x00000007,0x0004003b,0x0000000d,0x0000009e,0x00000007,0x0004003b, + 0x0000000d,0x000000ac,0x00000007,0x0004003b,0x0000000d,0x000000b4,0x00000007,0x0004003b, + 0x000000b7,0x000000b8,0x00000007,0x0004003b,0x000000b7,0x000000c6,0x00000007,0x0004003b, + 0x000000b7,0x000000d2,0x00000007,0x0004003b,0x000000b7,0x000000d6,0x00000007,0x0004003b, + 0x0000000d,0x000000da,0x00000007,0x0004003b,0x0000000d,0x000000e0,0x00000007,0x0004003b, + 0x0000000d,0x000000e6,0x00000007,0x0004003b,0x0000000d,0x000000ec,0x00000007,0x0004003b, + 0x0000000d,0x000000f3,0x00000007,0x0004003b,0x0000000d,0x000000f9,0x00000007,0x0004003d, + 0x00000006,0x0000005f,0x00000010,0x0004003d,0x00000006,0x00000060,0x00000011,0x00050081, + 0x00000006,0x00000061,0x0000005f,0x00000060,0x0004003d,0x00000006,0x00000062,0x00000012, + 0x00050081,0x00000006,0x00000063,0x00000061,0x00000062,0x0004003d,0x00000006,0x00000064, + 0x00000016,0x00050083,0x00000006,0x00000065,0x00000063,0x00000064,0x0004003d,0x00000006, + 0x00000066,0x00000017,0x00050083,0x00000006,0x00000067,0x00000065,0x00000066,0x0004003d, + 0x00000006,0x00000068,0x00000018,0x00050083,0x00000006,0x00000069,0x00000067,0x00000068, + 0x0006000c,0x00000006,0x0000006a,0x00000001,0x00000004,0x00000069,0x0003003e,0x0000005e, + 0x0000006a,0x0004003d,0x00000006,0x0000006c,0x00000013,0x0004003d,0x00000006,0x0000006d, + 0x00000010,0x00050081,0x00000006,0x0000006e,0x0000006c,0x0000006d,0x0004003d,0x00000006, + 0x0000006f,0x00000011,0x00050081,0x00000006,0x00000070,0x0000006e,0x0000006f,0x0004003d, + 0x00000006,0x00000071,0x00000017,0x00050083,0x00000006,0x00000072,0x00000070,0x00000071, + 0x0004003d,0x00000006,0x00000073,0x00000018,0x00050083,0x00000006,0x00000074,0x00000072, + 0x00000073,0x0004003d,0x00000006,0x00000075,0x00000015,0x00050083,0x00000006,0x00000076, + 0x00000074,0x00000075,0x0006000c,0x00000006,0x00000077,0x00000001,0x00000004,0x00000076, + 0x0003003e,0x0000006b,0x00000077,0x0004003d,0x00000006,0x00000079,0x00000010,0x0004003d, + 0x00000006,0x0000007a,0x00000013,0x00050081,0x00000006,0x0000007b,0x00000079,0x0000007a, + 0x0004003d,0x00000006,0x0000007c,0x00000016,0x00050081,0x00000006,0x0000007d,0x0000007b, + 0x0000007c,0x0004003d,0x00000006,0x0000007e,0x00000012,0x00050083,0x00000006,0x0000007f, + 0x0000007d,0x0000007e,0x0004003d,0x00000006,0x00000080,0x00000015,0x00050083,0x00000006, + 0x00000081,0x0000007f,0x00000080,0x0004003d,0x00000006,0x00000082,0x00000018,0x00050083, + 0x00000006,0x00000083,0x00000081,0x00000082,0x0006000c,0x00000006,0x00000084,0x00000001, + 0x00000004,0x00000083,0x0003003e,0x00000078,0x00000084,0x0004003d,0x00000006,0x00000086, + 0x00000013,0x0004003d,0x00000006,0x00000087,0x00000016,0x00050081,0x00000006,0x00000088, + 0x00000086,0x00000087,0x0004003d,0x00000006,0x00000089,0x00000017,0x00050081,0x00000006, + 0x0000008a,0x00000088,0x00000089,0x0004003d,0x00000006,0x0000008b,0x00000011,0x00050083, + 0x00000006,0x0000008c,0x0000008a,0x0000008b,0x0004003d,0x00000006,0x0000008d,0x00000012, + 0x00050083,0x00000006,0x0000008e,0x0000008c,0x0000008d,0x0004003d,0x00000006,0x0000008f, + 0x00000015,0x00050083,0x00000006,0x00000090,0x0000008e,0x0000008f,0x0006000c,0x00000006, + 0x00000091,0x00000001,0x00000004,0x00000090,0x0003003e,0x00000085,0x00000091,0x0004003d, + 0x00000006,0x00000093,0x0000005e,0x0004003d,0x00000006,0x00000094,0x00000078,0x0007000c, + 0x00000006,0x00000095,0x00000001,0x00000028,0x00000093,0x00000094,0x0003003e,0x00000092, + 0x00000095,0x0004003d,0x00000006,0x00000097,0x0000005e,0x0004003d,0x00000006,0x00000098, + 0x00000078,0x0007000c,0x00000006,0x00000099,0x00000001,0x00000025,0x00000097,0x00000098, + 0x0003003e,0x00000096,0x00000099,0x0004003d,0x00000006,0x0000009b,0x0000006b,0x0004003d, + 0x00000006,0x0000009c,0x00000085,0x0007000c,0x00000006,0x0000009d,0x00000001,0x00000028, + 0x0000009b,0x0000009c,0x0003003e,0x0000009a,0x0000009d,0x0004003d,0x00000006,0x0000009f, + 0x0000006b,0x0004003d,0x00000006,0x000000a0,0x00000085,0x0007000c,0x00000006,0x000000a1, + 0x00000001,0x00000025,0x0000009f,0x000000a0,0x0003003e,0x0000009e,0x000000a1,0x0004003d, + 0x00000006,0x000000a2,0x00000092,0x0004003d,0x00000006,0x000000a3,0x0000009a,0x00050081, + 0x00000006,0x000000a4,0x000000a2,0x000000a3,0x000500b4,0x000000a6,0x000000a7,0x000000a4, + 0x000000a5,0x000300f7,0x000000a9,0x00000000,0x000400fa,0x000000a7,0x000000a8,0x000000a9, + 0x000200f8,0x000000a8,0x000200fe,0x000000aa,0x000200f8,0x000000a9,0x0004003d,0x00000006, + 0x000000ad,0x00000092,0x0004003d,0x00000006,0x000000ae,0x00000092,0x0004003d,0x00000006, + 0x000000af,0x0000009a,0x00050081,0x00000006,0x000000b0,0x000000ae,0x000000af,0x00050088, + 0x00000006,0x000000b1,0x000000ad,0x000000b0,0x0007000c,0x00000006,0x000000b3,0x00000001, + 0x00000025,0x000000b1,0x000000b2,0x0003003e,0x000000ac,0x000000b3,0x0004003d,0x00000006, + 0x000000b5,0x000000ac,0x00050083,0x00000006,0x000000b6,0x000000b2,0x000000b5,0x0003003e, + 0x000000b4,0x000000b6,0x0004003d,0x00000006,0x000000b9,0x00000092,0x0004003d,0x00000006, + 0x000000ba,0x00000096,0x00050085,0x00000006,0x000000bc,0x000000ba,0x000000bb,0x000500ba, + 0x000000a6,0x000000bd,0x000000b9,0x000000bc,0x0004003d,0x00000006,0x000000be,0x00000092, + 0x000500ba,0x000000a6,0x000000c0,0x000000be,0x000000bf,0x000500a7,0x000000a6,0x000000c1, + 0x000000bd,0x000000c0,0x0004003d,0x00000006,0x000000c2,0x00000092,0x0004003d,0x00000006, + 0x000000c3,0x0000009e,0x000500ba,0x000000a6,0x000000c4,0x000000c2,0x000000c3,0x000500a7, + 0x000000a6,0x000000c5,0x000000c1,0x000000c4,0x0003003e,0x000000b8,0x000000c5,0x0004003d, + 0x00000006,0x000000c7,0x0000009a,0x0004003d,0x00000006,0x000000c8,0x0000009e,0x00050085, + 0x00000006,0x000000c9,0x000000c8,0x000000bb,0x000500ba,0x000000a6,0x000000ca,0x000000c7, + 0x000000c9,0x0004003d,0x00000006,0x000000cb,0x0000009a,0x000500ba,0x000000a6,0x000000cc, + 0x000000cb,0x000000bf,0x000500a7,0x000000a6,0x000000cd,0x000000ca,0x000000cc,0x0004003d, + 0x00000006,0x000000ce,0x0000009a,0x0004003d,0x00000006,0x000000cf,0x00000096,0x000500ba, + 0x000000a6,0x000000d0,0x000000ce,0x000000cf,0x000500a7,0x000000a6,0x000000d1,0x000000cd, + 0x000000d0,0x0003003e,0x000000c6,0x000000d1,0x0004003d,0x00000006,0x000000d3,0x00000092, + 0x0004003d,0x00000006,0x000000d4,0x0000005e,0x000500b4,0x000000a6,0x000000d5,0x000000d3, + 0x000000d4,0x0003003e,0x000000d2,0x000000d5,0x0004003d,0x00000006,0x000000d7,0x0000009a, + 0x0004003d,0x00000006,0x000000d8,0x0000006b,0x000500b4,0x000000a6,0x000000d9,0x000000d7, + 0x000000d8,0x0003003e,0x000000d6,0x000000d9,0x0004003d,0x000000a6,0x000000db,0x000000b8, + 0x0004003d,0x000000a6,0x000000dc,0x000000c6,0x000500a7,0x000000a6,0x000000dd,0x000000db, + 0x000000dc,0x0004003d,0x00000006,0x000000de,0x000000ac,0x000600a9,0x00000006,0x000000df, + 0x000000dd,0x000000de,0x000000b2,0x0003003e,0x000000da,0x000000df,0x0004003d,0x000000a6, + 0x000000e1,0x000000b8,0x0004003d,0x000000a6,0x000000e2,0x000000c6,0x000500a7,0x000000a6, + 0x000000e3,0x000000e1,0x000000e2,0x0004003d,0x00000006,0x000000e4,0x000000b4,0x000600a9, + 0x00000006,0x000000e5,0x000000e3,0x000000e4,0x000000b2,0x0003003e,0x000000e0,0x000000e5, + 0x0004003d,0x000000a6,0x000000e7,0x000000b8,0x0004003d,0x000000a6,0x000000e8,0x000000d2, + 0x000500a7,0x000000a6,0x000000e9,0x000000e7,0x000000e8,0x0004003d,0x00000006,0x000000ea, + 0x000000da,0x000600a9,0x00000006,0x000000eb,0x000000e9,0x000000ea,0x000000a5,0x0003003e, + 0x000000e6,0x000000eb,0x0004003d,0x000000a6,0x000000ed,0x000000b8,0x0004003d,0x000000a6, + 0x000000ee,0x000000d2,0x000400a8,0x000000a6,0x000000ef,0x000000ee,0x000500a7,0x000000a6, + 0x000000f0,0x000000ed,0x000000ef,0x0004003d,0x00000006,0x000000f1,0x000000da,0x000600a9, + 0x00000006,0x000000f2,0x000000f0,0x000000f1,0x000000a5,0x0003003e,0x000000ec,0x000000f2, + 0x0004003d,0x000000a6,0x000000f4,0x000000c6,0x0004003d,0x000000a6,0x000000f5,0x000000d6, + 0x000500a7,0x000000a6,0x000000f6,0x000000f4,0x000000f5,0x0004003d,0x00000006,0x000000f7, + 0x000000e0,0x000600a9,0x00000006,0x000000f8,0x000000f6,0x000000f7,0x000000a5,0x0003003e, + 0x000000f3,0x000000f8,0x0004003d,0x000000a6,0x000000fa,0x000000c6,0x0004003d,0x000000a6, + 0x000000fb,0x000000d6,0x000400a8,0x000000a6,0x000000fc,0x000000fb,0x000500a7,0x000000a6, + 0x000000fd,0x000000fa,0x000000fc,0x0004003d,0x00000006,0x000000fe,0x000000e0,0x000600a9, + 0x00000006,0x000000ff,0x000000fd,0x000000fe,0x000000a5,0x0003003e,0x000000f9,0x000000ff, + 0x0004003d,0x00000006,0x00000100,0x000000e6,0x0004003d,0x00000006,0x00000101,0x000000ec, + 0x0004003d,0x00000006,0x00000102,0x000000f3,0x0004003d,0x00000006,0x00000103,0x000000f9, + 0x00070050,0x0000000e,0x00000104,0x00000100,0x00000101,0x00000102,0x00000103,0x000200fe, + 0x00000104,0x00010038,0x00050036,0x0000000e,0x00000023,0x00000000,0x0000001c,0x00030037, + 0x0000001b,0x0000001d,0x00030037,0x0000001b,0x0000001e,0x00030037,0x0000001b,0x0000001f, + 0x00030037,0x0000001b,0x00000020,0x00030037,0x0000000d,0x00000021,0x00030037,0x0000000d, + 0x00000022,0x000200f8,0x00000024,0x0004003b,0x0000001b,0x00000107,0x00000007,0x0004003b, + 0x0000001b,0x0000010d,0x00000007,0x0004003d,0x0000000e,0x00000108,0x0000001d,0x0004003d, + 0x0000000e,0x00000109,0x0000001e,0x0004003d,0x00000006,0x0000010a,0x00000021,0x00070050, + 0x0000000e,0x0000010b,0x0000010a,0x0000010a,0x0000010a,0x0000010a,0x0008000c,0x0000000e, + 0x0000010c,0x00000001,0x0000002e,0x00000108,0x00000109,0x0000010b,0x0003003e,0x00000107, + 0x0000010c,0x0004003d,0x0000000e,0x0000010e,0x0000001f,0x0004003d,0x0000000e,0x0000010f, + 0x00000020,0x0004003d,0x00000006,0x00000110,0x00000021,0x00070050,0x0000000e,0x00000111, + 0x00000110,0x00000110,0x00000110,0x00000110,0x0008000c,0x0000000e,0x00000112,0x00000001, + 0x0000002e,0x0000010e,0x0000010f,0x00000111,0x0003003e,0x0000010d,0x00000112,0x0004003d, + 0x0000000e,0x00000113,0x00000107,0x0004003d,0x0000000e,0x00000114,0x0000010d,0x0004003d, + 0x00000006,0x00000115,0x00000022,0x00070050,0x0000000e,0x00000116,0x00000115,0x00000115, + 0x00000115,0x00000115,0x0008000c,0x0000000e,0x00000117,0x00000001,0x0000002e,0x00000113, + 0x00000114,0x00000116,0x000200fe,0x00000117,0x00010038,0x00050036,0x00000006,0x0000002f, + 0x00000000,0x00000027,0x00030037,0x0000000d,0x00000028,0x00030037,0x0000000d,0x00000029, + 0x00030037,0x0000000d,0x0000002a,0x00030037,0x0000000d,0x0000002b,0x00030037,0x0000000d, + 0x0000002c,0x00030037,0x0000000d,0x0000002d,0x00030037,0x00000026,0x0000002e,0x000200f8, + 0x00000030,0x0004003b,0x000000b7,0x0000011a,0x00000007,0x0004003b,0x0000000d,0x0000011e, + 0x00000007,0x0004003b,0x0000000d,0x00000123,0x00000007,0x0004003b,0x0000000d,0x00000129, + 0x00000007,0x0004003b,0x0000000d,0x00000133,0x00000007,0x0004003b,0x0000000d,0x00000139, + 0x00000007,0x0004003b,0x0000000d,0x0000013f,0x00000007,0x0004003b,0x0000000d,0x00000143, + 0x00000007,0x0004003b,0x0000000d,0x00000147,0x00000007,0x0004003d,0x00000025,0x0000011b, + 0x0000002e,0x000500b3,0x000000a6,0x0000011d,0x0000011b,0x0000011c,0x0003003e,0x0000011a, + 0x0000011d,0x0004003d,0x000000a6,0x0000011f,0x0000011a,0x0004003d,0x00000006,0x00000120, + 0x00000028,0x0004003d,0x00000006,0x00000121,0x0000002b,0x000600a9,0x00000006,0x00000122, + 0x0000011f,0x00000120,0x00000121,0x0003003e,0x0000011e,0x00000122,0x0004003d,0x00000006, + 0x00000124,0x00000029,0x0004003d,0x00000006,0x00000125,0x0000002a,0x0007000c,0x00000006, + 0x00000126,0x00000001,0x00000025,0x00000124,0x00000125,0x0004003d,0x00000006,0x00000127, + 0x0000011e,0x0007000c,0x00000006,0x00000128,0x00000001,0x00000025,0x00000126,0x00000127, + 0x0003003e,0x00000123,0x00000128,0x0004003d,0x00000006,0x0000012a,0x00000029,0x0004003d, + 0x00000006,0x0000012b,0x0000002a,0x0007000c,0x00000006,0x0000012c,0x00000001,0x00000028, + 0x0000012a,0x0000012b,0x0004003d,0x00000006,0x0000012d,0x0000011e,0x0007000c,0x00000006, + 0x0000012e,0x00000001,0x00000028,0x0000012c,0x0000012d,0x0003003e,0x00000129,0x0000012e, + 0x0004003d,0x000000a6,0x0000012f,0x0000011a,0x0004003d,0x00000006,0x00000130,0x0000002a, + 0x0004003d,0x00000006,0x00000131,0x0000002d,0x000600a9,0x00000006,0x00000132,0x0000012f, + 0x00000130,0x00000131,0x0003003e,0x0000011e,0x00000132,0x0004003d,0x00000006,0x00000134, + 0x0000002b,0x0004003d,0x00000006,0x00000135,0x0000002c,0x0007000c,0x00000006,0x00000136, + 0x00000001,0x00000025,0x00000134,0x00000135,0x0004003d,0x00000006,0x00000137,0x0000011e, + 0x0007000c,0x00000006,0x00000138,0x00000001,0x00000025,0x00000136,0x00000137,0x0003003e, + 0x00000133,0x00000138,0x0004003d,0x00000006,0x0000013a,0x0000002b,0x0004003d,0x00000006, + 0x0000013b,0x0000002c,0x0007000c,0x00000006,0x0000013c,0x00000001,0x00000028,0x0000013a, + 0x0000013b,0x0004003d,0x00000006,0x0000013d,0x0000011e,0x0007000c,0x00000006,0x0000013e, + 0x00000001,0x00000028,0x0000013c,0x0000013d,0x0003003e,0x00000139,0x0000013e,0x0004003d, + 0x00000006,0x00000140,0x00000129,0x0004003d,0x00000006,0x00000141,0x00000123,0x00050083, + 0x00000006,0x00000142,0x00000140,0x00000141,0x0003003e,0x0000013f,0x00000142,0x0004003d, + 0x00000006,0x00000144,0x00000139,0x0004003d,0x00000006,0x00000145,0x00000133,0x00050083, + 0x00000006,0x00000146,0x00000144,0x00000145,0x0003003e,0x00000143,0x00000146,0x0004003d, + 0x00000006,0x00000148,0x0000013f,0x0004003d,0x00000006,0x00000149,0x00000143,0x0007000c, + 0x00000006,0x0000014a,0x00000001,0x00000028,0x00000148,0x00000149,0x0004003d,0x00000006, + 0x0000014b,0x0000013f,0x0004003d,0x00000006,0x0000014c,0x00000143,0x0007000c,0x00000006, + 0x0000014d,0x00000001,0x00000025,0x0000014b,0x0000014c,0x00050081,0x00000006,0x0000014f, + 0x0000014d,0x0000014e,0x00050088,0x00000006,0x00000150,0x0000014a,0x0000014f,0x0003003e, + 0x00000147,0x00000150,0x0004003d,0x00000006,0x00000151,0x00000147,0x00050083,0x00000006, + 0x00000153,0x00000151,0x00000152,0x00050085,0x00000006,0x00000155,0x00000153,0x00000154, + 0x0008000c,0x00000006,0x00000156,0x00000001,0x0000002b,0x00000155,0x000000a5,0x000000b2, + 0x00050083,0x00000006,0x00000157,0x000000b2,0x00000156,0x00050085,0x00000006,0x00000158, + 0x00000157,0x000000b2,0x000200fe,0x00000158,0x00010038,0x00050036,0x00000006,0x00000038, + 0x00000000,0x00000035,0x00030037,0x00000034,0x00000036,0x00030037,0x00000026,0x00000037, + 0x000200f8,0x00000039,0x0004003b,0x0000000d,0x0000015f,0x00000007,0x0004003b,0x00000026, + 0x00000160,0x00000007,0x0004003b,0x00000214,0x00000215,0x00000007,0x0004003b,0x0000000d, + 0x00000221,0x00000007,0x0004003b,0x00000026,0x00000222,0x00000007,0x0004003b,0x00000214, + 0x000002b0,0x00000007,0x0004003b,0x0000000d,0x000002bb,0x00000007,0x0004003b,0x0000000d, + 0x000002c3,0x00000007,0x0004003b,0x0000000d,0x000002cf,0x00000007,0x0004003b,0x0000000d, + 0x000002e3,0x00000007,0x0004003b,0x0000000d,0x000002e6,0x00000007,0x0004003b,0x0000000d, + 0x000002e9,0x00000007,0x0004003b,0x0000000d,0x000002ec,0x00000007,0x0004003b,0x0000000d, + 0x000002ef,0x00000007,0x0004003b,0x0000000d,0x000002f2,0x00000007,0x0004003b,0x00000026, + 0x000002f5,0x00000007,0x0004003d,0x00000025,0x0000015b,0x00000037,0x0008000c,0x00000025, + 0x0000015e,0x00000001,0x0000002d,0x0000015b,0x0000015c,0x0000015d,0x0003003e,0x00000037, + 0x0000015e,0x0003003e,0x0000015f,0x000000a5,0x0003003e,0x00000160,0x0000015c,0x000200f9, + 0x00000161,0x000200f8,0x00000161,0x000400f6,0x00000163,0x00000164,0x00000000,0x000200f9, + 0x00000165,0x000200f8,0x00000165,0x0004003d,0x00000025,0x00000166,0x00000160,0x000500b1, + 0x000000a6,0x00000168,0x00000166,0x00000167,0x000400fa,0x00000168,0x00000162,0x00000163, + 0x000200f8,0x00000162,0x0004003d,0x00000025,0x00000210,0x00000037,0x00050084,0x00000025, + 0x00000211,0x00000210,0x00000167,0x0004003d,0x00000025,0x00000212,0x00000160,0x00050080, + 0x00000025,0x00000213,0x00000211,0x00000212,0x0003003e,0x00000215,0x0000020f,0x00050041, + 0x0000000d,0x00000216,0x00000215,0x00000213,0x0004003d,0x00000006,0x00000217,0x00000216, + 0x0004003d,0x00000025,0x00000218,0x00000160,0x00050041,0x0000000d,0x00000219,0x00000036, + 0x00000218,0x0004003d,0x00000006,0x0000021a,0x00000219,0x00050085,0x00000006,0x0000021b, + 0x00000217,0x0000021a,0x0004003d,0x00000006,0x0000021c,0x0000015f,0x00050081,0x00000006, + 0x0000021d,0x0000021c,0x0000021b,0x0003003e,0x0000015f,0x0000021d,0x000200f9,0x00000164, + 0x000200f8,0x00000164,0x0004003d,0x00000025,0x0000021e,0x00000160,0x00050080,0x00000025, + 0x00000220,0x0000021e,0x0000021f,0x0003003e,0x00000160,0x00000220,0x000200f9,0x00000161, + 0x000200f8,0x00000163,0x0003003e,0x00000221,0x000000a5,0x0003003e,0x00000222,0x0000015c, + 0x000200f9,0x00000223,0x000200f8,0x00000223,0x000400f6,0x00000225,0x00000226,0x00000000, + 0x000200f9,0x00000227,0x000200f8,0x00000227,0x0004003d,0x00000025,0x00000228,0x00000222, + 0x000500b1,0x000000a6,0x00000229,0x00000228,0x00000167,0x000400fa,0x00000229,0x00000224, + 0x00000225,0x000200f8,0x00000224,0x0004003d,0x00000025,0x000002ac,0x00000037,0x00050084, + 0x00000025,0x000002ad,0x000002ac,0x00000167,0x0004003d,0x00000025,0x000002ae,0x00000222, + 0x00050080,0x00000025,0x000002af,0x000002ad,0x000002ae,0x0003003e,0x000002b0,0x000002ab, + 0x00050041,0x0000000d,0x000002b1,0x000002b0,0x000002af,0x0004003d,0x00000006,0x000002b2, + 0x000002b1,0x0004003d,0x00000025,0x000002b3,0x00000222,0x00050041,0x0000000d,0x000002b4, + 0x00000036,0x000002b3,0x0004003d,0x00000006,0x000002b5,0x000002b4,0x00050085,0x00000006, + 0x000002b6,0x000002b2,0x000002b5,0x0004003d,0x00000006,0x000002b7,0x00000221,0x00050081, + 0x00000006,0x000002b8,0x000002b7,0x000002b6,0x0003003e,0x00000221,0x000002b8,0x000200f9, + 0x00000226,0x000200f8,0x00000226,0x0004003d,0x00000025,0x000002b9,0x00000222,0x00050080, + 0x00000025,0x000002ba,0x000002b9,0x0000021f,0x0003003e,0x00000222,0x000002ba,0x000200f9, + 0x00000223,0x000200f8,0x00000225,0x0004003d,0x00000006,0x000002bc,0x0000015f,0x00050083, + 0x00000006,0x000002be,0x000002bc,0x000002bd,0x00050085,0x00000006,0x000002c0,0x000002be, + 0x000002bf,0x0008000c,0x00000006,0x000002c1,0x00000001,0x0000002b,0x000002c0,0x000000a5, + 0x000000b2,0x00050083,0x00000006,0x000002c2,0x000000b2,0x000002c1,0x0003003e,0x000002bb, + 0x000002c2,0x0004003d,0x00000006,0x000002c4,0x000002bb,0x0004003d,0x00000006,0x000002c7, + 0x000002c6,0x00050085,0x00000006,0x000002c8,0x000002c4,0x000002c7,0x0004003d,0x00000006, + 0x000002ca,0x000002c9,0x00050081,0x00000006,0x000002cb,0x000002c8,0x000002ca,0x0003003e, + 0x000002c3,0x000002cb,0x0004003d,0x00000006,0x000002cc,0x000002c3,0x0004003d,0x00000006, + 0x000002cd,0x00000221,0x00050085,0x00000006,0x000002ce,0x000002cd,0x000002cc,0x0003003e, + 0x00000221,0x000002ce,0x0004003d,0x00000006,0x000002d0,0x000002bb,0x0004003d,0x00000006, + 0x000002d2,0x000002d1,0x00050085,0x00000006,0x000002d3,0x000002d0,0x000002d2,0x0004003d, + 0x00000006,0x000002d5,0x000002d4,0x00050081,0x00000006,0x000002d6,0x000002d3,0x000002d5, + 0x0004003d,0x00000006,0x000002d7,0x0000015f,0x00050085,0x00000006,0x000002d8,0x000002d6, + 0x000002d7,0x0003003e,0x000002cf,0x000002d8,0x0004003d,0x00000006,0x000002d9,0x000002cf, + 0x0004003d,0x00000006,0x000002da,0x000002cf,0x0004007f,0x00000006,0x000002db,0x000002da, + 0x0004003d,0x00000006,0x000002dc,0x00000221,0x0007000c,0x00000006,0x000002dd,0x00000001, + 0x00000028,0x000002db,0x000002dc,0x0007000c,0x00000006,0x000002de,0x00000001,0x00000025, + 0x000002d9,0x000002dd,0x0003003e,0x00000221,0x000002de,0x00050041,0x0000000d,0x000002e4, + 0x00000036,0x0000015c,0x0004003d,0x00000006,0x000002e5,0x000002e4,0x0003003e,0x000002e3, + 0x000002e5,0x00050041,0x0000000d,0x000002e7,0x00000036,0x0000021f,0x0004003d,0x00000006, + 0x000002e8,0x000002e7,0x0003003e,0x000002e6,0x000002e8,0x00050041,0x0000000d,0x000002ea, + 0x00000036,0x000002df,0x0004003d,0x00000006,0x000002eb,0x000002ea,0x0003003e,0x000002e9, + 0x000002eb,0x00050041,0x0000000d,0x000002ed,0x00000036,0x000002e0,0x0004003d,0x00000006, + 0x000002ee,0x000002ed,0x0003003e,0x000002ec,0x000002ee,0x00050041,0x0000000d,0x000002f0, + 0x00000036,0x000002e1,0x0004003d,0x00000006,0x000002f1,0x000002f0,0x0003003e,0x000002ef, + 0x000002f1,0x00050041,0x0000000d,0x000002f3,0x00000036,0x000002e2,0x0004003d,0x00000006, + 0x000002f4,0x000002f3,0x0003003e,0x000002f2,0x000002f4,0x0004003d,0x00000025,0x000002f6, + 0x00000037,0x0003003e,0x000002f5,0x000002f6,0x000b0039,0x00000006,0x000002f7,0x0000002f, + 0x000002e3,0x000002e6,0x000002e9,0x000002ec,0x000002ef,0x000002f2,0x000002f5,0x0004003d, + 0x00000006,0x000002f8,0x00000221,0x00050085,0x00000006,0x000002f9,0x000002f8,0x000002f7, + 0x0003003e,0x00000221,0x000002f9,0x0004003d,0x00000006,0x000002fa,0x0000015f,0x0004003d, + 0x00000006,0x000002fb,0x00000221,0x00050081,0x00000006,0x000002fc,0x000002fa,0x000002fb, + 0x000200fe,0x000002fc,0x00010038,0x00050036,0x00000006,0x00000040,0x00000000,0x0000003c, + 0x00030037,0x0000003b,0x0000003d,0x00030037,0x00000026,0x0000003e,0x00030037,0x00000026, + 0x0000003f,0x000200f8,0x00000041,0x0004003b,0x0000000d,0x00000303,0x00000007,0x0004003b, + 0x00000026,0x00000304,0x00000007,0x0004003b,0x0000000d,0x0000030c,0x00000007,0x0004003b, + 0x00000026,0x0000030d,0x00000007,0x0004003b,0x00000214,0x0000031d,0x00000007,0x0004003b, + 0x00000214,0x0000032a,0x00000007,0x0004003d,0x00000025,0x000002ff,0x0000003e,0x0008000c, + 0x00000025,0x00000300,0x00000001,0x0000002d,0x000002ff,0x0000015c,0x0000015d,0x0003003e, + 0x0000003e,0x00000300,0x0004003d,0x00000025,0x00000301,0x0000003f,0x0008000c,0x00000025, + 0x00000302,0x00000001,0x0000002d,0x00000301,0x0000015c,0x0000015d,0x0003003e,0x0000003f, + 0x00000302,0x0003003e,0x00000303,0x000000a5,0x0003003e,0x00000304,0x0000015c,0x000200f9, + 0x00000305,0x000200f8,0x00000305,0x000400f6,0x00000307,0x00000308,0x00000000,0x000200f9, + 0x00000309,0x000200f8,0x00000309,0x0004003d,0x00000025,0x0000030a,0x00000304,0x000500b1, + 0x000000a6,0x0000030b,0x0000030a,0x00000167,0x000400fa,0x0000030b,0x00000306,0x00000307, + 0x000200f8,0x00000306,0x0003003e,0x0000030c,0x000000a5,0x0003003e,0x0000030d,0x0000015c, + 0x000200f9,0x0000030e,0x000200f8,0x0000030e,0x000400f6,0x00000310,0x00000311,0x00000000, + 0x000200f9,0x00000312,0x000200f8,0x00000312,0x0004003d,0x00000025,0x00000313,0x0000030d, + 0x000500b1,0x000000a6,0x00000314,0x00000313,0x00000167,0x000400fa,0x00000314,0x0000030f, + 0x00000310,0x000200f8,0x0000030f,0x0004003d,0x00000025,0x00000315,0x0000030d,0x0004003d, + 0x00000025,0x00000316,0x00000304,0x00060041,0x0000000d,0x00000317,0x0000003d,0x00000315, + 0x00000316,0x0004003d,0x00000006,0x00000318,0x00000317,0x0004003d,0x00000025,0x00000319, + 0x0000003f,0x00050084,0x00000025,0x0000031a,0x00000319,0x00000167,0x0004003d,0x00000025, + 0x0000031b,0x0000030d,0x00050080,0x00000025,0x0000031c,0x0000031a,0x0000031b,0x0003003e, + 0x0000031d,0x0000020f,0x00050041,0x0000000d,0x0000031e,0x0000031d,0x0000031c,0x0004003d, + 0x00000006,0x0000031f,0x0000031e,0x00050085,0x00000006,0x00000320,0x00000318,0x0000031f, + 0x0004003d,0x00000006,0x00000321,0x0000030c,0x00050081,0x00000006,0x00000322,0x00000321, + 0x00000320,0x0003003e,0x0000030c,0x00000322,0x000200f9,0x00000311,0x000200f8,0x00000311, + 0x0004003d,0x00000025,0x00000323,0x0000030d,0x00050080,0x00000025,0x00000324,0x00000323, + 0x0000021f,0x0003003e,0x0000030d,0x00000324,0x000200f9,0x0000030e,0x000200f8,0x00000310, + 0x0004003d,0x00000006,0x00000325,0x0000030c,0x0004003d,0x00000025,0x00000326,0x0000003e, + 0x00050084,0x00000025,0x00000327,0x00000326,0x00000167,0x0004003d,0x00000025,0x00000328, + 0x00000304,0x00050080,0x00000025,0x00000329,0x00000327,0x00000328,0x0003003e,0x0000032a, + 0x0000020f,0x00050041,0x0000000d,0x0000032b,0x0000032a,0x00000329,0x0004003d,0x00000006, + 0x0000032c,0x0000032b,0x00050085,0x00000006,0x0000032d,0x00000325,0x0000032c,0x0004003d, + 0x00000006,0x0000032e,0x00000303,0x00050081,0x00000006,0x0000032f,0x0000032e,0x0000032d, + 0x0003003e,0x00000303,0x0000032f,0x000200f9,0x00000308,0x000200f8,0x00000308,0x0004003d, + 0x00000025,0x00000330,0x00000304,0x00050080,0x00000025,0x00000331,0x00000330,0x0000021f, + 0x0003003e,0x00000304,0x00000331,0x000200f9,0x00000305,0x000200f8,0x00000307,0x0004003d, + 0x00000006,0x00000332,0x00000303,0x000200fe,0x00000332,0x00010038,0x00050036,0x00000006, + 0x00000049,0x00000000,0x00000042,0x00030037,0x0000003b,0x00000043,0x00030037,0x0000000d, + 0x00000044,0x00030037,0x0000000d,0x00000045,0x00030037,0x00000026,0x00000046,0x00030037, + 0x00000026,0x00000047,0x00030037,0x0000001b,0x00000048,0x000200f8,0x0000004a,0x0004003b, + 0x0000000d,0x00000335,0x00000007,0x0004003b,0x00000026,0x0000033b,0x00000007,0x0004003b, + 0x00000034,0x00000343,0x00000007,0x0004003b,0x00000034,0x00000350,0x00000007,0x0004003b, + 0x00000026,0x00000352,0x00000007,0x0004003b,0x00000026,0x0000035f,0x00000007,0x0004003b, + 0x00000034,0x00000367,0x00000007,0x0004003b,0x00000034,0x00000374,0x00000007,0x0004003b, + 0x00000026,0x00000376,0x00000007,0x0004003b,0x0000000d,0x00000383,0x00000007,0x0004003b, + 0x0000038c,0x0000038d,0x00000007,0x0004003b,0x0000000d,0x000003a5,0x00000007,0x0004003b, + 0x0000000d,0x000003a8,0x00000007,0x0004003b,0x0000000d,0x000003b1,0x00000007,0x0004003b, + 0x0000000d,0x000003b4,0x00000007,0x0004003b,0x0000000d,0x000003bd,0x00000007,0x0004003b, + 0x0000000d,0x000003c0,0x00000007,0x0004003b,0x0000000d,0x000003c9,0x00000007,0x0004003b, + 0x0000000d,0x000003cc,0x00000007,0x0004003b,0x0000000d,0x000003f1,0x00000007,0x0004003b, + 0x00000026,0x000003f9,0x00000007,0x0004003b,0x00000034,0x00000401,0x00000007,0x0004003b, + 0x00000026,0x0000040d,0x00000007,0x0004003b,0x00000034,0x00000420,0x00000007,0x0004003b, + 0x00000026,0x00000422,0x00000007,0x0004003b,0x0000000d,0x0000042f,0x00000007,0x0004003b, + 0x0000038c,0x00000434,0x00000007,0x0004003b,0x0000000d,0x0000044c,0x00000007,0x0004003b, + 0x0000000d,0x0000044f,0x00000007,0x0004003b,0x0000000d,0x00000458,0x00000007,0x0004003b, + 0x0000000d,0x0000045b,0x00000007,0x0004003b,0x0000000d,0x00000464,0x00000007,0x0004003b, + 0x0000000d,0x00000467,0x00000007,0x0004003b,0x0000000d,0x00000470,0x00000007,0x0004003b, + 0x0000000d,0x00000473,0x00000007,0x0004003b,0x0000000d,0x00000498,0x00000007,0x0004003b, + 0x00000026,0x000004a1,0x00000007,0x0004003b,0x00000034,0x000004a9,0x00000007,0x0004003b, + 0x00000026,0x000004b5,0x00000007,0x0004003b,0x00000034,0x000004c7,0x00000007,0x0004003b, + 0x00000026,0x000004c9,0x00000007,0x0003003e,0x00000335,0x000000a5,0x00050041,0x0000000d, + 0x00000336,0x00000048,0x0000004c,0x0004003d,0x00000006,0x00000337,0x00000336,0x000500ba, + 0x000000a6,0x00000338,0x00000337,0x000000a5,0x000300f7,0x0000033a,0x00000000,0x000400fa, + 0x00000338,0x00000339,0x0000033a,0x000200f8,0x00000339,0x0003003e,0x0000033b,0x0000015c, + 0x000200f9,0x0000033c,0x000200f8,0x0000033c,0x000400f6,0x0000033e,0x0000033f,0x00000000, + 0x000200f9,0x00000340,0x000200f8,0x00000340,0x0004003d,0x00000025,0x00000341,0x0000033b, + 0x000500b1,0x000000a6,0x00000342,0x00000341,0x00000167,0x000400fa,0x00000342,0x0000033d, + 0x0000033e,0x000200f8,0x0000033d,0x0004003d,0x00000025,0x00000344,0x0000033b,0x0004003d, + 0x00000025,0x00000345,0x0000033b,0x00060041,0x0000000d,0x00000346,0x00000043,0x00000345, + 0x000002df,0x0004003d,0x00000006,0x00000347,0x00000346,0x0004003d,0x00000025,0x00000348, + 0x0000033b,0x00060041,0x0000000d,0x00000349,0x00000043,0x00000348,0x000002e0,0x0004003d, + 0x00000006,0x0000034a,0x00000349,0x0004003d,0x00000006,0x0000034b,0x00000044,0x0008000c, + 0x00000006,0x0000034c,0x00000001,0x0000002e,0x00000347,0x0000034a,0x0000034b,0x00050041, + 0x0000000d,0x0000034d,0x00000343,0x00000344,0x0003003e,0x0000034d,0x0000034c,0x000200f9, + 0x0000033f,0x000200f8,0x0000033f,0x0004003d,0x00000025,0x0000034e,0x0000033b,0x00050080, + 0x00000025,0x0000034f,0x0000034e,0x0000021f,0x0003003e,0x0000033b,0x0000034f,0x000200f9, + 0x0000033c,0x000200f8,0x0000033e,0x0004003d,0x00000033,0x00000351,0x00000343,0x0003003e, + 0x00000350,0x00000351,0x0004003d,0x00000025,0x00000353,0x00000047,0x0003003e,0x00000352, + 0x00000353,0x00060039,0x00000006,0x00000354,0x00000038,0x00000350,0x00000352,0x00050041, + 0x0000000d,0x00000355,0x00000048,0x0000004c,0x0004003d,0x00000006,0x00000356,0x00000355, + 0x00050085,0x00000006,0x00000357,0x00000354,0x00000356,0x0004003d,0x00000006,0x00000358, + 0x00000335,0x00050081,0x00000006,0x00000359,0x00000358,0x00000357,0x0003003e,0x00000335, + 0x00000359,0x000200f9,0x0000033a,0x000200f8,0x0000033a,0x00050041,0x0000000d,0x0000035a, + 0x00000048,0x00000051,0x0004003d,0x00000006,0x0000035b,0x0000035a,0x000500ba,0x000000a6, + 0x0000035c,0x0000035b,0x000000a5,0x000300f7,0x0000035e,0x00000000,0x000400fa,0x0000035c, + 0x0000035d,0x0000035e,0x000200f8,0x0000035d,0x0003003e,0x0000035f,0x0000015c,0x000200f9, + 0x00000360,0x000200f8,0x00000360,0x000400f6,0x00000362,0x00000363,0x00000000,0x000200f9, + 0x00000364,0x000200f8,0x00000364,0x0004003d,0x00000025,0x00000365,0x0000035f,0x000500b1, + 0x000000a6,0x00000366,0x00000365,0x00000167,0x000400fa,0x00000366,0x00000361,0x00000362, + 0x000200f8,0x00000361,0x0004003d,0x00000025,0x00000368,0x0000035f,0x0004003d,0x00000025, + 0x00000369,0x0000035f,0x00060041,0x0000000d,0x0000036a,0x00000043,0x000002df,0x00000369, + 0x0004003d,0x00000006,0x0000036b,0x0000036a,0x0004003d,0x00000025,0x0000036c,0x0000035f, + 0x00060041,0x0000000d,0x0000036d,0x00000043,0x000002e0,0x0000036c,0x0004003d,0x00000006, + 0x0000036e,0x0000036d,0x0004003d,0x00000006,0x0000036f,0x00000045,0x0008000c,0x00000006, + 0x00000370,0x00000001,0x0000002e,0x0000036b,0x0000036e,0x0000036f,0x00050041,0x0000000d, + 0x00000371,0x00000367,0x00000368,0x0003003e,0x00000371,0x00000370,0x000200f9,0x00000363, + 0x000200f8,0x00000363,0x0004003d,0x00000025,0x00000372,0x0000035f,0x00050080,0x00000025, + 0x00000373,0x00000372,0x0000021f,0x0003003e,0x0000035f,0x00000373,0x000200f9,0x00000360, + 0x000200f8,0x00000362,0x0004003d,0x00000033,0x00000375,0x00000367,0x0003003e,0x00000374, + 0x00000375,0x0004003d,0x00000025,0x00000377,0x00000046,0x0003003e,0x00000376,0x00000377, + 0x00060039,0x00000006,0x00000378,0x00000038,0x00000374,0x00000376,0x00050041,0x0000000d, + 0x00000379,0x00000048,0x00000051,0x0004003d,0x00000006,0x0000037a,0x00000379,0x00050085, + 0x00000006,0x0000037b,0x00000378,0x0000037a,0x0004003d,0x00000006,0x0000037c,0x00000335, + 0x00050081,0x00000006,0x0000037d,0x0000037c,0x0000037b,0x0003003e,0x00000335,0x0000037d, + 0x000200f9,0x0000035e,0x000200f8,0x0000035e,0x00050041,0x0000000d,0x0000037e,0x00000048, + 0x00000057,0x0004003d,0x00000006,0x0000037f,0x0000037e,0x000500ba,0x000000a6,0x00000380, + 0x0000037f,0x000000a5,0x000300f7,0x00000382,0x00000000,0x000400fa,0x00000380,0x00000381, + 0x00000382,0x000200f8,0x00000381,0x0004003d,0x00000006,0x00000385,0x00000044,0x0004003d, + 0x00000006,0x00000386,0x00000045,0x00050083,0x00000006,0x00000387,0x00000385,0x00000386, + 0x00050085,0x00000006,0x00000388,0x00000384,0x00000387,0x00050081,0x00000006,0x00000389, + 0x00000384,0x00000388,0x0003003e,0x00000383,0x00000389,0x00060041,0x0000000d,0x0000038e, + 0x00000043,0x000002df,0x0000021f,0x0004003d,0x00000006,0x0000038f,0x0000038e,0x00060041, + 0x0000000d,0x00000390,0x00000043,0x0000021f,0x000002df,0x0004003d,0x00000006,0x00000391, + 0x00000390,0x0004003d,0x00000006,0x00000392,0x00000383,0x0008000c,0x00000006,0x00000393, + 0x00000001,0x0000002e,0x0000038f,0x00000391,0x00000392,0x00050041,0x0000000d,0x00000394, + 0x0000038d,0x0000021f,0x0003003e,0x00000394,0x00000393,0x00060041,0x0000000d,0x00000395, + 0x00000043,0x000002e0,0x000002df,0x0004003d,0x00000006,0x00000396,0x00000395,0x00060041, + 0x0000000d,0x00000397,0x00000043,0x000002df,0x000002e0,0x0004003d,0x00000006,0x00000398, + 0x00000397,0x0004003d,0x00000006,0x00000399,0x00000383,0x0008000c,0x00000006,0x0000039a, + 0x00000001,0x0000002e,0x00000396,0x00000398,0x00000399,0x00050041,0x0000000d,0x0000039b, + 0x0000038d,0x000002e0,0x0003003e,0x0000039b,0x0000039a,0x00060041,0x0000000d,0x0000039c, + 0x00000043,0x000002e1,0x000002e0,0x0004003d,0x00000006,0x0000039d,0x0000039c,0x00060041, + 0x0000000d,0x0000039e,0x00000043,0x000002e0,0x000002e1,0x0004003d,0x00000006,0x0000039f, + 0x0000039e,0x0004003d,0x00000006,0x000003a0,0x00000383,0x0008000c,0x00000006,0x000003a1, + 0x00000001,0x0000002e,0x0000039d,0x0000039f,0x000003a0,0x00050041,0x0000000d,0x000003a2, + 0x0000038d,0x000002e2,0x0003003e,0x000003a2,0x000003a1,0x0004003d,0x00000006,0x000003a3, + 0x00000383,0x00050083,0x00000006,0x000003a4,0x000003a3,0x00000384,0x0003003e,0x00000383, + 0x000003a4,0x0004003d,0x00000006,0x000003a6,0x00000383,0x000500be,0x000000a6,0x000003a7, + 0x000003a6,0x000000a5,0x000300f7,0x000003aa,0x00000000,0x000400fa,0x000003a7,0x000003a9, + 0x000003ad,0x000200f8,0x000003a9,0x00060041,0x0000000d,0x000003ab,0x00000043,0x0000015c, + 0x000002df,0x0004003d,0x00000006,0x000003ac,0x000003ab,0x0003003e,0x000003a8,0x000003ac, + 0x000200f9,0x000003aa,0x000200f8,0x000003ad,0x00060041,0x0000000d,0x000003ae,0x00000043, + 0x000002df,0x0000015c,0x0004003d,0x00000006,0x000003af,0x000003ae,0x0003003e,0x000003a8, + 0x000003af,0x000200f9,0x000003aa,0x000200f8,0x000003aa,0x0004003d,0x00000006,0x000003b0, + 0x000003a8,0x0003003e,0x000003a5,0x000003b0,0x0004003d,0x00000006,0x000003b2,0x00000383, + 0x000500be,0x000000a6,0x000003b3,0x000003b2,0x000000a5,0x000300f7,0x000003b6,0x00000000, + 0x000400fa,0x000003b3,0x000003b5,0x000003b9,0x000200f8,0x000003b5,0x00060041,0x0000000d, + 0x000003b7,0x00000043,0x0000021f,0x000002e0,0x0004003d,0x00000006,0x000003b8,0x000003b7, + 0x0003003e,0x000003b4,0x000003b8,0x000200f9,0x000003b6,0x000200f8,0x000003b9,0x00060041, + 0x0000000d,0x000003ba,0x00000043,0x000002e0,0x0000021f,0x0004003d,0x00000006,0x000003bb, + 0x000003ba,0x0003003e,0x000003b4,0x000003bb,0x000200f9,0x000003b6,0x000200f8,0x000003b6, + 0x0004003d,0x00000006,0x000003bc,0x000003b4,0x0003003e,0x000003b1,0x000003bc,0x0004003d, + 0x00000006,0x000003be,0x00000383,0x000500be,0x000000a6,0x000003bf,0x000003be,0x000000a5, + 0x000300f7,0x000003c2,0x00000000,0x000400fa,0x000003bf,0x000003c1,0x000003c5,0x000200f8, + 0x000003c1,0x00060041,0x0000000d,0x000003c3,0x00000043,0x000002df,0x000002e1,0x0004003d, + 0x00000006,0x000003c4,0x000003c3,0x0003003e,0x000003c0,0x000003c4,0x000200f9,0x000003c2, + 0x000200f8,0x000003c5,0x00060041,0x0000000d,0x000003c6,0x00000043,0x000002e1,0x000002df, + 0x0004003d,0x00000006,0x000003c7,0x000003c6,0x0003003e,0x000003c0,0x000003c7,0x000200f9, + 0x000003c2,0x000200f8,0x000003c2,0x0004003d,0x00000006,0x000003c8,0x000003c0,0x0003003e, + 0x000003bd,0x000003c8,0x0004003d,0x00000006,0x000003ca,0x00000383,0x000500be,0x000000a6, + 0x000003cb,0x000003ca,0x000000a5,0x000300f7,0x000003ce,0x00000000,0x000400fa,0x000003cb, + 0x000003cd,0x000003d1,0x000200f8,0x000003cd,0x00060041,0x0000000d,0x000003cf,0x00000043, + 0x000002e0,0x000002e2,0x0004003d,0x00000006,0x000003d0,0x000003cf,0x0003003e,0x000003cc, + 0x000003d0,0x000200f9,0x000003ce,0x000200f8,0x000003d1,0x00060041,0x0000000d,0x000003d2, + 0x00000043,0x000002e2,0x000002e0,0x0004003d,0x00000006,0x000003d3,0x000003d2,0x0003003e, + 0x000003cc,0x000003d3,0x000200f9,0x000003ce,0x000200f8,0x000003ce,0x0004003d,0x00000006, + 0x000003d4,0x000003cc,0x0003003e,0x000003c9,0x000003d4,0x00060041,0x0000000d,0x000003d5, + 0x00000043,0x0000021f,0x0000021f,0x0004003d,0x00000006,0x000003d6,0x000003d5,0x0004003d, + 0x00000006,0x000003d7,0x000003a5,0x0004003d,0x00000006,0x000003d8,0x00000383,0x0006000c, + 0x00000006,0x000003d9,0x00000001,0x00000004,0x000003d8,0x0008000c,0x00000006,0x000003da, + 0x00000001,0x0000002e,0x000003d6,0x000003d7,0x000003d9,0x00050041,0x0000000d,0x000003db, + 0x0000038d,0x0000015c,0x0003003e,0x000003db,0x000003da,0x00060041,0x0000000d,0x000003dc, + 0x00000043,0x000002df,0x000002df,0x0004003d,0x00000006,0x000003dd,0x000003dc,0x0004003d, + 0x00000006,0x000003de,0x000003b1,0x0004003d,0x00000006,0x000003df,0x00000383,0x0006000c, + 0x00000006,0x000003e0,0x00000001,0x00000004,0x000003df,0x0008000c,0x00000006,0x000003e1, + 0x00000001,0x0000002e,0x000003dd,0x000003de,0x000003e0,0x00050041,0x0000000d,0x000003e2, + 0x0000038d,0x000002df,0x0003003e,0x000003e2,0x000003e1,0x00060041,0x0000000d,0x000003e3, + 0x00000043,0x000002e0,0x000002e0,0x0004003d,0x00000006,0x000003e4,0x000003e3,0x0004003d, + 0x00000006,0x000003e5,0x000003bd,0x0004003d,0x00000006,0x000003e6,0x00000383,0x0006000c, + 0x00000006,0x000003e7,0x00000001,0x00000004,0x000003e6,0x0008000c,0x00000006,0x000003e8, + 0x00000001,0x0000002e,0x000003e4,0x000003e5,0x000003e7,0x00050041,0x0000000d,0x000003e9, + 0x0000038d,0x000002e1,0x0003003e,0x000003e9,0x000003e8,0x00060041,0x0000000d,0x000003ea, + 0x00000043,0x000002e1,0x000002e1,0x0004003d,0x00000006,0x000003eb,0x000003ea,0x0004003d, + 0x00000006,0x000003ec,0x000003c9,0x0004003d,0x00000006,0x000003ed,0x00000383,0x0006000c, + 0x00000006,0x000003ee,0x00000001,0x00000004,0x000003ed,0x0008000c,0x00000006,0x000003ef, + 0x00000001,0x0000002e,0x000003eb,0x000003ec,0x000003ee,0x00050041,0x0000000d,0x000003f0, + 0x0000038d,0x00000167,0x0003003e,0x000003f0,0x000003ef,0x0004003d,0x00000006,0x000003f2, + 0x00000044,0x0004003d,0x00000006,0x000003f3,0x00000045,0x00050081,0x00000006,0x000003f4, + 0x000003f2,0x000003f3,0x0003003e,0x000003f1,0x000003f4,0x0004003d,0x00000006,0x000003f5, + 0x000003f1,0x000500be,0x000000a6,0x000003f6,0x000003f5,0x000000b2,0x000300f7,0x000003f8, + 0x00000000,0x000400fa,0x000003f6,0x000003f7,0x0000040c,0x000200f8,0x000003f7,0x0003003e, + 0x000003f9,0x0000015c,0x000200f9,0x000003fa,0x000200f8,0x000003fa,0x000400f6,0x000003fc, + 0x000003fd,0x00000000,0x000200f9,0x000003fe,0x000200f8,0x000003fe,0x0004003d,0x00000025, + 0x000003ff,0x000003f9,0x000500b1,0x000000a6,0x00000400,0x000003ff,0x00000167,0x000400fa, + 0x00000400,0x000003fb,0x000003fc,0x000200f8,0x000003fb,0x0004003d,0x00000025,0x00000402, + 0x000003f9,0x0004003d,0x00000025,0x00000403,0x000003f9,0x00050080,0x00000025,0x00000404, + 0x00000403,0x0000021f,0x00050041,0x0000000d,0x00000405,0x0000038d,0x00000404,0x0004003d, + 0x00000006,0x00000406,0x00000405,0x00050041,0x0000000d,0x00000407,0x00000401,0x00000402, + 0x0003003e,0x00000407,0x00000406,0x000200f9,0x000003fd,0x000200f8,0x000003fd,0x0004003d, + 0x00000025,0x00000408,0x000003f9,0x00050080,0x00000025,0x00000409,0x00000408,0x0000021f, + 0x0003003e,0x000003f9,0x00000409,0x000200f9,0x000003fa,0x000200f8,0x000003fc,0x0004003d, + 0x00000006,0x0000040a,0x000003f1,0x00050083,0x00000006,0x0000040b,0x0000040a,0x000000b2, + 0x0003003e,0x000003f1,0x0000040b,0x000200f9,0x000003f8,0x000200f8,0x0000040c,0x0003003e, + 0x0000040d,0x0000015c,0x000200f9,0x0000040e,0x000200f8,0x0000040e,0x000400f6,0x00000410, + 0x00000411,0x00000000,0x000200f9,0x00000412,0x000200f8,0x00000412,0x0004003d,0x00000025, + 0x00000413,0x0000040d,0x000500b1,0x000000a6,0x00000414,0x00000413,0x00000167,0x000400fa, + 0x00000414,0x0000040f,0x00000410,0x000200f8,0x0000040f,0x0004003d,0x00000025,0x00000415, + 0x0000040d,0x0004003d,0x00000025,0x00000416,0x0000040d,0x00050041,0x0000000d,0x00000417, + 0x0000038d,0x00000416,0x0004003d,0x00000006,0x00000418,0x00000417,0x00050041,0x0000000d, + 0x00000419,0x00000401,0x00000415,0x0003003e,0x00000419,0x00000418,0x000200f9,0x00000411, + 0x000200f8,0x00000411,0x0004003d,0x00000025,0x0000041a,0x0000040d,0x00050080,0x00000025, + 0x0000041b,0x0000041a,0x0000021f,0x0003003e,0x0000040d,0x0000041b,0x000200f9,0x0000040e, + 0x000200f8,0x00000410,0x000200f9,0x000003f8,0x000200f8,0x000003f8,0x0004003d,0x00000006, + 0x0000041c,0x000003f1,0x00050085,0x00000006,0x0000041e,0x0000041c,0x0000041d,0x0004006e, + 0x00000025,0x0000041f,0x0000041e,0x0004003d,0x00000033,0x00000421,0x00000401,0x0003003e, + 0x00000420,0x00000421,0x0003003e,0x00000422,0x0000041f,0x00060039,0x00000006,0x00000423, + 0x00000038,0x00000420,0x00000422,0x00050041,0x0000000d,0x00000424,0x00000048,0x00000057, + 0x0004003d,0x00000006,0x00000425,0x00000424,0x00050085,0x00000006,0x00000426,0x00000423, + 0x00000425,0x0004003d,0x00000006,0x00000427,0x00000335,0x00050081,0x00000006,0x00000428, + 0x00000427,0x00000426,0x0003003e,0x00000335,0x00000428,0x000200f9,0x00000382,0x000200f8, + 0x00000382,0x00050041,0x0000000d,0x0000042a,0x00000048,0x00000429,0x0004003d,0x00000006, + 0x0000042b,0x0000042a,0x000500ba,0x000000a6,0x0000042c,0x0000042b,0x000000a5,0x000300f7, + 0x0000042e,0x00000000,0x000400fa,0x0000042c,0x0000042d,0x0000042e,0x000200f8,0x0000042d, + 0x0004003d,0x00000006,0x00000430,0x00000044,0x0004003d,0x00000006,0x00000431,0x00000045, + 0x00050081,0x00000006,0x00000432,0x00000430,0x00000431,0x00050085,0x00000006,0x00000433, + 0x00000384,0x00000432,0x0003003e,0x0000042f,0x00000433,0x00060041,0x0000000d,0x00000435, + 0x00000043,0x000002e0,0x0000021f,0x0004003d,0x00000006,0x00000436,0x00000435,0x00060041, + 0x0000000d,0x00000437,0x00000043,0x000002e1,0x000002df,0x0004003d,0x00000006,0x00000438, + 0x00000437,0x0004003d,0x00000006,0x00000439,0x0000042f,0x0008000c,0x00000006,0x0000043a, + 0x00000001,0x0000002e,0x00000436,0x00000438,0x00000439,0x00050041,0x0000000d,0x0000043b, + 0x00000434,0x0000021f,0x0003003e,0x0000043b,0x0000043a,0x00060041,0x0000000d,0x0000043c, + 0x00000043,0x000002df,0x000002df,0x0004003d,0x00000006,0x0000043d,0x0000043c,0x00060041, + 0x0000000d,0x0000043e,0x00000043,0x000002e0,0x000002e0,0x0004003d,0x00000006,0x0000043f, + 0x0000043e,0x0004003d,0x00000006,0x00000440,0x0000042f,0x0008000c,0x00000006,0x00000441, + 0x00000001,0x0000002e,0x0000043d,0x0000043f,0x00000440,0x00050041,0x0000000d,0x00000442, + 0x00000434,0x000002e0,0x0003003e,0x00000442,0x00000441,0x00060041,0x0000000d,0x00000443, + 0x00000043,0x0000021f,0x000002e0,0x0004003d,0x00000006,0x00000444,0x00000443,0x00060041, + 0x0000000d,0x00000445,0x00000043,0x000002df,0x000002e1,0x0004003d,0x00000006,0x00000446, + 0x00000445,0x0004003d,0x00000006,0x00000447,0x0000042f,0x0008000c,0x00000006,0x00000448, + 0x00000001,0x0000002e,0x00000444,0x00000446,0x00000447,0x00050041,0x0000000d,0x00000449, + 0x00000434,0x000002e2,0x0003003e,0x00000449,0x00000448,0x0004003d,0x00000006,0x0000044a, + 0x0000042f,0x00050083,0x00000006,0x0000044b,0x0000044a,0x00000384,0x0003003e,0x0000042f, + 0x0000044b,0x0004003d,0x00000006,0x0000044d,0x0000042f,0x000500be,0x000000a6,0x0000044e, + 0x0000044d,0x000000a5,0x000300f7,0x00000451,0x00000000,0x000400fa,0x0000044e,0x00000450, + 0x00000454,0x000200f8,0x00000450,0x00060041,0x0000000d,0x00000452,0x00000043,0x000002e2, + 0x000002df,0x0004003d,0x00000006,0x00000453,0x00000452,0x0003003e,0x0000044f,0x00000453, + 0x000200f9,0x00000451,0x000200f8,0x00000454,0x00060041,0x0000000d,0x00000455,0x00000043, + 0x000002e0,0x0000015c,0x0004003d,0x00000006,0x00000456,0x00000455,0x0003003e,0x0000044f, + 0x00000456,0x000200f9,0x00000451,0x000200f8,0x00000451,0x0004003d,0x00000006,0x00000457, + 0x0000044f,0x0003003e,0x0000044c,0x00000457,0x0004003d,0x00000006,0x00000459,0x0000042f, + 0x000500be,0x000000a6,0x0000045a,0x00000459,0x000000a5,0x000300f7,0x0000045d,0x00000000, + 0x000400fa,0x0000045a,0x0000045c,0x00000460,0x000200f8,0x0000045c,0x00060041,0x0000000d, + 0x0000045e,0x00000043,0x000002e1,0x000002e0,0x0004003d,0x00000006,0x0000045f,0x0000045e, + 0x0003003e,0x0000045b,0x0000045f,0x000200f9,0x0000045d,0x000200f8,0x00000460,0x00060041, + 0x0000000d,0x00000461,0x00000043,0x000002df,0x0000021f,0x0004003d,0x00000006,0x00000462, + 0x00000461,0x0003003e,0x0000045b,0x00000462,0x000200f9,0x0000045d,0x000200f8,0x0000045d, + 0x0004003d,0x00000006,0x00000463,0x0000045b,0x0003003e,0x00000458,0x00000463,0x0004003d, + 0x00000006,0x00000465,0x0000042f,0x000500be,0x000000a6,0x00000466,0x00000465,0x000000a5, + 0x000300f7,0x00000469,0x00000000,0x000400fa,0x00000466,0x00000468,0x0000046c,0x000200f8, + 0x00000468,0x00060041,0x0000000d,0x0000046a,0x00000043,0x000002e0,0x000002e1,0x0004003d, + 0x00000006,0x0000046b,0x0000046a,0x0003003e,0x00000467,0x0000046b,0x000200f9,0x00000469, + 0x000200f8,0x0000046c,0x00060041,0x0000000d,0x0000046d,0x00000043,0x0000021f,0x000002df, + 0x0004003d,0x00000006,0x0000046e,0x0000046d,0x0003003e,0x00000467,0x0000046e,0x000200f9, + 0x00000469,0x000200f8,0x00000469,0x0004003d,0x00000006,0x0000046f,0x00000467,0x0003003e, + 0x00000464,0x0000046f,0x0004003d,0x00000006,0x00000471,0x0000042f,0x000500be,0x000000a6, + 0x00000472,0x00000471,0x000000a5,0x000300f7,0x00000475,0x00000000,0x000400fa,0x00000472, + 0x00000474,0x00000478,0x000200f8,0x00000474,0x00060041,0x0000000d,0x00000476,0x00000043, + 0x000002df,0x000002e2,0x0004003d,0x00000006,0x00000477,0x00000476,0x0003003e,0x00000473, + 0x00000477,0x000200f9,0x00000475,0x000200f8,0x00000478,0x00060041,0x0000000d,0x00000479, + 0x00000043,0x0000015c,0x000002e0,0x0004003d,0x00000006,0x0000047a,0x00000479,0x0003003e, + 0x00000473,0x0000047a,0x000200f9,0x00000475,0x000200f8,0x00000475,0x0004003d,0x00000006, + 0x0000047b,0x00000473,0x0003003e,0x00000470,0x0000047b,0x00060041,0x0000000d,0x0000047c, + 0x00000043,0x000002e1,0x0000021f,0x0004003d,0x00000006,0x0000047d,0x0000047c,0x0004003d, + 0x00000006,0x0000047e,0x0000044c,0x0004003d,0x00000006,0x0000047f,0x0000042f,0x0006000c, + 0x00000006,0x00000480,0x00000001,0x00000004,0x0000047f,0x0008000c,0x00000006,0x00000481, + 0x00000001,0x0000002e,0x0000047d,0x0000047e,0x00000480,0x00050041,0x0000000d,0x00000482, + 0x00000434,0x0000015c,0x0003003e,0x00000482,0x00000481,0x00060041,0x0000000d,0x00000483, + 0x00000043,0x000002e0,0x000002df,0x0004003d,0x00000006,0x00000484,0x00000483,0x0004003d, + 0x00000006,0x00000485,0x00000458,0x0004003d,0x00000006,0x00000486,0x0000042f,0x0006000c, + 0x00000006,0x00000487,0x00000001,0x00000004,0x00000486,0x0008000c,0x00000006,0x00000488, + 0x00000001,0x0000002e,0x00000484,0x00000485,0x00000487,0x00050041,0x0000000d,0x00000489, + 0x00000434,0x000002df,0x0003003e,0x00000489,0x00000488,0x00060041,0x0000000d,0x0000048a, + 0x00000043,0x000002df,0x000002e0,0x0004003d,0x00000006,0x0000048b,0x0000048a,0x0004003d, + 0x00000006,0x0000048c,0x00000464,0x0004003d,0x00000006,0x0000048d,0x0000042f,0x0006000c, + 0x00000006,0x0000048e,0x00000001,0x00000004,0x0000048d,0x0008000c,0x00000006,0x0000048f, + 0x00000001,0x0000002e,0x0000048b,0x0000048c,0x0000048e,0x00050041,0x0000000d,0x00000490, + 0x00000434,0x000002e1,0x0003003e,0x00000490,0x0000048f,0x00060041,0x0000000d,0x00000491, + 0x00000043,0x0000021f,0x000002e1,0x0004003d,0x00000006,0x00000492,0x00000491,0x0004003d, + 0x00000006,0x00000493,0x00000470,0x0004003d,0x00000006,0x00000494,0x0000042f,0x0006000c, + 0x00000006,0x00000495,0x00000001,0x00000004,0x00000494,0x0008000c,0x00000006,0x00000496, + 0x00000001,0x0000002e,0x00000492,0x00000493,0x00000495,0x00050041,0x0000000d,0x00000497, + 0x00000434,0x00000167,0x0003003e,0x00000497,0x00000496,0x0004003d,0x00000006,0x00000499, + 0x00000044,0x0004003d,0x00000006,0x0000049a,0x00000045,0x00050083,0x00000006,0x0000049b, + 0x00000499,0x0000049a,0x00050081,0x00000006,0x0000049c,0x000000b2,0x0000049b,0x0003003e, + 0x00000498,0x0000049c,0x0004003d,0x00000006,0x0000049d,0x00000498,0x000500be,0x000000a6, + 0x0000049e,0x0000049d,0x000000b2,0x000300f7,0x000004a0,0x00000000,0x000400fa,0x0000049e, + 0x0000049f,0x000004b4,0x000200f8,0x0000049f,0x0003003e,0x000004a1,0x0000015c,0x000200f9, + 0x000004a2,0x000200f8,0x000004a2,0x000400f6,0x000004a4,0x000004a5,0x00000000,0x000200f9, + 0x000004a6,0x000200f8,0x000004a6,0x0004003d,0x00000025,0x000004a7,0x000004a1,0x000500b1, + 0x000000a6,0x000004a8,0x000004a7,0x00000167,0x000400fa,0x000004a8,0x000004a3,0x000004a4, + 0x000200f8,0x000004a3,0x0004003d,0x00000025,0x000004aa,0x000004a1,0x0004003d,0x00000025, + 0x000004ab,0x000004a1,0x00050080,0x00000025,0x000004ac,0x000004ab,0x0000021f,0x00050041, + 0x0000000d,0x000004ad,0x00000434,0x000004ac,0x0004003d,0x00000006,0x000004ae,0x000004ad, + 0x00050041,0x0000000d,0x000004af,0x000004a9,0x000004aa,0x0003003e,0x000004af,0x000004ae, + 0x000200f9,0x000004a5,0x000200f8,0x000004a5,0x0004003d,0x00000025,0x000004b0,0x000004a1, + 0x00050080,0x00000025,0x000004b1,0x000004b0,0x0000021f,0x0003003e,0x000004a1,0x000004b1, + 0x000200f9,0x000004a2,0x000200f8,0x000004a4,0x0004003d,0x00000006,0x000004b2,0x00000498, + 0x00050083,0x00000006,0x000004b3,0x000004b2,0x000000b2,0x0003003e,0x00000498,0x000004b3, + 0x000200f9,0x000004a0,0x000200f8,0x000004b4,0x0003003e,0x000004b5,0x0000015c,0x000200f9, + 0x000004b6,0x000200f8,0x000004b6,0x000400f6,0x000004b8,0x000004b9,0x00000000,0x000200f9, + 0x000004ba,0x000200f8,0x000004ba,0x0004003d,0x00000025,0x000004bb,0x000004b5,0x000500b1, + 0x000000a6,0x000004bc,0x000004bb,0x00000167,0x000400fa,0x000004bc,0x000004b7,0x000004b8, + 0x000200f8,0x000004b7,0x0004003d,0x00000025,0x000004bd,0x000004b5,0x0004003d,0x00000025, + 0x000004be,0x000004b5,0x00050041,0x0000000d,0x000004bf,0x00000434,0x000004be,0x0004003d, + 0x00000006,0x000004c0,0x000004bf,0x00050041,0x0000000d,0x000004c1,0x000004a9,0x000004bd, + 0x0003003e,0x000004c1,0x000004c0,0x000200f9,0x000004b9,0x000200f8,0x000004b9,0x0004003d, + 0x00000025,0x000004c2,0x000004b5,0x00050080,0x00000025,0x000004c3,0x000004c2,0x0000021f, + 0x0003003e,0x000004b5,0x000004c3,0x000200f9,0x000004b6,0x000200f8,0x000004b8,0x000200f9, + 0x000004a0,0x000200f8,0x000004a0,0x0004003d,0x00000006,0x000004c4,0x00000498,0x00050085, + 0x00000006,0x000004c5,0x000004c4,0x0000041d,0x0004006e,0x00000025,0x000004c6,0x000004c5, + 0x0004003d,0x00000033,0x000004c8,0x000004a9,0x0003003e,0x000004c7,0x000004c8,0x0003003e, + 0x000004c9,0x000004c6,0x00060039,0x00000006,0x000004ca,0x00000038,0x000004c7,0x000004c9, + 0x00050041,0x0000000d,0x000004cb,0x00000048,0x00000429,0x0004003d,0x00000006,0x000004cc, + 0x000004cb,0x00050085,0x00000006,0x000004cd,0x000004ca,0x000004cc,0x0004003d,0x00000006, + 0x000004ce,0x00000335,0x00050081,0x00000006,0x000004cf,0x000004ce,0x000004cd,0x0003003e, + 0x00000335,0x000004cf,0x000200f9,0x0000042e,0x000200f8,0x0000042e,0x0004003d,0x00000006, + 0x000004d0,0x00000335,0x000200fe,0x000004d0,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/ntsc_frag.h b/app/src/main/cpp/shaders/ntsc_frag.h new file mode 100644 index 0000000000..9eb75f2184 --- /dev/null +++ b/app/src/main/cpp/shaders/ntsc_frag.h @@ -0,0 +1,154 @@ + // 1116.2.0 + #pragma once +const uint32_t ntsc_code[] = { + 0x07230203,0x00010000,0x0008000b,0x000000d5,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x000000bc,0x000000cf,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00060005,0x0000000c,0x6c707061,0x53544e79,0x66762843,0x00003b32,0x00030005, + 0x0000000b,0x00007675,0x00070005,0x0000000f,0x6c707061,0x61635379,0x6e696c6e,0x76287365, + 0x003b3266,0x00030005,0x0000000e,0x00007675,0x00060005,0x00000013,0x6c707061,0x72615779, + 0x66762870,0x00003b32,0x00030005,0x00000012,0x00007675,0x00030005,0x00000016,0x006c6f63, + 0x00060005,0x0000001a,0x75706e49,0x78655474,0x65727574,0x00000000,0x00030005,0x00000020, + 0x00716979,0x00050005,0x00000032,0x6f726863,0x6850616d,0x00657361,0x00030005,0x00000038, + 0x00004350,0x00040006,0x00000038,0x00000000,0x0063646e,0x00060006,0x00000038,0x00000001, + 0x6f736572,0x6974756c,0x00006e6f,0x00060006,0x00000038,0x00000002,0x6d617266,0x756f4365, + 0x0000746e,0x00030005,0x0000003a,0x00006370,0x00030005,0x00000058,0x00626772,0x00050005, + 0x00000066,0x616e6966,0x6c6f436c,0x0000726f,0x00030005,0x00000082,0x006c6f63,0x00050005, + 0x00000087,0x6e616373,0x656e696c,0x00000000,0x00030005,0x0000009e,0x00000072,0x00050005, + 0x000000ba,0x70726177,0x56556465,0x00000000,0x00060005,0x000000bc,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00040005,0x000000bd,0x61726170,0x0000006d,0x00050005,0x000000c0, + 0x6373746e,0x6f6c6f43,0x00000072,0x00040005,0x000000c1,0x61726170,0x0000006d,0x00060005, + 0x000000c4,0x6e616373,0x656e696c,0x6f6c6f43,0x00000072,0x00040005,0x000000c5,0x61726170, + 0x0000006d,0x00050005,0x000000c8,0x616e6966,0x6c6f436c,0x0000726f,0x00050005,0x000000cf, + 0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x0000001a,0x00000021,0x00000000,0x00040047, + 0x0000001a,0x00000022,0x00000000,0x00030047,0x00000038,0x00000002,0x00050048,0x00000038, + 0x00000000,0x00000023,0x00000000,0x00050048,0x00000038,0x00000001,0x00000023,0x00000010, + 0x00050048,0x00000038,0x00000002,0x00000023,0x00000018,0x00040047,0x000000bc,0x0000001e, + 0x00000000,0x00040047,0x000000cf,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021, + 0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006, + 0x00000002,0x00040020,0x00000008,0x00000007,0x00000007,0x00040017,0x00000009,0x00000006, + 0x00000003,0x00040021,0x0000000a,0x00000009,0x00000008,0x00040021,0x00000011,0x00000007, + 0x00000008,0x00040020,0x00000015,0x00000007,0x00000009,0x00090019,0x00000017,0x00000006, + 0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000018, + 0x00000017,0x00040020,0x00000019,0x00000000,0x00000018,0x0004003b,0x00000019,0x0000001a, + 0x00000000,0x00040017,0x0000001d,0x00000006,0x00000004,0x00040018,0x00000022,0x00000009, + 0x00000003,0x0004002b,0x00000006,0x00000023,0x3e991687,0x0004002b,0x00000006,0x00000024, + 0x3f1645a2,0x0004002b,0x00000006,0x00000025,0x3de978d5,0x0006002c,0x00000009,0x00000026, + 0x00000023,0x00000024,0x00000025,0x0004002b,0x00000006,0x00000027,0x3f189375,0x0004002b, + 0x00000006,0x00000028,0xbe8ccccd,0x0004002b,0x00000006,0x00000029,0xbea45a1d,0x0006002c, + 0x00000009,0x0000002a,0x00000027,0x00000028,0x00000029,0x0004002b,0x00000006,0x0000002b, + 0x3e591687,0x0004002b,0x00000006,0x0000002c,0xbf05e354,0x0004002b,0x00000006,0x0000002d, + 0x3e9f3b64,0x0006002c,0x00000009,0x0000002e,0x0000002b,0x0000002c,0x0000002d,0x0006002c, + 0x00000022,0x0000002f,0x00000026,0x0000002a,0x0000002e,0x00040020,0x00000031,0x00000007, + 0x00000006,0x0004002b,0x00000006,0x00000033,0x40490fdb,0x00040015,0x00000034,0x00000020, + 0x00000000,0x0004002b,0x00000034,0x00000035,0x00000001,0x0005001e,0x00000038,0x0000001d, + 0x00000007,0x00000006,0x00040020,0x00000039,0x00000009,0x00000038,0x0004003b,0x00000039, + 0x0000003a,0x00000009,0x00040015,0x0000003b,0x00000020,0x00000001,0x0004002b,0x0000003b, + 0x0000003c,0x00000001,0x00040020,0x0000003d,0x00000009,0x00000006,0x0004002b,0x00000006, + 0x00000041,0x40000000,0x0004002b,0x0000003b,0x00000043,0x00000002,0x0004002b,0x00000006, + 0x00000049,0x3f000000,0x0004002b,0x00000034,0x00000053,0x00000002,0x0004002b,0x00000006, + 0x0000005a,0x3f800000,0x0004002b,0x00000006,0x0000005b,0x3f74bc6a,0x0004002b,0x00000006, + 0x0000005c,0x3f1ef9db,0x0006002c,0x00000009,0x0000005d,0x0000005a,0x0000005b,0x0000005c, + 0x0004002b,0x00000006,0x0000005e,0xbe8b4396,0x0004002b,0x00000006,0x0000005f,0xbf25a1cb, + 0x0006002c,0x00000009,0x00000060,0x0000005a,0x0000005e,0x0000005f,0x0004002b,0x00000006, + 0x00000061,0xbf8d9168,0x0004002b,0x00000006,0x00000062,0x3fda3d71,0x0006002c,0x00000009, + 0x00000063,0x0000005a,0x00000061,0x00000062,0x0006002c,0x00000022,0x00000064,0x0000005d, + 0x00000060,0x00000063,0x0004002b,0x00000006,0x00000069,0x3ba3d70a,0x0004002b,0x00000006, + 0x0000006a,0x00000000,0x0005002c,0x00000007,0x0000006b,0x00000069,0x0000006a,0x0004002b, + 0x00000034,0x0000006e,0x00000000,0x0004002b,0x00000006,0x00000073,0x3b03126f,0x0005002c, + 0x00000007,0x00000074,0x0000006a,0x00000073,0x0004002b,0x00000006,0x00000090,0x3eb33333, + 0x0004002b,0x00000006,0x000000b0,0x3c23d70a,0x00040020,0x000000bb,0x00000001,0x00000007, + 0x0004003b,0x000000bb,0x000000bc,0x00000001,0x0004002b,0x00000006,0x000000cb,0x3f333333, + 0x00040020,0x000000ce,0x00000003,0x0000001d,0x0004003b,0x000000ce,0x000000cf,0x00000003, + 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b, + 0x00000008,0x000000ba,0x00000007,0x0004003b,0x00000008,0x000000bd,0x00000007,0x0004003b, + 0x00000015,0x000000c0,0x00000007,0x0004003b,0x00000008,0x000000c1,0x00000007,0x0004003b, + 0x00000015,0x000000c4,0x00000007,0x0004003b,0x00000008,0x000000c5,0x00000007,0x0004003b, + 0x00000015,0x000000c8,0x00000007,0x0004003d,0x00000007,0x000000be,0x000000bc,0x0003003e, + 0x000000bd,0x000000be,0x00050039,0x00000007,0x000000bf,0x00000013,0x000000bd,0x0003003e, + 0x000000ba,0x000000bf,0x0004003d,0x00000007,0x000000c2,0x000000ba,0x0003003e,0x000000c1, + 0x000000c2,0x00050039,0x00000009,0x000000c3,0x0000000c,0x000000c1,0x0003003e,0x000000c0, + 0x000000c3,0x0004003d,0x00000007,0x000000c6,0x000000ba,0x0003003e,0x000000c5,0x000000c6, + 0x00050039,0x00000009,0x000000c7,0x0000000f,0x000000c5,0x0003003e,0x000000c4,0x000000c7, + 0x0004003d,0x00000009,0x000000c9,0x000000c0,0x0004003d,0x00000009,0x000000ca,0x000000c4, + 0x00060050,0x00000009,0x000000cc,0x000000cb,0x000000cb,0x000000cb,0x0008000c,0x00000009, + 0x000000cd,0x00000001,0x0000002e,0x000000c9,0x000000ca,0x000000cc,0x0003003e,0x000000c8, + 0x000000cd,0x0004003d,0x00000009,0x000000d0,0x000000c8,0x00050051,0x00000006,0x000000d1, + 0x000000d0,0x00000000,0x00050051,0x00000006,0x000000d2,0x000000d0,0x00000001,0x00050051, + 0x00000006,0x000000d3,0x000000d0,0x00000002,0x00070050,0x0000001d,0x000000d4,0x000000d1, + 0x000000d2,0x000000d3,0x0000005a,0x0003003e,0x000000cf,0x000000d4,0x000100fd,0x00010038, + 0x00050036,0x00000009,0x0000000c,0x00000000,0x0000000a,0x00030037,0x00000008,0x0000000b, + 0x000200f8,0x0000000d,0x0004003b,0x00000015,0x00000016,0x00000007,0x0004003b,0x00000015, + 0x00000020,0x00000007,0x0004003b,0x00000031,0x00000032,0x00000007,0x0004003b,0x00000015, + 0x00000058,0x00000007,0x0004003b,0x00000015,0x00000066,0x00000007,0x0004003d,0x00000018, + 0x0000001b,0x0000001a,0x0004003d,0x00000007,0x0000001c,0x0000000b,0x00050057,0x0000001d, + 0x0000001e,0x0000001b,0x0000001c,0x0008004f,0x00000009,0x0000001f,0x0000001e,0x0000001e, + 0x00000000,0x00000001,0x00000002,0x0003003e,0x00000016,0x0000001f,0x0004003d,0x00000009, + 0x00000021,0x00000016,0x00050090,0x00000009,0x00000030,0x00000021,0x0000002f,0x0003003e, + 0x00000020,0x00000030,0x00050041,0x00000031,0x00000036,0x0000000b,0x00000035,0x0004003d, + 0x00000006,0x00000037,0x00000036,0x00060041,0x0000003d,0x0000003e,0x0000003a,0x0000003c, + 0x00000035,0x0004003d,0x00000006,0x0000003f,0x0000003e,0x00050085,0x00000006,0x00000040, + 0x00000037,0x0000003f,0x0005008d,0x00000006,0x00000042,0x00000040,0x00000041,0x00050041, + 0x0000003d,0x00000044,0x0000003a,0x00000043,0x0004003d,0x00000006,0x00000045,0x00000044, + 0x00050081,0x00000006,0x00000046,0x00000042,0x00000045,0x00050085,0x00000006,0x00000047, + 0x00000033,0x00000046,0x0003003e,0x00000032,0x00000047,0x0004003d,0x00000006,0x00000048, + 0x00000032,0x00050085,0x00000006,0x0000004a,0x00000048,0x00000049,0x0006000c,0x00000006, + 0x0000004b,0x00000001,0x0000000e,0x0000004a,0x00050041,0x00000031,0x0000004c,0x00000020, + 0x00000035,0x0004003d,0x00000006,0x0000004d,0x0000004c,0x00050085,0x00000006,0x0000004e, + 0x0000004d,0x0000004b,0x00050041,0x00000031,0x0000004f,0x00000020,0x00000035,0x0003003e, + 0x0000004f,0x0000004e,0x0004003d,0x00000006,0x00000050,0x00000032,0x00050085,0x00000006, + 0x00000051,0x00000050,0x00000049,0x0006000c,0x00000006,0x00000052,0x00000001,0x0000000d, + 0x00000051,0x00050041,0x00000031,0x00000054,0x00000020,0x00000053,0x0004003d,0x00000006, + 0x00000055,0x00000054,0x00050085,0x00000006,0x00000056,0x00000055,0x00000052,0x00050041, + 0x00000031,0x00000057,0x00000020,0x00000053,0x0003003e,0x00000057,0x00000056,0x0004003d, + 0x00000009,0x00000059,0x00000020,0x00050090,0x00000009,0x00000065,0x00000059,0x00000064, + 0x0003003e,0x00000058,0x00000065,0x0004003d,0x00000018,0x00000067,0x0000001a,0x0004003d, + 0x00000007,0x00000068,0x0000000b,0x00050081,0x00000007,0x0000006c,0x00000068,0x0000006b, + 0x00050057,0x0000001d,0x0000006d,0x00000067,0x0000006c,0x00050051,0x00000006,0x0000006f, + 0x0000006d,0x00000000,0x00050041,0x00000031,0x00000070,0x00000066,0x0000006e,0x0003003e, + 0x00000070,0x0000006f,0x0004003d,0x00000018,0x00000071,0x0000001a,0x0004003d,0x00000007, + 0x00000072,0x0000000b,0x00050081,0x00000007,0x00000075,0x00000072,0x00000074,0x00050057, + 0x0000001d,0x00000076,0x00000071,0x00000075,0x00050051,0x00000006,0x00000077,0x00000076, + 0x00000001,0x00050041,0x00000031,0x00000078,0x00000066,0x00000035,0x0003003e,0x00000078, + 0x00000077,0x0004003d,0x00000018,0x00000079,0x0000001a,0x0004003d,0x00000007,0x0000007a, + 0x0000000b,0x00050083,0x00000007,0x0000007b,0x0000007a,0x0000006b,0x00050057,0x0000001d, + 0x0000007c,0x00000079,0x0000007b,0x00050051,0x00000006,0x0000007d,0x0000007c,0x00000002, + 0x00050041,0x00000031,0x0000007e,0x00000066,0x00000053,0x0003003e,0x0000007e,0x0000007d, + 0x0004003d,0x00000009,0x0000007f,0x00000066,0x000200fe,0x0000007f,0x00010038,0x00050036, + 0x00000009,0x0000000f,0x00000000,0x0000000a,0x00030037,0x00000008,0x0000000e,0x000200f8, + 0x00000010,0x0004003b,0x00000015,0x00000082,0x00000007,0x0004003b,0x00000031,0x00000087, + 0x00000007,0x0004003d,0x00000018,0x00000083,0x0000001a,0x0004003d,0x00000007,0x00000084, + 0x0000000e,0x00050057,0x0000001d,0x00000085,0x00000083,0x00000084,0x0008004f,0x00000009, + 0x00000086,0x00000085,0x00000085,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000082, + 0x00000086,0x00050041,0x00000031,0x00000088,0x0000000e,0x00000035,0x0004003d,0x00000006, + 0x00000089,0x00000088,0x00060041,0x0000003d,0x0000008a,0x0000003a,0x0000003c,0x00000035, + 0x0004003d,0x00000006,0x0000008b,0x0000008a,0x00050085,0x00000006,0x0000008c,0x00000089, + 0x0000008b,0x00050085,0x00000006,0x0000008d,0x0000008c,0x00000041,0x0006000c,0x00000006, + 0x0000008e,0x00000001,0x0000000d,0x0000008d,0x0006000c,0x00000006,0x0000008f,0x00000001, + 0x00000004,0x0000008e,0x00050085,0x00000006,0x00000091,0x0000008f,0x00000090,0x0003003e, + 0x00000087,0x00000091,0x0004003d,0x00000006,0x00000092,0x00000087,0x00050085,0x00000006, + 0x00000093,0x00000092,0x00000049,0x00050083,0x00000006,0x00000094,0x0000005a,0x00000093, + 0x0004003d,0x00000009,0x00000095,0x00000082,0x0005008e,0x00000009,0x00000096,0x00000095, + 0x00000094,0x0003003e,0x00000082,0x00000096,0x0004003d,0x00000009,0x00000097,0x00000082, + 0x000200fe,0x00000097,0x00010038,0x00050036,0x00000007,0x00000013,0x00000000,0x00000011, + 0x00030037,0x00000008,0x00000012,0x000200f8,0x00000014,0x0004003b,0x00000031,0x0000009e, + 0x00000007,0x0004003d,0x00000007,0x0000009a,0x00000012,0x0005008e,0x00000007,0x0000009b, + 0x0000009a,0x00000041,0x00050050,0x00000007,0x0000009c,0x0000005a,0x0000005a,0x00050083, + 0x00000007,0x0000009d,0x0000009b,0x0000009c,0x0003003e,0x00000012,0x0000009d,0x00050041, + 0x00000031,0x0000009f,0x00000012,0x0000006e,0x0004003d,0x00000006,0x000000a0,0x0000009f, + 0x00050041,0x00000031,0x000000a1,0x00000012,0x0000006e,0x0004003d,0x00000006,0x000000a2, + 0x000000a1,0x00050085,0x00000006,0x000000a3,0x000000a0,0x000000a2,0x00050041,0x00000031, + 0x000000a4,0x00000012,0x00000035,0x0004003d,0x00000006,0x000000a5,0x000000a4,0x00050041, + 0x00000031,0x000000a6,0x00000012,0x00000035,0x0004003d,0x00000006,0x000000a7,0x000000a6, + 0x00050085,0x00000006,0x000000a8,0x000000a5,0x000000a7,0x00050081,0x00000006,0x000000a9, + 0x000000a3,0x000000a8,0x0006000c,0x00000006,0x000000aa,0x00000001,0x0000001f,0x000000a9, + 0x0003003e,0x0000009e,0x000000aa,0x0004003d,0x00000007,0x000000ab,0x00000012,0x0004003d, + 0x00000006,0x000000ac,0x0000009e,0x0004003d,0x00000006,0x000000ad,0x0000009e,0x00050085, + 0x00000006,0x000000ae,0x000000ac,0x000000ad,0x0005008e,0x00000007,0x000000af,0x000000ab, + 0x000000ae,0x0005008e,0x00000007,0x000000b1,0x000000af,0x000000b0,0x0004003d,0x00000007, + 0x000000b2,0x00000012,0x00050081,0x00000007,0x000000b3,0x000000b2,0x000000b1,0x0003003e, + 0x00000012,0x000000b3,0x0004003d,0x00000007,0x000000b4,0x00000012,0x0005008e,0x00000007, + 0x000000b5,0x000000b4,0x00000049,0x00050050,0x00000007,0x000000b6,0x00000049,0x00000049, + 0x00050081,0x00000007,0x000000b7,0x000000b5,0x000000b6,0x000200fe,0x000000b7,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/sgsr_frag.h b/app/src/main/cpp/shaders/sgsr_frag.h new file mode 100644 index 0000000000..2452fb68f3 --- /dev/null +++ b/app/src/main/cpp/shaders/sgsr_frag.h @@ -0,0 +1,403 @@ + // 1116.2.0 + #pragma once +const uint32_t sgsr_code[] = { + 0x07230203,0x00010000,0x0008000b,0x00000216,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000051,0x00000214,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00070005,0x0000000a,0x74736166,0x636e614c,0x32736f7a,0x3b316628,0x00000000, + 0x00030005,0x00000009,0x00000078,0x00080005,0x00000012,0x67696577,0x28597468,0x663b3166, + 0x31663b31,0x3b31663b,0x00000000,0x00030005,0x0000000e,0x00007864,0x00030005,0x0000000f, + 0x00007964,0x00030005,0x00000010,0x00000063,0x00030005,0x00000011,0x00647473,0x00030005, + 0x00000014,0x00004177,0x00030005,0x00000018,0x00004277,0x00030005,0x00000026,0x00000078, + 0x00030005,0x00000038,0x00000077,0x00040005,0x00000039,0x61726170,0x0000006d,0x00060005, + 0x00000045,0x77656956,0x74726f70,0x6f666e49,0x00000000,0x00030005,0x00000046,0x00004350, + 0x00040006,0x00000046,0x00000000,0x0063646e,0x00070006,0x00000046,0x00000001,0x77656956, + 0x74726f70,0x6f666e49,0x00000000,0x00070006,0x00000046,0x00000002,0x65676445,0x72616853, + 0x73656e70,0x00000073,0x00030005,0x00000048,0x00006370,0x00030005,0x0000004f,0x00007675, + 0x00060005,0x00000051,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040005,0x00000053, + 0x6f6c6f63,0x00000072,0x00030005,0x00000057,0x00307370,0x00050005,0x00000067,0x43676d69, + 0x64726f6f,0x00000000,0x00060005,0x00000070,0x43676d69,0x64726f6f,0x65786950,0x0000006c, + 0x00040005,0x00000073,0x726f6f63,0x00000064,0x00030005,0x00000078,0x00006c70,0x00040005, + 0x0000007d,0x7466656c,0x00000000,0x00050005,0x00000081,0x65676465,0x65746f56,0x00000000, + 0x00040005,0x000000a2,0x68676972,0x00000074,0x00040005,0x000000aa,0x6f447075,0x00006e77, + 0x00040005,0x000000c5,0x6e61656d,0x00000000,0x00030005,0x000000e4,0x006d7573,0x00030005, + 0x00000114,0x00647473,0x00030005,0x00000118,0x00595761,0x00040005,0x0000011c,0x61726170, + 0x0000006d,0x00040005,0x0000011f,0x61726170,0x0000006d,0x00040005,0x00000120,0x61726170, + 0x0000006d,0x00040005,0x00000123,0x61726170,0x0000006d,0x00040005,0x0000012c,0x61726170, + 0x0000006d,0x00040005,0x0000012d,0x61726170,0x0000006d,0x00040005,0x0000012e,0x61726170, + 0x0000006d,0x00040005,0x00000131,0x61726170,0x0000006d,0x00040005,0x0000013d,0x61726170, + 0x0000006d,0x00040005,0x0000013e,0x61726170,0x0000006d,0x00040005,0x0000013f,0x61726170, + 0x0000006d,0x00040005,0x00000142,0x61726170,0x0000006d,0x00040005,0x0000014a,0x61726170, + 0x0000006d,0x00040005,0x0000014d,0x61726170,0x0000006d,0x00040005,0x0000014e,0x61726170, + 0x0000006d,0x00040005,0x00000151,0x61726170,0x0000006d,0x00040005,0x0000015c,0x61726170, + 0x0000006d,0x00040005,0x0000015d,0x61726170,0x0000006d,0x00040005,0x0000015e,0x61726170, + 0x0000006d,0x00040005,0x00000161,0x61726170,0x0000006d,0x00040005,0x00000169,0x61726170, + 0x0000006d,0x00040005,0x0000016c,0x61726170,0x0000006d,0x00040005,0x0000016d,0x61726170, + 0x0000006d,0x00040005,0x00000170,0x61726170,0x0000006d,0x00040005,0x00000175,0x61726170, + 0x0000006d,0x00040005,0x00000178,0x61726170,0x0000006d,0x00040005,0x0000017b,0x61726170, + 0x0000006d,0x00040005,0x0000017e,0x61726170,0x0000006d,0x00040005,0x00000186,0x61726170, + 0x0000006d,0x00040005,0x00000187,0x61726170,0x0000006d,0x00040005,0x0000018a,0x61726170, + 0x0000006d,0x00040005,0x0000018d,0x61726170,0x0000006d,0x00040005,0x00000198,0x61726170, + 0x0000006d,0x00040005,0x00000199,0x61726170,0x0000006d,0x00040005,0x0000019a,0x61726170, + 0x0000006d,0x00040005,0x0000019d,0x61726170,0x0000006d,0x00040005,0x000001a8,0x61726170, + 0x0000006d,0x00040005,0x000001a9,0x61726170,0x0000006d,0x00040005,0x000001aa,0x61726170, + 0x0000006d,0x00040005,0x000001ad,0x61726170,0x0000006d,0x00040005,0x000001b5,0x61726170, + 0x0000006d,0x00040005,0x000001b6,0x61726170,0x0000006d,0x00040005,0x000001b9,0x61726170, + 0x0000006d,0x00040005,0x000001bc,0x61726170,0x0000006d,0x00040005,0x000001c4,0x61726170, + 0x0000006d,0x00040005,0x000001c5,0x61726170,0x0000006d,0x00040005,0x000001c8,0x61726170, + 0x0000006d,0x00040005,0x000001cb,0x61726170,0x0000006d,0x00040005,0x000001d0,0x616e6966, + 0x0000596c,0x00040005,0x000001d6,0x5978616d,0x00000000,0x00040005,0x000001e2,0x596e696d, + 0x00000000,0x00040005,0x000001f7,0x746c6564,0x00005961,0x00050005,0x00000214,0x5f74756f, + 0x67726154,0x00307465,0x00030047,0x00000046,0x00000002,0x00050048,0x00000046,0x00000000, + 0x00000023,0x00000000,0x00050048,0x00000046,0x00000001,0x00000023,0x00000010,0x00050048, + 0x00000046,0x00000002,0x00000023,0x00000020,0x00040047,0x00000051,0x0000001e,0x00000000, + 0x00040047,0x00000057,0x00000021,0x00000000,0x00040047,0x00000057,0x00000022,0x00000000, + 0x00040047,0x00000214,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003, + 0x00000002,0x00030016,0x00000006,0x00000020,0x00040020,0x00000007,0x00000007,0x00000006, + 0x00040021,0x00000008,0x00000006,0x00000007,0x00040017,0x0000000c,0x00000006,0x00000002, + 0x00070021,0x0000000d,0x0000000c,0x00000007,0x00000007,0x00000007,0x00000007,0x0004002b, + 0x00000006,0x00000016,0x40800000,0x0004002b,0x00000006,0x0000002e,0x3f0ccccd,0x0004002b, + 0x00000006,0x00000034,0x00000000,0x0004002b,0x00000006,0x00000035,0x3f800000,0x00040017, + 0x00000043,0x00000006,0x00000004,0x00040020,0x00000044,0x00000007,0x00000043,0x0005001e, + 0x00000046,0x00000043,0x00000043,0x00000006,0x00040020,0x00000047,0x00000009,0x00000046, + 0x0004003b,0x00000047,0x00000048,0x00000009,0x00040015,0x00000049,0x00000020,0x00000001, + 0x0004002b,0x00000049,0x0000004a,0x00000001,0x00040020,0x0000004b,0x00000009,0x00000043, + 0x00040020,0x0000004e,0x00000007,0x0000000c,0x00040020,0x00000050,0x00000001,0x0000000c, + 0x0004003b,0x00000050,0x00000051,0x00000001,0x00090019,0x00000054,0x00000006,0x00000001, + 0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000055,0x00000054, + 0x00040020,0x00000056,0x00000000,0x00000055,0x0004003b,0x00000056,0x00000057,0x00000000, + 0x00040017,0x0000005b,0x00000006,0x00000003,0x00040015,0x0000005d,0x00000020,0x00000000, + 0x0004002b,0x0000005d,0x0000005e,0x00000000,0x0004002b,0x0000005d,0x00000061,0x00000001, + 0x0004002b,0x0000005d,0x00000064,0x00000002,0x0004002b,0x00000006,0x0000006c,0xbf000000, + 0x0004002b,0x00000006,0x0000006d,0x3f000000,0x0005002c,0x0000000c,0x0000006e,0x0000006c, + 0x0000006d,0x0004002b,0x00000006,0x00000097,0x3d008081,0x00020014,0x00000098,0x0004002b, + 0x0000005d,0x000000c2,0x00000003,0x0004002b,0x00000006,0x000000d1,0x3e800000,0x0004002b, + 0x00000006,0x00000115,0x400ba2e8,0x0004002b,0x00000006,0x0000013b,0x40000000,0x0004002b, + 0x00000049,0x000001ee,0x00000002,0x00040020,0x000001ef,0x00000009,0x00000006,0x0004002b, + 0x00000006,0x000001fd,0xbdb8b8b9,0x0004002b,0x00000006,0x000001fe,0x3db8b8b9,0x00040020, + 0x00000213,0x00000003,0x00000043,0x0004003b,0x00000213,0x00000214,0x00000003,0x00050036, + 0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x00000044, + 0x00000045,0x00000007,0x0004003b,0x0000004e,0x0000004f,0x00000007,0x0004003b,0x00000044, + 0x00000053,0x00000007,0x0004003b,0x0000004e,0x00000067,0x00000007,0x0004003b,0x0000004e, + 0x00000070,0x00000007,0x0004003b,0x0000004e,0x00000073,0x00000007,0x0004003b,0x0000004e, + 0x00000078,0x00000007,0x0004003b,0x00000044,0x0000007d,0x00000007,0x0004003b,0x00000007, + 0x00000081,0x00000007,0x0004003b,0x00000044,0x000000a2,0x00000007,0x0004003b,0x00000044, + 0x000000aa,0x00000007,0x0004003b,0x00000007,0x000000c5,0x00000007,0x0004003b,0x00000007, + 0x000000e4,0x00000007,0x0004003b,0x00000007,0x00000114,0x00000007,0x0004003b,0x0000004e, + 0x00000118,0x00000007,0x0004003b,0x00000007,0x0000011c,0x00000007,0x0004003b,0x00000007, + 0x0000011f,0x00000007,0x0004003b,0x00000007,0x00000120,0x00000007,0x0004003b,0x00000007, + 0x00000123,0x00000007,0x0004003b,0x00000007,0x0000012c,0x00000007,0x0004003b,0x00000007, + 0x0000012d,0x00000007,0x0004003b,0x00000007,0x0000012e,0x00000007,0x0004003b,0x00000007, + 0x00000131,0x00000007,0x0004003b,0x00000007,0x0000013d,0x00000007,0x0004003b,0x00000007, + 0x0000013e,0x00000007,0x0004003b,0x00000007,0x0000013f,0x00000007,0x0004003b,0x00000007, + 0x00000142,0x00000007,0x0004003b,0x00000007,0x0000014a,0x00000007,0x0004003b,0x00000007, + 0x0000014d,0x00000007,0x0004003b,0x00000007,0x0000014e,0x00000007,0x0004003b,0x00000007, + 0x00000151,0x00000007,0x0004003b,0x00000007,0x0000015c,0x00000007,0x0004003b,0x00000007, + 0x0000015d,0x00000007,0x0004003b,0x00000007,0x0000015e,0x00000007,0x0004003b,0x00000007, + 0x00000161,0x00000007,0x0004003b,0x00000007,0x00000169,0x00000007,0x0004003b,0x00000007, + 0x0000016c,0x00000007,0x0004003b,0x00000007,0x0000016d,0x00000007,0x0004003b,0x00000007, + 0x00000170,0x00000007,0x0004003b,0x00000007,0x00000175,0x00000007,0x0004003b,0x00000007, + 0x00000178,0x00000007,0x0004003b,0x00000007,0x0000017b,0x00000007,0x0004003b,0x00000007, + 0x0000017e,0x00000007,0x0004003b,0x00000007,0x00000186,0x00000007,0x0004003b,0x00000007, + 0x00000187,0x00000007,0x0004003b,0x00000007,0x0000018a,0x00000007,0x0004003b,0x00000007, + 0x0000018d,0x00000007,0x0004003b,0x00000007,0x00000198,0x00000007,0x0004003b,0x00000007, + 0x00000199,0x00000007,0x0004003b,0x00000007,0x0000019a,0x00000007,0x0004003b,0x00000007, + 0x0000019d,0x00000007,0x0004003b,0x00000007,0x000001a8,0x00000007,0x0004003b,0x00000007, + 0x000001a9,0x00000007,0x0004003b,0x00000007,0x000001aa,0x00000007,0x0004003b,0x00000007, + 0x000001ad,0x00000007,0x0004003b,0x00000007,0x000001b5,0x00000007,0x0004003b,0x00000007, + 0x000001b6,0x00000007,0x0004003b,0x00000007,0x000001b9,0x00000007,0x0004003b,0x00000007, + 0x000001bc,0x00000007,0x0004003b,0x00000007,0x000001c4,0x00000007,0x0004003b,0x00000007, + 0x000001c5,0x00000007,0x0004003b,0x00000007,0x000001c8,0x00000007,0x0004003b,0x00000007, + 0x000001cb,0x00000007,0x0004003b,0x00000007,0x000001d0,0x00000007,0x0004003b,0x00000007, + 0x000001d6,0x00000007,0x0004003b,0x00000007,0x000001e2,0x00000007,0x0004003b,0x00000007, + 0x000001f7,0x00000007,0x00050041,0x0000004b,0x0000004c,0x00000048,0x0000004a,0x0004003d, + 0x00000043,0x0000004d,0x0000004c,0x0003003e,0x00000045,0x0000004d,0x0004003d,0x0000000c, + 0x00000052,0x00000051,0x0003003e,0x0000004f,0x00000052,0x0004003d,0x00000055,0x00000058, + 0x00000057,0x0004003d,0x0000000c,0x00000059,0x0000004f,0x00070058,0x00000043,0x0000005a, + 0x00000058,0x00000059,0x00000002,0x00000034,0x0008004f,0x0000005b,0x0000005c,0x0000005a, + 0x0000005a,0x00000000,0x00000001,0x00000002,0x00050041,0x00000007,0x0000005f,0x00000053, + 0x0000005e,0x00050051,0x00000006,0x00000060,0x0000005c,0x00000000,0x0003003e,0x0000005f, + 0x00000060,0x00050041,0x00000007,0x00000062,0x00000053,0x00000061,0x00050051,0x00000006, + 0x00000063,0x0000005c,0x00000001,0x0003003e,0x00000062,0x00000063,0x00050041,0x00000007, + 0x00000065,0x00000053,0x00000064,0x00050051,0x00000006,0x00000066,0x0000005c,0x00000002, + 0x0003003e,0x00000065,0x00000066,0x0004003d,0x0000000c,0x00000068,0x0000004f,0x0004003d, + 0x00000043,0x00000069,0x00000045,0x0007004f,0x0000000c,0x0000006a,0x00000069,0x00000069, + 0x00000002,0x00000003,0x00050085,0x0000000c,0x0000006b,0x00000068,0x0000006a,0x00050081, + 0x0000000c,0x0000006f,0x0000006b,0x0000006e,0x0003003e,0x00000067,0x0000006f,0x0004003d, + 0x0000000c,0x00000071,0x00000067,0x0006000c,0x0000000c,0x00000072,0x00000001,0x00000008, + 0x00000071,0x0003003e,0x00000070,0x00000072,0x0004003d,0x0000000c,0x00000074,0x00000070, + 0x0004003d,0x00000043,0x00000075,0x00000045,0x0007004f,0x0000000c,0x00000076,0x00000075, + 0x00000075,0x00000000,0x00000001,0x00050085,0x0000000c,0x00000077,0x00000074,0x00000076, + 0x0003003e,0x00000073,0x00000077,0x0004003d,0x0000000c,0x00000079,0x00000067,0x0004003d, + 0x0000000c,0x0000007a,0x00000070,0x0004007f,0x0000000c,0x0000007b,0x0000007a,0x00050081, + 0x0000000c,0x0000007c,0x00000079,0x0000007b,0x0003003e,0x00000078,0x0000007c,0x0004003d, + 0x00000055,0x0000007e,0x00000057,0x0004003d,0x0000000c,0x0000007f,0x00000073,0x00060060, + 0x00000043,0x00000080,0x0000007e,0x0000007f,0x0000004a,0x0003003e,0x0000007d,0x00000080, + 0x00050041,0x00000007,0x00000082,0x0000007d,0x00000064,0x0004003d,0x00000006,0x00000083, + 0x00000082,0x00050041,0x00000007,0x00000084,0x0000007d,0x00000061,0x0004003d,0x00000006, + 0x00000085,0x00000084,0x00050083,0x00000006,0x00000086,0x00000083,0x00000085,0x0006000c, + 0x00000006,0x00000087,0x00000001,0x00000004,0x00000086,0x00050041,0x00000007,0x00000088, + 0x00000053,0x00000061,0x0004003d,0x00000006,0x00000089,0x00000088,0x00050041,0x00000007, + 0x0000008a,0x0000007d,0x00000061,0x0004003d,0x00000006,0x0000008b,0x0000008a,0x00050083, + 0x00000006,0x0000008c,0x00000089,0x0000008b,0x0006000c,0x00000006,0x0000008d,0x00000001, + 0x00000004,0x0000008c,0x00050081,0x00000006,0x0000008e,0x00000087,0x0000008d,0x00050041, + 0x00000007,0x0000008f,0x00000053,0x00000061,0x0004003d,0x00000006,0x00000090,0x0000008f, + 0x00050041,0x00000007,0x00000091,0x0000007d,0x00000064,0x0004003d,0x00000006,0x00000092, + 0x00000091,0x00050083,0x00000006,0x00000093,0x00000090,0x00000092,0x0006000c,0x00000006, + 0x00000094,0x00000001,0x00000004,0x00000093,0x00050081,0x00000006,0x00000095,0x0000008e, + 0x00000094,0x0003003e,0x00000081,0x00000095,0x0004003d,0x00000006,0x00000096,0x00000081, + 0x000500ba,0x00000098,0x00000099,0x00000096,0x00000097,0x000300f7,0x0000009b,0x00000000, + 0x000400fa,0x00000099,0x0000009a,0x0000009b,0x000200f8,0x0000009a,0x00050041,0x00000007, + 0x0000009c,0x00000045,0x0000005e,0x0004003d,0x00000006,0x0000009d,0x0000009c,0x00050041, + 0x00000007,0x0000009e,0x00000073,0x0000005e,0x0004003d,0x00000006,0x0000009f,0x0000009e, + 0x00050081,0x00000006,0x000000a0,0x0000009f,0x0000009d,0x00050041,0x00000007,0x000000a1, + 0x00000073,0x0000005e,0x0003003e,0x000000a1,0x000000a0,0x0004003d,0x00000055,0x000000a3, + 0x00000057,0x0004003d,0x0000000c,0x000000a4,0x00000073,0x00050041,0x00000007,0x000000a5, + 0x00000045,0x0000005e,0x0004003d,0x00000006,0x000000a6,0x000000a5,0x00050050,0x0000000c, + 0x000000a7,0x000000a6,0x00000034,0x00050081,0x0000000c,0x000000a8,0x000000a4,0x000000a7, + 0x00060060,0x00000043,0x000000a9,0x000000a3,0x000000a8,0x0000004a,0x0003003e,0x000000a2, + 0x000000a9,0x0004003d,0x00000055,0x000000ab,0x00000057,0x0004003d,0x0000000c,0x000000ac, + 0x00000073,0x00050041,0x00000007,0x000000ad,0x00000045,0x00000061,0x0004003d,0x00000006, + 0x000000ae,0x000000ad,0x0004007f,0x00000006,0x000000af,0x000000ae,0x00050050,0x0000000c, + 0x000000b0,0x00000034,0x000000af,0x00050081,0x0000000c,0x000000b1,0x000000ac,0x000000b0, + 0x00060060,0x00000043,0x000000b2,0x000000ab,0x000000b1,0x0000004a,0x0007004f,0x0000000c, + 0x000000b3,0x000000b2,0x000000b2,0x00000003,0x00000002,0x00050041,0x00000007,0x000000b4, + 0x000000aa,0x0000005e,0x00050051,0x00000006,0x000000b5,0x000000b3,0x00000000,0x0003003e, + 0x000000b4,0x000000b5,0x00050041,0x00000007,0x000000b6,0x000000aa,0x00000061,0x00050051, + 0x00000006,0x000000b7,0x000000b3,0x00000001,0x0003003e,0x000000b6,0x000000b7,0x0004003d, + 0x00000055,0x000000b8,0x00000057,0x0004003d,0x0000000c,0x000000b9,0x00000073,0x00050041, + 0x00000007,0x000000ba,0x00000045,0x00000061,0x0004003d,0x00000006,0x000000bb,0x000000ba, + 0x00050050,0x0000000c,0x000000bc,0x00000034,0x000000bb,0x00050081,0x0000000c,0x000000bd, + 0x000000b9,0x000000bc,0x00060060,0x00000043,0x000000be,0x000000b8,0x000000bd,0x0000004a, + 0x0007004f,0x0000000c,0x000000bf,0x000000be,0x000000be,0x00000001,0x00000000,0x00050041, + 0x00000007,0x000000c0,0x000000aa,0x00000064,0x00050051,0x00000006,0x000000c1,0x000000bf, + 0x00000000,0x0003003e,0x000000c0,0x000000c1,0x00050041,0x00000007,0x000000c3,0x000000aa, + 0x000000c2,0x00050051,0x00000006,0x000000c4,0x000000bf,0x00000001,0x0003003e,0x000000c3, + 0x000000c4,0x00050041,0x00000007,0x000000c6,0x0000007d,0x00000061,0x0004003d,0x00000006, + 0x000000c7,0x000000c6,0x00050041,0x00000007,0x000000c8,0x0000007d,0x00000064,0x0004003d, + 0x00000006,0x000000c9,0x000000c8,0x00050081,0x00000006,0x000000ca,0x000000c7,0x000000c9, + 0x00050041,0x00000007,0x000000cb,0x000000a2,0x0000005e,0x0004003d,0x00000006,0x000000cc, + 0x000000cb,0x00050081,0x00000006,0x000000cd,0x000000ca,0x000000cc,0x00050041,0x00000007, + 0x000000ce,0x000000a2,0x000000c2,0x0004003d,0x00000006,0x000000cf,0x000000ce,0x00050081, + 0x00000006,0x000000d0,0x000000cd,0x000000cf,0x00050085,0x00000006,0x000000d2,0x000000d0, + 0x000000d1,0x0003003e,0x000000c5,0x000000d2,0x0004003d,0x00000043,0x000000d3,0x0000007d, + 0x0004003d,0x00000006,0x000000d4,0x000000c5,0x00070050,0x00000043,0x000000d5,0x000000d4, + 0x000000d4,0x000000d4,0x000000d4,0x00050083,0x00000043,0x000000d6,0x000000d3,0x000000d5, + 0x0003003e,0x0000007d,0x000000d6,0x0004003d,0x00000043,0x000000d7,0x000000a2,0x0004003d, + 0x00000006,0x000000d8,0x000000c5,0x00070050,0x00000043,0x000000d9,0x000000d8,0x000000d8, + 0x000000d8,0x000000d8,0x00050083,0x00000043,0x000000da,0x000000d7,0x000000d9,0x0003003e, + 0x000000a2,0x000000da,0x0004003d,0x00000043,0x000000db,0x000000aa,0x0004003d,0x00000006, + 0x000000dc,0x000000c5,0x00070050,0x00000043,0x000000dd,0x000000dc,0x000000dc,0x000000dc, + 0x000000dc,0x00050083,0x00000043,0x000000de,0x000000db,0x000000dd,0x0003003e,0x000000aa, + 0x000000de,0x00050041,0x00000007,0x000000df,0x00000053,0x00000061,0x0004003d,0x00000006, + 0x000000e0,0x000000df,0x0004003d,0x00000006,0x000000e1,0x000000c5,0x00050083,0x00000006, + 0x000000e2,0x000000e0,0x000000e1,0x00050041,0x00000007,0x000000e3,0x00000053,0x000000c2, + 0x0003003e,0x000000e3,0x000000e2,0x00050041,0x00000007,0x000000e5,0x0000007d,0x0000005e, + 0x0004003d,0x00000006,0x000000e6,0x000000e5,0x0006000c,0x00000006,0x000000e7,0x00000001, + 0x00000004,0x000000e6,0x00050041,0x00000007,0x000000e8,0x0000007d,0x00000061,0x0004003d, + 0x00000006,0x000000e9,0x000000e8,0x0006000c,0x00000006,0x000000ea,0x00000001,0x00000004, + 0x000000e9,0x00050081,0x00000006,0x000000eb,0x000000e7,0x000000ea,0x00050041,0x00000007, + 0x000000ec,0x0000007d,0x00000064,0x0004003d,0x00000006,0x000000ed,0x000000ec,0x0006000c, + 0x00000006,0x000000ee,0x00000001,0x00000004,0x000000ed,0x00050081,0x00000006,0x000000ef, + 0x000000eb,0x000000ee,0x00050041,0x00000007,0x000000f0,0x0000007d,0x000000c2,0x0004003d, + 0x00000006,0x000000f1,0x000000f0,0x0006000c,0x00000006,0x000000f2,0x00000001,0x00000004, + 0x000000f1,0x00050081,0x00000006,0x000000f3,0x000000ef,0x000000f2,0x00050041,0x00000007, + 0x000000f4,0x000000a2,0x0000005e,0x0004003d,0x00000006,0x000000f5,0x000000f4,0x0006000c, + 0x00000006,0x000000f6,0x00000001,0x00000004,0x000000f5,0x00050041,0x00000007,0x000000f7, + 0x000000a2,0x00000061,0x0004003d,0x00000006,0x000000f8,0x000000f7,0x0006000c,0x00000006, + 0x000000f9,0x00000001,0x00000004,0x000000f8,0x00050081,0x00000006,0x000000fa,0x000000f6, + 0x000000f9,0x00050041,0x00000007,0x000000fb,0x000000a2,0x00000064,0x0004003d,0x00000006, + 0x000000fc,0x000000fb,0x0006000c,0x00000006,0x000000fd,0x00000001,0x00000004,0x000000fc, + 0x00050081,0x00000006,0x000000fe,0x000000fa,0x000000fd,0x00050041,0x00000007,0x000000ff, + 0x000000a2,0x000000c2,0x0004003d,0x00000006,0x00000100,0x000000ff,0x0006000c,0x00000006, + 0x00000101,0x00000001,0x00000004,0x00000100,0x00050081,0x00000006,0x00000102,0x000000fe, + 0x00000101,0x00050081,0x00000006,0x00000103,0x000000f3,0x00000102,0x00050041,0x00000007, + 0x00000104,0x000000aa,0x0000005e,0x0004003d,0x00000006,0x00000105,0x00000104,0x0006000c, + 0x00000006,0x00000106,0x00000001,0x00000004,0x00000105,0x00050041,0x00000007,0x00000107, + 0x000000aa,0x00000061,0x0004003d,0x00000006,0x00000108,0x00000107,0x0006000c,0x00000006, + 0x00000109,0x00000001,0x00000004,0x00000108,0x00050081,0x00000006,0x0000010a,0x00000106, + 0x00000109,0x00050041,0x00000007,0x0000010b,0x000000aa,0x00000064,0x0004003d,0x00000006, + 0x0000010c,0x0000010b,0x0006000c,0x00000006,0x0000010d,0x00000001,0x00000004,0x0000010c, + 0x00050081,0x00000006,0x0000010e,0x0000010a,0x0000010d,0x00050041,0x00000007,0x0000010f, + 0x000000aa,0x000000c2,0x0004003d,0x00000006,0x00000110,0x0000010f,0x0006000c,0x00000006, + 0x00000111,0x00000001,0x00000004,0x00000110,0x00050081,0x00000006,0x00000112,0x0000010e, + 0x00000111,0x00050081,0x00000006,0x00000113,0x00000103,0x00000112,0x0003003e,0x000000e4, + 0x00000113,0x0004003d,0x00000006,0x00000116,0x000000e4,0x00050088,0x00000006,0x00000117, + 0x00000115,0x00000116,0x0003003e,0x00000114,0x00000117,0x00050041,0x00000007,0x00000119, + 0x00000078,0x00000061,0x0004003d,0x00000006,0x0000011a,0x00000119,0x00050081,0x00000006, + 0x0000011b,0x0000011a,0x00000035,0x00050041,0x00000007,0x0000011d,0x00000078,0x0000005e, + 0x0004003d,0x00000006,0x0000011e,0x0000011d,0x0003003e,0x0000011c,0x0000011e,0x0003003e, + 0x0000011f,0x0000011b,0x00050041,0x00000007,0x00000121,0x000000aa,0x0000005e,0x0004003d, + 0x00000006,0x00000122,0x00000121,0x0003003e,0x00000120,0x00000122,0x0004003d,0x00000006, + 0x00000124,0x00000114,0x0003003e,0x00000123,0x00000124,0x00080039,0x0000000c,0x00000125, + 0x00000012,0x0000011c,0x0000011f,0x00000120,0x00000123,0x0003003e,0x00000118,0x00000125, + 0x00050041,0x00000007,0x00000126,0x00000078,0x0000005e,0x0004003d,0x00000006,0x00000127, + 0x00000126,0x00050083,0x00000006,0x00000128,0x00000127,0x00000035,0x00050041,0x00000007, + 0x00000129,0x00000078,0x00000061,0x0004003d,0x00000006,0x0000012a,0x00000129,0x00050081, + 0x00000006,0x0000012b,0x0000012a,0x00000035,0x0003003e,0x0000012c,0x00000128,0x0003003e, + 0x0000012d,0x0000012b,0x00050041,0x00000007,0x0000012f,0x000000aa,0x00000061,0x0004003d, + 0x00000006,0x00000130,0x0000012f,0x0003003e,0x0000012e,0x00000130,0x0004003d,0x00000006, + 0x00000132,0x00000114,0x0003003e,0x00000131,0x00000132,0x00080039,0x0000000c,0x00000133, + 0x00000012,0x0000012c,0x0000012d,0x0000012e,0x00000131,0x0004003d,0x0000000c,0x00000134, + 0x00000118,0x00050081,0x0000000c,0x00000135,0x00000134,0x00000133,0x0003003e,0x00000118, + 0x00000135,0x00050041,0x00000007,0x00000136,0x00000078,0x0000005e,0x0004003d,0x00000006, + 0x00000137,0x00000136,0x00050083,0x00000006,0x00000138,0x00000137,0x00000035,0x00050041, + 0x00000007,0x00000139,0x00000078,0x00000061,0x0004003d,0x00000006,0x0000013a,0x00000139, + 0x00050083,0x00000006,0x0000013c,0x0000013a,0x0000013b,0x0003003e,0x0000013d,0x00000138, + 0x0003003e,0x0000013e,0x0000013c,0x00050041,0x00000007,0x00000140,0x000000aa,0x00000064, + 0x0004003d,0x00000006,0x00000141,0x00000140,0x0003003e,0x0000013f,0x00000141,0x0004003d, + 0x00000006,0x00000143,0x00000114,0x0003003e,0x00000142,0x00000143,0x00080039,0x0000000c, + 0x00000144,0x00000012,0x0000013d,0x0000013e,0x0000013f,0x00000142,0x0004003d,0x0000000c, + 0x00000145,0x00000118,0x00050081,0x0000000c,0x00000146,0x00000145,0x00000144,0x0003003e, + 0x00000118,0x00000146,0x00050041,0x00000007,0x00000147,0x00000078,0x00000061,0x0004003d, + 0x00000006,0x00000148,0x00000147,0x00050083,0x00000006,0x00000149,0x00000148,0x0000013b, + 0x00050041,0x00000007,0x0000014b,0x00000078,0x0000005e,0x0004003d,0x00000006,0x0000014c, + 0x0000014b,0x0003003e,0x0000014a,0x0000014c,0x0003003e,0x0000014d,0x00000149,0x00050041, + 0x00000007,0x0000014f,0x000000aa,0x000000c2,0x0004003d,0x00000006,0x00000150,0x0000014f, + 0x0003003e,0x0000014e,0x00000150,0x0004003d,0x00000006,0x00000152,0x00000114,0x0003003e, + 0x00000151,0x00000152,0x00080039,0x0000000c,0x00000153,0x00000012,0x0000014a,0x0000014d, + 0x0000014e,0x00000151,0x0004003d,0x0000000c,0x00000154,0x00000118,0x00050081,0x0000000c, + 0x00000155,0x00000154,0x00000153,0x0003003e,0x00000118,0x00000155,0x00050041,0x00000007, + 0x00000156,0x00000078,0x0000005e,0x0004003d,0x00000006,0x00000157,0x00000156,0x00050081, + 0x00000006,0x00000158,0x00000157,0x00000035,0x00050041,0x00000007,0x00000159,0x00000078, + 0x00000061,0x0004003d,0x00000006,0x0000015a,0x00000159,0x00050083,0x00000006,0x0000015b, + 0x0000015a,0x00000035,0x0003003e,0x0000015c,0x00000158,0x0003003e,0x0000015d,0x0000015b, + 0x00050041,0x00000007,0x0000015f,0x0000007d,0x0000005e,0x0004003d,0x00000006,0x00000160, + 0x0000015f,0x0003003e,0x0000015e,0x00000160,0x0004003d,0x00000006,0x00000162,0x00000114, + 0x0003003e,0x00000161,0x00000162,0x00080039,0x0000000c,0x00000163,0x00000012,0x0000015c, + 0x0000015d,0x0000015e,0x00000161,0x0004003d,0x0000000c,0x00000164,0x00000118,0x00050081, + 0x0000000c,0x00000165,0x00000164,0x00000163,0x0003003e,0x00000118,0x00000165,0x00050041, + 0x00000007,0x00000166,0x00000078,0x00000061,0x0004003d,0x00000006,0x00000167,0x00000166, + 0x00050083,0x00000006,0x00000168,0x00000167,0x00000035,0x00050041,0x00000007,0x0000016a, + 0x00000078,0x0000005e,0x0004003d,0x00000006,0x0000016b,0x0000016a,0x0003003e,0x00000169, + 0x0000016b,0x0003003e,0x0000016c,0x00000168,0x00050041,0x00000007,0x0000016e,0x0000007d, + 0x00000061,0x0004003d,0x00000006,0x0000016f,0x0000016e,0x0003003e,0x0000016d,0x0000016f, + 0x0004003d,0x00000006,0x00000171,0x00000114,0x0003003e,0x00000170,0x00000171,0x00080039, + 0x0000000c,0x00000172,0x00000012,0x00000169,0x0000016c,0x0000016d,0x00000170,0x0004003d, + 0x0000000c,0x00000173,0x00000118,0x00050081,0x0000000c,0x00000174,0x00000173,0x00000172, + 0x0003003e,0x00000118,0x00000174,0x00050041,0x00000007,0x00000176,0x00000078,0x0000005e, + 0x0004003d,0x00000006,0x00000177,0x00000176,0x0003003e,0x00000175,0x00000177,0x00050041, + 0x00000007,0x00000179,0x00000078,0x00000061,0x0004003d,0x00000006,0x0000017a,0x00000179, + 0x0003003e,0x00000178,0x0000017a,0x00050041,0x00000007,0x0000017c,0x0000007d,0x00000064, + 0x0004003d,0x00000006,0x0000017d,0x0000017c,0x0003003e,0x0000017b,0x0000017d,0x0004003d, + 0x00000006,0x0000017f,0x00000114,0x0003003e,0x0000017e,0x0000017f,0x00080039,0x0000000c, + 0x00000180,0x00000012,0x00000175,0x00000178,0x0000017b,0x0000017e,0x0004003d,0x0000000c, + 0x00000181,0x00000118,0x00050081,0x0000000c,0x00000182,0x00000181,0x00000180,0x0003003e, + 0x00000118,0x00000182,0x00050041,0x00000007,0x00000183,0x00000078,0x0000005e,0x0004003d, + 0x00000006,0x00000184,0x00000183,0x00050081,0x00000006,0x00000185,0x00000184,0x00000035, + 0x0003003e,0x00000186,0x00000185,0x00050041,0x00000007,0x00000188,0x00000078,0x00000061, + 0x0004003d,0x00000006,0x00000189,0x00000188,0x0003003e,0x00000187,0x00000189,0x00050041, + 0x00000007,0x0000018b,0x0000007d,0x000000c2,0x0004003d,0x00000006,0x0000018c,0x0000018b, + 0x0003003e,0x0000018a,0x0000018c,0x0004003d,0x00000006,0x0000018e,0x00000114,0x0003003e, + 0x0000018d,0x0000018e,0x00080039,0x0000000c,0x0000018f,0x00000012,0x00000186,0x00000187, + 0x0000018a,0x0000018d,0x0004003d,0x0000000c,0x00000190,0x00000118,0x00050081,0x0000000c, + 0x00000191,0x00000190,0x0000018f,0x0003003e,0x00000118,0x00000191,0x00050041,0x00000007, + 0x00000192,0x00000078,0x0000005e,0x0004003d,0x00000006,0x00000193,0x00000192,0x00050083, + 0x00000006,0x00000194,0x00000193,0x00000035,0x00050041,0x00000007,0x00000195,0x00000078, + 0x00000061,0x0004003d,0x00000006,0x00000196,0x00000195,0x00050083,0x00000006,0x00000197, + 0x00000196,0x00000035,0x0003003e,0x00000198,0x00000194,0x0003003e,0x00000199,0x00000197, + 0x00050041,0x00000007,0x0000019b,0x000000a2,0x0000005e,0x0004003d,0x00000006,0x0000019c, + 0x0000019b,0x0003003e,0x0000019a,0x0000019c,0x0004003d,0x00000006,0x0000019e,0x00000114, + 0x0003003e,0x0000019d,0x0000019e,0x00080039,0x0000000c,0x0000019f,0x00000012,0x00000198, + 0x00000199,0x0000019a,0x0000019d,0x0004003d,0x0000000c,0x000001a0,0x00000118,0x00050081, + 0x0000000c,0x000001a1,0x000001a0,0x0000019f,0x0003003e,0x00000118,0x000001a1,0x00050041, + 0x00000007,0x000001a2,0x00000078,0x0000005e,0x0004003d,0x00000006,0x000001a3,0x000001a2, + 0x00050083,0x00000006,0x000001a4,0x000001a3,0x0000013b,0x00050041,0x00000007,0x000001a5, + 0x00000078,0x00000061,0x0004003d,0x00000006,0x000001a6,0x000001a5,0x00050083,0x00000006, + 0x000001a7,0x000001a6,0x00000035,0x0003003e,0x000001a8,0x000001a4,0x0003003e,0x000001a9, + 0x000001a7,0x00050041,0x00000007,0x000001ab,0x000000a2,0x00000061,0x0004003d,0x00000006, + 0x000001ac,0x000001ab,0x0003003e,0x000001aa,0x000001ac,0x0004003d,0x00000006,0x000001ae, + 0x00000114,0x0003003e,0x000001ad,0x000001ae,0x00080039,0x0000000c,0x000001af,0x00000012, + 0x000001a8,0x000001a9,0x000001aa,0x000001ad,0x0004003d,0x0000000c,0x000001b0,0x00000118, + 0x00050081,0x0000000c,0x000001b1,0x000001b0,0x000001af,0x0003003e,0x00000118,0x000001b1, + 0x00050041,0x00000007,0x000001b2,0x00000078,0x0000005e,0x0004003d,0x00000006,0x000001b3, + 0x000001b2,0x00050083,0x00000006,0x000001b4,0x000001b3,0x0000013b,0x0003003e,0x000001b5, + 0x000001b4,0x00050041,0x00000007,0x000001b7,0x00000078,0x00000061,0x0004003d,0x00000006, + 0x000001b8,0x000001b7,0x0003003e,0x000001b6,0x000001b8,0x00050041,0x00000007,0x000001ba, + 0x000000a2,0x00000064,0x0004003d,0x00000006,0x000001bb,0x000001ba,0x0003003e,0x000001b9, + 0x000001bb,0x0004003d,0x00000006,0x000001bd,0x00000114,0x0003003e,0x000001bc,0x000001bd, + 0x00080039,0x0000000c,0x000001be,0x00000012,0x000001b5,0x000001b6,0x000001b9,0x000001bc, + 0x0004003d,0x0000000c,0x000001bf,0x00000118,0x00050081,0x0000000c,0x000001c0,0x000001bf, + 0x000001be,0x0003003e,0x00000118,0x000001c0,0x00050041,0x00000007,0x000001c1,0x00000078, + 0x0000005e,0x0004003d,0x00000006,0x000001c2,0x000001c1,0x00050083,0x00000006,0x000001c3, + 0x000001c2,0x00000035,0x0003003e,0x000001c4,0x000001c3,0x00050041,0x00000007,0x000001c6, + 0x00000078,0x00000061,0x0004003d,0x00000006,0x000001c7,0x000001c6,0x0003003e,0x000001c5, + 0x000001c7,0x00050041,0x00000007,0x000001c9,0x000000a2,0x000000c2,0x0004003d,0x00000006, + 0x000001ca,0x000001c9,0x0003003e,0x000001c8,0x000001ca,0x0004003d,0x00000006,0x000001cc, + 0x00000114,0x0003003e,0x000001cb,0x000001cc,0x00080039,0x0000000c,0x000001cd,0x00000012, + 0x000001c4,0x000001c5,0x000001c8,0x000001cb,0x0004003d,0x0000000c,0x000001ce,0x00000118, + 0x00050081,0x0000000c,0x000001cf,0x000001ce,0x000001cd,0x0003003e,0x00000118,0x000001cf, + 0x00050041,0x00000007,0x000001d1,0x00000118,0x00000061,0x0004003d,0x00000006,0x000001d2, + 0x000001d1,0x00050041,0x00000007,0x000001d3,0x00000118,0x0000005e,0x0004003d,0x00000006, + 0x000001d4,0x000001d3,0x00050088,0x00000006,0x000001d5,0x000001d2,0x000001d4,0x0003003e, + 0x000001d0,0x000001d5,0x00050041,0x00000007,0x000001d7,0x0000007d,0x00000061,0x0004003d, + 0x00000006,0x000001d8,0x000001d7,0x00050041,0x00000007,0x000001d9,0x0000007d,0x00000064, + 0x0004003d,0x00000006,0x000001da,0x000001d9,0x0007000c,0x00000006,0x000001db,0x00000001, + 0x00000028,0x000001d8,0x000001da,0x00050041,0x00000007,0x000001dc,0x000000a2,0x0000005e, + 0x0004003d,0x00000006,0x000001dd,0x000001dc,0x00050041,0x00000007,0x000001de,0x000000a2, + 0x000000c2,0x0004003d,0x00000006,0x000001df,0x000001de,0x0007000c,0x00000006,0x000001e0, + 0x00000001,0x00000028,0x000001dd,0x000001df,0x0007000c,0x00000006,0x000001e1,0x00000001, + 0x00000028,0x000001db,0x000001e0,0x0003003e,0x000001d6,0x000001e1,0x00050041,0x00000007, + 0x000001e3,0x0000007d,0x00000061,0x0004003d,0x00000006,0x000001e4,0x000001e3,0x00050041, + 0x00000007,0x000001e5,0x0000007d,0x00000064,0x0004003d,0x00000006,0x000001e6,0x000001e5, + 0x0007000c,0x00000006,0x000001e7,0x00000001,0x00000025,0x000001e4,0x000001e6,0x00050041, + 0x00000007,0x000001e8,0x000000a2,0x0000005e,0x0004003d,0x00000006,0x000001e9,0x000001e8, + 0x00050041,0x00000007,0x000001ea,0x000000a2,0x000000c2,0x0004003d,0x00000006,0x000001eb, + 0x000001ea,0x0007000c,0x00000006,0x000001ec,0x00000001,0x00000025,0x000001e9,0x000001eb, + 0x0007000c,0x00000006,0x000001ed,0x00000001,0x00000025,0x000001e7,0x000001ec,0x0003003e, + 0x000001e2,0x000001ed,0x00050041,0x000001ef,0x000001f0,0x00000048,0x000001ee,0x0004003d, + 0x00000006,0x000001f1,0x000001f0,0x0004003d,0x00000006,0x000001f2,0x000001d0,0x00050085, + 0x00000006,0x000001f3,0x000001f1,0x000001f2,0x0004003d,0x00000006,0x000001f4,0x000001e2, + 0x0004003d,0x00000006,0x000001f5,0x000001d6,0x0008000c,0x00000006,0x000001f6,0x00000001, + 0x0000002b,0x000001f3,0x000001f4,0x000001f5,0x0003003e,0x000001d0,0x000001f6,0x0004003d, + 0x00000006,0x000001f8,0x000001d0,0x00050041,0x00000007,0x000001f9,0x00000053,0x000000c2, + 0x0004003d,0x00000006,0x000001fa,0x000001f9,0x00050083,0x00000006,0x000001fb,0x000001f8, + 0x000001fa,0x0003003e,0x000001f7,0x000001fb,0x0004003d,0x00000006,0x000001fc,0x000001f7, + 0x0008000c,0x00000006,0x000001ff,0x00000001,0x0000002b,0x000001fc,0x000001fd,0x000001fe, + 0x0003003e,0x000001f7,0x000001ff,0x00050041,0x00000007,0x00000200,0x00000053,0x0000005e, + 0x0004003d,0x00000006,0x00000201,0x00000200,0x0004003d,0x00000006,0x00000202,0x000001f7, + 0x00050081,0x00000006,0x00000203,0x00000201,0x00000202,0x0008000c,0x00000006,0x00000204, + 0x00000001,0x0000002b,0x00000203,0x00000034,0x00000035,0x00050041,0x00000007,0x00000205, + 0x00000053,0x0000005e,0x0003003e,0x00000205,0x00000204,0x00050041,0x00000007,0x00000206, + 0x00000053,0x00000061,0x0004003d,0x00000006,0x00000207,0x00000206,0x0004003d,0x00000006, + 0x00000208,0x000001f7,0x00050081,0x00000006,0x00000209,0x00000207,0x00000208,0x0008000c, + 0x00000006,0x0000020a,0x00000001,0x0000002b,0x00000209,0x00000034,0x00000035,0x00050041, + 0x00000007,0x0000020b,0x00000053,0x00000061,0x0003003e,0x0000020b,0x0000020a,0x00050041, + 0x00000007,0x0000020c,0x00000053,0x00000064,0x0004003d,0x00000006,0x0000020d,0x0000020c, + 0x0004003d,0x00000006,0x0000020e,0x000001f7,0x00050081,0x00000006,0x0000020f,0x0000020d, + 0x0000020e,0x0008000c,0x00000006,0x00000210,0x00000001,0x0000002b,0x0000020f,0x00000034, + 0x00000035,0x00050041,0x00000007,0x00000211,0x00000053,0x00000064,0x0003003e,0x00000211, + 0x00000210,0x000200f9,0x0000009b,0x000200f8,0x0000009b,0x00050041,0x00000007,0x00000212, + 0x00000053,0x000000c2,0x0003003e,0x00000212,0x00000035,0x0004003d,0x00000043,0x00000215, + 0x00000053,0x0003003e,0x00000214,0x00000215,0x000100fd,0x00010038,0x00050036,0x00000006, + 0x0000000a,0x00000000,0x00000008,0x00030037,0x00000007,0x00000009,0x000200f8,0x0000000b, + 0x0004003b,0x00000007,0x00000014,0x00000007,0x0004003b,0x00000007,0x00000018,0x00000007, + 0x0004003d,0x00000006,0x00000015,0x00000009,0x00050083,0x00000006,0x00000017,0x00000015, + 0x00000016,0x0003003e,0x00000014,0x00000017,0x0004003d,0x00000006,0x00000019,0x00000009, + 0x0004003d,0x00000006,0x0000001a,0x00000014,0x00050085,0x00000006,0x0000001b,0x00000019, + 0x0000001a,0x0004003d,0x00000006,0x0000001c,0x00000014,0x00050083,0x00000006,0x0000001d, + 0x0000001b,0x0000001c,0x0003003e,0x00000018,0x0000001d,0x0004003d,0x00000006,0x0000001e, + 0x00000014,0x0004003d,0x00000006,0x0000001f,0x00000014,0x00050085,0x00000006,0x00000020, + 0x0000001f,0x0000001e,0x0003003e,0x00000014,0x00000020,0x0004003d,0x00000006,0x00000021, + 0x00000018,0x0004003d,0x00000006,0x00000022,0x00000014,0x00050085,0x00000006,0x00000023, + 0x00000021,0x00000022,0x000200fe,0x00000023,0x00010038,0x00050036,0x0000000c,0x00000012, + 0x00000000,0x0000000d,0x00030037,0x00000007,0x0000000e,0x00030037,0x00000007,0x0000000f, + 0x00030037,0x00000007,0x00000010,0x00030037,0x00000007,0x00000011,0x000200f8,0x00000013, + 0x0004003b,0x00000007,0x00000026,0x00000007,0x0004003b,0x00000007,0x00000038,0x00000007, + 0x0004003b,0x00000007,0x00000039,0x00000007,0x0004003d,0x00000006,0x00000027,0x0000000e, + 0x0004003d,0x00000006,0x00000028,0x0000000e,0x00050085,0x00000006,0x00000029,0x00000027, + 0x00000028,0x0004003d,0x00000006,0x0000002a,0x0000000f,0x0004003d,0x00000006,0x0000002b, + 0x0000000f,0x00050085,0x00000006,0x0000002c,0x0000002a,0x0000002b,0x00050081,0x00000006, + 0x0000002d,0x00000029,0x0000002c,0x00050085,0x00000006,0x0000002f,0x0000002d,0x0000002e, + 0x0004003d,0x00000006,0x00000030,0x00000010,0x0006000c,0x00000006,0x00000031,0x00000001, + 0x00000004,0x00000030,0x0004003d,0x00000006,0x00000032,0x00000011,0x00050085,0x00000006, + 0x00000033,0x00000031,0x00000032,0x0008000c,0x00000006,0x00000036,0x00000001,0x0000002b, + 0x00000033,0x00000034,0x00000035,0x00050081,0x00000006,0x00000037,0x0000002f,0x00000036, + 0x0003003e,0x00000026,0x00000037,0x0004003d,0x00000006,0x0000003a,0x00000026,0x0003003e, + 0x00000039,0x0000003a,0x00050039,0x00000006,0x0000003b,0x0000000a,0x00000039,0x0003003e, + 0x00000038,0x0000003b,0x0004003d,0x00000006,0x0000003c,0x00000038,0x0004003d,0x00000006, + 0x0000003d,0x00000038,0x0004003d,0x00000006,0x0000003e,0x00000010,0x00050085,0x00000006, + 0x0000003f,0x0000003d,0x0000003e,0x00050050,0x0000000c,0x00000040,0x0000003c,0x0000003f, + 0x000200fe,0x00000040,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/sgsr_quality_frag.h b/app/src/main/cpp/shaders/sgsr_quality_frag.h new file mode 100644 index 0000000000..ca44e6a6a5 --- /dev/null +++ b/app/src/main/cpp/shaders/sgsr_quality_frag.h @@ -0,0 +1,460 @@ + // 1116.5.0 + #pragma once +const uint32_t sgsr_quality_code[] = { + 0x07230203,0x00010000,0x0008000b,0x00000269,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000009c,0x00000267,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00070005,0x0000000a,0x74736166,0x636e614c,0x32736f7a,0x3b316628,0x00000000, + 0x00030005,0x00000009,0x00000078,0x00080005,0x00000014,0x67696577,0x28597468,0x663b3166, + 0x31663b31,0x3366763b,0x0000003b,0x00030005,0x00000010,0x00007864,0x00030005,0x00000011, + 0x00007964,0x00030005,0x00000012,0x00000063,0x00040005,0x00000013,0x61746164,0x00000000, + 0x00080005,0x0000001b,0x65676465,0x65726944,0x6f697463,0x6676286e,0x66763b34,0x00003b34, + 0x00040005,0x00000019,0x7466656c,0x00000000,0x00040005,0x0000001a,0x68676972,0x00000074, + 0x00030005,0x0000001d,0x00004177,0x00030005,0x00000021,0x00004277,0x00030005,0x0000002f, + 0x00647473,0x00030005,0x00000035,0x00726964,0x00040005,0x00000038,0x65676465,0x00736944, + 0x00030005,0x00000043,0x00000078,0x00030005,0x0000005b,0x00000077,0x00040005,0x0000005c, + 0x61726170,0x0000006d,0x00040005,0x00000066,0x7a4c7852,0x00000000,0x00040005,0x0000006d, + 0x794c7752,0x00000000,0x00040005,0x00000074,0x746c6564,0x00000061,0x00050005,0x0000007d, + 0x676e656c,0x6e496874,0x00000076,0x00060005,0x00000091,0x77656956,0x74726f70,0x6f666e49, + 0x00000000,0x00030005,0x00000092,0x00004350,0x00040006,0x00000092,0x00000000,0x0063646e, + 0x00070006,0x00000092,0x00000001,0x77656956,0x74726f70,0x6f666e49,0x00000000,0x00070006, + 0x00000092,0x00000002,0x65676445,0x72616853,0x73656e70,0x00000073,0x00030005,0x00000094, + 0x00006370,0x00030005,0x0000009a,0x00007675,0x00060005,0x0000009c,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00040005,0x0000009e,0x6f6c6f63,0x00000072,0x00030005,0x000000a2, + 0x00307370,0x00050005,0x000000ad,0x43676d69,0x64726f6f,0x00000000,0x00060005,0x000000b6, + 0x43676d69,0x64726f6f,0x65786950,0x0000006c,0x00040005,0x000000b9,0x726f6f63,0x00000064, + 0x00030005,0x000000be,0x00006c70,0x00040005,0x000000c3,0x7466656c,0x00000000,0x00050005, + 0x000000c7,0x65676465,0x65746f56,0x00000000,0x00040005,0x000000e8,0x68676972,0x00000074, + 0x00040005,0x000000f0,0x6f447075,0x00006e77,0x00040005,0x0000010a,0x6e61656d,0x00000000, + 0x00030005,0x00000129,0x006d7573,0x00040005,0x00000159,0x4d6d7573,0x006e6165,0x00030005, + 0x0000015d,0x00647473,0x00040005,0x00000161,0x61746164,0x00000000,0x00040005,0x00000163, + 0x61726170,0x0000006d,0x00040005,0x00000165,0x61726170,0x0000006d,0x00030005,0x0000016b, + 0x00595761,0x00040005,0x0000016f,0x61726170,0x0000006d,0x00040005,0x00000172,0x61726170, + 0x0000006d,0x00040005,0x00000173,0x61726170,0x0000006d,0x00040005,0x00000176,0x61726170, + 0x0000006d,0x00040005,0x0000017f,0x61726170,0x0000006d,0x00040005,0x00000180,0x61726170, + 0x0000006d,0x00040005,0x00000181,0x61726170,0x0000006d,0x00040005,0x00000184,0x61726170, + 0x0000006d,0x00040005,0x00000190,0x61726170,0x0000006d,0x00040005,0x00000191,0x61726170, + 0x0000006d,0x00040005,0x00000192,0x61726170,0x0000006d,0x00040005,0x00000195,0x61726170, + 0x0000006d,0x00040005,0x0000019d,0x61726170,0x0000006d,0x00040005,0x000001a0,0x61726170, + 0x0000006d,0x00040005,0x000001a1,0x61726170,0x0000006d,0x00040005,0x000001a4,0x61726170, + 0x0000006d,0x00040005,0x000001af,0x61726170,0x0000006d,0x00040005,0x000001b0,0x61726170, + 0x0000006d,0x00040005,0x000001b1,0x61726170,0x0000006d,0x00040005,0x000001b4,0x61726170, + 0x0000006d,0x00040005,0x000001bc,0x61726170,0x0000006d,0x00040005,0x000001bf,0x61726170, + 0x0000006d,0x00040005,0x000001c0,0x61726170,0x0000006d,0x00040005,0x000001c3,0x61726170, + 0x0000006d,0x00040005,0x000001c8,0x61726170,0x0000006d,0x00040005,0x000001cb,0x61726170, + 0x0000006d,0x00040005,0x000001ce,0x61726170,0x0000006d,0x00040005,0x000001d1,0x61726170, + 0x0000006d,0x00040005,0x000001d9,0x61726170,0x0000006d,0x00040005,0x000001da,0x61726170, + 0x0000006d,0x00040005,0x000001dd,0x61726170,0x0000006d,0x00040005,0x000001e0,0x61726170, + 0x0000006d,0x00040005,0x000001eb,0x61726170,0x0000006d,0x00040005,0x000001ec,0x61726170, + 0x0000006d,0x00040005,0x000001ed,0x61726170,0x0000006d,0x00040005,0x000001f0,0x61726170, + 0x0000006d,0x00040005,0x000001fb,0x61726170,0x0000006d,0x00040005,0x000001fc,0x61726170, + 0x0000006d,0x00040005,0x000001fd,0x61726170,0x0000006d,0x00040005,0x00000200,0x61726170, + 0x0000006d,0x00040005,0x00000208,0x61726170,0x0000006d,0x00040005,0x00000209,0x61726170, + 0x0000006d,0x00040005,0x0000020c,0x61726170,0x0000006d,0x00040005,0x0000020f,0x61726170, + 0x0000006d,0x00040005,0x00000217,0x61726170,0x0000006d,0x00040005,0x00000218,0x61726170, + 0x0000006d,0x00040005,0x0000021b,0x61726170,0x0000006d,0x00040005,0x0000021e,0x61726170, + 0x0000006d,0x00040005,0x00000223,0x616e6966,0x0000596c,0x00040005,0x00000229,0x5978616d, + 0x00000000,0x00040005,0x00000235,0x596e696d,0x00000000,0x00040005,0x0000024a,0x746c6564, + 0x00005961,0x00050005,0x00000267,0x5f74756f,0x67726154,0x00307465,0x00030047,0x00000092, + 0x00000002,0x00050048,0x00000092,0x00000000,0x00000023,0x00000000,0x00050048,0x00000092, + 0x00000001,0x00000023,0x00000010,0x00050048,0x00000092,0x00000002,0x00000023,0x00000020, + 0x00040047,0x0000009c,0x0000001e,0x00000000,0x00040047,0x000000a2,0x00000021,0x00000000, + 0x00040047,0x000000a2,0x00000022,0x00000000,0x00040047,0x00000267,0x0000001e,0x00000000, + 0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020, + 0x00040020,0x00000007,0x00000007,0x00000006,0x00040021,0x00000008,0x00000006,0x00000007, + 0x00040017,0x0000000c,0x00000006,0x00000003,0x00040020,0x0000000d,0x00000007,0x0000000c, + 0x00040017,0x0000000e,0x00000006,0x00000002,0x00070021,0x0000000f,0x0000000e,0x00000007, + 0x00000007,0x00000007,0x0000000d,0x00040017,0x00000016,0x00000006,0x00000004,0x00040020, + 0x00000017,0x00000007,0x00000016,0x00050021,0x00000018,0x0000000e,0x00000017,0x00000017, + 0x0004002b,0x00000006,0x0000001f,0x40800000,0x00040015,0x00000030,0x00000020,0x00000000, + 0x0004002b,0x00000030,0x00000031,0x00000000,0x00040020,0x00000034,0x00000007,0x0000000e, + 0x0004002b,0x00000030,0x0000003a,0x00000001,0x0004002b,0x00000006,0x00000053,0x00000000, + 0x0004002b,0x00000006,0x00000054,0x3f800000,0x0004002b,0x00000006,0x00000056,0x3f333333, + 0x0004002b,0x00000030,0x00000069,0x00000002,0x0004002b,0x00000030,0x0000006e,0x00000003, + 0x0004002b,0x00000006,0x00000083,0x38010182,0x0005001e,0x00000092,0x00000016,0x00000016, + 0x00000006,0x00040020,0x00000093,0x00000009,0x00000092,0x0004003b,0x00000093,0x00000094, + 0x00000009,0x00040015,0x00000095,0x00000020,0x00000001,0x0004002b,0x00000095,0x00000096, + 0x00000001,0x00040020,0x00000097,0x00000009,0x00000016,0x00040020,0x0000009b,0x00000001, + 0x0000000e,0x0004003b,0x0000009b,0x0000009c,0x00000001,0x00090019,0x0000009f,0x00000006, + 0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x000000a0, + 0x0000009f,0x00040020,0x000000a1,0x00000000,0x000000a0,0x0004003b,0x000000a1,0x000000a2, + 0x00000000,0x0004002b,0x00000006,0x000000b2,0xbf000000,0x0004002b,0x00000006,0x000000b3, + 0x3f000000,0x0005002c,0x0000000e,0x000000b4,0x000000b2,0x000000b3,0x0004002b,0x00000006, + 0x000000dd,0x3d008081,0x00020014,0x000000de,0x0004002b,0x00000006,0x00000116,0x3e800000, + 0x0004002b,0x00000006,0x0000015a,0x41224505,0x0004002b,0x00000006,0x0000018e,0x40000000, + 0x0004002b,0x00000095,0x00000241,0x00000002,0x00040020,0x00000242,0x00000009,0x00000006, + 0x0004002b,0x00000006,0x00000250,0xbdb8b8b9,0x0004002b,0x00000006,0x00000251,0x3db8b8b9, + 0x00040020,0x00000266,0x00000003,0x00000016,0x0004003b,0x00000266,0x00000267,0x00000003, + 0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b, + 0x00000017,0x00000091,0x00000007,0x0004003b,0x00000034,0x0000009a,0x00000007,0x0004003b, + 0x00000017,0x0000009e,0x00000007,0x0004003b,0x00000034,0x000000ad,0x00000007,0x0004003b, + 0x00000034,0x000000b6,0x00000007,0x0004003b,0x00000034,0x000000b9,0x00000007,0x0004003b, + 0x00000034,0x000000be,0x00000007,0x0004003b,0x00000017,0x000000c3,0x00000007,0x0004003b, + 0x00000007,0x000000c7,0x00000007,0x0004003b,0x00000017,0x000000e8,0x00000007,0x0004003b, + 0x00000017,0x000000f0,0x00000007,0x0004003b,0x00000007,0x0000010a,0x00000007,0x0004003b, + 0x00000007,0x00000129,0x00000007,0x0004003b,0x00000007,0x00000159,0x00000007,0x0004003b, + 0x00000007,0x0000015d,0x00000007,0x0004003b,0x0000000d,0x00000161,0x00000007,0x0004003b, + 0x00000017,0x00000163,0x00000007,0x0004003b,0x00000017,0x00000165,0x00000007,0x0004003b, + 0x00000034,0x0000016b,0x00000007,0x0004003b,0x00000007,0x0000016f,0x00000007,0x0004003b, + 0x00000007,0x00000172,0x00000007,0x0004003b,0x00000007,0x00000173,0x00000007,0x0004003b, + 0x0000000d,0x00000176,0x00000007,0x0004003b,0x00000007,0x0000017f,0x00000007,0x0004003b, + 0x00000007,0x00000180,0x00000007,0x0004003b,0x00000007,0x00000181,0x00000007,0x0004003b, + 0x0000000d,0x00000184,0x00000007,0x0004003b,0x00000007,0x00000190,0x00000007,0x0004003b, + 0x00000007,0x00000191,0x00000007,0x0004003b,0x00000007,0x00000192,0x00000007,0x0004003b, + 0x0000000d,0x00000195,0x00000007,0x0004003b,0x00000007,0x0000019d,0x00000007,0x0004003b, + 0x00000007,0x000001a0,0x00000007,0x0004003b,0x00000007,0x000001a1,0x00000007,0x0004003b, + 0x0000000d,0x000001a4,0x00000007,0x0004003b,0x00000007,0x000001af,0x00000007,0x0004003b, + 0x00000007,0x000001b0,0x00000007,0x0004003b,0x00000007,0x000001b1,0x00000007,0x0004003b, + 0x0000000d,0x000001b4,0x00000007,0x0004003b,0x00000007,0x000001bc,0x00000007,0x0004003b, + 0x00000007,0x000001bf,0x00000007,0x0004003b,0x00000007,0x000001c0,0x00000007,0x0004003b, + 0x0000000d,0x000001c3,0x00000007,0x0004003b,0x00000007,0x000001c8,0x00000007,0x0004003b, + 0x00000007,0x000001cb,0x00000007,0x0004003b,0x00000007,0x000001ce,0x00000007,0x0004003b, + 0x0000000d,0x000001d1,0x00000007,0x0004003b,0x00000007,0x000001d9,0x00000007,0x0004003b, + 0x00000007,0x000001da,0x00000007,0x0004003b,0x00000007,0x000001dd,0x00000007,0x0004003b, + 0x0000000d,0x000001e0,0x00000007,0x0004003b,0x00000007,0x000001eb,0x00000007,0x0004003b, + 0x00000007,0x000001ec,0x00000007,0x0004003b,0x00000007,0x000001ed,0x00000007,0x0004003b, + 0x0000000d,0x000001f0,0x00000007,0x0004003b,0x00000007,0x000001fb,0x00000007,0x0004003b, + 0x00000007,0x000001fc,0x00000007,0x0004003b,0x00000007,0x000001fd,0x00000007,0x0004003b, + 0x0000000d,0x00000200,0x00000007,0x0004003b,0x00000007,0x00000208,0x00000007,0x0004003b, + 0x00000007,0x00000209,0x00000007,0x0004003b,0x00000007,0x0000020c,0x00000007,0x0004003b, + 0x0000000d,0x0000020f,0x00000007,0x0004003b,0x00000007,0x00000217,0x00000007,0x0004003b, + 0x00000007,0x00000218,0x00000007,0x0004003b,0x00000007,0x0000021b,0x00000007,0x0004003b, + 0x0000000d,0x0000021e,0x00000007,0x0004003b,0x00000007,0x00000223,0x00000007,0x0004003b, + 0x00000007,0x00000229,0x00000007,0x0004003b,0x00000007,0x00000235,0x00000007,0x0004003b, + 0x00000007,0x0000024a,0x00000007,0x00050041,0x00000097,0x00000098,0x00000094,0x00000096, + 0x0004003d,0x00000016,0x00000099,0x00000098,0x0003003e,0x00000091,0x00000099,0x0004003d, + 0x0000000e,0x0000009d,0x0000009c,0x0003003e,0x0000009a,0x0000009d,0x0004003d,0x000000a0, + 0x000000a3,0x000000a2,0x0004003d,0x0000000e,0x000000a4,0x0000009a,0x00070058,0x00000016, + 0x000000a5,0x000000a3,0x000000a4,0x00000002,0x00000053,0x0008004f,0x0000000c,0x000000a6, + 0x000000a5,0x000000a5,0x00000000,0x00000001,0x00000002,0x00050041,0x00000007,0x000000a7, + 0x0000009e,0x00000031,0x00050051,0x00000006,0x000000a8,0x000000a6,0x00000000,0x0003003e, + 0x000000a7,0x000000a8,0x00050041,0x00000007,0x000000a9,0x0000009e,0x0000003a,0x00050051, + 0x00000006,0x000000aa,0x000000a6,0x00000001,0x0003003e,0x000000a9,0x000000aa,0x00050041, + 0x00000007,0x000000ab,0x0000009e,0x00000069,0x00050051,0x00000006,0x000000ac,0x000000a6, + 0x00000002,0x0003003e,0x000000ab,0x000000ac,0x0004003d,0x0000000e,0x000000ae,0x0000009a, + 0x0004003d,0x00000016,0x000000af,0x00000091,0x0007004f,0x0000000e,0x000000b0,0x000000af, + 0x000000af,0x00000002,0x00000003,0x00050085,0x0000000e,0x000000b1,0x000000ae,0x000000b0, + 0x00050081,0x0000000e,0x000000b5,0x000000b1,0x000000b4,0x0003003e,0x000000ad,0x000000b5, + 0x0004003d,0x0000000e,0x000000b7,0x000000ad,0x0006000c,0x0000000e,0x000000b8,0x00000001, + 0x00000008,0x000000b7,0x0003003e,0x000000b6,0x000000b8,0x0004003d,0x0000000e,0x000000ba, + 0x000000b6,0x0004003d,0x00000016,0x000000bb,0x00000091,0x0007004f,0x0000000e,0x000000bc, + 0x000000bb,0x000000bb,0x00000000,0x00000001,0x00050085,0x0000000e,0x000000bd,0x000000ba, + 0x000000bc,0x0003003e,0x000000b9,0x000000bd,0x0004003d,0x0000000e,0x000000bf,0x000000ad, + 0x0004003d,0x0000000e,0x000000c0,0x000000b6,0x0004007f,0x0000000e,0x000000c1,0x000000c0, + 0x00050081,0x0000000e,0x000000c2,0x000000bf,0x000000c1,0x0003003e,0x000000be,0x000000c2, + 0x0004003d,0x000000a0,0x000000c4,0x000000a2,0x0004003d,0x0000000e,0x000000c5,0x000000b9, + 0x00060060,0x00000016,0x000000c6,0x000000c4,0x000000c5,0x00000096,0x0003003e,0x000000c3, + 0x000000c6,0x00050041,0x00000007,0x000000c8,0x000000c3,0x00000069,0x0004003d,0x00000006, + 0x000000c9,0x000000c8,0x00050041,0x00000007,0x000000ca,0x000000c3,0x0000003a,0x0004003d, + 0x00000006,0x000000cb,0x000000ca,0x00050083,0x00000006,0x000000cc,0x000000c9,0x000000cb, + 0x0006000c,0x00000006,0x000000cd,0x00000001,0x00000004,0x000000cc,0x00050041,0x00000007, + 0x000000ce,0x0000009e,0x0000003a,0x0004003d,0x00000006,0x000000cf,0x000000ce,0x00050041, + 0x00000007,0x000000d0,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000000d1,0x000000d0, + 0x00050083,0x00000006,0x000000d2,0x000000cf,0x000000d1,0x0006000c,0x00000006,0x000000d3, + 0x00000001,0x00000004,0x000000d2,0x00050081,0x00000006,0x000000d4,0x000000cd,0x000000d3, + 0x00050041,0x00000007,0x000000d5,0x0000009e,0x0000003a,0x0004003d,0x00000006,0x000000d6, + 0x000000d5,0x00050041,0x00000007,0x000000d7,0x000000c3,0x00000069,0x0004003d,0x00000006, + 0x000000d8,0x000000d7,0x00050083,0x00000006,0x000000d9,0x000000d6,0x000000d8,0x0006000c, + 0x00000006,0x000000da,0x00000001,0x00000004,0x000000d9,0x00050081,0x00000006,0x000000db, + 0x000000d4,0x000000da,0x0003003e,0x000000c7,0x000000db,0x0004003d,0x00000006,0x000000dc, + 0x000000c7,0x000500ba,0x000000de,0x000000df,0x000000dc,0x000000dd,0x000300f7,0x000000e1, + 0x00000000,0x000400fa,0x000000df,0x000000e0,0x000000e1,0x000200f8,0x000000e0,0x00050041, + 0x00000007,0x000000e2,0x00000091,0x00000031,0x0004003d,0x00000006,0x000000e3,0x000000e2, + 0x00050041,0x00000007,0x000000e4,0x000000b9,0x00000031,0x0004003d,0x00000006,0x000000e5, + 0x000000e4,0x00050081,0x00000006,0x000000e6,0x000000e5,0x000000e3,0x00050041,0x00000007, + 0x000000e7,0x000000b9,0x00000031,0x0003003e,0x000000e7,0x000000e6,0x0004003d,0x000000a0, + 0x000000e9,0x000000a2,0x0004003d,0x0000000e,0x000000ea,0x000000b9,0x00050041,0x00000007, + 0x000000eb,0x00000091,0x00000031,0x0004003d,0x00000006,0x000000ec,0x000000eb,0x00050050, + 0x0000000e,0x000000ed,0x000000ec,0x00000053,0x00050081,0x0000000e,0x000000ee,0x000000ea, + 0x000000ed,0x00060060,0x00000016,0x000000ef,0x000000e9,0x000000ee,0x00000096,0x0003003e, + 0x000000e8,0x000000ef,0x0004003d,0x000000a0,0x000000f1,0x000000a2,0x0004003d,0x0000000e, + 0x000000f2,0x000000b9,0x00050041,0x00000007,0x000000f3,0x00000091,0x0000003a,0x0004003d, + 0x00000006,0x000000f4,0x000000f3,0x0004007f,0x00000006,0x000000f5,0x000000f4,0x00050050, + 0x0000000e,0x000000f6,0x00000053,0x000000f5,0x00050081,0x0000000e,0x000000f7,0x000000f2, + 0x000000f6,0x00060060,0x00000016,0x000000f8,0x000000f1,0x000000f7,0x00000096,0x0007004f, + 0x0000000e,0x000000f9,0x000000f8,0x000000f8,0x00000003,0x00000002,0x00050041,0x00000007, + 0x000000fa,0x000000f0,0x00000031,0x00050051,0x00000006,0x000000fb,0x000000f9,0x00000000, + 0x0003003e,0x000000fa,0x000000fb,0x00050041,0x00000007,0x000000fc,0x000000f0,0x0000003a, + 0x00050051,0x00000006,0x000000fd,0x000000f9,0x00000001,0x0003003e,0x000000fc,0x000000fd, + 0x0004003d,0x000000a0,0x000000fe,0x000000a2,0x0004003d,0x0000000e,0x000000ff,0x000000b9, + 0x00050041,0x00000007,0x00000100,0x00000091,0x0000003a,0x0004003d,0x00000006,0x00000101, + 0x00000100,0x00050050,0x0000000e,0x00000102,0x00000053,0x00000101,0x00050081,0x0000000e, + 0x00000103,0x000000ff,0x00000102,0x00060060,0x00000016,0x00000104,0x000000fe,0x00000103, + 0x00000096,0x0007004f,0x0000000e,0x00000105,0x00000104,0x00000104,0x00000001,0x00000000, + 0x00050041,0x00000007,0x00000106,0x000000f0,0x00000069,0x00050051,0x00000006,0x00000107, + 0x00000105,0x00000000,0x0003003e,0x00000106,0x00000107,0x00050041,0x00000007,0x00000108, + 0x000000f0,0x0000006e,0x00050051,0x00000006,0x00000109,0x00000105,0x00000001,0x0003003e, + 0x00000108,0x00000109,0x00050041,0x00000007,0x0000010b,0x000000c3,0x0000003a,0x0004003d, + 0x00000006,0x0000010c,0x0000010b,0x00050041,0x00000007,0x0000010d,0x000000c3,0x00000069, + 0x0004003d,0x00000006,0x0000010e,0x0000010d,0x00050081,0x00000006,0x0000010f,0x0000010c, + 0x0000010e,0x00050041,0x00000007,0x00000110,0x000000e8,0x00000031,0x0004003d,0x00000006, + 0x00000111,0x00000110,0x00050081,0x00000006,0x00000112,0x0000010f,0x00000111,0x00050041, + 0x00000007,0x00000113,0x000000e8,0x0000006e,0x0004003d,0x00000006,0x00000114,0x00000113, + 0x00050081,0x00000006,0x00000115,0x00000112,0x00000114,0x00050085,0x00000006,0x00000117, + 0x00000115,0x00000116,0x0003003e,0x0000010a,0x00000117,0x0004003d,0x00000016,0x00000118, + 0x000000c3,0x0004003d,0x00000006,0x00000119,0x0000010a,0x00070050,0x00000016,0x0000011a, + 0x00000119,0x00000119,0x00000119,0x00000119,0x00050083,0x00000016,0x0000011b,0x00000118, + 0x0000011a,0x0003003e,0x000000c3,0x0000011b,0x0004003d,0x00000016,0x0000011c,0x000000e8, + 0x0004003d,0x00000006,0x0000011d,0x0000010a,0x00070050,0x00000016,0x0000011e,0x0000011d, + 0x0000011d,0x0000011d,0x0000011d,0x00050083,0x00000016,0x0000011f,0x0000011c,0x0000011e, + 0x0003003e,0x000000e8,0x0000011f,0x0004003d,0x00000016,0x00000120,0x000000f0,0x0004003d, + 0x00000006,0x00000121,0x0000010a,0x00070050,0x00000016,0x00000122,0x00000121,0x00000121, + 0x00000121,0x00000121,0x00050083,0x00000016,0x00000123,0x00000120,0x00000122,0x0003003e, + 0x000000f0,0x00000123,0x00050041,0x00000007,0x00000124,0x0000009e,0x0000003a,0x0004003d, + 0x00000006,0x00000125,0x00000124,0x0004003d,0x00000006,0x00000126,0x0000010a,0x00050083, + 0x00000006,0x00000127,0x00000125,0x00000126,0x00050041,0x00000007,0x00000128,0x0000009e, + 0x0000006e,0x0003003e,0x00000128,0x00000127,0x00050041,0x00000007,0x0000012a,0x000000c3, + 0x00000031,0x0004003d,0x00000006,0x0000012b,0x0000012a,0x0006000c,0x00000006,0x0000012c, + 0x00000001,0x00000004,0x0000012b,0x00050041,0x00000007,0x0000012d,0x000000c3,0x0000003a, + 0x0004003d,0x00000006,0x0000012e,0x0000012d,0x0006000c,0x00000006,0x0000012f,0x00000001, + 0x00000004,0x0000012e,0x00050081,0x00000006,0x00000130,0x0000012c,0x0000012f,0x00050041, + 0x00000007,0x00000131,0x000000c3,0x00000069,0x0004003d,0x00000006,0x00000132,0x00000131, + 0x0006000c,0x00000006,0x00000133,0x00000001,0x00000004,0x00000132,0x00050081,0x00000006, + 0x00000134,0x00000130,0x00000133,0x00050041,0x00000007,0x00000135,0x000000c3,0x0000006e, + 0x0004003d,0x00000006,0x00000136,0x00000135,0x0006000c,0x00000006,0x00000137,0x00000001, + 0x00000004,0x00000136,0x00050081,0x00000006,0x00000138,0x00000134,0x00000137,0x00050041, + 0x00000007,0x00000139,0x000000e8,0x00000031,0x0004003d,0x00000006,0x0000013a,0x00000139, + 0x0006000c,0x00000006,0x0000013b,0x00000001,0x00000004,0x0000013a,0x00050041,0x00000007, + 0x0000013c,0x000000e8,0x0000003a,0x0004003d,0x00000006,0x0000013d,0x0000013c,0x0006000c, + 0x00000006,0x0000013e,0x00000001,0x00000004,0x0000013d,0x00050081,0x00000006,0x0000013f, + 0x0000013b,0x0000013e,0x00050041,0x00000007,0x00000140,0x000000e8,0x00000069,0x0004003d, + 0x00000006,0x00000141,0x00000140,0x0006000c,0x00000006,0x00000142,0x00000001,0x00000004, + 0x00000141,0x00050081,0x00000006,0x00000143,0x0000013f,0x00000142,0x00050041,0x00000007, + 0x00000144,0x000000e8,0x0000006e,0x0004003d,0x00000006,0x00000145,0x00000144,0x0006000c, + 0x00000006,0x00000146,0x00000001,0x00000004,0x00000145,0x00050081,0x00000006,0x00000147, + 0x00000143,0x00000146,0x00050081,0x00000006,0x00000148,0x00000138,0x00000147,0x00050041, + 0x00000007,0x00000149,0x000000f0,0x00000031,0x0004003d,0x00000006,0x0000014a,0x00000149, + 0x0006000c,0x00000006,0x0000014b,0x00000001,0x00000004,0x0000014a,0x00050041,0x00000007, + 0x0000014c,0x000000f0,0x0000003a,0x0004003d,0x00000006,0x0000014d,0x0000014c,0x0006000c, + 0x00000006,0x0000014e,0x00000001,0x00000004,0x0000014d,0x00050081,0x00000006,0x0000014f, + 0x0000014b,0x0000014e,0x00050041,0x00000007,0x00000150,0x000000f0,0x00000069,0x0004003d, + 0x00000006,0x00000151,0x00000150,0x0006000c,0x00000006,0x00000152,0x00000001,0x00000004, + 0x00000151,0x00050081,0x00000006,0x00000153,0x0000014f,0x00000152,0x00050041,0x00000007, + 0x00000154,0x000000f0,0x0000006e,0x0004003d,0x00000006,0x00000155,0x00000154,0x0006000c, + 0x00000006,0x00000156,0x00000001,0x00000004,0x00000155,0x00050081,0x00000006,0x00000157, + 0x00000153,0x00000156,0x00050081,0x00000006,0x00000158,0x00000148,0x00000157,0x0003003e, + 0x00000129,0x00000158,0x0004003d,0x00000006,0x0000015b,0x00000129,0x00050088,0x00000006, + 0x0000015c,0x0000015a,0x0000015b,0x0003003e,0x00000159,0x0000015c,0x0004003d,0x00000006, + 0x0000015e,0x00000159,0x0004003d,0x00000006,0x0000015f,0x00000159,0x00050085,0x00000006, + 0x00000160,0x0000015e,0x0000015f,0x0003003e,0x0000015d,0x00000160,0x0004003d,0x00000006, + 0x00000162,0x0000015d,0x0004003d,0x00000016,0x00000164,0x000000c3,0x0003003e,0x00000163, + 0x00000164,0x0004003d,0x00000016,0x00000166,0x000000e8,0x0003003e,0x00000165,0x00000166, + 0x00060039,0x0000000e,0x00000167,0x0000001b,0x00000163,0x00000165,0x00050051,0x00000006, + 0x00000168,0x00000167,0x00000000,0x00050051,0x00000006,0x00000169,0x00000167,0x00000001, + 0x00060050,0x0000000c,0x0000016a,0x00000162,0x00000168,0x00000169,0x0003003e,0x00000161, + 0x0000016a,0x00050041,0x00000007,0x0000016c,0x000000be,0x0000003a,0x0004003d,0x00000006, + 0x0000016d,0x0000016c,0x00050081,0x00000006,0x0000016e,0x0000016d,0x00000054,0x00050041, + 0x00000007,0x00000170,0x000000be,0x00000031,0x0004003d,0x00000006,0x00000171,0x00000170, + 0x0003003e,0x0000016f,0x00000171,0x0003003e,0x00000172,0x0000016e,0x00050041,0x00000007, + 0x00000174,0x000000f0,0x00000031,0x0004003d,0x00000006,0x00000175,0x00000174,0x0003003e, + 0x00000173,0x00000175,0x0004003d,0x0000000c,0x00000177,0x00000161,0x0003003e,0x00000176, + 0x00000177,0x00080039,0x0000000e,0x00000178,0x00000014,0x0000016f,0x00000172,0x00000173, + 0x00000176,0x0003003e,0x0000016b,0x00000178,0x00050041,0x00000007,0x00000179,0x000000be, + 0x00000031,0x0004003d,0x00000006,0x0000017a,0x00000179,0x00050083,0x00000006,0x0000017b, + 0x0000017a,0x00000054,0x00050041,0x00000007,0x0000017c,0x000000be,0x0000003a,0x0004003d, + 0x00000006,0x0000017d,0x0000017c,0x00050081,0x00000006,0x0000017e,0x0000017d,0x00000054, + 0x0003003e,0x0000017f,0x0000017b,0x0003003e,0x00000180,0x0000017e,0x00050041,0x00000007, + 0x00000182,0x000000f0,0x0000003a,0x0004003d,0x00000006,0x00000183,0x00000182,0x0003003e, + 0x00000181,0x00000183,0x0004003d,0x0000000c,0x00000185,0x00000161,0x0003003e,0x00000184, + 0x00000185,0x00080039,0x0000000e,0x00000186,0x00000014,0x0000017f,0x00000180,0x00000181, + 0x00000184,0x0004003d,0x0000000e,0x00000187,0x0000016b,0x00050081,0x0000000e,0x00000188, + 0x00000187,0x00000186,0x0003003e,0x0000016b,0x00000188,0x00050041,0x00000007,0x00000189, + 0x000000be,0x00000031,0x0004003d,0x00000006,0x0000018a,0x00000189,0x00050083,0x00000006, + 0x0000018b,0x0000018a,0x00000054,0x00050041,0x00000007,0x0000018c,0x000000be,0x0000003a, + 0x0004003d,0x00000006,0x0000018d,0x0000018c,0x00050083,0x00000006,0x0000018f,0x0000018d, + 0x0000018e,0x0003003e,0x00000190,0x0000018b,0x0003003e,0x00000191,0x0000018f,0x00050041, + 0x00000007,0x00000193,0x000000f0,0x00000069,0x0004003d,0x00000006,0x00000194,0x00000193, + 0x0003003e,0x00000192,0x00000194,0x0004003d,0x0000000c,0x00000196,0x00000161,0x0003003e, + 0x00000195,0x00000196,0x00080039,0x0000000e,0x00000197,0x00000014,0x00000190,0x00000191, + 0x00000192,0x00000195,0x0004003d,0x0000000e,0x00000198,0x0000016b,0x00050081,0x0000000e, + 0x00000199,0x00000198,0x00000197,0x0003003e,0x0000016b,0x00000199,0x00050041,0x00000007, + 0x0000019a,0x000000be,0x0000003a,0x0004003d,0x00000006,0x0000019b,0x0000019a,0x00050083, + 0x00000006,0x0000019c,0x0000019b,0x0000018e,0x00050041,0x00000007,0x0000019e,0x000000be, + 0x00000031,0x0004003d,0x00000006,0x0000019f,0x0000019e,0x0003003e,0x0000019d,0x0000019f, + 0x0003003e,0x000001a0,0x0000019c,0x00050041,0x00000007,0x000001a2,0x000000f0,0x0000006e, + 0x0004003d,0x00000006,0x000001a3,0x000001a2,0x0003003e,0x000001a1,0x000001a3,0x0004003d, + 0x0000000c,0x000001a5,0x00000161,0x0003003e,0x000001a4,0x000001a5,0x00080039,0x0000000e, + 0x000001a6,0x00000014,0x0000019d,0x000001a0,0x000001a1,0x000001a4,0x0004003d,0x0000000e, + 0x000001a7,0x0000016b,0x00050081,0x0000000e,0x000001a8,0x000001a7,0x000001a6,0x0003003e, + 0x0000016b,0x000001a8,0x00050041,0x00000007,0x000001a9,0x000000be,0x00000031,0x0004003d, + 0x00000006,0x000001aa,0x000001a9,0x00050081,0x00000006,0x000001ab,0x000001aa,0x00000054, + 0x00050041,0x00000007,0x000001ac,0x000000be,0x0000003a,0x0004003d,0x00000006,0x000001ad, + 0x000001ac,0x00050083,0x00000006,0x000001ae,0x000001ad,0x00000054,0x0003003e,0x000001af, + 0x000001ab,0x0003003e,0x000001b0,0x000001ae,0x00050041,0x00000007,0x000001b2,0x000000c3, + 0x00000031,0x0004003d,0x00000006,0x000001b3,0x000001b2,0x0003003e,0x000001b1,0x000001b3, + 0x0004003d,0x0000000c,0x000001b5,0x00000161,0x0003003e,0x000001b4,0x000001b5,0x00080039, + 0x0000000e,0x000001b6,0x00000014,0x000001af,0x000001b0,0x000001b1,0x000001b4,0x0004003d, + 0x0000000e,0x000001b7,0x0000016b,0x00050081,0x0000000e,0x000001b8,0x000001b7,0x000001b6, + 0x0003003e,0x0000016b,0x000001b8,0x00050041,0x00000007,0x000001b9,0x000000be,0x0000003a, + 0x0004003d,0x00000006,0x000001ba,0x000001b9,0x00050083,0x00000006,0x000001bb,0x000001ba, + 0x00000054,0x00050041,0x00000007,0x000001bd,0x000000be,0x00000031,0x0004003d,0x00000006, + 0x000001be,0x000001bd,0x0003003e,0x000001bc,0x000001be,0x0003003e,0x000001bf,0x000001bb, + 0x00050041,0x00000007,0x000001c1,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x000001c2, + 0x000001c1,0x0003003e,0x000001c0,0x000001c2,0x0004003d,0x0000000c,0x000001c4,0x00000161, + 0x0003003e,0x000001c3,0x000001c4,0x00080039,0x0000000e,0x000001c5,0x00000014,0x000001bc, + 0x000001bf,0x000001c0,0x000001c3,0x0004003d,0x0000000e,0x000001c6,0x0000016b,0x00050081, + 0x0000000e,0x000001c7,0x000001c6,0x000001c5,0x0003003e,0x0000016b,0x000001c7,0x00050041, + 0x00000007,0x000001c9,0x000000be,0x00000031,0x0004003d,0x00000006,0x000001ca,0x000001c9, + 0x0003003e,0x000001c8,0x000001ca,0x00050041,0x00000007,0x000001cc,0x000000be,0x0000003a, + 0x0004003d,0x00000006,0x000001cd,0x000001cc,0x0003003e,0x000001cb,0x000001cd,0x00050041, + 0x00000007,0x000001cf,0x000000c3,0x00000069,0x0004003d,0x00000006,0x000001d0,0x000001cf, + 0x0003003e,0x000001ce,0x000001d0,0x0004003d,0x0000000c,0x000001d2,0x00000161,0x0003003e, + 0x000001d1,0x000001d2,0x00080039,0x0000000e,0x000001d3,0x00000014,0x000001c8,0x000001cb, + 0x000001ce,0x000001d1,0x0004003d,0x0000000e,0x000001d4,0x0000016b,0x00050081,0x0000000e, + 0x000001d5,0x000001d4,0x000001d3,0x0003003e,0x0000016b,0x000001d5,0x00050041,0x00000007, + 0x000001d6,0x000000be,0x00000031,0x0004003d,0x00000006,0x000001d7,0x000001d6,0x00050081, + 0x00000006,0x000001d8,0x000001d7,0x00000054,0x0003003e,0x000001d9,0x000001d8,0x00050041, + 0x00000007,0x000001db,0x000000be,0x0000003a,0x0004003d,0x00000006,0x000001dc,0x000001db, + 0x0003003e,0x000001da,0x000001dc,0x00050041,0x00000007,0x000001de,0x000000c3,0x0000006e, + 0x0004003d,0x00000006,0x000001df,0x000001de,0x0003003e,0x000001dd,0x000001df,0x0004003d, + 0x0000000c,0x000001e1,0x00000161,0x0003003e,0x000001e0,0x000001e1,0x00080039,0x0000000e, + 0x000001e2,0x00000014,0x000001d9,0x000001da,0x000001dd,0x000001e0,0x0004003d,0x0000000e, + 0x000001e3,0x0000016b,0x00050081,0x0000000e,0x000001e4,0x000001e3,0x000001e2,0x0003003e, + 0x0000016b,0x000001e4,0x00050041,0x00000007,0x000001e5,0x000000be,0x00000031,0x0004003d, + 0x00000006,0x000001e6,0x000001e5,0x00050083,0x00000006,0x000001e7,0x000001e6,0x00000054, + 0x00050041,0x00000007,0x000001e8,0x000000be,0x0000003a,0x0004003d,0x00000006,0x000001e9, + 0x000001e8,0x00050083,0x00000006,0x000001ea,0x000001e9,0x00000054,0x0003003e,0x000001eb, + 0x000001e7,0x0003003e,0x000001ec,0x000001ea,0x00050041,0x00000007,0x000001ee,0x000000e8, + 0x00000031,0x0004003d,0x00000006,0x000001ef,0x000001ee,0x0003003e,0x000001ed,0x000001ef, + 0x0004003d,0x0000000c,0x000001f1,0x00000161,0x0003003e,0x000001f0,0x000001f1,0x00080039, + 0x0000000e,0x000001f2,0x00000014,0x000001eb,0x000001ec,0x000001ed,0x000001f0,0x0004003d, + 0x0000000e,0x000001f3,0x0000016b,0x00050081,0x0000000e,0x000001f4,0x000001f3,0x000001f2, + 0x0003003e,0x0000016b,0x000001f4,0x00050041,0x00000007,0x000001f5,0x000000be,0x00000031, + 0x0004003d,0x00000006,0x000001f6,0x000001f5,0x00050083,0x00000006,0x000001f7,0x000001f6, + 0x0000018e,0x00050041,0x00000007,0x000001f8,0x000000be,0x0000003a,0x0004003d,0x00000006, + 0x000001f9,0x000001f8,0x00050083,0x00000006,0x000001fa,0x000001f9,0x00000054,0x0003003e, + 0x000001fb,0x000001f7,0x0003003e,0x000001fc,0x000001fa,0x00050041,0x00000007,0x000001fe, + 0x000000e8,0x0000003a,0x0004003d,0x00000006,0x000001ff,0x000001fe,0x0003003e,0x000001fd, + 0x000001ff,0x0004003d,0x0000000c,0x00000201,0x00000161,0x0003003e,0x00000200,0x00000201, + 0x00080039,0x0000000e,0x00000202,0x00000014,0x000001fb,0x000001fc,0x000001fd,0x00000200, + 0x0004003d,0x0000000e,0x00000203,0x0000016b,0x00050081,0x0000000e,0x00000204,0x00000203, + 0x00000202,0x0003003e,0x0000016b,0x00000204,0x00050041,0x00000007,0x00000205,0x000000be, + 0x00000031,0x0004003d,0x00000006,0x00000206,0x00000205,0x00050083,0x00000006,0x00000207, + 0x00000206,0x0000018e,0x0003003e,0x00000208,0x00000207,0x00050041,0x00000007,0x0000020a, + 0x000000be,0x0000003a,0x0004003d,0x00000006,0x0000020b,0x0000020a,0x0003003e,0x00000209, + 0x0000020b,0x00050041,0x00000007,0x0000020d,0x000000e8,0x00000069,0x0004003d,0x00000006, + 0x0000020e,0x0000020d,0x0003003e,0x0000020c,0x0000020e,0x0004003d,0x0000000c,0x00000210, + 0x00000161,0x0003003e,0x0000020f,0x00000210,0x00080039,0x0000000e,0x00000211,0x00000014, + 0x00000208,0x00000209,0x0000020c,0x0000020f,0x0004003d,0x0000000e,0x00000212,0x0000016b, + 0x00050081,0x0000000e,0x00000213,0x00000212,0x00000211,0x0003003e,0x0000016b,0x00000213, + 0x00050041,0x00000007,0x00000214,0x000000be,0x00000031,0x0004003d,0x00000006,0x00000215, + 0x00000214,0x00050083,0x00000006,0x00000216,0x00000215,0x00000054,0x0003003e,0x00000217, + 0x00000216,0x00050041,0x00000007,0x00000219,0x000000be,0x0000003a,0x0004003d,0x00000006, + 0x0000021a,0x00000219,0x0003003e,0x00000218,0x0000021a,0x00050041,0x00000007,0x0000021c, + 0x000000e8,0x0000006e,0x0004003d,0x00000006,0x0000021d,0x0000021c,0x0003003e,0x0000021b, + 0x0000021d,0x0004003d,0x0000000c,0x0000021f,0x00000161,0x0003003e,0x0000021e,0x0000021f, + 0x00080039,0x0000000e,0x00000220,0x00000014,0x00000217,0x00000218,0x0000021b,0x0000021e, + 0x0004003d,0x0000000e,0x00000221,0x0000016b,0x00050081,0x0000000e,0x00000222,0x00000221, + 0x00000220,0x0003003e,0x0000016b,0x00000222,0x00050041,0x00000007,0x00000224,0x0000016b, + 0x0000003a,0x0004003d,0x00000006,0x00000225,0x00000224,0x00050041,0x00000007,0x00000226, + 0x0000016b,0x00000031,0x0004003d,0x00000006,0x00000227,0x00000226,0x00050088,0x00000006, + 0x00000228,0x00000225,0x00000227,0x0003003e,0x00000223,0x00000228,0x00050041,0x00000007, + 0x0000022a,0x000000c3,0x0000003a,0x0004003d,0x00000006,0x0000022b,0x0000022a,0x00050041, + 0x00000007,0x0000022c,0x000000c3,0x00000069,0x0004003d,0x00000006,0x0000022d,0x0000022c, + 0x0007000c,0x00000006,0x0000022e,0x00000001,0x00000028,0x0000022b,0x0000022d,0x00050041, + 0x00000007,0x0000022f,0x000000e8,0x00000031,0x0004003d,0x00000006,0x00000230,0x0000022f, + 0x00050041,0x00000007,0x00000231,0x000000e8,0x0000006e,0x0004003d,0x00000006,0x00000232, + 0x00000231,0x0007000c,0x00000006,0x00000233,0x00000001,0x00000028,0x00000230,0x00000232, + 0x0007000c,0x00000006,0x00000234,0x00000001,0x00000028,0x0000022e,0x00000233,0x0003003e, + 0x00000229,0x00000234,0x00050041,0x00000007,0x00000236,0x000000c3,0x0000003a,0x0004003d, + 0x00000006,0x00000237,0x00000236,0x00050041,0x00000007,0x00000238,0x000000c3,0x00000069, + 0x0004003d,0x00000006,0x00000239,0x00000238,0x0007000c,0x00000006,0x0000023a,0x00000001, + 0x00000025,0x00000237,0x00000239,0x00050041,0x00000007,0x0000023b,0x000000e8,0x00000031, + 0x0004003d,0x00000006,0x0000023c,0x0000023b,0x00050041,0x00000007,0x0000023d,0x000000e8, + 0x0000006e,0x0004003d,0x00000006,0x0000023e,0x0000023d,0x0007000c,0x00000006,0x0000023f, + 0x00000001,0x00000025,0x0000023c,0x0000023e,0x0007000c,0x00000006,0x00000240,0x00000001, + 0x00000025,0x0000023a,0x0000023f,0x0003003e,0x00000235,0x00000240,0x00050041,0x00000242, + 0x00000243,0x00000094,0x00000241,0x0004003d,0x00000006,0x00000244,0x00000243,0x0004003d, + 0x00000006,0x00000245,0x00000223,0x00050085,0x00000006,0x00000246,0x00000244,0x00000245, + 0x0004003d,0x00000006,0x00000247,0x00000235,0x0004003d,0x00000006,0x00000248,0x00000229, + 0x0008000c,0x00000006,0x00000249,0x00000001,0x0000002b,0x00000246,0x00000247,0x00000248, + 0x0003003e,0x00000223,0x00000249,0x0004003d,0x00000006,0x0000024b,0x00000223,0x00050041, + 0x00000007,0x0000024c,0x0000009e,0x0000006e,0x0004003d,0x00000006,0x0000024d,0x0000024c, + 0x00050083,0x00000006,0x0000024e,0x0000024b,0x0000024d,0x0003003e,0x0000024a,0x0000024e, + 0x0004003d,0x00000006,0x0000024f,0x0000024a,0x0008000c,0x00000006,0x00000252,0x00000001, + 0x0000002b,0x0000024f,0x00000250,0x00000251,0x0003003e,0x0000024a,0x00000252,0x00050041, + 0x00000007,0x00000253,0x0000009e,0x00000031,0x0004003d,0x00000006,0x00000254,0x00000253, + 0x0004003d,0x00000006,0x00000255,0x0000024a,0x00050081,0x00000006,0x00000256,0x00000254, + 0x00000255,0x0008000c,0x00000006,0x00000257,0x00000001,0x0000002b,0x00000256,0x00000053, + 0x00000054,0x00050041,0x00000007,0x00000258,0x0000009e,0x00000031,0x0003003e,0x00000258, + 0x00000257,0x00050041,0x00000007,0x00000259,0x0000009e,0x0000003a,0x0004003d,0x00000006, + 0x0000025a,0x00000259,0x0004003d,0x00000006,0x0000025b,0x0000024a,0x00050081,0x00000006, + 0x0000025c,0x0000025a,0x0000025b,0x0008000c,0x00000006,0x0000025d,0x00000001,0x0000002b, + 0x0000025c,0x00000053,0x00000054,0x00050041,0x00000007,0x0000025e,0x0000009e,0x0000003a, + 0x0003003e,0x0000025e,0x0000025d,0x00050041,0x00000007,0x0000025f,0x0000009e,0x00000069, + 0x0004003d,0x00000006,0x00000260,0x0000025f,0x0004003d,0x00000006,0x00000261,0x0000024a, + 0x00050081,0x00000006,0x00000262,0x00000260,0x00000261,0x0008000c,0x00000006,0x00000263, + 0x00000001,0x0000002b,0x00000262,0x00000053,0x00000054,0x00050041,0x00000007,0x00000264, + 0x0000009e,0x00000069,0x0003003e,0x00000264,0x00000263,0x000200f9,0x000000e1,0x000200f8, + 0x000000e1,0x00050041,0x00000007,0x00000265,0x0000009e,0x0000006e,0x0003003e,0x00000265, + 0x00000054,0x0004003d,0x00000016,0x00000268,0x0000009e,0x0003003e,0x00000267,0x00000268, + 0x000100fd,0x00010038,0x00050036,0x00000006,0x0000000a,0x00000000,0x00000008,0x00030037, + 0x00000007,0x00000009,0x000200f8,0x0000000b,0x0004003b,0x00000007,0x0000001d,0x00000007, + 0x0004003b,0x00000007,0x00000021,0x00000007,0x0004003d,0x00000006,0x0000001e,0x00000009, + 0x00050083,0x00000006,0x00000020,0x0000001e,0x0000001f,0x0003003e,0x0000001d,0x00000020, + 0x0004003d,0x00000006,0x00000022,0x00000009,0x0004003d,0x00000006,0x00000023,0x0000001d, + 0x00050085,0x00000006,0x00000024,0x00000022,0x00000023,0x0004003d,0x00000006,0x00000025, + 0x0000001d,0x00050083,0x00000006,0x00000026,0x00000024,0x00000025,0x0003003e,0x00000021, + 0x00000026,0x0004003d,0x00000006,0x00000027,0x0000001d,0x0004003d,0x00000006,0x00000028, + 0x0000001d,0x00050085,0x00000006,0x00000029,0x00000028,0x00000027,0x0003003e,0x0000001d, + 0x00000029,0x0004003d,0x00000006,0x0000002a,0x00000021,0x0004003d,0x00000006,0x0000002b, + 0x0000001d,0x00050085,0x00000006,0x0000002c,0x0000002a,0x0000002b,0x000200fe,0x0000002c, + 0x00010038,0x00050036,0x0000000e,0x00000014,0x00000000,0x0000000f,0x00030037,0x00000007, + 0x00000010,0x00030037,0x00000007,0x00000011,0x00030037,0x00000007,0x00000012,0x00030037, + 0x0000000d,0x00000013,0x000200f8,0x00000015,0x0004003b,0x00000007,0x0000002f,0x00000007, + 0x0004003b,0x00000034,0x00000035,0x00000007,0x0004003b,0x00000007,0x00000038,0x00000007, + 0x0004003b,0x00000007,0x00000043,0x00000007,0x0004003b,0x00000007,0x0000005b,0x00000007, + 0x0004003b,0x00000007,0x0000005c,0x00000007,0x00050041,0x00000007,0x00000032,0x00000013, + 0x00000031,0x0004003d,0x00000006,0x00000033,0x00000032,0x0003003e,0x0000002f,0x00000033, + 0x0004003d,0x0000000c,0x00000036,0x00000013,0x0007004f,0x0000000e,0x00000037,0x00000036, + 0x00000036,0x00000001,0x00000002,0x0003003e,0x00000035,0x00000037,0x0004003d,0x00000006, + 0x00000039,0x00000010,0x00050041,0x00000007,0x0000003b,0x00000035,0x0000003a,0x0004003d, + 0x00000006,0x0000003c,0x0000003b,0x00050085,0x00000006,0x0000003d,0x00000039,0x0000003c, + 0x0004003d,0x00000006,0x0000003e,0x00000011,0x00050041,0x00000007,0x0000003f,0x00000035, + 0x00000031,0x0004003d,0x00000006,0x00000040,0x0000003f,0x00050085,0x00000006,0x00000041, + 0x0000003e,0x00000040,0x00050081,0x00000006,0x00000042,0x0000003d,0x00000041,0x0003003e, + 0x00000038,0x00000042,0x0004003d,0x00000006,0x00000044,0x00000010,0x0004003d,0x00000006, + 0x00000045,0x00000010,0x00050085,0x00000006,0x00000046,0x00000044,0x00000045,0x0004003d, + 0x00000006,0x00000047,0x00000011,0x0004003d,0x00000006,0x00000048,0x00000011,0x00050085, + 0x00000006,0x00000049,0x00000047,0x00000048,0x00050081,0x00000006,0x0000004a,0x00000046, + 0x00000049,0x0004003d,0x00000006,0x0000004b,0x00000038,0x0004003d,0x00000006,0x0000004c, + 0x00000038,0x00050085,0x00000006,0x0000004d,0x0000004b,0x0000004c,0x0004003d,0x00000006, + 0x0000004e,0x00000012,0x0004003d,0x00000006,0x0000004f,0x00000012,0x00050085,0x00000006, + 0x00000050,0x0000004e,0x0000004f,0x0004003d,0x00000006,0x00000051,0x0000002f,0x00050085, + 0x00000006,0x00000052,0x00000050,0x00000051,0x0008000c,0x00000006,0x00000055,0x00000001, + 0x0000002b,0x00000052,0x00000053,0x00000054,0x00050085,0x00000006,0x00000057,0x00000055, + 0x00000056,0x00050083,0x00000006,0x00000058,0x00000057,0x00000054,0x00050085,0x00000006, + 0x00000059,0x0000004d,0x00000058,0x00050081,0x00000006,0x0000005a,0x0000004a,0x00000059, + 0x0003003e,0x00000043,0x0000005a,0x0004003d,0x00000006,0x0000005d,0x00000043,0x0003003e, + 0x0000005c,0x0000005d,0x00050039,0x00000006,0x0000005e,0x0000000a,0x0000005c,0x0003003e, + 0x0000005b,0x0000005e,0x0004003d,0x00000006,0x0000005f,0x0000005b,0x0004003d,0x00000006, + 0x00000060,0x0000005b,0x0004003d,0x00000006,0x00000061,0x00000012,0x00050085,0x00000006, + 0x00000062,0x00000060,0x00000061,0x00050050,0x0000000e,0x00000063,0x0000005f,0x00000062, + 0x000200fe,0x00000063,0x00010038,0x00050036,0x0000000e,0x0000001b,0x00000000,0x00000018, + 0x00030037,0x00000017,0x00000019,0x00030037,0x00000017,0x0000001a,0x000200f8,0x0000001c, + 0x0004003b,0x00000007,0x00000066,0x00000007,0x0004003b,0x00000007,0x0000006d,0x00000007, + 0x0004003b,0x00000034,0x00000074,0x00000007,0x0004003b,0x00000007,0x0000007d,0x00000007, + 0x00050041,0x00000007,0x00000067,0x0000001a,0x00000031,0x0004003d,0x00000006,0x00000068, + 0x00000067,0x00050041,0x00000007,0x0000006a,0x00000019,0x00000069,0x0004003d,0x00000006, + 0x0000006b,0x0000006a,0x00050083,0x00000006,0x0000006c,0x00000068,0x0000006b,0x0003003e, + 0x00000066,0x0000006c,0x00050041,0x00000007,0x0000006f,0x0000001a,0x0000006e,0x0004003d, + 0x00000006,0x00000070,0x0000006f,0x00050041,0x00000007,0x00000071,0x00000019,0x0000003a, + 0x0004003d,0x00000006,0x00000072,0x00000071,0x00050083,0x00000006,0x00000073,0x00000070, + 0x00000072,0x0003003e,0x0000006d,0x00000073,0x0004003d,0x00000006,0x00000075,0x00000066, + 0x0004003d,0x00000006,0x00000076,0x0000006d,0x00050081,0x00000006,0x00000077,0x00000075, + 0x00000076,0x00050041,0x00000007,0x00000078,0x00000074,0x00000031,0x0003003e,0x00000078, + 0x00000077,0x0004003d,0x00000006,0x00000079,0x00000066,0x0004003d,0x00000006,0x0000007a, + 0x0000006d,0x00050083,0x00000006,0x0000007b,0x00000079,0x0000007a,0x00050041,0x00000007, + 0x0000007c,0x00000074,0x0000003a,0x0003003e,0x0000007c,0x0000007b,0x00050041,0x00000007, + 0x0000007e,0x00000074,0x00000031,0x0004003d,0x00000006,0x0000007f,0x0000007e,0x00050041, + 0x00000007,0x00000080,0x00000074,0x00000031,0x0004003d,0x00000006,0x00000081,0x00000080, + 0x00050085,0x00000006,0x00000082,0x0000007f,0x00000081,0x00050081,0x00000006,0x00000084, + 0x00000082,0x00000083,0x00050041,0x00000007,0x00000085,0x00000074,0x0000003a,0x0004003d, + 0x00000006,0x00000086,0x00000085,0x00050041,0x00000007,0x00000087,0x00000074,0x0000003a, + 0x0004003d,0x00000006,0x00000088,0x00000087,0x00050085,0x00000006,0x00000089,0x00000086, + 0x00000088,0x00050081,0x00000006,0x0000008a,0x00000084,0x00000089,0x0006000c,0x00000006, + 0x0000008b,0x00000001,0x00000020,0x0000008a,0x0003003e,0x0000007d,0x0000008b,0x0004003d, + 0x0000000e,0x0000008c,0x00000074,0x0004003d,0x00000006,0x0000008d,0x0000007d,0x0005008e, + 0x0000000e,0x0000008e,0x0000008c,0x0000008d,0x000200fe,0x0000008e,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/toon_frag.h b/app/src/main/cpp/shaders/toon_frag.h new file mode 100644 index 0000000000..aa54788ff8 --- /dev/null +++ b/app/src/main/cpp/shaders/toon_frag.h @@ -0,0 +1,90 @@ + // 1116.2.0 + #pragma once +const uint32_t toon_code[] = { + 0x07230203,0x00010000,0x0008000b,0x0000006d,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x00000067,0x00030010, + 0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d, + 0x00000000,0x00030005,0x00000009,0x00007675,0x00060005,0x0000000b,0x67617266,0x43786554, + 0x64726f6f,0x00000000,0x00060005,0x0000000e,0x65676465,0x65726854,0x6c6f6873,0x00000064, + 0x00040005,0x00000010,0x7366666f,0x00007465,0x00030005,0x00000014,0x00004350,0x00040006, + 0x00000014,0x00000000,0x0063646e,0x00060006,0x00000014,0x00000001,0x6f736572,0x6974756c, + 0x00006e6f,0x00030005,0x00000016,0x00006370,0x00050005,0x0000001f,0x6f6c6f63,0x6e654372, + 0x00726574,0x00060005,0x00000023,0x75706e49,0x78655474,0x65727574,0x00000000,0x00050005, + 0x00000028,0x6f6c6f63,0x66654c72,0x00000074,0x00050005,0x00000034,0x6f6c6f63,0x67695272, + 0x00007468,0x00040005,0x0000003d,0x6f6c6f63,0x00705572,0x00050005,0x00000047,0x6f6c6f63, + 0x776f4472,0x0000006e,0x00060005,0x00000050,0x66666964,0x69726f48,0x746e6f7a,0x00006c61, + 0x00060005,0x00000055,0x66666964,0x74726556,0x6c616369,0x00000000,0x00050005,0x0000005a, + 0x65676465,0x74636146,0x0000726f,0x00060005,0x00000060,0x6c74756f,0x43656e69,0x726f6c6f, + 0x00000000,0x00050005,0x00000067,0x4374756f,0x726f6c6f,0x00000000,0x00040047,0x0000000b, + 0x0000001e,0x00000000,0x00030047,0x00000014,0x00000002,0x00050048,0x00000014,0x00000000, + 0x00000023,0x00000000,0x00050048,0x00000014,0x00000001,0x00000023,0x00000010,0x00040047, + 0x00000023,0x00000021,0x00000000,0x00040047,0x00000023,0x00000022,0x00000000,0x00040047, + 0x00000067,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002, + 0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000002,0x00040020, + 0x00000008,0x00000007,0x00000007,0x00040020,0x0000000a,0x00000001,0x00000007,0x0004003b, + 0x0000000a,0x0000000b,0x00000001,0x00040020,0x0000000d,0x00000007,0x00000006,0x0004002b, + 0x00000006,0x0000000f,0x3e4ccccd,0x0004002b,0x00000006,0x00000011,0x3f800000,0x0005002c, + 0x00000007,0x00000012,0x00000011,0x00000011,0x00040017,0x00000013,0x00000006,0x00000004, + 0x0004001e,0x00000014,0x00000013,0x00000007,0x00040020,0x00000015,0x00000009,0x00000014, + 0x0004003b,0x00000015,0x00000016,0x00000009,0x00040015,0x00000017,0x00000020,0x00000001, + 0x0004002b,0x00000017,0x00000018,0x00000001,0x00040020,0x00000019,0x00000009,0x00000007, + 0x00040017,0x0000001d,0x00000006,0x00000003,0x00040020,0x0000001e,0x00000007,0x0000001d, + 0x00090019,0x00000020,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,0x00000001, + 0x00000000,0x0003001b,0x00000021,0x00000020,0x00040020,0x00000022,0x00000000,0x00000021, + 0x0004003b,0x00000022,0x00000023,0x00000000,0x00040015,0x0000002b,0x00000020,0x00000000, + 0x0004002b,0x0000002b,0x0000002c,0x00000000,0x0004002b,0x00000006,0x0000002f,0x00000000, + 0x0004002b,0x0000002b,0x00000040,0x00000001,0x0006002c,0x0000001d,0x00000062,0x0000002f, + 0x0000002f,0x0000002f,0x00040020,0x00000066,0x00000003,0x00000013,0x0004003b,0x00000066, + 0x00000067,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8, + 0x00000005,0x0004003b,0x00000008,0x00000009,0x00000007,0x0004003b,0x0000000d,0x0000000e, + 0x00000007,0x0004003b,0x00000008,0x00000010,0x00000007,0x0004003b,0x0000001e,0x0000001f, + 0x00000007,0x0004003b,0x0000001e,0x00000028,0x00000007,0x0004003b,0x0000001e,0x00000034, + 0x00000007,0x0004003b,0x0000001e,0x0000003d,0x00000007,0x0004003b,0x0000001e,0x00000047, + 0x00000007,0x0004003b,0x0000000d,0x00000050,0x00000007,0x0004003b,0x0000000d,0x00000055, + 0x00000007,0x0004003b,0x0000000d,0x0000005a,0x00000007,0x0004003b,0x0000001e,0x00000060, + 0x00000007,0x0004003d,0x00000007,0x0000000c,0x0000000b,0x0003003e,0x00000009,0x0000000c, + 0x0003003e,0x0000000e,0x0000000f,0x00050041,0x00000019,0x0000001a,0x00000016,0x00000018, + 0x0004003d,0x00000007,0x0000001b,0x0000001a,0x00050088,0x00000007,0x0000001c,0x00000012, + 0x0000001b,0x0003003e,0x00000010,0x0000001c,0x0004003d,0x00000021,0x00000024,0x00000023, + 0x0004003d,0x00000007,0x00000025,0x00000009,0x00050057,0x00000013,0x00000026,0x00000024, + 0x00000025,0x0008004f,0x0000001d,0x00000027,0x00000026,0x00000026,0x00000000,0x00000001, + 0x00000002,0x0003003e,0x0000001f,0x00000027,0x0004003d,0x00000021,0x00000029,0x00000023, + 0x0004003d,0x00000007,0x0000002a,0x00000009,0x00050041,0x0000000d,0x0000002d,0x00000010, + 0x0000002c,0x0004003d,0x00000006,0x0000002e,0x0000002d,0x00050050,0x00000007,0x00000030, + 0x0000002e,0x0000002f,0x00050083,0x00000007,0x00000031,0x0000002a,0x00000030,0x00050057, + 0x00000013,0x00000032,0x00000029,0x00000031,0x0008004f,0x0000001d,0x00000033,0x00000032, + 0x00000032,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000028,0x00000033,0x0004003d, + 0x00000021,0x00000035,0x00000023,0x0004003d,0x00000007,0x00000036,0x00000009,0x00050041, + 0x0000000d,0x00000037,0x00000010,0x0000002c,0x0004003d,0x00000006,0x00000038,0x00000037, + 0x00050050,0x00000007,0x00000039,0x00000038,0x0000002f,0x00050081,0x00000007,0x0000003a, + 0x00000036,0x00000039,0x00050057,0x00000013,0x0000003b,0x00000035,0x0000003a,0x0008004f, + 0x0000001d,0x0000003c,0x0000003b,0x0000003b,0x00000000,0x00000001,0x00000002,0x0003003e, + 0x00000034,0x0000003c,0x0004003d,0x00000021,0x0000003e,0x00000023,0x0004003d,0x00000007, + 0x0000003f,0x00000009,0x00050041,0x0000000d,0x00000041,0x00000010,0x00000040,0x0004003d, + 0x00000006,0x00000042,0x00000041,0x00050050,0x00000007,0x00000043,0x0000002f,0x00000042, + 0x00050083,0x00000007,0x00000044,0x0000003f,0x00000043,0x00050057,0x00000013,0x00000045, + 0x0000003e,0x00000044,0x0008004f,0x0000001d,0x00000046,0x00000045,0x00000045,0x00000000, + 0x00000001,0x00000002,0x0003003e,0x0000003d,0x00000046,0x0004003d,0x00000021,0x00000048, + 0x00000023,0x0004003d,0x00000007,0x00000049,0x00000009,0x00050041,0x0000000d,0x0000004a, + 0x00000010,0x00000040,0x0004003d,0x00000006,0x0000004b,0x0000004a,0x00050050,0x00000007, + 0x0000004c,0x0000002f,0x0000004b,0x00050081,0x00000007,0x0000004d,0x00000049,0x0000004c, + 0x00050057,0x00000013,0x0000004e,0x00000048,0x0000004d,0x0008004f,0x0000001d,0x0000004f, + 0x0000004e,0x0000004e,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000047,0x0000004f, + 0x0004003d,0x0000001d,0x00000051,0x00000034,0x0004003d,0x0000001d,0x00000052,0x00000028, + 0x00050083,0x0000001d,0x00000053,0x00000051,0x00000052,0x0006000c,0x00000006,0x00000054, + 0x00000001,0x00000042,0x00000053,0x0003003e,0x00000050,0x00000054,0x0004003d,0x0000001d, + 0x00000056,0x0000003d,0x0004003d,0x0000001d,0x00000057,0x00000047,0x00050083,0x0000001d, + 0x00000058,0x00000056,0x00000057,0x0006000c,0x00000006,0x00000059,0x00000001,0x00000042, + 0x00000058,0x0003003e,0x00000055,0x00000059,0x0004003d,0x00000006,0x0000005b,0x0000000e, + 0x0004003d,0x00000006,0x0000005c,0x00000050,0x0004003d,0x00000006,0x0000005d,0x00000055, + 0x00050081,0x00000006,0x0000005e,0x0000005c,0x0000005d,0x0007000c,0x00000006,0x0000005f, + 0x00000001,0x00000030,0x0000005b,0x0000005e,0x0003003e,0x0000005a,0x0000005f,0x0004003d, + 0x0000001d,0x00000061,0x0000001f,0x0004003d,0x00000006,0x00000063,0x0000005a,0x00060050, + 0x0000001d,0x00000064,0x00000063,0x00000063,0x00000063,0x0008000c,0x0000001d,0x00000065, + 0x00000001,0x0000002e,0x00000061,0x00000062,0x00000064,0x0003003e,0x00000060,0x00000065, + 0x0004003d,0x0000001d,0x00000068,0x00000060,0x00050051,0x00000006,0x00000069,0x00000068, + 0x00000000,0x00050051,0x00000006,0x0000006a,0x00000068,0x00000001,0x00050051,0x00000006, + 0x0000006b,0x00000068,0x00000002,0x00070050,0x00000013,0x0000006c,0x00000069,0x0000006a, + 0x0000006b,0x00000011,0x0003003e,0x00000067,0x0000006c,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/shaders/upscale_vert.h b/app/src/main/cpp/shaders/upscale_vert.h new file mode 100644 index 0000000000..c64f91729d --- /dev/null +++ b/app/src/main/cpp/shaders/upscale_vert.h @@ -0,0 +1,65 @@ + // 1116.2.0 + #pragma once +const uint32_t upscale_vert_code[] = { + 0x07230203,0x00010000,0x0008000b,0x0000004b,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0008000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000a,0x0000003b,0x00000045, + 0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,0x00000000,0x00030005, + 0x00000008,0x00006978,0x00060005,0x0000000a,0x565f6c67,0x65747265,0x646e4978,0x00007865, + 0x00030005,0x0000000f,0x00006979,0x00030005,0x00000014,0x00000078,0x00030005,0x0000001c, + 0x00004350,0x00040006,0x0000001c,0x00000000,0x0063646e,0x00030005,0x0000001e,0x00006370, + 0x00030005,0x0000002a,0x00000079,0x00060005,0x00000039,0x505f6c67,0x65567265,0x78657472, + 0x00000000,0x00060006,0x00000039,0x00000000,0x505f6c67,0x7469736f,0x006e6f69,0x00070006, + 0x00000039,0x00000001,0x505f6c67,0x746e696f,0x657a6953,0x00000000,0x00070006,0x00000039, + 0x00000002,0x435f6c67,0x4470696c,0x61747369,0x0065636e,0x00070006,0x00000039,0x00000003, + 0x435f6c67,0x446c6c75,0x61747369,0x0065636e,0x00030005,0x0000003b,0x00000000,0x00060005, + 0x00000045,0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040047,0x0000000a,0x0000000b, + 0x0000002a,0x00030047,0x0000001c,0x00000002,0x00050048,0x0000001c,0x00000000,0x00000023, + 0x00000000,0x00030047,0x00000039,0x00000002,0x00050048,0x00000039,0x00000000,0x0000000b, + 0x00000000,0x00050048,0x00000039,0x00000001,0x0000000b,0x00000001,0x00050048,0x00000039, + 0x00000002,0x0000000b,0x00000003,0x00050048,0x00000039,0x00000003,0x0000000b,0x00000004, + 0x00040047,0x00000045,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003, + 0x00000002,0x00040015,0x00000006,0x00000020,0x00000001,0x00040020,0x00000007,0x00000007, + 0x00000006,0x00040020,0x00000009,0x00000001,0x00000006,0x0004003b,0x00000009,0x0000000a, + 0x00000001,0x0004002b,0x00000006,0x0000000c,0x00000001,0x00030016,0x00000012,0x00000020, + 0x00040020,0x00000013,0x00000007,0x00000012,0x00020014,0x00000016,0x00040017,0x0000001b, + 0x00000012,0x00000004,0x0003001e,0x0000001c,0x0000001b,0x00040020,0x0000001d,0x00000009, + 0x0000001c,0x0004003b,0x0000001d,0x0000001e,0x00000009,0x0004002b,0x00000006,0x0000001f, + 0x00000000,0x00040015,0x00000020,0x00000020,0x00000000,0x0004002b,0x00000020,0x00000021, + 0x00000002,0x00040020,0x00000022,0x00000009,0x00000012,0x0004002b,0x00000020,0x00000026, + 0x00000000,0x0004002b,0x00000020,0x00000030,0x00000003,0x0004002b,0x00000020,0x00000034, + 0x00000001,0x0004001c,0x00000038,0x00000012,0x00000034,0x0006001e,0x00000039,0x0000001b, + 0x00000012,0x00000038,0x00000038,0x00040020,0x0000003a,0x00000003,0x00000039,0x0004003b, + 0x0000003a,0x0000003b,0x00000003,0x0004002b,0x00000012,0x0000003e,0x00000000,0x0004002b, + 0x00000012,0x0000003f,0x3f800000,0x00040020,0x00000041,0x00000003,0x0000001b,0x00040017, + 0x00000043,0x00000012,0x00000002,0x00040020,0x00000044,0x00000003,0x00000043,0x0004003b, + 0x00000044,0x00000045,0x00000003,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003, + 0x000200f8,0x00000005,0x0004003b,0x00000007,0x00000008,0x00000007,0x0004003b,0x00000007, + 0x0000000f,0x00000007,0x0004003b,0x00000013,0x00000014,0x00000007,0x0004003b,0x00000013, + 0x00000018,0x00000007,0x0004003b,0x00000013,0x0000002a,0x00000007,0x0004003b,0x00000013, + 0x0000002d,0x00000007,0x0004003d,0x00000006,0x0000000b,0x0000000a,0x000500c3,0x00000006, + 0x0000000d,0x0000000b,0x0000000c,0x000500c7,0x00000006,0x0000000e,0x0000000d,0x0000000c, + 0x0003003e,0x00000008,0x0000000e,0x0004003d,0x00000006,0x00000010,0x0000000a,0x000500c7, + 0x00000006,0x00000011,0x00000010,0x0000000c,0x0003003e,0x0000000f,0x00000011,0x0004003d, + 0x00000006,0x00000015,0x00000008,0x000500aa,0x00000016,0x00000017,0x00000015,0x0000000c, + 0x000300f7,0x0000001a,0x00000000,0x000400fa,0x00000017,0x00000019,0x00000025,0x000200f8, + 0x00000019,0x00060041,0x00000022,0x00000023,0x0000001e,0x0000001f,0x00000021,0x0004003d, + 0x00000012,0x00000024,0x00000023,0x0003003e,0x00000018,0x00000024,0x000200f9,0x0000001a, + 0x000200f8,0x00000025,0x00060041,0x00000022,0x00000027,0x0000001e,0x0000001f,0x00000026, + 0x0004003d,0x00000012,0x00000028,0x00000027,0x0003003e,0x00000018,0x00000028,0x000200f9, + 0x0000001a,0x000200f8,0x0000001a,0x0004003d,0x00000012,0x00000029,0x00000018,0x0003003e, + 0x00000014,0x00000029,0x0004003d,0x00000006,0x0000002b,0x0000000f,0x000500aa,0x00000016, + 0x0000002c,0x0000002b,0x0000000c,0x000300f7,0x0000002f,0x00000000,0x000400fa,0x0000002c, + 0x0000002e,0x00000033,0x000200f8,0x0000002e,0x00060041,0x00000022,0x00000031,0x0000001e, + 0x0000001f,0x00000030,0x0004003d,0x00000012,0x00000032,0x00000031,0x0003003e,0x0000002d, + 0x00000032,0x000200f9,0x0000002f,0x000200f8,0x00000033,0x00060041,0x00000022,0x00000035, + 0x0000001e,0x0000001f,0x00000034,0x0004003d,0x00000012,0x00000036,0x00000035,0x0003003e, + 0x0000002d,0x00000036,0x000200f9,0x0000002f,0x000200f8,0x0000002f,0x0004003d,0x00000012, + 0x00000037,0x0000002d,0x0003003e,0x0000002a,0x00000037,0x0004003d,0x00000012,0x0000003c, + 0x00000014,0x0004003d,0x00000012,0x0000003d,0x0000002a,0x00070050,0x0000001b,0x00000040, + 0x0000003c,0x0000003d,0x0000003e,0x0000003f,0x00050041,0x00000041,0x00000042,0x0000003b, + 0x0000001f,0x0003003e,0x00000042,0x00000040,0x0004003d,0x00000006,0x00000046,0x00000008, + 0x0004006f,0x00000012,0x00000047,0x00000046,0x0004003d,0x00000006,0x00000048,0x0000000f, + 0x0004006f,0x00000012,0x00000049,0x00000048,0x00050050,0x00000043,0x0000004a,0x00000047, + 0x00000049,0x0003003e,0x00000045,0x0000004a,0x000100fd,0x00010038 +}; diff --git a/app/src/main/cpp/waylandcomp/CMakeLists.txt b/app/src/main/cpp/waylandcomp/CMakeLists.txt new file mode 100644 index 0000000000..1f20d2c11e --- /dev/null +++ b/app/src/main/cpp/waylandcomp/CMakeLists.txt @@ -0,0 +1,105 @@ +# ── Embedded Wayland compositor (experimental parallel runtime) ────────────── +# Runs a libwayland-server compositor in-process so games launched via Wine's +# winewayland.drv can present into it. Protocol glue is pre-generated in +# generated/ (no host wayland-scanner needed at app build time). Built by the app +# (add_subdirectory from ../CMakeLists.txt) and on its own by standalone/ for +# build-waylandcomp.yml. +add_library(bannerwayland SHARED + src/compositor.c + src/vk_present.c + src/effects_chain.c + src/vk_loader.c + src/sc_layer.c + src/ahb_swapchain.c + src/waylandcomp_jni.c + src/banner_ext.c + src/wl_clipboard.c + src/wl_text_input.c + src/wl_toplevel_icon.c + src/wl_color_mgmt.c + src/hdr_compose.c + generated/color-management-v1-protocol.c + generated/xdg-shell-protocol.c + generated/linux-dmabuf-v1-protocol.c + generated/viewporter-protocol.c + generated/banner-desktop-v1-protocol.c + generated/presentation-time-protocol.c + generated/pointer-constraints-unstable-v1-protocol.c + generated/relative-pointer-unstable-v1-protocol.c + generated/wlr-data-control-unstable-v1-protocol.c + generated/text-input-unstable-v3-protocol.c + generated/xdg-toplevel-icon-v1-protocol.c + generated/banner-ahb-v1-protocol.c + src/framegen_bridge.c + src/framegen_jni.c +) +target_include_directories(bannerwayland PRIVATE + generated + prebuilt/include + src + # The X11 Vulkan renderer's committed SPIR-V headers (*_frag.h / upscale_vert.h, made by + # winlator/gen_shaders.sh): the screen-effect chain (src/effects_chain.c) runs the same bytes. + ${CMAKE_CURRENT_SOURCE_DIR}/../shaders +) + +# ── Frame generation (feat/wayland-framegen) ───────────────────────────────── +# The two native engines the X11 renderer runs (LSFG Native: winlator/lsfg, Win-FG Native: +# winlator/winfg) are compiled into this library unmodified and driven by +# src/framegen_engine.cpp through the compositor's own Turnip entry points. They need the +# winlator tree and the vendored DXBC translator (thirdparty/dxbc, for the LSFG cache format), +# which only the app build has: the standalone build (standalone/) gets the stub, which reports +# every engine unavailable and generates nothing. +set(BANNER_FRAMEGEN_LSFG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../winlator/lsfg) +set(BANNER_FRAMEGEN_WINFG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../winlator/winfg) +if (TARGET dxbc AND EXISTS ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp + AND EXISTS ${BANNER_FRAMEGEN_WINFG_DIR}/winfg_engine.cpp) + message(STATUS "bannerwayland: frame-generation engines built in (LSFG Native, Win-FG Native)") + target_sources(bannerwayland PRIVATE + src/framegen_engine.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_probe.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_dll.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_dxbc.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_vkd.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_common.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_shaders.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_mipmaps.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_alpha.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_beta.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_gamma.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_delta.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_generate.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_chain.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_pacer.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_engine.cpp + ${BANNER_FRAMEGEN_LSFG_DIR}/lsfg_governor.cpp + ${BANNER_FRAMEGEN_WINFG_DIR}/framegen.cpp + ${BANNER_FRAMEGEN_WINFG_DIR}/winfg_vkd.cpp + ${BANNER_FRAMEGEN_WINFG_DIR}/winfg_engine.cpp + ) + target_include_directories(bannerwayland PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/.. # as the winlator target sees it + ${CMAKE_CURRENT_SOURCE_DIR}/../winlator # VulkanRendererContext.h (VkTable), lsfg/, winfg/ + ) + target_compile_options(bannerwayland PRIVATE + $<$:-std=c++17 -fvisibility=hidden>) + target_compile_definitions(bannerwayland PRIVATE + WINFG_UPSTREAM="${WINFG_UPSTREAM}" + WINFG_CHAIN_HASH="${WINFG_CHAIN_HASH}" + ) + target_link_libraries(bannerwayland dxbc atomic) +else() + message(STATUS "bannerwayland: frame-generation engines NOT built in (standalone build): stub") + target_sources(bannerwayland PRIVATE src/framegen_engine_stub.c) +endif() +add_library(wayland-server SHARED IMPORTED) +set_target_properties(wayland-server PROPERTIES IMPORTED_LOCATION + ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt/lib/libwayland-server.so) +# Vulkan is loaded at runtime via adrenotools (Turnip), not linked directly — so the +# compositor uses Turnip's driver, which supports dmabuf import (drm_format_modifier). +target_link_libraries(bannerwayland + wayland-server + adrenotools + dl + log + android +) diff --git a/app/src/main/cpp/waylandcomp/HDR_RECON.md b/app/src/main/cpp/waylandcomp/HDR_RECON.md new file mode 100644 index 0000000000..f30a4b8995 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/HDR_RECON.md @@ -0,0 +1,910 @@ +# HDR on the Wayland backend — reconnaissance + +> **2026-09-14: round 1 of Phase A is built** (branch `feat/wayland-hdr`, opt-in, testing only) — +> see **§10** at the end for what was built, how it is gated and how a tester's log proves it. +> The recon below is kept as written. + +Written 2026-09-13. **Recon only: no product code was changed, nothing was built, nothing was +installed on the device.** Branch surveyed: app `feat/wayland-phase2`, proton-wine +`feat/winewayland-desktop-11.0-2`, Banners-Turnip `wayland` (Mesa `7cda7850`, v26.3.0). +Device reads are `dumpsys` / `getprop` / `strings` only. + +Companion docs: `ZERO_COPY_SPIKE.md` (buffer path), `WAYLAND_RUNTIME.md`. + +--- + +## 0. Answer in one paragraph + +**The game half of HDR is already shipping and nobody noticed.** The Wayland Turnip inside +wcp v6 (`Proton-11.0-2.1-arm64ec-6/lib/libvulkan_freedreno_wayland.so`, verified on the device) +already contains Mesa's full `wp_color_manager_v1` client implementation and advertises +`VK_EXT_swapchain_colorspace` + `VK_EXT_hdr_metadata`; the shipping DXVK v3.1-gplasync already +carries `dxgi.enableHDR` / `DXVK_HDR` and the `VK_COLOR_SPACE_HDR10_ST2084_EXT` path; +`winewayland.drv` is a transparent 121-line shim that neither adds nor removes colour +information. **Everything that is missing is in our compositor**, which advertises no colour +protocol, offers only four 8-bit DRM formats over `zwp_linux_dmabuf_v1`, takes +`surfaceFormats[0]` for its own swapchain, runs an 8-bit scene/effects chain, and never calls +`ASurfaceTransaction_setBufferDataSpace`. The work is therefore **app-side only** — the memory +note in `project_bannerlator_wayland_phase4` that HDR "does need a new wcp" is **wrong for the +HDR10 (10-bit PQ) path**; a new wcp is only needed for scRGB/FP16 zero-copy. Estimated +**4–6 engineer-days** to a plumbed, log-verifiable HDR10 path. But the Pocket FIT's panel +reports `supportedHdrTypes=[]`, `supportedColorModes=[0]` (NATIVE only), `hdrSdrRatio +not_available` and `displayBrightnessNits=-1`, so **nothing of it can be seen on this device**, +and turning it on there would actively *cost* us the zero-copy DEVICE-composition win. Verdict +in §8: **not now.** + +--- + +## 1. Game side — how far an HDR request gets today + +### 1.1 What a Windows game does + +| Call | Where it lands in DXVK | Notes | +|---|---|---| +| `IDXGIOutput6::GetDesc1` → `DXGI_OUTPUT_DESC1::ColorSpace` | `src/dxgi/dxgi_output.cpp:220-259` | **Never queries Vulkan.** Reports `RGB_FULL_G2084_NONE_P2020` purely because `dxgi.enableHDR` is on. | +| `IDXGISwapChain3::CheckColorSpaceSupport` | `src/dxgi/dxgi_swapchain.cpp:655-667` | This *is* backed by Vulkan (below). Note it is a swapchain method, not a factory method. | +| `IDXGISwapChain3::SetColorSpace1` | `dxgi_swapchain.cpp:672-688` → `d3d11_swapchain.cpp:306-331` → `Presenter::supportsColorSpace` (`dxvk_presenter.cpp:319-343`) | Returns `E_INVALIDARG` if the Vulkan surface does not list the colour space. | +| `IDXGISwapChain4::SetHDRMetaData` | `dxgi_swapchain.cpp:690-717` → `vkSetHdrMetadataEXT` | Only `DXGI_HDR_METADATA_TYPE_HDR10`. Silently dropped if `VK_EXT_hdr_metadata` is absent (`dxvk_presenter.cpp:143-149`). | + +DXGI→Vulkan mapping (`src/d3d11/d3d11_swapchain.cpp:21-28`): + +``` +DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 -> VK_COLOR_SPACE_HDR10_ST2084_EXT +DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 -> VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT (scRGB) +DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 -> VK_COLOR_SPACE_SRGB_NONLINEAR_KHR +``` + +Swapchain formats DXVK will accept per colour space (`Presenter::pickFormat`, +`dxvk_presenter.cpp:1043-1081`): + +* `HDR10_ST2084` → `A2R10G10B10_UNORM_PACK32`, `A2B10G10R10_UNORM_PACK32`, + `E5B9G9R9_UFLOAT_PACK32`, `R16G16B16A16_UNORM`, `R16G16B16A16_SFLOAT` +* `EXTENDED_SRGB_LINEAR` (scRGB) → **`R16G16B16A16_SFLOAT` only** + +`VK_EXT_hdr_metadata` is optional in both DXVK and vkd3d-proton. `VK_EXT_swapchain_colorspace` +is *not* requested as an instance extension by DXVK's win32 WSI — it simply trusts the driver to +report the extra `VkColorSpaceKHR` values from `vkGetPhysicalDeviceSurfaceFormatsKHR`. Mesa's +Wayland WSI does exactly that (§2.3), so this is not a problem for us. + +**vkd3d-proton (D3D12)** ships its own swapchain (`libs/vkd3d/swapchain.c`), same colour-space +mapping (`convert_color_space`, :1717-1730), but **no fallback table**: if the requested +HDR colour space is not in `vkGetPhysicalDeviceSurfaceFormatsKHR`, `dxgi_vk_swap_chain_select_format` +(:1773-1791) returns `false` with the comment *"Refuse to present unsupported HDR since it will +look completely bogus"*, and the caller skips swapchain recreation for that cycle. A D3D12 game +that force-sets HDR without checking can therefore **stall presentation** rather than degrade. +DXGI enumeration for D3D12 titles is still DXVK's `dxgi.dll`, so `DXVK_HDR` still drives +`DXGI_OUTPUT_DESC1`. + +**Verified in our shipped binaries** (device, `strings`): +`contents/DXVK/v3.1-gplasync-0/system32/dxgi.dll` contains `dxgi.enableHDR`, `DXVK_HDR`, +`VK_COLOR_SPACE_HDR10_ST2084_EXT`; `d3d11.dll`/`d3d9.dll`/`dxgi.dll` contain +`VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT`; `contents/VKD3D/3.1.0-wave64-relax-1/.../d3d12core.dll` +contains `VK_EXT_hdr_metadata`. Nothing needs rebuilding on the D3D side. + +Proton-level gating: GE's `proton` script maps `PROTON_ENABLE_HDR` / `PROTON_USE_HDR` to +`DXVK_HDR=1` and nothing else. For us that is one container env var — no launcher work. + +### 1.2 The failure mode today, exactly + +DXVK's `DXGI_OUTPUT_DESC1` will claim HDR10 as soon as `DXVK_HDR=1`, regardless of Vulkan. +`SetColorSpace1` then fails with `E_INVALIDARG` because our compositor advertises no colour +management, so Mesa lists only `SRGB_NONLINEAR` + `PASS_THROUGH` (§2.3). Well-behaved games fall +back to SDR. Games that trust `GetDesc1` without checking `CheckColorSpaceSupport` can render an +HDR-authored image into an SDR swapchain (washed out) — this is a pre-existing foot-gun, not +something we introduce. **Recommendation regardless of whether we do HDR: do not expose a +`DXVK_HDR` container toggle until the compositor answers truthfully**, or we invite exactly that +bug class. + +### 1.3 `winewayland.drv` — carries nothing for colour, and blocks nothing + +`/home/claude-user/proton-wine-wayland2-wt/dlls/winewayland.drv/vulkan.c` is 121 lines: +`wayland_vulkan_surface_create` wraps the `wl_surface` in a `VkSurfaceKHR`, +`wayland_map_instance_extensions` aliases `VK_KHR_win32_surface` ⇄ `VK_KHR_wayland_surface`. +There is **no surface-format or colour-space filtering**, so whatever Mesa advertises reaches +DXVK unmodified. A grep for `color|colour|hdr|st2084|bt2020|gamut|10.?bit` across the whole +driver returns only GDI colour-bitmap helpers — nothing colorimetric. + +One real consequence: `wayland_output.c` publishes no EDID, and nothing in the tree writes the +`EDID` registry value `win32u/sysparams.c:815-818` reads. DXVK's +`src/wsi/win32/wsi_monitor_win32.cpp:288-361` therefore finds no EDID and falls back to its dummy +HDR luminances (`wsi_edid.h:38-56`: min 0.01 / max 1499 / maxFullFrame 799 nits). A game will +size its tonemapper for a 1499-nit display. Correctable later by synthesising an EDID in +`winewayland.drv` (that *would* need a new wcp), but not a blocker. + +### 1.4 Our bundled Turnip already speaks colour management — verified on the device + +``` +$ strings .../Proton/11.0-2.1-arm64ec-6/lib/libvulkan_freedreno_wayland.so +wp_color_manager_v1 PRESENT +wp_color_management_surface_v1 PRESENT +wp_image_description_creator_params_v1 PRESENT +banner_ahb_v1 PRESENT (our zero-copy patch) +VK_EXT_swapchain_colorspace PRESENT +VK_EXT_hdr_metadata PRESENT +``` + +The plain adrenotools driver the compositor itself loads +(`contents/adrenotools/Mesa Turnip v26.3.0-7cda785 (Android + Wayland)/libvulkan_freedreno.so`) +has the same colour-management symbols. Our own WSI patch is already aware of the protocol — +`patches/wayland/banner_ahb_wsi.py` anchors one of its edits on Mesa's +`if (display->color_manager) wp_color_manager_v1_destroy(...)` teardown line. + +**And the zero-copy patch already maps 10-bit to gralloc** — `banner_ahb_wsi.py:99-100, 225-237`: + +```c +#define BANNER_AHB_FORMAT_R8G8B8A8_UNORM 1u +#define BANNER_AHB_FORMAT_R10G10B10A2_UNORM 0x2bu /* AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM */ +... +case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return BANNER_AHB_FORMAT_R10G10B10A2_UNORM; +``` + +So a 10-bit HDR10 swapchain can already be gralloc-backed and go onto the display layer with the +**shipped** wcp. `VK_FORMAT_R16G16B16A16_SFLOAT` is *not* mapped, so `banner_ahb_skip_format` +(:239-242, applied at `:606-617`) hides FP16 surface formats whenever zero-copy is on — scRGB +zero-copy is the one thing that needs a driver change (one enum: `AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16`). + +### 1.5 X11 has no path — confirmed + +`app/src/main/cpp/winlator/VulkanRendererContext.cpp:439` hardcodes +`swapchainFmt = VK_FORMAT_R8G8B8A8_UNORM` and `:492` hardcodes +`imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR`. Upstream of that, the game presents through +`winex11.drv` into our pure-Java X11 server, which has no colour extension of any kind. HDR on X11 +would mean inventing a private X extension *and* teaching DXVK to use it. Correctly out of scope. + +--- + +## 2. Wayland side + +### 2.1 Protocol status + +`wp_color_management_v1` is **merged and stable-ish**: wayland-protocols MR !14, merged +2025-02-13, shipped in **wayland-protocols 1.41**, file +`staging/color-management/color-management-v1.xml`. Interfaces are at **version 3** upstream today +(v2 added `get_image_description`/`preferred_changed2`; v3 added `create_windows_bt2100` and the +`absolute_no_adaptation` intent). Predecessors: `zwp_linux_color_management_v1` → +`xx_color_management_v4` (the name most 2023–2025 shipping code targeted) → `wp_*` on landing. +`frog_color_management_v1` (Valve) is still vendored by gamescope alongside the real one and is +still functionally load-bearing on the Deck. + +Implementers: KWin (reference impl, most mature), Mutter (merged 2025-02-25 but still does not +advertise enough features for automatic HDR), wlroots 0.20 / Sway 1.12 (HDR10 on the Vulkan +renderer), gamescope (v1 semantics + frog), Weston (experimental, no tone mapping). +Proton-CachyOS's changelog notes that its `winewayland.drv` `windows_bt2100` path needs protocol +**v3** and that *"no compositor supports it yet"* — everybody is converged on **v1**. + +**We only need v1.** That is what Mesa binds. + +### 2.2 Minimum viable compositor subset + +At bind, on the `wp_color_manager_v1` global, send one event per supported item then `done`: + +* `supported_intent`: `perceptual` (mandatory anyway — it is all Mesa ever asks for) +* `supported_feature`: `parametric` (gates `create_parametric_creator`); optionally + `set_mastering_display_primaries`, and `extended_target_volume` **only if** we want scRGB +* `supported_primaries_named`: `bt2020` (HDR10), `srgb` (needed for scRGB and for Mesa's + "use a colour surface for sRGB too" branch), `display_p3` (wide gamut) +* `supported_tf_named`: `st2084_pq` (HDR10), `ext_linear` (scRGB), `srgb` + +Then implement: `create_parametric_creator` → `wp_image_description_creator_params_v1` +(`set_primaries_named`, `set_tf_named`, `set_mastering_display_primaries`, +`set_mastering_luminance`, `set_max_cll`, `set_max_fall`) → `create` → emit +`wp_image_description_v1.ready` (or `failed`) → `wp_color_manager_v1.get_surface` → +`wp_color_management_surface_v1.set_image_description(desc, intent)`, double-buffered on +`wl_surface.commit`. + +**Not needed:** ICC creator, `wp_color_management_surface_feedback_v1`, +`wp_image_description_info_v1`, output image descriptions, v2/v3 requests. Mesa uses none of them. + +### 2.3 What Mesa's WSI does — read from the exact commit we build + +Read from `src/vulkan/wsi/wsi_common_wayland.c` at Mesa `7cda7850` (4121 lines — the commit +recorded in `banners-turnip-wayland/mesa_hash.txt`). Landed upstream as MR !32038 (Xaver Hugl, +merged 2025-02-25, Mesa 25.1). + +* **Bind:** `registry_handle_global` binds `wp_color_manager_v1` at **version 1** unconditionally + when advertised (`:1536-1538`), and installs `color_manager_listener` (`:1217-1223`). +* **Colour-space list:** `wsi_wl_display_determine_colorspaces` (`:1122-1160`) always adds + `VK_COLOR_SPACE_SRGB_NONLINEAR_KHR` and `VK_COLOR_SPACE_PASS_THROUGH_EXT`; everything else comes + from the static `colorspace_mapping[]` table (`:1038-1118`) and is added **only if** the + compositor advertised that entry's primaries *and* transfer function (and, for entries flagged + `needs_extended_range`, `feature.extended_target_volume`). Table entries include + `HDR10_ST2084` (bt2020 + st2084_pq), `EXTENDED_SRGB_LINEAR` (srgb + ext_linear + extended range), + `DISPLAY_P3_NONLINEAR`, `DISPLAY_P3_LINEAR`, `BT709_LINEAR`, `BT709_NONLINEAR`, `BT2020_LINEAR`, + `HDR10_HLG`, `ADOBERGB_LINEAR`. +* **Surface formats:** `wsi_wl_surface_get_formats2` (`:2205-2246`) emits the **full cross product** of + `display.colorspaces` × `display.formats` with **no bit-depth gating**: + + ```c + u_vector_foreach(cs, &display.colorspaces) { + u_vector_foreach(disp_fmt, &display.formats) { + if (!(disp_fmt->flags & WSI_WL_FMT_ALPHA) || !(disp_fmt->flags & WSI_WL_FMT_OPAQUE)) + continue; + out_fmt->surfaceFormat.format = disp_fmt->vk_format; + out_fmt->surfaceFormat.colorSpace = *cs; + } + } + ``` + + Consequence: if we advertise BT.2020 + PQ but keep only 8-bit DRM formats, Mesa will happily + offer `R8G8B8A8_UNORM` + `HDR10_ST2084` and DXVK will **not** take it (`pickFormat`'s HDR10 list + is 10-bit/16-bit only) — so there is no accidental 8-bit-PQ trap, but there is also no HDR + unless we also advertise a 10-bit DRM format. +* **Apply:** `wsi_wl_swapchain_update_colorspace` (`:1323-1455`) builds the parametric creator, + blocks on `ready`/`failed` (it dispatches the queue in a loop), sets mastering primaries / + luminance / max_cll / max_fall when `should_use_hdr_metadata` is set for that colour space, and + calls `set_image_description(..., RENDER_INTENT_PERCEPTUAL)`. `is_hdr_metadata_legal` + (`:1277-1299`) drops illegal combinations rather than risking a protocol error. On `failed` + without `extended_target_volume` it retries once without metadata. +* **`VK_EXT_hdr_metadata`:** `wsi_wl_swapchain_set_hdr_metadata` (`:1459-1463`) just stashes + `VkHdrMetadataEXT`; the real work is in `update_colorspace` above. + +**Nothing to build in the driver for HDR10.** Mesa is done. + +### 2.4 Our compositor advertises nothing colorimetric + +Globals (`compositor.c:2527-2538`, plus `ahb_swapchain.c:406`, +`wl_clipboard.c:522-523`, `wl_text_input.c:275`, `wl_toplevel_icon.c:35`): +`wl_compositor` v6, `wl_subcompositor`, `wp_viewporter`, `wl_output` v2, `xdg_wm_base`, +`zwp_linux_dmabuf_v1` **v3**, `wl_seat` v5, `banner_desktop_v1`, `wp_presentation` v2, +pointer constraints, relative pointer, `banner_ahb_v1` v2, data device/control, text input, +toplevel icon. **No `wp_color_manager_v1`.** `protocols/` has no colour-management XML, and +protocol C glue is pre-generated into `generated/` (no `wayland-scanner` at app build time — +`CMakeLists.txt:1-4`), so adding a protocol means generating and committing the files offline. + +The dmabuf format table is 8-bit only (`compositor.c:1323-1326`): + +```c +#define DMABUF_NFMT 4 +static struct { uint32_t fmt; uint64_t mods[DMABUF_NMOD]; int n; } g_dmabuf_fmts[DMABUF_NFMT] = { + {DRM_ARGB8888}, {DRM_XRGB8888}, {DRM_ABGR8888}, {DRM_XBGR8888}}; +``` + +Good news: the machinery around it is already format-agnostic. +`vkp_dmabuf_modifiers` (`vk_present.c`) takes a DRM fourcc and asks the compositor's own Turnip via +`VkDrmFormatModifierPropertiesListEXT`, and `drm_to_vk` (`vk_present.c:105-123`) **already** maps +`AB30`/`XB30` → `A2B10G10R10_UNORM_PACK32`, `AR30`/`XR30` → `A2R10G10B10_UNORM_PACK32`, and +`AB4H`/`XB4H` → `R16G16B16A16_SFLOAT`. Adding 10-bit is a table edit plus the matching +`FOURCC` defines next to `compositor.c:415-421`. + +The compositor's own output swapchain is oblivious (`vk_present.c:301-311, 437-466`): two instance +extensions (`VK_KHR_surface`, `VK_KHR_android_surface` — **no `VK_EXT_swapchain_colorspace`**), +and `VkSurfaceFormatKHR chosen = fmts[0];` (`:441`) — the first format the Android WSI happens to +return, with whatever colour space rides along. The scene image and the whole 13-pass effects +chain are 8-bit (`vk_present.c:54` `SCENE_FMT = VK_FORMAT_R8G8B8A8_UNORM`; `effects_chain.c:29` +`FX_FORMAT = VK_FORMAT_R8G8B8A8_UNORM`). + +> **Naming collision, flag it in any UI work.** The drawer already has an "HDR" effect. It is +> `effects_chain.c:197` `P_HDR` / `app/src/main/cpp/winlator/hdr.frag` — a dual-radius bloom + +> contrast lift ported from `HDREffect.java`, `HDRPower = 1.30`, entirely SDR and entirely fake. +> Real HDR must be named something else ("HDR output", "HDR10") or users will conflate them. + +### 2.5 Is there a protocol-free shortcut? + +No. A `DRM_FORMAT_ABGR2101010` buffer is equally valid as SDR BT.709 or as PQ BT.2020; the format +and modifier describe byte layout, not colorimetry. That ambiguity is precisely why +`wp_color_management_v1` exists. We *could* add a `set_dataspace` request to our own +`banner_ahb_v1` and skip the standard protocol — but Mesa would never call it, so that would need +a driver patch (new wcp) to buy something Mesa already gives us for free. **Implement +`wp_color_manager_v1` v1 server-side; it is strictly cheaper.** + +--- + +## 3. Android side + +### 3.1 The real symbols, their API levels, and what the device has + +`frameworks/native/include/android/surface_control.h`: + +| Symbol | API level | Present in `/system/lib64/libandroid.so` on the Pocket FIT (API 34)? | +|---|---|---| +| `ASurfaceTransaction_setBufferDataSpace(tx, sc, ADataSpace)` | **29** | **PRESENT** | +| `ASurfaceTransaction_setHdrMetadata_smpte2086(tx, sc, AHdrMetadata_smpte2086*)` | **29** | **PRESENT** | +| `ASurfaceTransaction_setHdrMetadata_cta861_3(tx, sc, AHdrMetadata_cta861_3*)` | **29** | **PRESENT** | +| `ASurfaceTransaction_setExtendedRangeBrightness(tx, sc, float cur, float desired)` | **34** | **PRESENT** | +| `ASurfaceTransaction_setDesiredHdrHeadroom(tx, sc, float)` | **35** | absent (expected — device is 34) | +| `ASurfaceTransaction_setLuts` | 36 | n/a | +| `ASurfaceTransaction_setColorSpace` | **does not exist** | — | +| `ASurfaceTransaction_setLuma` | **does not exist** | — | + +(Checked with `strings` on the device's own `libandroid.so`; `setEnableBackPressure` and +`setFrameRateWithChangeStrategy` confirmed present alongside, matching what `sc_layer.c` already +dlsyms.) + +Our dlsym table is `sc_layer.c:82-97` — 15 entries, **none of them colorimetric**. The additions +needed are `setBufferDataSpace` (the only mandatory one), plus optionally +`setHdrMetadata_smpte2086` / `_cta861_3` and `setExtendedRangeBrightness`. All four are API ≤ 34, +i.e. inside the range `sc_layer.c` already targets, so the existing "missing symbol → path +unavailable" pattern covers older devices unchanged. + +### 3.2 Dataspaces we would emit + +`ADataSpace` = `STANDARD (63<<16) | TRANSFER (31<<22) | RANGE (7<<27)`, all in the NDK since 29: + +| Constant | Value | Maps from | +|---|---|---| +| `ADATASPACE_BT2020_PQ` | 163971072 | `VK_COLOR_SPACE_HDR10_ST2084_EXT` | +| `ADATASPACE_BT2020_HLG` | 168165376 | `VK_COLOR_SPACE_HDR10_HLG_EXT` | +| `ADATASPACE_SCRGB_LINEAR` | 406913024 | `VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT` | +| `ADATASPACE_DISPLAY_P3` | 143261696 | `VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT` | +| `ADATASPACE_SRGB` | 142671872 | `VK_COLOR_SPACE_SRGB_NONLINEAR_KHR` (today's implicit default) | + +Every layer on the device right now reports `dataspace=UNKNOWN (0)`, which SF treats as sRGB. + +### 3.3 Buffer formats + +`AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM = 0x2b` (API 26) ↔ `VK_FORMAT_A2B10G10R10_UNORM_PACK32` +— the normal 10-bit scanout format on Adreno DPUs. QTI gralloc on this device knows it: +`strings /vendor/lib64/libqdMetaData.so` lists `RGBA_1010102`, `RGBX_1010102`, `BGRA_1010102`, +`BGRX_1010102`. `AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT = 0x16` (API 26) exists but is a +compositing intermediate, not normally a scanout format — it was **not** found in the vendor +gralloc strings, so treat FP16 gralloc allocation on this SoC as unproven. +`AHardwareBuffer_isSupported()` (API 29) is the correct runtime probe, and we should use it rather +than assume. + +The compositor's own AHB pool is hardcoded 8-bit (`sc_layer.c:302` +`.format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM`) and the imported view is built with +`DRM_ABGR8888` (`sc_layer.c:326`). That is the *copy* path; the zero-copy path +(`sc_layer_present_ahb`, `sc_layer.c:430`) takes the game's own buffer and so already carries +whatever format the game allocated — it just never labels it. + +### 3.4 What SurfaceFlinger does with an HDR layer on an SDR panel + +From `services/surfaceflinger/CompositionEngine/src/Output.cpp`, `getBestDataspace()` / +`pickColorProfile()`: + +* A `BT2020_PQ` layer sets `outHdrDataSpace = BT2020_PQ` but the output only *adopts* it when + `DisplayColorProfile::hasLegacyHdrSupport(BT2020_PQ)` is true — i.e. when the Composer HAL + reported HDR types for that display. Otherwise the output dataspace stays `DISPLAY_P3` with + `COLORIMETRIC` intent, and the layer is **tone-mapped, not rejected**. +* Because the HWC for an SDR-only display cannot consume a PQ buffer, the standard + `validateDisplay()` negotiation marks that layer **CLIENT** instead of **DEVICE**, and + RenderEngine/Skia composites it with the `libtonemap` SkSL gain shader + (`libtonemap_LookupTonemapGain`, uniforms `in_libtonemap_displayMaxLuminance` / + `in_libtonemap_inputMaxLuminance`). +* **This is the trap for us.** Our whole zero-copy win is that `banner_wayland_game` composites + DEVICE (proven 2026-09-13: DEVICE with ROT_90 + 1.5× scale at 144 Hz, −4 pts GPU busy, −3 % + power). Tagging that layer `BT2020_PQ` on a panel with no HDR types is very likely to drop it to + CLIENT — i.e. HDR would **buy a washed-out tone-map and pay for it with the zero-copy saving**. + Any implementation must gate the dataspace on the *display's* reported HDR types, not on the + game's request. +* `setExtendedRangeBrightness` is a different mechanism: it applies only to `RANGE_EXTENDED` + (scRGB) layers and works by having SF dim the *other* layers by `whitePointNits / maxWhitePoint` + (`renderengine/LayerSettings.h`) while leaving the extended layer undimmed, so the boosted layer + reads brighter by simultaneous contrast without exceeding the panel ceiling. + **It needs the display to expose an HDR/SDR ratio.** This panel does not (§4). +* `setDesiredHdrHeadroom` (API 35) is the PQ/HLG equivalent and overrides/`is overridden by` + `setExtendedRangeBrightness` — last call wins. Not available on the test device at all. + +### 3.5 `has_HDR_display` vs `getHdrCapabilities()` + +`ro.surface_flinger.has_HDR_display` is a **build-time** declaration (`TARGET_HAS_HDR_DISPLAY`) +that the device *has* a wide-gamut, high-luminance panel; it gates SF-internal colour-management +machinery. `Display.getHdrCapabilities().getSupportedHdrTypes()` is the **runtime, per-display** +answer, built from the Composer HAL's `getHdrCapabilities()` for that connector, itself derived +from the EDID CTA-861.3 Static Metadata Data Block. **They can disagree, and on this device they +do.** An empty list does not mean rejection — it means "tone-map it." + +### 3.6 External display + +On hotplug, the framework queries `getDisplayConfigs`, `getColorModes`, `getHdrCapabilities`, +`getDisplayCapabilities` for the new display handle exactly as for the internal panel, so +`Display.getHdrCapabilities()` on an external `Display` *is* architecturally wired to reflect the +monitor's EDID. Whether it actually does is a vendor-HWC question; empty lists for genuinely +HDR10 USB-C monitors are a commonly reported Snapdragon gap. **Unproven for the Pocket FIT — the +only way to know is to plug one in.** + +--- + +## 4. What the test device can and cannot show + +All read today from the Pocket FIT (Adreno 750, Android 14 / API 34), read-only: + +``` +DisplayDeviceInfo{"Built-in Screen": 1080 x 1920, ... + supportedModes [... supportedHdrTypes=[] (all four modes) ], + colorMode 0, supportedColorModes [0], + hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, + mMaxAverageLuminance=500.0, mMinLuminance=0.0}, + hdrSdrRatio NaN, brightnessMaximum 1.0 ...} +mBaseDisplayInfo: ... hdrSdrRatio not_available, userDisabledHdrTypes [] +``` + +``` +dumpsys SurfaceFlinger: + Wide-Color information: + Device supports wide color: 1 + Device uses color management: 1 + DisplayColorSetting: Managed + Display 4630946852602928515 color modes: + ColorMode::NATIVE (0) + Current color mode: ColorMode::NATIVE (0) + colorMode=NATIVE (0) renderIntent=COLORIMETRIC (0) dataspace=UNKNOWN (0) targetDataspace=UNKNOWN (0) + displayBrightnessNits=-1.000000 sdrWhitePointNits=-1.000000 displayBrightness=nullopt + (every layer) dataspace=UNKNOWN (0) hdr metadata types=0 +``` + +``` +getprop: + [ro.surface_flinger.has_HDR_display]: [true] + [ro.surface_flinger.has_wide_color_display]: [true] + [ro.surface_flinger.wcg_composition_dataspace]: [143261696] = ADATASPACE_DISPLAY_P3 + [persist.sys.sf.color_mode]: [9] = ColorMode::DISPLAY_P3 + [vendor.display.enable_hdr10_gpu_target]: [1] +``` + +Reading: + +* The **build** declares an HDR, wide-colour device and even asks for `DISPLAY_P3` as the system + colour mode (`persist.sys.sf.color_mode=9`), but the **HWC reports `supportedColorModes=[0]` + (NATIVE only) and no HDR types**, so SF runs the display in NATIVE with COLORIMETRIC intent and + the P3 request is inert. The props are aspirational; the HAL is the truth. +* `hdrSdrRatio not_available` / `NaN` and `displayBrightnessNits = -1` mean + `Display.isHdrSdrRatioAvailable()` is false → **`setExtendedRangeBrightness` has nothing to act + on here.** The "brighten highlights on an SDR panel" trick is unavailable on this device. +* `supportedColorModes=[0]` also means **Display-P3 wide gamut is not available either** — not + just HDR. A P3-tagged layer would be colour-converted into the panel's native gamut, i.e. into + whatever the panel natively is, with no way for us to know what that is. +* 500 nits max luminance is below the ~540-nit bar AOSP's own `has_HDR_display` doc cites, and + there is no HDR type to signal anyway. + +**Conclusion: visual HDR cannot be demonstrated on the Pocket FIT's internal panel, and neither +can wide gamut, and neither can extended-range brightness.** The only things provable on this +device are (a) 10-bit buffers end to end (banding reduction, measurable), and (b) plumbing +correctness by logs and `dumpsys`. + +Vulkan-side, for completeness (device `strings`): + +| Library | `VK_EXT_swapchain_colorspace` | `VK_EXT_hdr_metadata` | +|---|---|---| +| `/system/lib64/libvulkan.so` (platform loader — implements the Android swapchain) | **PRESENT** | **PRESENT** | +| `/vendor/lib64/hw/vulkan.adreno.so` (Qualcomm blob) | absent | absent | +| `/vendor/lib64/hw/vulkan.turnip.so` (vendor-shipped Turnip) | **PRESENT** | **PRESENT** | +| wcp v6 `libvulkan_freedreno_wayland.so` (game driver) | **PRESENT** | **PRESENT** | + +The platform loader contains the string `native_window_set_buffers_data_space(%d) failed: %s (%d)` +— i.e. Android's own swapchain implementation is what turns a `VkColorSpaceKHR` into a surface +dataspace. So for the **copy path**, the compositor's output HDR is genuinely just "enable +`VK_EXT_swapchain_colorspace` at instance creation and pick a better surface format than +`fmts[0]`". No driver work. + +--- + +## 5. The gap list, ordered, with sizes + +Sizes are engineer-days for someone who already knows this code. "Prove" = device-visible in logs +or `dumpsys`, not by eye. **App-only unless marked.** + +### Phase A — make the truth reachable (no user-visible HDR yet) + +| # | Repo | Work | Size | +|---|---|---|---| +| A1 | app | **Advertise 10-bit DRM formats over `zwp_linux_dmabuf_v1`.** Add `AB30`/`XB30` (and optionally `AR30`/`XR30`, `AB4H`/`XB4H`) to `compositor.c:1323-1326` + `FOURCC` defines near `:415-421`. `vkp_dmabuf_modifiers` and `drm_to_vk` already handle them, so this is a table edit + a log line. Risk: a client picking a 10-bit format while the scene/effects chain stays 8-bit — the import works (`drm_to_vk`), the blit downconverts. Gate behind a flag until A4. | **0.5 d** | +| A2 | app | **Generate + commit `color-management-v1` protocol glue.** Fetch `staging/color-management/color-management-v1.xml` from wayland-protocols ≥ 1.41, run `wayland-scanner` offline, commit XML + `generated/color-management-v1-{protocol.c,server-protocol.h}`, add to `CMakeLists.txt`. Mechanical. | **0.5 d** | +| A3 | app | **Implement `wp_color_manager_v1` v1 server-side** (new `wl_color_mgmt.c`, ~400–500 lines): the global + bind-time feature/intent/primaries/tf events; the parametric creator with `set_primaries_named`/`set_tf_named`/`set_max_cll`/`set_max_fall`/`set_mastering_*`; image-description objects with `ready`/`failed`; `get_surface` → `wp_color_management_surface_v1` and `set_image_description` stored double-buffered on our `struct surface`. **Watch the blocking loop:** Mesa dispatches its queue waiting for `ready`, so we must send `ready` from the request handler's own flush, not defer it to the next frame, or a game stalls at swapchain creation. Advertise only what the *current output* can actually honour (see A5). | **2 d** | +| A4 | app | **Carry the image description onto the Android layer.** dlsym `ASurfaceTransaction_setBufferDataSpace` (+ `setHdrMetadata_smpte2086` / `_cta861_3`) in `sc_layer.c:82-97`; map surface image description → `ADataSpace` + `AHdrMetadata_*`; apply in `sc_layer_present_ahb` (`sc_layer.c:430-470`, next to the existing `setBuffer`). Plumb the per-surface description from `compositor.c` through `ahb_swapchain.c:219`. Also set an explicit `ADATASPACE_SRGB` on the existing 8-bit path so we stop relying on `UNKNOWN`. | **1 d** | +| A5 | app | **Capability gate.** Read `Display.getHdrCapabilities()` / `getSupportedHdrTypes()` / `isHdrSdrRatioAvailable()` (and the external `Display` when `ExternalDisplayController` has one) in Java, pass down over JNI, and *only then* advertise `bt2020`/`st2084_pq` from A3. Without this we advertise HDR on a panel that will tone-map it and drop the layer to CLIENT (§3.4). Include a `banner_log("color", ...)` line naming exactly what was advertised and why. | **0.5 d** | + +**Phase A total: ~4.5 days. App-only. No new wcp.** End state: a game with `DXVK_HDR=1` on a +genuinely HDR display gets an HDR10 swapchain, its buffer reaches an `ASurfaceControl` layer +tagged `BT2020_PQ` with real mastering metadata, and `dumpsys SurfaceFlinger` proves it. + +### Phase B — the copy path and the effects chain (only if A is kept) + +| # | Repo | Work | Size | +|---|---|---|---| +| B1 | app | **10-bit output swapchain.** Add `VK_EXT_swapchain_colorspace` to `vk_present.c:301-311` (`enabledExtensionCount` 2 → 3), replace `chosen = fmts[0]` (`:441`) with a real preference walk (HDR10 + `A2B10G10R10` when the display supports it, else `R8G8B8A8_UNORM` + sRGB). The Android platform loader does the rest. | **0.5 d** | +| B2 | app | **Widen the scene + effects chain.** `SCENE_FMT` (`vk_present.c:54`) and `FX_FORMAT` (`effects_chain.c:29`) → `A2B10G10R10_UNORM_PACK32` (or FP16 for real HDR headroom). Every one of the 13 passes samples/writes it; the debanding pass in particular must be re-tuned because its strength is calibrated for 8-bit quantisation. Memory and bandwidth go up ~25 % (or 100 % for FP16). This is the expensive item and it regresses SDR perf if done unconditionally. | **2 d** | +| B3 | app | **Layer pool at 10-bit.** `sc_layer.c:302` pool format → `R10G10B10A2_UNORM` when the chain is 10-bit, guarded by `AHardwareBuffer_isSupported()`, with the existing `sniff_modifier`/linear-fallback retry extended. | **0.5 d** | + +**Phase B total: ~3 days. App-only. No new wcp.** + +### Phase C — scRGB, and the one thing that needs a wcp + +| # | Repo | Work | Size | +|---|---|---|---| +| C1 | **driver (new wcp)** | Map `VK_FORMAT_R16G16B16A16_SFLOAT` → `AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT` (0x16) in `banner_ahb_format_for` (`patches/wayland/banner_ahb_wsi.py:225-237`) so FP16 swapchains are not hidden by `banner_ahb_skip_format` when zero-copy is on. One enum + a rebuild of eight drivers. **This is the only wcp-requiring item, and only for scRGB zero-copy.** Blocked on proving FP16 gralloc allocation works on Adreno at all (§3.3). | **0.5 d + a driver build cycle** | +| C2 | app | Advertise `extended_target_volume` + `ext_linear` + `AB4H`/`XB4H`, emit `ADATASPACE_SCRGB_LINEAR`, and wire `ASurfaceTransaction_setExtendedRangeBrightness` from `Display.getHdrSdrRatio()`. | **1 d** | +| C3 | **proton-wine (new wcp)** | *Optional, quality only.* Synthesise an EDID with a CTA-861.3 HDR static metadata block in `winewayland.drv` so DXVK reports the real panel luminance in `DXGI_OUTPUT_DESC1` instead of its 1499-nit dummy. | **1–2 d** | + +--- + +## 6. Cheap partial wins — and which are visible on a 500-nit panel + +| Idea | Verdict on the Pocket FIT | Notes | +|---|---|---| +| **10-bit output (banding)** | **Visible, and the best value here.** | This is the one real win. B1 alone (0.5 d) gets a 10-bit output swapchain; A1 (0.5 d) lets the *game* render 10-bit. Adreno 750 + the DPU handle `RGBA_1010102` natively, and `vendor.display.enable_hdr10_gpu_target=1` says the GPU target path expects it. Pairs with the existing debanding pass — arguably makes it unnecessary for 10-bit-capable games, which saves a full-screen pass. Visible on gradients (skyboxes, fog, dark interiors) where our deband pass currently earns its keep. | +| **Display-P3 wide gamut on SDR** | **Not visible. Do not build.** | `supportedColorModes=[0]` / `ColorMode::NATIVE` — the HWC exposes no P3 mode. `persist.sys.sf.color_mode=9` asks for P3 and is ignored. Tagging a layer `ADATASPACE_DISPLAY_P3` would make SF convert P3 → the panel's native gamut, which on a NATIVE-mode display is an unknown-to-us transform. Net effect on this device: at best nothing, at worst a colour shift. | +| **`setExtendedRangeBrightness` to lift highlights** | **Not available.** | `hdrSdrRatio not_available` / `NaN`, `displayBrightnessNits=-1`, `sdrWhitePointNits=-1`. `Display.isHdrSdrRatioAvailable()` is false, so there is no headroom to claim and SF has no nits data to dim the other layers against. | +| **`setDesiredHdrHeadroom`** | **Not available.** | API 35; device is API 34. Absent from `libandroid.so`. | +| **Set `ADATASPACE_SRGB` explicitly on our layers** | **Invisible but worth doing anyway (part of A4, ~0 extra cost).** | Every layer currently reports `dataspace=UNKNOWN (0)`. It works today because SF treats UNKNOWN as sRGB, but it is an accident we are relying on, and it will become wrong the moment any colour management is enabled. | + +**So: of the three "cheap wins" in the brief, exactly one — 10-bit — is real on this hardware, +and it is worth about 1 engineer-day (A1 + B1) on its own, independent of HDR.** + +--- + +## 7. How we would ever prove it + +### 7.1 Which games actually emit HDR under DXVK / VKD3D + +Requirements: a flip-model swapchain at `R10G10B10A2_UNORM` or `R16G16B16A16_FLOAT`, an +`IDXGISwapChain3::SetColorSpace1` call, and `DXVK_HDR=1` in the environment. Known-good +candidates, easiest first: + +* **D3D11 + scRGB:** *Shadow of the Tomb Raider*, *Resident Evil 2/3 Remake*, *Devil May Cry 5*, + *Mass Effect Legendary Edition*. RE Engine titles are the usual smoke test on Linux because they + call `SetColorSpace1` early and unconditionally when DXGI reports HDR. +* **D3D12 + HDR10:** *Cyberpunk 2077*, *Forza Horizon 5*, *Horizon Zero Dawn*. These go through + vkd3d-proton's stricter path (§1.1) — good for catching a half-done implementation, since a + wrong answer **stalls presentation** instead of degrading. +* **Sanity harness, no game needed:** anything that calls `vkGetPhysicalDeviceSurfaceFormatsKHR` + under the layer. `vulkaninfo` is not available in the prefix, but a tiny Win32 Vulkan probe + built against the layer's headers, or simply DXVK's own `VK_INSTANCE_LAYERS`-free log with + `DXVK_LOG_LEVEL=info` and `DXVK_HDR=1`, will say whether the colour space was accepted. **Start + here** — it is the cheapest signal and needs no HDR display at all. + +### 7.2 Platform-side verification (not by eye) + +Order of proof, each step gating the next: + +1. **Compositor log.** New `banner_log("color", ...)` lines: which primaries/tf we advertised and + why; every image description created (primaries, tf, max_cll, max_fall); every dataspace set on + the layer. This is the only step that works on any device. +2. **Guest log.** `DXVK_HDR=1` + `DXVK_LOG_LEVEL=info` → DXVK prints the chosen colour space and + format at swapchain creation. If `SetColorSpace1` was refused, DXVK says so. Mesa's WSI prints + `Not using HDR metadata to avoid protocol errors` when `is_hdr_metadata_legal` rejects metadata + — catching that string is a direct test of A3's metadata plumbing. +3. **`dumpsys SurfaceFlinger | grep banner_wayland_game`.** Today it prints + `dataspace=UNKNOWN (0) hdr metadata types=0`. Success = `dataspace:0x9c60000` (`BT2020_PQ`, 163971072 = + `STANDARD_BT2020|TRANSFER_ST2084|RANGE_FULL`) and `hdr metadata types=` non-zero. **Also record `composition:` on the same line** + — if it flips DEVICE → CLIENT, HDR cost us the zero-copy win (§3.4) and that is a failure, not a + success. +4. **`dumpsys display`.** On whatever display is in use: `supportedHdrTypes=[...]` non-empty, + `colorMode` ≠ 0, `hdrSdrRatio` ≠ `not_available`. This is the gate for steps 5–6; on the Pocket + FIT's internal panel it will never pass. +5. **`dumpsys SurfaceFlinger` Wide-Color section.** `Current color mode` should move off + `ColorMode::NATIVE (0)`, and the output line's `dataspace=`/`targetDataspace=` should stop being + `UNKNOWN (0)`. +6. **Only then, by eye.** + +### 7.3 Getting a display that can actually show it — three options, ranked + +1. **External HDR display over USB-C (recommended, cheapest).** The app already reparents the game + into a `Presentation` on a secondary display — + `app/src/main/java/com/winlator/star/display/ExternalDisplayController.java`, + `findPresentationDisplay()` picks a `DISPLAY_CATEGORY_PRESENTATION` display that is not the + activity's own. In the Wayland session the compositor's `SurfaceView` is the reparented view, so + `sc_layer.c`'s `ASurfaceControl_createFromWindow(vkp_window(), ...)` follows it automatically — + **no new plumbing to test on an external panel.** Risk: `Display.getHdrCapabilities()` for a + DP-alt-mode display depends on the vendor HWC reading the external EDID, and empty lists for + genuinely HDR10 monitors are a common Snapdragon gap (§3.6). **Step zero is a five-minute, + zero-code test: plug an HDR monitor in and run `dumpsys display | grep -A2 hdrCapabilities`.** + If the external display reports HDR types, everything else follows. If it does not, options 2 + and 3 are all that remain. +2. **The user's Galaxy Fold (Adreno 840).** Samsung foldables/flagships do report HDR10+ on the + internal panel, so this is the most likely device to show real HDR with no extra hardware. But + the Fold is *already* the outstanding unknown for basic Wayland bring-up (checkpoint item 1: + "Other GPUs… the Galaxy Fold (A840) logs are still outstanding"). Chasing HDR there before + plain Wayland is proven there inverts the priority order. +3. **Plumbing-only verification on SDR.** Everything in §7.2 steps 1–3 works on the Pocket FIT. + This proves the code is *correct* but proves nothing about whether it *looks right* — and + tone-mapping quality is the entire user-visible payload of HDR. **Do not ship on this evidence + alone.** + +--- + +## 8. Verdict + +**Not now. Do the 10-bit slice; park HDR behind the Fold.** + +The reasoning, plainly: + +* **The effort is genuinely small and smaller than we thought.** ~4.5 days to a plumbed HDR10 + path, **app-only, no new wcp** — because Mesa's colour-management client is already inside the + shipped wcp v6 driver and our zero-copy WSI patch already maps 10-bit to gralloc. The phase-4 + memory note saying HDR "does need a new wcp" should be corrected: only scRGB/FP16 zero-copy (C1) + does, and that is optional. +* **But the payload is zero on the only device we can test on.** The Pocket FIT reports no HDR + types, no colour modes but NATIVE, no HDR/SDR ratio and no brightness nits. We could not see the + feature, could not tune the tone-mapping, and could not tell a correct implementation from a + subtly wrong one. Shipping HDR proven only by log lines would be the exact opposite of this + project's "device-proven, not CI-green" rule. +* **On this device it would be a net negative if enabled.** §3.4: an HDR-dataspace layer on a + display with no HDR types drops from DEVICE to CLIENT composition. That trades the measured + zero-copy win (−4 pts GPU busy, −3 % power) for a GPU tone-map pass and a washed-out image. A + capability gate (A5) prevents the harm, but a gate that is always closed on our test hardware is + a feature nobody can exercise. +* **It is also out of order.** The pre-4 checkpoint's ranked list puts "other GPUs" and "prove + zero-copy where it can win, then make it the default" first, with multi-layer presentation in + flight. HDR competes with those for the same `sc_layer.c` surface area — and multi-layer will + rewrite exactly the code A4 touches. Landing HDR into `sc_layer.c` now means merging it twice. + +**What the user would actually see for the effort, honestly:** + +* **Today, Pocket FIT, full HDR (7.5 days):** nothing. Identical picture, plus a `dumpsys` line + that says `BT2020_PQ`, plus a risk of losing zero-copy. +* **Today, Pocket FIT, the 10-bit slice only (A1 + B1, ~1 day):** *slightly* smoother gradients in + dark scenes and skyboxes for games that offer a 10-bit swapchain, and a plausible route to + retiring the debanding pass (one fewer fullscreen pass) for those games. Small, real, and it is + the foundation Phase A sits on anyway — so it is not wasted work if HDR later goes ahead. +* **Later, on an HDR display (external monitor or the Fold), full Phase A:** genuinely brighter + highlights and a wider gamut in the ~15 PC titles that implement HDR properly, on the one Android + emulator that can do it. That is a real headline feature and a real differentiator — but only + once there is a panel to show it on. + +**Recommended sequence:** + +1. **Five minutes, zero code:** plug an HDR monitor into the Pocket FIT's USB-C and run + `dumpsys display | grep -A2 hdrCapabilities`. This single reading decides everything — + it is the difference between "we can develop and prove HDR today on hardware we own" and + "HDR is blocked on the Fold." +2. **~1 day, independent of HDR:** the 10-bit slice (A1 + B1), gated and A/B'd for banding and + perf. Ship it as a banding/quality improvement on its own merits. +3. **Park Phase A (A2–A5)** until either step 1 comes back positive or the Fold is in the loop + and plain Wayland is proven there. Revisit *after* multi-layer presentation lands, so the + `sc_layer.c` dataspace work is written once against the final layer API. + +--- + +## 9. What I could not establish, and why + +* **Whether FP16 (`R16G16B16A16_FLOAT`) AHardwareBuffers are allocatable on this SoC.** Not in the + vendor gralloc strings, and I did not install or run a probe binary (other agents are testing on + the device). Decides whether scRGB zero-copy (C1) is possible at all. Cheap to settle later with + a one-call `AHardwareBuffer_isSupported()` check inside the compositor's existing startup log. +* **Whether an external HDR display over USB-C actually reports HDR types on the Pocket FIT.** + No external display was connected and I did not connect one. This is the single highest-value + unknown in the whole report (§8, step 1). +* **Whether an HDR-tagged layer really drops DEVICE → CLIENT on this HWC.** The AOSP code path is + clear (§3.4) but it is vendor-HWC behaviour and I did not test it — testing it would mean + launching a game, which was out of scope. +* **What the Galaxy Fold (Adreno 840, Android version unknown to me) reports.** Not connected. + Its `getHdrCapabilities()` and `isHdrSdrRatioAvailable()` are the other decisive readings. +* **Exact Mesa line numbers.** Cited against `wsi_common_wayland.c` fetched from + `gitlab.freedesktop.org/mesa/mesa` at `7cda7850edd103ace21aac37d416d2fdf7a282e1`, the commit in + `banners-turnip-wayland/mesa_hash.txt`. They are accurate for that file; they will drift if the + Turnip base moves. +* **DXVK/vkd3d-proton line numbers** are cited against upstream `doitsujin/dxvk@8759acd1` and + `HansKristian-Work/vkd3d-proton@2a38e799` (master as of today), not against the exact + v3.1-gplasync / 3.1.0-wave64-relax builds we ship. The feature presence in *our* builds was + verified independently by `strings` on the device (§1.1); the line numbers are for orientation. +* **Whether any of the games in §7.1 launch and run correctly under our Wayland backend at all.** + Untested. Picking the HDR test title is its own small exercise and should start from games + already known to work in a Wayland container. + +--- + +## 10. Round 1 — as built (2026-09-14, `feat/wayland-hdr`) + +Phase A (A1–A5) for HDR10, opt-in, proven by the app's own logs because the first HDR panel in the +loop is a tester's non-rooted Galaxy Fold (Adreno 840, Android API 37: HDR10/HLG/HDR10+, 1351 nits, +HDR/SDR ratio available). App-only; no layer change. + +### 10.1 The gate (`wl_color_mgmt.c`, `banner_color_init`) + +Open only when ALL hold when the compositor starts: + +| Input | Where it comes from | +|---|---| +| `BANNER_WAYLAND_HDR=1` (or `true`/`on`) | container or shortcut env (`XServerDisplayActivity.resolvedWaylandHdrMode`) | +| the game's display lists **HDR10** | `DisplayHdrInfo.supportsHdr10` for `hdrTargetDisplay()` (the TV when the game is on it) | +| display layers with dataspace control | `sc_layer_can_tag_hdr()` = SurfaceControl API + `ASurfaceTransaction_setBufferDataSpace` | +| the zero-copy global | `ahb_swapchain_advertised()` | + +`BANNER_WAYLAND_HDR=force` skips the display row only (testing the negotiation on an SDR panel — +SurfaceFlinger then tone-maps the layer). A **closed** gate advertises nothing (no +`wp_color_manager_v1` global, no 10-bit dma-buf rows), writes `color … HDR gate CLOSED: ` and +`HDR on screen: no, because `, and the session is otherwise byte-for-byte the old one. With the +switch unset the module is silent unless the display lists HDR10 or `DXVK_HDR=1` is set (one hint line). +On an HDR10 display the app also turns **zero-copy presentation on** for the session (an HDR frame is +only right on the game's own layer) and exports `BANNER_WSI_AHB=1` to match. + +### 10.2 What an open gate offers (§2.2, exactly what Mesa binds) + +`wp_color_manager_v1` **version 1**: intent `perceptual`; features `parametric` + +`set_mastering_display_primaries` (Mesa only sends mastering luminance inside that feature's branch); +primaries `bt2020`; transfer `st2084_pq`. Not advertised: `srgb` (so Mesa creates no colour surface for +SDR swapchains at all), HLG (no DXGI swapchain uses it), `ext_linear`/`extended_target_volume` (scRGB = +Phase C, needs FP16 gralloc + a layer change), ICC, `windows_scrgb`. `zwp_linux_dmabuf_v1` gains +`AB30`/`XB30` (A2B10G10R10 — Mesa lists a VkFormat only when both the alpha and opaque fourcc are there), +appended after the four 8-bit rows. Protocol glue generated from wayland-protocols **1.41** with +wayland-scanner 1.24.0 (`protocols/color-management-v1.xml`). + +Strictness: protocol errors only where a conforming client can never hit them (un-advertised +feature/intent/primaries/tf, a property set twice, an incomplete set, a not-ready description). +Everything a conforming client can produce on a bad day is logged and absorbed instead — out-of-range +HDR metadata is dropped from what Android gets (and `max_cll`/`max_fall` of 0 = "unknown", which Mesa +sends as-is), a second colour surface for the same `wl_surface` replaces the first, requests on inert +objects are ignored. `ready` is sent from inside `create` (Mesa blocks its swapchain on it). +Output and surface-feedback image descriptions answer `failed` (Mesa uses neither). + +### 10.3 The layer path (`sc_layer.c`) + +`setBufferDataSpace` (+ `setHdrMetadata_smpte2086` / `_cta861_3` when present) ride the same +transaction as the buffer, per layer, only on change, re-sent on every new SurfaceControl (recovery +swap, window change). A layer that was never tagged is never touched; once tagged, an untagged frame +puts it back to `UNKNOWN` and clears the metadata. The zero-copy frame gets the surface's current +description; the 8-bit pool copy of an HDR frame keeps the PQ tag (colours right, 8-bit precision, +logged once); the effects pass and the overlay layer are always untagged. + +### 10.4 When an HDR frame cannot be zero-copy — round 1's decision + +No tone-mapping anywhere (the copy path is `vkCmdBlitImage` into an 8-bit sRGB swapchain; a PQ→SDR +shader pass is its own project). Instead: + +- **Effects on / frame generation on:** an HDR fullscreen game **keeps its display layer**; the + effects chain and frame generation are skipped for it (both are 8-bit SDR and would wash it out), + and the base surface's black frame skips them too (`vkp_render_plain`) so generated presents cannot + pace the loop. Logged when it starts and when it ends. +- **A window above the game on a display that cannot compose a second layer** (phase 5's + rotated+scaled rule is untouched), **a windowed HDR game**, **zero-copy switched off**, **layer + unavailable:** the scene goes through the copy path and the HDR frames are shown **untone-mapped + (washed out)**; every such scene is counted and the reason logged. + +### 10.5 Proof without root — what a tester's logs say + +`Download/Wayland-logs/wayland-*.log`, tag `color` (plus the existing `display` capability line): + +| Line | Means | +|---|---| +| `HDR gate OPEN: … "Built-in Screen" … reports HDR types HDR10, …` | the offer is on, with its inputs and which Android colour calls exist | +| ` bound wp_color_manager_v1 version 1 …` | Mesa saw it: `VK_COLOR_SPACE_HDR10_ST2084_EXT` is now listed | +| `: colour-management surface created` | a swapchain asked for a non-sRGB colour space | +| `image description #N from : BT.2020, ST 2084 (PQ); mastering …; max CLL …, max FALL …` | the game's colour space + `vkSetHdrMetadataEXT` values | +| ` presents WxH buffers in XB30 (10-bit A2B10G10R10) …, gralloc RGBA1010102 (10-bit)` | the 10-bit swapchain really arrived | +| `banner_wayland_game: dataspace BT2020_PQ (0x9c60000) set on the display layer …` | the tag + metadata SurfaceFlinger received | +| `HDR last 10 s: N frames on the display layer tagged BT2020_PQ …` | steady state | +| `display HDR/SDR ratio X (was Y; HDR frames on screen: yes …)` | `Display.getHdrSdrRatio()` — rises above 1.00 only when Android grants HDR headroom | +| `HDR on screen: yes / tagged but NOT confirmed / no, because …` | the verdict (written on changes, at game exit and at session end; the last one counts) | + +DXVK's own `_dxgi.log` / `_d3d11.log` add `Color space: VK_COLOR_SPACE_HDR10_ST2084_EXT` and +the 10-bit format at swapchain creation; Mesa's `Not using HDR metadata to avoid protocol errors` +(stderr → `wine_debug.log`) means the game's metadata failed Mesa's own legality check. + +## 11. Round 2 — as built (2026-09-14, `feat/wayland-hdr`; CI only, not device-proven yet) + +Round 1 is proven on the tester's Fold (God of War, DXVK v3.1: 10-bit zero-copy, `BT2020_PQ` on the +layer, HDR/SDR ratio 1.00 → 2.51, `HDR on screen: yes`). Round 2 makes it a setting and removes +round 1's big limitation (§10.4: no tone-mapping, effects/frame generation skipped, washed-out copies). +The gate itself is unchanged (§10.1) apart from its first input. + +### 11.1 The setting, and what the launch does with it + +- `Container.isWaylandHdr()` (extraData `waylandHdr`) and the shortcut extra `waylandHdr` (`1`/`0`/unset + = the container's) — one resolver, `display/WaylandHdr.effective()`, used by the three editors + (container, game shortcut, XMB game settings) and the launch path. `BANNER_WAYLAND_HDR` in the + environment still overrides it (`1` / `0` / `force`). Editors grey the row with the reason when the + built-in screen does not list HDR10 (`WaylandHdr.unavailableReason`), and say it applies from the + next launch. +- HDR on for the session (setting resolved on AND HDR10 display, or `force`): `DXVK_HDR=1` is exported + after the user's env merge unless the user set `DXVK_HDR` themselves. +- Every Wayland session whose display lists **HDR10** exports `BANNER_WAYLAND_HDR_MAX_NITS`, + `…_MAX_AVG_NITS`, `…_MIN_NITS` (decimal nits from `Display.getHdrCapabilities()`; unknown values and + a max of 0 are left out) — the contract the Wayland layer from versionCode 10 turns into EDID HDR + metadata for DXGI (checked by the Wine side against DXVK's own EDID parser: the Fold's 1351/1351/0 → + DXGI max 1345.43, max full-frame 1345.43, min 0.01). Never on an SDR display, whose EDID would then + claim PQ support. One `session environment:` line logs them. Android has no live absolute nits; the + live evidence stays the HDR/SDR ratio. +- A "DXVK before 3.0 needs layer v10" warning was built and then **removed**: its premise was wrong + (Wine already exposes `VK_EXT_swapchain_colorspace` at instance level; DXVK ≥ 2.1 looks for it in the + device list, logs 0 on every Mesa system — the working v3.1 run logs 0 too — and never uses it for the + HDR decision). Why God of War offered no HDR option on DXVK 2.4.1 is open (Fold A/B). + +### 11.2 HDR-aware composition (`hdr_compose.c`, `hdr_encode.frag`, compositor.c `hdr_plan`) + +Every scene with an HDR draw takes one of four routes (logged on each change, with the reason): + +| Route | When | What reaches the display | +|---|---|---| +| 0 | the HDR game alone fullscreen, zero-copy on, no effects, nothing above it (or one window the overlay layer can carry) | the game's own 10-bit gralloc frames on its layer, `BT2020_PQ` (round 1) | +| 1 | effects on, a window above on a display that cannot take a second layer, a windowed game, zero-copy off | **the HDR picture**: every draw blitted 1:1 into a 10-bit "mixed" image (each pixel still in its own encoding), ONE encode pass to PQ BT.2020 (SDR pixels sRGB → linear → BT.2020, placed at 203 nits, `BANNER_WAYLAND_HDR_SDR_NITS` overrides), the effects chain run on it in 10-bit (`vkp_effects_set_formats`), copied into a 10-bit (`RGBA1010102`) layer buffer, tagged with the game's description; 8-bit buffers if gralloc refuses 10-bit (logged) | +| 2 | frame generation on | composed into PQ in the 8-bit scene image, through the frame-generation engine, presented through an **HDR10 swapchain** (`VK_EXT_swapchain_colorspace` enabled on the compositor instance in HDR sessions only; first `A2B10G10R10` else FP16 pair the surface lists with `HDR10_ST2084`); where the surface lists none, **tone-mapped** into the ordinary swapchain. 8 bits through the engine: gradients may band | +| 3 | an HDR frame the compositor could not import | layer only; effects/frame generation skipped for it (round 1's behaviour, now the rare case) | + +The tone map (mode 1 of `hdr_encode.frag`): PQ → nits → BT.2020 → BT.709, relative to SDR white, maxRGB +curve linear to a 0.8 knee then an exponential roll-off that puts the content peak (the game's max CLL, +else mastering max, else 1000 nits) at 98 %, sRGB-encoded. Which pixels are HDR comes from up to six +top-first scene rects + a mask in the push constants (more windows over the game → the lowest are +treated as SDR, logged once). A composed frame that cannot reach the layer falls back to route 2 for as +long as that lasts (logged once each way). + +### 11.3 The live switch (lead's addition): drawer → Graphics → "HDR output" + +Shown only while the gate is open (the activity's 1 s HDR sampler flips `waylandHdrAvailable`). Per +session, starts on, nothing saved. Off (`banner_color_set_output(0)`, posted through the host queue +to the compositor thread, logged, redraw): route 0 becomes route 1 with the tone map, the picture goes +on the layer **untagged** on 8-bit buffers (the layer's dataspace returns to `UNKNOWN`); route 2 +rebuilds the swapchain as SDR and tone-maps; route 3 cannot (nothing can read those frames) and stays +HDR, said in the log. The game is told nothing (its DXVK_HDR and colour-manager offer were decided at +launch). The HUD reads `Wayland · HDR` while HDR frames are on screen (tagged in the last 1.5 s and +ratio > 1.01 where reported), `Wayland · HDR off` while the switch is off. Frames tone-mapped by the +switch are counted separately in the verdict. + +### 11.4 Live headroom (lead's addition after the second Fold run) + +The Fold's second run (brightness slider at maximum) showed the ratio at 3.23 for a minute and then +**1.00 for 3+ minutes with HDR frames on screen the whole time**, while the verdict kept saying "rose to +3.23". Android simply gave the layer no headroom (SDR white already at the panel's limit). Now, from the +ratio samples the app already sends (1 s + the display listener): the time with HDR frames on screen and +the part of it with ratio > 1.01; a no-headroom streak (HDR frames on screen, ratio <= 1.01) that after +5 s writes `no HDR headroom for 5 s … the screen brightness is probably at maximum …` (and `HDR headroom +is back …` when it ends), tags the 10 s line and the steady ratio line, puts the HUD on `Wayland · HDR +(no headroom)` and the drawer row on the same hint (`banner_color_hdr_state` = 2); and the verdict +reports `headroom above 1.00 for P% of the HDR time (a of b s), now R` plus the hint while the streak +lasts. Cheap: no new sampling, a few integers under the existing lock. + +**Round-2 Fold run (20:23, run 34911468350):** the first no-headroom streak was a **screen recording**, +not the brightness: the user's recording (210.8 s, BT.709 SDR H.264, finalised 20:27:30, so started +~20:23:59) lines up with the ratio falling 2.98 → 1.00 at 20:24:00.9 and staying there to the end. So +Android (at least Samsung's) turns HDR headroom off while the screen is recorded. Every hint now names +both causes; whether maximum brightness does it too is still unmeasured (tester note step H). + +### 11.5 The HUD's HDR line (round 2b, the user's layout request) + +`40.3ms · Wayland · HDR (no headroom)` ran off the pill's right edge (the capsule's ends curve in, and the +latency line is the bottom of the stack). The display-server label is plain `Wayland` again, and the HDR +state is a line of its own directly under it, fed as a `FusionHdr` code (`FusionHudView.setHdrState`): +`HDR` / `HDR (no headroom)` / `HDR off` / `HDR tone-mapped` (switch on, frame generation without an HDR10 +swapchain) / `HDR ready` (gate open, no HDR frames right now). `NONE` - every session whose gate is +closed - draws nothing, so those HUDs are unchanged to the pixel. Pill: the extra line makes the capsule +taller and its ends rounder, so in HDR sessions `fitCapsule()` measures every glyph's ink against the +two rounded ends (plus the outline and 2 sp) and shifts/widens the pill until nothing crosses. Full: an +`HDR` row under `DISP`; Tiles: the *Display* tile's sub-line; Minimal: a line under the footer; Mega: a +fragment after `DISP` in the bottom band. Only the Fusion HUD shows the display server at all; the +classic, GameHub and GameNative HUDs never received it and are untouched. + +### 11.6 Round 2d (Fold evidence from 2c) + +- **The format scan was a false negative.** FG with the AIO HDR card logged `lists no HDR10 swapchain + format (37/0 37/1000104001 … 37/1000104012)`: `swap_init` read the surface's list into + `VkSurfaceFormatKHR fmts[32]`, and with `VK_EXT_swapchain_colorspace` the Android WSI lists every + format once per colour space (11 on the Fold) - the 10-bit/FP16 rows were past entry 32, and the log's + 160-char buffer cut the list too. Now: all pairs read (heap), one line with the total, colour spaces + per format and every HDR-capable pair (10-bit/FP16 first); HDR10 pick A2B10G10R10 → A2R10G10B10 → + FP16 → 8-bit; a driver that refuses the HDR10 swapchain gets the SDR one at once. The only other + fixed array near it (queue families, 16) does not hold surface formats or present modes; FIFO is the + only present mode used, so no list is read. +- **VK_EXT_hdr_metadata** enabled in HDR sessions where the device lists it; the HDR10 swapchain gets the + game's SMPTE 2086 / CTA-861.3 once per swapchain and image description (none if the game sent none). +- **FP16 frame generation for HDR.** The bridge and both engines already take a format (the chain, + the ring); lsfg-vk itself runs HDR in `R16G16B16A16_SFLOAT`. With HDR frames through an HDR10 + swapchain the scene (`g_fgscene`), the encode pass (new FP16 output), the effects and the engine run + in FP16 where `fge_format_ok` (storage + linear sampling) passes; the PQ signal is fed as-is (the + shaders' own HDR flags stay off - PQ is already perceptual). A chain that fails to build in FP16 is + sticky inside both engines, so the bridge refuses the format for the session and restarts the engine + in 8 bits instead of marking frame generation failed. +- **Evidence beside the headroom** (app, non-root): PowerManager thermal status (+ listener) and + `getThermalHeadroom(10)` every 10 s, `Settings.System` brightness + mode (+ observer), screenshots + (`registerScreenCaptureCallback`, API 34) and screen recording (`addScreenRecordingCallback`, API 35, + reflection) with the normal `DETECT_SCREEN_CAPTURE` / `DETECT_SCREEN_RECORDING` permissions. Changes + are logged; the no-headroom lines, the 10 s line and the verdict carry the values and name the likely + cause (recording / hot / brightness at maximum) or say none is visible. The verdict lists only the + paths that carried frames, to leave room for it. + +### 11.7 Round 2e (headroom request, display ceiling, coverage) + +2d on the Fold: all pass (68 surface pairs, HDR10 swapchain A2B10G10R10, FP16 FG at 120 fps, 0 tone-mapped, +VK_EXT_hdr_metadata, headroom 3.00 at brightness 255 **auto**). A tester's ROG Phone 9 Pro (Adreno 830, +API 36): correct HDR frames, composed path, HDR layer ~80% of the 2400x1080 screen (windowed card), not +hot, not recording, brightness 8-223 manual - and the HDR/SDR ratio at **1.00 the whole session**. +- `ASurfaceTransaction_setDesiredHdrHeadroom` (API 35) on the game layer, per HDR frame, only on change: + content peak (max CLL, else mastering max, else the display's peak) / SDR white, capped at the display's + highest ratio; 0 (no preference) when the layer stops carrying HDR; re-sent on a fresh SurfaceControl. + The screen surface (HDR10 swapchain for frame generation) gets the same through + `SurfaceView.setDesiredHdrHeadroom` (API 35, reflection; `SurfaceControl.Transaction` fallback), applied + by the app from `banner_color_screen_headroom()`. +- `Display.getHighestHdrSdrRatio()` (Android 16+, reflection) in the display line and the verdict; 1.00 + means no boost at all, and the request is then not made. +- HDR layer coverage in the dataspace line, the composed-picture line and on geometry changes. +- "brightness at maximum" only for MANUAL >= 250/255; no visible cause -> "this phone may not boost HDR + from apps (the requested headroom was …, the display's highest ratio is …)". + +### 11.8 What is still NOT done / not proven + +- Round 2's composition, switch and HUD line were device-tested in parts on the Fold (setting-driven + gate, auto environment, composed picture, headroom lines, HUD); 2d is CI only. +- The engines' own HDR flags (lsfg `hdr_support` / FSR3 HDR input) stay off: the PQ signal is treated as + perceptual SDR-like data. If interpolation artefacts show only in HDR, that is the next thing to try. +- Colour effects (brightness/contrast/saturation/gamma, the "HDR" bloom) operate on the PQ signal in + route 1 and look stronger than in SDR; sharpening/AA/CRT/upscalers are perceptually fine. +- scRGB (FP16) swapchains (Phase C) — unchanged: needs FP16 gralloc and a layer change. diff --git a/app/src/main/cpp/waylandcomp/WAYLAND_RUNTIME.md b/app/src/main/cpp/waylandcomp/WAYLAND_RUNTIME.md new file mode 100644 index 0000000000..c240539c72 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/WAYLAND_RUNTIME.md @@ -0,0 +1,472 @@ +# Bannerlator Wayland runtime (feat/wayland-runtime) + +Experimental **parallel** display runtime: run/launch games through Wine's +`winewayland.drv` talking to our own embedded Wayland compositor, instead of the +X11 path (pure-Java X11 server + `libwinlator.so`). The X11 runtime stays the +default and is untouched — this is a separate flavor/branch. + +## What's already proven (spike repo `bannerlator-wayland`, device-tested on Adreno 750) +- Minimal libwayland-server compositor: globals + xdg-shell handshake + buffer commit. +- **Turnip's Vulkan WSI exports real zero-copy dmabufs to our external compositor** + (same Mesa path winewayland.drv uses for DXVK/VKD3D) — risk #1 retired. +- Compositor imports that dmabuf into its own Turnip VkImage (`vk_import.c`). +The staged `src/` here is that proven code, to grow into the app-embedded compositor. + +## Dependencies +1. **A Proton 11 arm64ec wcp that ships `winewayland.drv`** — built on branch + `The412Banner/proton-wine:feat/winewayland` (task #1). Nothing runs end-to-end + without it. +2. **Wayland runtime libs in the imagefs** so `winewayland.so` (unixlib) loads: + `libwayland-client.so`, `libwayland-egl.so`, `libxkbcommon.so`, `libxkbregistry.so` + (bionic aarch64). The wcp bundles them in its `lib/` as a fallback; the clean home + is the imagefs — add via `ImageFsInstaller` (new `installWaylandLibs()`), same + pattern as `installFFmpeg8()`. + +## Integration plan (M4) +- **CMake**: add `waylandcomp` as a native lib (`libbannerwayland.so`) built with the + NDK, linking the bionic `libwayland-server`/`libvulkan`. Generate protocol glue from + `protocols/*.xml` at build time (host `wayland-scanner`). +- **Surface**: a `WaylandDisplayActivity` (parallel to `XServerDisplayActivity`) hosts a + `SurfaceView`; JNI hands the `ANativeWindow` to the compositor, which creates a Vulkan + swapchain on it and blits the imported game VkImage each frame (the last un-proven + render step; standard Vulkan once the window exists). +- **Input**: Android `MotionEvent`/`KeyEvent` → `wl_seat`/`wl_pointer`/`wl_keyboard`. +- **Launch wiring**: start the compositor, export `WAYLAND_DISPLAY`, select the wayland + driver per-prefix (registry `Drivers\Graphics = winewayland`) instead of `winex11`, + and point the container at the winewayland wcp. + +## Status +- ✅ **Native lib foundation done + compile-verified.** Compositor + vk_import + pre-generated + protocol glue build as `libbannerwayland.so` (CMake target added), linking the vendored + bionic `libwayland-server`. Verified: compiles/links clean as an aarch64 bionic `.so`, + exports `banner_wayland_run`, NEEDED = libwayland-server + libvulkan. JNI entry + (`waylandcomp_jni.c`) + `WaylandCompositor.java` bring it up on a thread. Compositor-process + runtime deps (libwayland-server/libffi/libandroid-support) staged in `jniLibs/arm64-v8a`. +- ⏭️ **Next phase (gated on the winewayland wcp landing green):** `WaylandDisplayActivity` + (SurfaceView) + JNI `ANativeWindow`→Vulkan swapchain + blit the imported game VkImage to the + window (last un-proven render step) + input + launch wiring (start compositor, `WAYLAND_DISPLAY`, + per-prefix `Drivers\Graphics=winewayland`) + `ImageFsInstaller.installWaylandLibs()` (client/egl/xkb + into the imagefs for winewayland.so). + +## Pointer lock / relative mouse (zwp_pointer_constraints_v1 + zwp_relative_pointer_manager_v1) +- Both globals are advertised (version 1); glue is pre-generated in `generated/` with + `wayland-scanner server-header` / `private-code` from `protocols/*-unstable-v1.xml` (same + scanner version as the rest, 1.24.0), no build-time scanner needed. +- winewayland's use: `ClipCursor`/fullscreen + hidden cursor → `lock_pointer` (persistent); + `SetCursorPos` → lock + `set_cursor_position_hint` + commit + unlock; visible cursor + + `ClipCursor(rect)` → `confine_pointer` with a one-rectangle region. It only turns relative + motion on for a window its `wl_pointer` has entered, so **pointer focus follows an active + constraint** (the desktop surface gets `leave`, the constrained surface `enter`) and goes + back to the desktop on the next motion after the constraint ends. +- Lock: the pointer is frozen; every input delta becomes `relative_motion` (no `motion`). + Confine: absolute motion is clamped to surface ∩ region. The position hint is applied on + the surface's commit (pointer moves there) and is where the pointer stays when the lock ends. + One constraint holds at a time (a newer request ends the older one); oneshot constraints + are defunct after ending, persistent ones re-take hold on focus re-entry. +- App side: input type 6 = relative delta (1/256 px); `banner_on_pointer_lock(locked, x, y)` + tells Java to switch its touch/mouse path to deltas (`XServer.setExternalRelativeMode`) and, + on unlock, to re-sync the X pointer (the absolute input's source) to x,y. With Wayland mode + `WinHandler.mouseEvent` routes relative-mode input to the compositor instead of the guest. +- Session log tag `pointer`: `lock requested by …`, `locked: … frozen at x,y`, `unlocked: … (why)`, + `confined: …`, `unconfined: …`, `relative pointer created for …`, `position hint: …`. + Test FIFO gained `rel DX DY`. + +## Screen surface, swapchain recovery (vk_present.c) +- The app's UI thread never waits on the renderer: `vk_present_set_window()` only leaves the new + `ANativeWindow` (or NULL) in a request slot; the compositor thread applies it before its next + frame and on every vsync tick (`vkp_apply_window_request`), tearing the old swapchain down and + releasing the old window's reference. Acquire waits at most 1 s, never forever. +- OUT_OF_DATE / SURFACE_LOST on acquire or present rebuild the swapchain (once inline on acquire, so + the frame isn't lost). SUBOPTIMAL is presented as is: the swapchain uses IDENTITY preTransform on + purpose, so a rotated panel reports it on every frame. DEVICE_LOST logs + `GPU device lost … the compositor has stopped presenting` once and stops touching the device; + clients keep being paced (`pace_without_output`) so they don't wedge. +- A swapchain that can't be created is retried every 0.5 s and logged once per streak. + +## Buffer lifetime, FPS limiter (compositor.c) +- `struct dmabuf_buffer` is reference counted: one ref for the wl_buffer resource, one per surface + showing it. Mesa destroys a swapchain's wl_buffers when the game rebuilds its swapchain, while the + last committed one is still on screen; the surface keeps the import (`s->dmabuf_buf`) until its + next commit, so the window neither blinks to black nor is unmapped/remapped ("closed"/"opened"). +- Surface destroy releases its buffer immediately (`drop_dmabuf(s, 0)`), replaced buffers go back on + the limiter's cadence. The per-surface release schedule is bounded: a slot in the past is brought + to now, and the schedule never runs further ahead than `(releases still pending + 1)` intervals. + +## Fullscreen mode + screen alignment +- `WaylandCompositor.nativeSetScaleMode(fullscreenMode, screenAlignment)` takes the app's + `Container.FULLSCREEN_OFF/FIT/STRETCH/FILL/INTEGER` (0..4) and `ALIGN_CENTER/TOP/BOTTOM` (0..2), + any thread, any time (the drawer changes it live). `update_map()` in vk_present.c is a line-for-line + mirror of `ViewTransformation.update()`: OFF and FIT both letterbox (OFF only differs in the app's + fullscreen gates), TOP/BOTTOM confine the picture to the top/bottom half of the output (the + handheld split), FILL overflow is clipped to the region. The app maps touch through the same class + (TouchpadView → X server → input sink → scene input), the overlay arrow through + `waylandSceneToView`, and the SurfaceView's own INPUT_SPACE touches through `vkp_output_to_scene`. +- Log tag `screen`: `, : WxH scene shown WxH at x,y on the WxH output` whenever the + mapping changes (mode, alignment, scene or output size). + +## Clipboard, text input, window icons (feat/wayland-clipboard-ime) +Three globals winewayland used to complain about at startup, each in its own file behind the +small interface in `src/banner_ext.h` (compositor.c only gained hook calls + accessors): +- **Clipboard** (`src/wl_clipboard.c`): `wl_data_device_manager` **v3** and + `zwlr_data_control_manager_v1` **v1**, selection only (start_drag is refused with `cancelled`). + Wine prefers data-control: its desktop process then owns the clipboard without needing keyboard + focus and the "clipboard functionality will be limited" ERR goes away too. One shared selection: + a program's source, or text from Android (`nativeSetClipboardText`), or nothing. Data-control + devices hear every change; `wl_data_device`s only while their client holds keyboard focus (hook in + `keyboard_focus()`), and on focus arrival. Guest → Android: a selection with a text mime is read + once over a pipe on the event loop (1 MiB cap, 3 s timeout) → `banner_on_clipboard_text` → + `WaylandClipboardSync` → `ClipboardManager`. Android → guest: `OnPrimaryClipChangedListener` plus a + re-read on resume / window focus (Android hides clipboard changes from background apps); `receive` + is served by a non-blocking writer. Echo guard on both sides. Log tag `clipboard`. +- **Text input** (`src/wl_text_input.c`): `zwp_text_input_manager_v3` **v1**, double-buffered state, + `done(serial)` only when we sent events. winewayland enables text input for whichever surface gets + `enter` and posts IME updates inside *that window's process*, so text input can't follow keyboard + focus (the desktop surface): it follows the last clicked program window (`g_ime_click`, set in + `pointer_input`), else the topmost non-shell window. `set_cursor_rectangle` arrives when an edit + control calls `ImmSetCompositionWindow`; the app (`WaylandTextInput`) shows the soft keyboard only + then (and with no hardware keyboard), hides it on disable unless the user's own toggle opened it. + Typed text: `SurfaceInputView`'s `InputConnection` → `commit_string` / `preedit_string` + `done`. + Deletions become Backspace/Delete key presses — winewayland's `delete_surrounding_text` handler is + empty. Log tag `text-input`. +- **Window icons** (`src/wl_toplevel_icon.c`): `xdg_toplevel_icon_manager_v1` **v1**, accepts and + drops icons (`done` at bind, no sizes). +- Host → compositor text crosses as UTF-8 `byte[]` through `banner_ext.c`'s queue (mutex + wake + pipe), drained on the compositor thread. Glue for the three protocols is pre-generated with + wayland-scanner 1.24.0 from `protocols/`. + +## Compressed (UBWC) game buffers (feat/wayland-ubwc) +- `zwp_linux_dmabuf_v1` used to advertise `LINEAR` (+`INVALID`) only, so Turnip's Wayland WSI in the + game allocated linear swapchain images and DXVK/VKD3D resolved every frame from their tiled/UBWC + render targets into that linear copy, before the compositor's own blit. Now `bind_dmabuf` builds + its table at the first bind from the renderer's driver (`vkp_dmabuf_modifiers`): + `vkGetPhysicalDeviceFormatProperties2` + `VkDrmFormatModifierPropertiesListEXT` per fourcc + (AR24/XR24/AB24/XB24), each modifier confirmed with `vkGetPhysicalDeviceImageFormatProperties2` + for a dma-buf-backed `TRANSFER_SRC` image. Only `DRM_FORMAT_MOD_LINEAR` (0) and + `DRM_FORMAT_MOD_QCOM_COMPRESSED` (`0x0500000000000001`, UBWC, single memory plane on Adreno) are + ever advertised; anything else the driver reports goes to logcat as "not advertised". +- Mesa's WSI hands every advertised+supported modifier to `vkCreateImage` as a modifier *list* and + Turnip picks `QCOM_COMPRESSED` whenever it is in the list (`tu_image.cc`), so with the + advertisement the game's swapchain is UBWC. The `wl_buffer` then arrives with that modifier and + the pixel-plane pitch/offset from the game's `vkGetImageSubresourceLayout(MEMORY_PLANE_0)`; + `vkp_image_import_dmabuf` creates the compositor's image with the explicit modifier and that one + plane layout (`VkImageDrmFormatModifierExplicitCreateInfoEXT`), which Turnip validates + (`INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT` if the pitch does not fit its `fdl6` alignment). The + swapchain blit (`vkp_render`) and the layer-mode blit (`vkp_blit_image`) read it like any other + source; nothing CPU-side ever touches a dma-buf. Layer mode still blits into its own gralloc pool. +- **A/B switch:** `BANNER_WAYLAND_UBWC=0` (or `false`/`off`) in the container's/shortcut's + environment variables → `nativeSetUbwc(false)` → linear-only advertisement, exactly the old + behaviour. Default on. The driver is still queried, so the log shows what it could have done. +- Log tag `dmabuf`: `formats: AR24 linear+qcom_compressed, XR24 …, AB24 …, XB24 …` at the first + bind (with ` (BANNER_WAYLAND_UBWC=0: qcom_compressed not advertised)` when off, or a second line + `the compositor's driver (…) reports no importable qcom_compressed layout: game swapchains stay + linear` when the adrenotools Turnip lacks it). Per window, the existing `vulkan` line now names + the modifier: `… is presenting GPU frames through Wayland: 1920x1080, format XB24, qcom_compressed + (zero-copy)` vs `… linear (zero-copy)`. Import failures are `error` lines naming the stage, + modifier, size, pitch and VkResult (`dmabuf: vkCreateImage(qcom_compressed, …) -> …`). +- Caveat: both sides must agree on the UBWC encoding for the GPU. The game runs the wcp's Wayland + Turnip, the compositor the user's adrenotools Turnip; the layout code (`fdl6`) is the same, but a + very different Mesa version on one side is the first suspect if a compressed frame imports fine + yet looks scrambled — `=0` is the workaround, and the `gpu` line names both the GPU and the + compositor's driver. + +## Phones with no DRM node (OpenGL) — `BANNER_WAYLAND_NO_RENDER_NODE=1` +- The feedback's `main_device` is the first of `/dev/dri/renderD128`, `renderD129`, `card0` the app + can `stat`; retail phones (Adreno 830/840 reports, 2026-09-14) expose none, so it is `0:0`. + Vulkan games do not care. Mesa's EGL did: its Wayland DRM initialiser failed the display in + `dri2_setup_device()` without a render node and fell back to a software path that has no + rasteriser in these layers — native OpenGL black, sound playing. Wayland layer versionCode 9 + (Banners-Turnip `patches/wayland/egl_wayland_no_drm_node.py`) runs zink + kopper on the Vulkan + device without a node instead; nothing app-side is needed for that. +- `BANNER_WAYLAND_NO_RENDER_NODE=1` (container or shortcut env) makes the compositor advertise + `main device 0:0` on a device that does have a node, to reproduce those phones here. +- Log lines: `dmabuf` `… no display (DRM) device …: OpenGL games need Wayland layer versionCode 9 + or newer …` when the main device is 0:0; `opengl` ` asked for GPU buffers but has drawn + only software (shared-memory) frames …` once per program that asked for dma-buf feedback (EGL's + GPU path always does) and then committed 150 wl_shm frames without making a dma-buf buffer. + +## Zero-copy window layers (spike, `BANNER_WAYLAND_ZERO_COPY=1`) +Research + host-side prototype in `ZERO_COPY_SPIKE.md`: why a dma-buf can't become an +`AHardwareBuffer` (the game's buffers are DMA-heap allocations, not gralloc's), why the interop +must start from a gralloc buffer whose native-handle fd the drivers import (Turnip's own AHB path), +and the WSI patch this needs in our Wayland Turnip. `src/sc_layer.c` implements the receive side: +with the variable in the container's environment, one fullscreen game window is shown on its own +`ASurfaceControl` child of the SurfaceView (pool of three compositor-allocated AHBs, one blit, +release fences from `setOnComplete`, geometry from the fullscreen mode); any other scene falls back +to the swapchain blit. Log tag `layer`. Off by default. + +## Zero-copy game frames (`BANNER_WAYLAND_ZERO_COPY=1`, drawer switch live) +Option (a') of `ZERO_COPY_SPIKE.md`, both halves: +- **Guest (our Wayland Turnip, banners-turnip-wayland `patches/wayland/banner_ahb_wsi.py`, all + variants):** while the compositor's mode is on (see the live switch below), the Wayland + WSI allocates every swapchain image as a gralloc `AHardwareBuffer` (usage GPU_SAMPLED_IMAGE | + GPU_FRAMEBUFFER | COMPOSER_OVERLAY; UBWC when gralloc picks it and a test `vkCreateImage` with the + explicit `QCOM_COMPRESSED` layout succeeds, else linear via a CPU usage bit; `BANNER_WSI_AHB_LINEAR=1` + forces linear), imports the handle's dma-buf with an explicit modifier + pitch (the compositor's own + pool-import path; `vk_android.c` is not in a platforms=wayland build), shares it through + `zwp_linux_dmabuf_v1` as before (blit fallback), and sends the `AHardwareBuffer` once per image: + `socketpair` + `AHardwareBuffer_sendHandleToUnixSocket` + `banner_ahb_v1.attach(wl_buffer, fd, w, h, + stride, modifier hi/lo, image_count)`. Surface formats are limited to `R8G8B8A8_UNORM/SRGB` (and + `A2B10G10R10`) while the mode is on: gralloc has no BGRA (DXVK/Zink blit into the swapchain image + anyway). Marker: `strings libvulkan_freedreno_wayland*.so | grep banner_ahb_v1`. +- **Compositor (`src/ahb_swapchain.c`, protocol `protocols/banner-ahb-v1.xml`):** the global is + advertised on every session where a display layer is possible at all (`sc_layer_available()`); + whether gralloc buffers are WANTED right now is the `mode` event, not the global's presence. + `attach` → `AHardwareBuffer_recvHandleFromUnixSocket`, record on the `dmabuf_buffer`. + When that buffer is the one fullscreen frame (`layer_candidate`, or the layer-only candidate when + this renderer could not import it), `sc_layer_present_ahb` sets it on the `banner_wayland_game` + SurfaceControl as is. **Acquire fence** = `DMA_BUF_IOCTL_EXPORT_SYNC_FILE(READ)` of the dma-buf: Mesa + imports the render fence into the dma-buf (`wsi_signal_dma_buf_from_semaphore`) *before* the + `wl_surface.commit`, so the export always carries the frame; if the ioctl fails the compositor + polls the dma-buf instead (logged once). **Release**: `setOnComplete` → + `getPreviousReleaseFenceFd` → `DMA_BUF_IOCTL_IMPORT_SYNC_FILE(READ)` into the dma-buf → then + `wl_buffer.release` (still on the FPS limiter's cadence); Mesa's acquire + (`wsi_create_sync_for_dma_buf_wait`) exports every fence of the dma-buf, so the game waits for the + display. If the import fails the release waits on the fence fd in the event loop instead. A hidden + or retired layer gets a 16x16 blank buffer so SurfaceFlinger actually lets go of the game's buffer. +- **App:** `BANNER_WAYLAND_ZERO_COPY=1` (container/shortcut env) is the session's STARTING state and + also exports `BANNER_WSI_AHB=1` into the guest (`XServerDisplayActivity.isWaylandZeroCopyRequested`), + which is what an older driver (bound at `banner_ahb_v1` version 1) needs. + +### The live switch ("Zero-copy presentation", Graphics tab) +`banner_ahb_v1` version 2 adds one event, `mode(enabled)`, sent to every bound client on bind and +again on every flip. The compositor owns the state: +- `WaylandCompositor.nativeSetZeroCopy(on)` is live and callable from any thread. Before the + compositor starts it just seeds `g_zero_copy`; afterwards it posts through the `banner_ext.c` host + queue (like the clipboard/IME setters) so `ahb_swapchain_set_mode()` runs on the compositor thread, + which flips `g_zero_copy`, broadcasts `mode`, flushes the clients and redraws. +- **Guest:** the WSI follows `display->banner_ahb_mode`, decided per swapchain at creation. When a + live swapchain was built for the other mode, the next `vkAcquireNextImageKHR` / + `vkQueuePresentKHR` returns `VK_ERROR_OUT_OF_DATE_KHR` (it reuses Mesa's own `chain->retired` + early-outs), which DXVK, vkd3d-proton and Zink all answer by rebuilding the swapchain. The mode + event is read with a non-blocking dispatch of the display queue on each acquire/present, because + in MAILBOX that queue is otherwise only dispatched when the acquire loop runs out of images. +- **Compatibility, both directions.** The registry bind clamps to `MIN(advertised, 2)` — binding + above the advertised version is a fatal `wl_display` error, and a Bannerlator from before the live + switch advertises version 1. On version 1, and on version 2 before the first `mode` event arrives, + the driver keeps the original contract exactly: gralloc images iff `BANNER_WSI_AHB=1`, decided per + swapchain, and no swapchain is ever retired. Once the mode is in play `BANNER_WSI_AHB=1` no longer + forces it on (the app exports that on every zero-copy launch, which would freeze the switch); + `BANNER_WSI_AHB=0` still forces the whole feature off. +- **No black frame, either way.** Switching OFF does not tear down anything: the old gralloc chain's + frames keep being shown — on the layer when this renderer could not import them, through the copy + path when it could — until the game has rebuilt, and only then does `sc_layer_hide()` run. Buffers + already on the layer keep their deferred release (`ahb_swapchain_defer_release` is no longer gated + on `g_zero_copy`, or the display would be handed a buffer it is still scanning out). Switching ON, + the layer path resumes as soon as the first `attach` of the new chain lands. +- **Drawer:** the toggle applies live *and* writes the env as the next launch's default. Its status + line follows the compositor, not the switch: `nativeZeroCopyLastFrameAgeMs()` (updated on every + zero-copy present, unlike the 10 s counter) is what makes it say "Switching on…" / "Switching off…" + only for as long as it really is. +- **Log lines (tag `layer`):** `zero-copy: banner_ahb_v1 version 2 advertised …`, `zero-copy: + bound banner_ahb_v1 version N …`, `zero-copy: on|off at launch …`, `zero-copy switched on|off from + the drawer: N bound programs told to rebuild their swapchains …`, `zero-copy: AHB swapchain from (N images, WxH, UBWC (QCOM_COMPRESSED)|linear, + stride S px)`, `zero-copy: presenting "" (<exe>) without a copy`; the 10 s `stats` line ends + with `| N zero-copy frames`. Guest side (Mesa log, stderr of the game): `banner-ahb: WxH swapchain + (N images) on gralloc buffers: UBWC|linear, stride S px` or the reason it stayed on standard + buffers, plus `banner-ahb: compositor wants gralloc|standard swapchain images` and `banner-ahb: + zero-copy switched on|off: retiring the WxH swapchain …` on a live flip. + +## Multi-layer presentation (feat/wayland-multilayer, `src/sc_layer.c`) +Layer mode hands the scene to SurfaceFlinger as a small, deliberately ordered **set** of Android +display layers instead of one. The whole model, top to bottom: + +``` +app window ....... Compose UI, the in-game drawer, the perf HUD, the on-screen controls, the + pointer arrow - ordinary Android views in the activity's window, ALWAYS on top ++-- SurfaceView .. the compositor's Vulkan swapchain (black while layer mode is up) + +-- z=1 "banner_wayland_game" ...... the one fullscreen game window + +-- z=2 "banner_wayland_overlay" ... at most ONE window drawn above the game +``` + +- **Two layers is the hard cap** (`SC_LAYER_COUNT`). HWC composes only a few layers before + SurfaceFlinger falls back to GPU client composition, which would throw the whole benefit away, so + the compositor never asks for a third: a scene with two or more windows above the game goes back + to the copy path. The count is said out loud the first time the overlay goes up (`layer`: `2 + display layers in use: "banner_wayland_game" (z=1) and "banner_wayland_overlay" (z=2) above it …`). +- **Who owns what.** Each layer has its own `ASurfaceControl`, its own gralloc buffer pool (3 + buffers each), its own geometry and its own lifetime; `struct layer` + in `sc_layer.c` holds all of it and the z-order is fixed by the id (nothing is re-ordered at + runtime). The SurfaceControls are children of the SurfaceView's surface, created on first use and + retired together when the output window changes or goes away. +- **What can be on the game layer**, cheapest first: the game's own gralloc buffer (zero-copy, no + copy anywhere — `ahb_swapchain.c`); one blit of the game's frame into a compositor buffer + (`sc_layer_present`); or, with screen effects on, the compositor pass's **result** blitted into + such a buffer (`sc_layer_present_pass` → `vkp_pass_begin` / `vkp_pass_copy_to`). The last one is + what keeps a Look from dropping the session back to the app's swapchain: the scene → output + mapping (Fullscreen Mode / Alignment, and the scaling a mode like FSR asks for) is then done by + the display through `setGeometry` instead of by a second full-screen GPU blit. +- **Present order matters, and it was measured.** The layers go up first; the base surface's black + frame is presented *after* the layer transaction, and the effects chain runs in its own submit + with **no swapchain image acquired**. A present holds an acquired image and the acquire semaphore + is a vblank gate: folding the chain into that submit (one command buffer, one present — the + shape that looks cheaper) put the whole 13-pass chain behind a vblank and measured **72 fps** + against **111 fps** for the split shape, on HL2 + Retro CRT at 1920x1080 on the Pocket FIT (the + copy path is 129 fps on the same scene). Anyone tempted to "optimise" this into one submit should + read this paragraph first. +- **What goes on the overlay layer**: exactly one draw above the game — a second Wayland toplevel + (a launcher or settings window, a message box), copied 1:1 into the overlay pool and then + *cropped and placed* by the display through the same `vkp_map_draw` mapping the copy path uses. + The point is what does **not** happen: the game's frames are no longer copied through the + compositor's swapchain just because something small sits on top of them. +- **Transparency.** The compositor composes with blits, which overwrite — it never alpha-blends, + on either path — so every layer is marked `ASC_TRANSPARENCY_OPAQUE` and the overlay layer is + cropped to the window it carries. There is no blending to get wrong: no black box over the game, + no double-darkening, and the picture is the copy path's, pixel for pixel. +- **Input is untouched.** An `ASurfaceControl` has no input channel, so neither layer can take a + touch: everything still reaches the app's `SurfaceView` (and the views above it) exactly as + before, and the scene mapping touch goes through (`vkp_output_to_scene` / `ViewTransformation`) + is the same one the layers are placed with, so the cursor still lands where it is pointing. The + SurfaceView is not Z-on-top, so its whole subtree — both layers included — stays under the + activity's own window: the drawer, the HUD and every Compose dialog draw above them. +- **What cannot be layered, and why.** + - *Frame generation*: each generated frame needs a present of its own on consecutive vblanks, and + a display layer latches one buffer per refresh — pacing that is the swapchain's job. While an + engine is armed the whole scene takes the copy path (unchanged). + - *Effects with a window above the game*: the chain has to see the whole scene to look the way it + does on the copy path (and on X11), and the game layer only carries the game. Copy path. + - *Two or more draws above the game* (several windows, or a window with subsurfaces): a third + layer is not worth the client-composition risk. Copy path. +- **Lifecycle.** Hiding is top-down so nothing is uncovered for a frame; a hidden or retired layer + gets the shared 16x16 blank buffer so SurfaceFlinger really lets go of the game's buffer (and + reports a release fence for it) instead of holding it while invisible. `sc_layer_hide()` takes + every layer down (scene no longer a fullscreen game, zero-copy switched off live, session end), + `sc_layer_hide_overlay()` is used when only the window above the game closed, and + `sc_layer_window_gone()` retires both SurfaceControls and drains both pools on a surface loss / + HOME / resume. **The overlay layer is always RETIRED, never merely hidden** (both paths) — see + the HWC note below: a live second SurfaceControl keeps SurfaceFlinger composing on the GPU even + when it is invisible. The game layer keeps its SurfaceControl through a hide, because it goes up + and down with every effects / frame-generation toggle. +- **The display frame-rate vote belongs to one layer.** The refresh-rate stream's + `sc_layer_set_frame_rate()` (the game's cadence, the same value the app votes on its own surface) + is carried **only** by the layer the game presents on — the game layer. The overlay layer is + explicitly voted `0`, so a window that redraws once a second can never hold the panel at the + game's cadence, nor drag the game's cadence down to its own. Each layer remembers what its live + SurfaceControl carries (`fps_applied`) and re-applies on the next transaction, and a retired + SurfaceControl resets it so a re-created layer is re-voted from scratch. Log: `display frame-rate + vote on banner_wayland_game: 60.00 Hz`. +- **Stats.** The 10 s `stats` line now ends with `| N zero-copy frames` (the game's own buffers) and + `| N layer frames` (frames the compositor put on a layer through one of its own buffers — the + plain layer blit or the effects result). Both are hardware-composed; only the first is copy-free. +- **Measured on the Pocket FIT (Adreno 750, portrait panel, landscape session → every layer is + ROT_90 + scaled), `dumpsys android.hardware.graphics.composer3.IComposer/default`:** one layer is + `composition: DEVICE/DEVICE` (game's own gralloc buffer scanned out by the DPU), with effects on + the layer it stays `DEVICE/DEVICE`, but **two** layers flip the whole frame to `DEVICE/CLIENT` — + SurfaceFlinger composes it on the GPU — **and it does not come back when the overlay goes away**: + retiring the overlay's SurfaceControl (which the compositor now does rather than merely hiding + it) leaves the frame in client composition; only re-creating the *game* layer's SurfaceControl + clears it (HOME + resume does, reproduced twice). Retiring is still right — one fewer live layer, + and it leaves the HWC list — it is just not the whole cure; the open follow-up is to retire and + immediately re-create the game layer when the overlay goes, which would cost one black frame + unless the new SurfaceControl is shown before the old one is dropped. The likely mechanism is the + DPU's rotator budget (one rotated+scaled layer), not the layer count as such, so a device or + orientation that needs no rotation may well take both on the DPU. Even in client composition the + overlay layer is not a loss (SurfaceFlinger does the one blit the compositor would have done), but + the hardware-composition win is only real for the single-layer cases. Note `VRI[ScreenDecorHwcOverlay]` + is always `DISPLAY_DECORATION/CLIENT` (the system's rounded corners) — that is why SurfaceFlinger's + `clientCompositionFrames` counter reads 100 % on this device in every state and is useless here. +- **Not done yet:** a second toplevel that is itself rendering into gralloc buffers could go on the + overlay layer zero-copy too (the token machinery in `ahb_swapchain.c` is already per-buffer, not + per-layer); today the overlay always costs one small blit. + +## Screen effects (feat/wayland-effects, `src/effects_chain.c`) +The X11 renderer's screen-effect chain, run by the compositor between the composited scene and the +output. Same SPIR-V as the X11 Vulkan renderer (`winlator/*_frag.h`, made by `winlator/gen_shaders.sh` +and committed — the NDK build compiles no GLSL, so there is no build-time shader tooling), same +push-constant layouts, uniform ranges and pass order, so a saved preset looks the same on both backends. + +**Present-pass hook order (`vk_present.c`, `vkp_render`):** +``` +scene (every draw blitted 1:1 into a scene-sized R8G8B8A8 image; compositor pass only) + -> vkp_effects_run() effects_chain.c: scaling -> effects (below) + -> vkp_framegen_run() framegen_bridge.c: frame generation on the chain's result (next section) + -> update_map / blit Fullscreen Mode + Screen Alignment map the result (and each generated + frame) onto its own swapchain image + -> present generated frames first, the real frame last, FIFO +``` +The compositor pass runs when either stage needs it (`vkp_effects_active() || vkp_framegen_active()`). +Effects operate on the scene; the mapping operates on the output — the chain's result stands for +the whole scene and goes through the same `draw_to_blit` as a plain frame. With everything off the +frame takes the old path unchanged (draws blitted straight through the mapping); only the blit filter +follows the scaling mode (Nearest = `VK_FILTER_NEAREST`). + +**Pass order (locked to the X11 Vulkan renderer, `VulkanRendererContext::recordUpscalePasses`):** +scaling → FXAA → Toon → Colour (brightness/contrast/gamma/saturation) → CAS → HDR → NTSC → CRT → +Debanding (terminal dither). Scaling modes: 0 None / 1 Linear / 2 Nearest = a filtered resize; +3 SGSR, 8 SGSR HQ, 7 NIS = one pass; 4 FSR / 5 FSR Fit = EASU → RCAS (fill vs fit is the Fullscreen +Mode's business here, both run the same pair); 6 Sharpen = RCAS 1:1 (nearest scale + sharpen, as X11). +Render scale is "Not used on Wayland": the scaling modes resize the scene to its **mapped output size** +(3/4/5/7/8 only when that is larger than the scene, the X11 "render below display" gate; 6 always). +Every later pass runs at that resolution, ping-ponging between two targets (+ one EASU mid target). + +**Settings** (`WaylandCompositor.nativeSetUpscaler / nativeSetUpscaleSharpness / nativeSetCas / +nativeSetHdr / nativeSetDeband / nativeSetScreenEffects / nativeSetLookName`, 1:1 with +`VulkanRenderer`'s): any thread; the compositor thread snapshots them per frame, redraws even a +static scene, and writes one `effects` line per change: +`effects scaling=SGSR HQ 75%, CAS on 55%, Look="Game Clarity", colour b=+2 c=+12 g=1.00 s=108%` +(`effects all off: scaling=Linear (plain blit)` when nothing is on). The chain's Vulkan objects are +built on the first active frame (`effects chain ready: 13 passes … on <GPU>`; a driver that refuses +them logs an `error` and effects stay off for the session). The app wires the drawer's Vulkan +post-chain block (`XServerDialogState.on*Apply`) to these in `XServerDisplayActivity.initWaylandEffects` +and remembers the same per-game keys as the Vulkan path (#382). + +**Zero-copy interplay:** the chain's result no longer has to land in the app's swapchain — with a +fullscreen game alone on screen it is copied into the game layer's own gralloc buffer and the game +**stays on its display layer** while a Look is applied (see "Multi-layer presentation" below). It +still takes the copy path when a window is drawn above the game (the chain has to see the whole +scene to look as it does on X11) — `effects zero-copy paused: a window above the game needs the +compositor pass for the whole scene` — and always while frame generation is armed +(`framegen zero-copy paused: frame generation needs the compositor pass`); the layer comes back with +`effects zero-copy resumed: the game is back on its own display layer`. A frame this renderer could +not import (layer-only candidate) still goes on the layer, effects/frame generation skipped, said once. + +## Frame generation (feat/wayland-framegen, `src/framegen_bridge.c`) +The two **native** engines the X11 renderer hosts inside `libwinlator`'s compositor run inside the +Wayland compositor's own Turnip device: **LSFG Native** (the user's Lossless.dll chain, +`winlator/lsfg`) and **Win-FG Native** (our FSR3-derived optical-flow chain, `winlator/winfg`). +The engine sources are compiled into `libbannerwayland.so` unmodified (CMake, app build only; the +standalone build gets `framegen_engine_stub.c`) and driven by `src/framegen_engine.cpp`, which fills +their `VkTable` by name from the compositor's `vkGetInstanceProcAddr`/`vkGetDeviceProcAddr`. +**bionic-fg** (the guest-side win-fg Vulkan layer) is X11-only: its frames are born inside the guest +and have nothing to attach to here, so on Wayland the "bionic" engine is always Win-FG Native. +- **Where it runs** (the hook order above): frame generation takes the effects chain's RESULT + (`vkp_effects_run`'s output, at its size - the scene, or the mapped output size under a scaling + mode - moved to GENERAL), so generated frames carry the same look as real ones. The ONE hook + `vkp_framegen_run(cmd, image, view, w, h, fmt, gens[])` records the engine's chain into the same + command buffer and returns 0..3 generated images. Each image is then blitted through the scene -> + output mapping into its own acquired swapchain image and presented: **generated frames first, the + real frame last** (interpolation produces frames between N-1 and N; that one output interval of + latency is inherent). One acquire/render-done semaphore pair and command buffer per present + (`MAX_PRESENTS` = 4), the frame fence on the last submit. With the FIFO swapchain the presentation + engine shows them on consecutive vblanks: that is the pacing, there are no sleeps and no host pacer. + The swapchain is rebuilt with `multiplier - 1` extra images while armed so every present of a frame + queues without a vblank wait. Frame generation off and effects off = the direct path, byte-for-byte + as before. +- **Device**: `dev_init` asks the bridge for the LSFG feature chain (`VkPhysicalDeviceVulkan12Features` + vulkanMemoryModel + `shaderStorageImageWriteWithoutFormat/ExtendedFormats`, the same chain + `VulkanRendererContext::createLogicalDevice` uses; instance apiVersion is 1.3 for the probe) and + retries device creation without it if the driver refuses. Win-FG needs only a storage-capable ring + format (RGBA8). The generation ring (`STORAGE|SAMPLED|TRANSFER_SRC|DST`, GENERAL) and the engines' + own history live for the session; arming/disarming is a flag, a multiplier change resizes the ring. +- **FPS limiter / vsync**: untouched. The limiter still paces the game's buffer returns (real frames); + `applyNativeFgLocks` forces it on while multiplying, exactly as on X11 (`pacedLimitWithSlack` still + applies through `nativeSetFpsLimit`). Generated frames never touch the limiter, the frame callbacks + or the `wp_presentation` feedback - the guest sees one present per real frame. +- **Zero-copy**: the layer bypasses the compositor pass, so while frame generation is armed the + fullscreen window takes the copy path (`render_scene`: `framegen zero-copy paused: frame generation + needs the compositor pass`) and the layer resumes when both it and the effects are off (see the + effects section's zero-copy interplay). +- **App side**: `WaylandCompositor.nativeSetFrameGenEngine/Armed/Tuning`, `nativeSetLsfgCachePath`, + `nativeSetWinFgTuning`, `nativeFrameGenProblem/CapsReason/Stats` (same codes and six-float shape + as `VulkanRenderer`). `XServerDisplayActivity.applyWaylandFrameGen` is the single apply: + `applyLsfgNative`/`applyWinFgNative` route to it in Wayland mode (launch and drawer), the drawer's + `onBionicFgConfigChange` has a Wayland branch, `nativeFgProblemReason`/`startLsfgStatsReadout` read + the bridge. Every native setter is a value store, so the launch code may arm before the compositor + thread exists. +- **Log tag `framegen`**: `engines ready on the compositor's device: LSFG Native available (supported), + Win-FG Native available`, `<engine> engine ready (...)`, `<engine> x2 armed (flow scale 0.80, panel + 120 Hz): ...`, `generating: <engine> x2 at 1920x1080 (1 interpolated frame per game frame)`, the + fallbacks (`... can't start: no shader cache`, `... failed to start on the compositor's driver`, + `... could not build its chain at WxH`, `the driver refused the LSFG feature set`), `frame generation + off (N frames generated this session)`, and the zero-copy pause/resume above. The 10 s `stats` line + counts generated frames in `frames on screen` and ends with `| N generated frames`; `GPU frames from + games` never includes them. diff --git a/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md b/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md new file mode 100644 index 0000000000..ff52f31b02 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/ZERO_COPY_SPIKE.md @@ -0,0 +1,309 @@ +# Zero-copy window layers on Wayland — research spike + host-side prototype + +Branch `spike/wayland-zero-copy-layers` (on `feat/wayland-phase2`). Written 2026-09-13. + +**Question.** Today every game frame is a dma-buf the compositor imports as a `VkImage` +(`vk_present.c: vkp_image_from_dmabuf`) and blits into its own swapchain (`vkp_render`), one +full-screen copy per frame, and the FPS gap to X11 on the AIO is ~20 % for Vulkan/D3D12 +(596 vs 752, 336 vs 430 on the Adreno 750). Wayland lets each window buffer become its own +Android layer (`ASurfaceControl` + `AHardwareBuffer`) so SurfaceFlinger/the DPU composites it +with no copy. The blocker: dma-buf ↔ `AHardwareBuffer` interop on Turnip/KGSL/bionic/Android 14, +with the game on the Wayland Turnip bundled in the Proton wcp and the compositor on the +adrenotools Turnip. + +**Answer in one paragraph.** A raw dma-buf can never become an `AHardwareBuffer` (option b is +closed: no public API, and the game's buffers are `/dev/dma_heap/system` allocations, not +gralloc buffers). The interop must go the other way: the buffer is a **gralloc `AHardwareBuffer` +first**, and its dma-buf fd (`native_handle->data[0]`) is what the Vulkan drivers import — which is +exactly how Turnip already imports every gralloc buffer on Android (`vk_android.c`). Both Turnips +in play already have every extension needed; nothing is missing in the drivers. What is missing is +a **WSI hook**: Mesa's Wayland WSI always allocates its own dma-bufs and has no way to receive or +allocate compositor-visible buffers, so **option (a) or (c) each need a ~300-line patch to +`wsi_common_wayland.c` in our own Wayland Turnip build** (banners-turnip-wayland +`build_turnip_wayland_wsi.sh`, Mesa `7cda7850`) plus a small private Wayland protocol. Nothing in +the app can remove the copy on its own. Recommended: **option (a′) — the game's WSI allocates its +swapchain images as `AHardwareBuffer`s (gralloc-native, UBWC), imports them through the AHB path +Turnip already has, and hands the compositor the AHB over a Unix socket (`AHardwareBuffer_send/ +recvHandleFromUnixSocket`, the same mechanism the X11 renderer already uses for `GPUImage`) plus +the dma-buf fd through `zwp_linux_dmabuf_v1` as today (so the blit path stays as the fallback).** +The host half — one `ASurfaceControl` layer per fullscreen window, geometry from the fullscreen +mode, release fences from `ASurfaceTransaction_setOnComplete`, black base surface, HUD/pointer as +Android views above — is implemented in this branch as a gated prototype (`sc_layer.c`, +`BANNER_WAYLAND_ZERO_COPY=1`) with a compositor-owned AHB pool and one blit, so the +SurfaceFlinger side can be measured on the device before the driver work starts. + +--- + +## 1. Buffer path options + +Facts the options rest on (Mesa `7cda7850`, the commit both Turnips are built from): + +- **Game-side buffers today** are dma-bufs from a DMA heap: the KGSL winsys allocates exportable + memory with `DMA_HEAP_IOCTL_ALLOC` on `/dev/dma_heap/system` (ION on older kernels) and imports + the fd into KGSL with `IOCTL_KGSL_GPUOBJ_IMPORT` / `KGSL_USER_MEM_TYPE_DMABUF` + (`tu_knl_kgsl.cc:84-107`, `279-296`, `375-436`, `1836-1856`); export is a `dup()` of that fd + (`kgsl_bo_export_dmabuf`, `:438-442`). They are **not gralloc buffers**: no `private_handle_t`, + no metadata fd, nothing SurfaceFlinger's mapper could import. +- **Dma-buf import works on both Turnips**: `VK_KHR_external_memory_fd`, + `VK_EXT_external_memory_dma_buf`, `VK_EXT_image_drm_format_modifier` are unconditional + (`tu_device.cc:253, 354, 369`); the compositor proves it every frame. Only + `VK_EXT_physical_device_drm` is off on KGSL (`:385`) — relevant to dmabuf-v4 feedback (§2). +- **AHB import in Turnip is dma-buf import.** `VK_ANDROID_external_memory_android_hardware_buffer` + is exposed whenever a u_gralloc backend exists (`tu_device.cc:219, 428`), and the fallback backend + always exists. `vkGetAndroidHardwareBufferPropertiesANDROID` does + `AHardwareBuffer_getNativeHandle(buffer)->data[0]` → `lseek` for the size → + `GetMemoryFdPropertiesKHR(DMA_BUF, data[0])` (`vk_android.c:1225-1236`); the image is created with + `VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT` from the gralloc layout + (`vk_gralloc_to_drm_explicit_layout`, `vk_android.c:140-205`; `tu_image.cc:1006-1023`). The + layout comes from `u_gralloc_fallback.c:145-156`: on a QTI handle (magic `'gmsm'` in the first + int) the UBWC flag `0x08000000` in the next int selects `DRM_FORMAT_MOD_QCOM_COMPRESSED`, else + `DRM_FORMAT_MOD_LINEAR`; pitch = `pixel_stride × bpp`, offset 0. The qcom backend + (`u_gralloc_qcom.c`, `hw_get_module`) cannot load the vendor gralloc from an app process, so the + fallback is the one in use — the local KGSL build imports exactly `AHardwareBuffer_allocate / + describe / getNativeHandle / acquire / release / isSupported` and `hw_get_module`, NEEDED + `libnativewindow.so` + `libhardware.so` (readelf on `turnip608/stg/libvulkan_freedreno.so`). + So **the Wine process already loads `libnativewindow.so`** (as a dependency of the ICD), and + the X11 renderer already receives AHBs allocated inside guest processes over a Unix socket + (`DRI3Extension.java:141-150` → `GPUImage(fd)` → `gpu_image.c:74-86` + `AHardwareBuffer_recvHandleFromUnixSocket`; the sender is the X11 `libvulkan_wrapper.so` WSI). + +### (a) Game side: `AHardwareBuffer_allocate` in the guest, exported as a dma-buf + +Feasible with the current drivers, **but only through a WSI patch** — the app cannot do it. +Mesa's Wayland WSI creates every native swapchain image with `wsi_create_native_image_mem` +(`wsi_common_drm.c:760-850`): `vkAllocateMemory` with `VkExportMemoryAllocateInfo{DMA_BUF}` → +`vkGetMemoryFdKHR` → `zwp_linux_buffer_params_v1.add(fd, …)` + `create_immed` +(`wsi_common_wayland.c:3558-3620`). Nothing in it allocates from gralloc, and `VkNativeBufferANDROID` +(the Android-WSI import path, `tu_image.cc:880-925`) is only reachable from the Android swapchain. + +The patch (in our Wayland Turnip build): a new `create_mem` for the Wayland chain, selected when the +compositor advertises a private global `banner_layer_buffer_v1`: +1. `AHardwareBuffer_allocate(w, h, R8G8B8A8, GPU_COLOR_OUTPUT | GPU_SAMPLED_IMAGE)`; + `vkGetAndroidHardwareBufferPropertiesANDROID` → `vkAllocateMemory` with + `VkImportAndroidHardwareBufferInfoANDROID` (Turnip: `tu_device.cc:3828`), bind — the image was + created with the modifier/pitch gralloc reports, i.e. UBWC on Adreno gralloc (§2). +2. `wsi_image.dma_buf_fd = dup(native_handle->data[0])`, `drm_modifier` / `row_pitches[0]` from + the same layout → the existing `zwp_linux_dmabuf_v1` path stays untouched: the compositor keeps + importing a dma-buf and can keep the blit path as the fallback. +3. `banner_layer_buffer_v1.attach(wl_buffer, socket_fd)`: the WSI creates a `socketpair`, sends one + end in the request, and calls `AHardwareBuffer_sendHandleToUnixSocket(ahb, other_end)`; the + compositor's request handler does `AHardwareBuffer_recvHandleFromUnixSocket` and stores the AHB + on `struct dmabuf_buffer`. Per swapchain image, once — not per frame. +Extensions used by the game: `VK_ANDROID_external_memory_android_hardware_buffer` only (the +dma-buf/modifier extensions are used internally by the same driver). Note winevulkan does not +expose the AHB extension to PE code — irrelevant here, the WSI is unix-side inside the ICD. +Effort: 2–3 days WSI + protocol + wcp rebuild (wine-compat-engineer for the packaging). + +### (b) Import the game's existing dma-buf as an `AHardwareBuffer` + +**No.** There is no public API: `AHardwareBuffer_createFromHandle` exists only in +`vndk/hardware_buffer.h` (exported by `libnativewindow.so`, so `dlsym` finds it), but it takes a +gralloc `native_handle_t` that the vendor mapper (`IMapper::importBuffer`) validates — on QTI a +`private_handle_t` with the `'gmsm'` magic, a metadata dma-buf, and vendor-specific ints. The game's +buffers are bare DMA-heap fds. Fabricating a vendor handle around a foreign fd is unversioned +private ABI (differs across gralloc4 releases/OEMs) and is exactly the kind of thing that +reboots non-Adreno/old SoCs. `AHardwareBuffer_createFromHandle` also requires the caller to be +in the VNDK namespace for its stub; only `dlsym` reaches it. Rejected. + +### (c) Compositor-owned pool offered to the game + +Compositor allocates AHBs, gets the fd from the native handle, and the game imports them. On the +game side this is the same driver path as (a) minus gralloc (`VK_EXT_external_memory_dma_buf` + +explicit modifier/pitch from the compositor). It **still needs the same WSI patch** (a `create_mem` +that imports instead of exports) and in addition a protocol to carry `fd + modifier + pitch + size` +before the swapchain image is created, plus reallocation on `vkCreateSwapchainKHR` (size changes), +plus fence plumbing in both directions. `zwp_linux_dmabuf_v1` v4 feedback cannot express this (it +only steers format/modifier/device; the client still allocates), and on KGSL v4 is a trap anyway: +the driver has no DRM `dev_t`, so `same_gpu` stays false (`wsi_common_wayland.c:1660-1686`) and +Mesa takes the prime-blit path (one extra copy per frame). The one advantage over (a) — the +compositor decides linear vs UBWC — is moot because gralloc's decision is the right one for the DPU. +Effort: 3–4 days; strictly more moving parts than (a). Not recommended. + +**Recommendation: (a).** It reuses two proven mechanisms (Turnip's AHB import, the X11 path's +AHB-over-socket), keeps `zwp_linux_dmabuf_v1` as the fallback transport, and confines the new code +to our own Mesa build plus one small protocol. + +## 2. Modifiers / UBWC + +- Turnip advertises exactly two modifiers: `DRM_FORMAT_MOD_LINEAR` and + `DRM_FORMAT_MOD_QCOM_COMPRESSED` (UBWC), the latter whenever the format tiles and + `ubwc_possible()` (`tu_formats.cc:416-443`); explicit-modifier images accept only these two + (`:530-575`). `QCOM_COMPRESSED` forces UBWC (`tu_image.cc:723-727`); an explicit plane layout is + validated by `fdl6_layout_image` and rejected with + `VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT` if the pitch does not fit + (`:762-806`). Export/import of both is symmetric (same driver, same `fdl6` layout). +- The compositor advertises `LINEAR` and `INVALID` only (`compositor.c: bind_dmabuf`, + `uint64_t mods[] = {MOD_LINEAR, MOD_INVALID}`); `INVALID` is dropped by the WSI + (`wsi_common_wayland.c:449-451`), so every game swapchain is linear today. DXVK/VKD3D render to + their own tiled/UBWC targets and copy into the linear swapchain image at present — a full-frame + linear write per frame on the game side, on top of the compositor's blit. This is a real part of + the 20 %. +- Advertising `QCOM_COMPRESSED` as well: one line in `bind_dmabuf`. The WSI intersects the + compositor's list with the driver's (`wsi_common_drm.c:686-733`) and Turnip prefers UBWC when + offered; `vkp_image_from_dmabuf` already passes any modifier through. Two cautions: the pitch + the game sends is the UBWC pixel-plane pitch (Mesa reports plane 0 of the modifier, `:817-830`) + and both sides run the same `fdl6` code, so the import must succeed on the same GPU; and a + UBWC buffer must never be read by the CPU path (`wl_shm` is unaffected). This is independent of + layers and worth its own A/B (experiment plan step 0). +- For layers the buffer is gralloc's, so UBWC is decided by gralloc: QTI allocates UBWC for + `GPU_COLOR_OUTPUT` RGBA8 unless a CPU usage bit is set (the prototype exploits exactly that: + `sc_layer.c: alloc_slot` retries with `CPU_READ_RARELY` when a UBWC import fails). The DPU + scans out UBWC RGBA natively; a prior device experiment (GL native rendering, 2026-06-29) + found the SDE pipes accepted both UBWC and linear layers — rotation+scale was the blocker, not + UBWC. + +## 3. Per-layer composition (design; the prototype implements the single-layer subset) + +- **wl_surface → SurfaceControl.** One `ASurfaceControl_createFromWindow(surfaceView_window, + name)` child per mapped toplevel (and per subsurface tree flattened per toplevel); the desktop + surface is the base layer at z 0 (or, with `g_hide_shell`, a black base — the SurfaceView's own + buffer); toplevels get `setZOrder` from the `g_toplevels` order (`apply_zorder`), with + `INT_MAX` reserved for the app's cursor/HUD if they ever move native. Position/scale: + `ASurfaceTransaction_setGeometry(src = buffer rect, dst = output rect, transform 0)`, with the + output rect produced by the same `update_map()` / `draw_to_blit()` arithmetic the blit path uses + (`vk_present.c: vkp_map_draw`) — letterbox/FILL crop/TOP-BOTTOM half all come out identical, so + **input stays consistent by construction**: the app maps touch through `ViewTransformation` + with the same inputs (see `WAYLAND_RUNTIME.md` "Fullscreen mode"), and the compositor's own + `vkp_output_to_scene` keeps working because the map is still updated every frame. + `setBufferTransparency(OPAQUE)` for XR24/XB24; `setBufferTransform` stays 0 — the DPU refuses + rotation+scale on one pipe (prior experiment), so a rotated panel must be handled by the + activity's orientation, not the layer. +- **HUD.** Already a separate layer: `PerfHudView`/`FrameRating`/cursor are Android views in + `rootView` above `waylandSurfaceView`, i.e. the ViewRoot's SurfaceFlinger layer above the + SurfaceView and all its child SurfaceControls. Nothing to do; the prototype keeps it. +- **Vsync / frame callbacks.** Keep the app's Choreographer tick (`nativeVsync`) as the pacing + edge: on each tick the compositor applies **one transaction** containing every surface that + committed since the last tick (`setBuffer` per changed layer, geometry/z for changed ones), then + fires `wl_callback.done` for those surfaces (as today, `fire_all_frames`). `wp_presentation` + feedback moves from "after our present" to the transaction's `ASurfaceTransaction_setOnComplete` + → `ASurfaceTransactionStats_getLatchTime` / `getPresentFenceFd` (API 29) give the real on-glass + time — better than today's `now_ns()`; `setFrameTimeline` (API 33) can be added later for + `VK_GOOGLE_display_timing` work. Without a window, `pace_without_output` stays as is. +- **`wl_buffer.release` timing.** Today a replaced buffer is released on the limiter's cadence, + which is safe because the blit was waited for. With layers the buffer is on the display until + SurfaceFlinger says otherwise: keep the buffer un-released until the OnComplete callback of the + transaction that **replaced** it delivers `ASurfaceTransactionStats_getPreviousReleaseFenceFd` + (this is what `ASurfaceRendererContext::transactionCompleteCallback` does), wait that fence on + the compositor thread (or, better, hand it to the game: with option (a) the WSI can import it as + the `WSI_ES_RELEASE` point — Turnip/KGSL implements `vk_sync.import_sync_file`, + `tu_knl_kgsl.cc:1261-1303`), then `wl_buffer_send_release`. The FPS limiter keeps working: it only + delays the release further. Android 16's `setBufferWithRelease` is not available on 14. +- **Acquire fence.** Two sources: (1) if the kernel supports `DMA_BUF_IOCTL_EXPORT_SYNC_FILE` + (6.x GKI), the WSI already attaches its present semaphore to the dma-buf as a sync_file + (`wsi_drm_init_swapchain_implicit_sync`, `wsi_common_drm.c:368-395`, gated on the driver + exporting `SYNC_FD` semaphores — KGSL does, `:1278-1303`), and the compositor can + `EXPORT_SYNC_FILE(READ)` it and pass the fd to `setBuffer` — the prototype probes this on the + first frame and logs the answer; (2) otherwise the option-(a) protocol carries a sync_fd per + present (`vkGetSemaphoreFdKHR`), which is what the X11 wrapper does. Never `-1` for a real + zero-copy frame. +- **Lifecycle.** SurfaceView destroyed/recreated (background, rotation): `vkp_apply_window_request` + already serialises window changes on the compositor thread; the layer code retires its + SurfaceControls (hide + `reparent(NULL)` + release in the OnComplete callback) and recreates + them on the new window. Buffers stay valid across that (gralloc buffers are process-independent + refcounted objects), so the first frame after resume is the last committed one. + +## 4. Risks + +- **HWC fallback to GPU composition** (the whole point is DEVICE composition). Known from the + 2026-06-29 experiments on the Adreno 750 device: a layer with `transform 90` **and** scale went + CLIENT and dragged the base layer with it; the same layer pre-rotated at panel resolution with + src == dst was DEVICE on every layer, GPU_TARGET empty. So: no SurfaceControl rotation ever; on + a landscape-native panel (handheld) the identity-transform game layer with a DPU scale should + promote; on a portrait phone in landscape it will not, and the base swapchain path is the better + one there — decide per device by measurement, not by assumption. Measure with + `dumpsys SurfaceFlinger` (layer `composition: DEVICE/DEVICE` vs `DEVICE/CLIENT`, and the SDE pipe + table `GPU_TARGET` line) with the app foreground and the drawer closed. +- **Layer count.** The DPU has a handful of pipes (4–8 usable RGB pipes on SDM/SM8xxx); 2–3 game + layers + base + HUD + cursor is fine, a desktop with 10 windows is not — SurfaceFlinger then + composites the overflow on the GPU (still correct, just no gain). Policy: layers only for + fullscreen/topmost windows, everything else stays in the base swapchain (the prototype's rule). +- **Buffer ownership across processes.** The game's `AHardwareBuffer` is alive in the guest; the + compositor's received copy holds its own gralloc reference, SurfaceFlinger a third. A guest crash + mid-present leaves SurfaceFlinger with a valid buffer (no black flash). Fds: one dma-buf fd + one + socket per swapchain image; clean up on `wl_buffer` destroy (today's `dmabuf_buffer_unref`). +- **Fences.** Passing `-1` acquire fences with a buffer the GPU is still writing shows tearing or + stale content; KGSL has no BO implicit sync, so the sync_file path in §3 is mandatory for the + real thing (the prototype waits on the CPU instead, which is safe). +- **Background / rotation / device lost.** Covered by the window-request serialisation; a device + loss in the compositor's Turnip does not affect layers already on screen (SurfaceFlinger owns + them) — the old path's `device_lost` message stays. +- **Non-Adreno / old SoCs.** Everything here is NDK API 29 + gralloc-allocated buffers; the only + vendor-specific piece is the `'gmsm'` handle sniff, which degrades to "linear with a CPU bit". + Same risk class as the X11 ASR renderer; keep it opt-in until proven on a second SoC. +- **`vk_present.c` stays.** Fallback for: no `ASurfaceControl` API, multi-window scenes, popups + above the game, the first frames before the layer is up, and any device where composition goes + CLIENT. The prototype switches per frame (`layer_candidate` in `compositor.c`). + +## 5. Experiment plan (each step ≤ 1 hour on the device, in order) + +Prerequisite: a build of this branch, container on Wayland, the AIO Graphics Test (Vulkan and +D3D12 tabs) as the workload, session log in `Download/Wayland-logs/`. + +0. **UBWC modifier A/B (no layers).** Done on `feat/wayland-ubwc` (advertised when the compositor's + driver imports it, `BANNER_WAYLAND_UBWC=0` = old linear-only list; see `WAYLAND_RUNTIME.md` + "Compressed (UBWC) game buffers"). Run the AIO Vulkan/D3D12 with and without. Expect + `vulkan: … is presenting GPU frames through Wayland: WxH, format XB24, tiled (zero-copy)` and + no `dmabuf import failed`. Records how much of the 20 % is the linear swapchain alone. +1. **Layer mode smoke.** Put `BANNER_WAYLAND_ZERO_COPY=1` in the container's environment + variables, launch the AIO fullscreen. Expected log lines (tag `layer`): + `SurfaceControl "banner_wayland_game" created as a child of the screen surface`, + `pool buffer 1920x1080 UBWC (QCOM_COMPRESSED), stride 1920 px (gralloc handle 2 fds / N ints)` + (or `linear` after `import of a UBWC … failed` — also a result: it tells whether the compositor + Turnip accepts gralloc's UBWC pitch), `geometry: buffer 0,0-1920,1080 -> screen …`, + `presenting 1920x1080 game frames on their own SurfaceControl layer (UBWC pool, 3 buffers)`, + and the probe line `kernel exports sync_file fences from the game's dma-buf …` or + `DMA_BUF_IOCTL_EXPORT_SYNC_FILE … failed (…)`. Picture correct, HUD and pointer on top, fullscreen + mode changes move the layer (`geometry:` lines). +2. **Composition type.** With the AIO running: `dumpsys SurfaceFlinger | grep -A3 banner_wayland_game` + and the `GPU_TARGET` line of the pipe table. DEVICE/DEVICE on the game layer with an empty GPU + target = the DPU does the scaling; CLIENT = no gain on this panel orientation → try the + handheld's native orientation / a resolution equal to the panel's. +3. **Cost of the host copy.** AIO Vulkan fps with the flag on vs off (same cost expected ± noise, + since the blit only changed its destination) and `dumpsys gfxinfo`/battery for 5 min each. This + is the baseline the WSI patch is measured against. +4. **Fence probe outcome → choose the acquire-fence design** (§3) before starting the WSI patch. +5. **WSI patch (option a) in banners-turnip-wayland**, wcp rebuild, then the same steps 1–3 with + the AHB arriving from the guest: log line to add on the compositor side `layer: buffer N of + "<window>" received from the game (AHardwareBuffer WxH, UBWC)` and the fps delta vs X11. + +Work estimates: step 0 = 0.5 day incl. A/B; host layer prototype = done (this branch, ~1 day to +harden: async fence instead of CPU wait, per-window layers, presentation feedback from +`getLatchTime`); option (a) WSI + protocol + wcp = 2–3 days + 1 day device proving; option (c) = +3–4 days + the same proving; (b) = not buildable. + +## 6. What the prototype in this branch does (`BANNER_WAYLAND_ZERO_COPY=1`) + +Files: `src/sc_layer.{c,h}` (new), `src/vk_present.{c,h}` (`vkp_image_import_dmabuf` with a +blit-destination role, `vkp_blit_image`, `vkp_update_map`, `vkp_map_draw`, `vkp_window`, +`vkp_signal_first_frame`; the layer is retired on window changes), `src/compositor.c` +(`g_zero_copy`, `layer_candidate`, the `render_scene` branch, the dma-buf sync_file probe), +`src/waylandcomp_jni.c` + `WaylandCompositor.java` (`nativeSetZeroCopy`), +`XServerDisplayActivity.startWaylandCompositor` (reads the flag from the container's / shortcut's +environment variables before the compositor starts). + +Behaviour: when the topmost draw is a client GPU frame covering the whole scene (one fullscreen +game, nothing above it), the screen swapchain is presented black and the frame is blitted (1:1, +`vkCmdBlitImage`, CPU-waited) into one of three compositor-allocated `AHardwareBuffer`s +(R8G8B8A8, `GPU_COLOR_OUTPUT | GPU_SAMPLED_IMAGE`, imported into the compositor's Turnip through +its native-handle dma-buf fd with the modifier from the `'gmsm'` sniff, linear fallback), which +is set on a child `ASurfaceControl` of the SurfaceView with the fullscreen-mode geometry, z 1, +opaque. `setOnComplete` returns the previous buffer's release fence, which is waited on before +that pool slot is reused; no free slot = frame dropped (logged at most every 5 s). Any other scene +hides the layer and draws the old way; the layer is retired when the SurfaceView goes away. +Everything else (frame callbacks, presentation feedback, FPS limiter, HUD counting, input) is +unchanged. Off by default: with the variable unset no new code runs. + +Not zero-copy yet — it is the receive side. The copy disappears when step 5 lands and +`sc_layer_present` is handed the game's own `AHardwareBuffer` instead of a pool slot. + +## 7. Step 5 implemented (feat/wayland-zero-copy-wsi + banners-turnip-wayland `banner_ahb_wsi.py`) + +Option (a′) as recommended, with one deviation forced by the build: the Wayland Turnip is a +`platforms=wayland` build with Android detection off, so `VK_ANDROID_external_memory_android_hardware_buffer` +/ `vk_android.c` do not exist in it. The WSI therefore allocates the `AHardwareBuffer` itself +(`libnativewindow.so` dlopen'd), sniffs the gralloc handle for UBWC exactly like `u_gralloc_fallback.c`, +and imports `native_handle->data[0]` as a dma-buf with an explicit modifier + pitch — the same path +this compositor's pool uses (`vkp_image_import_dmabuf`) — after a test `vkCreateImage` proves the +driver accepts that layout (linear retry otherwise). Fences: implicit via the dma-buf in both +directions (§3's option 1, proven by the probe; the compositor imports SurfaceFlinger's release +fence back into the dma-buf before `wl_buffer.release`). Details in `WAYLAND_RUNTIME.md`. diff --git a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c new file mode 100644 index 0000000000..08e5d76e0f --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-protocol.c @@ -0,0 +1,69 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright 2026 The412Banner + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_buffer_interface; + +static const struct wl_interface *banner_ahb_v1_types[] = { + NULL, + &wl_buffer_interface, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +}; + +static const struct wl_message banner_ahb_v1_requests[] = { + { "destroy", "", banner_ahb_v1_types + 0 }, + { "attach", "ohuuuuuu", banner_ahb_v1_types + 1 }, +}; + +static const struct wl_message banner_ahb_v1_events[] = { + { "mode", "2u", banner_ahb_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface banner_ahb_v1_interface = { + "banner_ahb_v1", 2, + 2, banner_ahb_v1_requests, + 1, banner_ahb_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h new file mode 100644 index 0000000000..a06ea07061 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/banner-ahb-v1-server-protocol.h @@ -0,0 +1,214 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef BANNER_AHB_V1_SERVER_PROTOCOL_H +#define BANNER_AHB_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_banner_ahb_v1 The banner_ahb_v1 protocol + * @section page_ifaces_banner_ahb_v1 Interfaces + * - @subpage page_iface_banner_ahb_v1 - Android gralloc buffers behind dma-buf wl_buffers + * @section page_copyright_banner_ahb_v1 Copyright + * <pre> + * + * Copyright 2026 The412Banner + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct banner_ahb_v1; +struct wl_buffer; + +#ifndef BANNER_AHB_V1_INTERFACE +#define BANNER_AHB_V1_INTERFACE +/** + * @page page_iface_banner_ahb_v1 banner_ahb_v1 + * @section page_iface_banner_ahb_v1_desc Description + * + * Zero-copy window layers on Android. A Vulkan swapchain image that the + * client allocated as an Android AHardwareBuffer (gralloc) is still shared + * as a dma-buf through zwp_linux_dmabuf_v1, so the compositor can import + * and draw it the usual way. This interface additionally hands the + * compositor the AHardwareBuffer itself, once per wl_buffer, so the + * compositor can put the buffer straight on an Android SurfaceControl + * layer (SurfaceFlinger / the display hardware composite it) without + * copying it. + * + * The AHardwareBuffer travels over a Unix socket: the client creates a + * socketpair, writes the buffer's handle into one end with + * AHardwareBuffer_sendHandleToUnixSocket, then sends the other end in the + * attach request. The compositor reads it with + * AHardwareBuffer_recvHandleFromUnixSocket and closes the socket. Its + * reference to the AHardwareBuffer lives as long as the wl_buffer (plus + * whatever the display still holds). + * + * The compositor advertises this global whenever it can put buffers on a + * display layer at all; whether it WANTS gralloc buffers right now is the + * mode event (version 2), sent on bind and every time the user switches + * zero-copy on or off during the session. A client decides per swapchain, + * when it creates the swapchain, from the last mode it received, and a + * client whose live swapchain was built for the other mode retires it + * (VK_ERROR_OUT_OF_DATE_KHR on its next acquire or present) so the program + * rebuilds it for the new mode. Buffers of the old swapchain stay fully + * presentable until then: an attached AHardwareBuffer keeps its association + * for the wl_buffer's lifetime whatever the mode is now. A version 1 + * client (no mode event) keeps deciding from its own environment. A + * client that does not see the global (or does not want it) allocates + * swapchain images the standard way; nothing else changes. + * + * Synchronisation stays implicit: the dma-buf carries the client's render + * fence (DMA_BUF_IOCTL_IMPORT_SYNC_FILE by the client's driver), the + * compositor exports it as the layer's acquire fence, and the compositor + * imports the display's release fence into the dma-buf before it sends + * wl_buffer.release, so the client's next acquire waits on it. + * @section page_iface_banner_ahb_v1_api API + * See @ref iface_banner_ahb_v1. + */ +/** + * @defgroup iface_banner_ahb_v1 The banner_ahb_v1 interface + * + * Zero-copy window layers on Android. A Vulkan swapchain image that the + * client allocated as an Android AHardwareBuffer (gralloc) is still shared + * as a dma-buf through zwp_linux_dmabuf_v1, so the compositor can import + * and draw it the usual way. This interface additionally hands the + * compositor the AHardwareBuffer itself, once per wl_buffer, so the + * compositor can put the buffer straight on an Android SurfaceControl + * layer (SurfaceFlinger / the display hardware composite it) without + * copying it. + * + * The AHardwareBuffer travels over a Unix socket: the client creates a + * socketpair, writes the buffer's handle into one end with + * AHardwareBuffer_sendHandleToUnixSocket, then sends the other end in the + * attach request. The compositor reads it with + * AHardwareBuffer_recvHandleFromUnixSocket and closes the socket. Its + * reference to the AHardwareBuffer lives as long as the wl_buffer (plus + * whatever the display still holds). + * + * The compositor advertises this global whenever it can put buffers on a + * display layer at all; whether it WANTS gralloc buffers right now is the + * mode event (version 2), sent on bind and every time the user switches + * zero-copy on or off during the session. A client decides per swapchain, + * when it creates the swapchain, from the last mode it received, and a + * client whose live swapchain was built for the other mode retires it + * (VK_ERROR_OUT_OF_DATE_KHR on its next acquire or present) so the program + * rebuilds it for the new mode. Buffers of the old swapchain stay fully + * presentable until then: an attached AHardwareBuffer keeps its association + * for the wl_buffer's lifetime whatever the mode is now. A version 1 + * client (no mode event) keeps deciding from its own environment. A + * client that does not see the global (or does not want it) allocates + * swapchain images the standard way; nothing else changes. + * + * Synchronisation stays implicit: the dma-buf carries the client's render + * fence (DMA_BUF_IOCTL_IMPORT_SYNC_FILE by the client's driver), the + * compositor exports it as the layer's acquire fence, and the compositor + * imports the display's release fence into the dma-buf before it sends + * wl_buffer.release, so the client's next acquire waits on it. + */ +extern const struct wl_interface banner_ahb_v1_interface; +#endif + +/** + * @ingroup iface_banner_ahb_v1 + * @struct banner_ahb_v1_interface + */ +struct banner_ahb_v1_interface { + /** + * destroy the object + * + * Buffers already attached keep their AHardwareBuffer + * association. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * hand the compositor a buffer's AHardwareBuffer + * + * Associates the AHardwareBuffer readable from socket with the + * (already created) dma-buf wl_buffer. width, height and stride + * (pixels) describe the gralloc allocation; modifier_hi/lo is the + * DRM format modifier the dma-buf was shared with (the same value + * passed to zwp_linux_buffer_params_v1.add); image_count is the + * number of images in the swapchain this buffer belongs to (for + * the compositor's log). Sent once per wl_buffer, before the + * buffer is first attached to a surface. + * @param buffer the dma-buf wl_buffer + * @param socket socket the AHardwareBuffer handle was written to + * @param width buffer width in pixels + * @param height buffer height in pixels + * @param stride gralloc row stride in pixels + * @param modifier_hi high 32 bits of the DRM format modifier + * @param modifier_lo low 32 bits of the DRM format modifier + * @param image_count images in the client's swapchain + */ + void (*attach)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *buffer, + int32_t socket, + uint32_t width, + uint32_t height, + uint32_t stride, + uint32_t modifier_hi, + uint32_t modifier_lo, + uint32_t image_count); +}; + +#define BANNER_AHB_V1_MODE 0 + +/** + * @ingroup iface_banner_ahb_v1 + */ +#define BANNER_AHB_V1_MODE_SINCE_VERSION 2 + +/** + * @ingroup iface_banner_ahb_v1 + */ +#define BANNER_AHB_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_banner_ahb_v1 + */ +#define BANNER_AHB_V1_ATTACH_SINCE_VERSION 1 + +/** + * @ingroup iface_banner_ahb_v1 + * Sends an mode event to the client owning the resource. + * @param resource_ The client's resource + * @param enabled 1 = gralloc swapchain images wanted, 0 = not + */ +static inline void +banner_ahb_v1_send_mode(struct wl_resource *resource_, uint32_t enabled) +{ + wl_resource_post_event(resource_, BANNER_AHB_V1_MODE, enabled); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-protocol.c new file mode 100644 index 0000000000..9ed8996dd9 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-protocol.c @@ -0,0 +1,64 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright 2026 The412Banner + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_surface_interface; + +static const struct wl_interface *banner_desktop_v1_types[] = { + NULL, + &wl_surface_interface, + &wl_surface_interface, + NULL, + NULL, + NULL, +}; + +static const struct wl_message banner_desktop_v1_requests[] = { + { "destroy", "", banner_desktop_v1_types + 0 }, + { "set_desktop", "o", banner_desktop_v1_types + 1 }, + { "set_window", "ouii", banner_desktop_v1_types + 2 }, + { "set_zorder", "a", banner_desktop_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface banner_desktop_v1_interface = { + "banner_desktop_v1", 1, + 4, banner_desktop_v1_requests, + 0, NULL, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-server-protocol.h new file mode 100644 index 0000000000..f2608a46e2 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/banner-desktop-v1-server-protocol.h @@ -0,0 +1,142 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef BANNER_DESKTOP_V1_SERVER_PROTOCOL_H +#define BANNER_DESKTOP_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_banner_desktop_v1 The banner_desktop_v1 protocol + * @section page_ifaces_banner_desktop_v1 Interfaces + * - @subpage page_iface_banner_desktop_v1 - Windows virtual desktop layout + * @section page_copyright_banner_desktop_v1 Copyright + * <pre> + * + * Copyright 2026 The412Banner + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct banner_desktop_v1; +struct wl_surface; + +#ifndef BANNER_DESKTOP_V1_INTERFACE +#define BANNER_DESKTOP_V1_INTERFACE +/** + * @page page_iface_banner_desktop_v1 banner_desktop_v1 + * @section page_iface_banner_desktop_v1_desc Description + * + * Each Wine process is a separate Wayland client, so a Windows virtual + * desktop can't be built from subsurfaces. Instead the process that owns + * the desktop window marks one surface as the desktop, and every process + * reports where its top-level windows sit on that desktop and the global + * window stacking order. The compositor draws the desktop at the bottom, + * the windows at the reported positions, and sends pointer and keyboard + * input to the desktop surface; Wine routes it to the right window. + * @section page_iface_banner_desktop_v1_api API + * See @ref iface_banner_desktop_v1. + */ +/** + * @defgroup iface_banner_desktop_v1 The banner_desktop_v1 interface + * + * Each Wine process is a separate Wayland client, so a Windows virtual + * desktop can't be built from subsurfaces. Instead the process that owns + * the desktop window marks one surface as the desktop, and every process + * reports where its top-level windows sit on that desktop and the global + * window stacking order. The compositor draws the desktop at the bottom, + * the windows at the reported positions, and sends pointer and keyboard + * input to the desktop surface; Wine routes it to the right window. + */ +extern const struct wl_interface banner_desktop_v1_interface; +#endif + +/** + * @ingroup iface_banner_desktop_v1 + * @struct banner_desktop_v1_interface + */ +struct banner_desktop_v1_interface { + /** + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * mark a surface as the virtual desktop + * + * The surface is drawn at the origin, below every window, and + * sets the size of the desktop. + */ + void (*set_desktop)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *surface); + /** + * place a top-level window on the desktop + * + * Position of the top-left corner of the surface in desktop + * coordinates, and the window handle used by set_zorder. + */ + void (*set_window)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *surface, + uint32_t hwnd, + int32_t x, + int32_t y); + /** + * report the desktop's window stacking order + * + * Visible top-level window handles as 32-bit values, topmost + * first. + */ + void (*set_zorder)(struct wl_client *client, + struct wl_resource *resource, + struct wl_array *hwnds); +}; + + +/** + * @ingroup iface_banner_desktop_v1 + */ +#define BANNER_DESKTOP_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_banner_desktop_v1 + */ +#define BANNER_DESKTOP_V1_SET_DESKTOP_SINCE_VERSION 1 +/** + * @ingroup iface_banner_desktop_v1 + */ +#define BANNER_DESKTOP_V1_SET_WINDOW_SINCE_VERSION 1 +/** + * @ingroup iface_banner_desktop_v1 + */ +#define BANNER_DESKTOP_V1_SET_ZORDER_SINCE_VERSION 1 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/color-management-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/color-management-v1-protocol.c new file mode 100644 index 0000000000..ff31f8a411 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/color-management-v1-protocol.c @@ -0,0 +1,216 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright 2019 Sebastian Wick + * Copyright 2019 Erwin Burema + * Copyright 2020 AMD + * Copyright 2020-2024 Collabora, Ltd. + * Copyright 2024 Xaver Hugl + * Copyright 2022-2025 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_output_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface wp_color_management_output_v1_interface; +extern const struct wl_interface wp_color_management_surface_feedback_v1_interface; +extern const struct wl_interface wp_color_management_surface_v1_interface; +extern const struct wl_interface wp_image_description_creator_icc_v1_interface; +extern const struct wl_interface wp_image_description_creator_params_v1_interface; +extern const struct wl_interface wp_image_description_info_v1_interface; +extern const struct wl_interface wp_image_description_v1_interface; + +static const struct wl_interface *color_management_v1_types[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &wp_color_management_output_v1_interface, + &wl_output_interface, + &wp_color_management_surface_v1_interface, + &wl_surface_interface, + &wp_color_management_surface_feedback_v1_interface, + &wl_surface_interface, + &wp_image_description_creator_icc_v1_interface, + &wp_image_description_creator_params_v1_interface, + &wp_image_description_v1_interface, + &wp_image_description_v1_interface, + &wp_image_description_v1_interface, + NULL, + &wp_image_description_v1_interface, + &wp_image_description_v1_interface, + &wp_image_description_v1_interface, + &wp_image_description_v1_interface, + &wp_image_description_info_v1_interface, +}; + +static const struct wl_message wp_color_manager_v1_requests[] = { + { "destroy", "", color_management_v1_types + 0 }, + { "get_output", "no", color_management_v1_types + 8 }, + { "get_surface", "no", color_management_v1_types + 10 }, + { "get_surface_feedback", "no", color_management_v1_types + 12 }, + { "create_icc_creator", "n", color_management_v1_types + 14 }, + { "create_parametric_creator", "n", color_management_v1_types + 15 }, + { "create_windows_scrgb", "n", color_management_v1_types + 16 }, +}; + +static const struct wl_message wp_color_manager_v1_events[] = { + { "supported_intent", "u", color_management_v1_types + 0 }, + { "supported_feature", "u", color_management_v1_types + 0 }, + { "supported_tf_named", "u", color_management_v1_types + 0 }, + { "supported_primaries_named", "u", color_management_v1_types + 0 }, + { "done", "", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_color_manager_v1_interface = { + "wp_color_manager_v1", 1, + 7, wp_color_manager_v1_requests, + 5, wp_color_manager_v1_events, +}; + +static const struct wl_message wp_color_management_output_v1_requests[] = { + { "destroy", "", color_management_v1_types + 0 }, + { "get_image_description", "n", color_management_v1_types + 17 }, +}; + +static const struct wl_message wp_color_management_output_v1_events[] = { + { "image_description_changed", "", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_color_management_output_v1_interface = { + "wp_color_management_output_v1", 1, + 2, wp_color_management_output_v1_requests, + 1, wp_color_management_output_v1_events, +}; + +static const struct wl_message wp_color_management_surface_v1_requests[] = { + { "destroy", "", color_management_v1_types + 0 }, + { "set_image_description", "ou", color_management_v1_types + 18 }, + { "unset_image_description", "", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_color_management_surface_v1_interface = { + "wp_color_management_surface_v1", 1, + 3, wp_color_management_surface_v1_requests, + 0, NULL, +}; + +static const struct wl_message wp_color_management_surface_feedback_v1_requests[] = { + { "destroy", "", color_management_v1_types + 0 }, + { "get_preferred", "n", color_management_v1_types + 20 }, + { "get_preferred_parametric", "n", color_management_v1_types + 21 }, +}; + +static const struct wl_message wp_color_management_surface_feedback_v1_events[] = { + { "preferred_changed", "u", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_color_management_surface_feedback_v1_interface = { + "wp_color_management_surface_feedback_v1", 1, + 3, wp_color_management_surface_feedback_v1_requests, + 1, wp_color_management_surface_feedback_v1_events, +}; + +static const struct wl_message wp_image_description_creator_icc_v1_requests[] = { + { "create", "n", color_management_v1_types + 22 }, + { "set_icc_file", "huu", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_image_description_creator_icc_v1_interface = { + "wp_image_description_creator_icc_v1", 1, + 2, wp_image_description_creator_icc_v1_requests, + 0, NULL, +}; + +static const struct wl_message wp_image_description_creator_params_v1_requests[] = { + { "create", "n", color_management_v1_types + 23 }, + { "set_tf_named", "u", color_management_v1_types + 0 }, + { "set_tf_power", "u", color_management_v1_types + 0 }, + { "set_primaries_named", "u", color_management_v1_types + 0 }, + { "set_primaries", "iiiiiiii", color_management_v1_types + 0 }, + { "set_luminances", "uuu", color_management_v1_types + 0 }, + { "set_mastering_display_primaries", "iiiiiiii", color_management_v1_types + 0 }, + { "set_mastering_luminance", "uu", color_management_v1_types + 0 }, + { "set_max_cll", "u", color_management_v1_types + 0 }, + { "set_max_fall", "u", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_image_description_creator_params_v1_interface = { + "wp_image_description_creator_params_v1", 1, + 10, wp_image_description_creator_params_v1_requests, + 0, NULL, +}; + +static const struct wl_message wp_image_description_v1_requests[] = { + { "destroy", "", color_management_v1_types + 0 }, + { "get_information", "n", color_management_v1_types + 24 }, +}; + +static const struct wl_message wp_image_description_v1_events[] = { + { "failed", "us", color_management_v1_types + 0 }, + { "ready", "u", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_image_description_v1_interface = { + "wp_image_description_v1", 1, + 2, wp_image_description_v1_requests, + 2, wp_image_description_v1_events, +}; + +static const struct wl_message wp_image_description_info_v1_events[] = { + { "done", "", color_management_v1_types + 0 }, + { "icc_file", "hu", color_management_v1_types + 0 }, + { "primaries", "iiiiiiii", color_management_v1_types + 0 }, + { "primaries_named", "u", color_management_v1_types + 0 }, + { "tf_power", "u", color_management_v1_types + 0 }, + { "tf_named", "u", color_management_v1_types + 0 }, + { "luminances", "uuu", color_management_v1_types + 0 }, + { "target_primaries", "iiiiiiii", color_management_v1_types + 0 }, + { "target_luminance", "uu", color_management_v1_types + 0 }, + { "target_max_cll", "u", color_management_v1_types + 0 }, + { "target_max_fall", "u", color_management_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_image_description_info_v1_interface = { + "wp_image_description_info_v1", 1, + 0, NULL, + 11, wp_image_description_info_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/color-management-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/color-management-v1-server-protocol.h new file mode 100644 index 0000000000..08008e8f88 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/color-management-v1-server-protocol.h @@ -0,0 +1,2607 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef COLOR_MANAGEMENT_V1_SERVER_PROTOCOL_H +#define COLOR_MANAGEMENT_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_color_management_v1 The color_management_v1 protocol + * color management protocol + * + * @section page_desc_color_management_v1 Description + * + * The aim of the color management extension is to allow clients to know + * the color properties of outputs, and to tell the compositor about the color + * properties of their content on surfaces. Doing this enables a compositor + * to perform automatic color management of content for different outputs + * according to how content is intended to look like. + * + * The color properties are represented as an image description object which + * is immutable after it has been created. A wl_output always has an + * associated image description that clients can observe. A wl_surface + * always has an associated preferred image description as a hint chosen by + * the compositor that clients can also observe. Clients can set an image + * description on a wl_surface to denote the color characteristics of the + * surface contents. + * + * An image description includes SDR and HDR colorimetry and encoding, HDR + * metadata, and viewing environment parameters. An image description does + * not include the properties set through color-representation extension. + * It is expected that the color-representation extension is used in + * conjunction with the color management extension when necessary, + * particularly with the YUV family of pixel formats. + * + * Recommendation ITU-T H.273 + * "Coding-independent code points for video signal type identification" + * shall be referred to as simply H.273 here. + * + * The color-and-hdr repository + * (https://gitlab.freedesktop.org/pq/color-and-hdr) contains + * background information on the protocol design and legacy color management. + * It also contains a glossary, learning resources for digital color, tools, + * samples and more. + * + * The terminology used in this protocol is based on common color science and + * color encoding terminology where possible. The glossary in the color-and-hdr + * repository shall be the authority on the definition of terms in this + * protocol. + * + * Warning! The protocol described in this file is currently in the testing + * phase. Backward compatible changes may be added together with the + * corresponding interface version bump. Backward incompatible changes can + * only be done by creating a new major version of the extension. + * + * @section page_ifaces_color_management_v1 Interfaces + * - @subpage page_iface_wp_color_manager_v1 - color manager singleton + * - @subpage page_iface_wp_color_management_output_v1 - output color properties + * - @subpage page_iface_wp_color_management_surface_v1 - color management extension to a surface + * - @subpage page_iface_wp_color_management_surface_feedback_v1 - color management extension to a surface + * - @subpage page_iface_wp_image_description_creator_icc_v1 - holder of image description ICC information + * - @subpage page_iface_wp_image_description_creator_params_v1 - holder of image description parameters + * - @subpage page_iface_wp_image_description_v1 - Colorimetric image description + * - @subpage page_iface_wp_image_description_info_v1 - Colorimetric image description information + * @section page_copyright_color_management_v1 Copyright + * <pre> + * + * Copyright 2019 Sebastian Wick + * Copyright 2019 Erwin Burema + * Copyright 2020 AMD + * Copyright 2020-2024 Collabora, Ltd. + * Copyright 2024 Xaver Hugl + * Copyright 2022-2025 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_output; +struct wl_surface; +struct wp_color_management_output_v1; +struct wp_color_management_surface_feedback_v1; +struct wp_color_management_surface_v1; +struct wp_color_manager_v1; +struct wp_image_description_creator_icc_v1; +struct wp_image_description_creator_params_v1; +struct wp_image_description_info_v1; +struct wp_image_description_v1; + +#ifndef WP_COLOR_MANAGER_V1_INTERFACE +#define WP_COLOR_MANAGER_V1_INTERFACE +/** + * @page page_iface_wp_color_manager_v1 wp_color_manager_v1 + * @section page_iface_wp_color_manager_v1_desc Description + * + * A singleton global interface used for getting color management extensions + * for wl_surface and wl_output objects, and for creating client defined + * image description objects. The extension interfaces allow + * getting the image description of outputs and setting the image + * description of surfaces. + * + * Compositors should never remove this global. + * @section page_iface_wp_color_manager_v1_api API + * See @ref iface_wp_color_manager_v1. + */ +/** + * @defgroup iface_wp_color_manager_v1 The wp_color_manager_v1 interface + * + * A singleton global interface used for getting color management extensions + * for wl_surface and wl_output objects, and for creating client defined + * image description objects. The extension interfaces allow + * getting the image description of outputs and setting the image + * description of surfaces. + * + * Compositors should never remove this global. + */ +extern const struct wl_interface wp_color_manager_v1_interface; +#endif +#ifndef WP_COLOR_MANAGEMENT_OUTPUT_V1_INTERFACE +#define WP_COLOR_MANAGEMENT_OUTPUT_V1_INTERFACE +/** + * @page page_iface_wp_color_management_output_v1 wp_color_management_output_v1 + * @section page_iface_wp_color_management_output_v1_desc Description + * + * A wp_color_management_output_v1 describes the color properties of an + * output. + * + * The wp_color_management_output_v1 is associated with the wl_output global + * underlying the wl_output object. Therefore the client destroying the + * wl_output object has no impact, but the compositor removing the output + * global makes the wp_color_management_output_v1 object inert. + * @section page_iface_wp_color_management_output_v1_api API + * See @ref iface_wp_color_management_output_v1. + */ +/** + * @defgroup iface_wp_color_management_output_v1 The wp_color_management_output_v1 interface + * + * A wp_color_management_output_v1 describes the color properties of an + * output. + * + * The wp_color_management_output_v1 is associated with the wl_output global + * underlying the wl_output object. Therefore the client destroying the + * wl_output object has no impact, but the compositor removing the output + * global makes the wp_color_management_output_v1 object inert. + */ +extern const struct wl_interface wp_color_management_output_v1_interface; +#endif +#ifndef WP_COLOR_MANAGEMENT_SURFACE_V1_INTERFACE +#define WP_COLOR_MANAGEMENT_SURFACE_V1_INTERFACE +/** + * @page page_iface_wp_color_management_surface_v1 wp_color_management_surface_v1 + * @section page_iface_wp_color_management_surface_v1_desc Description + * + * A wp_color_management_surface_v1 allows the client to set the color + * space and HDR properties of a surface. + * + * If the wl_surface associated with the wp_color_management_surface_v1 is + * destroyed, the wp_color_management_surface_v1 object becomes inert. + * @section page_iface_wp_color_management_surface_v1_api API + * See @ref iface_wp_color_management_surface_v1. + */ +/** + * @defgroup iface_wp_color_management_surface_v1 The wp_color_management_surface_v1 interface + * + * A wp_color_management_surface_v1 allows the client to set the color + * space and HDR properties of a surface. + * + * If the wl_surface associated with the wp_color_management_surface_v1 is + * destroyed, the wp_color_management_surface_v1 object becomes inert. + */ +extern const struct wl_interface wp_color_management_surface_v1_interface; +#endif +#ifndef WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_INTERFACE +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_INTERFACE +/** + * @page page_iface_wp_color_management_surface_feedback_v1 wp_color_management_surface_feedback_v1 + * @section page_iface_wp_color_management_surface_feedback_v1_desc Description + * + * A wp_color_management_surface_feedback_v1 allows the client to get the + * preferred image description of a surface. + * + * If the wl_surface associated with this object is destroyed, the + * wp_color_management_surface_feedback_v1 object becomes inert. + * @section page_iface_wp_color_management_surface_feedback_v1_api API + * See @ref iface_wp_color_management_surface_feedback_v1. + */ +/** + * @defgroup iface_wp_color_management_surface_feedback_v1 The wp_color_management_surface_feedback_v1 interface + * + * A wp_color_management_surface_feedback_v1 allows the client to get the + * preferred image description of a surface. + * + * If the wl_surface associated with this object is destroyed, the + * wp_color_management_surface_feedback_v1 object becomes inert. + */ +extern const struct wl_interface wp_color_management_surface_feedback_v1_interface; +#endif +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_INTERFACE +#define WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_INTERFACE +/** + * @page page_iface_wp_image_description_creator_icc_v1 wp_image_description_creator_icc_v1 + * @section page_iface_wp_image_description_creator_icc_v1_desc Description + * + * This type of object is used for collecting all the information required + * to create a wp_image_description_v1 object from an ICC file. A complete + * set of required parameters consists of these properties: + * - ICC file + * + * Each required property must be set exactly once if the client is to create + * an image description. The set requests verify that a property was not + * already set. The create request verifies that all required properties are + * set. There may be several alternative requests for setting each property, + * and in that case the client must choose one of them. + * + * Once all properties have been set, the create request must be used to + * create the image description object, destroying the creator in the + * process. + * @section page_iface_wp_image_description_creator_icc_v1_api API + * See @ref iface_wp_image_description_creator_icc_v1. + */ +/** + * @defgroup iface_wp_image_description_creator_icc_v1 The wp_image_description_creator_icc_v1 interface + * + * This type of object is used for collecting all the information required + * to create a wp_image_description_v1 object from an ICC file. A complete + * set of required parameters consists of these properties: + * - ICC file + * + * Each required property must be set exactly once if the client is to create + * an image description. The set requests verify that a property was not + * already set. The create request verifies that all required properties are + * set. There may be several alternative requests for setting each property, + * and in that case the client must choose one of them. + * + * Once all properties have been set, the create request must be used to + * create the image description object, destroying the creator in the + * process. + */ +extern const struct wl_interface wp_image_description_creator_icc_v1_interface; +#endif +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_INTERFACE +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_INTERFACE +/** + * @page page_iface_wp_image_description_creator_params_v1 wp_image_description_creator_params_v1 + * @section page_iface_wp_image_description_creator_params_v1_desc Description + * + * This type of object is used for collecting all the parameters required + * to create a wp_image_description_v1 object. A complete set of required + * parameters consists of these properties: + * - transfer characteristic function (tf) + * - chromaticities of primaries and white point (primary color volume) + * + * The following properties are optional and have a well-defined default + * if not explicitly set: + * - primary color volume luminance range + * - reference white luminance level + * - mastering display primaries and white point (target color volume) + * - mastering luminance range + * + * The following properties are optional and will be ignored + * if not explicitly set: + * - maximum content light level + * - maximum frame-average light level + * + * Each required property must be set exactly once if the client is to create + * an image description. The set requests verify that a property was not + * already set. The create request verifies that all required properties are + * set. There may be several alternative requests for setting each property, + * and in that case the client must choose one of them. + * + * Once all properties have been set, the create request must be used to + * create the image description object, destroying the creator in the + * process. + * @section page_iface_wp_image_description_creator_params_v1_api API + * See @ref iface_wp_image_description_creator_params_v1. + */ +/** + * @defgroup iface_wp_image_description_creator_params_v1 The wp_image_description_creator_params_v1 interface + * + * This type of object is used for collecting all the parameters required + * to create a wp_image_description_v1 object. A complete set of required + * parameters consists of these properties: + * - transfer characteristic function (tf) + * - chromaticities of primaries and white point (primary color volume) + * + * The following properties are optional and have a well-defined default + * if not explicitly set: + * - primary color volume luminance range + * - reference white luminance level + * - mastering display primaries and white point (target color volume) + * - mastering luminance range + * + * The following properties are optional and will be ignored + * if not explicitly set: + * - maximum content light level + * - maximum frame-average light level + * + * Each required property must be set exactly once if the client is to create + * an image description. The set requests verify that a property was not + * already set. The create request verifies that all required properties are + * set. There may be several alternative requests for setting each property, + * and in that case the client must choose one of them. + * + * Once all properties have been set, the create request must be used to + * create the image description object, destroying the creator in the + * process. + */ +extern const struct wl_interface wp_image_description_creator_params_v1_interface; +#endif +#ifndef WP_IMAGE_DESCRIPTION_V1_INTERFACE +#define WP_IMAGE_DESCRIPTION_V1_INTERFACE +/** + * @page page_iface_wp_image_description_v1 wp_image_description_v1 + * @section page_iface_wp_image_description_v1_desc Description + * + * An image description carries information about the color encoding used on + * a surface when attached to a wl_surface via + * wp_color_management_surface_v1.set_image_description. A compositor can use + * this information to decode pixel values into colorimetrically meaningful + * quantities. + * + * Note, that the wp_image_description_v1 object is not ready to be used + * immediately after creation. The object eventually delivers either the + * 'ready' or the 'failed' event, specified in all requests creating it. The + * object is deemed "ready" after receiving the 'ready' event. + * + * An object which is not ready is illegal to use, it can only be destroyed. + * Any other request in this interface shall result in the 'not_ready' + * protocol error. Attempts to use an object which is not ready through other + * interfaces shall raise protocol errors defined there. + * + * Once created and regardless of how it was created, a + * wp_image_description_v1 object always refers to one fixed image + * description. It cannot change after creation. + * @section page_iface_wp_image_description_v1_api API + * See @ref iface_wp_image_description_v1. + */ +/** + * @defgroup iface_wp_image_description_v1 The wp_image_description_v1 interface + * + * An image description carries information about the color encoding used on + * a surface when attached to a wl_surface via + * wp_color_management_surface_v1.set_image_description. A compositor can use + * this information to decode pixel values into colorimetrically meaningful + * quantities. + * + * Note, that the wp_image_description_v1 object is not ready to be used + * immediately after creation. The object eventually delivers either the + * 'ready' or the 'failed' event, specified in all requests creating it. The + * object is deemed "ready" after receiving the 'ready' event. + * + * An object which is not ready is illegal to use, it can only be destroyed. + * Any other request in this interface shall result in the 'not_ready' + * protocol error. Attempts to use an object which is not ready through other + * interfaces shall raise protocol errors defined there. + * + * Once created and regardless of how it was created, a + * wp_image_description_v1 object always refers to one fixed image + * description. It cannot change after creation. + */ +extern const struct wl_interface wp_image_description_v1_interface; +#endif +#ifndef WP_IMAGE_DESCRIPTION_INFO_V1_INTERFACE +#define WP_IMAGE_DESCRIPTION_INFO_V1_INTERFACE +/** + * @page page_iface_wp_image_description_info_v1 wp_image_description_info_v1 + * @section page_iface_wp_image_description_info_v1_desc Description + * + * Sends all matching events describing an image description object exactly + * once and finally sends the 'done' event. + * + * This means + * - if the image description is parametric, it must send + * - primaries + * - named_primaries, if applicable + * - at least one of tf_power and tf_named, as applicable + * - luminances + * - target_primaries + * - target_luminance + * - if the image description is parametric, it may send, if applicable, + * - target_max_cll + * - target_max_fall + * - if the image description contains an ICC profile, it must send the + * icc_file event + * + * Once a wp_image_description_info_v1 object has delivered a 'done' event it + * is automatically destroyed. + * + * Every wp_image_description_info_v1 created from the same + * wp_image_description_v1 shall always return the exact same data. + * @section page_iface_wp_image_description_info_v1_api API + * See @ref iface_wp_image_description_info_v1. + */ +/** + * @defgroup iface_wp_image_description_info_v1 The wp_image_description_info_v1 interface + * + * Sends all matching events describing an image description object exactly + * once and finally sends the 'done' event. + * + * This means + * - if the image description is parametric, it must send + * - primaries + * - named_primaries, if applicable + * - at least one of tf_power and tf_named, as applicable + * - luminances + * - target_primaries + * - target_luminance + * - if the image description is parametric, it may send, if applicable, + * - target_max_cll + * - target_max_fall + * - if the image description contains an ICC profile, it must send the + * icc_file event + * + * Once a wp_image_description_info_v1 object has delivered a 'done' event it + * is automatically destroyed. + * + * Every wp_image_description_info_v1 created from the same + * wp_image_description_v1 shall always return the exact same data. + */ +extern const struct wl_interface wp_image_description_info_v1_interface; +#endif + +#ifndef WP_COLOR_MANAGER_V1_ERROR_ENUM +#define WP_COLOR_MANAGER_V1_ERROR_ENUM +enum wp_color_manager_v1_error { + /** + * request not supported + */ + WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE = 0, + /** + * color management surface exists already + */ + WP_COLOR_MANAGER_V1_ERROR_SURFACE_EXISTS = 1, +}; +#endif /* WP_COLOR_MANAGER_V1_ERROR_ENUM */ + +#ifndef WP_COLOR_MANAGER_V1_ERROR_ENUM_IS_VALID +#define WP_COLOR_MANAGER_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_manager_v1 + * Validate a wp_color_manager_v1 error value. + * + * @return true on success, false on error. + * @ref wp_color_manager_v1_error + */ +static inline bool +wp_color_manager_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE: + return version >= 1; + case WP_COLOR_MANAGER_V1_ERROR_SURFACE_EXISTS: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGER_V1_ERROR_ENUM_IS_VALID */ + +#ifndef WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM +#define WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM +/** + * @ingroup iface_wp_color_manager_v1 + * rendering intents + * + * See the ICC.1:2022 specification from the International Color Consortium + * for more details about rendering intents. + * + * The principles of ICC defined rendering intents apply with all types of + * image descriptions, not only those with ICC file profiles. + * + * Compositors must support the perceptual rendering intent. Other + * rendering intents are optional. + */ +enum wp_color_manager_v1_render_intent { + /** + * perceptual + */ + WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL = 0, + /** + * media-relative colorimetric + */ + WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE = 1, + /** + * saturation + */ + WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION = 2, + /** + * ICC-absolute colorimetric + */ + WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE = 3, + /** + * media-relative colorimetric + black point compensation + */ + WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC = 4, +}; +#endif /* WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM */ + +#ifndef WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM_IS_VALID +#define WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_manager_v1 + * Validate a wp_color_manager_v1 render_intent value. + * + * @return true on success, false on error. + * @ref wp_color_manager_v1_render_intent + */ +static inline bool +wp_color_manager_v1_render_intent_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL: + return version >= 1; + case WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE: + return version >= 1; + case WP_COLOR_MANAGER_V1_RENDER_INTENT_SATURATION: + return version >= 1; + case WP_COLOR_MANAGER_V1_RENDER_INTENT_ABSOLUTE: + return version >= 1; + case WP_COLOR_MANAGER_V1_RENDER_INTENT_RELATIVE_BPC: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGER_V1_RENDER_INTENT_ENUM_IS_VALID */ + +#ifndef WP_COLOR_MANAGER_V1_FEATURE_ENUM +#define WP_COLOR_MANAGER_V1_FEATURE_ENUM +/** + * @ingroup iface_wp_color_manager_v1 + * compositor supported features + */ +enum wp_color_manager_v1_feature { + /** + * create_icc_creator request + */ + WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4 = 0, + /** + * create_parametric_creator request + */ + WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC = 1, + /** + * parametric set_primaries request + */ + WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES = 2, + /** + * parametric set_tf_power request + */ + WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER = 3, + /** + * parametric set_luminances request + */ + WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES = 4, + /** + * parametric set_mastering_display_primaries request + * + * The compositor supports set_mastering_display_primaries + * request with a target color volume fully contained inside the + * primary color volume. + */ + WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES = 5, + /** + * parametric target exceeds primary color volume + * + * The compositor additionally supports target color volumes that + * extend outside of the primary color volume. + * + * This can only be advertised if feature + * set_mastering_display_primaries is supported as well. + */ + WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME = 6, + /** + * get_windows_scrgb request + */ + WP_COLOR_MANAGER_V1_FEATURE_WINDOWS_SCRGB = 7, +}; +#endif /* WP_COLOR_MANAGER_V1_FEATURE_ENUM */ + +#ifndef WP_COLOR_MANAGER_V1_FEATURE_ENUM_IS_VALID +#define WP_COLOR_MANAGER_V1_FEATURE_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_manager_v1 + * Validate a wp_color_manager_v1 feature value. + * + * @return true on success, false on error. + * @ref wp_color_manager_v1_feature + */ +static inline bool +wp_color_manager_v1_feature_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME: + return version >= 1; + case WP_COLOR_MANAGER_V1_FEATURE_WINDOWS_SCRGB: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGER_V1_FEATURE_ENUM_IS_VALID */ + +#ifndef WP_COLOR_MANAGER_V1_PRIMARIES_ENUM +#define WP_COLOR_MANAGER_V1_PRIMARIES_ENUM +/** + * @ingroup iface_wp_color_manager_v1 + * named color primaries + * + * Named color primaries used to encode well-known sets of primaries. H.273 + * is the authority, when it comes to the exact values of primaries and + * authoritative specifications, where an equivalent code point exists. + * + * A value of 0 is invalid and will never be present in the list of enums. + * + * Descriptions do list the specifications for convenience. + */ +enum wp_color_manager_v1_primaries { + /** + * Color primaries for the sRGB color space as defined by the BT.709 standard + * + * Color primaries as defined by - Rec. ITU-R BT.709-6 - Rec. + * ITU-R BT.1361-0 conventional colour gamut system and extended + * colour gamut system (historical) - IEC 61966-2-1 sRGB or sYCC - + * IEC 61966-2-4 - Society of Motion Picture and Television + * Engineers (SMPTE) RP 177 (1993) Annex B Equivalent to H.273 + * ColourPrimaries code point 1. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_SRGB = 1, + /** + * Color primaries for PAL-M as defined by the BT.470 standard + * + * Color primaries as defined by - Rec. ITU-R BT.470-6 System M + * (historical) - United States National Television System + * Committee 1953 Recommendation for transmission standards for + * color television - United States Federal Communications + * Commission (2003) Title 47 Code of Federal Regulations 73.682 + * (a)(20) Equivalent to H.273 ColourPrimaries code point 4. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M = 2, + /** + * Color primaries for PAL as defined by the BT.601 standard + * + * Color primaries as defined by - Rec. ITU-R BT.470-6 System B, + * G (historical) - Rec. ITU-R BT.601-7 625 - Rec. ITU-R BT.1358-0 + * 625 (historical) - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM + * Equivalent to H.273 ColourPrimaries code point 5. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_PAL = 3, + /** + * Color primaries for NTSC as defined by the BT.601 standard + * + * Color primaries as defined by - Rec. ITU-R BT.601-7 525 - Rec. + * ITU-R BT.1358-1 525 or 625 (historical) - Rec. ITU-R BT.1700-0 + * NTSC - SMPTE 170M (2004) - SMPTE 240M (1999) (historical) + * Equivalent to H.273 ColourPrimaries code point 6 and 7. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_NTSC = 4, + /** + * Generic film with colour filters using Illuminant C + * + * Color primaries as defined by H.273 for generic film. + * Equivalent to H.273 ColourPrimaries code point 8. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM = 5, + /** + * Color primaries as defined by the BT.2020 and BT.2100 standard + * + * Color primaries as defined by - Rec. ITU-R BT.2020-2 - Rec. + * ITU-R BT.2100-0 Equivalent to H.273 ColourPrimaries code point + * 9. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 = 6, + /** + * Color primaries of the full CIE 1931 XYZ color space + * + * Color primaries as defined as the maximum of the CIE 1931 XYZ + * color space by - SMPTE ST 428-1 - (CIE 1931 XYZ as in ISO + * 11664-1) Equivalent to H.273 ColourPrimaries code point 10. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ = 7, + /** + * Color primaries of the DCI P3 color space as defined by the SMPTE RP 431 standard + * + * Color primaries as defined by Digital Cinema System and + * published in SMPTE RP 431-2 (2011). Equivalent to H.273 + * ColourPrimaries code point 11. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3 = 8, + /** + * Color primaries of Display P3 variant of the DCI-P3 color space as defined by the SMPTE EG 432 standard + * + * Color primaries as defined by Digital Cinema System and + * published in SMPTE EG 432-1 (2010). Equivalent to H.273 + * ColourPrimaries code point 12. + */ + WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3 = 9, + /** + * Color primaries of the Adobe RGB color space as defined by the ISO 12640 standard + * + * Color primaries as defined by Adobe as "Adobe RGB" and later + * published by ISO 12640-4 (2011). + */ + WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB = 10, +}; +#endif /* WP_COLOR_MANAGER_V1_PRIMARIES_ENUM */ + +#ifndef WP_COLOR_MANAGER_V1_PRIMARIES_ENUM_IS_VALID +#define WP_COLOR_MANAGER_V1_PRIMARIES_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_manager_v1 + * Validate a wp_color_manager_v1 primaries value. + * + * @return true on success, false on error. + * @ref wp_color_manager_v1_primaries + */ +static inline bool +wp_color_manager_v1_primaries_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGER_V1_PRIMARIES_SRGB: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_PAL: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_NTSC: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_BT2020: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3: + return version >= 1; + case WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGER_V1_PRIMARIES_ENUM_IS_VALID */ + +#ifndef WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM +#define WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM +/** + * @ingroup iface_wp_color_manager_v1 + * named transfer functions + * + * Named transfer functions used to represent well-known transfer + * characteristics. H.273 is the authority, when it comes to the exact + * formulas and authoritative specifications, where an equivalent code + * point exists. + * + * A value of 0 is invalid and will never be present in the list of enums. + * + * Descriptions do list the specifications for convenience. + */ +enum wp_color_manager_v1_transfer_function { + /** + * BT.1886 display transfer characteristic + * + * Rec. ITU-R BT.1886 is the display transfer characteristic + * assumed by - Rec. ITU-R BT.601-7 525 and 625 - Rec. ITU-R + * BT.709-6 - Rec. ITU-R BT.2020-2 These recommendations are + * referred to by H.273 TransferCharacteristics code points 1, 6, + * 14, and 15, which are all equivalent. + * + * This TF implies these default luminances from Rec. ITU-R + * BT.2035: - primary color volume minimum: 0.01 cd/m² - primary + * color volume maximum: 100 cd/m² - reference white: 100 cd/m² + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_BT1886 = 1, + /** + * Assumed display gamma 2.2 transfer function + * + * Transfer characteristics as defined by - Rec. ITU-R BT.470-6 + * System M (historical) - United States National Television System + * Committee 1953 Recommendation for transmission standards for + * color television - United States Federal Communications + * Commission (2003) Title 47 Code of Federal Regulations 73.682 + * (a) (20) - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM Equivalent + * to H.273 TransferCharacteristics code point 4. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22 = 2, + /** + * Assumed display gamma 2.8 transfer function + * + * Transfer characteristics as defined by - Rec. ITU-R BT.470-6 + * System B, G (historical) Equivalent to H.273 + * TransferCharacteristics code point 5. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28 = 3, + /** + * SMPTE ST 240 transfer function + * + * Transfer characteristics as defined by - SMPTE ST 240 (1999) + * Equivalent to H.273 TransferCharacteristics code point 7. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST240 = 4, + /** + * extended linear transfer function + * + * Linear transfer function defined over all real numbers. + * Normalised electrical values are equal the normalised optical + * values. + * + * The differences to H.273 TransferCharacteristics code point 8 + * are the definition over all real numbers. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR = 5, + /** + * logarithmic 100:1 transfer function + * + * Logarithmic transfer characteristic (100:1 range). Equivalent + * to H.273 TransferCharacteristics code point 9. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_100 = 6, + /** + * logarithmic (100*Sqrt(10) : 1) transfer function + * + * Logarithmic transfer characteristic (100 * Sqrt(10) : 1 + * range). Equivalent to H.273 TransferCharacteristics code point + * 10. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_316 = 7, + /** + * IEC 61966-2-4 transfer function + * + * Transfer characteristics as defined by - IEC 61966-2-4 + * Equivalent to H.273 TransferCharacteristics code point 11. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_XVYCC = 8, + /** + * sRGB piece-wise transfer function + * + * Transfer characteristics as defined by - IEC 61966-2-1 sRGB + * Equivalent to H.273 TransferCharacteristics code point 13 with + * MatrixCoefficients set to 0. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB = 9, + /** + * Extended sRGB piece-wise transfer function + * + * Transfer characteristics as defined by - IEC 61966-2-1 sYCC + * Equivalent to H.273 TransferCharacteristics code point 13 with + * MatrixCoefficients set to anything but 0. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_SRGB = 10, + /** + * perceptual quantizer transfer function + * + * Transfer characteristics as defined by - SMPTE ST 2084 (2014) + * for 10-, 12-, 14- and 16-bit systems - Rec. ITU-R BT.2100-2 + * perceptual quantization (PQ) system Equivalent to H.273 + * TransferCharacteristics code point 16. + * + * This TF implies these default luminances - primary color volume + * minimum: 0.005 cd/m² - primary color volume maximum: 10000 + * cd/m² - reference white: 203 cd/m² + * + * The difference between the primary color volume minimum and + * maximum must be approximately 10000 cd/m² as that is the swing + * of the EOTF defined by ST 2084 and BT.2100. The default value + * for the reference white is a protocol addition: it is suggested + * by Report ITU-R BT.2408-7 and is not part of ST 2084 or BT.2100. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ = 11, + /** + * SMPTE ST 428 transfer function + * + * Transfer characteristics as defined by - SMPTE ST 428-1 (2019) + * Equivalent to H.273 TransferCharacteristics code point 17. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST428 = 12, + /** + * hybrid log-gamma transfer function + * + * Transfer characteristics as defined by - ARIB STD-B67 (2015) - + * Rec. ITU-R BT.2100-2 hybrid log-gamma (HLG) system Equivalent to + * H.273 TransferCharacteristics code point 18. + * + * This TF implies these default luminances - primary color volume + * minimum: 0.005 cd/m² - primary color volume maximum: 1000 + * cd/m² - reference white: 203 cd/m² + * + * HLG is a relative display-referred signal with a specified + * non-linear mapping to the display peak luminance (the HLG OOTF). + * All absolute luminance values used here for HLG assume a 1000 + * cd/m² peak display. + * + * The default value for the reference white is a protocol + * addition: it is suggested by Report ITU-R BT.2408-7 and is not + * part of ARIB STD-B67 or BT.2100. + */ + WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG = 13, +}; +#endif /* WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM */ + +#ifndef WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM_IS_VALID +#define WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_manager_v1 + * Validate a wp_color_manager_v1 transfer_function value. + * + * @return true on success, false on error. + * @ref wp_color_manager_v1_transfer_function + */ +static inline bool +wp_color_manager_v1_transfer_function_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_BT1886: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST240: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_100: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_316: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_XVYCC: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_SRGB: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST428: + return version >= 1; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_color_manager_v1 + * @struct wp_color_manager_v1_interface + */ +struct wp_color_manager_v1_interface { + /** + * destroy the color manager + * + * Destroy the wp_color_manager_v1 object. This does not affect + * any other objects in any way. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * create a color management interface for a wl_output + * + * This creates a new wp_color_management_output_v1 object for + * the given wl_output. + * + * See the wp_color_management_output_v1 interface for more + * details. + */ + void (*get_output)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *output); + /** + * create a color management interface for a wl_surface + * + * If a wp_color_management_surface_v1 object already exists for + * the given wl_surface, the protocol error surface_exists is + * raised. + * + * This creates a new color wp_color_management_surface_v1 object + * for the given wl_surface. + * + * See the wp_color_management_surface_v1 interface for more + * details. + */ + void (*get_surface)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); + /** + * create a color management feedback interface + * + * This creates a new color + * wp_color_management_surface_feedback_v1 object for the given + * wl_surface. + * + * See the wp_color_management_surface_feedback_v1 interface for + * more details. + */ + void (*get_surface_feedback)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); + /** + * make a new ICC-based image description creator object + * + * Makes a new ICC-based image description creator object with + * all properties initially unset. The client can then use the + * object's interface to define all the required properties for an + * image description and finally create a wp_image_description_v1 + * object. + * + * This request can be used when the compositor advertises + * wp_color_manager_v1.feature.icc_v2_v4. Otherwise this request + * raises the protocol error unsupported_feature. + * @param obj the new creator object + */ + void (*create_icc_creator)(struct wl_client *client, + struct wl_resource *resource, + uint32_t obj); + /** + * make a new parametric image description creator object + * + * Makes a new parametric image description creator object with + * all properties initially unset. The client can then use the + * object's interface to define all the required properties for an + * image description and finally create a wp_image_description_v1 + * object. + * + * This request can be used when the compositor advertises + * wp_color_manager_v1.feature.parametric. Otherwise this request + * raises the protocol error unsupported_feature. + * @param obj the new creator object + */ + void (*create_parametric_creator)(struct wl_client *client, + struct wl_resource *resource, + uint32_t obj); + /** + * create Windows-scRGB image description object + * + * This creates a pre-defined image description for the so-called + * Windows-scRGB stimulus encoding. This comes from the Windows 10 + * handling of its own definition of an scRGB color space for an + * HDR screen driven in BT.2100/PQ signalling mode. + * + * Windows-scRGB uses sRGB (BT.709) color primaries and white + * point. The transfer characteristic is extended linear. + * + * The nominal color channel value range is extended, meaning it + * includes negative and greater than 1.0 values. Negative values + * are used to escape the sRGB color gamut boundaries. To make use + * of the extended range, the client needs to use a pixel format + * that can represent those values, e.g. floating-point 16 bits per + * channel. + * + * Nominal color value R=G=B=0.0 corresponds to BT.2100/PQ system 0 + * cd/m², and R=G=B=1.0 corresponds to BT.2100/PQ system 80 + * cd/m². The maximum is R=G=B=125.0 corresponding to 10k cd/m². + * + * Windows-scRGB is displayed by Windows 10 by converting it to + * BT.2100/PQ, maintaining the CIE 1931 chromaticity and mapping + * the luminance as above. No adjustment is made to the signal to + * account for the viewing conditions. + * + * The reference white level of Windows-scRGB is unknown. If a + * reference white level must be assumed for compositor processing, + * it should be R=G=B=2.5375 corresponding to 203 cd/m² of Report + * ITU-R BT.2408-7. + * + * The target color volume of Windows-scRGB is unknown. The color + * gamut may be anything between sRGB and BT.2100. + * + * Note: EGL_EXT_gl_colorspace_scrgb_linear definition differs from + * Windows-scRGB by using R=G=B=1.0 as the reference white level, + * while Windows-scRGB reference white level is unknown or varies. + * However, it seems probable that Windows implements both + * EGL_EXT_gl_colorspace_scrgb_linear and Vulkan + * VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT as Windows-scRGB. + * + * This request can be used when the compositor advertises + * wp_color_manager_v1.feature.windows_scrgb. Otherwise this + * request raises the protocol error unsupported_feature. + * + * The resulting image description object does not allow + * get_information request. The wp_image_description_v1.ready event + * shall be sent. + */ + void (*create_windows_scrgb)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); +}; + +#define WP_COLOR_MANAGER_V1_SUPPORTED_INTENT 0 +#define WP_COLOR_MANAGER_V1_SUPPORTED_FEATURE 1 +#define WP_COLOR_MANAGER_V1_SUPPORTED_TF_NAMED 2 +#define WP_COLOR_MANAGER_V1_SUPPORTED_PRIMARIES_NAMED 3 +#define WP_COLOR_MANAGER_V1_DONE 4 + +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_SUPPORTED_INTENT_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_SUPPORTED_FEATURE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_SUPPORTED_TF_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_SUPPORTED_PRIMARIES_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_DONE_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_GET_OUTPUT_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_GET_SURFACE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_CREATE_ICC_CREATOR_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_CREATE_PARAMETRIC_CREATOR_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_manager_v1 + */ +#define WP_COLOR_MANAGER_V1_CREATE_WINDOWS_SCRGB_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_manager_v1 + * Sends an supported_intent event to the client owning the resource. + * @param resource_ The client's resource + * @param render_intent rendering intent + */ +static inline void +wp_color_manager_v1_send_supported_intent(struct wl_resource *resource_, uint32_t render_intent) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGER_V1_SUPPORTED_INTENT, render_intent); +} + +/** + * @ingroup iface_wp_color_manager_v1 + * Sends an supported_feature event to the client owning the resource. + * @param resource_ The client's resource + * @param feature supported feature + */ +static inline void +wp_color_manager_v1_send_supported_feature(struct wl_resource *resource_, uint32_t feature) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGER_V1_SUPPORTED_FEATURE, feature); +} + +/** + * @ingroup iface_wp_color_manager_v1 + * Sends an supported_tf_named event to the client owning the resource. + * @param resource_ The client's resource + * @param tf Named transfer function + */ +static inline void +wp_color_manager_v1_send_supported_tf_named(struct wl_resource *resource_, uint32_t tf) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGER_V1_SUPPORTED_TF_NAMED, tf); +} + +/** + * @ingroup iface_wp_color_manager_v1 + * Sends an supported_primaries_named event to the client owning the resource. + * @param resource_ The client's resource + * @param primaries Named color primaries + */ +static inline void +wp_color_manager_v1_send_supported_primaries_named(struct wl_resource *resource_, uint32_t primaries) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGER_V1_SUPPORTED_PRIMARIES_NAMED, primaries); +} + +/** + * @ingroup iface_wp_color_manager_v1 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wp_color_manager_v1_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGER_V1_DONE); +} + +/** + * @ingroup iface_wp_color_management_output_v1 + * @struct wp_color_management_output_v1_interface + */ +struct wp_color_management_output_v1_interface { + /** + * destroy the color management output + * + * Destroy the color wp_color_management_output_v1 object. This + * does not affect any remaining protocol objects. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * get the image description of the output + * + * This creates a new wp_image_description_v1 object for the + * current image description of the output. There always is exactly + * one image description active for an output so the client should + * destroy the image description created by earlier invocations of + * this request. This request is usually sent as a reaction to the + * image_description_changed event or when creating a + * wp_color_management_output_v1 object. + * + * The image description of an output represents the color encoding + * the output expects. There might be performance and power + * advantages, as well as improved color reproduction, if a content + * update matches the image description of the output it is being + * shown on. If a content update is shown on any other output than + * the one it matches the image description of, then the color + * reproduction on those outputs might be considerably worse. + * + * The created wp_image_description_v1 object preserves the image + * description of the output from the time the object was created. + * + * The resulting image description object allows get_information + * request. + * + * If this protocol object is inert, the resulting image + * description object shall immediately deliver the + * wp_image_description_v1.failed event with the no_output cause. + * + * If the interface version is inadequate for the output's image + * description, meaning that the client does not support all the + * events needed to deliver the crucial information, the resulting + * image description object shall immediately deliver the + * wp_image_description_v1.failed event with the low_version cause. + * + * Otherwise the object shall immediately deliver the ready event. + */ + void (*get_image_description)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); +}; + +#define WP_COLOR_MANAGEMENT_OUTPUT_V1_IMAGE_DESCRIPTION_CHANGED 0 + +/** + * @ingroup iface_wp_color_management_output_v1 + */ +#define WP_COLOR_MANAGEMENT_OUTPUT_V1_IMAGE_DESCRIPTION_CHANGED_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_management_output_v1 + */ +#define WP_COLOR_MANAGEMENT_OUTPUT_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_management_output_v1 + */ +#define WP_COLOR_MANAGEMENT_OUTPUT_V1_GET_IMAGE_DESCRIPTION_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_management_output_v1 + * Sends an image_description_changed event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wp_color_management_output_v1_send_image_description_changed(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGEMENT_OUTPUT_V1_IMAGE_DESCRIPTION_CHANGED); +} + +#ifndef WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM +#define WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM +/** + * @ingroup iface_wp_color_management_surface_v1 + * protocol errors + */ +enum wp_color_management_surface_v1_error { + /** + * unsupported rendering intent + */ + WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_RENDER_INTENT = 0, + /** + * invalid image description + */ + WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_IMAGE_DESCRIPTION = 1, + /** + * forbidden request on inert object + */ + WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_INERT = 2, +}; +#endif /* WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM */ + +#ifndef WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM_IS_VALID +#define WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_management_surface_v1 + * Validate a wp_color_management_surface_v1 error value. + * + * @return true on success, false on error. + * @ref wp_color_management_surface_v1_error + */ +static inline bool +wp_color_management_surface_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_RENDER_INTENT: + return version >= 1; + case WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_IMAGE_DESCRIPTION: + return version >= 1; + case WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_INERT: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_color_management_surface_v1 + * @struct wp_color_management_surface_v1_interface + */ +struct wp_color_management_surface_v1_interface { + /** + * destroy the color management interface for a surface + * + * Destroy the wp_color_management_surface_v1 object and do the + * same as unset_image_description. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the surface image description + * + * If this protocol object is inert, the protocol error inert is + * raised. + * + * Set the image description of the underlying surface. The image + * description and rendering intent are double-buffered state, see + * wl_surface.commit. + * + * It is the client's responsibility to understand the image + * description it sets on a surface, and to provide content that + * matches that image description. Compositors might convert images + * to match their own or any other image descriptions. + * + * Image descriptions which are not ready (see + * wp_image_description_v1) are forbidden in this request, and in + * such case the protocol error image_description is raised. + * + * All image descriptions which are ready (see + * wp_image_description_v1) are allowed and must always be accepted + * by the compositor. + * + * A rendering intent provides the client's preference on how + * content colors should be mapped to each output. The + * render_intent value must be one advertised by the compositor + * with wp_color_manager_v1.render_intent event, otherwise the + * protocol error render_intent is raised. + * + * When an image description is set on a surface, the Transfer + * Characteristics of the image description defines the valid range + * of the nominal (real-valued) color channel values. The + * processing of out-of-range color channel values is undefined, + * but compositors are recommended to clamp the values to the valid + * range when possible. + * + * By default, a surface does not have an associated image + * description nor a rendering intent. The handling of color on + * such surfaces is compositor implementation defined. Compositors + * should handle such surfaces as sRGB, but may handle them + * differently if they have specific requirements. + * + * Setting the image description has copy semantics; after this + * request, the image description can be immediately destroyed + * without affecting the pending state of the surface. + * @param render_intent rendering intent + */ + void (*set_image_description)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *image_description, + uint32_t render_intent); + /** + * remove the surface image description + * + * If this protocol object is inert, the protocol error inert is + * raised. + * + * This request removes any image description from the surface. See + * set_image_description for how a compositor handles a surface + * without an image description. This is double-buffered state, see + * wl_surface.commit. + */ + void (*unset_image_description)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_wp_color_management_surface_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_management_surface_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_V1_SET_IMAGE_DESCRIPTION_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_management_surface_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_V1_UNSET_IMAGE_DESCRIPTION_SINCE_VERSION 1 + +#ifndef WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + * protocol errors + */ +enum wp_color_management_surface_feedback_v1_error { + /** + * forbidden request on inert object + */ + WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_INERT = 0, + /** + * attempted to use an unsupported feature + */ + WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_UNSUPPORTED_FEATURE = 1, +}; +#endif /* WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM */ + +#ifndef WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM_IS_VALID +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + * Validate a wp_color_management_surface_feedback_v1 error value. + * + * @return true on success, false on error. + * @ref wp_color_management_surface_feedback_v1_error + */ +static inline bool +wp_color_management_surface_feedback_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_INERT: + return version >= 1; + case WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_UNSUPPORTED_FEATURE: + return version >= 1; + default: + return false; + } +} +#endif /* WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + * @struct wp_color_management_surface_feedback_v1_interface + */ +struct wp_color_management_surface_feedback_v1_interface { + /** + * destroy the color management interface for a surface + * + * Destroy the wp_color_management_surface_feedback_v1 object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * get the preferred image description + * + * If this protocol object is inert, the protocol error inert is + * raised. + * + * The preferred image description represents the compositor's + * preferred color encoding for this wl_surface at the current + * time. There might be performance and power advantages, as well + * as improved color reproduction, if the image description of a + * content update matches the preferred image description. + * + * This creates a new wp_image_description_v1 object for the + * currently preferred image description for the wl_surface. The + * client should stop using and destroy the image descriptions + * created by earlier invocations of this request for the + * associated wl_surface. This request is usually sent as a + * reaction to the preferred_changed event or when creating a + * wp_color_management_surface_feedback_v1 object if the client is + * capable of adapting to image descriptions. + * + * The created wp_image_description_v1 object preserves the + * preferred image description of the wl_surface from the time the + * object was created. + * + * The resulting image description object allows get_information + * request. + * + * If the image description is parametric, the client should set it + * on its wl_surface only if the image description is an exact + * match with the client content. Particularly if everything else + * matches, but the target color volume is greater than what the + * client needs, the client should create its own parameric image + * description with its exact parameters. + * + * If the interface version is inadequate for the preferred image + * description, meaning that the client does not support all the + * events needed to deliver the crucial information, the resulting + * image description object shall immediately deliver the + * wp_image_description_v1.failed event with the low_version cause, + * otherwise the object shall immediately deliver the ready event. + */ + void (*get_preferred)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); + /** + * get the preferred image description + * + * The same description as for get_preferred applies, except the + * returned image description is guaranteed to be parametric. This + * is meant for clients that can only deal with parametric image + * descriptions. + * + * If the compositor doesn't support parametric image descriptions, + * the unsupported_feature error is emitted. + */ + void (*get_preferred_parametric)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); +}; + +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_PREFERRED_CHANGED 0 + +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_PREFERRED_CHANGED_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_GET_PREFERRED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + */ +#define WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_GET_PREFERRED_PARAMETRIC_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_color_management_surface_feedback_v1 + * Sends an preferred_changed event to the client owning the resource. + * @param resource_ The client's resource + * @param identity image description id number + */ +static inline void +wp_color_management_surface_feedback_v1_send_preferred_changed(struct wl_resource *resource_, uint32_t identity) +{ + wl_resource_post_event(resource_, WP_COLOR_MANAGEMENT_SURFACE_FEEDBACK_V1_PREFERRED_CHANGED, identity); +} + +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM +#define WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM +/** + * @ingroup iface_wp_image_description_creator_icc_v1 + * protocol errors + */ +enum wp_image_description_creator_icc_v1_error { + /** + * incomplete parameter set + */ + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_INCOMPLETE_SET = 0, + /** + * property already set + */ + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ALREADY_SET = 1, + /** + * fd not seekable and readable + */ + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD = 2, + /** + * no or too much data + */ + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_SIZE = 3, + /** + * offset + length exceeds file size + */ + WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_OUT_OF_FILE = 4, +}; +#endif /* WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM */ + +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM_IS_VALID +#define WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_image_description_creator_icc_v1 + * Validate a wp_image_description_creator_icc_v1 error value. + * + * @return true on success, false on error. + * @ref wp_image_description_creator_icc_v1_error + */ +static inline bool +wp_image_description_creator_icc_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_INCOMPLETE_SET: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ALREADY_SET: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_FD: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_BAD_SIZE: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_OUT_OF_FILE: + return version >= 1; + default: + return false; + } +} +#endif /* WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_image_description_creator_icc_v1 + * @struct wp_image_description_creator_icc_v1_interface + */ +struct wp_image_description_creator_icc_v1_interface { + /** + * Create the image description object from ICC data + * + * Create an image description object based on the ICC + * information previously set on this object. A compositor must + * parse the ICC data in some undefined but finite amount of time. + * + * The completeness of the parameter set is verified. If the set is + * not complete, the protocol error incomplete_set is raised. For + * the definition of a complete set, see the description of this + * interface. + * + * If the particular combination of the information is not + * supported by the compositor, the resulting image description + * object shall immediately deliver the + * wp_image_description_v1.failed event with the 'unsupported' + * cause. If a valid image description was created from the + * information, the wp_image_description_v1.ready event will + * eventually be sent instead. + * + * This request destroys the wp_image_description_creator_icc_v1 + * object. + * + * The resulting image description object does not allow + * get_information request. + */ + void (*create)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); + /** + * set the ICC profile file + * + * Sets the ICC profile file to be used as the basis of the image + * description. + * + * The data shall be found through the given fd at the given + * offset, having the given length. The fd must be seekable and + * readable. Violating these requirements raises the bad_fd + * protocol error. + * + * If reading the data fails due to an error independent of the + * client, the compositor shall send the + * wp_image_description_v1.failed event on the created + * wp_image_description_v1 with the 'operating_system' cause. + * + * The maximum size of the ICC profile is 32 MB. If length is + * greater than that or zero, the protocol error bad_size is + * raised. If offset + length exceeds the file size, the protocol + * error out_of_file is raised. + * + * A compositor may read the file at any time starting from this + * request and only until whichever happens first: - If create + * request was issued, the wp_image_description_v1 object delivers + * either failed or ready event; or - if create request was not + * issued, this wp_image_description_creator_icc_v1 object is + * destroyed. + * + * A compositor shall not modify the contents of the file, and the + * fd may be sealed for writes and size changes. The client must + * ensure to its best ability that the data does not change while + * the compositor is reading it. + * + * The data must represent a valid ICC profile. The ICC profile + * version must be 2 or 4, it must be a 3 channel profile and the + * class must be Display or ColorSpace. Violating these + * requirements will not result in a protocol error, but will + * eventually send the wp_image_description_v1.failed event on the + * created wp_image_description_v1 with the 'unsupported' cause. + * + * See the International Color Consortium specification ICC.1:2022 + * for more details about ICC profiles. + * + * If ICC file has already been set on this object, the protocol + * error already_set is raised. + * @param icc_profile ICC profile + * @param offset byte offset in fd to start of ICC data + * @param length length of ICC data in bytes + */ + void (*set_icc_file)(struct wl_client *client, + struct wl_resource *resource, + int32_t icc_profile, + uint32_t offset, + uint32_t length); +}; + + +/** + * @ingroup iface_wp_image_description_creator_icc_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_CREATE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_icc_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_ICC_V1_SET_ICC_FILE_SINCE_VERSION 1 + +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM +/** + * @ingroup iface_wp_image_description_creator_params_v1 + * protocol errors + */ +enum wp_image_description_creator_params_v1_error { + /** + * incomplete parameter set + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET = 0, + /** + * property already set + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET = 1, + /** + * request not supported + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE = 2, + /** + * invalid transfer characteristic + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF = 3, + /** + * invalid primaries named + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED = 4, + /** + * invalid luminance value or range + */ + WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE = 5, +}; +#endif /* WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM */ + +#ifndef WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM_IS_VALID +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_image_description_creator_params_v1 + * Validate a wp_image_description_creator_params_v1 error value. + * + * @return true on success, false on error. + * @ref wp_image_description_creator_params_v1_error + */ +static inline bool +wp_image_description_creator_params_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED: + return version >= 1; + case WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE: + return version >= 1; + default: + return false; + } +} +#endif /* WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_image_description_creator_params_v1 + * @struct wp_image_description_creator_params_v1_interface + */ +struct wp_image_description_creator_params_v1_interface { + /** + * Create the image description object using params + * + * Create an image description object based on the parameters + * previously set on this object. + * + * The completeness of the parameter set is verified. If the set is + * not complete, the protocol error incomplete_set is raised. For + * the definition of a complete set, see the description of this + * interface. + * + * The protocol error invalid_luminance is raised if any of the + * following requirements is not met: - When max_cll is set, it + * must be greater than min L and less or equal to max L of the + * mastering luminance range. - When max_fall is set, it must be + * greater than min L and less or equal to max L of the mastering + * luminance range. - When both max_cll and max_fall are set, + * max_fall must be less or equal to max_cll. + * + * If the particular combination of the parameter set is not + * supported by the compositor, the resulting image description + * object shall immediately deliver the + * wp_image_description_v1.failed event with the 'unsupported' + * cause. If a valid image description was created from the + * parameter set, the wp_image_description_v1.ready event will + * eventually be sent instead. + * + * This request destroys the wp_image_description_creator_params_v1 + * object. + * + * The resulting image description object does not allow + * get_information request. + */ + void (*create)(struct wl_client *client, + struct wl_resource *resource, + uint32_t image_description); + /** + * named transfer characteristic + * + * Sets the transfer characteristic using explicitly enumerated + * named functions. + * + * When the resulting image description is attached to an image, + * the content should be encoded and decoded according to the + * industry standard practices for the transfer characteristic. + * + * Only names advertised with wp_color_manager_v1 event + * supported_tf_named are allowed. Other values shall raise the + * protocol error invalid_tf. + * + * If transfer characteristic has already been set on this object, + * the protocol error already_set is raised. + * @param tf named transfer function + */ + void (*set_tf_named)(struct wl_client *client, + struct wl_resource *resource, + uint32_t tf); + /** + * transfer characteristic as a power curve + * + * Sets the color component transfer characteristic to a power + * curve with the given exponent. Negative values are handled by + * mirroring the positive half of the curve through the origin. The + * valid domain and range of the curve are all finite real numbers. + * This curve represents the conversion from electrical to optical + * color channel values. + * + * When the resulting image description is attached to an image, + * the content should be encoded with the inverse of the power + * curve. + * + * The curve exponent shall be multiplied by 10000 to get the + * argument eexp value to carry the precision of 4 decimals. + * + * The curve exponent must be at least 1.0 and at most 10.0. + * Otherwise the protocol error invalid_tf is raised. + * + * If transfer characteristic has already been set on this object, + * the protocol error already_set is raised. + * + * This request can be used when the compositor advertises + * wp_color_manager_v1.feature.set_tf_power. Otherwise this request + * raises the protocol error unsupported_feature. + * @param eexp the exponent * 10000 + */ + void (*set_tf_power)(struct wl_client *client, + struct wl_resource *resource, + uint32_t eexp); + /** + * named primaries + * + * Sets the color primaries and white point using explicitly + * named sets. This describes the primary color volume which is the + * basis for color value encoding. + * + * Only names advertised with wp_color_manager_v1 event + * supported_primaries_named are allowed. Other values shall raise + * the protocol error invalid_primaries_named. + * + * If primaries have already been set on this object, the protocol + * error already_set is raised. + * @param primaries named primaries + */ + void (*set_primaries_named)(struct wl_client *client, + struct wl_resource *resource, + uint32_t primaries); + /** + * primaries as chromaticity coordinates + * + * Sets the color primaries and white point using CIE 1931 xy + * chromaticity coordinates. This describes the primary color + * volume which is the basis for color value encoding. + * + * Each coordinate value is multiplied by 1 million to get the + * argument value to carry precision of 6 decimals. + * + * If primaries have already been set on this object, the protocol + * error already_set is raised. + * + * This request can be used if the compositor advertises + * wp_color_manager_v1.feature.set_primaries. Otherwise this + * request raises the protocol error unsupported_feature. + * @param r_x Red x * 1M + * @param r_y Red y * 1M + * @param g_x Green x * 1M + * @param g_y Green y * 1M + * @param b_x Blue x * 1M + * @param b_y Blue y * 1M + * @param w_x White x * 1M + * @param w_y White y * 1M + */ + void (*set_primaries)(struct wl_client *client, + struct wl_resource *resource, + int32_t r_x, + int32_t r_y, + int32_t g_x, + int32_t g_y, + int32_t b_x, + int32_t b_y, + int32_t w_x, + int32_t w_y); + /** + * primary color volume luminance range and reference white + * + * Sets the primary color volume luminance range and the + * reference white luminance level. These values include the + * minimum display emission and ambient flare luminances, assumed + * to be optically additive and have the chromaticity of the + * primary color volume white point. + * + * The default luminances from + * https://www.color.org/chardata/rgb/srgb.xalter are - primary + * color volume minimum: 0.2 cd/m² - primary color volume maximum: + * 80 cd/m² - reference white: 80 cd/m² + * + * Setting a named transfer characteristic can imply other default + * luminances. + * + * The default luminances get overwritten when this request is + * used. With transfer_function.st2084_pq the given 'max_lum' value + * is ignored, and 'max_lum' is taken as 'min_lum' + 10000 cd/m². + * + * 'min_lum' and 'max_lum' specify the minimum and maximum + * luminances of the primary color volume as reproduced by the + * targeted display. + * + * 'reference_lum' specifies the luminance of the reference white + * as reproduced by the targeted display, and reflects the targeted + * viewing environment. + * + * Compositors should make sure that all content is anchored, + * meaning that an input signal level of 'reference_lum' on one + * image description and another input signal level of + * 'reference_lum' on another image description should produce the + * same output level, even though the 'reference_lum' on both image + * representations can be different. + * + * 'reference_lum' may be higher than 'max_lum'. In that case + * reaching the reference white output level in image content + * requires the 'extended_target_volume' feature support. + * + * If 'max_lum' or 'reference_lum' are less than or equal to + * 'min_lum', the protocol error invalid_luminance is raised. + * + * The minimum luminance is multiplied by 10000 to get the argument + * 'min_lum' value and carries precision of 4 decimals. The maximum + * luminance and reference white luminance values are unscaled. + * + * If the primary color volume luminance range and the reference + * white luminance level have already been set on this object, the + * protocol error already_set is raised. + * + * This request can be used if the compositor advertises + * wp_color_manager_v1.feature.set_luminances. Otherwise this + * request raises the protocol error unsupported_feature. + * @param min_lum minimum luminance (cd/m²) * 10000 + * @param max_lum maximum luminance (cd/m²) + * @param reference_lum reference white luminance (cd/m²) + */ + void (*set_luminances)(struct wl_client *client, + struct wl_resource *resource, + uint32_t min_lum, + uint32_t max_lum, + uint32_t reference_lum); + /** + * mastering display primaries as chromaticity coordinates + * + * Provides the color primaries and white point of the mastering + * display using CIE 1931 xy chromaticity coordinates. This is + * compatible with the SMPTE ST 2086 definition of HDR static + * metadata. + * + * The mastering display primaries and mastering display luminances + * define the target color volume. + * + * If mastering display primaries are not explicitly set, the + * target color volume is assumed to have the same primaries as the + * primary color volume. + * + * The target color volume is defined by all tristimulus values + * between 0.0 and 1.0 (inclusive) of the color space defined by + * the given mastering display primaries and white point. The + * colorimetry is identical between the container color space and + * the mastering display color space, including that no chromatic + * adaptation is applied even if the white points differ. + * + * The target color volume can exceed the primary color volume to + * allow for a greater color volume with an existing color space + * definition (for example scRGB). It can be smaller than the + * primary color volume to minimize gamut and tone mapping + * distances for big color spaces (HDR metadata). + * + * To make use of the entire target color volume a suitable pixel + * format has to be chosen (e.g. floating point to exceed the + * primary color volume, or abusing limited quantization range as + * with xvYCC). + * + * Each coordinate value is multiplied by 1 million to get the + * argument value to carry precision of 6 decimals. + * + * If mastering display primaries have already been set on this + * object, the protocol error already_set is raised. + * + * This request can be used if the compositor advertises + * wp_color_manager_v1.feature.set_mastering_display_primaries. + * Otherwise this request raises the protocol error + * unsupported_feature. The advertisement implies support only for + * target color volumes fully contained within the primary color + * volume. + * + * If a compositor additionally supports target color volume + * exceeding the primary color volume, it must advertise + * wp_color_manager_v1.feature.extended_target_volume. If a client + * uses target color volume exceeding the primary color volume and + * the compositor does not support it, the result is implementation + * defined. Compositors are recommended to detect this case and + * fail the image description gracefully, but it may as well result + * in color artifacts. + * @param r_x Red x * 1M + * @param r_y Red y * 1M + * @param g_x Green x * 1M + * @param g_y Green y * 1M + * @param b_x Blue x * 1M + * @param b_y Blue y * 1M + * @param w_x White x * 1M + * @param w_y White y * 1M + */ + void (*set_mastering_display_primaries)(struct wl_client *client, + struct wl_resource *resource, + int32_t r_x, + int32_t r_y, + int32_t g_x, + int32_t g_y, + int32_t b_x, + int32_t b_y, + int32_t w_x, + int32_t w_y); + /** + * display mastering luminance range + * + * Sets the luminance range that was used during the content + * mastering process as the minimum and maximum absolute luminance + * L. These values include the minimum display emission and ambient + * flare luminances, assumed to be optically additive and have the + * chromaticity of the primary color volume white point. This + * should be compatible with the SMPTE ST 2086 definition of HDR + * static metadata. + * + * The mastering display primaries and mastering display luminances + * define the target color volume. + * + * If mastering luminances are not explicitly set, the target color + * volume is assumed to have the same min and max luminances as the + * primary color volume. + * + * If max L is less than or equal to min L, the protocol error + * invalid_luminance is raised. + * + * Min L value is multiplied by 10000 to get the argument min_lum + * value and carry precision of 4 decimals. Max L value is unscaled + * for max_lum. + * + * This request can be used if the compositor advertises + * wp_color_manager_v1.feature.set_mastering_display_primaries. + * Otherwise this request raises the protocol error + * unsupported_feature. The advertisement implies support only for + * target color volumes fully contained within the primary color + * volume. + * + * If a compositor additionally supports target color volume + * exceeding the primary color volume, it must advertise + * wp_color_manager_v1.feature.extended_target_volume. If a client + * uses target color volume exceeding the primary color volume and + * the compositor does not support it, the result is implementation + * defined. Compositors are recommended to detect this case and + * fail the image description gracefully, but it may as well result + * in color artifacts. + * @param min_lum min L (cd/m²) * 10000 + * @param max_lum max L (cd/m²) + */ + void (*set_mastering_luminance)(struct wl_client *client, + struct wl_resource *resource, + uint32_t min_lum, + uint32_t max_lum); + /** + * maximum content light level + * + * Sets the maximum content light level (max_cll) as defined by + * CTA-861-H. + * + * max_cll is undefined by default. + * @param max_cll Maximum content light level (cd/m²) + */ + void (*set_max_cll)(struct wl_client *client, + struct wl_resource *resource, + uint32_t max_cll); + /** + * maximum frame-average light level + * + * Sets the maximum frame-average light level (max_fall) as + * defined by CTA-861-H. + * + * max_fall is undefined by default. + * @param max_fall Maximum frame-average light level (cd/m²) + */ + void (*set_max_fall)(struct wl_client *client, + struct wl_resource *resource, + uint32_t max_fall); +}; + + +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_CREATE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_TF_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_TF_POWER_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_PRIMARIES_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_PRIMARIES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_LUMINANCES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_MASTERING_DISPLAY_PRIMARIES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_MASTERING_LUMINANCE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_MAX_CLL_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_creator_params_v1 + */ +#define WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_SET_MAX_FALL_SINCE_VERSION 1 + +#ifndef WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM +#define WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM +/** + * @ingroup iface_wp_image_description_v1 + * protocol errors + */ +enum wp_image_description_v1_error { + /** + * attempted to use an object which is not ready + */ + WP_IMAGE_DESCRIPTION_V1_ERROR_NOT_READY = 0, + /** + * get_information not allowed + */ + WP_IMAGE_DESCRIPTION_V1_ERROR_NO_INFORMATION = 1, +}; +#endif /* WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM */ + +#ifndef WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM_IS_VALID +#define WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_image_description_v1 + * Validate a wp_image_description_v1 error value. + * + * @return true on success, false on error. + * @ref wp_image_description_v1_error + */ +static inline bool +wp_image_description_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_IMAGE_DESCRIPTION_V1_ERROR_NOT_READY: + return version >= 1; + case WP_IMAGE_DESCRIPTION_V1_ERROR_NO_INFORMATION: + return version >= 1; + default: + return false; + } +} +#endif /* WP_IMAGE_DESCRIPTION_V1_ERROR_ENUM_IS_VALID */ + +#ifndef WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM +#define WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM +/** + * @ingroup iface_wp_image_description_v1 + * generic reason for failure + */ +enum wp_image_description_v1_cause { + /** + * interface version too low + */ + WP_IMAGE_DESCRIPTION_V1_CAUSE_LOW_VERSION = 0, + /** + * unsupported image description data + */ + WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED = 1, + /** + * error independent of the client + */ + WP_IMAGE_DESCRIPTION_V1_CAUSE_OPERATING_SYSTEM = 2, + /** + * the relevant output no longer exists + */ + WP_IMAGE_DESCRIPTION_V1_CAUSE_NO_OUTPUT = 3, +}; +#endif /* WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM */ + +#ifndef WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM_IS_VALID +#define WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM_IS_VALID +/** + * @ingroup iface_wp_image_description_v1 + * Validate a wp_image_description_v1 cause value. + * + * @return true on success, false on error. + * @ref wp_image_description_v1_cause + */ +static inline bool +wp_image_description_v1_cause_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_IMAGE_DESCRIPTION_V1_CAUSE_LOW_VERSION: + return version >= 1; + case WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED: + return version >= 1; + case WP_IMAGE_DESCRIPTION_V1_CAUSE_OPERATING_SYSTEM: + return version >= 1; + case WP_IMAGE_DESCRIPTION_V1_CAUSE_NO_OUTPUT: + return version >= 1; + default: + return false; + } +} +#endif /* WP_IMAGE_DESCRIPTION_V1_CAUSE_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_image_description_v1 + * @struct wp_image_description_v1_interface + */ +struct wp_image_description_v1_interface { + /** + * destroy the image description + * + * Destroy this object. It is safe to destroy an object which is + * not ready. + * + * Destroying a wp_image_description_v1 object has no side-effects, + * not even if a + * wp_color_management_surface_v1.set_image_description has not yet + * been followed by a wl_surface.commit. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * get information about the image description + * + * Creates a wp_image_description_info_v1 object which delivers + * the information that makes up the image description. + * + * Not all image description protocol objects allow get_information + * request. Whether it is allowed or not is defined by the request + * that created the object. If get_information is not allowed, the + * protocol error no_information is raised. + */ + void (*get_information)(struct wl_client *client, + struct wl_resource *resource, + uint32_t information); +}; + +#define WP_IMAGE_DESCRIPTION_V1_FAILED 0 +#define WP_IMAGE_DESCRIPTION_V1_READY 1 + +/** + * @ingroup iface_wp_image_description_v1 + */ +#define WP_IMAGE_DESCRIPTION_V1_FAILED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_v1 + */ +#define WP_IMAGE_DESCRIPTION_V1_READY_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_image_description_v1 + */ +#define WP_IMAGE_DESCRIPTION_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_v1 + */ +#define WP_IMAGE_DESCRIPTION_V1_GET_INFORMATION_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_image_description_v1 + * Sends an failed event to the client owning the resource. + * @param resource_ The client's resource + * @param cause generic reason + * @param msg ad hoc human-readable explanation + */ +static inline void +wp_image_description_v1_send_failed(struct wl_resource *resource_, uint32_t cause, const char *msg) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_V1_FAILED, cause, msg); +} + +/** + * @ingroup iface_wp_image_description_v1 + * Sends an ready event to the client owning the resource. + * @param resource_ The client's resource + * @param identity image description id number + */ +static inline void +wp_image_description_v1_send_ready(struct wl_resource *resource_, uint32_t identity) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_V1_READY, identity); +} + +#define WP_IMAGE_DESCRIPTION_INFO_V1_DONE 0 +#define WP_IMAGE_DESCRIPTION_INFO_V1_ICC_FILE 1 +#define WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES 2 +#define WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES_NAMED 3 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TF_POWER 4 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TF_NAMED 5 +#define WP_IMAGE_DESCRIPTION_INFO_V1_LUMINANCES 6 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_PRIMARIES 7 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_LUMINANCE 8 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_CLL 9 +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_FALL 10 + +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_ICC_FILE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TF_POWER_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TF_NAMED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_LUMINANCES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_PRIMARIES_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_LUMINANCE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_CLL_SINCE_VERSION 1 +/** + * @ingroup iface_wp_image_description_info_v1 + */ +#define WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_FALL_SINCE_VERSION 1 + + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wp_image_description_info_v1_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_DONE); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an icc_file event to the client owning the resource. + * @param resource_ The client's resource + * @param icc ICC profile file descriptor + * @param icc_size ICC profile size, in bytes + */ +static inline void +wp_image_description_info_v1_send_icc_file(struct wl_resource *resource_, int32_t icc, uint32_t icc_size) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_ICC_FILE, icc, icc_size); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an primaries event to the client owning the resource. + * @param resource_ The client's resource + * @param r_x Red x * 1M + * @param r_y Red y * 1M + * @param g_x Green x * 1M + * @param g_y Green y * 1M + * @param b_x Blue x * 1M + * @param b_y Blue y * 1M + * @param w_x White x * 1M + * @param w_y White y * 1M + */ +static inline void +wp_image_description_info_v1_send_primaries(struct wl_resource *resource_, int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES, r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an primaries_named event to the client owning the resource. + * @param resource_ The client's resource + * @param primaries named primaries + */ +static inline void +wp_image_description_info_v1_send_primaries_named(struct wl_resource *resource_, uint32_t primaries) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_PRIMARIES_NAMED, primaries); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an tf_power event to the client owning the resource. + * @param resource_ The client's resource + * @param eexp the exponent * 10000 + */ +static inline void +wp_image_description_info_v1_send_tf_power(struct wl_resource *resource_, uint32_t eexp) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TF_POWER, eexp); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an tf_named event to the client owning the resource. + * @param resource_ The client's resource + * @param tf named transfer function + */ +static inline void +wp_image_description_info_v1_send_tf_named(struct wl_resource *resource_, uint32_t tf) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TF_NAMED, tf); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an luminances event to the client owning the resource. + * @param resource_ The client's resource + * @param min_lum minimum luminance (cd/m²) * 10000 + * @param max_lum maximum luminance (cd/m²) + * @param reference_lum reference white luminance (cd/m²) + */ +static inline void +wp_image_description_info_v1_send_luminances(struct wl_resource *resource_, uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_LUMINANCES, min_lum, max_lum, reference_lum); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an target_primaries event to the client owning the resource. + * @param resource_ The client's resource + * @param r_x Red x * 1M + * @param r_y Red y * 1M + * @param g_x Green x * 1M + * @param g_y Green y * 1M + * @param b_x Blue x * 1M + * @param b_y Blue y * 1M + * @param w_x White x * 1M + * @param w_y White y * 1M + */ +static inline void +wp_image_description_info_v1_send_target_primaries(struct wl_resource *resource_, int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_PRIMARIES, r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an target_luminance event to the client owning the resource. + * @param resource_ The client's resource + * @param min_lum min L (cd/m²) * 10000 + * @param max_lum max L (cd/m²) + */ +static inline void +wp_image_description_info_v1_send_target_luminance(struct wl_resource *resource_, uint32_t min_lum, uint32_t max_lum) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_LUMINANCE, min_lum, max_lum); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an target_max_cll event to the client owning the resource. + * @param resource_ The client's resource + * @param max_cll Maximum content light-level (cd/m²) + */ +static inline void +wp_image_description_info_v1_send_target_max_cll(struct wl_resource *resource_, uint32_t max_cll) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_CLL, max_cll); +} + +/** + * @ingroup iface_wp_image_description_info_v1 + * Sends an target_max_fall event to the client owning the resource. + * @param resource_ The client's resource + * @param max_fall Maximum frame-average light level (cd/m²) + */ +static inline void +wp_image_description_info_v1_send_target_max_fall(struct wl_resource *resource_, uint32_t max_fall) +{ + wl_resource_post_event(resource_, WP_IMAGE_DESCRIPTION_INFO_V1_TARGET_MAX_FALL, max_fall); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-client-protocol.h b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-client-protocol.h new file mode 100644 index 0000000000..e7c4665f37 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-client-protocol.h @@ -0,0 +1,1153 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef LINUX_DMABUF_V1_CLIENT_PROTOCOL_H +#define LINUX_DMABUF_V1_CLIENT_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page page_linux_dmabuf_v1 The linux_dmabuf_v1 protocol + * @section page_ifaces_linux_dmabuf_v1 Interfaces + * - @subpage page_iface_zwp_linux_dmabuf_v1 - factory for creating dmabuf-based wl_buffers + * - @subpage page_iface_zwp_linux_buffer_params_v1 - parameters for creating a dmabuf-based wl_buffer + * - @subpage page_iface_zwp_linux_dmabuf_feedback_v1 - dmabuf feedback + * @section page_copyright_linux_dmabuf_v1 Copyright + * <pre> + * + * Copyright © 2014, 2015 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_buffer; +struct wl_surface; +struct zwp_linux_buffer_params_v1; +struct zwp_linux_dmabuf_feedback_v1; +struct zwp_linux_dmabuf_v1; + +#ifndef ZWP_LINUX_DMABUF_V1_INTERFACE +#define ZWP_LINUX_DMABUF_V1_INTERFACE +/** + * @page page_iface_zwp_linux_dmabuf_v1 zwp_linux_dmabuf_v1 + * @section page_iface_zwp_linux_dmabuf_v1_desc Description + * + * This interface offers ways to create generic dmabuf-based wl_buffers. + * + * For more information about dmabuf, see: + * https://www.kernel.org/doc/html/next/userspace-api/dma-buf-alloc-exchange.html + * + * Clients can use the get_surface_feedback request to get dmabuf feedback + * for a particular surface. If the client wants to retrieve feedback not + * tied to a surface, they can use the get_default_feedback request. + * + * The following are required from clients: + * + * - Clients must ensure that either all data in the dma-buf is + * coherent for all subsequent read access or that coherency is + * correctly handled by the underlying kernel-side dma-buf + * implementation. + * + * - Don't make any more attachments after sending the buffer to the + * compositor. Making more attachments later increases the risk of + * the compositor not being able to use (re-import) an existing + * dmabuf-based wl_buffer. + * + * The underlying graphics stack must ensure the following: + * + * - The dmabuf file descriptors relayed to the server will stay valid + * for the whole lifetime of the wl_buffer. This means the server may + * at any time use those fds to import the dmabuf into any kernel + * sub-system that might accept it. + * + * However, when the underlying graphics stack fails to deliver the + * promise, because of e.g. a device hot-unplug which raises internal + * errors, after the wl_buffer has been successfully created the + * compositor must not raise protocol errors to the client when dmabuf + * import later fails. + * + * To create a wl_buffer from one or more dmabufs, a client creates a + * zwp_linux_buffer_params_v1 object with a zwp_linux_dmabuf_v1.create_params + * request. All planes required by the intended format are added with + * the 'add' request. Finally, a 'create' or 'create_immed' request is + * issued, which has the following outcome depending on the import success. + * + * The 'create' request, + * - on success, triggers a 'created' event which provides the final + * wl_buffer to the client. + * - on failure, triggers a 'failed' event to convey that the server + * cannot use the dmabufs received from the client. + * + * For the 'create_immed' request, + * - on success, the server immediately imports the added dmabufs to + * create a wl_buffer. No event is sent from the server in this case. + * - on failure, the server can choose to either: + * - terminate the client by raising a fatal error. + * - mark the wl_buffer as failed, and send a 'failed' event to the + * client. If the client uses a failed wl_buffer as an argument to any + * request, the behaviour is compositor implementation-defined. + * + * For all DRM formats and unless specified in another protocol extension, + * pre-multiplied alpha is used for pixel values. + * + * Unless specified otherwise in another protocol extension, implicit + * synchronization is used. In other words, compositors and clients must + * wait and signal fences implicitly passed via the DMA-BUF's reservation + * mechanism. + * @section page_iface_zwp_linux_dmabuf_v1_api API + * See @ref iface_zwp_linux_dmabuf_v1. + */ +/** + * @defgroup iface_zwp_linux_dmabuf_v1 The zwp_linux_dmabuf_v1 interface + * + * This interface offers ways to create generic dmabuf-based wl_buffers. + * + * For more information about dmabuf, see: + * https://www.kernel.org/doc/html/next/userspace-api/dma-buf-alloc-exchange.html + * + * Clients can use the get_surface_feedback request to get dmabuf feedback + * for a particular surface. If the client wants to retrieve feedback not + * tied to a surface, they can use the get_default_feedback request. + * + * The following are required from clients: + * + * - Clients must ensure that either all data in the dma-buf is + * coherent for all subsequent read access or that coherency is + * correctly handled by the underlying kernel-side dma-buf + * implementation. + * + * - Don't make any more attachments after sending the buffer to the + * compositor. Making more attachments later increases the risk of + * the compositor not being able to use (re-import) an existing + * dmabuf-based wl_buffer. + * + * The underlying graphics stack must ensure the following: + * + * - The dmabuf file descriptors relayed to the server will stay valid + * for the whole lifetime of the wl_buffer. This means the server may + * at any time use those fds to import the dmabuf into any kernel + * sub-system that might accept it. + * + * However, when the underlying graphics stack fails to deliver the + * promise, because of e.g. a device hot-unplug which raises internal + * errors, after the wl_buffer has been successfully created the + * compositor must not raise protocol errors to the client when dmabuf + * import later fails. + * + * To create a wl_buffer from one or more dmabufs, a client creates a + * zwp_linux_buffer_params_v1 object with a zwp_linux_dmabuf_v1.create_params + * request. All planes required by the intended format are added with + * the 'add' request. Finally, a 'create' or 'create_immed' request is + * issued, which has the following outcome depending on the import success. + * + * The 'create' request, + * - on success, triggers a 'created' event which provides the final + * wl_buffer to the client. + * - on failure, triggers a 'failed' event to convey that the server + * cannot use the dmabufs received from the client. + * + * For the 'create_immed' request, + * - on success, the server immediately imports the added dmabufs to + * create a wl_buffer. No event is sent from the server in this case. + * - on failure, the server can choose to either: + * - terminate the client by raising a fatal error. + * - mark the wl_buffer as failed, and send a 'failed' event to the + * client. If the client uses a failed wl_buffer as an argument to any + * request, the behaviour is compositor implementation-defined. + * + * For all DRM formats and unless specified in another protocol extension, + * pre-multiplied alpha is used for pixel values. + * + * Unless specified otherwise in another protocol extension, implicit + * synchronization is used. In other words, compositors and clients must + * wait and signal fences implicitly passed via the DMA-BUF's reservation + * mechanism. + */ +extern const struct wl_interface zwp_linux_dmabuf_v1_interface; +#endif +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_INTERFACE +#define ZWP_LINUX_BUFFER_PARAMS_V1_INTERFACE +/** + * @page page_iface_zwp_linux_buffer_params_v1 zwp_linux_buffer_params_v1 + * @section page_iface_zwp_linux_buffer_params_v1_desc Description + * + * This temporary object is a collection of dmabufs and other + * parameters that together form a single logical buffer. The temporary + * object may eventually create one wl_buffer unless cancelled by + * destroying it before requesting 'create'. + * + * Single-planar formats only require one dmabuf, however + * multi-planar formats may require more than one dmabuf. For all + * formats, an 'add' request must be called once per plane (even if the + * underlying dmabuf fd is identical). + * + * You must use consecutive plane indices ('plane_idx' argument for 'add') + * from zero to the number of planes used by the drm_fourcc format code. + * All planes required by the format must be given exactly once, but can + * be given in any order. Each plane index can only be set once; subsequent + * calls with a plane index which has already been set will result in a + * plane_set error being generated. + * @section page_iface_zwp_linux_buffer_params_v1_api API + * See @ref iface_zwp_linux_buffer_params_v1. + */ +/** + * @defgroup iface_zwp_linux_buffer_params_v1 The zwp_linux_buffer_params_v1 interface + * + * This temporary object is a collection of dmabufs and other + * parameters that together form a single logical buffer. The temporary + * object may eventually create one wl_buffer unless cancelled by + * destroying it before requesting 'create'. + * + * Single-planar formats only require one dmabuf, however + * multi-planar formats may require more than one dmabuf. For all + * formats, an 'add' request must be called once per plane (even if the + * underlying dmabuf fd is identical). + * + * You must use consecutive plane indices ('plane_idx' argument for 'add') + * from zero to the number of planes used by the drm_fourcc format code. + * All planes required by the format must be given exactly once, but can + * be given in any order. Each plane index can only be set once; subsequent + * calls with a plane index which has already been set will result in a + * plane_set error being generated. + */ +extern const struct wl_interface zwp_linux_buffer_params_v1_interface; +#endif +#ifndef ZWP_LINUX_DMABUF_FEEDBACK_V1_INTERFACE +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_INTERFACE +/** + * @page page_iface_zwp_linux_dmabuf_feedback_v1 zwp_linux_dmabuf_feedback_v1 + * @section page_iface_zwp_linux_dmabuf_feedback_v1_desc Description + * + * This object advertises dmabuf parameters feedback. This includes the + * preferred devices and the supported formats/modifiers. + * + * The parameters are sent once when this object is created and whenever they + * change. The done event is always sent once after all parameters have been + * sent. When a single parameter changes, all parameters are re-sent by the + * compositor. + * + * Compositors can re-send the parameters when the current client buffer + * allocations are sub-optimal. Compositors should not re-send the + * parameters if re-allocating the buffers would not result in a more optimal + * configuration. In particular, compositors should avoid sending the exact + * same parameters multiple times in a row. + * + * The tranche_target_device and tranche_formats events are grouped by + * tranches of preference. For each tranche, a tranche_target_device, one + * tranche_flags and one or more tranche_formats events are sent, followed + * by a tranche_done event finishing the list. The tranches are sent in + * descending order of preference. All formats and modifiers in the same + * tranche have the same preference. + * + * To send parameters, the compositor sends one main_device event (unless + * the client bound version 6 or above), tranches (each consisting of one + * tranche_target_device event, one tranche_flags event, tranche_formats + * events and then a tranche_done event), then one done event. + * + * With version 6 and above, the compositor must always advertise at least + * one tranche with the sampling flag set. + * + * The compositor sends a format_table event at least once for each dmabuf + * parameters feedback object, before any tranche events. Unless the format + * table contents change later, the compositor is free not to send another + * format_table event for the same dmabuf parameters feedback object. + * @section page_iface_zwp_linux_dmabuf_feedback_v1_api API + * See @ref iface_zwp_linux_dmabuf_feedback_v1. + */ +/** + * @defgroup iface_zwp_linux_dmabuf_feedback_v1 The zwp_linux_dmabuf_feedback_v1 interface + * + * This object advertises dmabuf parameters feedback. This includes the + * preferred devices and the supported formats/modifiers. + * + * The parameters are sent once when this object is created and whenever they + * change. The done event is always sent once after all parameters have been + * sent. When a single parameter changes, all parameters are re-sent by the + * compositor. + * + * Compositors can re-send the parameters when the current client buffer + * allocations are sub-optimal. Compositors should not re-send the + * parameters if re-allocating the buffers would not result in a more optimal + * configuration. In particular, compositors should avoid sending the exact + * same parameters multiple times in a row. + * + * The tranche_target_device and tranche_formats events are grouped by + * tranches of preference. For each tranche, a tranche_target_device, one + * tranche_flags and one or more tranche_formats events are sent, followed + * by a tranche_done event finishing the list. The tranches are sent in + * descending order of preference. All formats and modifiers in the same + * tranche have the same preference. + * + * To send parameters, the compositor sends one main_device event (unless + * the client bound version 6 or above), tranches (each consisting of one + * tranche_target_device event, one tranche_flags event, tranche_formats + * events and then a tranche_done event), then one done event. + * + * With version 6 and above, the compositor must always advertise at least + * one tranche with the sampling flag set. + * + * The compositor sends a format_table event at least once for each dmabuf + * parameters feedback object, before any tranche events. Unless the format + * table contents change later, the compositor is free not to send another + * format_table event for the same dmabuf parameters feedback object. + */ +extern const struct wl_interface zwp_linux_dmabuf_feedback_v1_interface; +#endif + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * @struct zwp_linux_dmabuf_v1_listener + */ +struct zwp_linux_dmabuf_v1_listener { + /** + * supported buffer format + * + * This event advertises one buffer format that the server + * supports. All the supported formats are advertised once when the + * client binds to this interface. A roundtrip after binding + * guarantees that the client has received all supported formats. + * + * For the definition of the format codes, see the + * zwp_linux_buffer_params_v1::create request. + * + * Starting version 4, the format event is deprecated and must not + * be sent by compositors. Instead, use get_default_feedback or + * get_surface_feedback. + * @param format DRM_FORMAT code + * @deprecated Deprecated since version 4 + */ + void (*format)(void *data, + struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, + uint32_t format); + /** + * supported buffer format modifier + * + * This event advertises the formats that the server supports, + * along with the modifiers supported for each format. All the + * supported modifiers for all the supported formats are advertised + * once when the client binds to this interface. A roundtrip after + * binding guarantees that the client has received all supported + * format-modifier pairs. + * + * For legacy support, DRM_FORMAT_MOD_INVALID (that is, modifier_hi + * == 0x00ffffff and modifier_lo == 0xffffffff) is allowed in this + * event. It indicates that the server can support the format with + * an implicit modifier. When a plane has DRM_FORMAT_MOD_INVALID as + * its modifier, it is as if no explicit modifier is specified. The + * effective modifier will be derived from the dmabuf. + * + * A compositor that sends valid modifiers and + * DRM_FORMAT_MOD_INVALID for a given format supports both explicit + * modifiers and implicit modifiers. + * + * For the definition of the format and modifier codes, see the + * zwp_linux_buffer_params_v1::create and + * zwp_linux_buffer_params_v1::add requests. + * + * Starting version 4, the modifier event is deprecated and must + * not be sent by compositors. Instead, use get_default_feedback or + * get_surface_feedback. + * @param format DRM_FORMAT code + * @param modifier_hi high 32 bits of layout modifier + * @param modifier_lo low 32 bits of layout modifier + * @since 3 + * @deprecated Deprecated since version 4 + */ + void (*modifier)(void *data, + struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, + uint32_t format, + uint32_t modifier_hi, + uint32_t modifier_lo); +}; + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +static inline int +zwp_linux_dmabuf_v1_add_listener(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, + const struct zwp_linux_dmabuf_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwp_linux_dmabuf_v1, + (void (**)(void)) listener, data); +} + +#define ZWP_LINUX_DMABUF_V1_DESTROY 0 +#define ZWP_LINUX_DMABUF_V1_CREATE_PARAMS 1 +#define ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK 2 +#define ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK 3 + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_FORMAT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION 3 + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_CREATE_PARAMS_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION 4 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION 4 + +/** @ingroup iface_zwp_linux_dmabuf_v1 */ +static inline void +zwp_linux_dmabuf_v1_set_user_data(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwp_linux_dmabuf_v1, user_data); +} + +/** @ingroup iface_zwp_linux_dmabuf_v1 */ +static inline void * +zwp_linux_dmabuf_v1_get_user_data(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwp_linux_dmabuf_v1); +} + +static inline uint32_t +zwp_linux_dmabuf_v1_get_version(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_v1); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * + * Objects created through this interface, especially wl_buffers, will + * remain valid. + */ +static inline void +zwp_linux_dmabuf_v1_destroy(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_dmabuf_v1, + ZWP_LINUX_DMABUF_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_v1), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * + * This temporary object is used to collect multiple dmabuf handles into + * a single batch to create a wl_buffer. It can only be used once and + * should be destroyed after a 'created' or 'failed' event has been + * received. + */ +static inline struct zwp_linux_buffer_params_v1 * +zwp_linux_dmabuf_v1_create_params(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1) +{ + struct wl_proxy *params_id; + + params_id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_dmabuf_v1, + ZWP_LINUX_DMABUF_V1_CREATE_PARAMS, &zwp_linux_buffer_params_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_v1), 0, NULL); + + return (struct zwp_linux_buffer_params_v1 *) params_id; +} + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * + * This request creates a new zwp_linux_dmabuf_feedback_v1 object not bound + * to a particular surface. This object will deliver feedback about dmabuf + * parameters to use if the client doesn't support per-surface feedback + * (see get_surface_feedback). + */ +static inline struct zwp_linux_dmabuf_feedback_v1 * +zwp_linux_dmabuf_v1_get_default_feedback(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_dmabuf_v1, + ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK, &zwp_linux_dmabuf_feedback_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_v1), 0, NULL); + + return (struct zwp_linux_dmabuf_feedback_v1 *) id; +} + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * + * This request creates a new zwp_linux_dmabuf_feedback_v1 object for the + * specified wl_surface. This object will deliver feedback about dmabuf + * parameters to use for buffers attached to this surface. + * + * If the surface is destroyed before the zwp_linux_dmabuf_feedback_v1 object, + * the feedback object becomes inert. + */ +static inline struct zwp_linux_dmabuf_feedback_v1 * +zwp_linux_dmabuf_v1_get_surface_feedback(struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, struct wl_surface *surface) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_dmabuf_v1, + ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK, &zwp_linux_dmabuf_feedback_v1_interface, wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_v1), 0, NULL, surface); + + return (struct zwp_linux_dmabuf_feedback_v1 *) id; +} + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM +#define ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM +enum zwp_linux_buffer_params_v1_error { + /** + * the zwp_linux_buffer_params_v1 object has already been used to create a wl_buffer + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED = 0, + /** + * plane index out of bounds + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX = 1, + /** + * the plane index was already set + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET = 2, + /** + * missing or too many planes to create a buffer + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE = 3, + /** + * format not supported + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT = 4, + /** + * invalid width or height + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS = 5, + /** + * offset + stride * height goes out of dmabuf bounds + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS = 6, + /** + * invalid wl_buffer resulted from importing dmabufs via the create_immed request on given buffer_params + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER = 7, + /** + * an array with mismatching size for a dev_t was used + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DEV_T_SIZE = 8, +}; +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM */ + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM +#define ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM +enum zwp_linux_buffer_params_v1_flags { + /** + * contents are y-inverted + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT = 1, + /** + * content is interlaced + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED = 2, + /** + * bottom field first + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST = 4, +}; +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM */ + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * @struct zwp_linux_buffer_params_v1_listener + */ +struct zwp_linux_buffer_params_v1_listener { + /** + * buffer creation succeeded + * + * This event indicates that the attempted buffer creation was + * successful. It provides the new wl_buffer referencing the + * dmabuf(s). + * + * Upon receiving this event, the client should destroy the + * zwp_linux_buffer_params_v1 object. + * @param buffer id for the the newly created wl_buffer + */ + void (*created)(void *data, + struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, + struct wl_buffer *buffer); + /** + * buffer creation failed + * + * This event indicates that the attempted buffer creation has + * failed. It usually means that one of the dmabuf constraints has + * not been fulfilled. + * + * Upon receiving this event, the client should destroy the + * zwp_linux_buffer_params_v1 object. + */ + void (*failed)(void *data, + struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1); +}; + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +static inline int +zwp_linux_buffer_params_v1_add_listener(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, + const struct zwp_linux_buffer_params_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwp_linux_buffer_params_v1, + (void (**)(void)) listener, data); +} + +#define ZWP_LINUX_BUFFER_PARAMS_V1_DESTROY 0 +#define ZWP_LINUX_BUFFER_PARAMS_V1_ADD 1 +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE 2 +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_IMMED 3 +#define ZWP_LINUX_BUFFER_PARAMS_V1_SET_SAMPLING_DEVICE 4 + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATED_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_FAILED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_ADD_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_IMMED_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_SET_SAMPLING_DEVICE_SINCE_VERSION 6 + +/** @ingroup iface_zwp_linux_buffer_params_v1 */ +static inline void +zwp_linux_buffer_params_v1_set_user_data(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwp_linux_buffer_params_v1, user_data); +} + +/** @ingroup iface_zwp_linux_buffer_params_v1 */ +static inline void * +zwp_linux_buffer_params_v1_get_user_data(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwp_linux_buffer_params_v1); +} + +static inline uint32_t +zwp_linux_buffer_params_v1_get_version(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1); +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * + * Cleans up the temporary data sent to the server for dmabuf-based + * wl_buffer creation. + */ +static inline void +zwp_linux_buffer_params_v1_destroy(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_buffer_params_v1, + ZWP_LINUX_BUFFER_PARAMS_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * + * This request adds one dmabuf to the set in this + * zwp_linux_buffer_params_v1. + * + * The 64-bit unsigned value combined from modifier_hi and modifier_lo + * is the dmabuf layout modifier. DRM AddFB2 ioctl calls this the + * fb modifier, which is defined in drm_mode.h of Linux UAPI. + * This is an opaque token. Drivers use this token to express tiling, + * compression, etc. driver-specific modifications to the base format + * defined by the DRM fourcc code. + * + * Starting from version 4, the invalid_format protocol error is sent if + * the format + modifier pair was not advertised as supported. + * + * Starting from version 5, the invalid_format protocol error is sent if + * all planes don't use the same modifier. + * + * This request raises the PLANE_IDX error if plane_idx is too large. + * The error PLANE_SET is raised if attempting to set a plane that + * was already set. + */ +static inline void +zwp_linux_buffer_params_v1_add(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, int32_t fd, uint32_t plane_idx, uint32_t offset, uint32_t stride, uint32_t modifier_hi, uint32_t modifier_lo) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_buffer_params_v1, + ZWP_LINUX_BUFFER_PARAMS_V1_ADD, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1), 0, fd, plane_idx, offset, stride, modifier_hi, modifier_lo); +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * + * This asks for creation of a wl_buffer from the added dmabuf + * buffers. The wl_buffer is not created immediately but returned via + * the 'created' event if the dmabuf sharing succeeds. The sharing + * may fail at runtime for reasons a client cannot predict, in + * which case the 'failed' event is triggered. + * + * The 'format' argument is a DRM_FORMAT code, as defined by the + * libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the + * authoritative source on how the format codes should work. + * + * The 'flags' is a bitfield of the flags defined in enum "flags". + * 'y_invert' means that the image needs to be y-flipped. + * + * Flag 'interlaced' means that the frame in the buffer is not + * progressive as usual, but interlaced. An interlaced buffer as + * supported here must always contain both top and bottom fields. + * The top field always begins on the first pixel row. The temporal + * ordering between the two fields is top field first, unless + * 'bottom_first' is specified. It is undefined whether 'bottom_first' + * is ignored if 'interlaced' is not set. + * + * This protocol does not convey any information about field rate, + * duration, or timing, other than the relative ordering between the + * two fields in one buffer. A compositor may have to estimate the + * intended field rate from the incoming buffer rate. It is undefined + * whether the time of receiving wl_surface.commit with a new buffer + * attached, applying the wl_surface state, wl_surface.frame callback + * trigger, presentation, or any other point in the compositor cycle + * is used to measure the frame or field times. There is no support + * for detecting missed or late frames/fields/buffers either, and + * there is no support whatsoever for cooperating with interlaced + * compositor output. + * + * The composited image quality resulting from the use of interlaced + * buffers is explicitly undefined. A compositor may use elaborate + * hardware features or software to deinterlace and create progressive + * output frames from a sequence of interlaced input buffers, or it + * may produce substandard image quality. However, compositors that + * cannot guarantee reasonable image quality in all cases are recommended + * to just reject all interlaced buffers. + * + * Any argument errors, including non-positive width or height, + * mismatch between the number of planes and the format, bad + * format, bad offset or stride, may be indicated by fatal protocol + * errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, + * OUT_OF_BOUNDS. + * + * Dmabuf import errors in the server that are not obvious client + * bugs are returned via the 'failed' event as non-fatal. This + * allows attempting dmabuf sharing and falling back in the client + * if it fails. + * + * This request can be sent only once in the object's lifetime, after + * which the only legal request is destroy. This object should be + * destroyed after issuing a 'create' request. Attempting to use this + * object after issuing 'create' raises the ALREADY_USED protocol error. + * + * It is not mandatory to issue 'create'. If a client wants to + * cancel the buffer creation, it can just destroy this object. + */ +static inline void +zwp_linux_buffer_params_v1_create(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, int32_t width, int32_t height, uint32_t format, uint32_t flags) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_buffer_params_v1, + ZWP_LINUX_BUFFER_PARAMS_V1_CREATE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1), 0, width, height, format, flags); +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * + * This asks for immediate creation of a wl_buffer by importing the + * added dmabufs. + * + * In case of import success, no event is sent from the server, and the + * wl_buffer is ready to be used by the client. + * + * Upon import failure, either of the following may happen, as seen fit + * by the implementation: + * - the client is terminated with one of the following fatal protocol + * errors: + * - INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS, + * in case of argument errors such as mismatch between the number + * of planes and the format, bad format, non-positive width or + * height, or bad offset or stride. + * - INVALID_WL_BUFFER, in case the cause for failure is unknown or + * platform specific. + * - the server creates an invalid wl_buffer, marks it as failed and + * sends a 'failed' event to the client. The result of using this + * invalid wl_buffer as an argument in any request by the client is + * defined by the compositor implementation. + * + * This takes the same arguments as a 'create' request, and obeys the + * same restrictions. + */ +static inline struct wl_buffer * +zwp_linux_buffer_params_v1_create_immed(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, int32_t width, int32_t height, uint32_t format, uint32_t flags) +{ + struct wl_proxy *buffer_id; + + buffer_id = wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_buffer_params_v1, + ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_IMMED, &wl_buffer_interface, wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1), 0, NULL, width, height, format, flags); + + return (struct wl_buffer *) buffer_id; +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * + * Set the device the compositor should import the dmabufs to for sampling + * in the next create or create_immed request. + * + * To avoid race conditions when the compositor removes a device from the + * tranches, it is not a protocol error if the device hasn't been advertised + * by the compositor in a tranche with the sampling flag, but the import is + * likely to fail in that case. + * + * If the client doesn't know a suitable target device, it shouldn't set one, + * and the compositor should attempt import on all devices it supports. + * + * If the array is too small to contain a dev_t or larger than required, the + * invalid_dev_t_size error will be emitted. + */ +static inline void +zwp_linux_buffer_params_v1_set_sampling_device(struct zwp_linux_buffer_params_v1 *zwp_linux_buffer_params_v1, struct wl_array *device) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_buffer_params_v1, + ZWP_LINUX_BUFFER_PARAMS_V1_SET_SAMPLING_DEVICE, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_buffer_params_v1), 0, device); +} + +#ifndef ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM +enum zwp_linux_dmabuf_feedback_v1_tranche_flags { + /** + * direct scan-out tranche + * + * The scanout flag is a hint that direct scan-out may be + * attempted by the compositor on the target device if the client + * appropriately allocates a buffer. How to allocate a buffer that + * can be scanned out on the target device is + * implementation-defined. + * @since 4 + */ + ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT = 1, + /** + * sampling tranche + * + * The sampling flag describes that the compositor is able to + * efficiently sample from buffers imported to the target device if + * the client appropriately allocates a buffer. How to allocate a + * buffer that can be efficiently sampled on the target device is + * implementation defined. + * @since 6 + */ + ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SAMPLING = 2, +}; +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT_SINCE_VERSION 4 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SAMPLING_SINCE_VERSION 6 +#endif /* ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM */ + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * @struct zwp_linux_dmabuf_feedback_v1_listener + */ +struct zwp_linux_dmabuf_feedback_v1_listener { + /** + * all feedback has been sent + * + * This event is sent after all parameters of a + * zwp_linux_dmabuf_feedback_v1 object have been sent. + * + * This allows changes to the zwp_linux_dmabuf_feedback_v1 + * parameters to be seen as atomic, even if they happen via + * multiple events. + */ + void (*done)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1); + /** + * format and modifier table + * + * This event provides a file descriptor which can be + * memory-mapped to access the format and modifier table. + * + * The table contains a tightly packed array of consecutive format + * + modifier pairs. Each pair is 16 bytes wide. It contains a + * format as a 32-bit unsigned integer, followed by 4 bytes of + * unused padding, and a modifier as a 64-bit unsigned integer. The + * native endianness is used. + * + * The client must map the file descriptor in read-only private + * mode. + * + * Compositors are not allowed to mutate the table file contents + * once this event has been sent. Instead, compositors must create + * a new, separate table file and re-send feedback parameters. + * Compositors are allowed to store duplicate format + modifier + * pairs in the table. + * @param fd table file descriptor + * @param size table size, in bytes + */ + void (*format_table)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + int32_t fd, + uint32_t size); + /** + * preferred main device + * + * This event advertises the main device that the server prefers + * to use when direct scan-out to the target device isn't possible. + * The advertised main device may be different for each + * zwp_linux_dmabuf_feedback_v1 object, and may change over time. + * + * There is exactly one main device. The compositor must send at + * least one preference tranche with tranche_target_device equal to + * main_device. + * + * Clients need to create buffers that the main device can import + * and read from, otherwise creating the dmabuf wl_buffer will fail + * (see the zwp_linux_buffer_params_v1.create and create_immed + * requests for details). The main device will also likely be kept + * active by the compositor, so clients can use it instead of + * waking up another device for power savings. + * + * In general the device is a DRM node. The DRM node type (primary + * vs. render) is unspecified. Clients must not rely on the + * compositor sending a particular node type. Clients cannot check + * two devices for equality by comparing the dev_t value. + * + * If explicit modifiers are not supported and the client performs + * buffer allocations on a different device than the main device, + * then the client must force the buffer to have a linear layout. + * + * With version 6 and above, this event is no longer sent. Clients + * should use a device with the sampling flag in the tranches + * instead. + * @param device device dev_t value + * @deprecated Deprecated since version 6 + */ + void (*main_device)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + struct wl_array *device); + /** + * a preference tranche has been sent + * + * This event splits tranche_target_device and tranche_formats + * events into preference tranches. It is sent after a set of + * tranche_target_device and tranche_formats events; it represents + * the end of a tranche. The next tranche will have a lower + * preference. + */ + void (*tranche_done)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1); + /** + * target device + * + * This event advertises the target device that the server + * prefers to use for a buffer created given this tranche. The + * advertised target device may be different for each preference + * tranche, and may change over time. + * + * There is exactly one target device per tranche. + * + * The target device may be a scan-out device, for example if the + * compositor prefers to directly scan-out a buffer created given + * this tranche. The target device may be a rendering device, for + * example if the compositor prefers to texture from said buffer. + * + * The client can use this hint to allocate the buffer in a way + * that makes it accessible from the target device, ideally + * directly. The buffer must still be accessible from a device with + * the sampling flag, either through direct import or a potentially + * more expensive fallback path. If the buffer can't be directly + * imported for sampling, then clients must be prepared for the + * compositor changing the tranche priority or making wl_buffer + * creation fail (see the zwp_linux_buffer_params_v1.create and + * create_immed requests for details). + * + * If the device is a DRM node, the DRM node type (primary vs. + * render) is unspecified. Clients must not rely on the compositor + * sending a particular node type. Clients cannot check two devices + * for equality by comparing the dev_t value. + * + * This event is tied to a preference tranche, see the tranche_done + * event. + * @param device device dev_t value + */ + void (*tranche_target_device)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + struct wl_array *device); + /** + * supported buffer format modifiers + * + * This event advertises the format + modifier combinations that + * the compositor supports. + * + * It carries an array of indices, each referring to a format + + * modifier pair in the last received format table (see the + * format_table event). Each index is a 16-bit unsigned integer in + * native endianness. + * + * For legacy support, DRM_FORMAT_MOD_INVALID is an allowed + * modifier. It indicates that the server can support the format + * with an implicit modifier. When a buffer has + * DRM_FORMAT_MOD_INVALID as its modifier, it is as if no explicit + * modifier is specified. The effective modifier will be derived + * from the dmabuf. + * + * A compositor that sends valid modifiers and + * DRM_FORMAT_MOD_INVALID for a given format supports both explicit + * modifiers and implicit modifiers. + * + * Compositors must not send duplicate format + modifier pairs + * within the same tranche or across two different tranches with + * the same target device and flags. + * + * This event is tied to a preference tranche, see the tranche_done + * event. + * + * For the definition of the format and modifier codes, see the + * zwp_linux_buffer_params_v1.create request. + * @param indices array of 16-bit indexes + */ + void (*tranche_formats)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + struct wl_array *indices); + /** + * tranche flags + * + * This event sets tranche-specific flags. This event is tied to + * a preference tranche, see the tranche_done event. With version 6 + * and above, the compositor must set at least one flag in each + * tranche. + * @param flags tranche flags + */ + void (*tranche_flags)(void *data, + struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + uint32_t flags); +}; + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +static inline int +zwp_linux_dmabuf_feedback_v1_add_listener(struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, + const struct zwp_linux_dmabuf_feedback_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1, + (void (**)(void)) listener, data); +} + +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DESTROY 0 + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_FORMAT_TABLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_MAIN_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_TARGET_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FORMATS_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DESTROY_SINCE_VERSION 1 + +/** @ingroup iface_zwp_linux_dmabuf_feedback_v1 */ +static inline void +zwp_linux_dmabuf_feedback_v1_set_user_data(struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1, user_data); +} + +/** @ingroup iface_zwp_linux_dmabuf_feedback_v1 */ +static inline void * +zwp_linux_dmabuf_feedback_v1_get_user_data(struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1); +} + +static inline uint32_t +zwp_linux_dmabuf_feedback_v1_get_version(struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * + * Using this request a client can tell the server that it is not going to + * use the zwp_linux_dmabuf_feedback_v1 object anymore. + */ +static inline void +zwp_linux_dmabuf_feedback_v1_destroy(struct zwp_linux_dmabuf_feedback_v1 *zwp_linux_dmabuf_feedback_v1) +{ + wl_proxy_marshal_flags((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1, + ZWP_LINUX_DMABUF_FEEDBACK_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zwp_linux_dmabuf_feedback_v1), WL_MARSHAL_FLAG_DESTROY); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-protocol.c new file mode 100644 index 0000000000..7d2c38984e --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-protocol.c @@ -0,0 +1,121 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2014, 2015 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_buffer_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface zwp_linux_buffer_params_v1_interface; +extern const struct wl_interface zwp_linux_dmabuf_feedback_v1_interface; + +static const struct wl_interface *linux_dmabuf_v1_types[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &zwp_linux_buffer_params_v1_interface, + &zwp_linux_dmabuf_feedback_v1_interface, + &zwp_linux_dmabuf_feedback_v1_interface, + &wl_surface_interface, + &wl_buffer_interface, + NULL, + NULL, + NULL, + NULL, + &wl_buffer_interface, +}; + +static const struct wl_message zwp_linux_dmabuf_v1_requests[] = { + { "destroy", "", linux_dmabuf_v1_types + 0 }, + { "create_params", "n", linux_dmabuf_v1_types + 6 }, + { "get_default_feedback", "4n", linux_dmabuf_v1_types + 7 }, + { "get_surface_feedback", "4no", linux_dmabuf_v1_types + 8 }, +}; + +static const struct wl_message zwp_linux_dmabuf_v1_events[] = { + { "format", "u", linux_dmabuf_v1_types + 0 }, + { "modifier", "3uuu", linux_dmabuf_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_linux_dmabuf_v1_interface = { + "zwp_linux_dmabuf_v1", 6, + 4, zwp_linux_dmabuf_v1_requests, + 2, zwp_linux_dmabuf_v1_events, +}; + +static const struct wl_message zwp_linux_buffer_params_v1_requests[] = { + { "destroy", "", linux_dmabuf_v1_types + 0 }, + { "add", "huuuuu", linux_dmabuf_v1_types + 0 }, + { "create", "iiuu", linux_dmabuf_v1_types + 0 }, + { "create_immed", "2niiuu", linux_dmabuf_v1_types + 10 }, + { "set_sampling_device", "6a", linux_dmabuf_v1_types + 0 }, +}; + +static const struct wl_message zwp_linux_buffer_params_v1_events[] = { + { "created", "n", linux_dmabuf_v1_types + 15 }, + { "failed", "", linux_dmabuf_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_linux_buffer_params_v1_interface = { + "zwp_linux_buffer_params_v1", 6, + 5, zwp_linux_buffer_params_v1_requests, + 2, zwp_linux_buffer_params_v1_events, +}; + +static const struct wl_message zwp_linux_dmabuf_feedback_v1_requests[] = { + { "destroy", "", linux_dmabuf_v1_types + 0 }, +}; + +static const struct wl_message zwp_linux_dmabuf_feedback_v1_events[] = { + { "done", "", linux_dmabuf_v1_types + 0 }, + { "format_table", "hu", linux_dmabuf_v1_types + 0 }, + { "main_device", "a", linux_dmabuf_v1_types + 0 }, + { "tranche_done", "", linux_dmabuf_v1_types + 0 }, + { "tranche_target_device", "a", linux_dmabuf_v1_types + 0 }, + { "tranche_formats", "a", linux_dmabuf_v1_types + 0 }, + { "tranche_flags", "u", linux_dmabuf_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_linux_dmabuf_feedback_v1_interface = { + "zwp_linux_dmabuf_feedback_v1", 6, + 1, zwp_linux_dmabuf_feedback_v1_requests, + 7, zwp_linux_dmabuf_feedback_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-server-protocol.h new file mode 100644 index 0000000000..7d87d90ace --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/linux-dmabuf-v1-server-protocol.h @@ -0,0 +1,996 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef LINUX_DMABUF_V1_SERVER_PROTOCOL_H +#define LINUX_DMABUF_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_linux_dmabuf_v1 The linux_dmabuf_v1 protocol + * @section page_ifaces_linux_dmabuf_v1 Interfaces + * - @subpage page_iface_zwp_linux_dmabuf_v1 - factory for creating dmabuf-based wl_buffers + * - @subpage page_iface_zwp_linux_buffer_params_v1 - parameters for creating a dmabuf-based wl_buffer + * - @subpage page_iface_zwp_linux_dmabuf_feedback_v1 - dmabuf feedback + * @section page_copyright_linux_dmabuf_v1 Copyright + * <pre> + * + * Copyright © 2014, 2015 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_buffer; +struct wl_surface; +struct zwp_linux_buffer_params_v1; +struct zwp_linux_dmabuf_feedback_v1; +struct zwp_linux_dmabuf_v1; + +#ifndef ZWP_LINUX_DMABUF_V1_INTERFACE +#define ZWP_LINUX_DMABUF_V1_INTERFACE +/** + * @page page_iface_zwp_linux_dmabuf_v1 zwp_linux_dmabuf_v1 + * @section page_iface_zwp_linux_dmabuf_v1_desc Description + * + * This interface offers ways to create generic dmabuf-based wl_buffers. + * + * For more information about dmabuf, see: + * https://www.kernel.org/doc/html/next/userspace-api/dma-buf-alloc-exchange.html + * + * Clients can use the get_surface_feedback request to get dmabuf feedback + * for a particular surface. If the client wants to retrieve feedback not + * tied to a surface, they can use the get_default_feedback request. + * + * The following are required from clients: + * + * - Clients must ensure that either all data in the dma-buf is + * coherent for all subsequent read access or that coherency is + * correctly handled by the underlying kernel-side dma-buf + * implementation. + * + * - Don't make any more attachments after sending the buffer to the + * compositor. Making more attachments later increases the risk of + * the compositor not being able to use (re-import) an existing + * dmabuf-based wl_buffer. + * + * The underlying graphics stack must ensure the following: + * + * - The dmabuf file descriptors relayed to the server will stay valid + * for the whole lifetime of the wl_buffer. This means the server may + * at any time use those fds to import the dmabuf into any kernel + * sub-system that might accept it. + * + * However, when the underlying graphics stack fails to deliver the + * promise, because of e.g. a device hot-unplug which raises internal + * errors, after the wl_buffer has been successfully created the + * compositor must not raise protocol errors to the client when dmabuf + * import later fails. + * + * To create a wl_buffer from one or more dmabufs, a client creates a + * zwp_linux_buffer_params_v1 object with a zwp_linux_dmabuf_v1.create_params + * request. All planes required by the intended format are added with + * the 'add' request. Finally, a 'create' or 'create_immed' request is + * issued, which has the following outcome depending on the import success. + * + * The 'create' request, + * - on success, triggers a 'created' event which provides the final + * wl_buffer to the client. + * - on failure, triggers a 'failed' event to convey that the server + * cannot use the dmabufs received from the client. + * + * For the 'create_immed' request, + * - on success, the server immediately imports the added dmabufs to + * create a wl_buffer. No event is sent from the server in this case. + * - on failure, the server can choose to either: + * - terminate the client by raising a fatal error. + * - mark the wl_buffer as failed, and send a 'failed' event to the + * client. If the client uses a failed wl_buffer as an argument to any + * request, the behaviour is compositor implementation-defined. + * + * For all DRM formats and unless specified in another protocol extension, + * pre-multiplied alpha is used for pixel values. + * + * Unless specified otherwise in another protocol extension, implicit + * synchronization is used. In other words, compositors and clients must + * wait and signal fences implicitly passed via the DMA-BUF's reservation + * mechanism. + * @section page_iface_zwp_linux_dmabuf_v1_api API + * See @ref iface_zwp_linux_dmabuf_v1. + */ +/** + * @defgroup iface_zwp_linux_dmabuf_v1 The zwp_linux_dmabuf_v1 interface + * + * This interface offers ways to create generic dmabuf-based wl_buffers. + * + * For more information about dmabuf, see: + * https://www.kernel.org/doc/html/next/userspace-api/dma-buf-alloc-exchange.html + * + * Clients can use the get_surface_feedback request to get dmabuf feedback + * for a particular surface. If the client wants to retrieve feedback not + * tied to a surface, they can use the get_default_feedback request. + * + * The following are required from clients: + * + * - Clients must ensure that either all data in the dma-buf is + * coherent for all subsequent read access or that coherency is + * correctly handled by the underlying kernel-side dma-buf + * implementation. + * + * - Don't make any more attachments after sending the buffer to the + * compositor. Making more attachments later increases the risk of + * the compositor not being able to use (re-import) an existing + * dmabuf-based wl_buffer. + * + * The underlying graphics stack must ensure the following: + * + * - The dmabuf file descriptors relayed to the server will stay valid + * for the whole lifetime of the wl_buffer. This means the server may + * at any time use those fds to import the dmabuf into any kernel + * sub-system that might accept it. + * + * However, when the underlying graphics stack fails to deliver the + * promise, because of e.g. a device hot-unplug which raises internal + * errors, after the wl_buffer has been successfully created the + * compositor must not raise protocol errors to the client when dmabuf + * import later fails. + * + * To create a wl_buffer from one or more dmabufs, a client creates a + * zwp_linux_buffer_params_v1 object with a zwp_linux_dmabuf_v1.create_params + * request. All planes required by the intended format are added with + * the 'add' request. Finally, a 'create' or 'create_immed' request is + * issued, which has the following outcome depending on the import success. + * + * The 'create' request, + * - on success, triggers a 'created' event which provides the final + * wl_buffer to the client. + * - on failure, triggers a 'failed' event to convey that the server + * cannot use the dmabufs received from the client. + * + * For the 'create_immed' request, + * - on success, the server immediately imports the added dmabufs to + * create a wl_buffer. No event is sent from the server in this case. + * - on failure, the server can choose to either: + * - terminate the client by raising a fatal error. + * - mark the wl_buffer as failed, and send a 'failed' event to the + * client. If the client uses a failed wl_buffer as an argument to any + * request, the behaviour is compositor implementation-defined. + * + * For all DRM formats and unless specified in another protocol extension, + * pre-multiplied alpha is used for pixel values. + * + * Unless specified otherwise in another protocol extension, implicit + * synchronization is used. In other words, compositors and clients must + * wait and signal fences implicitly passed via the DMA-BUF's reservation + * mechanism. + */ +extern const struct wl_interface zwp_linux_dmabuf_v1_interface; +#endif +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_INTERFACE +#define ZWP_LINUX_BUFFER_PARAMS_V1_INTERFACE +/** + * @page page_iface_zwp_linux_buffer_params_v1 zwp_linux_buffer_params_v1 + * @section page_iface_zwp_linux_buffer_params_v1_desc Description + * + * This temporary object is a collection of dmabufs and other + * parameters that together form a single logical buffer. The temporary + * object may eventually create one wl_buffer unless cancelled by + * destroying it before requesting 'create'. + * + * Single-planar formats only require one dmabuf, however + * multi-planar formats may require more than one dmabuf. For all + * formats, an 'add' request must be called once per plane (even if the + * underlying dmabuf fd is identical). + * + * You must use consecutive plane indices ('plane_idx' argument for 'add') + * from zero to the number of planes used by the drm_fourcc format code. + * All planes required by the format must be given exactly once, but can + * be given in any order. Each plane index can only be set once; subsequent + * calls with a plane index which has already been set will result in a + * plane_set error being generated. + * @section page_iface_zwp_linux_buffer_params_v1_api API + * See @ref iface_zwp_linux_buffer_params_v1. + */ +/** + * @defgroup iface_zwp_linux_buffer_params_v1 The zwp_linux_buffer_params_v1 interface + * + * This temporary object is a collection of dmabufs and other + * parameters that together form a single logical buffer. The temporary + * object may eventually create one wl_buffer unless cancelled by + * destroying it before requesting 'create'. + * + * Single-planar formats only require one dmabuf, however + * multi-planar formats may require more than one dmabuf. For all + * formats, an 'add' request must be called once per plane (even if the + * underlying dmabuf fd is identical). + * + * You must use consecutive plane indices ('plane_idx' argument for 'add') + * from zero to the number of planes used by the drm_fourcc format code. + * All planes required by the format must be given exactly once, but can + * be given in any order. Each plane index can only be set once; subsequent + * calls with a plane index which has already been set will result in a + * plane_set error being generated. + */ +extern const struct wl_interface zwp_linux_buffer_params_v1_interface; +#endif +#ifndef ZWP_LINUX_DMABUF_FEEDBACK_V1_INTERFACE +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_INTERFACE +/** + * @page page_iface_zwp_linux_dmabuf_feedback_v1 zwp_linux_dmabuf_feedback_v1 + * @section page_iface_zwp_linux_dmabuf_feedback_v1_desc Description + * + * This object advertises dmabuf parameters feedback. This includes the + * preferred devices and the supported formats/modifiers. + * + * The parameters are sent once when this object is created and whenever they + * change. The done event is always sent once after all parameters have been + * sent. When a single parameter changes, all parameters are re-sent by the + * compositor. + * + * Compositors can re-send the parameters when the current client buffer + * allocations are sub-optimal. Compositors should not re-send the + * parameters if re-allocating the buffers would not result in a more optimal + * configuration. In particular, compositors should avoid sending the exact + * same parameters multiple times in a row. + * + * The tranche_target_device and tranche_formats events are grouped by + * tranches of preference. For each tranche, a tranche_target_device, one + * tranche_flags and one or more tranche_formats events are sent, followed + * by a tranche_done event finishing the list. The tranches are sent in + * descending order of preference. All formats and modifiers in the same + * tranche have the same preference. + * + * To send parameters, the compositor sends one main_device event (unless + * the client bound version 6 or above), tranches (each consisting of one + * tranche_target_device event, one tranche_flags event, tranche_formats + * events and then a tranche_done event), then one done event. + * + * With version 6 and above, the compositor must always advertise at least + * one tranche with the sampling flag set. + * + * The compositor sends a format_table event at least once for each dmabuf + * parameters feedback object, before any tranche events. Unless the format + * table contents change later, the compositor is free not to send another + * format_table event for the same dmabuf parameters feedback object. + * @section page_iface_zwp_linux_dmabuf_feedback_v1_api API + * See @ref iface_zwp_linux_dmabuf_feedback_v1. + */ +/** + * @defgroup iface_zwp_linux_dmabuf_feedback_v1 The zwp_linux_dmabuf_feedback_v1 interface + * + * This object advertises dmabuf parameters feedback. This includes the + * preferred devices and the supported formats/modifiers. + * + * The parameters are sent once when this object is created and whenever they + * change. The done event is always sent once after all parameters have been + * sent. When a single parameter changes, all parameters are re-sent by the + * compositor. + * + * Compositors can re-send the parameters when the current client buffer + * allocations are sub-optimal. Compositors should not re-send the + * parameters if re-allocating the buffers would not result in a more optimal + * configuration. In particular, compositors should avoid sending the exact + * same parameters multiple times in a row. + * + * The tranche_target_device and tranche_formats events are grouped by + * tranches of preference. For each tranche, a tranche_target_device, one + * tranche_flags and one or more tranche_formats events are sent, followed + * by a tranche_done event finishing the list. The tranches are sent in + * descending order of preference. All formats and modifiers in the same + * tranche have the same preference. + * + * To send parameters, the compositor sends one main_device event (unless + * the client bound version 6 or above), tranches (each consisting of one + * tranche_target_device event, one tranche_flags event, tranche_formats + * events and then a tranche_done event), then one done event. + * + * With version 6 and above, the compositor must always advertise at least + * one tranche with the sampling flag set. + * + * The compositor sends a format_table event at least once for each dmabuf + * parameters feedback object, before any tranche events. Unless the format + * table contents change later, the compositor is free not to send another + * format_table event for the same dmabuf parameters feedback object. + */ +extern const struct wl_interface zwp_linux_dmabuf_feedback_v1_interface; +#endif + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * @struct zwp_linux_dmabuf_v1_interface + */ +struct zwp_linux_dmabuf_v1_interface { + /** + * unbind the factory + * + * Objects created through this interface, especially wl_buffers, + * will remain valid. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * create a temporary object for buffer parameters + * + * This temporary object is used to collect multiple dmabuf + * handles into a single batch to create a wl_buffer. It can only + * be used once and should be destroyed after a 'created' or + * 'failed' event has been received. + * @param params_id id for the newly created zwp_linux_buffer_params_v1 + */ + void (*create_params)(struct wl_client *client, + struct wl_resource *resource, + uint32_t params_id); + /** + * get default feedback + * + * This request creates a new zwp_linux_dmabuf_feedback_v1 object + * not bound to a particular surface. This object will deliver + * feedback about dmabuf parameters to use if the client doesn't + * support per-surface feedback (see get_surface_feedback). + * @since 4 + */ + void (*get_default_feedback)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * get feedback for a surface + * + * This request creates a new zwp_linux_dmabuf_feedback_v1 object + * for the specified wl_surface. This object will deliver feedback + * about dmabuf parameters to use for buffers attached to this + * surface. + * + * If the surface is destroyed before the + * zwp_linux_dmabuf_feedback_v1 object, the feedback object becomes + * inert. + * @since 4 + */ + void (*get_surface_feedback)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); +}; + +#define ZWP_LINUX_DMABUF_V1_FORMAT 0 +#define ZWP_LINUX_DMABUF_V1_MODIFIER 1 + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_FORMAT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION 3 + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_CREATE_PARAMS_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION 4 +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + */ +#define ZWP_LINUX_DMABUF_V1_GET_SURFACE_FEEDBACK_SINCE_VERSION 4 + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * Sends an format event to the client owning the resource. + * @param resource_ The client's resource + * @param format DRM_FORMAT code + */ +static inline void +zwp_linux_dmabuf_v1_send_format(struct wl_resource *resource_, uint32_t format) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_V1_FORMAT, format); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_v1 + * Sends an modifier event to the client owning the resource. + * @param resource_ The client's resource + * @param format DRM_FORMAT code + * @param modifier_hi high 32 bits of layout modifier + * @param modifier_lo low 32 bits of layout modifier + */ +static inline void +zwp_linux_dmabuf_v1_send_modifier(struct wl_resource *resource_, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_V1_MODIFIER, format, modifier_hi, modifier_lo); +} + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM +#define ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM +enum zwp_linux_buffer_params_v1_error { + /** + * the zwp_linux_buffer_params_v1 object has already been used to create a wl_buffer + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED = 0, + /** + * plane index out of bounds + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX = 1, + /** + * the plane index was already set + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET = 2, + /** + * missing or too many planes to create a buffer + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE = 3, + /** + * format not supported + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT = 4, + /** + * invalid width or height + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS = 5, + /** + * offset + stride * height goes out of dmabuf bounds + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS = 6, + /** + * invalid wl_buffer resulted from importing dmabufs via the create_immed request on given buffer_params + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER = 7, + /** + * an array with mismatching size for a dev_t was used + */ + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DEV_T_SIZE = 8, +}; +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM */ + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM_IS_VALID +#define ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * Validate a zwp_linux_buffer_params_v1 error value. + * + * @return true on success, false on error. + * @ref zwp_linux_buffer_params_v1_error + */ +static inline bool +zwp_linux_buffer_params_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER: + return version >= 1; + case ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DEV_T_SIZE: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM_IS_VALID */ + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM +#define ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM +enum zwp_linux_buffer_params_v1_flags { + /** + * contents are y-inverted + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT = 1, + /** + * content is interlaced + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED = 2, + /** + * bottom field first + */ + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST = 4, +}; +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM */ + +#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM_IS_VALID +#define ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM_IS_VALID +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * Validate a zwp_linux_buffer_params_v1 flags value. + * + * @return true on success, false on error. + * @ref zwp_linux_buffer_params_v1_flags + */ +static inline bool +zwp_linux_buffer_params_v1_flags_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT; + if (version >= 1) + valid |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED; + if (version >= 1) + valid |= ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST; + return (value & ~valid) == 0; +} +#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * @struct zwp_linux_buffer_params_v1_interface + */ +struct zwp_linux_buffer_params_v1_interface { + /** + * delete this object, used or not + * + * Cleans up the temporary data sent to the server for + * dmabuf-based wl_buffer creation. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * add a dmabuf to the temporary set + * + * This request adds one dmabuf to the set in this + * zwp_linux_buffer_params_v1. + * + * The 64-bit unsigned value combined from modifier_hi and + * modifier_lo is the dmabuf layout modifier. DRM AddFB2 ioctl + * calls this the fb modifier, which is defined in drm_mode.h of + * Linux UAPI. This is an opaque token. Drivers use this token to + * express tiling, compression, etc. driver-specific modifications + * to the base format defined by the DRM fourcc code. + * + * Starting from version 4, the invalid_format protocol error is + * sent if the format + modifier pair was not advertised as + * supported. + * + * Starting from version 5, the invalid_format protocol error is + * sent if all planes don't use the same modifier. + * + * This request raises the PLANE_IDX error if plane_idx is too + * large. The error PLANE_SET is raised if attempting to set a + * plane that was already set. + * @param fd dmabuf fd + * @param plane_idx plane index + * @param offset offset in bytes + * @param stride stride in bytes + * @param modifier_hi high 32 bits of layout modifier + * @param modifier_lo low 32 bits of layout modifier + */ + void (*add)(struct wl_client *client, + struct wl_resource *resource, + int32_t fd, + uint32_t plane_idx, + uint32_t offset, + uint32_t stride, + uint32_t modifier_hi, + uint32_t modifier_lo); + /** + * create a wl_buffer from the given dmabufs + * + * This asks for creation of a wl_buffer from the added dmabuf + * buffers. The wl_buffer is not created immediately but returned + * via the 'created' event if the dmabuf sharing succeeds. The + * sharing may fail at runtime for reasons a client cannot predict, + * in which case the 'failed' event is triggered. + * + * The 'format' argument is a DRM_FORMAT code, as defined by the + * libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the + * authoritative source on how the format codes should work. + * + * The 'flags' is a bitfield of the flags defined in enum "flags". + * 'y_invert' means that the image needs to be y-flipped. + * + * Flag 'interlaced' means that the frame in the buffer is not + * progressive as usual, but interlaced. An interlaced buffer as + * supported here must always contain both top and bottom fields. + * The top field always begins on the first pixel row. The temporal + * ordering between the two fields is top field first, unless + * 'bottom_first' is specified. It is undefined whether + * 'bottom_first' is ignored if 'interlaced' is not set. + * + * This protocol does not convey any information about field rate, + * duration, or timing, other than the relative ordering between + * the two fields in one buffer. A compositor may have to estimate + * the intended field rate from the incoming buffer rate. It is + * undefined whether the time of receiving wl_surface.commit with a + * new buffer attached, applying the wl_surface state, + * wl_surface.frame callback trigger, presentation, or any other + * point in the compositor cycle is used to measure the frame or + * field times. There is no support for detecting missed or late + * frames/fields/buffers either, and there is no support whatsoever + * for cooperating with interlaced compositor output. + * + * The composited image quality resulting from the use of + * interlaced buffers is explicitly undefined. A compositor may use + * elaborate hardware features or software to deinterlace and + * create progressive output frames from a sequence of interlaced + * input buffers, or it may produce substandard image quality. + * However, compositors that cannot guarantee reasonable image + * quality in all cases are recommended to just reject all + * interlaced buffers. + * + * Any argument errors, including non-positive width or height, + * mismatch between the number of planes and the format, bad + * format, bad offset or stride, may be indicated by fatal protocol + * errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, + * OUT_OF_BOUNDS. + * + * Dmabuf import errors in the server that are not obvious client + * bugs are returned via the 'failed' event as non-fatal. This + * allows attempting dmabuf sharing and falling back in the client + * if it fails. + * + * This request can be sent only once in the object's lifetime, + * after which the only legal request is destroy. This object + * should be destroyed after issuing a 'create' request. Attempting + * to use this object after issuing 'create' raises the + * ALREADY_USED protocol error. + * + * It is not mandatory to issue 'create'. If a client wants to + * cancel the buffer creation, it can just destroy this object. + * @param width base plane width in pixels + * @param height base plane height in pixels + * @param format DRM_FORMAT code + * @param flags see enum flags + */ + void (*create)(struct wl_client *client, + struct wl_resource *resource, + int32_t width, + int32_t height, + uint32_t format, + uint32_t flags); + /** + * immediately create a wl_buffer from the given dmabufs + * + * This asks for immediate creation of a wl_buffer by importing + * the added dmabufs. + * + * In case of import success, no event is sent from the server, and + * the wl_buffer is ready to be used by the client. + * + * Upon import failure, either of the following may happen, as seen + * fit by the implementation: - the client is terminated with one + * of the following fatal protocol errors: - INCOMPLETE, + * INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS, in case of + * argument errors such as mismatch between the number of planes + * and the format, bad format, non-positive width or height, or bad + * offset or stride. - INVALID_WL_BUFFER, in case the cause for + * failure is unknown or platform specific. - the server creates an + * invalid wl_buffer, marks it as failed and sends a 'failed' event + * to the client. The result of using this invalid wl_buffer as an + * argument in any request by the client is defined by the + * compositor implementation. + * + * This takes the same arguments as a 'create' request, and obeys + * the same restrictions. + * @param buffer_id id for the newly created wl_buffer + * @param width base plane width in pixels + * @param height base plane height in pixels + * @param format DRM_FORMAT code + * @param flags see enum flags + * @since 2 + */ + void (*create_immed)(struct wl_client *client, + struct wl_resource *resource, + uint32_t buffer_id, + int32_t width, + int32_t height, + uint32_t format, + uint32_t flags); + /** + * set the target device of the wl_buffer + * + * Set the device the compositor should import the dmabufs to for + * sampling in the next create or create_immed request. + * + * To avoid race conditions when the compositor removes a device + * from the tranches, it is not a protocol error if the device + * hasn't been advertised by the compositor in a tranche with the + * sampling flag, but the import is likely to fail in that case. + * + * If the client doesn't know a suitable target device, it + * shouldn't set one, and the compositor should attempt import on + * all devices it supports. + * + * If the array is too small to contain a dev_t or larger than + * required, the invalid_dev_t_size error will be emitted. + * @param device device dev_t value + * @since 6 + */ + void (*set_sampling_device)(struct wl_client *client, + struct wl_resource *resource, + struct wl_array *device); +}; + +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATED 0 +#define ZWP_LINUX_BUFFER_PARAMS_V1_FAILED 1 + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATED_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_FAILED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_ADD_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_IMMED_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + */ +#define ZWP_LINUX_BUFFER_PARAMS_V1_SET_SAMPLING_DEVICE_SINCE_VERSION 6 + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * Sends an created event to the client owning the resource. + * @param resource_ The client's resource + * @param buffer id for the the newly created wl_buffer + */ +static inline void +zwp_linux_buffer_params_v1_send_created(struct wl_resource *resource_, struct wl_resource *buffer) +{ + wl_resource_post_event(resource_, ZWP_LINUX_BUFFER_PARAMS_V1_CREATED, buffer); +} + +/** + * @ingroup iface_zwp_linux_buffer_params_v1 + * Sends an failed event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_linux_buffer_params_v1_send_failed(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_LINUX_BUFFER_PARAMS_V1_FAILED); +} + +#ifndef ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM +enum zwp_linux_dmabuf_feedback_v1_tranche_flags { + /** + * direct scan-out tranche + * + * The scanout flag is a hint that direct scan-out may be + * attempted by the compositor on the target device if the client + * appropriately allocates a buffer. How to allocate a buffer that + * can be scanned out on the target device is + * implementation-defined. + * @since 4 + */ + ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT = 1, + /** + * sampling tranche + * + * The sampling flag describes that the compositor is able to + * efficiently sample from buffers imported to the target device if + * the client appropriately allocates a buffer. How to allocate a + * buffer that can be efficiently sampled on the target device is + * implementation defined. + * @since 6 + */ + ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SAMPLING = 2, +}; +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT_SINCE_VERSION 4 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SAMPLING_SINCE_VERSION 6 +#endif /* ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM */ + +#ifndef ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM_IS_VALID +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM_IS_VALID +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Validate a zwp_linux_dmabuf_feedback_v1 tranche_flags value. + * + * @return true on success, false on error. + * @ref zwp_linux_dmabuf_feedback_v1_tranche_flags + */ +static inline bool +zwp_linux_dmabuf_feedback_v1_tranche_flags_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 4) + valid |= ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT; + if (version >= 6) + valid |= ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SAMPLING; + return (value & ~valid) == 0; +} +#endif /* ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * @struct zwp_linux_dmabuf_feedback_v1_interface + */ +struct zwp_linux_dmabuf_feedback_v1_interface { + /** + * destroy the feedback object + * + * Using this request a client can tell the server that it is not + * going to use the zwp_linux_dmabuf_feedback_v1 object anymore. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DONE 0 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_FORMAT_TABLE 1 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_MAIN_DEVICE 2 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_DONE 3 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_TARGET_DEVICE 4 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FORMATS 5 +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS 6 + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_FORMAT_TABLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_MAIN_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_TARGET_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FORMATS_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + */ +#define ZWP_LINUX_DMABUF_FEEDBACK_V1_DESTROY_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_DONE); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an format_table event to the client owning the resource. + * @param resource_ The client's resource + * @param fd table file descriptor + * @param size table size, in bytes + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_format_table(struct wl_resource *resource_, int32_t fd, uint32_t size) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_FORMAT_TABLE, fd, size); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an main_device event to the client owning the resource. + * @param resource_ The client's resource + * @param device device dev_t value + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_main_device(struct wl_resource *resource_, struct wl_array *device) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_MAIN_DEVICE, device); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an tranche_done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_tranche_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_DONE); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an tranche_target_device event to the client owning the resource. + * @param resource_ The client's resource + * @param device device dev_t value + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_tranche_target_device(struct wl_resource *resource_, struct wl_array *device) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_TARGET_DEVICE, device); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an tranche_formats event to the client owning the resource. + * @param resource_ The client's resource + * @param indices array of 16-bit indexes + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_tranche_formats(struct wl_resource *resource_, struct wl_array *indices) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FORMATS, indices); +} + +/** + * @ingroup iface_zwp_linux_dmabuf_feedback_v1 + * Sends an tranche_flags event to the client owning the resource. + * @param resource_ The client's resource + * @param flags tranche flags + */ +static inline void +zwp_linux_dmabuf_feedback_v1_send_tranche_flags(struct wl_resource *resource_, uint32_t flags) +{ + wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS, flags); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-protocol.c new file mode 100644 index 0000000000..89ea811bad --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-protocol.c @@ -0,0 +1,109 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2014 Jonas Ådahl + * Copyright © 2015 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_pointer_interface; +extern const struct wl_interface wl_region_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface zwp_confined_pointer_v1_interface; +extern const struct wl_interface zwp_locked_pointer_v1_interface; + +static const struct wl_interface *pointer_constraints_unstable_v1_types[] = { + NULL, + NULL, + &zwp_locked_pointer_v1_interface, + &wl_surface_interface, + &wl_pointer_interface, + &wl_region_interface, + NULL, + &zwp_confined_pointer_v1_interface, + &wl_surface_interface, + &wl_pointer_interface, + &wl_region_interface, + NULL, + &wl_region_interface, + &wl_region_interface, +}; + +static const struct wl_message zwp_pointer_constraints_v1_requests[] = { + { "destroy", "", pointer_constraints_unstable_v1_types + 0 }, + { "lock_pointer", "noo?ou", pointer_constraints_unstable_v1_types + 2 }, + { "confine_pointer", "noo?ou", pointer_constraints_unstable_v1_types + 7 }, +}; + +WL_PRIVATE const struct wl_interface zwp_pointer_constraints_v1_interface = { + "zwp_pointer_constraints_v1", 1, + 3, zwp_pointer_constraints_v1_requests, + 0, NULL, +}; + +static const struct wl_message zwp_locked_pointer_v1_requests[] = { + { "destroy", "", pointer_constraints_unstable_v1_types + 0 }, + { "set_cursor_position_hint", "ff", pointer_constraints_unstable_v1_types + 0 }, + { "set_region", "?o", pointer_constraints_unstable_v1_types + 12 }, +}; + +static const struct wl_message zwp_locked_pointer_v1_events[] = { + { "locked", "", pointer_constraints_unstable_v1_types + 0 }, + { "unlocked", "", pointer_constraints_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_locked_pointer_v1_interface = { + "zwp_locked_pointer_v1", 1, + 3, zwp_locked_pointer_v1_requests, + 2, zwp_locked_pointer_v1_events, +}; + +static const struct wl_message zwp_confined_pointer_v1_requests[] = { + { "destroy", "", pointer_constraints_unstable_v1_types + 0 }, + { "set_region", "?o", pointer_constraints_unstable_v1_types + 13 }, +}; + +static const struct wl_message zwp_confined_pointer_v1_events[] = { + { "confined", "", pointer_constraints_unstable_v1_types + 0 }, + { "unconfined", "", pointer_constraints_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_confined_pointer_v1_interface = { + "zwp_confined_pointer_v1", 1, + 2, zwp_confined_pointer_v1_requests, + 2, zwp_confined_pointer_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-server-protocol.h new file mode 100644 index 0000000000..8aeb921410 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/pointer-constraints-unstable-v1-server-protocol.h @@ -0,0 +1,619 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef POINTER_CONSTRAINTS_UNSTABLE_V1_SERVER_PROTOCOL_H +#define POINTER_CONSTRAINTS_UNSTABLE_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_pointer_constraints_unstable_v1 The pointer_constraints_unstable_v1 protocol + * protocol for constraining pointer motions + * + * @section page_desc_pointer_constraints_unstable_v1 Description + * + * This protocol specifies a set of interfaces used for adding constraints to + * the motion of a pointer. Possible constraints include confining pointer + * motions to a given region, or locking it to its current position. + * + * In order to constrain the pointer, a client must first bind the global + * interface "wp_pointer_constraints" which, if a compositor supports pointer + * constraints, is exposed by the registry. Using the bound global object, the + * client uses the request that corresponds to the type of constraint it wants + * to make. See wp_pointer_constraints for more details. + * + * Warning! The protocol described in this file is experimental and backward + * incompatible changes may be made. Backward compatible changes may be added + * together with the corresponding interface version bump. Backward + * incompatible changes are done by bumping the version number in the protocol + * and interface names and resetting the interface version. Once the protocol + * is to be declared stable, the 'z' prefix and the version number in the + * protocol and interface names are removed and the interface version number is + * reset. + * + * @section page_ifaces_pointer_constraints_unstable_v1 Interfaces + * - @subpage page_iface_zwp_pointer_constraints_v1 - constrain the movement of a pointer + * - @subpage page_iface_zwp_locked_pointer_v1 - receive relative pointer motion events + * - @subpage page_iface_zwp_confined_pointer_v1 - confined pointer object + * @section page_copyright_pointer_constraints_unstable_v1 Copyright + * <pre> + * + * Copyright © 2014 Jonas Ådahl + * Copyright © 2015 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_pointer; +struct wl_region; +struct wl_surface; +struct zwp_confined_pointer_v1; +struct zwp_locked_pointer_v1; +struct zwp_pointer_constraints_v1; + +#ifndef ZWP_POINTER_CONSTRAINTS_V1_INTERFACE +#define ZWP_POINTER_CONSTRAINTS_V1_INTERFACE +/** + * @page page_iface_zwp_pointer_constraints_v1 zwp_pointer_constraints_v1 + * @section page_iface_zwp_pointer_constraints_v1_desc Description + * + * The global interface exposing pointer constraining functionality. It + * exposes two requests: lock_pointer for locking the pointer to its + * position, and confine_pointer for locking the pointer to a region. + * + * The lock_pointer and confine_pointer requests create the objects + * wp_locked_pointer and wp_confined_pointer respectively, and the client can + * use these objects to interact with the lock. + * + * For any surface, only one lock or confinement may be active across all + * wl_pointer objects of the same seat. If a lock or confinement is requested + * when another lock or confinement is active or requested on the same surface + * and with any of the wl_pointer objects of the same seat, an + * 'already_constrained' error will be raised. + * @section page_iface_zwp_pointer_constraints_v1_api API + * See @ref iface_zwp_pointer_constraints_v1. + */ +/** + * @defgroup iface_zwp_pointer_constraints_v1 The zwp_pointer_constraints_v1 interface + * + * The global interface exposing pointer constraining functionality. It + * exposes two requests: lock_pointer for locking the pointer to its + * position, and confine_pointer for locking the pointer to a region. + * + * The lock_pointer and confine_pointer requests create the objects + * wp_locked_pointer and wp_confined_pointer respectively, and the client can + * use these objects to interact with the lock. + * + * For any surface, only one lock or confinement may be active across all + * wl_pointer objects of the same seat. If a lock or confinement is requested + * when another lock or confinement is active or requested on the same surface + * and with any of the wl_pointer objects of the same seat, an + * 'already_constrained' error will be raised. + */ +extern const struct wl_interface zwp_pointer_constraints_v1_interface; +#endif +#ifndef ZWP_LOCKED_POINTER_V1_INTERFACE +#define ZWP_LOCKED_POINTER_V1_INTERFACE +/** + * @page page_iface_zwp_locked_pointer_v1 zwp_locked_pointer_v1 + * @section page_iface_zwp_locked_pointer_v1_desc Description + * + * The wp_locked_pointer interface represents a locked pointer state. + * + * While the lock of this object is active, the wl_pointer objects of the + * associated seat will not emit any wl_pointer.motion events. + * + * This object will send the event 'locked' when the lock is activated. + * Whenever the lock is activated, it is guaranteed that the locked surface + * will already have received pointer focus and that the pointer will be + * within the region passed to the request creating this object. + * + * To unlock the pointer, send the destroy request. This will also destroy + * the wp_locked_pointer object. + * + * If the compositor decides to unlock the pointer the unlocked event is + * sent. See wp_locked_pointer.unlock for details. + * + * When unlocking, the compositor may warp the cursor position to the set + * cursor position hint. If it does, it will not result in any relative + * motion events emitted via wp_relative_pointer. + * + * If the surface the lock was requested on is destroyed and the lock is not + * yet activated, the wp_locked_pointer object is now defunct and must be + * destroyed. + * @section page_iface_zwp_locked_pointer_v1_api API + * See @ref iface_zwp_locked_pointer_v1. + */ +/** + * @defgroup iface_zwp_locked_pointer_v1 The zwp_locked_pointer_v1 interface + * + * The wp_locked_pointer interface represents a locked pointer state. + * + * While the lock of this object is active, the wl_pointer objects of the + * associated seat will not emit any wl_pointer.motion events. + * + * This object will send the event 'locked' when the lock is activated. + * Whenever the lock is activated, it is guaranteed that the locked surface + * will already have received pointer focus and that the pointer will be + * within the region passed to the request creating this object. + * + * To unlock the pointer, send the destroy request. This will also destroy + * the wp_locked_pointer object. + * + * If the compositor decides to unlock the pointer the unlocked event is + * sent. See wp_locked_pointer.unlock for details. + * + * When unlocking, the compositor may warp the cursor position to the set + * cursor position hint. If it does, it will not result in any relative + * motion events emitted via wp_relative_pointer. + * + * If the surface the lock was requested on is destroyed and the lock is not + * yet activated, the wp_locked_pointer object is now defunct and must be + * destroyed. + */ +extern const struct wl_interface zwp_locked_pointer_v1_interface; +#endif +#ifndef ZWP_CONFINED_POINTER_V1_INTERFACE +#define ZWP_CONFINED_POINTER_V1_INTERFACE +/** + * @page page_iface_zwp_confined_pointer_v1 zwp_confined_pointer_v1 + * @section page_iface_zwp_confined_pointer_v1_desc Description + * + * The wp_confined_pointer interface represents a confined pointer state. + * + * This object will send the event 'confined' when the confinement is + * activated. Whenever the confinement is activated, it is guaranteed that + * the surface the pointer is confined to will already have received pointer + * focus and that the pointer will be within the region passed to the request + * creating this object. It is up to the compositor to decide whether this + * requires some user interaction and if the pointer will warp to within the + * passed region if outside. + * + * To unconfine the pointer, send the destroy request. This will also destroy + * the wp_confined_pointer object. + * + * If the compositor decides to unconfine the pointer the unconfined event is + * sent. The wp_confined_pointer object is at this point defunct and should + * be destroyed. + * @section page_iface_zwp_confined_pointer_v1_api API + * See @ref iface_zwp_confined_pointer_v1. + */ +/** + * @defgroup iface_zwp_confined_pointer_v1 The zwp_confined_pointer_v1 interface + * + * The wp_confined_pointer interface represents a confined pointer state. + * + * This object will send the event 'confined' when the confinement is + * activated. Whenever the confinement is activated, it is guaranteed that + * the surface the pointer is confined to will already have received pointer + * focus and that the pointer will be within the region passed to the request + * creating this object. It is up to the compositor to decide whether this + * requires some user interaction and if the pointer will warp to within the + * passed region if outside. + * + * To unconfine the pointer, send the destroy request. This will also destroy + * the wp_confined_pointer object. + * + * If the compositor decides to unconfine the pointer the unconfined event is + * sent. The wp_confined_pointer object is at this point defunct and should + * be destroyed. + */ +extern const struct wl_interface zwp_confined_pointer_v1_interface; +#endif + +#ifndef ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM +#define ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM +/** + * @ingroup iface_zwp_pointer_constraints_v1 + * wp_pointer_constraints error values + * + * These errors can be emitted in response to wp_pointer_constraints + * requests. + */ +enum zwp_pointer_constraints_v1_error { + /** + * pointer constraint already requested on that surface + */ + ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED = 1, +}; +#endif /* ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM */ + +#ifndef ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM_IS_VALID +#define ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_zwp_pointer_constraints_v1 + * Validate a zwp_pointer_constraints_v1 error value. + * + * @return true on success, false on error. + * @ref zwp_pointer_constraints_v1_error + */ +static inline bool +zwp_pointer_constraints_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM_IS_VALID */ + +#ifndef ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM +#define ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM +/** + * @ingroup iface_zwp_pointer_constraints_v1 + * constraint lifetime + * + * These values represent different lifetime semantics. They are passed + * as arguments to the factory requests to specify how the constraint + * lifetimes should be managed. + */ +enum zwp_pointer_constraints_v1_lifetime { + /** + * the pointer constraint is defunct once deactivated + * + * A oneshot pointer constraint will never reactivate once it has + * been deactivated. See the corresponding deactivation event + * (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) + * for details. + */ + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT = 1, + /** + * the pointer constraint may reactivate + * + * A persistent pointer constraint may again reactivate once it + * has been deactivated. See the corresponding deactivation event + * (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) + * for details. + */ + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT = 2, +}; +#endif /* ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM */ + +#ifndef ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM_IS_VALID +#define ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM_IS_VALID +/** + * @ingroup iface_zwp_pointer_constraints_v1 + * Validate a zwp_pointer_constraints_v1 lifetime value. + * + * @return true on success, false on error. + * @ref zwp_pointer_constraints_v1_lifetime + */ +static inline bool +zwp_pointer_constraints_v1_lifetime_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT: + return version >= 1; + case ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwp_pointer_constraints_v1 + * @struct zwp_pointer_constraints_v1_interface + */ +struct zwp_pointer_constraints_v1_interface { + /** + * destroy the pointer constraints manager object + * + * Used by the client to notify the server that it will no longer + * use this pointer constraints object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * lock pointer to a position + * + * The lock_pointer request lets the client request to disable + * movements of the virtual pointer (i.e. the cursor), effectively + * locking the pointer to a position. This request may not take + * effect immediately; in the future, when the compositor deems + * implementation-specific constraints are satisfied, the pointer + * lock will be activated and the compositor sends a locked event. + * + * The protocol provides no guarantee that the constraints are ever + * satisfied, and does not require the compositor to send an error + * if the constraints cannot ever be satisfied. It is thus possible + * to request a lock that will never activate. + * + * There may not be another pointer constraint of any kind + * requested or active on the surface for any of the wl_pointer + * objects of the seat of the passed pointer when requesting a + * lock. If there is, an error will be raised. See general pointer + * lock documentation for more details. + * + * The intersection of the region passed with this request and the + * input region of the surface is used to determine where the + * pointer must be in order for the lock to activate. It is up to + * the compositor whether to warp the pointer or require some kind + * of user interaction for the lock to activate. If the region is + * null the surface input region is used. + * + * A surface may receive pointer focus without the lock being + * activated. + * + * The request creates a new object wp_locked_pointer which is used + * to interact with the lock as well as receive updates about its + * state. See the the description of wp_locked_pointer for further + * information. + * + * Note that while a pointer is locked, the wl_pointer objects of + * the corresponding seat will not emit any wl_pointer.motion + * events, but relative motion events will still be emitted via + * wp_relative_pointer objects of the same seat. wl_pointer.axis + * and wl_pointer.button events are unaffected. + * @param surface surface to lock pointer to + * @param pointer the pointer that should be locked + * @param region region of surface + * @param lifetime lock lifetime + */ + void (*lock_pointer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface, + struct wl_resource *pointer, + struct wl_resource *region, + uint32_t lifetime); + /** + * confine pointer to a region + * + * The confine_pointer request lets the client request to confine + * the pointer cursor to a given region. This request may not take + * effect immediately; in the future, when the compositor deems + * implementation- specific constraints are satisfied, the pointer + * confinement will be activated and the compositor sends a + * confined event. + * + * The intersection of the region passed with this request and the + * input region of the surface is used to determine where the + * pointer must be in order for the confinement to activate. It is + * up to the compositor whether to warp the pointer or require some + * kind of user interaction for the confinement to activate. If the + * region is null the surface input region is used. + * + * The request will create a new object wp_confined_pointer which + * is used to interact with the confinement as well as receive + * updates about its state. See the the description of + * wp_confined_pointer for further information. + * @param surface surface to lock pointer to + * @param pointer the pointer that should be confined + * @param region region of surface + * @param lifetime confinement lifetime + */ + void (*confine_pointer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface, + struct wl_resource *pointer, + struct wl_resource *region, + uint32_t lifetime); +}; + + +/** + * @ingroup iface_zwp_pointer_constraints_v1 + */ +#define ZWP_POINTER_CONSTRAINTS_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_pointer_constraints_v1 + */ +#define ZWP_POINTER_CONSTRAINTS_V1_LOCK_POINTER_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_pointer_constraints_v1 + */ +#define ZWP_POINTER_CONSTRAINTS_V1_CONFINE_POINTER_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_locked_pointer_v1 + * @struct zwp_locked_pointer_v1_interface + */ +struct zwp_locked_pointer_v1_interface { + /** + * destroy the locked pointer object + * + * Destroy the locked pointer object. If applicable, the + * compositor will unlock the pointer. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the pointer cursor position hint + * + * Set the cursor position hint relative to the top left corner + * of the surface. + * + * If the client is drawing its own cursor, it should update the + * position hint to the position of its own cursor. A compositor + * may use this information to warp the pointer upon unlock in + * order to avoid pointer jumps. + * + * The cursor position hint is double buffered. The new hint will + * only take effect when the associated surface gets it pending + * state applied. See wl_surface.commit for details. + * @param surface_x surface-local x coordinate + * @param surface_y surface-local y coordinate + */ + void (*set_cursor_position_hint)(struct wl_client *client, + struct wl_resource *resource, + wl_fixed_t surface_x, + wl_fixed_t surface_y); + /** + * set a new lock region + * + * Set a new region used to lock the pointer. + * + * The new lock region is double-buffered. The new lock region will + * only take effect when the associated surface gets its pending + * state applied. See wl_surface.commit for details. + * + * For details about the lock region, see wp_locked_pointer. + * @param region region of surface + */ + void (*set_region)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region); +}; + +#define ZWP_LOCKED_POINTER_V1_LOCKED 0 +#define ZWP_LOCKED_POINTER_V1_UNLOCKED 1 + +/** + * @ingroup iface_zwp_locked_pointer_v1 + */ +#define ZWP_LOCKED_POINTER_V1_LOCKED_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_locked_pointer_v1 + */ +#define ZWP_LOCKED_POINTER_V1_UNLOCKED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_locked_pointer_v1 + */ +#define ZWP_LOCKED_POINTER_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_locked_pointer_v1 + */ +#define ZWP_LOCKED_POINTER_V1_SET_CURSOR_POSITION_HINT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_locked_pointer_v1 + */ +#define ZWP_LOCKED_POINTER_V1_SET_REGION_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_locked_pointer_v1 + * Sends an locked event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_locked_pointer_v1_send_locked(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_LOCKED_POINTER_V1_LOCKED); +} + +/** + * @ingroup iface_zwp_locked_pointer_v1 + * Sends an unlocked event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_locked_pointer_v1_send_unlocked(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_LOCKED_POINTER_V1_UNLOCKED); +} + +/** + * @ingroup iface_zwp_confined_pointer_v1 + * @struct zwp_confined_pointer_v1_interface + */ +struct zwp_confined_pointer_v1_interface { + /** + * destroy the confined pointer object + * + * Destroy the confined pointer object. If applicable, the + * compositor will unconfine the pointer. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set a new confine region + * + * Set a new region used to confine the pointer. + * + * The new confine region is double-buffered. The new confine + * region will only take effect when the associated surface gets + * its pending state applied. See wl_surface.commit for details. + * + * If the confinement is active when the new confinement region is + * applied and the pointer ends up outside of newly applied region, + * the pointer may warped to a position within the new confinement + * region. If warped, a wl_pointer.motion event will be emitted, + * but no wp_relative_pointer.relative_motion event. + * + * The compositor may also, instead of using the new region, + * unconfine the pointer. + * + * For details about the confine region, see wp_confined_pointer. + * @param region region of surface + */ + void (*set_region)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region); +}; + +#define ZWP_CONFINED_POINTER_V1_CONFINED 0 +#define ZWP_CONFINED_POINTER_V1_UNCONFINED 1 + +/** + * @ingroup iface_zwp_confined_pointer_v1 + */ +#define ZWP_CONFINED_POINTER_V1_CONFINED_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_confined_pointer_v1 + */ +#define ZWP_CONFINED_POINTER_V1_UNCONFINED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_confined_pointer_v1 + */ +#define ZWP_CONFINED_POINTER_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_confined_pointer_v1 + */ +#define ZWP_CONFINED_POINTER_V1_SET_REGION_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_confined_pointer_v1 + * Sends an confined event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_confined_pointer_v1_send_confined(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_CONFINED_POINTER_V1_CONFINED); +} + +/** + * @ingroup iface_zwp_confined_pointer_v1 + * Sends an unconfined event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_confined_pointer_v1_send_unconfined(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWP_CONFINED_POINTER_V1_UNCONFINED); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/presentation-time-protocol.c b/app/src/main/cpp/waylandcomp/generated/presentation-time-protocol.c new file mode 100644 index 0000000000..63eea910d4 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/presentation-time-protocol.c @@ -0,0 +1,84 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2013-2014 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_output_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface wp_presentation_feedback_interface; + +static const struct wl_interface *presentation_time_types[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &wl_surface_interface, + &wp_presentation_feedback_interface, + &wl_output_interface, +}; + +static const struct wl_message wp_presentation_requests[] = { + { "destroy", "", presentation_time_types + 0 }, + { "feedback", "on", presentation_time_types + 7 }, +}; + +static const struct wl_message wp_presentation_events[] = { + { "clock_id", "u", presentation_time_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_presentation_interface = { + "wp_presentation", 2, + 2, wp_presentation_requests, + 1, wp_presentation_events, +}; + +static const struct wl_message wp_presentation_feedback_events[] = { + { "sync_output", "o", presentation_time_types + 9 }, + { "presented", "uuuuuuu", presentation_time_types + 0 }, + { "discarded", "", presentation_time_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_presentation_feedback_interface = { + "wp_presentation_feedback", 2, + 0, NULL, + 3, wp_presentation_feedback_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/presentation-time-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/presentation-time-server-protocol.h new file mode 100644 index 0000000000..1e1a39c075 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/presentation-time-server-protocol.h @@ -0,0 +1,395 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef PRESENTATION_TIME_SERVER_PROTOCOL_H +#define PRESENTATION_TIME_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_presentation_time The presentation_time protocol + * @section page_ifaces_presentation_time Interfaces + * - @subpage page_iface_wp_presentation - timed presentation related wl_surface requests + * - @subpage page_iface_wp_presentation_feedback - presentation time feedback event + * @section page_copyright_presentation_time Copyright + * <pre> + * + * Copyright © 2013-2014 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_output; +struct wl_surface; +struct wp_presentation; +struct wp_presentation_feedback; + +#ifndef WP_PRESENTATION_INTERFACE +#define WP_PRESENTATION_INTERFACE +/** + * @page page_iface_wp_presentation wp_presentation + * @section page_iface_wp_presentation_desc Description + * + * + * + * + * The main feature of this interface is accurate presentation + * timing feedback to ensure smooth video playback while maintaining + * audio/video synchronization. Some features use the concept of a + * presentation clock, which is defined in the + * presentation.clock_id event. + * + * A content update for a wl_surface is submitted by a + * wl_surface.commit request. Request 'feedback' associates with + * the wl_surface.commit and provides feedback on the content + * update, particularly the final realized presentation time. + * + * + * + * When the final realized presentation time is available, e.g. + * after a framebuffer flip completes, the requested + * presentation_feedback.presented events are sent. The final + * presentation time can differ from the compositor's predicted + * display update time and the update's target time, especially + * when the compositor misses its target vertical blanking period. + * @section page_iface_wp_presentation_api API + * See @ref iface_wp_presentation. + */ +/** + * @defgroup iface_wp_presentation The wp_presentation interface + * + * + * + * + * The main feature of this interface is accurate presentation + * timing feedback to ensure smooth video playback while maintaining + * audio/video synchronization. Some features use the concept of a + * presentation clock, which is defined in the + * presentation.clock_id event. + * + * A content update for a wl_surface is submitted by a + * wl_surface.commit request. Request 'feedback' associates with + * the wl_surface.commit and provides feedback on the content + * update, particularly the final realized presentation time. + * + * + * + * When the final realized presentation time is available, e.g. + * after a framebuffer flip completes, the requested + * presentation_feedback.presented events are sent. The final + * presentation time can differ from the compositor's predicted + * display update time and the update's target time, especially + * when the compositor misses its target vertical blanking period. + */ +extern const struct wl_interface wp_presentation_interface; +#endif +#ifndef WP_PRESENTATION_FEEDBACK_INTERFACE +#define WP_PRESENTATION_FEEDBACK_INTERFACE +/** + * @page page_iface_wp_presentation_feedback wp_presentation_feedback + * @section page_iface_wp_presentation_feedback_desc Description + * + * A presentation_feedback object returns an indication that a + * wl_surface content update has become visible to the user. + * One object corresponds to one content update submission + * (wl_surface.commit). There are two possible outcomes: the + * content update is presented to the user, and a presentation + * timestamp delivered; or, the user did not see the content + * update because it was superseded or its surface destroyed, + * and the content update is discarded. + * + * Once a presentation_feedback object has delivered a 'presented' + * or 'discarded' event it is automatically destroyed. + * @section page_iface_wp_presentation_feedback_api API + * See @ref iface_wp_presentation_feedback. + */ +/** + * @defgroup iface_wp_presentation_feedback The wp_presentation_feedback interface + * + * A presentation_feedback object returns an indication that a + * wl_surface content update has become visible to the user. + * One object corresponds to one content update submission + * (wl_surface.commit). There are two possible outcomes: the + * content update is presented to the user, and a presentation + * timestamp delivered; or, the user did not see the content + * update because it was superseded or its surface destroyed, + * and the content update is discarded. + * + * Once a presentation_feedback object has delivered a 'presented' + * or 'discarded' event it is automatically destroyed. + */ +extern const struct wl_interface wp_presentation_feedback_interface; +#endif + +#ifndef WP_PRESENTATION_ERROR_ENUM +#define WP_PRESENTATION_ERROR_ENUM +/** + * @ingroup iface_wp_presentation + * fatal presentation errors + * + * These fatal protocol errors may be emitted in response to + * illegal presentation requests. + */ +enum wp_presentation_error { + /** + * invalid value in tv_nsec + */ + WP_PRESENTATION_ERROR_INVALID_TIMESTAMP = 0, + /** + * invalid flag + */ + WP_PRESENTATION_ERROR_INVALID_FLAG = 1, +}; +#endif /* WP_PRESENTATION_ERROR_ENUM */ + +#ifndef WP_PRESENTATION_ERROR_ENUM_IS_VALID +#define WP_PRESENTATION_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_presentation + * Validate a wp_presentation error value. + * + * @return true on success, false on error. + * @ref wp_presentation_error + */ +static inline bool +wp_presentation_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_PRESENTATION_ERROR_INVALID_TIMESTAMP: + return version >= 1; + case WP_PRESENTATION_ERROR_INVALID_FLAG: + return version >= 1; + default: + return false; + } +} +#endif /* WP_PRESENTATION_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_presentation + * @struct wp_presentation_interface + */ +struct wp_presentation_interface { + /** + * unbind from the presentation interface + * + * Informs the server that the client will no longer be using + * this protocol object. Existing objects created by this object + * are not affected. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * request presentation feedback information + * + * Request presentation feedback for the current content + * submission on the given surface. This creates a new + * presentation_feedback object, which will deliver the feedback + * information once. If multiple presentation_feedback objects are + * created for the same submission, they will all deliver the same + * information. + * + * For details on what information is returned, see the + * presentation_feedback interface. + * @param surface target surface + * @param callback new feedback object + */ + void (*feedback)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *surface, + uint32_t callback); +}; + +#define WP_PRESENTATION_CLOCK_ID 0 + +/** + * @ingroup iface_wp_presentation + */ +#define WP_PRESENTATION_CLOCK_ID_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_presentation + */ +#define WP_PRESENTATION_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_presentation + */ +#define WP_PRESENTATION_FEEDBACK_SINCE_VERSION 1 + +/** + * @ingroup iface_wp_presentation + * Sends an clock_id event to the client owning the resource. + * @param resource_ The client's resource + * @param clk_id platform clock identifier + */ +static inline void +wp_presentation_send_clock_id(struct wl_resource *resource_, uint32_t clk_id) +{ + wl_resource_post_event(resource_, WP_PRESENTATION_CLOCK_ID, clk_id); +} + +#ifndef WP_PRESENTATION_FEEDBACK_KIND_ENUM +#define WP_PRESENTATION_FEEDBACK_KIND_ENUM +/** + * @ingroup iface_wp_presentation_feedback + * bitmask of flags in presented event + * + * These flags provide information about how the presentation of + * the related content update was done. The intent is to help + * clients assess the reliability of the feedback and the visual + * quality with respect to possible tearing and timings. + */ +enum wp_presentation_feedback_kind { + /** + * presentation was vsync'd + * + * The presentation was synchronized to the "vertical retrace" by + * the display hardware such that tearing does not happen. Relying + * on software scheduling is not acceptable for this flag. If + * presentation is done by a copy to the active frontbuffer, then + * it must guarantee that tearing cannot happen. + */ + WP_PRESENTATION_FEEDBACK_KIND_VSYNC = 0x1, + /** + * hardware provided the presentation timestamp + * + * The display hardware provided measurements that the hardware + * driver converted into a presentation timestamp. Sampling a clock + * in software is not acceptable for this flag. + */ + WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK = 0x2, + /** + * hardware signalled the start of the presentation + * + * The display hardware signalled that it started using the new + * image content. The opposite of this is e.g. a timer being used + * to guess when the display hardware has switched to the new image + * content. + */ + WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION = 0x4, + /** + * presentation was done zero-copy + * + * The presentation of this update was done zero-copy. This means + * the buffer from the client was given to display hardware as is, + * without copying it. Compositing with OpenGL counts as copying, + * even if textured directly from the client buffer. Possible + * zero-copy cases include direct scanout of a fullscreen surface + * and a surface on a hardware overlay. + */ + WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY = 0x8, +}; +#endif /* WP_PRESENTATION_FEEDBACK_KIND_ENUM */ + +#ifndef WP_PRESENTATION_FEEDBACK_KIND_ENUM_IS_VALID +#define WP_PRESENTATION_FEEDBACK_KIND_ENUM_IS_VALID +/** + * @ingroup iface_wp_presentation_feedback + * Validate a wp_presentation_feedback kind value. + * + * @return true on success, false on error. + * @ref wp_presentation_feedback_kind + */ +static inline bool +wp_presentation_feedback_kind_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WP_PRESENTATION_FEEDBACK_KIND_VSYNC; + if (version >= 1) + valid |= WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK; + if (version >= 1) + valid |= WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION; + if (version >= 1) + valid |= WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY; + return (value & ~valid) == 0; +} +#endif /* WP_PRESENTATION_FEEDBACK_KIND_ENUM_IS_VALID */ + +#define WP_PRESENTATION_FEEDBACK_SYNC_OUTPUT 0 +#define WP_PRESENTATION_FEEDBACK_PRESENTED 1 +#define WP_PRESENTATION_FEEDBACK_DISCARDED 2 + +/** + * @ingroup iface_wp_presentation_feedback + */ +#define WP_PRESENTATION_FEEDBACK_SYNC_OUTPUT_SINCE_VERSION 1 +/** + * @ingroup iface_wp_presentation_feedback + */ +#define WP_PRESENTATION_FEEDBACK_PRESENTED_SINCE_VERSION 1 +/** + * @ingroup iface_wp_presentation_feedback + */ +#define WP_PRESENTATION_FEEDBACK_DISCARDED_SINCE_VERSION 1 + + +/** + * @ingroup iface_wp_presentation_feedback + * Sends an sync_output event to the client owning the resource. + * @param resource_ The client's resource + * @param output presentation output + */ +static inline void +wp_presentation_feedback_send_sync_output(struct wl_resource *resource_, struct wl_resource *output) +{ + wl_resource_post_event(resource_, WP_PRESENTATION_FEEDBACK_SYNC_OUTPUT, output); +} + +/** + * @ingroup iface_wp_presentation_feedback + * Sends an presented event to the client owning the resource. + * @param resource_ The client's resource + * @param tv_sec_hi high 32 bits of the seconds part of the presentation timestamp + * @param tv_sec_lo low 32 bits of the seconds part of the presentation timestamp + * @param tv_nsec nanoseconds part of the presentation timestamp + * @param refresh nanoseconds till next refresh + * @param seq_hi high 32 bits of refresh counter + * @param seq_lo low 32 bits of refresh counter + * @param flags combination of 'kind' values + */ +static inline void +wp_presentation_feedback_send_presented(struct wl_resource *resource_, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh, uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) +{ + wl_resource_post_event(resource_, WP_PRESENTATION_FEEDBACK_PRESENTED, tv_sec_hi, tv_sec_lo, tv_nsec, refresh, seq_hi, seq_lo, flags); +} + +/** + * @ingroup iface_wp_presentation_feedback + * Sends an discarded event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wp_presentation_feedback_send_discarded(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WP_PRESENTATION_FEEDBACK_DISCARDED); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-protocol.c new file mode 100644 index 0000000000..454f955562 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-protocol.c @@ -0,0 +1,80 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2014 Jonas Ådahl + * Copyright © 2015 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_pointer_interface; +extern const struct wl_interface zwp_relative_pointer_v1_interface; + +static const struct wl_interface *relative_pointer_unstable_v1_types[] = { + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &zwp_relative_pointer_v1_interface, + &wl_pointer_interface, +}; + +static const struct wl_message zwp_relative_pointer_manager_v1_requests[] = { + { "destroy", "", relative_pointer_unstable_v1_types + 0 }, + { "get_relative_pointer", "no", relative_pointer_unstable_v1_types + 6 }, +}; + +WL_PRIVATE const struct wl_interface zwp_relative_pointer_manager_v1_interface = { + "zwp_relative_pointer_manager_v1", 1, + 2, zwp_relative_pointer_manager_v1_requests, + 0, NULL, +}; + +static const struct wl_message zwp_relative_pointer_v1_requests[] = { + { "destroy", "", relative_pointer_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwp_relative_pointer_v1_events[] = { + { "relative_motion", "uuffff", relative_pointer_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_relative_pointer_v1_interface = { + "zwp_relative_pointer_v1", 1, + 1, zwp_relative_pointer_v1_requests, + 1, zwp_relative_pointer_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-server-protocol.h new file mode 100644 index 0000000000..f40c974980 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/relative-pointer-unstable-v1-server-protocol.h @@ -0,0 +1,204 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef RELATIVE_POINTER_UNSTABLE_V1_SERVER_PROTOCOL_H +#define RELATIVE_POINTER_UNSTABLE_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_relative_pointer_unstable_v1 The relative_pointer_unstable_v1 protocol + * protocol for relative pointer motion events + * + * @section page_desc_relative_pointer_unstable_v1 Description + * + * This protocol specifies a set of interfaces used for making clients able to + * receive relative pointer events not obstructed by barriers (such as the + * monitor edge or other pointer barriers). + * + * To start receiving relative pointer events, a client must first bind the + * global interface "wp_relative_pointer_manager" which, if a compositor + * supports relative pointer motion events, is exposed by the registry. After + * having created the relative pointer manager proxy object, the client uses + * it to create the actual relative pointer object using the + * "get_relative_pointer" request given a wl_pointer. The relative pointer + * motion events will then, when applicable, be transmitted via the proxy of + * the newly created relative pointer object. See the documentation of the + * relative pointer interface for more details. + * + * Warning! The protocol described in this file is experimental and backward + * incompatible changes may be made. Backward compatible changes may be added + * together with the corresponding interface version bump. Backward + * incompatible changes are done by bumping the version number in the protocol + * and interface names and resetting the interface version. Once the protocol + * is to be declared stable, the 'z' prefix and the version number in the + * protocol and interface names are removed and the interface version number is + * reset. + * + * @section page_ifaces_relative_pointer_unstable_v1 Interfaces + * - @subpage page_iface_zwp_relative_pointer_manager_v1 - get relative pointer objects + * - @subpage page_iface_zwp_relative_pointer_v1 - relative pointer object + * @section page_copyright_relative_pointer_unstable_v1 Copyright + * <pre> + * + * Copyright © 2014 Jonas Ådahl + * Copyright © 2015 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_pointer; +struct zwp_relative_pointer_manager_v1; +struct zwp_relative_pointer_v1; + +#ifndef ZWP_RELATIVE_POINTER_MANAGER_V1_INTERFACE +#define ZWP_RELATIVE_POINTER_MANAGER_V1_INTERFACE +/** + * @page page_iface_zwp_relative_pointer_manager_v1 zwp_relative_pointer_manager_v1 + * @section page_iface_zwp_relative_pointer_manager_v1_desc Description + * + * A global interface used for getting the relative pointer object for a + * given pointer. + * @section page_iface_zwp_relative_pointer_manager_v1_api API + * See @ref iface_zwp_relative_pointer_manager_v1. + */ +/** + * @defgroup iface_zwp_relative_pointer_manager_v1 The zwp_relative_pointer_manager_v1 interface + * + * A global interface used for getting the relative pointer object for a + * given pointer. + */ +extern const struct wl_interface zwp_relative_pointer_manager_v1_interface; +#endif +#ifndef ZWP_RELATIVE_POINTER_V1_INTERFACE +#define ZWP_RELATIVE_POINTER_V1_INTERFACE +/** + * @page page_iface_zwp_relative_pointer_v1 zwp_relative_pointer_v1 + * @section page_iface_zwp_relative_pointer_v1_desc Description + * + * A wp_relative_pointer object is an extension to the wl_pointer interface + * used for emitting relative pointer events. It shares the same focus as + * wl_pointer objects of the same seat and will only emit events when it has + * focus. + * @section page_iface_zwp_relative_pointer_v1_api API + * See @ref iface_zwp_relative_pointer_v1. + */ +/** + * @defgroup iface_zwp_relative_pointer_v1 The zwp_relative_pointer_v1 interface + * + * A wp_relative_pointer object is an extension to the wl_pointer interface + * used for emitting relative pointer events. It shares the same focus as + * wl_pointer objects of the same seat and will only emit events when it has + * focus. + */ +extern const struct wl_interface zwp_relative_pointer_v1_interface; +#endif + +/** + * @ingroup iface_zwp_relative_pointer_manager_v1 + * @struct zwp_relative_pointer_manager_v1_interface + */ +struct zwp_relative_pointer_manager_v1_interface { + /** + * destroy the relative pointer manager object + * + * Used by the client to notify the server that it will no longer + * use this relative pointer manager object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * get a relative pointer object + * + * Create a relative pointer interface given a wl_pointer object. + * See the wp_relative_pointer interface for more details. + */ + void (*get_relative_pointer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *pointer); +}; + + +/** + * @ingroup iface_zwp_relative_pointer_manager_v1 + */ +#define ZWP_RELATIVE_POINTER_MANAGER_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_relative_pointer_manager_v1 + */ +#define ZWP_RELATIVE_POINTER_MANAGER_V1_GET_RELATIVE_POINTER_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_relative_pointer_v1 + * @struct zwp_relative_pointer_v1_interface + */ +struct zwp_relative_pointer_v1_interface { + /** + * release the relative pointer object + * + * + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define ZWP_RELATIVE_POINTER_V1_RELATIVE_MOTION 0 + +/** + * @ingroup iface_zwp_relative_pointer_v1 + */ +#define ZWP_RELATIVE_POINTER_V1_RELATIVE_MOTION_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_relative_pointer_v1 + */ +#define ZWP_RELATIVE_POINTER_V1_DESTROY_SINCE_VERSION 1 + +/** + * @ingroup iface_zwp_relative_pointer_v1 + * Sends an relative_motion event to the client owning the resource. + * @param resource_ The client's resource + * @param utime_hi high 32 bits of a 64 bit timestamp with microsecond granularity + * @param utime_lo low 32 bits of a 64 bit timestamp with microsecond granularity + * @param dx the x component of the motion vector + * @param dy the y component of the motion vector + * @param dx_unaccel the x component of the unaccelerated motion vector + * @param dy_unaccel the y component of the unaccelerated motion vector + */ +static inline void +zwp_relative_pointer_v1_send_relative_motion(struct wl_resource *resource_, uint32_t utime_hi, uint32_t utime_lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel) +{ + wl_resource_post_event(resource_, ZWP_RELATIVE_POINTER_V1_RELATIVE_MOTION, utime_hi, utime_lo, dx, dy, dx_unaccel, dy_unaccel); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-protocol.c b/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-protocol.c new file mode 100644 index 0000000000..a6030f8df8 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-protocol.c @@ -0,0 +1,103 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2012, 2013 Intel Corporation + * Copyright © 2015, 2016 Jan Arne Petersen + * Copyright © 2017, 2018 Red Hat, Inc. + * Copyright © 2018 Purism SPC + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_seat_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface zwp_text_input_v3_interface; + +static const struct wl_interface *text_input_unstable_v3_types[] = { + NULL, + NULL, + NULL, + NULL, + &wl_surface_interface, + &wl_surface_interface, + &zwp_text_input_v3_interface, + &wl_seat_interface, +}; + +static const struct wl_message zwp_text_input_v3_requests[] = { + { "destroy", "", text_input_unstable_v3_types + 0 }, + { "enable", "", text_input_unstable_v3_types + 0 }, + { "disable", "", text_input_unstable_v3_types + 0 }, + { "set_surrounding_text", "sii", text_input_unstable_v3_types + 0 }, + { "set_text_change_cause", "u", text_input_unstable_v3_types + 0 }, + { "set_content_type", "uu", text_input_unstable_v3_types + 0 }, + { "set_cursor_rectangle", "iiii", text_input_unstable_v3_types + 0 }, + { "commit", "", text_input_unstable_v3_types + 0 }, + { "set_available_actions", "2a", text_input_unstable_v3_types + 0 }, + { "show_input_panel", "2", text_input_unstable_v3_types + 0 }, + { "hide_input_panel", "2", text_input_unstable_v3_types + 0 }, +}; + +static const struct wl_message zwp_text_input_v3_events[] = { + { "enter", "o", text_input_unstable_v3_types + 4 }, + { "leave", "o", text_input_unstable_v3_types + 5 }, + { "preedit_string", "?sii", text_input_unstable_v3_types + 0 }, + { "commit_string", "?s", text_input_unstable_v3_types + 0 }, + { "delete_surrounding_text", "uu", text_input_unstable_v3_types + 0 }, + { "done", "u", text_input_unstable_v3_types + 0 }, + { "action", "2uu", text_input_unstable_v3_types + 0 }, + { "language", "2s", text_input_unstable_v3_types + 0 }, + { "preedit_hint", "2uuu", text_input_unstable_v3_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwp_text_input_v3_interface = { + "zwp_text_input_v3", 2, + 11, zwp_text_input_v3_requests, + 9, zwp_text_input_v3_events, +}; + +static const struct wl_message zwp_text_input_manager_v3_requests[] = { + { "destroy", "", text_input_unstable_v3_types + 0 }, + { "get_text_input", "no", text_input_unstable_v3_types + 6 }, +}; + +WL_PRIVATE const struct wl_interface zwp_text_input_manager_v3_interface = { + "zwp_text_input_manager_v3", 2, + 2, zwp_text_input_manager_v3_requests, + 0, NULL, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-server-protocol.h new file mode 100644 index 0000000000..c8473dd6ad --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/text-input-unstable-v3-server-protocol.h @@ -0,0 +1,1098 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef TEXT_INPUT_UNSTABLE_V3_SERVER_PROTOCOL_H +#define TEXT_INPUT_UNSTABLE_V3_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_text_input_unstable_v3 The text_input_unstable_v3 protocol + * Protocol for composing text + * + * @section page_desc_text_input_unstable_v3 Description + * + * This protocol allows compositors to act as input methods and to send text + * to applications. A text input object is used to manage state of what are + * typically text entry fields in the application. + * + * This document adheres to the RFC 2119 when using words like "must", + * "should", "may", etc. + * + * Warning! The protocol described in this file is experimental and + * backward incompatible changes may be made. Backward compatible changes + * may be added together with the corresponding interface version bump. + * Backward incompatible changes are done by bumping the version number in + * the protocol and interface names and resetting the interface version. + * Once the protocol is to be declared stable, the 'z' prefix and the + * version number in the protocol and interface names are removed and the + * interface version number is reset. + * + * @section page_ifaces_text_input_unstable_v3 Interfaces + * - @subpage page_iface_zwp_text_input_v3 - text input + * - @subpage page_iface_zwp_text_input_manager_v3 - text input manager + * @section page_copyright_text_input_unstable_v3 Copyright + * <pre> + * + * Copyright © 2012, 2013 Intel Corporation + * Copyright © 2015, 2016 Jan Arne Petersen + * Copyright © 2017, 2018 Red Hat, Inc. + * Copyright © 2018 Purism SPC + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * </pre> + */ +struct wl_seat; +struct wl_surface; +struct zwp_text_input_manager_v3; +struct zwp_text_input_v3; + +#ifndef ZWP_TEXT_INPUT_V3_INTERFACE +#define ZWP_TEXT_INPUT_V3_INTERFACE +/** + * @page page_iface_zwp_text_input_v3 zwp_text_input_v3 + * @section page_iface_zwp_text_input_v3_desc Description + * + * The zwp_text_input_v3 interface represents text input and input methods + * associated with a seat. It provides enter/leave events to follow the + * text input focus for a seat. + * + * Requests are used to enable/disable the text-input object and set + * state information like surrounding and selected text or the content type. + * The information about the entered text is sent to the text-input object + * via the preedit_string and commit_string events. + * + * Text is valid UTF-8 encoded, indices and lengths are in bytes. Indices + * must not point to middle bytes inside a code point: they must either + * point to the first byte of a code point or to the end of the buffer. + * Lengths must be measured between two valid indices. + * + * Focus moving throughout surfaces will result in the emission of + * zwp_text_input_v3.enter and zwp_text_input_v3.leave events. The focused + * surface must commit zwp_text_input_v3.enable and + * zwp_text_input_v3.disable requests as the keyboard focus moves across + * editable and non-editable elements of the UI. Those two requests are not + * expected to be paired with each other, the compositor must be able to + * handle consecutive series of the same request. + * + * State is sent by the state requests (set_surrounding_text, + * set_content_type and set_cursor_rectangle) and a commit request. After an + * enter event or disable request all state information is invalidated and + * needs to be resent by the client. + * @section page_iface_zwp_text_input_v3_api API + * See @ref iface_zwp_text_input_v3. + */ +/** + * @defgroup iface_zwp_text_input_v3 The zwp_text_input_v3 interface + * + * The zwp_text_input_v3 interface represents text input and input methods + * associated with a seat. It provides enter/leave events to follow the + * text input focus for a seat. + * + * Requests are used to enable/disable the text-input object and set + * state information like surrounding and selected text or the content type. + * The information about the entered text is sent to the text-input object + * via the preedit_string and commit_string events. + * + * Text is valid UTF-8 encoded, indices and lengths are in bytes. Indices + * must not point to middle bytes inside a code point: they must either + * point to the first byte of a code point or to the end of the buffer. + * Lengths must be measured between two valid indices. + * + * Focus moving throughout surfaces will result in the emission of + * zwp_text_input_v3.enter and zwp_text_input_v3.leave events. The focused + * surface must commit zwp_text_input_v3.enable and + * zwp_text_input_v3.disable requests as the keyboard focus moves across + * editable and non-editable elements of the UI. Those two requests are not + * expected to be paired with each other, the compositor must be able to + * handle consecutive series of the same request. + * + * State is sent by the state requests (set_surrounding_text, + * set_content_type and set_cursor_rectangle) and a commit request. After an + * enter event or disable request all state information is invalidated and + * needs to be resent by the client. + */ +extern const struct wl_interface zwp_text_input_v3_interface; +#endif +#ifndef ZWP_TEXT_INPUT_MANAGER_V3_INTERFACE +#define ZWP_TEXT_INPUT_MANAGER_V3_INTERFACE +/** + * @page page_iface_zwp_text_input_manager_v3 zwp_text_input_manager_v3 + * @section page_iface_zwp_text_input_manager_v3_desc Description + * + * A factory for text-input objects. This object is a global singleton. + * @section page_iface_zwp_text_input_manager_v3_api API + * See @ref iface_zwp_text_input_manager_v3. + */ +/** + * @defgroup iface_zwp_text_input_manager_v3 The zwp_text_input_manager_v3 interface + * + * A factory for text-input objects. This object is a global singleton. + */ +extern const struct wl_interface zwp_text_input_manager_v3_interface; +#endif + +#ifndef ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM +#define ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM +/** + * @ingroup iface_zwp_text_input_v3 + * text change reason + * + * Reason for the change of surrounding text or cursor posision. + */ +enum zwp_text_input_v3_change_cause { + /** + * input method caused the change + */ + ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD = 0, + /** + * something else than the input method caused the change + */ + ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_OTHER = 1, +}; +#endif /* ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 change_cause value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_change_cause + */ +static inline bool +zwp_text_input_v3_change_cause_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_OTHER: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_ENUM_IS_VALID */ + +#ifndef ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM +#define ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM +/** + * @ingroup iface_zwp_text_input_v3 + * content hint + * + * Content hint is a bitmask to allow to modify the behavior of the text + * input. + */ +enum zwp_text_input_v3_content_hint { + /** + * no special behavior + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE = 0x0, + /** + * suggest word completions + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION = 0x1, + /** + * suggest word corrections + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK = 0x2, + /** + * switch to uppercase letters at the start of a sentence + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION = 0x4, + /** + * prefer lowercase letters + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE = 0x8, + /** + * prefer uppercase letters + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE = 0x10, + /** + * prefer casing for titles and headings (can be language dependent) + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_TITLECASE = 0x20, + /** + * characters should be hidden + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_HIDDEN_TEXT = 0x40, + /** + * typed text should not be stored + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_SENSITIVE_DATA = 0x80, + /** + * just Latin characters should be entered + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_LATIN = 0x100, + /** + * the text input is multiline + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_MULTILINE = 0x200, + /** + * an on-screen way to fill in the input is already provided by the client + * @since 2 + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_ON_SCREEN_INPUT_PROVIDED = 0x400, + /** + * prefer not offering emoji support + * @since 2 + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_NO_EMOJI = 0x800, + /** + * the text input will display preedit text in place + * @since 2 + */ + ZWP_TEXT_INPUT_V3_CONTENT_HINT_PREEDIT_SHOWN = 0x1000, +}; +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_CONTENT_HINT_ON_SCREEN_INPUT_PROVIDED_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_CONTENT_HINT_NO_EMOJI_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_CONTENT_HINT_PREEDIT_SHOWN_SINCE_VERSION 2 +#endif /* ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 content_hint value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_content_hint + */ +static inline bool +zwp_text_input_v3_content_hint_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_TITLECASE; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_HIDDEN_TEXT; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_SENSITIVE_DATA; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LATIN; + if (version >= 1) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_MULTILINE; + if (version >= 2) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_ON_SCREEN_INPUT_PROVIDED; + if (version >= 2) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_NO_EMOJI; + if (version >= 2) + valid |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_PREEDIT_SHOWN; + return (value & ~valid) == 0; +} +#endif /* ZWP_TEXT_INPUT_V3_CONTENT_HINT_ENUM_IS_VALID */ + +#ifndef ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM +#define ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM +/** + * @ingroup iface_zwp_text_input_v3 + * content purpose + * + * The content purpose allows to specify the primary purpose of a text + * input. + * + * This allows an input method to show special purpose input panels with + * extra characters or to disallow some characters. + */ +enum zwp_text_input_v3_content_purpose { + /** + * default input, allowing all characters + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL = 0, + /** + * allow only alphabetic characters + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ALPHA = 1, + /** + * allow only digits + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS = 2, + /** + * input a number (including decimal separator and sign) + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER = 3, + /** + * input a phone number + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE = 4, + /** + * input an URL + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL = 5, + /** + * input an email address + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL = 6, + /** + * input a name of a person + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NAME = 7, + /** + * input a password (combine with sensitive_data hint) + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD = 8, + /** + * input is a numeric password (combine with sensitive_data hint) + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PIN = 9, + /** + * input a date + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATE = 10, + /** + * input a time + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TIME = 11, + /** + * input a date and time + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATETIME = 12, + /** + * input for a terminal + */ + ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL = 13, +}; +#endif /* ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 content_purpose value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_content_purpose + */ +static inline bool +zwp_text_input_v3_content_purpose_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ALPHA: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NAME: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PIN: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATE: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TIME: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATETIME: + return version >= 1; + case ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ENUM_IS_VALID */ + +#ifndef ZWP_TEXT_INPUT_V3_ERROR_ENUM +#define ZWP_TEXT_INPUT_V3_ERROR_ENUM +enum zwp_text_input_v3_error { + /** + * an invalid or duplicate action was specified + */ + ZWP_TEXT_INPUT_V3_ERROR_INVALID_ACTION = 0, +}; +#endif /* ZWP_TEXT_INPUT_V3_ERROR_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_ERROR_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 error value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_error + */ +static inline bool +zwp_text_input_v3_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_TEXT_INPUT_V3_ERROR_INVALID_ACTION: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_TEXT_INPUT_V3_ERROR_ENUM_IS_VALID */ + +#ifndef ZWP_TEXT_INPUT_V3_ACTION_ENUM +#define ZWP_TEXT_INPUT_V3_ACTION_ENUM +/** + * @ingroup iface_zwp_text_input_v3 + * action + * + * A possible action to perform on a text input. + * + * The submit action is intended for input entries that expect some sort of + * activation after user interaction, e.g. the URL entry in a browser. + */ +enum zwp_text_input_v3_action { + /** + * no action + */ + ZWP_TEXT_INPUT_V3_ACTION_NONE = 0, + /** + * the action is submitted + */ + ZWP_TEXT_INPUT_V3_ACTION_SUBMIT = 1, +}; +#endif /* ZWP_TEXT_INPUT_V3_ACTION_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_ACTION_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_ACTION_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 action value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_action + */ +static inline bool +zwp_text_input_v3_action_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_TEXT_INPUT_V3_ACTION_NONE: + return version >= 1; + case ZWP_TEXT_INPUT_V3_ACTION_SUBMIT: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_TEXT_INPUT_V3_ACTION_ENUM_IS_VALID */ + +#ifndef ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM +#define ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM +/** + * @ingroup iface_zwp_text_input_v3 + * preedit style hint + * + * Style hints for the preedit string. + */ +enum zwp_text_input_v3_preedit_hint { + /** + * simple pre-edit text style, typically underlined + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_WHOLE = 1, + /** + * hint for a selected piece of text, e.g. per-character navigation and composition + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SELECTION = 2, + /** + * predicted text, not typed by the user + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_PREDICTION = 3, + /** + * prefixed text not being currently edited, e.g. prior to a 'selection' section + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_PREFIX = 4, + /** + * suffixed text not being currently edited, e.g. after a 'selection' section + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SUFFIX = 5, + /** + * spelling error + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SPELLING_ERROR = 6, + /** + * wrong composition, e.g. user input that can not be transliterated + */ + ZWP_TEXT_INPUT_V3_PREEDIT_HINT_COMPOSE_ERROR = 7, +}; +#endif /* ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM */ + +#ifndef ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM_IS_VALID +#define ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM_IS_VALID +/** + * @ingroup iface_zwp_text_input_v3 + * Validate a zwp_text_input_v3 preedit_hint value. + * + * @return true on success, false on error. + * @ref zwp_text_input_v3_preedit_hint + */ +static inline bool +zwp_text_input_v3_preedit_hint_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_WHOLE: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SELECTION: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_PREDICTION: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_PREFIX: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SUFFIX: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SPELLING_ERROR: + return version >= 1; + case ZWP_TEXT_INPUT_V3_PREEDIT_HINT_COMPOSE_ERROR: + return version >= 1; + default: + return false; + } +} +#endif /* ZWP_TEXT_INPUT_V3_PREEDIT_HINT_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwp_text_input_v3 + * @struct zwp_text_input_v3_interface + */ +struct zwp_text_input_v3_interface { + /** + * Destroy the wp_text_input + * + * Destroy the wp_text_input object. Also disables all surfaces + * enabled through this wp_text_input object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * Request text input to be enabled + * + * Requests text input on the surface previously obtained from + * the enter event. + * + * This request must be issued every time the focused text input + * changes to a new one, including within the current surface. Use + * zwp_text_input_v3.disable when there is no longer any input + * focus on the current surface. + * + * Clients must not enable more than one text input on the single + * seat and should disable the current text input before enabling + * the new one. Requests to enable a text input when another text + * input is enabled on the same seat must be ignored by compositor. + * + * This request resets all state associated with previous enable, + * disable, set_surrounding_text, set_text_change_cause, + * set_content_type, and set_cursor_rectangle requests, as well as + * the state associated with preedit_string, commit_string, and + * delete_surrounding_text events. + * + * The set_surrounding_text, set_content_type and + * set_cursor_rectangle requests must follow if the text input + * supports the necessary functionality. + * + * State set with this request is double-buffered. It will get + * applied on the next zwp_text_input_v3.commit request, and stay + * valid until the next committed enable or disable request. + * + * The changes must be applied by the compositor after issuing a + * zwp_text_input_v3.commit request. + */ + void (*enable)(struct wl_client *client, + struct wl_resource *resource); + /** + * Disable text input on a surface + * + * Explicitly disable text input on the current surface + * (typically when there is no focus on any text entry inside the + * surface). + * + * State set with this request is double-buffered. It will get + * applied on the next zwp_text_input_v3.commit request. + */ + void (*disable)(struct wl_client *client, + struct wl_resource *resource); + /** + * sets the surrounding text + * + * Sets the surrounding plain text around the input, excluding + * the preedit text. + * + * The client should notify the compositor of any changes in any of + * the values carried with this request, including changes caused + * by handling incoming text-input events as well as changes caused + * by other mechanisms like keyboard typing. + * + * If the client is unaware of the text around the cursor, it + * should not issue this request, to signify lack of support to the + * compositor. + * + * Text is UTF-8 encoded, and should include the cursor position, + * the complete selection and additional characters before and + * after them. There is a maximum length of wayland messages, so + * text can not be longer than 4000 bytes. + * + * Cursor is the byte offset of the cursor within text buffer. + * + * Anchor is the byte offset of the selection anchor within text + * buffer. If there is no selected text, anchor is the same as + * cursor. + * + * If any preedit text is present, it is replaced with a cursor for + * the purpose of this event. + * + * Values set with this request are double-buffered. They will get + * applied on the next zwp_text_input_v3.commit request, and stay + * valid until the next committed enable or disable request. + * + * The initial state for affected fields is empty, meaning that the + * text input does not support sending surrounding text. If the + * empty values get applied, subsequent attempts to change them may + * have no effect. + */ + void (*set_surrounding_text)(struct wl_client *client, + struct wl_resource *resource, + const char *text, + int32_t cursor, + int32_t anchor); + /** + * indicates the cause of surrounding text change + * + * Tells the compositor why the text surrounding the cursor + * changed. + * + * Whenever the client detects an external change in text, cursor, + * or anchor posision, it must issue this request to the + * compositor. This request is intended to give the input method a + * chance to update the preedit text in an appropriate way, e.g. by + * removing it when the user starts typing with a keyboard. + * + * cause describes the source of the change. + * + * The value set with this request is double-buffered. It must be + * applied and reset to initial at the next + * zwp_text_input_v3.commit request. + * + * The initial value of cause is input_method. + */ + void (*set_text_change_cause)(struct wl_client *client, + struct wl_resource *resource, + uint32_t cause); + /** + * set content purpose and hint + * + * Sets the content purpose and content hint. While the purpose + * is the basic purpose of an input field, the hint flags allow to + * modify some of the behavior. + * + * Values set with this request are double-buffered. They will get + * applied on the next zwp_text_input_v3.commit request. Subsequent + * attempts to update them may have no effect. The values remain + * valid until the next committed enable or disable request. + * + * The initial value for hint is none, and the initial value for + * purpose is normal. + */ + void (*set_content_type)(struct wl_client *client, + struct wl_resource *resource, + uint32_t hint, + uint32_t purpose); + /** + * set cursor position + * + * Marks an area around the cursor as a x, y, width, height + * rectangle in surface local coordinates. + * + * Allows the compositor to put a window with word suggestions near + * the cursor, without obstructing the text being input. + * + * If the client is unaware of the position of edited text, it + * should not issue this request, to signify lack of support to the + * compositor. + * + * Values set with this request are double-buffered. They will get + * applied on the next zwp_text_input_v3.commit request, and stay + * valid until the next committed enable or disable request. + * + * The initial values describing a cursor rectangle are empty. That + * means the text input does not support describing the cursor + * area. If the empty values get applied, subsequent attempts to + * change them may have no effect. + * + * As of version 2, the zwp_text_input_v3.commit request does not + * apply values sent with this request. Instead, it stores them in + * a separate "committed" area. The committed values, if still + * valid, get applied on the next wl_surface.commit request on the + * surface with text-input focus. Both committed and applied values + * get invalidated on: + * + * - the next committed enable or disable request, or - a change of + * the focused surface of the text-input (leave or enter events). + * + * This double stage application allows the compositor to position + * the input method popup in the same frame as the contents of the + * text on the surface are updated. + */ + void (*set_cursor_rectangle)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * commit state + * + * Atomically applies state changes recently sent to the + * compositor. + * + * The commit request establishes and updates the state of the + * client, and must be issued after any changes to apply them. + * + * Text input state (enabled status, content purpose, content hint, + * surrounding text and change cause, cursor rectangle) is + * conceptually double-buffered within the context of a text input, + * i.e. between a committed enable request and the following + * committed enable or disable request. + * + * Protocol requests modify the pending state, as opposed to the + * current state in use by the input method. A commit request + * atomically applies all pending state, replacing the current + * state. After commit, the new pending state is as documented for + * each related request. + * + * Requests are applied in the order of arrival. + * + * Neither current nor pending state are modified unless noted + * otherwise. + * + * The compositor must count the number of commit requests coming + * from each zwp_text_input_v3 object and use the count as the + * serial in done events. + */ + void (*commit)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the available actions + * + * Set the actions available for this text input. + * + * Values set with this request are double-buffered. They will get + * applied on the next zwp_text_input_v3.commit request. + * + * If the available_actions array contains the none action, or + * contains the same action multiple times, the compositor must + * raise the invalid_action protocol error. + * + * Initially, no actions are available. + * @param available_actions available actions + * @since 2 + */ + void (*set_available_actions)(struct wl_client *client, + struct wl_resource *resource, + struct wl_array *available_actions); + /** + * show input panel + * + * Requests an input panel to be shown (e.g. a on-screen + * keyboard). + * + * This request only hints the desired interaction pattern from the + * client side, and its effect may be ignored by compositors given + * other environmental factors. Repeated calls will be ignored. + * @since 2 + */ + void (*show_input_panel)(struct wl_client *client, + struct wl_resource *resource); + /** + * hide input panel + * + * Requests an input panel to be hidden. + * + * This request only hints the desired interaction pattern from the + * client side, and its effect may be ignored by compositors given + * other environmental factors. Repeated calls will be ignored. + * @since 2 + */ + void (*hide_input_panel)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define ZWP_TEXT_INPUT_V3_ENTER 0 +#define ZWP_TEXT_INPUT_V3_LEAVE 1 +#define ZWP_TEXT_INPUT_V3_PREEDIT_STRING 2 +#define ZWP_TEXT_INPUT_V3_COMMIT_STRING 3 +#define ZWP_TEXT_INPUT_V3_DELETE_SURROUNDING_TEXT 4 +#define ZWP_TEXT_INPUT_V3_DONE 5 +#define ZWP_TEXT_INPUT_V3_ACTION 6 +#define ZWP_TEXT_INPUT_V3_LANGUAGE 7 +#define ZWP_TEXT_INPUT_V3_PREEDIT_HINT 8 + +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_PREEDIT_STRING_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_COMMIT_STRING_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_DELETE_SURROUNDING_TEXT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_ACTION_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_LANGUAGE_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_PREEDIT_HINT_SINCE_VERSION 2 + +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_ENABLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_DISABLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SET_SURROUNDING_TEXT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SET_TEXT_CHANGE_CAUSE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SET_CONTENT_TYPE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SET_CURSOR_RECTANGLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_COMMIT_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SET_AVAILABLE_ACTIONS_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_SHOW_INPUT_PANEL_SINCE_VERSION 2 +/** + * @ingroup iface_zwp_text_input_v3 + */ +#define ZWP_TEXT_INPUT_V3_HIDE_INPUT_PANEL_SINCE_VERSION 2 + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an enter event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_text_input_v3_send_enter(struct wl_resource *resource_, struct wl_resource *surface) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_ENTER, surface); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an leave event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_text_input_v3_send_leave(struct wl_resource *resource_, struct wl_resource *surface) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_LEAVE, surface); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an preedit_string event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_text_input_v3_send_preedit_string(struct wl_resource *resource_, const char *text, int32_t cursor_begin, int32_t cursor_end) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_PREEDIT_STRING, text, cursor_begin, cursor_end); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an commit_string event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_text_input_v3_send_commit_string(struct wl_resource *resource_, const char *text) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_COMMIT_STRING, text); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an delete_surrounding_text event to the client owning the resource. + * @param resource_ The client's resource + * @param before_length length of text before current cursor position + * @param after_length length of text after current cursor position + */ +static inline void +zwp_text_input_v3_send_delete_surrounding_text(struct wl_resource *resource_, uint32_t before_length, uint32_t after_length) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_DELETE_SURROUNDING_TEXT, before_length, after_length); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwp_text_input_v3_send_done(struct wl_resource *resource_, uint32_t serial) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_DONE, serial); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an action event to the client owning the resource. + * @param resource_ The client's resource + * @param action action performed + * @param serial serial number of the action event + */ +static inline void +zwp_text_input_v3_send_action(struct wl_resource *resource_, uint32_t action, uint32_t serial) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_ACTION, action, serial); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an language event to the client owning the resource. + * @param resource_ The client's resource + * @param language new language set by IME + */ +static inline void +zwp_text_input_v3_send_language(struct wl_resource *resource_, const char *language) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_LANGUAGE, language); +} + +/** + * @ingroup iface_zwp_text_input_v3 + * Sends an preedit_hint event to the client owning the resource. + * @param resource_ The client's resource + * @param start starting point of the affected substring + * @param end end point of the affected substring + * @param hint hint to apply + */ +static inline void +zwp_text_input_v3_send_preedit_hint(struct wl_resource *resource_, uint32_t start, uint32_t end, uint32_t hint) +{ + wl_resource_post_event(resource_, ZWP_TEXT_INPUT_V3_PREEDIT_HINT, start, end, hint); +} + +/** + * @ingroup iface_zwp_text_input_manager_v3 + * @struct zwp_text_input_manager_v3_interface + */ +struct zwp_text_input_manager_v3_interface { + /** + * Destroy the wp_text_input_manager + * + * Destroy the wp_text_input_manager object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * create a new text input object + * + * Creates a new text-input object for a given seat. + */ + void (*get_text_input)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *seat); +}; + + +/** + * @ingroup iface_zwp_text_input_manager_v3 + */ +#define ZWP_TEXT_INPUT_MANAGER_V3_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwp_text_input_manager_v3 + */ +#define ZWP_TEXT_INPUT_MANAGER_V3_GET_TEXT_INPUT_SINCE_VERSION 1 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/viewporter-protocol.c b/app/src/main/cpp/waylandcomp/generated/viewporter-protocol.c new file mode 100644 index 0000000000..d6aaa71e7f --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/viewporter-protocol.c @@ -0,0 +1,75 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2013-2016 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface wp_viewport_interface; + +static const struct wl_interface *viewporter_types[] = { + NULL, + NULL, + NULL, + NULL, + &wp_viewport_interface, + &wl_surface_interface, +}; + +static const struct wl_message wp_viewporter_requests[] = { + { "destroy", "", viewporter_types + 0 }, + { "get_viewport", "no", viewporter_types + 4 }, +}; + +WL_PRIVATE const struct wl_interface wp_viewporter_interface = { + "wp_viewporter", 1, + 2, wp_viewporter_requests, + 0, NULL, +}; + +static const struct wl_message wp_viewport_requests[] = { + { "destroy", "", viewporter_types + 0 }, + { "set_source", "ffff", viewporter_types + 0 }, + { "set_destination", "ii", viewporter_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface wp_viewport_interface = { + "wp_viewport", 1, + 3, wp_viewport_requests, + 0, NULL, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/viewporter-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/viewporter-server-protocol.h new file mode 100644 index 0000000000..51957565cb --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/viewporter-server-protocol.h @@ -0,0 +1,401 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef VIEWPORTER_SERVER_PROTOCOL_H +#define VIEWPORTER_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_viewporter The viewporter protocol + * @section page_ifaces_viewporter Interfaces + * - @subpage page_iface_wp_viewporter - surface cropping and scaling + * - @subpage page_iface_wp_viewport - crop and scale interface to a wl_surface + * @section page_copyright_viewporter Copyright + * <pre> + * + * Copyright © 2013-2016 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_surface; +struct wp_viewport; +struct wp_viewporter; + +#ifndef WP_VIEWPORTER_INTERFACE +#define WP_VIEWPORTER_INTERFACE +/** + * @page page_iface_wp_viewporter wp_viewporter + * @section page_iface_wp_viewporter_desc Description + * + * The global interface exposing surface cropping and scaling + * capabilities is used to instantiate an interface extension for a + * wl_surface object. This extended interface will then allow + * cropping and scaling the surface contents, effectively + * disconnecting the direct relationship between the buffer and the + * surface size. + * @section page_iface_wp_viewporter_api API + * See @ref iface_wp_viewporter. + */ +/** + * @defgroup iface_wp_viewporter The wp_viewporter interface + * + * The global interface exposing surface cropping and scaling + * capabilities is used to instantiate an interface extension for a + * wl_surface object. This extended interface will then allow + * cropping and scaling the surface contents, effectively + * disconnecting the direct relationship between the buffer and the + * surface size. + */ +extern const struct wl_interface wp_viewporter_interface; +#endif +#ifndef WP_VIEWPORT_INTERFACE +#define WP_VIEWPORT_INTERFACE +/** + * @page page_iface_wp_viewport wp_viewport + * @section page_iface_wp_viewport_desc Description + * + * An additional interface to a wl_surface object, which allows the + * client to specify the cropping and scaling of the surface + * contents. + * + * This interface works with two concepts: the source rectangle (src_x, + * src_y, src_width, src_height), and the destination size (dst_width, + * dst_height). The contents of the source rectangle are scaled to the + * destination size, and content outside the source rectangle is ignored. + * This state is double-buffered, and is applied on the next + * wl_surface.commit. + * + * The two parts of crop and scale state are independent: the source + * rectangle, and the destination size. Initially both are unset, that + * is, no scaling is applied. The whole of the current wl_buffer is + * used as the source, and the surface size is as defined in + * wl_surface.attach. + * + * If the destination size is set, it causes the surface size to become + * dst_width, dst_height. The source (rectangle) is scaled to exactly + * this size. This overrides whatever the attached wl_buffer size is, + * unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface + * has no content and therefore no size. Otherwise, the size is always + * at least 1x1 in surface local coordinates. + * + * If the source rectangle is set, it defines what area of the wl_buffer is + * taken as the source. If the source rectangle is set and the destination + * size is not set, then src_width and src_height must be integers, and the + * surface size becomes the source rectangle size. This results in cropping + * without scaling. If src_width or src_height are not integers and + * destination size is not set, the bad_size protocol error is raised when + * the surface state is applied. + * + * The coordinate transformations from buffer pixel coordinates up to + * the surface-local coordinates happen in the following order: + * 1. buffer_transform (wl_surface.set_buffer_transform) + * 2. buffer_scale (wl_surface.set_buffer_scale) + * 3. crop and scale (wp_viewport.set*) + * This means, that the source rectangle coordinates of crop and scale + * are given in the coordinates after the buffer transform and scale, + * i.e. in the coordinates that would be the surface-local coordinates + * if the crop and scale was not applied. + * + * If src_x or src_y are negative, the bad_value protocol error is raised. + * Otherwise, if the source rectangle is partially or completely outside of + * the non-NULL wl_buffer, then the out_of_buffer protocol error is raised + * when the surface state is applied. A NULL wl_buffer does not raise the + * out_of_buffer error. + * + * If the wl_surface associated with the wp_viewport is destroyed, + * all wp_viewport requests except 'destroy' raise the protocol error + * no_surface. + * + * If the wp_viewport object is destroyed, the crop and scale + * state is removed from the wl_surface. The change will be applied + * on the next wl_surface.commit. + * @section page_iface_wp_viewport_api API + * See @ref iface_wp_viewport. + */ +/** + * @defgroup iface_wp_viewport The wp_viewport interface + * + * An additional interface to a wl_surface object, which allows the + * client to specify the cropping and scaling of the surface + * contents. + * + * This interface works with two concepts: the source rectangle (src_x, + * src_y, src_width, src_height), and the destination size (dst_width, + * dst_height). The contents of the source rectangle are scaled to the + * destination size, and content outside the source rectangle is ignored. + * This state is double-buffered, and is applied on the next + * wl_surface.commit. + * + * The two parts of crop and scale state are independent: the source + * rectangle, and the destination size. Initially both are unset, that + * is, no scaling is applied. The whole of the current wl_buffer is + * used as the source, and the surface size is as defined in + * wl_surface.attach. + * + * If the destination size is set, it causes the surface size to become + * dst_width, dst_height. The source (rectangle) is scaled to exactly + * this size. This overrides whatever the attached wl_buffer size is, + * unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface + * has no content and therefore no size. Otherwise, the size is always + * at least 1x1 in surface local coordinates. + * + * If the source rectangle is set, it defines what area of the wl_buffer is + * taken as the source. If the source rectangle is set and the destination + * size is not set, then src_width and src_height must be integers, and the + * surface size becomes the source rectangle size. This results in cropping + * without scaling. If src_width or src_height are not integers and + * destination size is not set, the bad_size protocol error is raised when + * the surface state is applied. + * + * The coordinate transformations from buffer pixel coordinates up to + * the surface-local coordinates happen in the following order: + * 1. buffer_transform (wl_surface.set_buffer_transform) + * 2. buffer_scale (wl_surface.set_buffer_scale) + * 3. crop and scale (wp_viewport.set*) + * This means, that the source rectangle coordinates of crop and scale + * are given in the coordinates after the buffer transform and scale, + * i.e. in the coordinates that would be the surface-local coordinates + * if the crop and scale was not applied. + * + * If src_x or src_y are negative, the bad_value protocol error is raised. + * Otherwise, if the source rectangle is partially or completely outside of + * the non-NULL wl_buffer, then the out_of_buffer protocol error is raised + * when the surface state is applied. A NULL wl_buffer does not raise the + * out_of_buffer error. + * + * If the wl_surface associated with the wp_viewport is destroyed, + * all wp_viewport requests except 'destroy' raise the protocol error + * no_surface. + * + * If the wp_viewport object is destroyed, the crop and scale + * state is removed from the wl_surface. The change will be applied + * on the next wl_surface.commit. + */ +extern const struct wl_interface wp_viewport_interface; +#endif + +#ifndef WP_VIEWPORTER_ERROR_ENUM +#define WP_VIEWPORTER_ERROR_ENUM +enum wp_viewporter_error { + /** + * the surface already has a viewport object associated + */ + WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS = 0, +}; +#endif /* WP_VIEWPORTER_ERROR_ENUM */ + +#ifndef WP_VIEWPORTER_ERROR_ENUM_IS_VALID +#define WP_VIEWPORTER_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_viewporter + * Validate a wp_viewporter error value. + * + * @return true on success, false on error. + * @ref wp_viewporter_error + */ +static inline bool +wp_viewporter_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS: + return version >= 1; + default: + return false; + } +} +#endif /* WP_VIEWPORTER_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_viewporter + * @struct wp_viewporter_interface + */ +struct wp_viewporter_interface { + /** + * unbind from the cropping and scaling interface + * + * Informs the server that the client will not be using this + * protocol object anymore. This does not affect any other objects, + * wp_viewport objects included. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * extend surface interface for crop and scale + * + * Instantiate an interface extension for the given wl_surface to + * crop and scale its content. If the given wl_surface already has + * a wp_viewport object associated, the viewport_exists protocol + * error is raised. + * @param id the new viewport interface id + * @param surface the surface + */ + void (*get_viewport)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); +}; + + +/** + * @ingroup iface_wp_viewporter + */ +#define WP_VIEWPORTER_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_viewporter + */ +#define WP_VIEWPORTER_GET_VIEWPORT_SINCE_VERSION 1 + +#ifndef WP_VIEWPORT_ERROR_ENUM +#define WP_VIEWPORT_ERROR_ENUM +enum wp_viewport_error { + /** + * negative or zero values in width or height + */ + WP_VIEWPORT_ERROR_BAD_VALUE = 0, + /** + * destination size is not integer + */ + WP_VIEWPORT_ERROR_BAD_SIZE = 1, + /** + * source rectangle extends outside of the content area + */ + WP_VIEWPORT_ERROR_OUT_OF_BUFFER = 2, + /** + * the wl_surface was destroyed + */ + WP_VIEWPORT_ERROR_NO_SURFACE = 3, +}; +#endif /* WP_VIEWPORT_ERROR_ENUM */ + +#ifndef WP_VIEWPORT_ERROR_ENUM_IS_VALID +#define WP_VIEWPORT_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wp_viewport + * Validate a wp_viewport error value. + * + * @return true on success, false on error. + * @ref wp_viewport_error + */ +static inline bool +wp_viewport_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WP_VIEWPORT_ERROR_BAD_VALUE: + return version >= 1; + case WP_VIEWPORT_ERROR_BAD_SIZE: + return version >= 1; + case WP_VIEWPORT_ERROR_OUT_OF_BUFFER: + return version >= 1; + case WP_VIEWPORT_ERROR_NO_SURFACE: + return version >= 1; + default: + return false; + } +} +#endif /* WP_VIEWPORT_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wp_viewport + * @struct wp_viewport_interface + */ +struct wp_viewport_interface { + /** + * remove scaling and cropping from the surface + * + * The associated wl_surface's crop and scale state is removed. + * The change is applied on the next wl_surface.commit. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the source rectangle for cropping + * + * Set the source rectangle of the associated wl_surface. See + * wp_viewport for the description, and relation to the wl_buffer + * size. + * + * If all of x, y, width and height are -1.0, the source rectangle + * is unset instead. Any other set of values where width or height + * are zero or negative, or x or y are negative, raise the + * bad_value protocol error. + * + * The crop and scale state is double-buffered state, and will be + * applied on the next wl_surface.commit. + * @param x source rectangle x + * @param y source rectangle y + * @param width source rectangle width + * @param height source rectangle height + */ + void (*set_source)(struct wl_client *client, + struct wl_resource *resource, + wl_fixed_t x, + wl_fixed_t y, + wl_fixed_t width, + wl_fixed_t height); + /** + * set the surface size for scaling + * + * Set the destination size of the associated wl_surface. See + * wp_viewport for the description, and relation to the wl_buffer + * size. + * + * If width is -1 and height is -1, the destination size is unset + * instead. Any other pair of values for width and height that + * contains zero or negative values raises the bad_value protocol + * error. + * + * The crop and scale state is double-buffered state, and will be + * applied on the next wl_surface.commit. + * @param width surface width + * @param height surface height + */ + void (*set_destination)(struct wl_client *client, + struct wl_resource *resource, + int32_t width, + int32_t height); +}; + + +/** + * @ingroup iface_wp_viewport + */ +#define WP_VIEWPORT_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wp_viewport + */ +#define WP_VIEWPORT_SET_SOURCE_SINCE_VERSION 1 +/** + * @ingroup iface_wp_viewport + */ +#define WP_VIEWPORT_SET_DESTINATION_SINCE_VERSION 1 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-protocol.c new file mode 100644 index 0000000000..4bb2945afc --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-protocol.c @@ -0,0 +1,123 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2018 Simon Ser + * Copyright © 2019 Ivan Molodetskikh + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_seat_interface; +extern const struct wl_interface zwlr_data_control_device_v1_interface; +extern const struct wl_interface zwlr_data_control_offer_v1_interface; +extern const struct wl_interface zwlr_data_control_source_v1_interface; + +static const struct wl_interface *wlr_data_control_unstable_v1_types[] = { + NULL, + NULL, + &zwlr_data_control_source_v1_interface, + &zwlr_data_control_device_v1_interface, + &wl_seat_interface, + &zwlr_data_control_source_v1_interface, + &zwlr_data_control_source_v1_interface, + &zwlr_data_control_offer_v1_interface, + &zwlr_data_control_offer_v1_interface, + &zwlr_data_control_offer_v1_interface, +}; + +static const struct wl_message zwlr_data_control_manager_v1_requests[] = { + { "create_data_source", "n", wlr_data_control_unstable_v1_types + 2 }, + { "get_data_device", "no", wlr_data_control_unstable_v1_types + 3 }, + { "destroy", "", wlr_data_control_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_data_control_manager_v1_interface = { + "zwlr_data_control_manager_v1", 2, + 3, zwlr_data_control_manager_v1_requests, + 0, NULL, +}; + +static const struct wl_message zwlr_data_control_device_v1_requests[] = { + { "set_selection", "?o", wlr_data_control_unstable_v1_types + 5 }, + { "destroy", "", wlr_data_control_unstable_v1_types + 0 }, + { "set_primary_selection", "2?o", wlr_data_control_unstable_v1_types + 6 }, +}; + +static const struct wl_message zwlr_data_control_device_v1_events[] = { + { "data_offer", "n", wlr_data_control_unstable_v1_types + 7 }, + { "selection", "?o", wlr_data_control_unstable_v1_types + 8 }, + { "finished", "", wlr_data_control_unstable_v1_types + 0 }, + { "primary_selection", "2?o", wlr_data_control_unstable_v1_types + 9 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_data_control_device_v1_interface = { + "zwlr_data_control_device_v1", 2, + 3, zwlr_data_control_device_v1_requests, + 4, zwlr_data_control_device_v1_events, +}; + +static const struct wl_message zwlr_data_control_source_v1_requests[] = { + { "offer", "s", wlr_data_control_unstable_v1_types + 0 }, + { "destroy", "", wlr_data_control_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwlr_data_control_source_v1_events[] = { + { "send", "sh", wlr_data_control_unstable_v1_types + 0 }, + { "cancelled", "", wlr_data_control_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_data_control_source_v1_interface = { + "zwlr_data_control_source_v1", 1, + 2, zwlr_data_control_source_v1_requests, + 2, zwlr_data_control_source_v1_events, +}; + +static const struct wl_message zwlr_data_control_offer_v1_requests[] = { + { "receive", "sh", wlr_data_control_unstable_v1_types + 0 }, + { "destroy", "", wlr_data_control_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwlr_data_control_offer_v1_events[] = { + { "offer", "s", wlr_data_control_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_data_control_offer_v1_interface = { + "zwlr_data_control_offer_v1", 1, + 2, zwlr_data_control_offer_v1_requests, + 1, zwlr_data_control_offer_v1_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-server-protocol.h new file mode 100644 index 0000000000..a484875848 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/wlr-data-control-unstable-v1-server-protocol.h @@ -0,0 +1,541 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef WLR_DATA_CONTROL_UNSTABLE_V1_SERVER_PROTOCOL_H +#define WLR_DATA_CONTROL_UNSTABLE_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_wlr_data_control_unstable_v1 The wlr_data_control_unstable_v1 protocol + * control data devices + * + * @section page_desc_wlr_data_control_unstable_v1 Description + * + * This protocol allows a privileged client to control data devices. In + * particular, the client will be able to manage the current selection and take + * the role of a clipboard manager. + * + * Warning! The protocol described in this file is experimental and + * backward incompatible changes may be made. Backward compatible changes + * may be added together with the corresponding interface version bump. + * Backward incompatible changes are done by bumping the version number in + * the protocol and interface names and resetting the interface version. + * Once the protocol is to be declared stable, the 'z' prefix and the + * version number in the protocol and interface names are removed and the + * interface version number is reset. + * + * Note! This protocol is deprecated and not intended for production use. + * For clipboard management, use the ext-data-control-v1 protocol. + * + * @section page_ifaces_wlr_data_control_unstable_v1 Interfaces + * - @subpage page_iface_zwlr_data_control_manager_v1 - manager to control data devices + * - @subpage page_iface_zwlr_data_control_device_v1 - manage a data device for a seat + * - @subpage page_iface_zwlr_data_control_source_v1 - offer to transfer data + * - @subpage page_iface_zwlr_data_control_offer_v1 - offer to transfer data + * @section page_copyright_wlr_data_control_unstable_v1 Copyright + * <pre> + * + * Copyright © 2018 Simon Ser + * Copyright © 2019 Ivan Molodetskikh + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + * </pre> + */ +struct wl_seat; +struct zwlr_data_control_device_v1; +struct zwlr_data_control_manager_v1; +struct zwlr_data_control_offer_v1; +struct zwlr_data_control_source_v1; + +#ifndef ZWLR_DATA_CONTROL_MANAGER_V1_INTERFACE +#define ZWLR_DATA_CONTROL_MANAGER_V1_INTERFACE +/** + * @page page_iface_zwlr_data_control_manager_v1 zwlr_data_control_manager_v1 + * @section page_iface_zwlr_data_control_manager_v1_desc Description + * + * This interface is a manager that allows creating per-seat data device + * controls. + * @section page_iface_zwlr_data_control_manager_v1_api API + * See @ref iface_zwlr_data_control_manager_v1. + */ +/** + * @defgroup iface_zwlr_data_control_manager_v1 The zwlr_data_control_manager_v1 interface + * + * This interface is a manager that allows creating per-seat data device + * controls. + */ +extern const struct wl_interface zwlr_data_control_manager_v1_interface; +#endif +#ifndef ZWLR_DATA_CONTROL_DEVICE_V1_INTERFACE +#define ZWLR_DATA_CONTROL_DEVICE_V1_INTERFACE +/** + * @page page_iface_zwlr_data_control_device_v1 zwlr_data_control_device_v1 + * @section page_iface_zwlr_data_control_device_v1_desc Description + * + * This interface allows a client to manage a seat's selection. + * + * When the seat is destroyed, this object becomes inert. + * @section page_iface_zwlr_data_control_device_v1_api API + * See @ref iface_zwlr_data_control_device_v1. + */ +/** + * @defgroup iface_zwlr_data_control_device_v1 The zwlr_data_control_device_v1 interface + * + * This interface allows a client to manage a seat's selection. + * + * When the seat is destroyed, this object becomes inert. + */ +extern const struct wl_interface zwlr_data_control_device_v1_interface; +#endif +#ifndef ZWLR_DATA_CONTROL_SOURCE_V1_INTERFACE +#define ZWLR_DATA_CONTROL_SOURCE_V1_INTERFACE +/** + * @page page_iface_zwlr_data_control_source_v1 zwlr_data_control_source_v1 + * @section page_iface_zwlr_data_control_source_v1_desc Description + * + * The wlr_data_control_source object is the source side of a + * wlr_data_control_offer. It is created by the source client in a data + * transfer and provides a way to describe the offered data and a way to + * respond to requests to transfer the data. + * @section page_iface_zwlr_data_control_source_v1_api API + * See @ref iface_zwlr_data_control_source_v1. + */ +/** + * @defgroup iface_zwlr_data_control_source_v1 The zwlr_data_control_source_v1 interface + * + * The wlr_data_control_source object is the source side of a + * wlr_data_control_offer. It is created by the source client in a data + * transfer and provides a way to describe the offered data and a way to + * respond to requests to transfer the data. + */ +extern const struct wl_interface zwlr_data_control_source_v1_interface; +#endif +#ifndef ZWLR_DATA_CONTROL_OFFER_V1_INTERFACE +#define ZWLR_DATA_CONTROL_OFFER_V1_INTERFACE +/** + * @page page_iface_zwlr_data_control_offer_v1 zwlr_data_control_offer_v1 + * @section page_iface_zwlr_data_control_offer_v1_desc Description + * + * A wlr_data_control_offer represents a piece of data offered for transfer + * by another client (the source client). The offer describes the different + * MIME types that the data can be converted to and provides the mechanism + * for transferring the data directly from the source client. + * @section page_iface_zwlr_data_control_offer_v1_api API + * See @ref iface_zwlr_data_control_offer_v1. + */ +/** + * @defgroup iface_zwlr_data_control_offer_v1 The zwlr_data_control_offer_v1 interface + * + * A wlr_data_control_offer represents a piece of data offered for transfer + * by another client (the source client). The offer describes the different + * MIME types that the data can be converted to and provides the mechanism + * for transferring the data directly from the source client. + */ +extern const struct wl_interface zwlr_data_control_offer_v1_interface; +#endif + +/** + * @ingroup iface_zwlr_data_control_manager_v1 + * @struct zwlr_data_control_manager_v1_interface + */ +struct zwlr_data_control_manager_v1_interface { + /** + * create a new data source + * + * Create a new data source. + * @param id data source to create + */ + void (*create_data_source)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * get a data device for a seat + * + * Create a data device that can be used to manage a seat's + * selection. + */ + void (*get_data_device)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *seat); + /** + * destroy the manager + * + * All objects created by the manager will still remain valid, + * until their appropriate destroy request has been called. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_zwlr_data_control_manager_v1 + */ +#define ZWLR_DATA_CONTROL_MANAGER_V1_CREATE_DATA_SOURCE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_manager_v1 + */ +#define ZWLR_DATA_CONTROL_MANAGER_V1_GET_DATA_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_manager_v1 + */ +#define ZWLR_DATA_CONTROL_MANAGER_V1_DESTROY_SINCE_VERSION 1 + +#ifndef ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM +#define ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM +enum zwlr_data_control_device_v1_error { + /** + * source given to set_selection or set_primary_selection was already used before + */ + ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_USED_SOURCE = 1, +}; +#endif /* ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM */ + +#ifndef ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM_IS_VALID +#define ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_zwlr_data_control_device_v1 + * Validate a zwlr_data_control_device_v1 error value. + * + * @return true on success, false on error. + * @ref zwlr_data_control_device_v1_error + */ +static inline bool +zwlr_data_control_device_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_USED_SOURCE: + return version >= 1; + default: + return false; + } +} +#endif /* ZWLR_DATA_CONTROL_DEVICE_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwlr_data_control_device_v1 + * @struct zwlr_data_control_device_v1_interface + */ +struct zwlr_data_control_device_v1_interface { + /** + * copy data to the selection + * + * This request asks the compositor to set the selection to the + * data from the source on behalf of the client. + * + * The given source may not be used in any further set_selection or + * set_primary_selection requests. Attempting to use a previously + * used source is a protocol error. + * + * To unset the selection, set the source to NULL. + */ + void (*set_selection)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *source); + /** + * destroy this data device + * + * Destroys the data device object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * copy data to the primary selection + * + * This request asks the compositor to set the primary selection + * to the data from the source on behalf of the client. + * + * The given source may not be used in any further set_selection or + * set_primary_selection requests. Attempting to use a previously + * used source is a protocol error. + * + * To unset the primary selection, set the source to NULL. + * + * The compositor will ignore this request if it does not support + * primary selection. + * @since 2 + */ + void (*set_primary_selection)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *source); +}; + +#define ZWLR_DATA_CONTROL_DEVICE_V1_DATA_OFFER 0 +#define ZWLR_DATA_CONTROL_DEVICE_V1_SELECTION 1 +#define ZWLR_DATA_CONTROL_DEVICE_V1_FINISHED 2 +#define ZWLR_DATA_CONTROL_DEVICE_V1_PRIMARY_SELECTION 3 + +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_DATA_OFFER_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_SELECTION_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_FINISHED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_PRIMARY_SELECTION_SINCE_VERSION 2 + +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_SET_SELECTION_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_device_v1 + */ +#define ZWLR_DATA_CONTROL_DEVICE_V1_SET_PRIMARY_SELECTION_SINCE_VERSION 2 + +/** + * @ingroup iface_zwlr_data_control_device_v1 + * Sends an data_offer event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwlr_data_control_device_v1_send_data_offer(struct wl_resource *resource_, struct wl_resource *id) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_DEVICE_V1_DATA_OFFER, id); +} + +/** + * @ingroup iface_zwlr_data_control_device_v1 + * Sends an selection event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwlr_data_control_device_v1_send_selection(struct wl_resource *resource_, struct wl_resource *id) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_DEVICE_V1_SELECTION, id); +} + +/** + * @ingroup iface_zwlr_data_control_device_v1 + * Sends an finished event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwlr_data_control_device_v1_send_finished(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_DEVICE_V1_FINISHED); +} + +/** + * @ingroup iface_zwlr_data_control_device_v1 + * Sends an primary_selection event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwlr_data_control_device_v1_send_primary_selection(struct wl_resource *resource_, struct wl_resource *id) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_DEVICE_V1_PRIMARY_SELECTION, id); +} + +#ifndef ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM +#define ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM +enum zwlr_data_control_source_v1_error { + /** + * offer sent after wlr_data_control_device.set_selection + */ + ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_INVALID_OFFER = 1, +}; +#endif /* ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM */ + +#ifndef ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM_IS_VALID +#define ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_zwlr_data_control_source_v1 + * Validate a zwlr_data_control_source_v1 error value. + * + * @return true on success, false on error. + * @ref zwlr_data_control_source_v1_error + */ +static inline bool +zwlr_data_control_source_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_INVALID_OFFER: + return version >= 1; + default: + return false; + } +} +#endif /* ZWLR_DATA_CONTROL_SOURCE_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_zwlr_data_control_source_v1 + * @struct zwlr_data_control_source_v1_interface + */ +struct zwlr_data_control_source_v1_interface { + /** + * add an offered MIME type + * + * This request adds a MIME type to the set of MIME types + * advertised to targets. Can be called several times to offer + * multiple types. + * + * Calling this after wlr_data_control_device.set_selection is a + * protocol error. + * @param mime_type MIME type offered by the data source + */ + void (*offer)(struct wl_client *client, + struct wl_resource *resource, + const char *mime_type); + /** + * destroy this source + * + * Destroys the data source object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define ZWLR_DATA_CONTROL_SOURCE_V1_SEND 0 +#define ZWLR_DATA_CONTROL_SOURCE_V1_CANCELLED 1 + +/** + * @ingroup iface_zwlr_data_control_source_v1 + */ +#define ZWLR_DATA_CONTROL_SOURCE_V1_SEND_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_source_v1 + */ +#define ZWLR_DATA_CONTROL_SOURCE_V1_CANCELLED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_data_control_source_v1 + */ +#define ZWLR_DATA_CONTROL_SOURCE_V1_OFFER_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_source_v1 + */ +#define ZWLR_DATA_CONTROL_SOURCE_V1_DESTROY_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_data_control_source_v1 + * Sends an send event to the client owning the resource. + * @param resource_ The client's resource + * @param mime_type MIME type for the data + * @param fd file descriptor for the data + */ +static inline void +zwlr_data_control_source_v1_send_send(struct wl_resource *resource_, const char *mime_type, int32_t fd) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_SOURCE_V1_SEND, mime_type, fd); +} + +/** + * @ingroup iface_zwlr_data_control_source_v1 + * Sends an cancelled event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +zwlr_data_control_source_v1_send_cancelled(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_SOURCE_V1_CANCELLED); +} + +/** + * @ingroup iface_zwlr_data_control_offer_v1 + * @struct zwlr_data_control_offer_v1_interface + */ +struct zwlr_data_control_offer_v1_interface { + /** + * request that the data is transferred + * + * To transfer the offered data, the client issues this request + * and indicates the MIME type it wants to receive. The transfer + * happens through the passed file descriptor (typically created + * with the pipe system call). The source client writes the data in + * the MIME type representation requested and then closes the file + * descriptor. + * + * The receiving client reads from the read end of the pipe until + * EOF and then closes its end, at which point the transfer is + * complete. + * + * This request may happen multiple times for different MIME types. + * @param mime_type MIME type desired by receiver + * @param fd file descriptor for data transfer + */ + void (*receive)(struct wl_client *client, + struct wl_resource *resource, + const char *mime_type, + int32_t fd); + /** + * destroy this offer + * + * Destroys the data offer object. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define ZWLR_DATA_CONTROL_OFFER_V1_OFFER 0 + +/** + * @ingroup iface_zwlr_data_control_offer_v1 + */ +#define ZWLR_DATA_CONTROL_OFFER_V1_OFFER_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_data_control_offer_v1 + */ +#define ZWLR_DATA_CONTROL_OFFER_V1_RECEIVE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_data_control_offer_v1 + */ +#define ZWLR_DATA_CONTROL_OFFER_V1_DESTROY_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_data_control_offer_v1 + * Sends an offer event to the client owning the resource. + * @param resource_ The client's resource + * @param mime_type offered MIME type + */ +static inline void +zwlr_data_control_offer_v1_send_offer(struct wl_resource *resource_, const char *mime_type) +{ + wl_resource_post_event(resource_, ZWLR_DATA_CONTROL_OFFER_V1_OFFER, mime_type); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/xdg-shell-client-protocol.h b/app/src/main/cpp/waylandcomp/generated/xdg-shell-client-protocol.h new file mode 100644 index 0000000000..5280ba38b8 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/xdg-shell-client-protocol.h @@ -0,0 +1,2280 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef XDG_SHELL_CLIENT_PROTOCOL_H +#define XDG_SHELL_CLIENT_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page page_xdg_shell The xdg_shell protocol + * @section page_ifaces_xdg_shell Interfaces + * - @subpage page_iface_xdg_wm_base - create desktop-style surfaces + * - @subpage page_iface_xdg_positioner - child surface positioner + * - @subpage page_iface_xdg_surface - desktop user interface surface base interface + * - @subpage page_iface_xdg_toplevel - toplevel surface + * - @subpage page_iface_xdg_popup - short-lived, popup surfaces for menus + * @section page_copyright_xdg_shell Copyright + * <pre> + * + * Copyright © 2008-2013 Kristian Høgsberg + * Copyright © 2013 Rafael Antognolli + * Copyright © 2013 Jasper St. Pierre + * Copyright © 2010-2013 Intel Corporation + * Copyright © 2015-2017 Samsung Electronics Co., Ltd + * Copyright © 2015-2017 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_output; +struct wl_seat; +struct wl_surface; +struct xdg_popup; +struct xdg_positioner; +struct xdg_surface; +struct xdg_toplevel; +struct xdg_wm_base; + +#ifndef XDG_WM_BASE_INTERFACE +#define XDG_WM_BASE_INTERFACE +/** + * @page page_iface_xdg_wm_base xdg_wm_base + * @section page_iface_xdg_wm_base_desc Description + * + * The xdg_wm_base interface is exposed as a global object enabling clients + * to turn their wl_surfaces into windows in a desktop environment. It + * defines the basic functionality needed for clients and the compositor to + * create windows that can be dragged, resized, maximized, etc, as well as + * creating transient windows such as popup menus. + * @section page_iface_xdg_wm_base_api API + * See @ref iface_xdg_wm_base. + */ +/** + * @defgroup iface_xdg_wm_base The xdg_wm_base interface + * + * The xdg_wm_base interface is exposed as a global object enabling clients + * to turn their wl_surfaces into windows in a desktop environment. It + * defines the basic functionality needed for clients and the compositor to + * create windows that can be dragged, resized, maximized, etc, as well as + * creating transient windows such as popup menus. + */ +extern const struct wl_interface xdg_wm_base_interface; +#endif +#ifndef XDG_POSITIONER_INTERFACE +#define XDG_POSITIONER_INTERFACE +/** + * @page page_iface_xdg_positioner xdg_positioner + * @section page_iface_xdg_positioner_desc Description + * + * The xdg_positioner provides a collection of rules for the placement of a + * child surface relative to a parent surface. Rules can be defined to ensure + * the child surface remains within the visible area's borders, and to + * specify how the child surface changes its position, such as sliding along + * an axis, or flipping around a rectangle. These positioner-created rules are + * constrained by the requirement that a child surface must intersect with or + * be at least partially adjacent to its parent surface. + * + * See the various requests for details about possible rules. + * + * At the time of the request, the compositor makes a copy of the rules + * specified by the xdg_positioner. Thus, after the request is complete the + * xdg_positioner object can be destroyed or reused; further changes to the + * object will have no effect on previous usages. + * + * For an xdg_positioner object to be considered complete, it must have a + * non-zero size set by set_size, and a non-zero anchor rectangle set by + * set_anchor_rect. Passing an incomplete xdg_positioner object when + * positioning a surface raises an invalid_positioner error. + * @section page_iface_xdg_positioner_api API + * See @ref iface_xdg_positioner. + */ +/** + * @defgroup iface_xdg_positioner The xdg_positioner interface + * + * The xdg_positioner provides a collection of rules for the placement of a + * child surface relative to a parent surface. Rules can be defined to ensure + * the child surface remains within the visible area's borders, and to + * specify how the child surface changes its position, such as sliding along + * an axis, or flipping around a rectangle. These positioner-created rules are + * constrained by the requirement that a child surface must intersect with or + * be at least partially adjacent to its parent surface. + * + * See the various requests for details about possible rules. + * + * At the time of the request, the compositor makes a copy of the rules + * specified by the xdg_positioner. Thus, after the request is complete the + * xdg_positioner object can be destroyed or reused; further changes to the + * object will have no effect on previous usages. + * + * For an xdg_positioner object to be considered complete, it must have a + * non-zero size set by set_size, and a non-zero anchor rectangle set by + * set_anchor_rect. Passing an incomplete xdg_positioner object when + * positioning a surface raises an invalid_positioner error. + */ +extern const struct wl_interface xdg_positioner_interface; +#endif +#ifndef XDG_SURFACE_INTERFACE +#define XDG_SURFACE_INTERFACE +/** + * @page page_iface_xdg_surface xdg_surface + * @section page_iface_xdg_surface_desc Description + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides a base set of functionality required to construct user + * interface elements requiring management by the compositor, such as + * toplevel windows, menus, etc. The types of functionality are split into + * xdg_surface roles. + * + * Creating an xdg_surface does not set the role for a wl_surface. In order + * to map an xdg_surface, the client must create a role-specific object + * using, e.g., get_toplevel, get_popup. The wl_surface for any given + * xdg_surface can have at most one role, and may not be assigned any role + * not based on xdg_surface. + * + * A role must be assigned before any other requests are made to the + * xdg_surface object. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_surface state to take effect. + * + * Creating an xdg_surface from a wl_surface which has a buffer attached or + * committed is a client error, and any attempts by a client to attach or + * manipulate a buffer prior to the first xdg_surface.configure call must + * also be treated as errors. + * + * After creating a role-specific object and setting it up, the client must + * perform an initial commit without any buffer attached. The compositor + * will reply with an xdg_surface.configure event. The client must + * acknowledge it and is then allowed to attach a buffer to map the surface. + * + * Mapping an xdg_surface-based role surface is defined as making it + * possible for the surface to be shown by the compositor. Note that + * a mapped surface is not guaranteed to be visible once it is mapped. + * + * For an xdg_surface to be mapped by the compositor, the following + * conditions must be met: + * (1) the client has assigned an xdg_surface-based role to the surface + * (2) the client has set and committed the xdg_surface state and the + * role-dependent state to the surface + * (3) the client has committed a buffer to the surface + * + * A newly-unmapped surface is considered to have met condition (1) out + * of the 3 required conditions for mapping a surface if its role surface + * has not been destroyed, i.e. the client must perform the initial commit + * again before attaching a buffer. + * @section page_iface_xdg_surface_api API + * See @ref iface_xdg_surface. + */ +/** + * @defgroup iface_xdg_surface The xdg_surface interface + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides a base set of functionality required to construct user + * interface elements requiring management by the compositor, such as + * toplevel windows, menus, etc. The types of functionality are split into + * xdg_surface roles. + * + * Creating an xdg_surface does not set the role for a wl_surface. In order + * to map an xdg_surface, the client must create a role-specific object + * using, e.g., get_toplevel, get_popup. The wl_surface for any given + * xdg_surface can have at most one role, and may not be assigned any role + * not based on xdg_surface. + * + * A role must be assigned before any other requests are made to the + * xdg_surface object. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_surface state to take effect. + * + * Creating an xdg_surface from a wl_surface which has a buffer attached or + * committed is a client error, and any attempts by a client to attach or + * manipulate a buffer prior to the first xdg_surface.configure call must + * also be treated as errors. + * + * After creating a role-specific object and setting it up, the client must + * perform an initial commit without any buffer attached. The compositor + * will reply with an xdg_surface.configure event. The client must + * acknowledge it and is then allowed to attach a buffer to map the surface. + * + * Mapping an xdg_surface-based role surface is defined as making it + * possible for the surface to be shown by the compositor. Note that + * a mapped surface is not guaranteed to be visible once it is mapped. + * + * For an xdg_surface to be mapped by the compositor, the following + * conditions must be met: + * (1) the client has assigned an xdg_surface-based role to the surface + * (2) the client has set and committed the xdg_surface state and the + * role-dependent state to the surface + * (3) the client has committed a buffer to the surface + * + * A newly-unmapped surface is considered to have met condition (1) out + * of the 3 required conditions for mapping a surface if its role surface + * has not been destroyed, i.e. the client must perform the initial commit + * again before attaching a buffer. + */ +extern const struct wl_interface xdg_surface_interface; +#endif +#ifndef XDG_TOPLEVEL_INTERFACE +#define XDG_TOPLEVEL_INTERFACE +/** + * @page page_iface_xdg_toplevel xdg_toplevel + * @section page_iface_xdg_toplevel_desc Description + * + * This interface defines an xdg_surface role which allows a surface to, + * among other things, set window-like properties such as maximize, + * fullscreen, and minimize, set application-specific metadata like title and + * id, and well as trigger user interactive operations such as interactive + * resize and move. + * + * Unmapping an xdg_toplevel means that the surface cannot be shown + * by the compositor until it is explicitly mapped again. + * All active operations (e.g., move, resize) are canceled and all + * attributes (e.g. title, state, stacking, ...) are discarded for + * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to + * the state it had right after xdg_surface.get_toplevel. The client + * can re-map the toplevel by performing a commit without any buffer + * attached, waiting for a configure event and handling it as usual (see + * xdg_surface description). + * + * Attaching a null buffer to a toplevel unmaps the surface. + * @section page_iface_xdg_toplevel_api API + * See @ref iface_xdg_toplevel. + */ +/** + * @defgroup iface_xdg_toplevel The xdg_toplevel interface + * + * This interface defines an xdg_surface role which allows a surface to, + * among other things, set window-like properties such as maximize, + * fullscreen, and minimize, set application-specific metadata like title and + * id, and well as trigger user interactive operations such as interactive + * resize and move. + * + * Unmapping an xdg_toplevel means that the surface cannot be shown + * by the compositor until it is explicitly mapped again. + * All active operations (e.g., move, resize) are canceled and all + * attributes (e.g. title, state, stacking, ...) are discarded for + * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to + * the state it had right after xdg_surface.get_toplevel. The client + * can re-map the toplevel by performing a commit without any buffer + * attached, waiting for a configure event and handling it as usual (see + * xdg_surface description). + * + * Attaching a null buffer to a toplevel unmaps the surface. + */ +extern const struct wl_interface xdg_toplevel_interface; +#endif +#ifndef XDG_POPUP_INTERFACE +#define XDG_POPUP_INTERFACE +/** + * @page page_iface_xdg_popup xdg_popup + * @section page_iface_xdg_popup_desc Description + * + * A popup surface is a short-lived, temporary surface. It can be used to + * implement for example menus, popovers, tooltips and other similar user + * interface concepts. + * + * A popup can be made to take an explicit grab. See xdg_popup.grab for + * details. + * + * When the popup is dismissed, a popup_done event will be sent out, and at + * the same time the surface will be unmapped. See the xdg_popup.popup_done + * event for details. + * + * Explicitly destroying the xdg_popup object will also dismiss the popup and + * unmap the surface. Clients that want to dismiss the popup when another + * surface of their own is clicked should dismiss the popup using the destroy + * request. + * + * A newly created xdg_popup will be stacked on top of all previously created + * xdg_popup surfaces associated with the same xdg_toplevel. + * + * The parent of an xdg_popup must be mapped (see the xdg_surface + * description) before the xdg_popup itself. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_popup state to take effect. + * @section page_iface_xdg_popup_api API + * See @ref iface_xdg_popup. + */ +/** + * @defgroup iface_xdg_popup The xdg_popup interface + * + * A popup surface is a short-lived, temporary surface. It can be used to + * implement for example menus, popovers, tooltips and other similar user + * interface concepts. + * + * A popup can be made to take an explicit grab. See xdg_popup.grab for + * details. + * + * When the popup is dismissed, a popup_done event will be sent out, and at + * the same time the surface will be unmapped. See the xdg_popup.popup_done + * event for details. + * + * Explicitly destroying the xdg_popup object will also dismiss the popup and + * unmap the surface. Clients that want to dismiss the popup when another + * surface of their own is clicked should dismiss the popup using the destroy + * request. + * + * A newly created xdg_popup will be stacked on top of all previously created + * xdg_popup surfaces associated with the same xdg_toplevel. + * + * The parent of an xdg_popup must be mapped (see the xdg_surface + * description) before the xdg_popup itself. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_popup state to take effect. + */ +extern const struct wl_interface xdg_popup_interface; +#endif + +#ifndef XDG_WM_BASE_ERROR_ENUM +#define XDG_WM_BASE_ERROR_ENUM +enum xdg_wm_base_error { + /** + * given wl_surface has another role + */ + XDG_WM_BASE_ERROR_ROLE = 0, + /** + * xdg_wm_base was destroyed before children + */ + XDG_WM_BASE_ERROR_DEFUNCT_SURFACES = 1, + /** + * the client tried to map or destroy a non-topmost popup + */ + XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP = 2, + /** + * the client specified an invalid popup parent surface + */ + XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT = 3, + /** + * the client provided an invalid surface state + */ + XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE = 4, + /** + * the client provided an invalid positioner + */ + XDG_WM_BASE_ERROR_INVALID_POSITIONER = 5, + /** + * the client didn’t respond to a ping event in time + */ + XDG_WM_BASE_ERROR_UNRESPONSIVE = 6, +}; +#endif /* XDG_WM_BASE_ERROR_ENUM */ + +/** + * @ingroup iface_xdg_wm_base + * @struct xdg_wm_base_listener + */ +struct xdg_wm_base_listener { + /** + * check if the client is alive + * + * The ping event asks the client if it's still alive. Pass the + * serial specified in the event back to the compositor by sending + * a "pong" request back with the specified serial. See + * xdg_wm_base.pong. + * + * Compositors can use this to determine if the client is still + * alive. It's unspecified what will happen if the client doesn't + * respond to the ping request, or in what timeframe. Clients + * should try to respond in a reasonable amount of time. The + * “unresponsive” error is provided for compositors that wish + * to disconnect unresponsive clients. + * + * A compositor is free to ping in any way it wants, but a client + * must always respond to any xdg_wm_base object it created. + * @param serial pass this to the pong request + */ + void (*ping)(void *data, + struct xdg_wm_base *xdg_wm_base, + uint32_t serial); +}; + +/** + * @ingroup iface_xdg_wm_base + */ +static inline int +xdg_wm_base_add_listener(struct xdg_wm_base *xdg_wm_base, + const struct xdg_wm_base_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) xdg_wm_base, + (void (**)(void)) listener, data); +} + +#define XDG_WM_BASE_DESTROY 0 +#define XDG_WM_BASE_CREATE_POSITIONER 1 +#define XDG_WM_BASE_GET_XDG_SURFACE 2 +#define XDG_WM_BASE_PONG 3 + +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_PING_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_CREATE_POSITIONER_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_GET_XDG_SURFACE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_PONG_SINCE_VERSION 1 + +/** @ingroup iface_xdg_wm_base */ +static inline void +xdg_wm_base_set_user_data(struct xdg_wm_base *xdg_wm_base, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) xdg_wm_base, user_data); +} + +/** @ingroup iface_xdg_wm_base */ +static inline void * +xdg_wm_base_get_user_data(struct xdg_wm_base *xdg_wm_base) +{ + return wl_proxy_get_user_data((struct wl_proxy *) xdg_wm_base); +} + +static inline uint32_t +xdg_wm_base_get_version(struct xdg_wm_base *xdg_wm_base) +{ + return wl_proxy_get_version((struct wl_proxy *) xdg_wm_base); +} + +/** + * @ingroup iface_xdg_wm_base + * + * Destroy this xdg_wm_base object. + * + * Destroying a bound xdg_wm_base object while there are surfaces + * still alive created by this xdg_wm_base object instance is illegal + * and will result in a defunct_surfaces error. + */ +static inline void +xdg_wm_base_destroy(struct xdg_wm_base *xdg_wm_base) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_wm_base, + XDG_WM_BASE_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_wm_base), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_xdg_wm_base + * + * Create a positioner object. A positioner object is used to position + * surfaces relative to some parent surface. See the interface description + * and xdg_surface.get_popup for details. + */ +static inline struct xdg_positioner * +xdg_wm_base_create_positioner(struct xdg_wm_base *xdg_wm_base) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) xdg_wm_base, + XDG_WM_BASE_CREATE_POSITIONER, &xdg_positioner_interface, wl_proxy_get_version((struct wl_proxy *) xdg_wm_base), 0, NULL); + + return (struct xdg_positioner *) id; +} + +/** + * @ingroup iface_xdg_wm_base + * + * This creates an xdg_surface for the given surface. While xdg_surface + * itself is not a role, the corresponding surface may only be assigned + * a role extending xdg_surface, such as xdg_toplevel or xdg_popup. It is + * illegal to create an xdg_surface for a wl_surface which already has an + * assigned role and this will result in a role error. + * + * This creates an xdg_surface for the given surface. An xdg_surface is + * used as basis to define a role to a given surface, such as xdg_toplevel + * or xdg_popup. It also manages functionality shared between xdg_surface + * based surface roles. + * + * See the documentation of xdg_surface for more details about what an + * xdg_surface is and how it is used. + */ +static inline struct xdg_surface * +xdg_wm_base_get_xdg_surface(struct xdg_wm_base *xdg_wm_base, struct wl_surface *surface) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) xdg_wm_base, + XDG_WM_BASE_GET_XDG_SURFACE, &xdg_surface_interface, wl_proxy_get_version((struct wl_proxy *) xdg_wm_base), 0, NULL, surface); + + return (struct xdg_surface *) id; +} + +/** + * @ingroup iface_xdg_wm_base + * + * A client must respond to a ping event with a pong request or + * the client may be deemed unresponsive. See xdg_wm_base.ping + * and xdg_wm_base.error.unresponsive. + */ +static inline void +xdg_wm_base_pong(struct xdg_wm_base *xdg_wm_base, uint32_t serial) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_wm_base, + XDG_WM_BASE_PONG, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_wm_base), 0, serial); +} + +#ifndef XDG_POSITIONER_ERROR_ENUM +#define XDG_POSITIONER_ERROR_ENUM +enum xdg_positioner_error { + /** + * invalid input provided + */ + XDG_POSITIONER_ERROR_INVALID_INPUT = 0, +}; +#endif /* XDG_POSITIONER_ERROR_ENUM */ + +#ifndef XDG_POSITIONER_ANCHOR_ENUM +#define XDG_POSITIONER_ANCHOR_ENUM +enum xdg_positioner_anchor { + XDG_POSITIONER_ANCHOR_NONE = 0, + XDG_POSITIONER_ANCHOR_TOP = 1, + XDG_POSITIONER_ANCHOR_BOTTOM = 2, + XDG_POSITIONER_ANCHOR_LEFT = 3, + XDG_POSITIONER_ANCHOR_RIGHT = 4, + XDG_POSITIONER_ANCHOR_TOP_LEFT = 5, + XDG_POSITIONER_ANCHOR_BOTTOM_LEFT = 6, + XDG_POSITIONER_ANCHOR_TOP_RIGHT = 7, + XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT = 8, +}; +#endif /* XDG_POSITIONER_ANCHOR_ENUM */ + +#ifndef XDG_POSITIONER_GRAVITY_ENUM +#define XDG_POSITIONER_GRAVITY_ENUM +enum xdg_positioner_gravity { + XDG_POSITIONER_GRAVITY_NONE = 0, + XDG_POSITIONER_GRAVITY_TOP = 1, + XDG_POSITIONER_GRAVITY_BOTTOM = 2, + XDG_POSITIONER_GRAVITY_LEFT = 3, + XDG_POSITIONER_GRAVITY_RIGHT = 4, + XDG_POSITIONER_GRAVITY_TOP_LEFT = 5, + XDG_POSITIONER_GRAVITY_BOTTOM_LEFT = 6, + XDG_POSITIONER_GRAVITY_TOP_RIGHT = 7, + XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT = 8, +}; +#endif /* XDG_POSITIONER_GRAVITY_ENUM */ + +#ifndef XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM +#define XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM +/** + * @ingroup iface_xdg_positioner + * constraint adjustments + * + * The constraint adjustment value define ways the compositor will adjust + * the position of the surface, if the unadjusted position would result + * in the surface being partly constrained. + * + * Whether a surface is considered 'constrained' is left to the compositor + * to determine. For example, the surface may be partly outside the + * compositor's defined 'work area', thus necessitating the child surface's + * position be adjusted until it is entirely inside the work area. + * + * The adjustments can be combined, according to a defined precedence: 1) + * Flip, 2) Slide, 3) Resize. + */ +enum xdg_positioner_constraint_adjustment { + /** + * don't move the child surface when constrained + * + * Don't alter the surface position even if it is constrained on + * some axis, for example partially outside the edge of an output. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE = 0, + /** + * move along the x axis until unconstrained + * + * Slide the surface along the x axis until it is no longer + * constrained. + * + * First try to slide towards the direction of the gravity on the x + * axis until either the edge in the opposite direction of the + * gravity is unconstrained or the edge in the direction of the + * gravity is constrained. + * + * Then try to slide towards the opposite direction of the gravity + * on the x axis until either the edge in the direction of the + * gravity is unconstrained or the edge in the opposite direction + * of the gravity is constrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1, + /** + * move along the y axis until unconstrained + * + * Slide the surface along the y axis until it is no longer + * constrained. + * + * First try to slide towards the direction of the gravity on the y + * axis until either the edge in the opposite direction of the + * gravity is unconstrained or the edge in the direction of the + * gravity is constrained. + * + * Then try to slide towards the opposite direction of the gravity + * on the y axis until either the edge in the direction of the + * gravity is unconstrained or the edge in the opposite direction + * of the gravity is constrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 2, + /** + * invert the anchor and gravity on the x axis + * + * Invert the anchor and gravity on the x axis if the surface is + * constrained on the x axis. For example, if the left edge of the + * surface is constrained, the gravity is 'left' and the anchor is + * 'left', change the gravity to 'right' and the anchor to 'right'. + * + * If the adjusted position also ends up being constrained, the + * resulting position of the flip_x adjustment will be the one + * before the adjustment. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X = 4, + /** + * invert the anchor and gravity on the y axis + * + * Invert the anchor and gravity on the y axis if the surface is + * constrained on the y axis. For example, if the bottom edge of + * the surface is constrained, the gravity is 'bottom' and the + * anchor is 'bottom', change the gravity to 'top' and the anchor + * to 'top'. + * + * The adjusted position is calculated given the original anchor + * rectangle and offset, but with the new flipped anchor and + * gravity values. + * + * If the adjusted position also ends up being constrained, the + * resulting position of the flip_y adjustment will be the one + * before the adjustment. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y = 8, + /** + * horizontally resize the surface + * + * Resize the surface horizontally so that it is completely + * unconstrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X = 16, + /** + * vertically resize the surface + * + * Resize the surface vertically so that it is completely + * unconstrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, +}; +#endif /* XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM */ + +#define XDG_POSITIONER_DESTROY 0 +#define XDG_POSITIONER_SET_SIZE 1 +#define XDG_POSITIONER_SET_ANCHOR_RECT 2 +#define XDG_POSITIONER_SET_ANCHOR 3 +#define XDG_POSITIONER_SET_GRAVITY 4 +#define XDG_POSITIONER_SET_CONSTRAINT_ADJUSTMENT 5 +#define XDG_POSITIONER_SET_OFFSET 6 +#define XDG_POSITIONER_SET_REACTIVE 7 +#define XDG_POSITIONER_SET_PARENT_SIZE 8 +#define XDG_POSITIONER_SET_PARENT_CONFIGURE 9 + + +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_ANCHOR_RECT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_ANCHOR_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_GRAVITY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_CONSTRAINT_ADJUSTMENT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_OFFSET_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_REACTIVE_SINCE_VERSION 3 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_PARENT_SIZE_SINCE_VERSION 3 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_PARENT_CONFIGURE_SINCE_VERSION 3 + +/** @ingroup iface_xdg_positioner */ +static inline void +xdg_positioner_set_user_data(struct xdg_positioner *xdg_positioner, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) xdg_positioner, user_data); +} + +/** @ingroup iface_xdg_positioner */ +static inline void * +xdg_positioner_get_user_data(struct xdg_positioner *xdg_positioner) +{ + return wl_proxy_get_user_data((struct wl_proxy *) xdg_positioner); +} + +static inline uint32_t +xdg_positioner_get_version(struct xdg_positioner *xdg_positioner) +{ + return wl_proxy_get_version((struct wl_proxy *) xdg_positioner); +} + +/** + * @ingroup iface_xdg_positioner + * + * Notify the compositor that the xdg_positioner will no longer be used. + */ +static inline void +xdg_positioner_destroy(struct xdg_positioner *xdg_positioner) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_xdg_positioner + * + * Set the size of the surface that is to be positioned with the positioner + * object. The size is in surface-local coordinates and corresponds to the + * window geometry. See xdg_surface.set_window_geometry. + * + * If a zero or negative size is set the invalid_input error is raised. + */ +static inline void +xdg_positioner_set_size(struct xdg_positioner *xdg_positioner, int32_t width, int32_t height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_SIZE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, width, height); +} + +/** + * @ingroup iface_xdg_positioner + * + * Specify the anchor rectangle within the parent surface that the child + * surface will be placed relative to. The rectangle is relative to the + * window geometry as defined by xdg_surface.set_window_geometry of the + * parent surface. + * + * When the xdg_positioner object is used to position a child surface, the + * anchor rectangle may not extend outside the window geometry of the + * positioned child's parent surface. + * + * If a negative size is set the invalid_input error is raised. + */ +static inline void +xdg_positioner_set_anchor_rect(struct xdg_positioner *xdg_positioner, int32_t x, int32_t y, int32_t width, int32_t height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_ANCHOR_RECT, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, x, y, width, height); +} + +/** + * @ingroup iface_xdg_positioner + * + * Defines the anchor point for the anchor rectangle. The specified anchor + * is used derive an anchor point that the child surface will be + * positioned relative to. If a corner anchor is set (e.g. 'top_left' or + * 'bottom_right'), the anchor point will be at the specified corner; + * otherwise, the derived anchor point will be centered on the specified + * edge, or in the center of the anchor rectangle if no edge is specified. + */ +static inline void +xdg_positioner_set_anchor(struct xdg_positioner *xdg_positioner, uint32_t anchor) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_ANCHOR, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, anchor); +} + +/** + * @ingroup iface_xdg_positioner + * + * Defines in what direction a surface should be positioned, relative to + * the anchor point of the parent surface. If a corner gravity is + * specified (e.g. 'bottom_right' or 'top_left'), then the child surface + * will be placed towards the specified gravity; otherwise, the child + * surface will be centered over the anchor point on any axis that had no + * gravity specified. If the gravity is not in the ‘gravity’ enum, an + * invalid_input error is raised. + */ +static inline void +xdg_positioner_set_gravity(struct xdg_positioner *xdg_positioner, uint32_t gravity) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_GRAVITY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, gravity); +} + +/** + * @ingroup iface_xdg_positioner + * + * Specify how the window should be positioned if the originally intended + * position caused the surface to be constrained, meaning at least + * partially outside positioning boundaries set by the compositor. The + * adjustment is set by constructing a bitmask describing the adjustment to + * be made when the surface is constrained on that axis. + * + * If no bit for one axis is set, the compositor will assume that the child + * surface should not change its position on that axis when constrained. + * + * If more than one bit for one axis is set, the order of how adjustments + * are applied is specified in the corresponding adjustment descriptions. + * + * The default adjustment is none. + */ +static inline void +xdg_positioner_set_constraint_adjustment(struct xdg_positioner *xdg_positioner, uint32_t constraint_adjustment) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_CONSTRAINT_ADJUSTMENT, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, constraint_adjustment); +} + +/** + * @ingroup iface_xdg_positioner + * + * Specify the surface position offset relative to the position of the + * anchor on the anchor rectangle and the anchor on the surface. For + * example if the anchor of the anchor rectangle is at (x, y), the surface + * has the gravity bottom|right, and the offset is (ox, oy), the calculated + * surface position will be (x + ox, y + oy). The offset position of the + * surface is the one used for constraint testing. See + * set_constraint_adjustment. + * + * An example use case is placing a popup menu on top of a user interface + * element, while aligning the user interface element of the parent surface + * with some user interface element placed somewhere in the popup surface. + */ +static inline void +xdg_positioner_set_offset(struct xdg_positioner *xdg_positioner, int32_t x, int32_t y) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_OFFSET, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, x, y); +} + +/** + * @ingroup iface_xdg_positioner + * + * When set reactive, the surface is reconstrained if the conditions used + * for constraining changed, e.g. the parent window moved. + * + * If the conditions changed and the popup was reconstrained, an + * xdg_popup.configure event is sent with updated geometry, followed by an + * xdg_surface.configure event. + */ +static inline void +xdg_positioner_set_reactive(struct xdg_positioner *xdg_positioner) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_REACTIVE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0); +} + +/** + * @ingroup iface_xdg_positioner + * + * Set the parent window geometry the compositor should use when + * positioning the popup. The compositor may use this information to + * determine the future state the popup should be constrained using. If + * this doesn't match the dimension of the parent the popup is eventually + * positioned against, the behavior is undefined. + * + * The arguments are given in the surface-local coordinate space. + */ +static inline void +xdg_positioner_set_parent_size(struct xdg_positioner *xdg_positioner, int32_t parent_width, int32_t parent_height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_PARENT_SIZE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, parent_width, parent_height); +} + +/** + * @ingroup iface_xdg_positioner + * + * Set the serial of an xdg_surface.configure event this positioner will be + * used in response to. The compositor may use this information together + * with set_parent_size to determine what future state the popup should be + * constrained using. + */ +static inline void +xdg_positioner_set_parent_configure(struct xdg_positioner *xdg_positioner, uint32_t serial) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_positioner, + XDG_POSITIONER_SET_PARENT_CONFIGURE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_positioner), 0, serial); +} + +#ifndef XDG_SURFACE_ERROR_ENUM +#define XDG_SURFACE_ERROR_ENUM +enum xdg_surface_error { + /** + * Surface was not fully constructed + */ + XDG_SURFACE_ERROR_NOT_CONSTRUCTED = 1, + /** + * Surface was already constructed + */ + XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED = 2, + /** + * Attaching a buffer to an unconfigured surface + */ + XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER = 3, + /** + * Invalid serial number when acking a configure event + */ + XDG_SURFACE_ERROR_INVALID_SERIAL = 4, + /** + * Width or height was zero or negative + */ + XDG_SURFACE_ERROR_INVALID_SIZE = 5, + /** + * Surface was destroyed before its role object + */ + XDG_SURFACE_ERROR_DEFUNCT_ROLE_OBJECT = 6, +}; +#endif /* XDG_SURFACE_ERROR_ENUM */ + +/** + * @ingroup iface_xdg_surface + * @struct xdg_surface_listener + */ +struct xdg_surface_listener { + /** + * suggest a surface change + * + * The configure event marks the end of a configure sequence. A + * configure sequence is a set of one or more events configuring + * the state of the xdg_surface, including the final + * xdg_surface.configure event. + * + * Where applicable, xdg_surface surface roles will during a + * configure sequence extend this event as a latched state sent as + * events before the xdg_surface.configure event. Such events + * should be considered to make up a set of atomically applied + * configuration states, where the xdg_surface.configure commits + * the accumulated state. + * + * Clients should arrange their surface for the new states, and + * then send an ack_configure request with the serial sent in this + * configure event at some point before committing the new surface. + * + * If the client receives multiple configure events before it can + * respond to one, it is free to discard all but the last event it + * received. + * @param serial serial of the configure event + */ + void (*configure)(void *data, + struct xdg_surface *xdg_surface, + uint32_t serial); +}; + +/** + * @ingroup iface_xdg_surface + */ +static inline int +xdg_surface_add_listener(struct xdg_surface *xdg_surface, + const struct xdg_surface_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) xdg_surface, + (void (**)(void)) listener, data); +} + +#define XDG_SURFACE_DESTROY 0 +#define XDG_SURFACE_GET_TOPLEVEL 1 +#define XDG_SURFACE_GET_POPUP 2 +#define XDG_SURFACE_SET_WINDOW_GEOMETRY 3 +#define XDG_SURFACE_ACK_CONFIGURE 4 + +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_CONFIGURE_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_GET_TOPLEVEL_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_GET_POPUP_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_SET_WINDOW_GEOMETRY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_ACK_CONFIGURE_SINCE_VERSION 1 + +/** @ingroup iface_xdg_surface */ +static inline void +xdg_surface_set_user_data(struct xdg_surface *xdg_surface, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) xdg_surface, user_data); +} + +/** @ingroup iface_xdg_surface */ +static inline void * +xdg_surface_get_user_data(struct xdg_surface *xdg_surface) +{ + return wl_proxy_get_user_data((struct wl_proxy *) xdg_surface); +} + +static inline uint32_t +xdg_surface_get_version(struct xdg_surface *xdg_surface) +{ + return wl_proxy_get_version((struct wl_proxy *) xdg_surface); +} + +/** + * @ingroup iface_xdg_surface + * + * Destroy the xdg_surface object. An xdg_surface must only be destroyed + * after its role object has been destroyed, otherwise + * a defunct_role_object error is raised. + */ +static inline void +xdg_surface_destroy(struct xdg_surface *xdg_surface) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_surface, + XDG_SURFACE_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_surface), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_xdg_surface + * + * This creates an xdg_toplevel object for the given xdg_surface and gives + * the associated wl_surface the xdg_toplevel role. + * + * See the documentation of xdg_toplevel for more details about what an + * xdg_toplevel is and how it is used. + */ +static inline struct xdg_toplevel * +xdg_surface_get_toplevel(struct xdg_surface *xdg_surface) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) xdg_surface, + XDG_SURFACE_GET_TOPLEVEL, &xdg_toplevel_interface, wl_proxy_get_version((struct wl_proxy *) xdg_surface), 0, NULL); + + return (struct xdg_toplevel *) id; +} + +/** + * @ingroup iface_xdg_surface + * + * This creates an xdg_popup object for the given xdg_surface and gives + * the associated wl_surface the xdg_popup role. + * + * If null is passed as a parent, a parent surface must be specified using + * some other protocol, before committing the initial state. + * + * See the documentation of xdg_popup for more details about what an + * xdg_popup is and how it is used. + */ +static inline struct xdg_popup * +xdg_surface_get_popup(struct xdg_surface *xdg_surface, struct xdg_surface *parent, struct xdg_positioner *positioner) +{ + struct wl_proxy *id; + + id = wl_proxy_marshal_flags((struct wl_proxy *) xdg_surface, + XDG_SURFACE_GET_POPUP, &xdg_popup_interface, wl_proxy_get_version((struct wl_proxy *) xdg_surface), 0, NULL, parent, positioner); + + return (struct xdg_popup *) id; +} + +/** + * @ingroup iface_xdg_surface + * + * The window geometry of a surface is its "visible bounds" from the + * user's perspective. Client-side decorations often have invisible + * portions like drop-shadows which should be ignored for the + * purposes of aligning, placing and constraining windows. + * + * The window geometry is double buffered, and will be applied at the + * time wl_surface.commit of the corresponding wl_surface is called. + * + * When maintaining a position, the compositor should treat the (x, y) + * coordinate of the window geometry as the top left corner of the window. + * A client changing the (x, y) window geometry coordinate should in + * general not alter the position of the window. + * + * Once the window geometry of the surface is set, it is not possible to + * unset it, and it will remain the same until set_window_geometry is + * called again, even if a new subsurface or buffer is attached. + * + * If never set, the value is the full bounds of the surface, + * including any subsurfaces. This updates dynamically on every + * commit. This unset is meant for extremely simple clients. + * + * The arguments are given in the surface-local coordinate space of + * the wl_surface associated with this xdg_surface. + * + * The width and height must be greater than zero. Setting an invalid size + * will raise an invalid_size error. When applied, the effective window + * geometry will be the set window geometry clamped to the bounding + * rectangle of the combined geometry of the surface of the xdg_surface and + * the associated subsurfaces. + */ +static inline void +xdg_surface_set_window_geometry(struct xdg_surface *xdg_surface, int32_t x, int32_t y, int32_t width, int32_t height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_surface, + XDG_SURFACE_SET_WINDOW_GEOMETRY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_surface), 0, x, y, width, height); +} + +/** + * @ingroup iface_xdg_surface + * + * When a configure event is received, if a client commits the + * surface in response to the configure event, then the client + * must make an ack_configure request sometime before the commit + * request, passing along the serial of the configure event. + * + * For instance, for toplevel surfaces the compositor might use this + * information to move a surface to the top left only when the client has + * drawn itself for the maximized or fullscreen state. + * + * If the client receives multiple configure events before it + * can respond to one, it only has to ack the last configure event. + * Acking a configure event that was never sent raises an invalid_serial + * error. + * + * A client is not required to commit immediately after sending + * an ack_configure request - it may even ack_configure several times + * before its next surface commit. + * + * A client may send multiple ack_configure requests before committing, but + * only the last request sent before a commit indicates which configure + * event the client really is responding to. + * + * Sending an ack_configure request consumes the serial number sent with + * the request, as well as serial numbers sent by all configure events + * sent on this xdg_surface prior to the configure event referenced by + * the committed serial. + * + * It is an error to issue multiple ack_configure requests referencing a + * serial from the same configure event, or to issue an ack_configure + * request referencing a serial from a configure event issued before the + * event identified by the last ack_configure request for the same + * xdg_surface. Doing so will raise an invalid_serial error. + */ +static inline void +xdg_surface_ack_configure(struct xdg_surface *xdg_surface, uint32_t serial) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_surface, + XDG_SURFACE_ACK_CONFIGURE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_surface), 0, serial); +} + +#ifndef XDG_TOPLEVEL_ERROR_ENUM +#define XDG_TOPLEVEL_ERROR_ENUM +enum xdg_toplevel_error { + /** + * provided value is not a valid variant of the resize_edge enum + */ + XDG_TOPLEVEL_ERROR_INVALID_RESIZE_EDGE = 0, + /** + * invalid parent toplevel + */ + XDG_TOPLEVEL_ERROR_INVALID_PARENT = 1, + /** + * client provided an invalid min or max size + */ + XDG_TOPLEVEL_ERROR_INVALID_SIZE = 2, +}; +#endif /* XDG_TOPLEVEL_ERROR_ENUM */ + +#ifndef XDG_TOPLEVEL_RESIZE_EDGE_ENUM +#define XDG_TOPLEVEL_RESIZE_EDGE_ENUM +/** + * @ingroup iface_xdg_toplevel + * edge values for resizing + * + * These values are used to indicate which edge of a surface + * is being dragged in a resize operation. + */ +enum xdg_toplevel_resize_edge { + XDG_TOPLEVEL_RESIZE_EDGE_NONE = 0, + XDG_TOPLEVEL_RESIZE_EDGE_TOP = 1, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM = 2, + XDG_TOPLEVEL_RESIZE_EDGE_LEFT = 4, + XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT = 5, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT = 6, + XDG_TOPLEVEL_RESIZE_EDGE_RIGHT = 8, + XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT = 9, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT = 10, +}; +#endif /* XDG_TOPLEVEL_RESIZE_EDGE_ENUM */ + +#ifndef XDG_TOPLEVEL_STATE_ENUM +#define XDG_TOPLEVEL_STATE_ENUM +/** + * @ingroup iface_xdg_toplevel + * types of state on the surface + * + * The different state values used on the surface. This is designed for + * state values like maximized, fullscreen. It is paired with the + * configure event to ensure that both the client and the compositor + * setting the state can be synchronized. + * + * States set in this way are double-buffered. They will get applied on + * the next commit. + */ +enum xdg_toplevel_state { + /** + * the surface is maximized + * the surface is maximized + * + * The surface is maximized. The window geometry specified in the + * configure event must be obeyed by the client. + * + * The client should draw without shadow or other decoration + * outside of the window geometry. + */ + XDG_TOPLEVEL_STATE_MAXIMIZED = 1, + /** + * the surface is fullscreen + * the surface is fullscreen + * + * The surface is fullscreen. The window geometry specified in + * the configure event is a maximum; the client cannot resize + * beyond it. For a surface to cover the whole fullscreened area, + * the geometry dimensions must be obeyed by the client. For more + * details, see xdg_toplevel.set_fullscreen. + */ + XDG_TOPLEVEL_STATE_FULLSCREEN = 2, + /** + * the surface is being resized + * the surface is being resized + * + * The surface is being resized. The window geometry specified in + * the configure event is a maximum; the client cannot resize + * beyond it. Clients that have aspect ratio or cell sizing + * configuration can use a smaller size, however. + */ + XDG_TOPLEVEL_STATE_RESIZING = 3, + /** + * the surface is now activated + * the surface is now activated + * + * Client window decorations should be painted as if the window + * is active. Do not assume this means that the window actually has + * keyboard or pointer focus. + */ + XDG_TOPLEVEL_STATE_ACTIVATED = 4, + /** + * the surface’s left edge is tiled + * + * The window is currently in a tiled layout and the left edge is + * considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_LEFT = 5, + /** + * the surface’s right edge is tiled + * + * The window is currently in a tiled layout and the right edge + * is considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_RIGHT = 6, + /** + * the surface’s top edge is tiled + * + * The window is currently in a tiled layout and the top edge is + * considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_TOP = 7, + /** + * the surface’s bottom edge is tiled + * + * The window is currently in a tiled layout and the bottom edge + * is considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_BOTTOM = 8, +}; +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_TOP_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_BOTTOM_SINCE_VERSION 2 +#endif /* XDG_TOPLEVEL_STATE_ENUM */ + +#ifndef XDG_TOPLEVEL_WM_CAPABILITIES_ENUM +#define XDG_TOPLEVEL_WM_CAPABILITIES_ENUM +enum xdg_toplevel_wm_capabilities { + /** + * show_window_menu is available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU = 1, + /** + * set_maximized and unset_maximized are available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE = 2, + /** + * set_fullscreen and unset_fullscreen are available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN = 3, + /** + * set_minimized is available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE = 4, +}; +#endif /* XDG_TOPLEVEL_WM_CAPABILITIES_ENUM */ + +/** + * @ingroup iface_xdg_toplevel + * @struct xdg_toplevel_listener + */ +struct xdg_toplevel_listener { + /** + * suggest a surface change + * + * This configure event asks the client to resize its toplevel + * surface or to change its state. The configured state should not + * be applied immediately. See xdg_surface.configure for details. + * + * The width and height arguments specify a hint to the window + * about how its surface should be resized in window geometry + * coordinates. See set_window_geometry. + * + * If the width or height arguments are zero, it means the client + * should decide its own window dimension. This may happen when the + * compositor needs to configure the state of the surface but + * doesn't have any information about any previous or expected + * dimension. + * + * The states listed in the event specify how the width/height + * arguments should be interpreted, and possibly how it should be + * drawn. + * + * Clients must send an ack_configure in response to this event. + * See xdg_surface.configure and xdg_surface.ack_configure for + * details. + */ + void (*configure)(void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *states); + /** + * surface wants to be closed + * + * The close event is sent by the compositor when the user wants + * the surface to be closed. This should be equivalent to the user + * clicking the close button in client-side decorations, if your + * application has any. + * + * This is only a request that the user intends to close the + * window. The client may choose to ignore this request, or show a + * dialog to ask the user to save their data, etc. + */ + void (*close)(void *data, + struct xdg_toplevel *xdg_toplevel); + /** + * recommended window geometry bounds + * + * The configure_bounds event may be sent prior to a + * xdg_toplevel.configure event to communicate the bounds a window + * geometry size is recommended to constrain to. + * + * The passed width and height are in surface coordinate space. If + * width and height are 0, it means bounds is unknown and + * equivalent to as if no configure_bounds event was ever sent for + * this surface. + * + * The bounds can for example correspond to the size of a monitor + * excluding any panels or other shell components, so that a + * surface isn't created in a way that it cannot fit. + * + * The bounds may change at any point, and in such a case, a new + * xdg_toplevel.configure_bounds will be sent, followed by + * xdg_toplevel.configure and xdg_surface.configure. + * @since 4 + */ + void (*configure_bounds)(void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height); + /** + * compositor capabilities + * + * This event advertises the capabilities supported by the + * compositor. If a capability isn't supported, clients should hide + * or disable the UI elements that expose this functionality. For + * instance, if the compositor doesn't advertise support for + * minimized toplevels, a button triggering the set_minimized + * request should not be displayed. + * + * The compositor will ignore requests it doesn't support. For + * instance, a compositor which doesn't advertise support for + * minimized will ignore set_minimized requests. + * + * Compositors must send this event once before the first + * xdg_surface.configure event. When the capabilities change, + * compositors must send this event again and then send an + * xdg_surface.configure event. + * + * The configured state should not be applied immediately. See + * xdg_surface.configure for details. + * + * The capabilities are sent as an array of 32-bit unsigned + * integers in native endianness. + * @param capabilities array of 32-bit capabilities + * @since 5 + */ + void (*wm_capabilities)(void *data, + struct xdg_toplevel *xdg_toplevel, + struct wl_array *capabilities); +}; + +/** + * @ingroup iface_xdg_toplevel + */ +static inline int +xdg_toplevel_add_listener(struct xdg_toplevel *xdg_toplevel, + const struct xdg_toplevel_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) xdg_toplevel, + (void (**)(void)) listener, data); +} + +#define XDG_TOPLEVEL_DESTROY 0 +#define XDG_TOPLEVEL_SET_PARENT 1 +#define XDG_TOPLEVEL_SET_TITLE 2 +#define XDG_TOPLEVEL_SET_APP_ID 3 +#define XDG_TOPLEVEL_SHOW_WINDOW_MENU 4 +#define XDG_TOPLEVEL_MOVE 5 +#define XDG_TOPLEVEL_RESIZE 6 +#define XDG_TOPLEVEL_SET_MAX_SIZE 7 +#define XDG_TOPLEVEL_SET_MIN_SIZE 8 +#define XDG_TOPLEVEL_SET_MAXIMIZED 9 +#define XDG_TOPLEVEL_UNSET_MAXIMIZED 10 +#define XDG_TOPLEVEL_SET_FULLSCREEN 11 +#define XDG_TOPLEVEL_UNSET_FULLSCREEN 12 +#define XDG_TOPLEVEL_SET_MINIMIZED 13 + +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CONFIGURE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CLOSE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION 4 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION 5 + +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_PARENT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_TITLE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_APP_ID_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SHOW_WINDOW_MENU_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_MOVE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_RESIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MAX_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MIN_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_UNSET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_FULLSCREEN_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_UNSET_FULLSCREEN_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MINIMIZED_SINCE_VERSION 1 + +/** @ingroup iface_xdg_toplevel */ +static inline void +xdg_toplevel_set_user_data(struct xdg_toplevel *xdg_toplevel, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) xdg_toplevel, user_data); +} + +/** @ingroup iface_xdg_toplevel */ +static inline void * +xdg_toplevel_get_user_data(struct xdg_toplevel *xdg_toplevel) +{ + return wl_proxy_get_user_data((struct wl_proxy *) xdg_toplevel); +} + +static inline uint32_t +xdg_toplevel_get_version(struct xdg_toplevel *xdg_toplevel) +{ + return wl_proxy_get_version((struct wl_proxy *) xdg_toplevel); +} + +/** + * @ingroup iface_xdg_toplevel + * + * This request destroys the role surface and unmaps the surface; + * see "Unmapping" behavior in interface section for details. + */ +static inline void +xdg_toplevel_destroy(struct xdg_toplevel *xdg_toplevel) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Set the "parent" of this surface. This surface should be stacked + * above the parent surface and all other ancestor surfaces. + * + * Parent surfaces should be set on dialogs, toolboxes, or other + * "auxiliary" surfaces, so that the parent is raised when the dialog + * is raised. + * + * Setting a null parent for a child surface unsets its parent. Setting + * a null parent for a surface which currently has no parent is a no-op. + * + * Only mapped surfaces can have child surfaces. Setting a parent which + * is not mapped is equivalent to setting a null parent. If a surface + * becomes unmapped, its children's parent is set to the parent of + * the now-unmapped surface. If the now-unmapped surface has no parent, + * its children's parent is unset. If the now-unmapped surface becomes + * mapped again, its parent-child relationship is not restored. + * + * The parent toplevel must not be one of the child toplevel's + * descendants, and the parent must be different from the child toplevel, + * otherwise the invalid_parent protocol error is raised. + */ +static inline void +xdg_toplevel_set_parent(struct xdg_toplevel *xdg_toplevel, struct xdg_toplevel *parent) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_PARENT, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, parent); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Set a short title for the surface. + * + * This string may be used to identify the surface in a task bar, + * window list, or other user interface elements provided by the + * compositor. + * + * The string must be encoded in UTF-8. + */ +static inline void +xdg_toplevel_set_title(struct xdg_toplevel *xdg_toplevel, const char *title) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_TITLE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, title); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Set an application identifier for the surface. + * + * The app ID identifies the general class of applications to which + * the surface belongs. The compositor can use this to group multiple + * surfaces together, or to determine how to launch a new application. + * + * For D-Bus activatable applications, the app ID is used as the D-Bus + * service name. + * + * The compositor shell will try to group application surfaces together + * by their app ID. As a best practice, it is suggested to select app + * ID's that match the basename of the application's .desktop file. + * For example, "org.freedesktop.FooViewer" where the .desktop file is + * "org.freedesktop.FooViewer.desktop". + * + * Like other properties, a set_app_id request can be sent after the + * xdg_toplevel has been mapped to update the property. + * + * See the desktop-entry specification [0] for more details on + * application identifiers and how they relate to well-known D-Bus + * names and .desktop files. + * + * [0] https://standards.freedesktop.org/desktop-entry-spec/ + */ +static inline void +xdg_toplevel_set_app_id(struct xdg_toplevel *xdg_toplevel, const char *app_id) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_APP_ID, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, app_id); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Clients implementing client-side decorations might want to show + * a context menu when right-clicking on the decorations, giving the + * user a menu that they can use to maximize or minimize the window. + * + * This request asks the compositor to pop up such a window menu at + * the given position, relative to the local surface coordinates of + * the parent surface. There are no guarantees as to what menu items + * the window menu contains, or even if a window menu will be drawn + * at all. + * + * This request must be used in response to some sort of user action + * like a button press, key press, or touch down event. + */ +static inline void +xdg_toplevel_show_window_menu(struct xdg_toplevel *xdg_toplevel, struct wl_seat *seat, uint32_t serial, int32_t x, int32_t y) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SHOW_WINDOW_MENU, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, seat, serial, x, y); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Start an interactive, user-driven move of the surface. + * + * This request must be used in response to some sort of user action + * like a button press, key press, or touch down event. The passed + * serial is used to determine the type of interactive move (touch, + * pointer, etc). + * + * The server may ignore move requests depending on the state of + * the surface (e.g. fullscreen or maximized), or if the passed serial + * is no longer valid. + * + * If triggered, the surface will lose the focus of the device + * (wl_pointer, wl_touch, etc) used for the move. It is up to the + * compositor to visually indicate that the move is taking place, such as + * updating a pointer cursor, during the move. There is no guarantee + * that the device focus will return when the move is completed. + */ +static inline void +xdg_toplevel_move(struct xdg_toplevel *xdg_toplevel, struct wl_seat *seat, uint32_t serial) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_MOVE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, seat, serial); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Start a user-driven, interactive resize of the surface. + * + * This request must be used in response to some sort of user action + * like a button press, key press, or touch down event. The passed + * serial is used to determine the type of interactive resize (touch, + * pointer, etc). + * + * The server may ignore resize requests depending on the state of + * the surface (e.g. fullscreen or maximized). + * + * If triggered, the client will receive configure events with the + * "resize" state enum value and the expected sizes. See the "resize" + * enum value for more details about what is required. The client + * must also acknowledge configure events using "ack_configure". After + * the resize is completed, the client will receive another "configure" + * event without the resize state. + * + * If triggered, the surface also will lose the focus of the device + * (wl_pointer, wl_touch, etc) used for the resize. It is up to the + * compositor to visually indicate that the resize is taking place, + * such as updating a pointer cursor, during the resize. There is no + * guarantee that the device focus will return when the resize is + * completed. + * + * The edges parameter specifies how the surface should be resized, and + * is one of the values of the resize_edge enum. Values not matching + * a variant of the enum will cause a protocol error. The compositor + * may use this information to update the surface position for example + * when dragging the top left corner. The compositor may also use + * this information to adapt its behavior, e.g. choose an appropriate + * cursor image. + */ +static inline void +xdg_toplevel_resize(struct xdg_toplevel *xdg_toplevel, struct wl_seat *seat, uint32_t serial, uint32_t edges) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_RESIZE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, seat, serial, edges); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Set a maximum size for the window. + * + * The client can specify a maximum size so that the compositor does + * not try to configure the window beyond this size. + * + * The width and height arguments are in window geometry coordinates. + * See xdg_surface.set_window_geometry. + * + * Values set in this way are double-buffered. They will get applied + * on the next commit. + * + * The compositor can use this information to allow or disallow + * different states like maximize or fullscreen and draw accurate + * animations. + * + * Similarly, a tiling window manager may use this information to + * place and resize client windows in a more effective way. + * + * The client should not rely on the compositor to obey the maximum + * size. The compositor may decide to ignore the values set by the + * client and request a larger size. + * + * If never set, or a value of zero in the request, means that the + * client has no expected maximum size in the given dimension. + * As a result, a client wishing to reset the maximum size + * to an unspecified state can use zero for width and height in the + * request. + * + * Requesting a maximum size to be smaller than the minimum size of + * a surface is illegal and will result in an invalid_size error. + * + * The width and height must be greater than or equal to zero. Using + * strictly negative values for width or height will result in a + * invalid_size error. + */ +static inline void +xdg_toplevel_set_max_size(struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_MAX_SIZE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, width, height); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Set a minimum size for the window. + * + * The client can specify a minimum size so that the compositor does + * not try to configure the window below this size. + * + * The width and height arguments are in window geometry coordinates. + * See xdg_surface.set_window_geometry. + * + * Values set in this way are double-buffered. They will get applied + * on the next commit. + * + * The compositor can use this information to allow or disallow + * different states like maximize or fullscreen and draw accurate + * animations. + * + * Similarly, a tiling window manager may use this information to + * place and resize client windows in a more effective way. + * + * The client should not rely on the compositor to obey the minimum + * size. The compositor may decide to ignore the values set by the + * client and request a smaller size. + * + * If never set, or a value of zero in the request, means that the + * client has no expected minimum size in the given dimension. + * As a result, a client wishing to reset the minimum size + * to an unspecified state can use zero for width and height in the + * request. + * + * Requesting a minimum size to be larger than the maximum size of + * a surface is illegal and will result in an invalid_size error. + * + * The width and height must be greater than or equal to zero. Using + * strictly negative values for width and height will result in a + * invalid_size error. + */ +static inline void +xdg_toplevel_set_min_size(struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_MIN_SIZE, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, width, height); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Maximize the surface. + * + * After requesting that the surface should be maximized, the compositor + * will respond by emitting a configure event. Whether this configure + * actually sets the window maximized is subject to compositor policies. + * The client must then update its content, drawing in the configured + * state. The client must also acknowledge the configure when committing + * the new content (see ack_configure). + * + * It is up to the compositor to decide how and where to maximize the + * surface, for example which output and what region of the screen should + * be used. + * + * If the surface was already maximized, the compositor will still emit + * a configure event with the "maximized" state. + * + * If the surface is in a fullscreen state, this request has no direct + * effect. It may alter the state the surface is returned to when + * unmaximized unless overridden by the compositor. + */ +static inline void +xdg_toplevel_set_maximized(struct xdg_toplevel *xdg_toplevel) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_MAXIMIZED, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Unmaximize the surface. + * + * After requesting that the surface should be unmaximized, the compositor + * will respond by emitting a configure event. Whether this actually + * un-maximizes the window is subject to compositor policies. + * If available and applicable, the compositor will include the window + * geometry dimensions the window had prior to being maximized in the + * configure event. The client must then update its content, drawing it in + * the configured state. The client must also acknowledge the configure + * when committing the new content (see ack_configure). + * + * It is up to the compositor to position the surface after it was + * unmaximized; usually the position the surface had before maximizing, if + * applicable. + * + * If the surface was already not maximized, the compositor will still + * emit a configure event without the "maximized" state. + * + * If the surface is in a fullscreen state, this request has no direct + * effect. It may alter the state the surface is returned to when + * unmaximized unless overridden by the compositor. + */ +static inline void +xdg_toplevel_unset_maximized(struct xdg_toplevel *xdg_toplevel) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_UNSET_MAXIMIZED, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Make the surface fullscreen. + * + * After requesting that the surface should be fullscreened, the + * compositor will respond by emitting a configure event. Whether the + * client is actually put into a fullscreen state is subject to compositor + * policies. The client must also acknowledge the configure when + * committing the new content (see ack_configure). + * + * The output passed by the request indicates the client's preference as + * to which display it should be set fullscreen on. If this value is NULL, + * it's up to the compositor to choose which display will be used to map + * this surface. + * + * If the surface doesn't cover the whole output, the compositor will + * position the surface in the center of the output and compensate with + * with border fill covering the rest of the output. The content of the + * border fill is undefined, but should be assumed to be in some way that + * attempts to blend into the surrounding area (e.g. solid black). + * + * If the fullscreened surface is not opaque, the compositor must make + * sure that other screen content not part of the same surface tree (made + * up of subsurfaces, popups or similarly coupled surfaces) are not + * visible below the fullscreened surface. + */ +static inline void +xdg_toplevel_set_fullscreen(struct xdg_toplevel *xdg_toplevel, struct wl_output *output) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_FULLSCREEN, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0, output); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Make the surface no longer fullscreen. + * + * After requesting that the surface should be unfullscreened, the + * compositor will respond by emitting a configure event. + * Whether this actually removes the fullscreen state of the client is + * subject to compositor policies. + * + * Making a surface unfullscreen sets states for the surface based on the following: + * * the state(s) it may have had before becoming fullscreen + * * any state(s) decided by the compositor + * * any state(s) requested by the client while the surface was fullscreen + * + * The compositor may include the previous window geometry dimensions in + * the configure event, if applicable. + * + * The client must also acknowledge the configure when committing the new + * content (see ack_configure). + */ +static inline void +xdg_toplevel_unset_fullscreen(struct xdg_toplevel *xdg_toplevel) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_UNSET_FULLSCREEN, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0); +} + +/** + * @ingroup iface_xdg_toplevel + * + * Request that the compositor minimize your surface. There is no + * way to know if the surface is currently minimized, nor is there + * any way to unset minimization on this surface. + * + * If you are looking to throttle redrawing when minimized, please + * instead use the wl_surface.frame event for this, as this will + * also work with live previews on windows in Alt-Tab, Expose or + * similar compositor features. + */ +static inline void +xdg_toplevel_set_minimized(struct xdg_toplevel *xdg_toplevel) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, + XDG_TOPLEVEL_SET_MINIMIZED, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), 0); +} + +#ifndef XDG_POPUP_ERROR_ENUM +#define XDG_POPUP_ERROR_ENUM +enum xdg_popup_error { + /** + * tried to grab after being mapped + */ + XDG_POPUP_ERROR_INVALID_GRAB = 0, +}; +#endif /* XDG_POPUP_ERROR_ENUM */ + +/** + * @ingroup iface_xdg_popup + * @struct xdg_popup_listener + */ +struct xdg_popup_listener { + /** + * configure the popup surface + * + * This event asks the popup surface to configure itself given + * the configuration. The configured state should not be applied + * immediately. See xdg_surface.configure for details. + * + * The x and y arguments represent the position the popup was + * placed at given the xdg_positioner rule, relative to the upper + * left corner of the window geometry of the parent surface. + * + * For version 2 or older, the configure event for an xdg_popup is + * only ever sent once for the initial configuration. Starting with + * version 3, it may be sent again if the popup is setup with an + * xdg_positioner with set_reactive requested, or in response to + * xdg_popup.reposition requests. + * @param x x position relative to parent surface window geometry + * @param y y position relative to parent surface window geometry + * @param width window geometry width + * @param height window geometry height + */ + void (*configure)(void *data, + struct xdg_popup *xdg_popup, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * popup interaction is done + * + * The popup_done event is sent out when a popup is dismissed by + * the compositor. The client should destroy the xdg_popup object + * at this point. + */ + void (*popup_done)(void *data, + struct xdg_popup *xdg_popup); + /** + * signal the completion of a repositioned request + * + * The repositioned event is sent as part of a popup + * configuration sequence, together with xdg_popup.configure and + * lastly xdg_surface.configure to notify the completion of a + * reposition request. + * + * The repositioned event is to notify about the completion of a + * xdg_popup.reposition request. The token argument is the token + * passed in the xdg_popup.reposition request. + * + * Immediately after this event is emitted, xdg_popup.configure and + * xdg_surface.configure will be sent with the updated size and + * position, as well as a new configure serial. + * + * The client should optionally update the content of the popup, + * but must acknowledge the new popup configuration for the new + * position to take effect. See xdg_surface.ack_configure for + * details. + * @param token reposition request token + * @since 3 + */ + void (*repositioned)(void *data, + struct xdg_popup *xdg_popup, + uint32_t token); +}; + +/** + * @ingroup iface_xdg_popup + */ +static inline int +xdg_popup_add_listener(struct xdg_popup *xdg_popup, + const struct xdg_popup_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) xdg_popup, + (void (**)(void)) listener, data); +} + +#define XDG_POPUP_DESTROY 0 +#define XDG_POPUP_GRAB 1 +#define XDG_POPUP_REPOSITION 2 + +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_CONFIGURE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_POPUP_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_REPOSITIONED_SINCE_VERSION 3 + +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_GRAB_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_REPOSITION_SINCE_VERSION 3 + +/** @ingroup iface_xdg_popup */ +static inline void +xdg_popup_set_user_data(struct xdg_popup *xdg_popup, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) xdg_popup, user_data); +} + +/** @ingroup iface_xdg_popup */ +static inline void * +xdg_popup_get_user_data(struct xdg_popup *xdg_popup) +{ + return wl_proxy_get_user_data((struct wl_proxy *) xdg_popup); +} + +static inline uint32_t +xdg_popup_get_version(struct xdg_popup *xdg_popup) +{ + return wl_proxy_get_version((struct wl_proxy *) xdg_popup); +} + +/** + * @ingroup iface_xdg_popup + * + * This destroys the popup. Explicitly destroying the xdg_popup + * object will also dismiss the popup, and unmap the surface. + * + * If this xdg_popup is not the "topmost" popup, a protocol error + * will be sent. + */ +static inline void +xdg_popup_destroy(struct xdg_popup *xdg_popup) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_popup, + XDG_POPUP_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_popup), WL_MARSHAL_FLAG_DESTROY); +} + +/** + * @ingroup iface_xdg_popup + * + * This request makes the created popup take an explicit grab. An explicit + * grab will be dismissed when the user dismisses the popup, or when the + * client destroys the xdg_popup. This can be done by the user clicking + * outside the surface, using the keyboard, or even locking the screen + * through closing the lid or a timeout. + * + * If the compositor denies the grab, the popup will be immediately + * dismissed. + * + * This request must be used in response to some sort of user action like a + * button press, key press, or touch down event. The serial number of the + * event should be passed as 'serial'. + * + * The parent of a grabbing popup must either be an xdg_toplevel surface or + * another xdg_popup with an explicit grab. If the parent is another + * xdg_popup it means that the popups are nested, with this popup now being + * the topmost popup. + * + * Nested popups must be destroyed in the reverse order they were created + * in, e.g. the only popup you are allowed to destroy at all times is the + * topmost one. + * + * When compositors choose to dismiss a popup, they may dismiss every + * nested grabbing popup as well. When a compositor dismisses popups, it + * will follow the same dismissing order as required from the client. + * + * If the topmost grabbing popup is destroyed, the grab will be returned to + * the parent of the popup, if that parent previously had an explicit grab. + * + * If the parent is a grabbing popup which has already been dismissed, this + * popup will be immediately dismissed. If the parent is a popup that did + * not take an explicit grab, an error will be raised. + * + * During a popup grab, the client owning the grab will receive pointer + * and touch events for all their surfaces as normal (similar to an + * "owner-events" grab in X11 parlance), while the top most grabbing popup + * will always have keyboard focus. + */ +static inline void +xdg_popup_grab(struct xdg_popup *xdg_popup, struct wl_seat *seat, uint32_t serial) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_popup, + XDG_POPUP_GRAB, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_popup), 0, seat, serial); +} + +/** + * @ingroup iface_xdg_popup + * + * Reposition an already-mapped popup. The popup will be placed given the + * details in the passed xdg_positioner object, and a + * xdg_popup.repositioned followed by xdg_popup.configure and + * xdg_surface.configure will be emitted in response. Any parameters set + * by the previous positioner will be discarded. + * + * The passed token will be sent in the corresponding + * xdg_popup.repositioned event. The new popup position will not take + * effect until the corresponding configure event is acknowledged by the + * client. See xdg_popup.repositioned for details. The token itself is + * opaque, and has no other special meaning. + * + * If multiple reposition requests are sent, the compositor may skip all + * but the last one. + * + * If the popup is repositioned in response to a configure event for its + * parent, the client should send an xdg_positioner.set_parent_configure + * and possibly an xdg_positioner.set_parent_size request to allow the + * compositor to properly constrain the popup. + * + * If the popup is repositioned together with a parent that is being + * resized, but not in response to a configure event, the client should + * send an xdg_positioner.set_parent_size request. + */ +static inline void +xdg_popup_reposition(struct xdg_popup *xdg_popup, struct xdg_positioner *positioner, uint32_t token) +{ + wl_proxy_marshal_flags((struct wl_proxy *) xdg_popup, + XDG_POPUP_REPOSITION, NULL, wl_proxy_get_version((struct wl_proxy *) xdg_popup), 0, positioner, token); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/xdg-shell-protocol.c b/app/src/main/cpp/waylandcomp/generated/xdg-shell-protocol.c new file mode 100644 index 0000000000..72b394a2b5 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/xdg-shell-protocol.c @@ -0,0 +1,184 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2008-2013 Kristian Høgsberg + * Copyright © 2013 Rafael Antognolli + * Copyright © 2013 Jasper St. Pierre + * Copyright © 2010-2013 Intel Corporation + * Copyright © 2015-2017 Samsung Electronics Co., Ltd + * Copyright © 2015-2017 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_output_interface; +extern const struct wl_interface wl_seat_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface xdg_popup_interface; +extern const struct wl_interface xdg_positioner_interface; +extern const struct wl_interface xdg_surface_interface; +extern const struct wl_interface xdg_toplevel_interface; + +static const struct wl_interface *xdg_shell_types[] = { + NULL, + NULL, + NULL, + NULL, + &xdg_positioner_interface, + &xdg_surface_interface, + &wl_surface_interface, + &xdg_toplevel_interface, + &xdg_popup_interface, + &xdg_surface_interface, + &xdg_positioner_interface, + &xdg_toplevel_interface, + &wl_seat_interface, + NULL, + NULL, + NULL, + &wl_seat_interface, + NULL, + &wl_seat_interface, + NULL, + NULL, + &wl_output_interface, + &wl_seat_interface, + NULL, + &xdg_positioner_interface, + NULL, +}; + +static const struct wl_message xdg_wm_base_requests[] = { + { "destroy", "", xdg_shell_types + 0 }, + { "create_positioner", "n", xdg_shell_types + 4 }, + { "get_xdg_surface", "no", xdg_shell_types + 5 }, + { "pong", "u", xdg_shell_types + 0 }, +}; + +static const struct wl_message xdg_wm_base_events[] = { + { "ping", "u", xdg_shell_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_wm_base_interface = { + "xdg_wm_base", 5, + 4, xdg_wm_base_requests, + 1, xdg_wm_base_events, +}; + +static const struct wl_message xdg_positioner_requests[] = { + { "destroy", "", xdg_shell_types + 0 }, + { "set_size", "ii", xdg_shell_types + 0 }, + { "set_anchor_rect", "iiii", xdg_shell_types + 0 }, + { "set_anchor", "u", xdg_shell_types + 0 }, + { "set_gravity", "u", xdg_shell_types + 0 }, + { "set_constraint_adjustment", "u", xdg_shell_types + 0 }, + { "set_offset", "ii", xdg_shell_types + 0 }, + { "set_reactive", "3", xdg_shell_types + 0 }, + { "set_parent_size", "3ii", xdg_shell_types + 0 }, + { "set_parent_configure", "3u", xdg_shell_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_positioner_interface = { + "xdg_positioner", 5, + 10, xdg_positioner_requests, + 0, NULL, +}; + +static const struct wl_message xdg_surface_requests[] = { + { "destroy", "", xdg_shell_types + 0 }, + { "get_toplevel", "n", xdg_shell_types + 7 }, + { "get_popup", "n?oo", xdg_shell_types + 8 }, + { "set_window_geometry", "iiii", xdg_shell_types + 0 }, + { "ack_configure", "u", xdg_shell_types + 0 }, +}; + +static const struct wl_message xdg_surface_events[] = { + { "configure", "u", xdg_shell_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_surface_interface = { + "xdg_surface", 5, + 5, xdg_surface_requests, + 1, xdg_surface_events, +}; + +static const struct wl_message xdg_toplevel_requests[] = { + { "destroy", "", xdg_shell_types + 0 }, + { "set_parent", "?o", xdg_shell_types + 11 }, + { "set_title", "s", xdg_shell_types + 0 }, + { "set_app_id", "s", xdg_shell_types + 0 }, + { "show_window_menu", "ouii", xdg_shell_types + 12 }, + { "move", "ou", xdg_shell_types + 16 }, + { "resize", "ouu", xdg_shell_types + 18 }, + { "set_max_size", "ii", xdg_shell_types + 0 }, + { "set_min_size", "ii", xdg_shell_types + 0 }, + { "set_maximized", "", xdg_shell_types + 0 }, + { "unset_maximized", "", xdg_shell_types + 0 }, + { "set_fullscreen", "?o", xdg_shell_types + 21 }, + { "unset_fullscreen", "", xdg_shell_types + 0 }, + { "set_minimized", "", xdg_shell_types + 0 }, +}; + +static const struct wl_message xdg_toplevel_events[] = { + { "configure", "iia", xdg_shell_types + 0 }, + { "close", "", xdg_shell_types + 0 }, + { "configure_bounds", "4ii", xdg_shell_types + 0 }, + { "wm_capabilities", "5a", xdg_shell_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_toplevel_interface = { + "xdg_toplevel", 5, + 14, xdg_toplevel_requests, + 4, xdg_toplevel_events, +}; + +static const struct wl_message xdg_popup_requests[] = { + { "destroy", "", xdg_shell_types + 0 }, + { "grab", "ou", xdg_shell_types + 22 }, + { "reposition", "3ou", xdg_shell_types + 24 }, +}; + +static const struct wl_message xdg_popup_events[] = { + { "configure", "iiii", xdg_shell_types + 0 }, + { "popup_done", "", xdg_shell_types + 0 }, + { "repositioned", "3u", xdg_shell_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_popup_interface = { + "xdg_popup", 5, + 3, xdg_popup_requests, + 3, xdg_popup_events, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/xdg-shell-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/xdg-shell-server-protocol.h new file mode 100644 index 0000000000..2683694cee --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/xdg-shell-server-protocol.h @@ -0,0 +1,2257 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef XDG_SHELL_SERVER_PROTOCOL_H +#define XDG_SHELL_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_xdg_shell The xdg_shell protocol + * @section page_ifaces_xdg_shell Interfaces + * - @subpage page_iface_xdg_wm_base - create desktop-style surfaces + * - @subpage page_iface_xdg_positioner - child surface positioner + * - @subpage page_iface_xdg_surface - desktop user interface surface base interface + * - @subpage page_iface_xdg_toplevel - toplevel surface + * - @subpage page_iface_xdg_popup - short-lived, popup surfaces for menus + * @section page_copyright_xdg_shell Copyright + * <pre> + * + * Copyright © 2008-2013 Kristian Høgsberg + * Copyright © 2013 Rafael Antognolli + * Copyright © 2013 Jasper St. Pierre + * Copyright © 2010-2013 Intel Corporation + * Copyright © 2015-2017 Samsung Electronics Co., Ltd + * Copyright © 2015-2017 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_output; +struct wl_seat; +struct wl_surface; +struct xdg_popup; +struct xdg_positioner; +struct xdg_surface; +struct xdg_toplevel; +struct xdg_wm_base; + +#ifndef XDG_WM_BASE_INTERFACE +#define XDG_WM_BASE_INTERFACE +/** + * @page page_iface_xdg_wm_base xdg_wm_base + * @section page_iface_xdg_wm_base_desc Description + * + * The xdg_wm_base interface is exposed as a global object enabling clients + * to turn their wl_surfaces into windows in a desktop environment. It + * defines the basic functionality needed for clients and the compositor to + * create windows that can be dragged, resized, maximized, etc, as well as + * creating transient windows such as popup menus. + * @section page_iface_xdg_wm_base_api API + * See @ref iface_xdg_wm_base. + */ +/** + * @defgroup iface_xdg_wm_base The xdg_wm_base interface + * + * The xdg_wm_base interface is exposed as a global object enabling clients + * to turn their wl_surfaces into windows in a desktop environment. It + * defines the basic functionality needed for clients and the compositor to + * create windows that can be dragged, resized, maximized, etc, as well as + * creating transient windows such as popup menus. + */ +extern const struct wl_interface xdg_wm_base_interface; +#endif +#ifndef XDG_POSITIONER_INTERFACE +#define XDG_POSITIONER_INTERFACE +/** + * @page page_iface_xdg_positioner xdg_positioner + * @section page_iface_xdg_positioner_desc Description + * + * The xdg_positioner provides a collection of rules for the placement of a + * child surface relative to a parent surface. Rules can be defined to ensure + * the child surface remains within the visible area's borders, and to + * specify how the child surface changes its position, such as sliding along + * an axis, or flipping around a rectangle. These positioner-created rules are + * constrained by the requirement that a child surface must intersect with or + * be at least partially adjacent to its parent surface. + * + * See the various requests for details about possible rules. + * + * At the time of the request, the compositor makes a copy of the rules + * specified by the xdg_positioner. Thus, after the request is complete the + * xdg_positioner object can be destroyed or reused; further changes to the + * object will have no effect on previous usages. + * + * For an xdg_positioner object to be considered complete, it must have a + * non-zero size set by set_size, and a non-zero anchor rectangle set by + * set_anchor_rect. Passing an incomplete xdg_positioner object when + * positioning a surface raises an invalid_positioner error. + * @section page_iface_xdg_positioner_api API + * See @ref iface_xdg_positioner. + */ +/** + * @defgroup iface_xdg_positioner The xdg_positioner interface + * + * The xdg_positioner provides a collection of rules for the placement of a + * child surface relative to a parent surface. Rules can be defined to ensure + * the child surface remains within the visible area's borders, and to + * specify how the child surface changes its position, such as sliding along + * an axis, or flipping around a rectangle. These positioner-created rules are + * constrained by the requirement that a child surface must intersect with or + * be at least partially adjacent to its parent surface. + * + * See the various requests for details about possible rules. + * + * At the time of the request, the compositor makes a copy of the rules + * specified by the xdg_positioner. Thus, after the request is complete the + * xdg_positioner object can be destroyed or reused; further changes to the + * object will have no effect on previous usages. + * + * For an xdg_positioner object to be considered complete, it must have a + * non-zero size set by set_size, and a non-zero anchor rectangle set by + * set_anchor_rect. Passing an incomplete xdg_positioner object when + * positioning a surface raises an invalid_positioner error. + */ +extern const struct wl_interface xdg_positioner_interface; +#endif +#ifndef XDG_SURFACE_INTERFACE +#define XDG_SURFACE_INTERFACE +/** + * @page page_iface_xdg_surface xdg_surface + * @section page_iface_xdg_surface_desc Description + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides a base set of functionality required to construct user + * interface elements requiring management by the compositor, such as + * toplevel windows, menus, etc. The types of functionality are split into + * xdg_surface roles. + * + * Creating an xdg_surface does not set the role for a wl_surface. In order + * to map an xdg_surface, the client must create a role-specific object + * using, e.g., get_toplevel, get_popup. The wl_surface for any given + * xdg_surface can have at most one role, and may not be assigned any role + * not based on xdg_surface. + * + * A role must be assigned before any other requests are made to the + * xdg_surface object. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_surface state to take effect. + * + * Creating an xdg_surface from a wl_surface which has a buffer attached or + * committed is a client error, and any attempts by a client to attach or + * manipulate a buffer prior to the first xdg_surface.configure call must + * also be treated as errors. + * + * After creating a role-specific object and setting it up, the client must + * perform an initial commit without any buffer attached. The compositor + * will reply with an xdg_surface.configure event. The client must + * acknowledge it and is then allowed to attach a buffer to map the surface. + * + * Mapping an xdg_surface-based role surface is defined as making it + * possible for the surface to be shown by the compositor. Note that + * a mapped surface is not guaranteed to be visible once it is mapped. + * + * For an xdg_surface to be mapped by the compositor, the following + * conditions must be met: + * (1) the client has assigned an xdg_surface-based role to the surface + * (2) the client has set and committed the xdg_surface state and the + * role-dependent state to the surface + * (3) the client has committed a buffer to the surface + * + * A newly-unmapped surface is considered to have met condition (1) out + * of the 3 required conditions for mapping a surface if its role surface + * has not been destroyed, i.e. the client must perform the initial commit + * again before attaching a buffer. + * @section page_iface_xdg_surface_api API + * See @ref iface_xdg_surface. + */ +/** + * @defgroup iface_xdg_surface The xdg_surface interface + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides a base set of functionality required to construct user + * interface elements requiring management by the compositor, such as + * toplevel windows, menus, etc. The types of functionality are split into + * xdg_surface roles. + * + * Creating an xdg_surface does not set the role for a wl_surface. In order + * to map an xdg_surface, the client must create a role-specific object + * using, e.g., get_toplevel, get_popup. The wl_surface for any given + * xdg_surface can have at most one role, and may not be assigned any role + * not based on xdg_surface. + * + * A role must be assigned before any other requests are made to the + * xdg_surface object. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_surface state to take effect. + * + * Creating an xdg_surface from a wl_surface which has a buffer attached or + * committed is a client error, and any attempts by a client to attach or + * manipulate a buffer prior to the first xdg_surface.configure call must + * also be treated as errors. + * + * After creating a role-specific object and setting it up, the client must + * perform an initial commit without any buffer attached. The compositor + * will reply with an xdg_surface.configure event. The client must + * acknowledge it and is then allowed to attach a buffer to map the surface. + * + * Mapping an xdg_surface-based role surface is defined as making it + * possible for the surface to be shown by the compositor. Note that + * a mapped surface is not guaranteed to be visible once it is mapped. + * + * For an xdg_surface to be mapped by the compositor, the following + * conditions must be met: + * (1) the client has assigned an xdg_surface-based role to the surface + * (2) the client has set and committed the xdg_surface state and the + * role-dependent state to the surface + * (3) the client has committed a buffer to the surface + * + * A newly-unmapped surface is considered to have met condition (1) out + * of the 3 required conditions for mapping a surface if its role surface + * has not been destroyed, i.e. the client must perform the initial commit + * again before attaching a buffer. + */ +extern const struct wl_interface xdg_surface_interface; +#endif +#ifndef XDG_TOPLEVEL_INTERFACE +#define XDG_TOPLEVEL_INTERFACE +/** + * @page page_iface_xdg_toplevel xdg_toplevel + * @section page_iface_xdg_toplevel_desc Description + * + * This interface defines an xdg_surface role which allows a surface to, + * among other things, set window-like properties such as maximize, + * fullscreen, and minimize, set application-specific metadata like title and + * id, and well as trigger user interactive operations such as interactive + * resize and move. + * + * Unmapping an xdg_toplevel means that the surface cannot be shown + * by the compositor until it is explicitly mapped again. + * All active operations (e.g., move, resize) are canceled and all + * attributes (e.g. title, state, stacking, ...) are discarded for + * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to + * the state it had right after xdg_surface.get_toplevel. The client + * can re-map the toplevel by performing a commit without any buffer + * attached, waiting for a configure event and handling it as usual (see + * xdg_surface description). + * + * Attaching a null buffer to a toplevel unmaps the surface. + * @section page_iface_xdg_toplevel_api API + * See @ref iface_xdg_toplevel. + */ +/** + * @defgroup iface_xdg_toplevel The xdg_toplevel interface + * + * This interface defines an xdg_surface role which allows a surface to, + * among other things, set window-like properties such as maximize, + * fullscreen, and minimize, set application-specific metadata like title and + * id, and well as trigger user interactive operations such as interactive + * resize and move. + * + * Unmapping an xdg_toplevel means that the surface cannot be shown + * by the compositor until it is explicitly mapped again. + * All active operations (e.g., move, resize) are canceled and all + * attributes (e.g. title, state, stacking, ...) are discarded for + * an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to + * the state it had right after xdg_surface.get_toplevel. The client + * can re-map the toplevel by performing a commit without any buffer + * attached, waiting for a configure event and handling it as usual (see + * xdg_surface description). + * + * Attaching a null buffer to a toplevel unmaps the surface. + */ +extern const struct wl_interface xdg_toplevel_interface; +#endif +#ifndef XDG_POPUP_INTERFACE +#define XDG_POPUP_INTERFACE +/** + * @page page_iface_xdg_popup xdg_popup + * @section page_iface_xdg_popup_desc Description + * + * A popup surface is a short-lived, temporary surface. It can be used to + * implement for example menus, popovers, tooltips and other similar user + * interface concepts. + * + * A popup can be made to take an explicit grab. See xdg_popup.grab for + * details. + * + * When the popup is dismissed, a popup_done event will be sent out, and at + * the same time the surface will be unmapped. See the xdg_popup.popup_done + * event for details. + * + * Explicitly destroying the xdg_popup object will also dismiss the popup and + * unmap the surface. Clients that want to dismiss the popup when another + * surface of their own is clicked should dismiss the popup using the destroy + * request. + * + * A newly created xdg_popup will be stacked on top of all previously created + * xdg_popup surfaces associated with the same xdg_toplevel. + * + * The parent of an xdg_popup must be mapped (see the xdg_surface + * description) before the xdg_popup itself. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_popup state to take effect. + * @section page_iface_xdg_popup_api API + * See @ref iface_xdg_popup. + */ +/** + * @defgroup iface_xdg_popup The xdg_popup interface + * + * A popup surface is a short-lived, temporary surface. It can be used to + * implement for example menus, popovers, tooltips and other similar user + * interface concepts. + * + * A popup can be made to take an explicit grab. See xdg_popup.grab for + * details. + * + * When the popup is dismissed, a popup_done event will be sent out, and at + * the same time the surface will be unmapped. See the xdg_popup.popup_done + * event for details. + * + * Explicitly destroying the xdg_popup object will also dismiss the popup and + * unmap the surface. Clients that want to dismiss the popup when another + * surface of their own is clicked should dismiss the popup using the destroy + * request. + * + * A newly created xdg_popup will be stacked on top of all previously created + * xdg_popup surfaces associated with the same xdg_toplevel. + * + * The parent of an xdg_popup must be mapped (see the xdg_surface + * description) before the xdg_popup itself. + * + * The client must call wl_surface.commit on the corresponding wl_surface + * for the xdg_popup state to take effect. + */ +extern const struct wl_interface xdg_popup_interface; +#endif + +#ifndef XDG_WM_BASE_ERROR_ENUM +#define XDG_WM_BASE_ERROR_ENUM +enum xdg_wm_base_error { + /** + * given wl_surface has another role + */ + XDG_WM_BASE_ERROR_ROLE = 0, + /** + * xdg_wm_base was destroyed before children + */ + XDG_WM_BASE_ERROR_DEFUNCT_SURFACES = 1, + /** + * the client tried to map or destroy a non-topmost popup + */ + XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP = 2, + /** + * the client specified an invalid popup parent surface + */ + XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT = 3, + /** + * the client provided an invalid surface state + */ + XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE = 4, + /** + * the client provided an invalid positioner + */ + XDG_WM_BASE_ERROR_INVALID_POSITIONER = 5, + /** + * the client didn’t respond to a ping event in time + */ + XDG_WM_BASE_ERROR_UNRESPONSIVE = 6, +}; +#endif /* XDG_WM_BASE_ERROR_ENUM */ + +#ifndef XDG_WM_BASE_ERROR_ENUM_IS_VALID +#define XDG_WM_BASE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_wm_base + * Validate a xdg_wm_base error value. + * + * @return true on success, false on error. + * @ref xdg_wm_base_error + */ +static inline bool +xdg_wm_base_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_WM_BASE_ERROR_ROLE: + return version >= 1; + case XDG_WM_BASE_ERROR_DEFUNCT_SURFACES: + return version >= 1; + case XDG_WM_BASE_ERROR_NOT_THE_TOPMOST_POPUP: + return version >= 1; + case XDG_WM_BASE_ERROR_INVALID_POPUP_PARENT: + return version >= 1; + case XDG_WM_BASE_ERROR_INVALID_SURFACE_STATE: + return version >= 1; + case XDG_WM_BASE_ERROR_INVALID_POSITIONER: + return version >= 1; + case XDG_WM_BASE_ERROR_UNRESPONSIVE: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_WM_BASE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_wm_base + * @struct xdg_wm_base_interface + */ +struct xdg_wm_base_interface { + /** + * destroy xdg_wm_base + * + * Destroy this xdg_wm_base object. + * + * Destroying a bound xdg_wm_base object while there are surfaces + * still alive created by this xdg_wm_base object instance is + * illegal and will result in a defunct_surfaces error. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * create a positioner object + * + * Create a positioner object. A positioner object is used to + * position surfaces relative to some parent surface. See the + * interface description and xdg_surface.get_popup for details. + */ + void (*create_positioner)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * create a shell surface from a surface + * + * This creates an xdg_surface for the given surface. While + * xdg_surface itself is not a role, the corresponding surface may + * only be assigned a role extending xdg_surface, such as + * xdg_toplevel or xdg_popup. It is illegal to create an + * xdg_surface for a wl_surface which already has an assigned role + * and this will result in a role error. + * + * This creates an xdg_surface for the given surface. An + * xdg_surface is used as basis to define a role to a given + * surface, such as xdg_toplevel or xdg_popup. It also manages + * functionality shared between xdg_surface based surface roles. + * + * See the documentation of xdg_surface for more details about what + * an xdg_surface is and how it is used. + */ + void (*get_xdg_surface)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); + /** + * respond to a ping event + * + * A client must respond to a ping event with a pong request or + * the client may be deemed unresponsive. See xdg_wm_base.ping and + * xdg_wm_base.error.unresponsive. + * @param serial serial of the ping event + */ + void (*pong)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial); +}; + +#define XDG_WM_BASE_PING 0 + +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_PING_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_CREATE_POSITIONER_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_GET_XDG_SURFACE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_wm_base + */ +#define XDG_WM_BASE_PONG_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_wm_base + * Sends an ping event to the client owning the resource. + * @param resource_ The client's resource + * @param serial pass this to the pong request + */ +static inline void +xdg_wm_base_send_ping(struct wl_resource *resource_, uint32_t serial) +{ + wl_resource_post_event(resource_, XDG_WM_BASE_PING, serial); +} + +#ifndef XDG_POSITIONER_ERROR_ENUM +#define XDG_POSITIONER_ERROR_ENUM +enum xdg_positioner_error { + /** + * invalid input provided + */ + XDG_POSITIONER_ERROR_INVALID_INPUT = 0, +}; +#endif /* XDG_POSITIONER_ERROR_ENUM */ + +#ifndef XDG_POSITIONER_ERROR_ENUM_IS_VALID +#define XDG_POSITIONER_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_positioner + * Validate a xdg_positioner error value. + * + * @return true on success, false on error. + * @ref xdg_positioner_error + */ +static inline bool +xdg_positioner_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_POSITIONER_ERROR_INVALID_INPUT: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_POSITIONER_ERROR_ENUM_IS_VALID */ + +#ifndef XDG_POSITIONER_ANCHOR_ENUM +#define XDG_POSITIONER_ANCHOR_ENUM +enum xdg_positioner_anchor { + XDG_POSITIONER_ANCHOR_NONE = 0, + XDG_POSITIONER_ANCHOR_TOP = 1, + XDG_POSITIONER_ANCHOR_BOTTOM = 2, + XDG_POSITIONER_ANCHOR_LEFT = 3, + XDG_POSITIONER_ANCHOR_RIGHT = 4, + XDG_POSITIONER_ANCHOR_TOP_LEFT = 5, + XDG_POSITIONER_ANCHOR_BOTTOM_LEFT = 6, + XDG_POSITIONER_ANCHOR_TOP_RIGHT = 7, + XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT = 8, +}; +#endif /* XDG_POSITIONER_ANCHOR_ENUM */ + +#ifndef XDG_POSITIONER_ANCHOR_ENUM_IS_VALID +#define XDG_POSITIONER_ANCHOR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_positioner + * Validate a xdg_positioner anchor value. + * + * @return true on success, false on error. + * @ref xdg_positioner_anchor + */ +static inline bool +xdg_positioner_anchor_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_POSITIONER_ANCHOR_NONE: + return version >= 1; + case XDG_POSITIONER_ANCHOR_TOP: + return version >= 1; + case XDG_POSITIONER_ANCHOR_BOTTOM: + return version >= 1; + case XDG_POSITIONER_ANCHOR_LEFT: + return version >= 1; + case XDG_POSITIONER_ANCHOR_RIGHT: + return version >= 1; + case XDG_POSITIONER_ANCHOR_TOP_LEFT: + return version >= 1; + case XDG_POSITIONER_ANCHOR_BOTTOM_LEFT: + return version >= 1; + case XDG_POSITIONER_ANCHOR_TOP_RIGHT: + return version >= 1; + case XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_POSITIONER_ANCHOR_ENUM_IS_VALID */ + +#ifndef XDG_POSITIONER_GRAVITY_ENUM +#define XDG_POSITIONER_GRAVITY_ENUM +enum xdg_positioner_gravity { + XDG_POSITIONER_GRAVITY_NONE = 0, + XDG_POSITIONER_GRAVITY_TOP = 1, + XDG_POSITIONER_GRAVITY_BOTTOM = 2, + XDG_POSITIONER_GRAVITY_LEFT = 3, + XDG_POSITIONER_GRAVITY_RIGHT = 4, + XDG_POSITIONER_GRAVITY_TOP_LEFT = 5, + XDG_POSITIONER_GRAVITY_BOTTOM_LEFT = 6, + XDG_POSITIONER_GRAVITY_TOP_RIGHT = 7, + XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT = 8, +}; +#endif /* XDG_POSITIONER_GRAVITY_ENUM */ + +#ifndef XDG_POSITIONER_GRAVITY_ENUM_IS_VALID +#define XDG_POSITIONER_GRAVITY_ENUM_IS_VALID +/** + * @ingroup iface_xdg_positioner + * Validate a xdg_positioner gravity value. + * + * @return true on success, false on error. + * @ref xdg_positioner_gravity + */ +static inline bool +xdg_positioner_gravity_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_POSITIONER_GRAVITY_NONE: + return version >= 1; + case XDG_POSITIONER_GRAVITY_TOP: + return version >= 1; + case XDG_POSITIONER_GRAVITY_BOTTOM: + return version >= 1; + case XDG_POSITIONER_GRAVITY_LEFT: + return version >= 1; + case XDG_POSITIONER_GRAVITY_RIGHT: + return version >= 1; + case XDG_POSITIONER_GRAVITY_TOP_LEFT: + return version >= 1; + case XDG_POSITIONER_GRAVITY_BOTTOM_LEFT: + return version >= 1; + case XDG_POSITIONER_GRAVITY_TOP_RIGHT: + return version >= 1; + case XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_POSITIONER_GRAVITY_ENUM_IS_VALID */ + +#ifndef XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM +#define XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM +/** + * @ingroup iface_xdg_positioner + * constraint adjustments + * + * The constraint adjustment value define ways the compositor will adjust + * the position of the surface, if the unadjusted position would result + * in the surface being partly constrained. + * + * Whether a surface is considered 'constrained' is left to the compositor + * to determine. For example, the surface may be partly outside the + * compositor's defined 'work area', thus necessitating the child surface's + * position be adjusted until it is entirely inside the work area. + * + * The adjustments can be combined, according to a defined precedence: 1) + * Flip, 2) Slide, 3) Resize. + */ +enum xdg_positioner_constraint_adjustment { + /** + * don't move the child surface when constrained + * + * Don't alter the surface position even if it is constrained on + * some axis, for example partially outside the edge of an output. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE = 0, + /** + * move along the x axis until unconstrained + * + * Slide the surface along the x axis until it is no longer + * constrained. + * + * First try to slide towards the direction of the gravity on the x + * axis until either the edge in the opposite direction of the + * gravity is unconstrained or the edge in the direction of the + * gravity is constrained. + * + * Then try to slide towards the opposite direction of the gravity + * on the x axis until either the edge in the direction of the + * gravity is unconstrained or the edge in the opposite direction + * of the gravity is constrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X = 1, + /** + * move along the y axis until unconstrained + * + * Slide the surface along the y axis until it is no longer + * constrained. + * + * First try to slide towards the direction of the gravity on the y + * axis until either the edge in the opposite direction of the + * gravity is unconstrained or the edge in the direction of the + * gravity is constrained. + * + * Then try to slide towards the opposite direction of the gravity + * on the y axis until either the edge in the direction of the + * gravity is unconstrained or the edge in the opposite direction + * of the gravity is constrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y = 2, + /** + * invert the anchor and gravity on the x axis + * + * Invert the anchor and gravity on the x axis if the surface is + * constrained on the x axis. For example, if the left edge of the + * surface is constrained, the gravity is 'left' and the anchor is + * 'left', change the gravity to 'right' and the anchor to 'right'. + * + * If the adjusted position also ends up being constrained, the + * resulting position of the flip_x adjustment will be the one + * before the adjustment. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X = 4, + /** + * invert the anchor and gravity on the y axis + * + * Invert the anchor and gravity on the y axis if the surface is + * constrained on the y axis. For example, if the bottom edge of + * the surface is constrained, the gravity is 'bottom' and the + * anchor is 'bottom', change the gravity to 'top' and the anchor + * to 'top'. + * + * The adjusted position is calculated given the original anchor + * rectangle and offset, but with the new flipped anchor and + * gravity values. + * + * If the adjusted position also ends up being constrained, the + * resulting position of the flip_y adjustment will be the one + * before the adjustment. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y = 8, + /** + * horizontally resize the surface + * + * Resize the surface horizontally so that it is completely + * unconstrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X = 16, + /** + * vertically resize the surface + * + * Resize the surface vertically so that it is completely + * unconstrained. + */ + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y = 32, +}; +#endif /* XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM */ + +#ifndef XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM_IS_VALID +#define XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM_IS_VALID +/** + * @ingroup iface_xdg_positioner + * Validate a xdg_positioner constraint_adjustment value. + * + * @return true on success, false on error. + * @ref xdg_positioner_constraint_adjustment + */ +static inline bool +xdg_positioner_constraint_adjustment_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_NONE; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X; + if (version >= 1) + valid |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y; + return (value & ~valid) == 0; +} +#endif /* XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_positioner + * @struct xdg_positioner_interface + */ +struct xdg_positioner_interface { + /** + * destroy the xdg_positioner object + * + * Notify the compositor that the xdg_positioner will no longer + * be used. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the size of the to-be positioned rectangle + * + * Set the size of the surface that is to be positioned with the + * positioner object. The size is in surface-local coordinates and + * corresponds to the window geometry. See + * xdg_surface.set_window_geometry. + * + * If a zero or negative size is set the invalid_input error is + * raised. + * @param width width of positioned rectangle + * @param height height of positioned rectangle + */ + void (*set_size)(struct wl_client *client, + struct wl_resource *resource, + int32_t width, + int32_t height); + /** + * set the anchor rectangle within the parent surface + * + * Specify the anchor rectangle within the parent surface that + * the child surface will be placed relative to. The rectangle is + * relative to the window geometry as defined by + * xdg_surface.set_window_geometry of the parent surface. + * + * When the xdg_positioner object is used to position a child + * surface, the anchor rectangle may not extend outside the window + * geometry of the positioned child's parent surface. + * + * If a negative size is set the invalid_input error is raised. + * @param x x position of anchor rectangle + * @param y y position of anchor rectangle + * @param width width of anchor rectangle + * @param height height of anchor rectangle + */ + void (*set_anchor_rect)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * set anchor rectangle anchor + * + * Defines the anchor point for the anchor rectangle. The + * specified anchor is used derive an anchor point that the child + * surface will be positioned relative to. If a corner anchor is + * set (e.g. 'top_left' or 'bottom_right'), the anchor point will + * be at the specified corner; otherwise, the derived anchor point + * will be centered on the specified edge, or in the center of the + * anchor rectangle if no edge is specified. + * @param anchor anchor + */ + void (*set_anchor)(struct wl_client *client, + struct wl_resource *resource, + uint32_t anchor); + /** + * set child surface gravity + * + * Defines in what direction a surface should be positioned, + * relative to the anchor point of the parent surface. If a corner + * gravity is specified (e.g. 'bottom_right' or 'top_left'), then + * the child surface will be placed towards the specified gravity; + * otherwise, the child surface will be centered over the anchor + * point on any axis that had no gravity specified. If the gravity + * is not in the ‘gravity’ enum, an invalid_input error is + * raised. + * @param gravity gravity direction + */ + void (*set_gravity)(struct wl_client *client, + struct wl_resource *resource, + uint32_t gravity); + /** + * set the adjustment to be done when constrained + * + * Specify how the window should be positioned if the originally + * intended position caused the surface to be constrained, meaning + * at least partially outside positioning boundaries set by the + * compositor. The adjustment is set by constructing a bitmask + * describing the adjustment to be made when the surface is + * constrained on that axis. + * + * If no bit for one axis is set, the compositor will assume that + * the child surface should not change its position on that axis + * when constrained. + * + * If more than one bit for one axis is set, the order of how + * adjustments are applied is specified in the corresponding + * adjustment descriptions. + * + * The default adjustment is none. + * @param constraint_adjustment bit mask of constraint adjustments + */ + void (*set_constraint_adjustment)(struct wl_client *client, + struct wl_resource *resource, + uint32_t constraint_adjustment); + /** + * set surface position offset + * + * Specify the surface position offset relative to the position + * of the anchor on the anchor rectangle and the anchor on the + * surface. For example if the anchor of the anchor rectangle is at + * (x, y), the surface has the gravity bottom|right, and the offset + * is (ox, oy), the calculated surface position will be (x + ox, y + * + oy). The offset position of the surface is the one used for + * constraint testing. See set_constraint_adjustment. + * + * An example use case is placing a popup menu on top of a user + * interface element, while aligning the user interface element of + * the parent surface with some user interface element placed + * somewhere in the popup surface. + * @param x surface position x offset + * @param y surface position y offset + */ + void (*set_offset)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y); + /** + * continuously reconstrain the surface + * + * When set reactive, the surface is reconstrained if the + * conditions used for constraining changed, e.g. the parent window + * moved. + * + * If the conditions changed and the popup was reconstrained, an + * xdg_popup.configure event is sent with updated geometry, + * followed by an xdg_surface.configure event. + * @since 3 + */ + void (*set_reactive)(struct wl_client *client, + struct wl_resource *resource); + /** + * + * + * Set the parent window geometry the compositor should use when + * positioning the popup. The compositor may use this information + * to determine the future state the popup should be constrained + * using. If this doesn't match the dimension of the parent the + * popup is eventually positioned against, the behavior is + * undefined. + * + * The arguments are given in the surface-local coordinate space. + * @param parent_width future window geometry width of parent + * @param parent_height future window geometry height of parent + * @since 3 + */ + void (*set_parent_size)(struct wl_client *client, + struct wl_resource *resource, + int32_t parent_width, + int32_t parent_height); + /** + * set parent configure this is a response to + * + * Set the serial of an xdg_surface.configure event this + * positioner will be used in response to. The compositor may use + * this information together with set_parent_size to determine what + * future state the popup should be constrained using. + * @param serial serial of parent configure event + * @since 3 + */ + void (*set_parent_configure)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial); +}; + + +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_ANCHOR_RECT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_ANCHOR_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_GRAVITY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_CONSTRAINT_ADJUSTMENT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_OFFSET_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_REACTIVE_SINCE_VERSION 3 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_PARENT_SIZE_SINCE_VERSION 3 +/** + * @ingroup iface_xdg_positioner + */ +#define XDG_POSITIONER_SET_PARENT_CONFIGURE_SINCE_VERSION 3 + +#ifndef XDG_SURFACE_ERROR_ENUM +#define XDG_SURFACE_ERROR_ENUM +enum xdg_surface_error { + /** + * Surface was not fully constructed + */ + XDG_SURFACE_ERROR_NOT_CONSTRUCTED = 1, + /** + * Surface was already constructed + */ + XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED = 2, + /** + * Attaching a buffer to an unconfigured surface + */ + XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER = 3, + /** + * Invalid serial number when acking a configure event + */ + XDG_SURFACE_ERROR_INVALID_SERIAL = 4, + /** + * Width or height was zero or negative + */ + XDG_SURFACE_ERROR_INVALID_SIZE = 5, + /** + * Surface was destroyed before its role object + */ + XDG_SURFACE_ERROR_DEFUNCT_ROLE_OBJECT = 6, +}; +#endif /* XDG_SURFACE_ERROR_ENUM */ + +#ifndef XDG_SURFACE_ERROR_ENUM_IS_VALID +#define XDG_SURFACE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_surface + * Validate a xdg_surface error value. + * + * @return true on success, false on error. + * @ref xdg_surface_error + */ +static inline bool +xdg_surface_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_SURFACE_ERROR_NOT_CONSTRUCTED: + return version >= 1; + case XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED: + return version >= 1; + case XDG_SURFACE_ERROR_UNCONFIGURED_BUFFER: + return version >= 1; + case XDG_SURFACE_ERROR_INVALID_SERIAL: + return version >= 1; + case XDG_SURFACE_ERROR_INVALID_SIZE: + return version >= 1; + case XDG_SURFACE_ERROR_DEFUNCT_ROLE_OBJECT: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_SURFACE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_surface + * @struct xdg_surface_interface + */ +struct xdg_surface_interface { + /** + * destroy the xdg_surface + * + * Destroy the xdg_surface object. An xdg_surface must only be + * destroyed after its role object has been destroyed, otherwise a + * defunct_role_object error is raised. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * assign the xdg_toplevel surface role + * + * This creates an xdg_toplevel object for the given xdg_surface + * and gives the associated wl_surface the xdg_toplevel role. + * + * See the documentation of xdg_toplevel for more details about + * what an xdg_toplevel is and how it is used. + */ + void (*get_toplevel)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * assign the xdg_popup surface role + * + * This creates an xdg_popup object for the given xdg_surface and + * gives the associated wl_surface the xdg_popup role. + * + * If null is passed as a parent, a parent surface must be + * specified using some other protocol, before committing the + * initial state. + * + * See the documentation of xdg_popup for more details about what + * an xdg_popup is and how it is used. + */ + void (*get_popup)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *parent, + struct wl_resource *positioner); + /** + * set the new window geometry + * + * The window geometry of a surface is its "visible bounds" from + * the user's perspective. Client-side decorations often have + * invisible portions like drop-shadows which should be ignored for + * the purposes of aligning, placing and constraining windows. + * + * The window geometry is double buffered, and will be applied at + * the time wl_surface.commit of the corresponding wl_surface is + * called. + * + * When maintaining a position, the compositor should treat the (x, + * y) coordinate of the window geometry as the top left corner of + * the window. A client changing the (x, y) window geometry + * coordinate should in general not alter the position of the + * window. + * + * Once the window geometry of the surface is set, it is not + * possible to unset it, and it will remain the same until + * set_window_geometry is called again, even if a new subsurface or + * buffer is attached. + * + * If never set, the value is the full bounds of the surface, + * including any subsurfaces. This updates dynamically on every + * commit. This unset is meant for extremely simple clients. + * + * The arguments are given in the surface-local coordinate space of + * the wl_surface associated with this xdg_surface. + * + * The width and height must be greater than zero. Setting an + * invalid size will raise an invalid_size error. When applied, the + * effective window geometry will be the set window geometry + * clamped to the bounding rectangle of the combined geometry of + * the surface of the xdg_surface and the associated subsurfaces. + */ + void (*set_window_geometry)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * ack a configure event + * + * When a configure event is received, if a client commits the + * surface in response to the configure event, then the client must + * make an ack_configure request sometime before the commit + * request, passing along the serial of the configure event. + * + * For instance, for toplevel surfaces the compositor might use + * this information to move a surface to the top left only when the + * client has drawn itself for the maximized or fullscreen state. + * + * If the client receives multiple configure events before it can + * respond to one, it only has to ack the last configure event. + * Acking a configure event that was never sent raises an + * invalid_serial error. + * + * A client is not required to commit immediately after sending an + * ack_configure request - it may even ack_configure several times + * before its next surface commit. + * + * A client may send multiple ack_configure requests before + * committing, but only the last request sent before a commit + * indicates which configure event the client really is responding + * to. + * + * Sending an ack_configure request consumes the serial number sent + * with the request, as well as serial numbers sent by all + * configure events sent on this xdg_surface prior to the configure + * event referenced by the committed serial. + * + * It is an error to issue multiple ack_configure requests + * referencing a serial from the same configure event, or to issue + * an ack_configure request referencing a serial from a configure + * event issued before the event identified by the last + * ack_configure request for the same xdg_surface. Doing so will + * raise an invalid_serial error. + * @param serial the serial from the configure event + */ + void (*ack_configure)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial); +}; + +#define XDG_SURFACE_CONFIGURE 0 + +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_CONFIGURE_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_GET_TOPLEVEL_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_GET_POPUP_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_SET_WINDOW_GEOMETRY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_surface + */ +#define XDG_SURFACE_ACK_CONFIGURE_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_surface + * Sends an configure event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial of the configure event + */ +static inline void +xdg_surface_send_configure(struct wl_resource *resource_, uint32_t serial) +{ + wl_resource_post_event(resource_, XDG_SURFACE_CONFIGURE, serial); +} + +#ifndef XDG_TOPLEVEL_ERROR_ENUM +#define XDG_TOPLEVEL_ERROR_ENUM +enum xdg_toplevel_error { + /** + * provided value is not a valid variant of the resize_edge enum + */ + XDG_TOPLEVEL_ERROR_INVALID_RESIZE_EDGE = 0, + /** + * invalid parent toplevel + */ + XDG_TOPLEVEL_ERROR_INVALID_PARENT = 1, + /** + * client provided an invalid min or max size + */ + XDG_TOPLEVEL_ERROR_INVALID_SIZE = 2, +}; +#endif /* XDG_TOPLEVEL_ERROR_ENUM */ + +#ifndef XDG_TOPLEVEL_ERROR_ENUM_IS_VALID +#define XDG_TOPLEVEL_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_toplevel + * Validate a xdg_toplevel error value. + * + * @return true on success, false on error. + * @ref xdg_toplevel_error + */ +static inline bool +xdg_toplevel_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_TOPLEVEL_ERROR_INVALID_RESIZE_EDGE: + return version >= 1; + case XDG_TOPLEVEL_ERROR_INVALID_PARENT: + return version >= 1; + case XDG_TOPLEVEL_ERROR_INVALID_SIZE: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_TOPLEVEL_ERROR_ENUM_IS_VALID */ + +#ifndef XDG_TOPLEVEL_RESIZE_EDGE_ENUM +#define XDG_TOPLEVEL_RESIZE_EDGE_ENUM +/** + * @ingroup iface_xdg_toplevel + * edge values for resizing + * + * These values are used to indicate which edge of a surface + * is being dragged in a resize operation. + */ +enum xdg_toplevel_resize_edge { + XDG_TOPLEVEL_RESIZE_EDGE_NONE = 0, + XDG_TOPLEVEL_RESIZE_EDGE_TOP = 1, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM = 2, + XDG_TOPLEVEL_RESIZE_EDGE_LEFT = 4, + XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT = 5, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT = 6, + XDG_TOPLEVEL_RESIZE_EDGE_RIGHT = 8, + XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT = 9, + XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT = 10, +}; +#endif /* XDG_TOPLEVEL_RESIZE_EDGE_ENUM */ + +#ifndef XDG_TOPLEVEL_RESIZE_EDGE_ENUM_IS_VALID +#define XDG_TOPLEVEL_RESIZE_EDGE_ENUM_IS_VALID +/** + * @ingroup iface_xdg_toplevel + * Validate a xdg_toplevel resize_edge value. + * + * @return true on success, false on error. + * @ref xdg_toplevel_resize_edge + */ +static inline bool +xdg_toplevel_resize_edge_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_TOPLEVEL_RESIZE_EDGE_NONE: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_TOP: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_LEFT: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_RIGHT: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT: + return version >= 1; + case XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_RIGHT: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_TOPLEVEL_RESIZE_EDGE_ENUM_IS_VALID */ + +#ifndef XDG_TOPLEVEL_STATE_ENUM +#define XDG_TOPLEVEL_STATE_ENUM +/** + * @ingroup iface_xdg_toplevel + * types of state on the surface + * + * The different state values used on the surface. This is designed for + * state values like maximized, fullscreen. It is paired with the + * configure event to ensure that both the client and the compositor + * setting the state can be synchronized. + * + * States set in this way are double-buffered. They will get applied on + * the next commit. + */ +enum xdg_toplevel_state { + /** + * the surface is maximized + * the surface is maximized + * + * The surface is maximized. The window geometry specified in the + * configure event must be obeyed by the client. + * + * The client should draw without shadow or other decoration + * outside of the window geometry. + */ + XDG_TOPLEVEL_STATE_MAXIMIZED = 1, + /** + * the surface is fullscreen + * the surface is fullscreen + * + * The surface is fullscreen. The window geometry specified in + * the configure event is a maximum; the client cannot resize + * beyond it. For a surface to cover the whole fullscreened area, + * the geometry dimensions must be obeyed by the client. For more + * details, see xdg_toplevel.set_fullscreen. + */ + XDG_TOPLEVEL_STATE_FULLSCREEN = 2, + /** + * the surface is being resized + * the surface is being resized + * + * The surface is being resized. The window geometry specified in + * the configure event is a maximum; the client cannot resize + * beyond it. Clients that have aspect ratio or cell sizing + * configuration can use a smaller size, however. + */ + XDG_TOPLEVEL_STATE_RESIZING = 3, + /** + * the surface is now activated + * the surface is now activated + * + * Client window decorations should be painted as if the window + * is active. Do not assume this means that the window actually has + * keyboard or pointer focus. + */ + XDG_TOPLEVEL_STATE_ACTIVATED = 4, + /** + * the surface’s left edge is tiled + * + * The window is currently in a tiled layout and the left edge is + * considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_LEFT = 5, + /** + * the surface’s right edge is tiled + * + * The window is currently in a tiled layout and the right edge + * is considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_RIGHT = 6, + /** + * the surface’s top edge is tiled + * + * The window is currently in a tiled layout and the top edge is + * considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_TOP = 7, + /** + * the surface’s bottom edge is tiled + * + * The window is currently in a tiled layout and the bottom edge + * is considered to be adjacent to another part of the tiling grid. + * @since 2 + */ + XDG_TOPLEVEL_STATE_TILED_BOTTOM = 8, +}; +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_TOP_SINCE_VERSION 2 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_STATE_TILED_BOTTOM_SINCE_VERSION 2 +#endif /* XDG_TOPLEVEL_STATE_ENUM */ + +#ifndef XDG_TOPLEVEL_STATE_ENUM_IS_VALID +#define XDG_TOPLEVEL_STATE_ENUM_IS_VALID +/** + * @ingroup iface_xdg_toplevel + * Validate a xdg_toplevel state value. + * + * @return true on success, false on error. + * @ref xdg_toplevel_state + */ +static inline bool +xdg_toplevel_state_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_TOPLEVEL_STATE_MAXIMIZED: + return version >= 1; + case XDG_TOPLEVEL_STATE_FULLSCREEN: + return version >= 1; + case XDG_TOPLEVEL_STATE_RESIZING: + return version >= 1; + case XDG_TOPLEVEL_STATE_ACTIVATED: + return version >= 1; + case XDG_TOPLEVEL_STATE_TILED_LEFT: + return version >= 2; + case XDG_TOPLEVEL_STATE_TILED_RIGHT: + return version >= 2; + case XDG_TOPLEVEL_STATE_TILED_TOP: + return version >= 2; + case XDG_TOPLEVEL_STATE_TILED_BOTTOM: + return version >= 2; + default: + return false; + } +} +#endif /* XDG_TOPLEVEL_STATE_ENUM_IS_VALID */ + +#ifndef XDG_TOPLEVEL_WM_CAPABILITIES_ENUM +#define XDG_TOPLEVEL_WM_CAPABILITIES_ENUM +enum xdg_toplevel_wm_capabilities { + /** + * show_window_menu is available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU = 1, + /** + * set_maximized and unset_maximized are available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE = 2, + /** + * set_fullscreen and unset_fullscreen are available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN = 3, + /** + * set_minimized is available + */ + XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE = 4, +}; +#endif /* XDG_TOPLEVEL_WM_CAPABILITIES_ENUM */ + +#ifndef XDG_TOPLEVEL_WM_CAPABILITIES_ENUM_IS_VALID +#define XDG_TOPLEVEL_WM_CAPABILITIES_ENUM_IS_VALID +/** + * @ingroup iface_xdg_toplevel + * Validate a xdg_toplevel wm_capabilities value. + * + * @return true on success, false on error. + * @ref xdg_toplevel_wm_capabilities + */ +static inline bool +xdg_toplevel_wm_capabilities_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU: + return version >= 1; + case XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE: + return version >= 1; + case XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN: + return version >= 1; + case XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_TOPLEVEL_WM_CAPABILITIES_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_toplevel + * @struct xdg_toplevel_interface + */ +struct xdg_toplevel_interface { + /** + * destroy the xdg_toplevel + * + * This request destroys the role surface and unmaps the surface; + * see "Unmapping" behavior in interface section for details. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the parent of this surface + * + * Set the "parent" of this surface. This surface should be + * stacked above the parent surface and all other ancestor + * surfaces. + * + * Parent surfaces should be set on dialogs, toolboxes, or other + * "auxiliary" surfaces, so that the parent is raised when the + * dialog is raised. + * + * Setting a null parent for a child surface unsets its parent. + * Setting a null parent for a surface which currently has no + * parent is a no-op. + * + * Only mapped surfaces can have child surfaces. Setting a parent + * which is not mapped is equivalent to setting a null parent. If a + * surface becomes unmapped, its children's parent is set to the + * parent of the now-unmapped surface. If the now-unmapped surface + * has no parent, its children's parent is unset. If the + * now-unmapped surface becomes mapped again, its parent-child + * relationship is not restored. + * + * The parent toplevel must not be one of the child toplevel's + * descendants, and the parent must be different from the child + * toplevel, otherwise the invalid_parent protocol error is raised. + */ + void (*set_parent)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *parent); + /** + * set surface title + * + * Set a short title for the surface. + * + * This string may be used to identify the surface in a task bar, + * window list, or other user interface elements provided by the + * compositor. + * + * The string must be encoded in UTF-8. + */ + void (*set_title)(struct wl_client *client, + struct wl_resource *resource, + const char *title); + /** + * set application ID + * + * Set an application identifier for the surface. + * + * The app ID identifies the general class of applications to which + * the surface belongs. The compositor can use this to group + * multiple surfaces together, or to determine how to launch a new + * application. + * + * For D-Bus activatable applications, the app ID is used as the + * D-Bus service name. + * + * The compositor shell will try to group application surfaces + * together by their app ID. As a best practice, it is suggested to + * select app ID's that match the basename of the application's + * .desktop file. For example, "org.freedesktop.FooViewer" where + * the .desktop file is "org.freedesktop.FooViewer.desktop". + * + * Like other properties, a set_app_id request can be sent after + * the xdg_toplevel has been mapped to update the property. + * + * See the desktop-entry specification [0] for more details on + * application identifiers and how they relate to well-known D-Bus + * names and .desktop files. + * + * [0] https://standards.freedesktop.org/desktop-entry-spec/ + */ + void (*set_app_id)(struct wl_client *client, + struct wl_resource *resource, + const char *app_id); + /** + * show the window menu + * + * Clients implementing client-side decorations might want to + * show a context menu when right-clicking on the decorations, + * giving the user a menu that they can use to maximize or minimize + * the window. + * + * This request asks the compositor to pop up such a window menu at + * the given position, relative to the local surface coordinates of + * the parent surface. There are no guarantees as to what menu + * items the window menu contains, or even if a window menu will be + * drawn at all. + * + * This request must be used in response to some sort of user + * action like a button press, key press, or touch down event. + * @param seat the wl_seat of the user event + * @param serial the serial of the user event + * @param x the x position to pop up the window menu at + * @param y the y position to pop up the window menu at + */ + void (*show_window_menu)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial, + int32_t x, + int32_t y); + /** + * start an interactive move + * + * Start an interactive, user-driven move of the surface. + * + * This request must be used in response to some sort of user + * action like a button press, key press, or touch down event. The + * passed serial is used to determine the type of interactive move + * (touch, pointer, etc). + * + * The server may ignore move requests depending on the state of + * the surface (e.g. fullscreen or maximized), or if the passed + * serial is no longer valid. + * + * If triggered, the surface will lose the focus of the device + * (wl_pointer, wl_touch, etc) used for the move. It is up to the + * compositor to visually indicate that the move is taking place, + * such as updating a pointer cursor, during the move. There is no + * guarantee that the device focus will return when the move is + * completed. + * @param seat the wl_seat of the user event + * @param serial the serial of the user event + */ + void (*move)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial); + /** + * start an interactive resize + * + * Start a user-driven, interactive resize of the surface. + * + * This request must be used in response to some sort of user + * action like a button press, key press, or touch down event. The + * passed serial is used to determine the type of interactive + * resize (touch, pointer, etc). + * + * The server may ignore resize requests depending on the state of + * the surface (e.g. fullscreen or maximized). + * + * If triggered, the client will receive configure events with the + * "resize" state enum value and the expected sizes. See the + * "resize" enum value for more details about what is required. The + * client must also acknowledge configure events using + * "ack_configure". After the resize is completed, the client will + * receive another "configure" event without the resize state. + * + * If triggered, the surface also will lose the focus of the device + * (wl_pointer, wl_touch, etc) used for the resize. It is up to the + * compositor to visually indicate that the resize is taking place, + * such as updating a pointer cursor, during the resize. There is + * no guarantee that the device focus will return when the resize + * is completed. + * + * The edges parameter specifies how the surface should be resized, + * and is one of the values of the resize_edge enum. Values not + * matching a variant of the enum will cause a protocol error. The + * compositor may use this information to update the surface + * position for example when dragging the top left corner. The + * compositor may also use this information to adapt its behavior, + * e.g. choose an appropriate cursor image. + * @param seat the wl_seat of the user event + * @param serial the serial of the user event + * @param edges which edge or corner is being dragged + */ + void (*resize)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial, + uint32_t edges); + /** + * set the maximum size + * + * Set a maximum size for the window. + * + * The client can specify a maximum size so that the compositor + * does not try to configure the window beyond this size. + * + * The width and height arguments are in window geometry + * coordinates. See xdg_surface.set_window_geometry. + * + * Values set in this way are double-buffered. They will get + * applied on the next commit. + * + * The compositor can use this information to allow or disallow + * different states like maximize or fullscreen and draw accurate + * animations. + * + * Similarly, a tiling window manager may use this information to + * place and resize client windows in a more effective way. + * + * The client should not rely on the compositor to obey the maximum + * size. The compositor may decide to ignore the values set by the + * client and request a larger size. + * + * If never set, or a value of zero in the request, means that the + * client has no expected maximum size in the given dimension. As a + * result, a client wishing to reset the maximum size to an + * unspecified state can use zero for width and height in the + * request. + * + * Requesting a maximum size to be smaller than the minimum size of + * a surface is illegal and will result in an invalid_size error. + * + * The width and height must be greater than or equal to zero. + * Using strictly negative values for width or height will result + * in a invalid_size error. + */ + void (*set_max_size)(struct wl_client *client, + struct wl_resource *resource, + int32_t width, + int32_t height); + /** + * set the minimum size + * + * Set a minimum size for the window. + * + * The client can specify a minimum size so that the compositor + * does not try to configure the window below this size. + * + * The width and height arguments are in window geometry + * coordinates. See xdg_surface.set_window_geometry. + * + * Values set in this way are double-buffered. They will get + * applied on the next commit. + * + * The compositor can use this information to allow or disallow + * different states like maximize or fullscreen and draw accurate + * animations. + * + * Similarly, a tiling window manager may use this information to + * place and resize client windows in a more effective way. + * + * The client should not rely on the compositor to obey the minimum + * size. The compositor may decide to ignore the values set by the + * client and request a smaller size. + * + * If never set, or a value of zero in the request, means that the + * client has no expected minimum size in the given dimension. As a + * result, a client wishing to reset the minimum size to an + * unspecified state can use zero for width and height in the + * request. + * + * Requesting a minimum size to be larger than the maximum size of + * a surface is illegal and will result in an invalid_size error. + * + * The width and height must be greater than or equal to zero. + * Using strictly negative values for width and height will result + * in a invalid_size error. + */ + void (*set_min_size)(struct wl_client *client, + struct wl_resource *resource, + int32_t width, + int32_t height); + /** + * maximize the window + * + * Maximize the surface. + * + * After requesting that the surface should be maximized, the + * compositor will respond by emitting a configure event. Whether + * this configure actually sets the window maximized is subject to + * compositor policies. The client must then update its content, + * drawing in the configured state. The client must also + * acknowledge the configure when committing the new content (see + * ack_configure). + * + * It is up to the compositor to decide how and where to maximize + * the surface, for example which output and what region of the + * screen should be used. + * + * If the surface was already maximized, the compositor will still + * emit a configure event with the "maximized" state. + * + * If the surface is in a fullscreen state, this request has no + * direct effect. It may alter the state the surface is returned to + * when unmaximized unless overridden by the compositor. + */ + void (*set_maximized)(struct wl_client *client, + struct wl_resource *resource); + /** + * unmaximize the window + * + * Unmaximize the surface. + * + * After requesting that the surface should be unmaximized, the + * compositor will respond by emitting a configure event. Whether + * this actually un-maximizes the window is subject to compositor + * policies. If available and applicable, the compositor will + * include the window geometry dimensions the window had prior to + * being maximized in the configure event. The client must then + * update its content, drawing it in the configured state. The + * client must also acknowledge the configure when committing the + * new content (see ack_configure). + * + * It is up to the compositor to position the surface after it was + * unmaximized; usually the position the surface had before + * maximizing, if applicable. + * + * If the surface was already not maximized, the compositor will + * still emit a configure event without the "maximized" state. + * + * If the surface is in a fullscreen state, this request has no + * direct effect. It may alter the state the surface is returned to + * when unmaximized unless overridden by the compositor. + */ + void (*unset_maximized)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the window as fullscreen on an output + * + * Make the surface fullscreen. + * + * After requesting that the surface should be fullscreened, the + * compositor will respond by emitting a configure event. Whether + * the client is actually put into a fullscreen state is subject to + * compositor policies. The client must also acknowledge the + * configure when committing the new content (see ack_configure). + * + * The output passed by the request indicates the client's + * preference as to which display it should be set fullscreen on. + * If this value is NULL, it's up to the compositor to choose which + * display will be used to map this surface. + * + * If the surface doesn't cover the whole output, the compositor + * will position the surface in the center of the output and + * compensate with with border fill covering the rest of the + * output. The content of the border fill is undefined, but should + * be assumed to be in some way that attempts to blend into the + * surrounding area (e.g. solid black). + * + * If the fullscreened surface is not opaque, the compositor must + * make sure that other screen content not part of the same surface + * tree (made up of subsurfaces, popups or similarly coupled + * surfaces) are not visible below the fullscreened surface. + */ + void (*set_fullscreen)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *output); + /** + * unset the window as fullscreen + * + * Make the surface no longer fullscreen. + * + * After requesting that the surface should be unfullscreened, the + * compositor will respond by emitting a configure event. Whether + * this actually removes the fullscreen state of the client is + * subject to compositor policies. + * + * Making a surface unfullscreen sets states for the surface based + * on the following: * the state(s) it may have had before becoming + * fullscreen * any state(s) decided by the compositor * any + * state(s) requested by the client while the surface was + * fullscreen + * + * The compositor may include the previous window geometry + * dimensions in the configure event, if applicable. + * + * The client must also acknowledge the configure when committing + * the new content (see ack_configure). + */ + void (*unset_fullscreen)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the window as minimized + * + * Request that the compositor minimize your surface. There is no + * way to know if the surface is currently minimized, nor is there + * any way to unset minimization on this surface. + * + * If you are looking to throttle redrawing when minimized, please + * instead use the wl_surface.frame event for this, as this will + * also work with live previews on windows in Alt-Tab, Expose or + * similar compositor features. + */ + void (*set_minimized)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define XDG_TOPLEVEL_CONFIGURE 0 +#define XDG_TOPLEVEL_CLOSE 1 +#define XDG_TOPLEVEL_CONFIGURE_BOUNDS 2 +#define XDG_TOPLEVEL_WM_CAPABILITIES 3 + +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CONFIGURE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CLOSE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION 4 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION 5 + +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_PARENT_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_TITLE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_APP_ID_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SHOW_WINDOW_MENU_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_MOVE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_RESIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MAX_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MIN_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_UNSET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_FULLSCREEN_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_UNSET_FULLSCREEN_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel + */ +#define XDG_TOPLEVEL_SET_MINIMIZED_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_toplevel + * Sends an configure event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +xdg_toplevel_send_configure(struct wl_resource *resource_, int32_t width, int32_t height, struct wl_array *states) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_CONFIGURE, width, height, states); +} + +/** + * @ingroup iface_xdg_toplevel + * Sends an close event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +xdg_toplevel_send_close(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_CLOSE); +} + +/** + * @ingroup iface_xdg_toplevel + * Sends an configure_bounds event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +xdg_toplevel_send_configure_bounds(struct wl_resource *resource_, int32_t width, int32_t height) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_CONFIGURE_BOUNDS, width, height); +} + +/** + * @ingroup iface_xdg_toplevel + * Sends an wm_capabilities event to the client owning the resource. + * @param resource_ The client's resource + * @param capabilities array of 32-bit capabilities + */ +static inline void +xdg_toplevel_send_wm_capabilities(struct wl_resource *resource_, struct wl_array *capabilities) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_WM_CAPABILITIES, capabilities); +} + +#ifndef XDG_POPUP_ERROR_ENUM +#define XDG_POPUP_ERROR_ENUM +enum xdg_popup_error { + /** + * tried to grab after being mapped + */ + XDG_POPUP_ERROR_INVALID_GRAB = 0, +}; +#endif /* XDG_POPUP_ERROR_ENUM */ + +#ifndef XDG_POPUP_ERROR_ENUM_IS_VALID +#define XDG_POPUP_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_popup + * Validate a xdg_popup error value. + * + * @return true on success, false on error. + * @ref xdg_popup_error + */ +static inline bool +xdg_popup_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_POPUP_ERROR_INVALID_GRAB: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_POPUP_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_popup + * @struct xdg_popup_interface + */ +struct xdg_popup_interface { + /** + * remove xdg_popup interface + * + * This destroys the popup. Explicitly destroying the xdg_popup + * object will also dismiss the popup, and unmap the surface. + * + * If this xdg_popup is not the "topmost" popup, a protocol error + * will be sent. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * make the popup take an explicit grab + * + * This request makes the created popup take an explicit grab. An + * explicit grab will be dismissed when the user dismisses the + * popup, or when the client destroys the xdg_popup. This can be + * done by the user clicking outside the surface, using the + * keyboard, or even locking the screen through closing the lid or + * a timeout. + * + * If the compositor denies the grab, the popup will be immediately + * dismissed. + * + * This request must be used in response to some sort of user + * action like a button press, key press, or touch down event. The + * serial number of the event should be passed as 'serial'. + * + * The parent of a grabbing popup must either be an xdg_toplevel + * surface or another xdg_popup with an explicit grab. If the + * parent is another xdg_popup it means that the popups are nested, + * with this popup now being the topmost popup. + * + * Nested popups must be destroyed in the reverse order they were + * created in, e.g. the only popup you are allowed to destroy at + * all times is the topmost one. + * + * When compositors choose to dismiss a popup, they may dismiss + * every nested grabbing popup as well. When a compositor dismisses + * popups, it will follow the same dismissing order as required + * from the client. + * + * If the topmost grabbing popup is destroyed, the grab will be + * returned to the parent of the popup, if that parent previously + * had an explicit grab. + * + * If the parent is a grabbing popup which has already been + * dismissed, this popup will be immediately dismissed. If the + * parent is a popup that did not take an explicit grab, an error + * will be raised. + * + * During a popup grab, the client owning the grab will receive + * pointer and touch events for all their surfaces as normal + * (similar to an "owner-events" grab in X11 parlance), while the + * top most grabbing popup will always have keyboard focus. + * @param seat the wl_seat of the user event + * @param serial the serial of the user event + */ + void (*grab)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial); + /** + * recalculate the popup's location + * + * Reposition an already-mapped popup. The popup will be placed + * given the details in the passed xdg_positioner object, and a + * xdg_popup.repositioned followed by xdg_popup.configure and + * xdg_surface.configure will be emitted in response. Any + * parameters set by the previous positioner will be discarded. + * + * The passed token will be sent in the corresponding + * xdg_popup.repositioned event. The new popup position will not + * take effect until the corresponding configure event is + * acknowledged by the client. See xdg_popup.repositioned for + * details. The token itself is opaque, and has no other special + * meaning. + * + * If multiple reposition requests are sent, the compositor may + * skip all but the last one. + * + * If the popup is repositioned in response to a configure event + * for its parent, the client should send an + * xdg_positioner.set_parent_configure and possibly an + * xdg_positioner.set_parent_size request to allow the compositor + * to properly constrain the popup. + * + * If the popup is repositioned together with a parent that is + * being resized, but not in response to a configure event, the + * client should send an xdg_positioner.set_parent_size request. + * @param token reposition request token + * @since 3 + */ + void (*reposition)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *positioner, + uint32_t token); +}; + +#define XDG_POPUP_CONFIGURE 0 +#define XDG_POPUP_POPUP_DONE 1 +#define XDG_POPUP_REPOSITIONED 2 + +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_CONFIGURE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_POPUP_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_REPOSITIONED_SINCE_VERSION 3 + +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_GRAB_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_popup + */ +#define XDG_POPUP_REPOSITION_SINCE_VERSION 3 + +/** + * @ingroup iface_xdg_popup + * Sends an configure event to the client owning the resource. + * @param resource_ The client's resource + * @param x x position relative to parent surface window geometry + * @param y y position relative to parent surface window geometry + * @param width window geometry width + * @param height window geometry height + */ +static inline void +xdg_popup_send_configure(struct wl_resource *resource_, int32_t x, int32_t y, int32_t width, int32_t height) +{ + wl_resource_post_event(resource_, XDG_POPUP_CONFIGURE, x, y, width, height); +} + +/** + * @ingroup iface_xdg_popup + * Sends an popup_done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +xdg_popup_send_popup_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, XDG_POPUP_POPUP_DONE); +} + +/** + * @ingroup iface_xdg_popup + * Sends an repositioned event to the client owning the resource. + * @param resource_ The client's resource + * @param token reposition request token + */ +static inline void +xdg_popup_send_repositioned(struct wl_resource *resource_, uint32_t token) +{ + wl_resource_post_event(resource_, XDG_POPUP_REPOSITIONED, token); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-protocol.c b/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-protocol.c new file mode 100644 index 0000000000..73d39d207a --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-protocol.c @@ -0,0 +1,83 @@ +/* Generated by wayland-scanner 1.24.0 */ + +/* + * Copyright © 2023-2024 Matthias Klumpp + * Copyright © 2024 David Edmundson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include <stdbool.h> +#include <stdlib.h> +#include <stdint.h> +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_buffer_interface; +extern const struct wl_interface xdg_toplevel_interface; +extern const struct wl_interface xdg_toplevel_icon_v1_interface; + +static const struct wl_interface *xdg_toplevel_icon_v1_types[] = { + NULL, + &xdg_toplevel_icon_v1_interface, + &xdg_toplevel_interface, + &xdg_toplevel_icon_v1_interface, + &wl_buffer_interface, + NULL, +}; + +static const struct wl_message xdg_toplevel_icon_manager_v1_requests[] = { + { "destroy", "", xdg_toplevel_icon_v1_types + 0 }, + { "create_icon", "n", xdg_toplevel_icon_v1_types + 1 }, + { "set_icon", "o?o", xdg_toplevel_icon_v1_types + 2 }, +}; + +static const struct wl_message xdg_toplevel_icon_manager_v1_events[] = { + { "icon_size", "i", xdg_toplevel_icon_v1_types + 0 }, + { "done", "", xdg_toplevel_icon_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface xdg_toplevel_icon_manager_v1_interface = { + "xdg_toplevel_icon_manager_v1", 1, + 3, xdg_toplevel_icon_manager_v1_requests, + 2, xdg_toplevel_icon_manager_v1_events, +}; + +static const struct wl_message xdg_toplevel_icon_v1_requests[] = { + { "destroy", "", xdg_toplevel_icon_v1_types + 0 }, + { "set_name", "s", xdg_toplevel_icon_v1_types + 0 }, + { "add_buffer", "oi", xdg_toplevel_icon_v1_types + 4 }, +}; + +WL_PRIVATE const struct wl_interface xdg_toplevel_icon_v1_interface = { + "xdg_toplevel_icon_v1", 1, + 3, xdg_toplevel_icon_v1_requests, + 0, NULL, +}; + diff --git a/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-server-protocol.h b/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-server-protocol.h new file mode 100644 index 0000000000..b186d88975 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/generated/xdg-toplevel-icon-v1-server-protocol.h @@ -0,0 +1,362 @@ +/* Generated by wayland-scanner 1.24.0 */ + +#ifndef XDG_TOPLEVEL_ICON_V1_SERVER_PROTOCOL_H +#define XDG_TOPLEVEL_ICON_V1_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_xdg_toplevel_icon_v1 The xdg_toplevel_icon_v1 protocol + * protocol to assign icons to toplevels + * + * @section page_desc_xdg_toplevel_icon_v1 Description + * + * This protocol allows clients to set icons for their toplevel surfaces + * either via the XDG icon stock (using an icon name), or from pixel data. + * + * A toplevel icon represents the individual toplevel (unlike the application + * or launcher icon, which represents the application as a whole), and may be + * shown in window switchers, window overviews and taskbars that list + * individual windows. + * + * This document adheres to RFC 2119 when using words like "must", + * "should", "may", etc. + * + * Warning! The protocol described in this file is currently in the testing + * phase. Backward compatible changes may be added together with the + * corresponding interface version bump. Backward incompatible changes can + * only be done by creating a new major version of the extension. + * + * @section page_ifaces_xdg_toplevel_icon_v1 Interfaces + * - @subpage page_iface_xdg_toplevel_icon_manager_v1 - interface to manage toplevel icons + * - @subpage page_iface_xdg_toplevel_icon_v1 - a toplevel window icon + * @section page_copyright_xdg_toplevel_icon_v1 Copyright + * <pre> + * + * Copyright © 2023-2024 Matthias Klumpp + * Copyright © 2024 David Edmundson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * </pre> + */ +struct wl_buffer; +struct xdg_toplevel; +struct xdg_toplevel_icon_manager_v1; +struct xdg_toplevel_icon_v1; + +#ifndef XDG_TOPLEVEL_ICON_MANAGER_V1_INTERFACE +#define XDG_TOPLEVEL_ICON_MANAGER_V1_INTERFACE +/** + * @page page_iface_xdg_toplevel_icon_manager_v1 xdg_toplevel_icon_manager_v1 + * @section page_iface_xdg_toplevel_icon_manager_v1_desc Description + * + * This interface allows clients to create toplevel window icons and set + * them on toplevel windows to be displayed to the user. + * @section page_iface_xdg_toplevel_icon_manager_v1_api API + * See @ref iface_xdg_toplevel_icon_manager_v1. + */ +/** + * @defgroup iface_xdg_toplevel_icon_manager_v1 The xdg_toplevel_icon_manager_v1 interface + * + * This interface allows clients to create toplevel window icons and set + * them on toplevel windows to be displayed to the user. + */ +extern const struct wl_interface xdg_toplevel_icon_manager_v1_interface; +#endif +#ifndef XDG_TOPLEVEL_ICON_V1_INTERFACE +#define XDG_TOPLEVEL_ICON_V1_INTERFACE +/** + * @page page_iface_xdg_toplevel_icon_v1 xdg_toplevel_icon_v1 + * @section page_iface_xdg_toplevel_icon_v1_desc Description + * + * This interface defines a toplevel icon. + * An icon can have a name, and multiple buffers. + * In order to be applied, the icon must have either a name, or at least + * one buffer assigned. Applying an empty icon (with no buffer or name) to + * a toplevel should reset its icon to the default icon. + * + * It is up to compositor policy whether to prefer using a buffer or loading + * an icon via its name. See 'set_name' and 'add_buffer' for details. + * @section page_iface_xdg_toplevel_icon_v1_api API + * See @ref iface_xdg_toplevel_icon_v1. + */ +/** + * @defgroup iface_xdg_toplevel_icon_v1 The xdg_toplevel_icon_v1 interface + * + * This interface defines a toplevel icon. + * An icon can have a name, and multiple buffers. + * In order to be applied, the icon must have either a name, or at least + * one buffer assigned. Applying an empty icon (with no buffer or name) to + * a toplevel should reset its icon to the default icon. + * + * It is up to compositor policy whether to prefer using a buffer or loading + * an icon via its name. See 'set_name' and 'add_buffer' for details. + */ +extern const struct wl_interface xdg_toplevel_icon_v1_interface; +#endif + +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + * @struct xdg_toplevel_icon_manager_v1_interface + */ +struct xdg_toplevel_icon_manager_v1_interface { + /** + * destroy the toplevel icon manager + * + * Destroy the toplevel icon manager. This does not destroy + * objects created with the manager. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * create a new icon instance + * + * Creates a new icon object. This icon can then be attached to a + * xdg_toplevel via the 'set_icon' request. + */ + void (*create_icon)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * set an icon on a toplevel window + * + * This request assigns the icon 'icon' to 'toplevel', or clears + * the toplevel icon if 'icon' was null. This state is + * double-buffered and is applied on the next wl_surface.commit of + * the toplevel. + * + * After making this call, the xdg_toplevel_icon_v1 provided as + * 'icon' can be destroyed by the client without 'toplevel' losing + * its icon. The xdg_toplevel_icon_v1 is immutable from this point, + * and any future attempts to change it must raise the + * 'xdg_toplevel_icon_v1.immutable' protocol error. + * + * The compositor must set the toplevel icon from either the pixel + * data the icon provides, or by loading a stock icon using the + * icon name. See the description of 'xdg_toplevel_icon_v1' for + * details. + * + * If 'icon' is set to null, the icon of the respective toplevel is + * reset to its default icon (usually the icon of the application, + * derived from its desktop-entry file, or a placeholder icon). If + * this request is passed an icon with no pixel buffers or icon + * name assigned, the icon must be reset just like if 'icon' was + * null. + * @param toplevel the toplevel to act on + */ + void (*set_icon)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *toplevel, + struct wl_resource *icon); +}; + +#define XDG_TOPLEVEL_ICON_MANAGER_V1_ICON_SIZE 0 +#define XDG_TOPLEVEL_ICON_MANAGER_V1_DONE 1 + +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + */ +#define XDG_TOPLEVEL_ICON_MANAGER_V1_ICON_SIZE_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + */ +#define XDG_TOPLEVEL_ICON_MANAGER_V1_DONE_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + */ +#define XDG_TOPLEVEL_ICON_MANAGER_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + */ +#define XDG_TOPLEVEL_ICON_MANAGER_V1_CREATE_ICON_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + */ +#define XDG_TOPLEVEL_ICON_MANAGER_V1_SET_ICON_SINCE_VERSION 1 + +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + * Sends an icon_size event to the client owning the resource. + * @param resource_ The client's resource + * @param size the edge size of the square icon in surface-local coordinates, e.g. 64 + */ +static inline void +xdg_toplevel_icon_manager_v1_send_icon_size(struct wl_resource *resource_, int32_t size) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_ICON_MANAGER_V1_ICON_SIZE, size); +} + +/** + * @ingroup iface_xdg_toplevel_icon_manager_v1 + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +xdg_toplevel_icon_manager_v1_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, XDG_TOPLEVEL_ICON_MANAGER_V1_DONE); +} + +#ifndef XDG_TOPLEVEL_ICON_V1_ERROR_ENUM +#define XDG_TOPLEVEL_ICON_V1_ERROR_ENUM +enum xdg_toplevel_icon_v1_error { + /** + * the provided buffer does not satisfy requirements + */ + XDG_TOPLEVEL_ICON_V1_ERROR_INVALID_BUFFER = 1, + /** + * the icon has already been assigned to a toplevel and must not be changed + */ + XDG_TOPLEVEL_ICON_V1_ERROR_IMMUTABLE = 2, + /** + * the provided buffer has been destroyed before the toplevel icon + */ + XDG_TOPLEVEL_ICON_V1_ERROR_NO_BUFFER = 3, +}; +#endif /* XDG_TOPLEVEL_ICON_V1_ERROR_ENUM */ + +#ifndef XDG_TOPLEVEL_ICON_V1_ERROR_ENUM_IS_VALID +#define XDG_TOPLEVEL_ICON_V1_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_xdg_toplevel_icon_v1 + * Validate a xdg_toplevel_icon_v1 error value. + * + * @return true on success, false on error. + * @ref xdg_toplevel_icon_v1_error + */ +static inline bool +xdg_toplevel_icon_v1_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case XDG_TOPLEVEL_ICON_V1_ERROR_INVALID_BUFFER: + return version >= 1; + case XDG_TOPLEVEL_ICON_V1_ERROR_IMMUTABLE: + return version >= 1; + case XDG_TOPLEVEL_ICON_V1_ERROR_NO_BUFFER: + return version >= 1; + default: + return false; + } +} +#endif /* XDG_TOPLEVEL_ICON_V1_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_xdg_toplevel_icon_v1 + * @struct xdg_toplevel_icon_v1_interface + */ +struct xdg_toplevel_icon_v1_interface { + /** + * destroy the icon object + * + * Destroys the 'xdg_toplevel_icon_v1' object. The icon must + * still remain set on every toplevel it was assigned to, until the + * toplevel icon is reset explicitly. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set an icon name + * + * This request assigns an icon name to this icon. Any previously + * set name is overridden. + * + * The compositor must resolve 'icon_name' according to the lookup + * rules described in the XDG icon theme specification[1] using the + * environment's current icon theme. + * + * If the compositor does not support icon names or cannot resolve + * 'icon_name' according to the XDG icon theme specification it + * must fall back to using pixel buffer data instead. + * + * If this request is made after the icon has been assigned to a + * toplevel via 'set_icon', an 'immutable' error must be raised. + * + * [1]: + * https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html + */ + void (*set_name)(struct wl_client *client, + struct wl_resource *resource, + const char *icon_name); + /** + * add icon data from a pixel buffer + * + * This request adds pixel data supplied as wl_buffer to the + * icon. + * + * The client should add pixel data for all icon sizes and scales + * that it can provide, or which are explicitly requested by the + * compositor via 'icon_size' events on + * xdg_toplevel_icon_manager_v1. + * + * The wl_buffer supplying pixel data as 'buffer' must be backed by + * wl_shm and must be a square (width and height being equal). If + * any of these buffer requirements are not fulfilled, a + * 'invalid_buffer' error must be raised. + * + * If this icon instance already has a buffer of the same size and + * scale from a previous 'add_buffer' request, data from the last + * request overrides the preexisting pixel data. + * + * The wl_buffer must be kept alive for as long as the + * xdg_toplevel_icon it is associated with is not destroyed, + * otherwise a 'no_buffer' error is raised. The buffer contents + * must not be modified after it was assigned to the icon. As a + * result, the region of the wl_shm_pool's backing storage used for + * the wl_buffer must not be modified after this request is sent. + * The wl_buffer.release event is unused. + * + * If this request is made after the icon has been assigned to a + * toplevel via 'set_icon', an 'immutable' error must be raised. + * @param scale the scaling factor of the icon, e.g. 1 + */ + void (*add_buffer)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *buffer, + int32_t scale); +}; + + +/** + * @ingroup iface_xdg_toplevel_icon_v1 + */ +#define XDG_TOPLEVEL_ICON_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel_icon_v1 + */ +#define XDG_TOPLEVEL_ICON_V1_SET_NAME_SINCE_VERSION 1 +/** + * @ingroup iface_xdg_toplevel_icon_v1 + */ +#define XDG_TOPLEVEL_ICON_V1_ADD_BUFFER_SINCE_VERSION 1 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-core.h b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-core.h new file mode 100644 index 0000000000..757f6a1f1e --- /dev/null +++ b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-core.h @@ -0,0 +1,747 @@ +/* + * Copyright © 2008 Kristian Høgsberg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef WAYLAND_SERVER_CORE_H +#define WAYLAND_SERVER_CORE_H + +#include <sys/types.h> +#include <stdint.h> +#include <stdbool.h> +#include "wayland-util.h" +#include "wayland-version.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + WL_EVENT_READABLE = 0x01, + WL_EVENT_WRITABLE = 0x02, + WL_EVENT_HANGUP = 0x04, + WL_EVENT_ERROR = 0x08 +}; + +/** File descriptor dispatch function type + * + * Functions of this type are used as callbacks for file descriptor events. + * + * \param fd The file descriptor delivering the event. + * \param mask Describes the kind of the event as a bitwise-or of: + * \c WL_EVENT_READABLE, \c WL_EVENT_WRITABLE, \c WL_EVENT_HANGUP, + * \c WL_EVENT_ERROR. + * \param data The user data argument of the related wl_event_loop_add_fd() + * call. + * \return If the event source is registered for re-check with + * wl_event_source_check(): 0 for all done, 1 for needing a re-check. + * If not registered, the return value is ignored and should be zero. + * + * \sa wl_event_loop_add_fd() + * \memberof wl_event_source + */ +typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data); + +/** Timer dispatch function type + * + * Functions of this type are used as callbacks for timer expiry. + * + * \param data The user data argument of the related wl_event_loop_add_timer() + * call. + * \return If the event source is registered for re-check with + * wl_event_source_check(): 0 for all done, 1 for needing a re-check. + * If not registered, the return value is ignored and should be zero. + * + * \sa wl_event_loop_add_timer() + * \memberof wl_event_source + */ +typedef int (*wl_event_loop_timer_func_t)(void *data); + +/** Signal dispatch function type + * + * Functions of this type are used as callbacks for (POSIX) signals. + * + * \param signal_number + * \param data The user data argument of the related wl_event_loop_add_signal() + * call. + * \return If the event source is registered for re-check with + * wl_event_source_check(): 0 for all done, 1 for needing a re-check. + * If not registered, the return value is ignored and should be zero. + * + * \sa wl_event_loop_add_signal() + * \memberof wl_event_source + */ +typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data); + +/** Idle task function type + * + * Functions of this type are used as callbacks before blocking in + * wl_event_loop_dispatch(). + * + * \param data The user data argument of the related wl_event_loop_add_idle() + * call. + * + * \sa wl_event_loop_add_idle() wl_event_loop_dispatch() + * \memberof wl_event_source + */ +typedef void (*wl_event_loop_idle_func_t)(void *data); + +/** \struct wl_event_loop + * + * \brief An event loop context + * + * Usually you create an event loop context, add sources to it, and call + * wl_event_loop_dispatch() in a loop to process events. + * + * \sa wl_event_source + */ + +/** \struct wl_event_source + * + * \brief An abstract event source + * + * This is the generic type for fd, timer, signal, and idle sources. + * Functions that operate on specific source types must not be used with + * a different type, even if the function signature allows it. + */ + +struct wl_event_loop * +wl_event_loop_create(void); + +void +wl_event_loop_destroy(struct wl_event_loop *loop); + +struct wl_event_source * +wl_event_loop_add_fd(struct wl_event_loop *loop, + int fd, uint32_t mask, + wl_event_loop_fd_func_t func, + void *data); + +int +wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask); + +struct wl_event_source * +wl_event_loop_add_timer(struct wl_event_loop *loop, + wl_event_loop_timer_func_t func, + void *data); + +struct wl_event_source * +wl_event_loop_add_signal(struct wl_event_loop *loop, + int signal_number, + wl_event_loop_signal_func_t func, + void *data); + +int +wl_event_source_timer_update(struct wl_event_source *source, + int ms_delay); + +int +wl_event_source_remove(struct wl_event_source *source); + +void +wl_event_source_check(struct wl_event_source *source); + +int +wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout); + +void +wl_event_loop_dispatch_idle(struct wl_event_loop *loop); + +struct wl_event_source * +wl_event_loop_add_idle(struct wl_event_loop *loop, + wl_event_loop_idle_func_t func, + void *data); + +int +wl_event_loop_get_fd(struct wl_event_loop *loop); + +struct wl_listener; + +typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data); + +void +wl_event_loop_add_destroy_listener(struct wl_event_loop *loop, + struct wl_listener *listener); + +struct wl_listener * +wl_event_loop_get_destroy_listener(struct wl_event_loop *loop, + wl_notify_func_t notify); + +struct wl_display * +wl_display_create(void); + +void +wl_display_destroy(struct wl_display *display); + +struct wl_event_loop * +wl_display_get_event_loop(struct wl_display *display); + +int +wl_display_add_socket(struct wl_display *display, const char *name); + +const char * +wl_display_add_socket_auto(struct wl_display *display); + +int +wl_display_add_socket_fd(struct wl_display *display, int sock_fd); + +int +wl_display_remove_socket_fd(struct wl_display *display, int sock_fd); + +void +wl_display_terminate(struct wl_display *display); + +void +wl_display_run(struct wl_display *display); + +void +wl_display_flush_clients(struct wl_display *display); + +void +wl_display_destroy_clients(struct wl_display *display); + +void +wl_display_set_default_max_buffer_size(struct wl_display *display, + size_t max_buffer_size); + +struct wl_client; +struct wl_global; + +typedef void (*wl_global_bind_func_t)(struct wl_client *client, void *data, + uint32_t version, uint32_t id); + +typedef void (*wl_global_withdrawn_func_t)(struct wl_global *global); + +uint32_t +wl_display_get_serial(const struct wl_display *display); + +uint32_t +wl_display_next_serial(struct wl_display *display); + +void +wl_display_add_destroy_listener(struct wl_display *display, + struct wl_listener *listener); + +void +wl_display_add_client_created_listener(struct wl_display *display, + struct wl_listener *listener); + +struct wl_listener * +wl_display_get_destroy_listener(struct wl_display *display, + wl_notify_func_t notify); + +struct wl_global * +wl_global_create(struct wl_display *display, + const struct wl_interface *interface, + int version, + void *data, wl_global_bind_func_t bind); + +void +wl_global_remove(struct wl_global *global); + +void +wl_global_set_withdrawn_listener(struct wl_global *global, + wl_global_withdrawn_func_t func); + +void +wl_global_destroy(struct wl_global *global); + +/** A filter function for wl_global objects + * + * \param client The client object + * \param global The global object to show or hide + * \param data The user data pointer + * + * A filter function enables the server to decide which globals to + * advertise to each client. + * + * When a wl_global filter is set, the given callback function will be + * called during wl_global advertisement and binding. + * + * This function should return true if the global object should be made + * visible to the client or false otherwise. + */ +typedef bool (*wl_display_global_filter_func_t)(const struct wl_client *client, + const struct wl_global *global, + void *data); + +void +wl_display_set_global_filter(struct wl_display *display, + wl_display_global_filter_func_t filter, + void *data); + +const struct wl_interface * +wl_global_get_interface(const struct wl_global *global); + +uint32_t +wl_global_get_name(const struct wl_global *global, + const struct wl_client *client); + +uint32_t +wl_global_get_version(const struct wl_global *global); + +struct wl_display * +wl_global_get_display(const struct wl_global *global); + +void * +wl_global_get_user_data(const struct wl_global *global); + +void +wl_global_set_user_data(struct wl_global *global, void *data); + +struct wl_client * +wl_client_create(struct wl_display *display, int fd); + +struct wl_list * +wl_display_get_client_list(struct wl_display *display); + +struct wl_list * +wl_client_get_link(struct wl_client *client); + +struct wl_client * +wl_client_from_link(struct wl_list *link); + +/** Iterate over a list of clients. */ +#define wl_client_for_each(client, list) \ + for (client = wl_client_from_link((list)->next); \ + wl_client_get_link(client) != (list); \ + client = wl_client_from_link(wl_client_get_link(client)->next)) + +void +wl_client_destroy(struct wl_client *client); + +void +wl_client_flush(struct wl_client *client); + +void +wl_client_get_credentials(const struct wl_client *client, + pid_t *pid, uid_t *uid, gid_t *gid); + +int +wl_client_get_fd(struct wl_client *client); + +void +wl_client_add_destroy_listener(struct wl_client *client, + struct wl_listener *listener); + +struct wl_listener * +wl_client_get_destroy_listener(struct wl_client *client, + wl_notify_func_t notify); + +void +wl_client_add_destroy_late_listener(struct wl_client *client, + struct wl_listener *listener); + +struct wl_listener * +wl_client_get_destroy_late_listener(struct wl_client *client, + wl_notify_func_t notify); + +struct wl_resource * +wl_client_get_object(struct wl_client *client, uint32_t id); + +void +wl_client_post_no_memory(struct wl_client *client); + +void +wl_client_post_implementation_error(struct wl_client *client, + const char* msg, ...) WL_PRINTF(2,3); + +void +wl_client_add_resource_created_listener(struct wl_client *client, + struct wl_listener *listener); + +/** Callback function type for wl_client_for_each_resource() */ +typedef enum wl_iterator_result (*wl_client_for_each_resource_iterator_func_t)( + struct wl_resource *resource, + void *user_data); + +void +wl_client_for_each_resource(struct wl_client *client, + wl_client_for_each_resource_iterator_func_t iterator, + void *user_data); + +typedef void (*wl_user_data_destroy_func_t)(void *data); + +void +wl_client_set_user_data(struct wl_client *client, + void *data, + wl_user_data_destroy_func_t dtor); + +void * +wl_client_get_user_data(struct wl_client *client); + +void +wl_client_set_max_buffer_size(struct wl_client *client, size_t max_buffer_size); + +/** \class wl_listener + * + * \brief A single listener for Wayland signals + * + * wl_listener provides the means to listen for wl_signal notifications. Many + * Wayland objects use wl_listener for notification of significant events like + * object destruction. + * + * Clients should create wl_listener objects manually and can register them as + * listeners to signals using wl_signal_add(), assuming the signal is + * directly accessible. For opaque structs like wl_event_loop, adding a + * listener should be done through provided accessor methods. A listener can + * only listen to one signal at a time. + * + * \code + * struct wl_listener your_listener; + * + * your_listener.notify = your_callback_method; + * + * // Direct access + * wl_signal_add(&some_object->destroy_signal, &your_listener); + * + * // Accessor access + * wl_event_loop *loop = ...; + * wl_event_loop_add_destroy_listener(loop, &your_listener); + * \endcode + * + * If the listener is part of a larger struct, #wl_container_of can be used + * to retrieve a pointer to it: + * + * \code + * void your_listener(struct wl_listener *listener, void *data) + * { + * struct your_data *data; + * + * your_data = wl_container_of(listener, data, your_member_name); + * } + * \endcode + * + * If you need to remove a listener from a signal, use wl_list_remove(). + * + * \code + * wl_list_remove(&your_listener.link); + * \endcode + * + * \sa wl_signal + */ +struct wl_listener { + /** Part of wl_signal::listener_list */ + struct wl_list link; + + /** Callback function pointer */ + wl_notify_func_t notify; +}; + +/** \class wl_signal + * + * \brief A source of a type of observable event + * + * Signals are recognized points where significant events can be observed. + * Compositors as well as the server can provide signals. Observers are + * wl_listener's that are added through #wl_signal_add. Signals are emitted + * using #wl_signal_emit, which will invoke all listeners until that + * listener is removed by wl_list_remove() (or whenever the signal is + * destroyed). + * + * \sa wl_listener for more information on using wl_signal + */ +struct wl_signal { + struct wl_list listener_list; +}; + +/** Initialize a new \ref wl_signal for use. + * + * \param signal The signal that will be initialized + * + * \memberof wl_signal + */ +static inline void +wl_signal_init(struct wl_signal *signal) +{ + wl_list_init(&signal->listener_list); +} + +/** Add the specified listener to this signal. + * + * \param signal The signal that will emit events to the listener + * \param listener The listener to add + * + * \memberof wl_signal + */ +static inline void +wl_signal_add(struct wl_signal *signal, struct wl_listener *listener) +{ + wl_list_insert(signal->listener_list.prev, &listener->link); +} + +/** Gets the listener struct for the specified callback. + * + * \param signal The signal that contains the specified listener + * \param notify The listener that is the target of this search + * \return the list item that corresponds to the specified listener, or NULL + * if none was found + * + * \memberof wl_signal + */ +static inline struct wl_listener * +wl_signal_get(struct wl_signal *signal, wl_notify_func_t notify) +{ + struct wl_listener *l; + + wl_list_for_each(l, &signal->listener_list, link) + if (l->notify == notify) + return l; + + return NULL; +} + +/** Emits this signal, notifying all registered listeners. + * + * \param signal The signal object that will emit the signal + * \param data The data that will be emitted with the signal + * + * \memberof wl_signal + */ +static inline void +wl_signal_emit(struct wl_signal *signal, void *data) +{ + struct wl_listener *l, *next; + + wl_list_for_each_safe(l, next, &signal->listener_list, link) + l->notify(l, data); +} + +void +wl_signal_emit_mutable(struct wl_signal *signal, void *data); + +typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource); + +/* + * Post an event to the client's object referred to by 'resource'. + * 'opcode' is the event number generated from the protocol XML + * description (the event name). The variable arguments are the event + * parameters, in the order they appear in the protocol XML specification. + * + * The variable arguments' types are: + * - type=uint: uint32_t + * - type=int: int32_t + * - type=fixed: wl_fixed_t + * - type=string: (const char *) to a nil-terminated string + * - type=array: (struct wl_array *) + * - type=fd: int, that is an open file descriptor + * - type=new_id: (struct wl_object *) or (struct wl_resource *) + * - type=object: (struct wl_object *) or (struct wl_resource *) + */ +void +wl_resource_post_event(struct wl_resource *resource, + uint32_t opcode, ...); + +void +wl_resource_post_event_array(struct wl_resource *resource, + uint32_t opcode, union wl_argument *args); + +void +wl_resource_queue_event(struct wl_resource *resource, + uint32_t opcode, ...); + +void +wl_resource_queue_event_array(struct wl_resource *resource, + uint32_t opcode, union wl_argument *args); + +void +wl_resource_post_error_vargs(struct wl_resource *resource, + uint32_t code, const char *msg, va_list argp); + +void +wl_resource_post_error(struct wl_resource *resource, + uint32_t code, const char *msg, ...) WL_PRINTF(3, 4); + +void +wl_resource_post_no_memory(struct wl_resource *resource); + +struct wl_display * +wl_client_get_display(struct wl_client *client); + +struct wl_resource * +wl_resource_create(struct wl_client *client, + const struct wl_interface *interface, + int version, uint32_t id); + +void +wl_resource_set_implementation(struct wl_resource *resource, + const void *implementation, + void *data, + wl_resource_destroy_func_t destroy); + +void +wl_resource_set_dispatcher(struct wl_resource *resource, + wl_dispatcher_func_t dispatcher, + const void *implementation, + void *data, + wl_resource_destroy_func_t destroy); + +void +wl_resource_destroy(struct wl_resource *resource); + +uint32_t +wl_resource_get_id(const struct wl_resource *resource); + +struct wl_list * +wl_resource_get_link(struct wl_resource *resource); + +struct wl_resource * +wl_resource_from_link(struct wl_list *resource); + +struct wl_resource * +wl_resource_find_for_client(struct wl_list *list, struct wl_client *client); + +struct wl_client * +wl_resource_get_client(struct wl_resource *resource); + +void +wl_resource_set_user_data(struct wl_resource *resource, void *data); + +void * +wl_resource_get_user_data(struct wl_resource *resource); + +int +wl_resource_get_version(const struct wl_resource *resource); + +void +wl_resource_set_destructor(struct wl_resource *resource, + wl_resource_destroy_func_t destroy); + +int +wl_resource_instance_of(struct wl_resource *resource, + const struct wl_interface *interface, + const void *implementation); + +const char * +wl_resource_get_class(const struct wl_resource *resource); + +const struct wl_interface * +wl_resource_get_interface(struct wl_resource *resource); + +void +wl_resource_add_destroy_listener(struct wl_resource *resource, + struct wl_listener *listener); + +struct wl_listener * +wl_resource_get_destroy_listener(struct wl_resource *resource, + wl_notify_func_t notify); + +#define wl_resource_for_each(resource, list) \ + for (resource = 0, resource = wl_resource_from_link((list)->next); \ + wl_resource_get_link(resource) != (list); \ + resource = wl_resource_from_link(wl_resource_get_link(resource)->next)) + +#define wl_resource_for_each_safe(resource, tmp, list) \ + for (resource = 0, tmp = 0, \ + resource = wl_resource_from_link((list)->next), \ + tmp = wl_resource_from_link((list)->next->next); \ + wl_resource_get_link(resource) != (list); \ + resource = tmp, \ + tmp = wl_resource_from_link(wl_resource_get_link(resource)->next)) + +struct wl_shm_buffer * +wl_shm_buffer_get(struct wl_resource *resource); + +void +wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer); + +void +wl_shm_buffer_end_access(struct wl_shm_buffer *buffer); + +void * +wl_shm_buffer_get_data(struct wl_shm_buffer *buffer); + +int32_t +wl_shm_buffer_get_stride(const struct wl_shm_buffer *buffer); + +uint32_t +wl_shm_buffer_get_format(const struct wl_shm_buffer *buffer); + +int32_t +wl_shm_buffer_get_width(const struct wl_shm_buffer *buffer); + +int32_t +wl_shm_buffer_get_height(const struct wl_shm_buffer *buffer); + +struct wl_shm_buffer * +wl_shm_buffer_ref(struct wl_shm_buffer *buffer); + +void +wl_shm_buffer_unref(struct wl_shm_buffer *buffer); + +struct wl_shm_pool * +wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer); + +void +wl_shm_pool_unref(struct wl_shm_pool *pool); + +int +wl_display_init_shm(struct wl_display *display); + +uint32_t * +wl_display_add_shm_format(struct wl_display *display, uint32_t format); + +WL_DEPRECATED +struct wl_shm_buffer * +wl_shm_buffer_create(struct wl_client *client, + uint32_t id, int32_t width, int32_t height, + int32_t stride, uint32_t format); + +void +wl_log_set_handler_server(wl_log_func_t handler); + +enum wl_protocol_logger_type { + WL_PROTOCOL_LOGGER_REQUEST, + WL_PROTOCOL_LOGGER_EVENT, +}; + +struct wl_protocol_logger_message { + struct wl_resource *resource; + int message_opcode; + const struct wl_message *message; + int arguments_count; + const union wl_argument *arguments; +}; + +/** Callback function type for wl_display_add_protocol_logger() */ +typedef void (*wl_protocol_logger_func_t)(void *user_data, + enum wl_protocol_logger_type direction, + const struct wl_protocol_logger_message *message); + +struct wl_protocol_logger * +wl_display_add_protocol_logger(struct wl_display *display, + wl_protocol_logger_func_t, void *user_data); + +void +wl_protocol_logger_destroy(struct wl_protocol_logger *logger); + +void +wl_fixes_handle_ack_global_remove(struct wl_resource *fixes_resource, + struct wl_resource *registry_resource, + uint32_t global_name); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-protocol.h b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-protocol.h new file mode 100644 index 0000000000..484faff1b1 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server-protocol.h @@ -0,0 +1,6252 @@ +/* Generated by wayland-scanner 1.26.0 */ + +#ifndef WAYLAND_SERVER_PROTOCOL_H +#define WAYLAND_SERVER_PROTOCOL_H + +#include <stdint.h> +#include <stddef.h> +#include "wayland-server.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct wl_client; +struct wl_resource; + +/** + * @page page_wayland The wayland protocol + * @section page_ifaces_wayland Interfaces + * - @subpage page_iface_wl_display - core global object + * - @subpage page_iface_wl_registry - global registry object + * - @subpage page_iface_wl_callback - callback object + * - @subpage page_iface_wl_compositor - the compositor singleton + * - @subpage page_iface_wl_shm_pool - a shared memory pool + * - @subpage page_iface_wl_shm - shared memory support + * - @subpage page_iface_wl_buffer - content for a wl_surface + * - @subpage page_iface_wl_data_offer - offer to transfer data + * - @subpage page_iface_wl_data_source - offer to transfer data + * - @subpage page_iface_wl_data_device - data transfer device + * - @subpage page_iface_wl_data_device_manager - data transfer interface + * - @subpage page_iface_wl_shell - create desktop-style surfaces + * - @subpage page_iface_wl_shell_surface - desktop-style metadata interface + * - @subpage page_iface_wl_surface - an onscreen surface + * - @subpage page_iface_wl_seat - group of input devices + * - @subpage page_iface_wl_pointer - pointer input device + * - @subpage page_iface_wl_keyboard - keyboard input device + * - @subpage page_iface_wl_touch - touchscreen input device + * - @subpage page_iface_wl_output - compositor output region + * - @subpage page_iface_wl_region - region interface + * - @subpage page_iface_wl_subcompositor - sub-surface compositing + * - @subpage page_iface_wl_subsurface - sub-surface interface to a wl_surface + * - @subpage page_iface_wl_fixes - wayland protocol fixes + * @section page_copyright_wayland Copyright + * <pre> + * + * Copyright © 2008-2011 Kristian Høgsberg + * Copyright © 2010-2011 Intel Corporation + * Copyright © 2012-2013 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * </pre> + */ +struct wl_buffer; +struct wl_callback; +struct wl_compositor; +struct wl_data_device; +struct wl_data_device_manager; +struct wl_data_offer; +struct wl_data_source; +struct wl_display; +struct wl_fixes; +struct wl_keyboard; +struct wl_output; +struct wl_pointer; +struct wl_region; +struct wl_registry; +struct wl_seat; +struct wl_shell; +struct wl_shell_surface; +struct wl_shm; +struct wl_shm_pool; +struct wl_subcompositor; +struct wl_subsurface; +struct wl_surface; +struct wl_touch; + +#ifndef WL_DISPLAY_INTERFACE +#define WL_DISPLAY_INTERFACE +/** + * @page page_iface_wl_display wl_display + * @section page_iface_wl_display_desc Description + * + * The core global object. This is a special singleton object. It + * is used for internal Wayland protocol features. + * @section page_iface_wl_display_api API + * See @ref iface_wl_display. + */ +/** + * @defgroup iface_wl_display The wl_display interface + * + * The core global object. This is a special singleton object. It + * is used for internal Wayland protocol features. + */ +extern const struct wl_interface wl_display_interface; +#endif +#ifndef WL_REGISTRY_INTERFACE +#define WL_REGISTRY_INTERFACE +/** + * @page page_iface_wl_registry wl_registry + * @section page_iface_wl_registry_desc Description + * + * The singleton global registry object. The server has a number of + * global objects that are available to all clients. These objects + * typically represent an actual object in the server (for example, + * an input device) or they are singleton objects that provide + * extension functionality. + * + * When a client creates a registry object, the registry object + * will emit a global event for each global currently in the + * registry. Globals come and go as a result of device or + * monitor hotplugs, reconfiguration or other events, and the + * registry will send out global and global_remove events to + * keep the client up to date with the changes. To mark the end + * of the initial burst of events, the client can use the + * wl_display.sync request immediately after calling + * wl_display.get_registry. + * + * A client can bind to a global object by using the bind + * request. This creates a client-side handle that lets the object + * emit events to the client and lets the client invoke requests on + * the object. + * @section page_iface_wl_registry_api API + * See @ref iface_wl_registry. + */ +/** + * @defgroup iface_wl_registry The wl_registry interface + * + * The singleton global registry object. The server has a number of + * global objects that are available to all clients. These objects + * typically represent an actual object in the server (for example, + * an input device) or they are singleton objects that provide + * extension functionality. + * + * When a client creates a registry object, the registry object + * will emit a global event for each global currently in the + * registry. Globals come and go as a result of device or + * monitor hotplugs, reconfiguration or other events, and the + * registry will send out global and global_remove events to + * keep the client up to date with the changes. To mark the end + * of the initial burst of events, the client can use the + * wl_display.sync request immediately after calling + * wl_display.get_registry. + * + * A client can bind to a global object by using the bind + * request. This creates a client-side handle that lets the object + * emit events to the client and lets the client invoke requests on + * the object. + */ +extern const struct wl_interface wl_registry_interface; +#endif +#ifndef WL_CALLBACK_INTERFACE +#define WL_CALLBACK_INTERFACE +/** + * @page page_iface_wl_callback wl_callback + * @section page_iface_wl_callback_desc Description + * + * Clients can handle the 'done' event to get notified when + * the related request is done. + * + * Note, because wl_callback objects are created from multiple independent + * factory interfaces, the wl_callback interface is frozen at version 1. + * @section page_iface_wl_callback_api API + * See @ref iface_wl_callback. + */ +/** + * @defgroup iface_wl_callback The wl_callback interface + * + * Clients can handle the 'done' event to get notified when + * the related request is done. + * + * Note, because wl_callback objects are created from multiple independent + * factory interfaces, the wl_callback interface is frozen at version 1. + */ +extern const struct wl_interface wl_callback_interface; +#endif +#ifndef WL_COMPOSITOR_INTERFACE +#define WL_COMPOSITOR_INTERFACE +/** + * @page page_iface_wl_compositor wl_compositor + * @section page_iface_wl_compositor_desc Description + * + * A compositor. This object is a singleton global. The + * compositor is in charge of combining the contents of multiple + * surfaces into one displayable output. + * @section page_iface_wl_compositor_api API + * See @ref iface_wl_compositor. + */ +/** + * @defgroup iface_wl_compositor The wl_compositor interface + * + * A compositor. This object is a singleton global. The + * compositor is in charge of combining the contents of multiple + * surfaces into one displayable output. + */ +extern const struct wl_interface wl_compositor_interface; +#endif +#ifndef WL_SHM_POOL_INTERFACE +#define WL_SHM_POOL_INTERFACE +/** + * @page page_iface_wl_shm_pool wl_shm_pool + * @section page_iface_wl_shm_pool_desc Description + * + * The wl_shm_pool object encapsulates a piece of memory shared + * between the compositor and client. Through the wl_shm_pool + * object, the client can allocate shared memory wl_buffer objects. + * All objects created through the same pool share the same + * underlying mapped memory. Reusing the mapped memory avoids the + * setup/teardown overhead and is useful when interactively resizing + * a surface or for many small buffers. + * @section page_iface_wl_shm_pool_api API + * See @ref iface_wl_shm_pool. + */ +/** + * @defgroup iface_wl_shm_pool The wl_shm_pool interface + * + * The wl_shm_pool object encapsulates a piece of memory shared + * between the compositor and client. Through the wl_shm_pool + * object, the client can allocate shared memory wl_buffer objects. + * All objects created through the same pool share the same + * underlying mapped memory. Reusing the mapped memory avoids the + * setup/teardown overhead and is useful when interactively resizing + * a surface or for many small buffers. + */ +extern const struct wl_interface wl_shm_pool_interface; +#endif +#ifndef WL_SHM_INTERFACE +#define WL_SHM_INTERFACE +/** + * @page page_iface_wl_shm wl_shm + * @section page_iface_wl_shm_desc Description + * + * A singleton global object that provides support for shared + * memory. + * + * Clients can create wl_shm_pool objects using the create_pool + * request. + * + * On binding the wl_shm object one or more format events + * are emitted to inform clients about the valid pixel formats + * that can be used for buffers. + * @section page_iface_wl_shm_api API + * See @ref iface_wl_shm. + */ +/** + * @defgroup iface_wl_shm The wl_shm interface + * + * A singleton global object that provides support for shared + * memory. + * + * Clients can create wl_shm_pool objects using the create_pool + * request. + * + * On binding the wl_shm object one or more format events + * are emitted to inform clients about the valid pixel formats + * that can be used for buffers. + */ +extern const struct wl_interface wl_shm_interface; +#endif +#ifndef WL_BUFFER_INTERFACE +#define WL_BUFFER_INTERFACE +/** + * @page page_iface_wl_buffer wl_buffer + * @section page_iface_wl_buffer_desc Description + * + * A buffer provides the content for a wl_surface. Buffers are + * created through factory interfaces such as wl_shm, wp_linux_buffer_params + * (from the linux-dmabuf protocol extension) or similar. It has a width and + * a height and can be attached to a wl_surface, but the mechanism by which a + * client provides and updates the contents is defined by the buffer factory + * interface. + * + * Color channels are assumed to be electrical rather than optical (in other + * words, encoded with a transfer function) unless otherwise specified. If + * the buffer uses a format that has an alpha channel, the alpha channel is + * assumed to be premultiplied into the electrical color channel values + * (after transfer function encoding) unless otherwise specified. + * + * Note, because wl_buffer objects are created from multiple independent + * factory interfaces, the wl_buffer interface is frozen at version 1. + * @section page_iface_wl_buffer_api API + * See @ref iface_wl_buffer. + */ +/** + * @defgroup iface_wl_buffer The wl_buffer interface + * + * A buffer provides the content for a wl_surface. Buffers are + * created through factory interfaces such as wl_shm, wp_linux_buffer_params + * (from the linux-dmabuf protocol extension) or similar. It has a width and + * a height and can be attached to a wl_surface, but the mechanism by which a + * client provides and updates the contents is defined by the buffer factory + * interface. + * + * Color channels are assumed to be electrical rather than optical (in other + * words, encoded with a transfer function) unless otherwise specified. If + * the buffer uses a format that has an alpha channel, the alpha channel is + * assumed to be premultiplied into the electrical color channel values + * (after transfer function encoding) unless otherwise specified. + * + * Note, because wl_buffer objects are created from multiple independent + * factory interfaces, the wl_buffer interface is frozen at version 1. + */ +extern const struct wl_interface wl_buffer_interface; +#endif +#ifndef WL_DATA_OFFER_INTERFACE +#define WL_DATA_OFFER_INTERFACE +/** + * @page page_iface_wl_data_offer wl_data_offer + * @section page_iface_wl_data_offer_desc Description + * + * A wl_data_offer represents a piece of data offered for transfer + * by another client (the source client). It is used by the + * copy-and-paste and drag-and-drop mechanisms. The offer + * describes the different mime types that the data can be + * converted to and provides the mechanism for transferring the + * data directly from the source client. + * @section page_iface_wl_data_offer_api API + * See @ref iface_wl_data_offer. + */ +/** + * @defgroup iface_wl_data_offer The wl_data_offer interface + * + * A wl_data_offer represents a piece of data offered for transfer + * by another client (the source client). It is used by the + * copy-and-paste and drag-and-drop mechanisms. The offer + * describes the different mime types that the data can be + * converted to and provides the mechanism for transferring the + * data directly from the source client. + */ +extern const struct wl_interface wl_data_offer_interface; +#endif +#ifndef WL_DATA_SOURCE_INTERFACE +#define WL_DATA_SOURCE_INTERFACE +/** + * @page page_iface_wl_data_source wl_data_source + * @section page_iface_wl_data_source_desc Description + * + * The wl_data_source object is the source side of a wl_data_offer. + * It is created by the source client in a data transfer and + * provides a way to describe the offered data and a way to respond + * to requests to transfer the data. + * @section page_iface_wl_data_source_api API + * See @ref iface_wl_data_source. + */ +/** + * @defgroup iface_wl_data_source The wl_data_source interface + * + * The wl_data_source object is the source side of a wl_data_offer. + * It is created by the source client in a data transfer and + * provides a way to describe the offered data and a way to respond + * to requests to transfer the data. + */ +extern const struct wl_interface wl_data_source_interface; +#endif +#ifndef WL_DATA_DEVICE_INTERFACE +#define WL_DATA_DEVICE_INTERFACE +/** + * @page page_iface_wl_data_device wl_data_device + * @section page_iface_wl_data_device_desc Description + * + * There is one wl_data_device per seat which can be obtained + * from the global wl_data_device_manager singleton. + * + * A wl_data_device provides access to inter-client data transfer + * mechanisms such as copy-and-paste and drag-and-drop. + * @section page_iface_wl_data_device_api API + * See @ref iface_wl_data_device. + */ +/** + * @defgroup iface_wl_data_device The wl_data_device interface + * + * There is one wl_data_device per seat which can be obtained + * from the global wl_data_device_manager singleton. + * + * A wl_data_device provides access to inter-client data transfer + * mechanisms such as copy-and-paste and drag-and-drop. + */ +extern const struct wl_interface wl_data_device_interface; +#endif +#ifndef WL_DATA_DEVICE_MANAGER_INTERFACE +#define WL_DATA_DEVICE_MANAGER_INTERFACE +/** + * @page page_iface_wl_data_device_manager wl_data_device_manager + * @section page_iface_wl_data_device_manager_desc Description + * + * The wl_data_device_manager is a singleton global object that + * provides access to inter-client data transfer mechanisms such as + * copy-and-paste and drag-and-drop. These mechanisms are tied to + * a wl_seat and this interface lets a client get a wl_data_device + * corresponding to a wl_seat. + * + * Depending on the version bound, the objects created from the bound + * wl_data_device_manager object will have different requirements for + * functioning properly. See wl_data_source.set_actions, + * wl_data_offer.accept and wl_data_offer.finish for details. + * @section page_iface_wl_data_device_manager_api API + * See @ref iface_wl_data_device_manager. + */ +/** + * @defgroup iface_wl_data_device_manager The wl_data_device_manager interface + * + * The wl_data_device_manager is a singleton global object that + * provides access to inter-client data transfer mechanisms such as + * copy-and-paste and drag-and-drop. These mechanisms are tied to + * a wl_seat and this interface lets a client get a wl_data_device + * corresponding to a wl_seat. + * + * Depending on the version bound, the objects created from the bound + * wl_data_device_manager object will have different requirements for + * functioning properly. See wl_data_source.set_actions, + * wl_data_offer.accept and wl_data_offer.finish for details. + */ +extern const struct wl_interface wl_data_device_manager_interface; +#endif +#ifndef WL_SHELL_INTERFACE +#define WL_SHELL_INTERFACE +/** + * @page page_iface_wl_shell wl_shell + * @section page_iface_wl_shell_desc Description + * + * This interface is implemented by servers that provide + * desktop-style user interfaces. + * + * It allows clients to associate a wl_shell_surface with + * a basic surface. + * + * Note! This protocol is deprecated and not intended for production use. + * For desktop-style user interfaces, use xdg_shell. Compositors and clients + * should not implement this interface. + * @section page_iface_wl_shell_api API + * See @ref iface_wl_shell. + */ +/** + * @defgroup iface_wl_shell The wl_shell interface + * + * This interface is implemented by servers that provide + * desktop-style user interfaces. + * + * It allows clients to associate a wl_shell_surface with + * a basic surface. + * + * Note! This protocol is deprecated and not intended for production use. + * For desktop-style user interfaces, use xdg_shell. Compositors and clients + * should not implement this interface. + */ +extern const struct wl_interface wl_shell_interface; +#endif +#ifndef WL_SHELL_SURFACE_INTERFACE +#define WL_SHELL_SURFACE_INTERFACE +/** + * @page page_iface_wl_shell_surface wl_shell_surface + * @section page_iface_wl_shell_surface_desc Description + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides requests to treat surfaces like toplevel, fullscreen + * or popup windows, move, resize or maximize them, associate + * metadata like title and class, etc. + * + * On the server side the object is automatically destroyed when + * the related wl_surface is destroyed. On the client side, + * wl_shell_surface_destroy() must be called before destroying + * the wl_surface object. + * @section page_iface_wl_shell_surface_api API + * See @ref iface_wl_shell_surface. + */ +/** + * @defgroup iface_wl_shell_surface The wl_shell_surface interface + * + * An interface that may be implemented by a wl_surface, for + * implementations that provide a desktop-style user interface. + * + * It provides requests to treat surfaces like toplevel, fullscreen + * or popup windows, move, resize or maximize them, associate + * metadata like title and class, etc. + * + * On the server side the object is automatically destroyed when + * the related wl_surface is destroyed. On the client side, + * wl_shell_surface_destroy() must be called before destroying + * the wl_surface object. + */ +extern const struct wl_interface wl_shell_surface_interface; +#endif +#ifndef WL_SURFACE_INTERFACE +#define WL_SURFACE_INTERFACE +/** + * @page page_iface_wl_surface wl_surface + * @section page_iface_wl_surface_desc Description + * + * A surface is a rectangular area that may be displayed on zero + * or more outputs, and shown any number of times at the compositor's + * discretion. They can present wl_buffers, receive user input, and + * define a local coordinate system. + * + * The size of a surface (and relative positions on it) is described + * in surface-local coordinates, which may differ from the buffer + * coordinates of the pixel content, in case a buffer_transform + * or a buffer_scale is used. + * + * A surface without a "role" is fairly useless: a compositor does + * not know where, when or how to present it. The role is the + * purpose of a wl_surface. Examples of roles are a cursor for a + * pointer (as set by wl_pointer.set_cursor), a drag icon + * (wl_data_device.start_drag), a sub-surface + * (wl_subcompositor.get_subsurface), and a window as defined by a + * shell protocol (e.g. wl_shell.get_shell_surface). + * + * A surface can have only one role at a time. Initially a + * wl_surface does not have a role. Once a wl_surface is given a + * role, it is set permanently for the whole lifetime of the + * wl_surface object. Giving the current role again is allowed, + * unless explicitly forbidden by the relevant interface + * specification. + * + * Surface roles are given by requests in other interfaces such as + * wl_pointer.set_cursor. The request should explicitly mention + * that this request gives a role to a wl_surface. Often, this + * request also creates a new protocol object that represents the + * role and adds additional functionality to wl_surface. When a + * client wants to destroy a wl_surface, they must destroy this role + * object before the wl_surface, otherwise a defunct_role_object error is + * sent. + * + * Destroying the role object does not remove the role from the + * wl_surface, but it may stop the wl_surface from "playing the role". + * For instance, if a wl_subsurface object is destroyed, the wl_surface + * it was created for will be unmapped and forget its position and + * z-order. It is allowed to create a wl_subsurface for the same + * wl_surface again, but it is not allowed to use the wl_surface as + * a cursor (cursor is a different role than sub-surface, and role + * switching is not allowed). + * @section page_iface_wl_surface_api API + * See @ref iface_wl_surface. + */ +/** + * @defgroup iface_wl_surface The wl_surface interface + * + * A surface is a rectangular area that may be displayed on zero + * or more outputs, and shown any number of times at the compositor's + * discretion. They can present wl_buffers, receive user input, and + * define a local coordinate system. + * + * The size of a surface (and relative positions on it) is described + * in surface-local coordinates, which may differ from the buffer + * coordinates of the pixel content, in case a buffer_transform + * or a buffer_scale is used. + * + * A surface without a "role" is fairly useless: a compositor does + * not know where, when or how to present it. The role is the + * purpose of a wl_surface. Examples of roles are a cursor for a + * pointer (as set by wl_pointer.set_cursor), a drag icon + * (wl_data_device.start_drag), a sub-surface + * (wl_subcompositor.get_subsurface), and a window as defined by a + * shell protocol (e.g. wl_shell.get_shell_surface). + * + * A surface can have only one role at a time. Initially a + * wl_surface does not have a role. Once a wl_surface is given a + * role, it is set permanently for the whole lifetime of the + * wl_surface object. Giving the current role again is allowed, + * unless explicitly forbidden by the relevant interface + * specification. + * + * Surface roles are given by requests in other interfaces such as + * wl_pointer.set_cursor. The request should explicitly mention + * that this request gives a role to a wl_surface. Often, this + * request also creates a new protocol object that represents the + * role and adds additional functionality to wl_surface. When a + * client wants to destroy a wl_surface, they must destroy this role + * object before the wl_surface, otherwise a defunct_role_object error is + * sent. + * + * Destroying the role object does not remove the role from the + * wl_surface, but it may stop the wl_surface from "playing the role". + * For instance, if a wl_subsurface object is destroyed, the wl_surface + * it was created for will be unmapped and forget its position and + * z-order. It is allowed to create a wl_subsurface for the same + * wl_surface again, but it is not allowed to use the wl_surface as + * a cursor (cursor is a different role than sub-surface, and role + * switching is not allowed). + */ +extern const struct wl_interface wl_surface_interface; +#endif +#ifndef WL_SEAT_INTERFACE +#define WL_SEAT_INTERFACE +/** + * @page page_iface_wl_seat wl_seat + * @section page_iface_wl_seat_desc Description + * + * A seat is a group of keyboards, pointer and touch devices. This + * object is published as a global during start up, or when such a + * device is hot plugged. A seat typically has a pointer and + * maintains a keyboard focus and a pointer focus. + * @section page_iface_wl_seat_api API + * See @ref iface_wl_seat. + */ +/** + * @defgroup iface_wl_seat The wl_seat interface + * + * A seat is a group of keyboards, pointer and touch devices. This + * object is published as a global during start up, or when such a + * device is hot plugged. A seat typically has a pointer and + * maintains a keyboard focus and a pointer focus. + */ +extern const struct wl_interface wl_seat_interface; +#endif +#ifndef WL_POINTER_INTERFACE +#define WL_POINTER_INTERFACE +/** + * @page page_iface_wl_pointer wl_pointer + * @section page_iface_wl_pointer_desc Description + * + * The wl_pointer interface represents one or more input devices, + * such as mice, which control the pointer location and pointer_focus + * of a seat. + * + * The wl_pointer interface generates motion, enter and leave + * events for the surfaces that the pointer is located over, + * and button and axis events for button presses, button releases + * and scrolling. + * @section page_iface_wl_pointer_api API + * See @ref iface_wl_pointer. + */ +/** + * @defgroup iface_wl_pointer The wl_pointer interface + * + * The wl_pointer interface represents one or more input devices, + * such as mice, which control the pointer location and pointer_focus + * of a seat. + * + * The wl_pointer interface generates motion, enter and leave + * events for the surfaces that the pointer is located over, + * and button and axis events for button presses, button releases + * and scrolling. + */ +extern const struct wl_interface wl_pointer_interface; +#endif +#ifndef WL_KEYBOARD_INTERFACE +#define WL_KEYBOARD_INTERFACE +/** + * @page page_iface_wl_keyboard wl_keyboard + * @section page_iface_wl_keyboard_desc Description + * + * The wl_keyboard interface represents one or more keyboards + * associated with a seat. + * + * Each wl_keyboard has the following logical state: + * + * - an active surface (possibly null), + * - the keys currently logically down, + * - the active modifiers, + * - the active group. + * + * By default, the active surface is null, the keys currently logically down + * are empty, the active modifiers and the active group are 0. + * @section page_iface_wl_keyboard_api API + * See @ref iface_wl_keyboard. + */ +/** + * @defgroup iface_wl_keyboard The wl_keyboard interface + * + * The wl_keyboard interface represents one or more keyboards + * associated with a seat. + * + * Each wl_keyboard has the following logical state: + * + * - an active surface (possibly null), + * - the keys currently logically down, + * - the active modifiers, + * - the active group. + * + * By default, the active surface is null, the keys currently logically down + * are empty, the active modifiers and the active group are 0. + */ +extern const struct wl_interface wl_keyboard_interface; +#endif +#ifndef WL_TOUCH_INTERFACE +#define WL_TOUCH_INTERFACE +/** + * @page page_iface_wl_touch wl_touch + * @section page_iface_wl_touch_desc Description + * + * The wl_touch interface represents a touchscreen + * associated with a seat. + * + * Touch interactions can consist of one or more contacts. + * For each contact, a series of events is generated, starting + * with a down event, followed by zero or more motion events, + * and ending with an up event. Events relating to the same + * contact point can be identified by the ID of the sequence. + * @section page_iface_wl_touch_api API + * See @ref iface_wl_touch. + */ +/** + * @defgroup iface_wl_touch The wl_touch interface + * + * The wl_touch interface represents a touchscreen + * associated with a seat. + * + * Touch interactions can consist of one or more contacts. + * For each contact, a series of events is generated, starting + * with a down event, followed by zero or more motion events, + * and ending with an up event. Events relating to the same + * contact point can be identified by the ID of the sequence. + */ +extern const struct wl_interface wl_touch_interface; +#endif +#ifndef WL_OUTPUT_INTERFACE +#define WL_OUTPUT_INTERFACE +/** + * @page page_iface_wl_output wl_output + * @section page_iface_wl_output_desc Description + * + * An output describes part of the compositor geometry. The + * compositor works in the 'compositor coordinate system' and an + * output corresponds to a rectangular area in that space that is + * actually visible. This typically corresponds to a monitor that + * displays part of the compositor space. This object is published + * as global during start up, or when a monitor is hotplugged. + * @section page_iface_wl_output_api API + * See @ref iface_wl_output. + */ +/** + * @defgroup iface_wl_output The wl_output interface + * + * An output describes part of the compositor geometry. The + * compositor works in the 'compositor coordinate system' and an + * output corresponds to a rectangular area in that space that is + * actually visible. This typically corresponds to a monitor that + * displays part of the compositor space. This object is published + * as global during start up, or when a monitor is hotplugged. + */ +extern const struct wl_interface wl_output_interface; +#endif +#ifndef WL_REGION_INTERFACE +#define WL_REGION_INTERFACE +/** + * @page page_iface_wl_region wl_region + * @section page_iface_wl_region_desc Description + * + * A region object describes an area. + * + * Region objects are used to describe the opaque and input + * regions of a surface. + * @section page_iface_wl_region_api API + * See @ref iface_wl_region. + */ +/** + * @defgroup iface_wl_region The wl_region interface + * + * A region object describes an area. + * + * Region objects are used to describe the opaque and input + * regions of a surface. + */ +extern const struct wl_interface wl_region_interface; +#endif +#ifndef WL_SUBCOMPOSITOR_INTERFACE +#define WL_SUBCOMPOSITOR_INTERFACE +/** + * @page page_iface_wl_subcompositor wl_subcompositor + * @section page_iface_wl_subcompositor_desc Description + * + * The global interface exposing sub-surface compositing capabilities. + * A wl_surface, that has sub-surfaces associated, is called the + * parent surface. Sub-surfaces can be arbitrarily nested and create + * a tree of sub-surfaces. + * + * The root surface in a tree of sub-surfaces is the main + * surface. The main surface cannot be a sub-surface, because + * sub-surfaces must always have a parent. + * + * A main surface with its sub-surfaces forms a (compound) window. + * For window management purposes, this set of wl_surface objects is + * to be considered as a single window, and it should also behave as + * such. + * + * The aim of sub-surfaces is to offload some of the compositing work + * within a window from clients to the compositor. A prime example is + * a video player with decorations and video in separate wl_surface + * objects. This should allow the compositor to pass YUV video buffer + * processing to dedicated overlay hardware when possible. + * @section page_iface_wl_subcompositor_api API + * See @ref iface_wl_subcompositor. + */ +/** + * @defgroup iface_wl_subcompositor The wl_subcompositor interface + * + * The global interface exposing sub-surface compositing capabilities. + * A wl_surface, that has sub-surfaces associated, is called the + * parent surface. Sub-surfaces can be arbitrarily nested and create + * a tree of sub-surfaces. + * + * The root surface in a tree of sub-surfaces is the main + * surface. The main surface cannot be a sub-surface, because + * sub-surfaces must always have a parent. + * + * A main surface with its sub-surfaces forms a (compound) window. + * For window management purposes, this set of wl_surface objects is + * to be considered as a single window, and it should also behave as + * such. + * + * The aim of sub-surfaces is to offload some of the compositing work + * within a window from clients to the compositor. A prime example is + * a video player with decorations and video in separate wl_surface + * objects. This should allow the compositor to pass YUV video buffer + * processing to dedicated overlay hardware when possible. + */ +extern const struct wl_interface wl_subcompositor_interface; +#endif +#ifndef WL_SUBSURFACE_INTERFACE +#define WL_SUBSURFACE_INTERFACE +/** + * @page page_iface_wl_subsurface wl_subsurface + * @section page_iface_wl_subsurface_desc Description + * + * An additional interface to a wl_surface object, which has been + * made a sub-surface. A sub-surface has one parent surface. A + * sub-surface's size and position are not limited to that of the parent. + * Particularly, a sub-surface is not automatically clipped to its + * parent's area. + * + * A sub-surface becomes mapped, when a non-NULL wl_buffer is applied + * and the parent surface is mapped. The order of which one happens + * first is irrelevant. A sub-surface is hidden if the parent becomes + * hidden, or if a NULL wl_buffer is applied. These rules apply + * recursively through the tree of surfaces. + * + * A sub-surface can be in one of two modes. The possible modes are + * synchronized and desynchronized, see methods wl_subsurface.set_sync and + * wl_subsurface.set_desync. + * + * The main surface can be thought to be always in desynchronized mode, + * since it does not have a parent in the sub-surfaces sense. + * + * Even if a sub-surface is in desynchronized mode, it will behave as + * in synchronized mode, if its parent surface behaves as in + * synchronized mode. This rule is applied recursively throughout the + * tree of surfaces. This means, that one can set a sub-surface into + * synchronized mode, and then assume that all its child and grand-child + * sub-surfaces are synchronized, too, without explicitly setting them. + * + * If a surface behaves as in synchronized mode, it is effectively + * synchronized, otherwise it is effectively desynchronized. + * + * A sub-surface is initially in the synchronized mode. + * + * The wl_subsurface interface has requests which modify double-buffered + * state of the parent surface (wl_subsurface.set_position, .place_above and + * .place_below). + * + * Destroying a sub-surface takes effect immediately. If you need to + * synchronize the removal of a sub-surface to the parent surface update, + * unmap the sub-surface first by attaching a NULL wl_buffer, update parent, + * and then destroy the sub-surface. + * + * If the parent wl_surface object is destroyed, the sub-surface is + * unmapped. + * + * A sub-surface never has the keyboard focus of any seat. + * + * The wl_surface.offset request is ignored: clients must use set_position + * instead to move the sub-surface. + * @section page_iface_wl_subsurface_api API + * See @ref iface_wl_subsurface. + */ +/** + * @defgroup iface_wl_subsurface The wl_subsurface interface + * + * An additional interface to a wl_surface object, which has been + * made a sub-surface. A sub-surface has one parent surface. A + * sub-surface's size and position are not limited to that of the parent. + * Particularly, a sub-surface is not automatically clipped to its + * parent's area. + * + * A sub-surface becomes mapped, when a non-NULL wl_buffer is applied + * and the parent surface is mapped. The order of which one happens + * first is irrelevant. A sub-surface is hidden if the parent becomes + * hidden, or if a NULL wl_buffer is applied. These rules apply + * recursively through the tree of surfaces. + * + * A sub-surface can be in one of two modes. The possible modes are + * synchronized and desynchronized, see methods wl_subsurface.set_sync and + * wl_subsurface.set_desync. + * + * The main surface can be thought to be always in desynchronized mode, + * since it does not have a parent in the sub-surfaces sense. + * + * Even if a sub-surface is in desynchronized mode, it will behave as + * in synchronized mode, if its parent surface behaves as in + * synchronized mode. This rule is applied recursively throughout the + * tree of surfaces. This means, that one can set a sub-surface into + * synchronized mode, and then assume that all its child and grand-child + * sub-surfaces are synchronized, too, without explicitly setting them. + * + * If a surface behaves as in synchronized mode, it is effectively + * synchronized, otherwise it is effectively desynchronized. + * + * A sub-surface is initially in the synchronized mode. + * + * The wl_subsurface interface has requests which modify double-buffered + * state of the parent surface (wl_subsurface.set_position, .place_above and + * .place_below). + * + * Destroying a sub-surface takes effect immediately. If you need to + * synchronize the removal of a sub-surface to the parent surface update, + * unmap the sub-surface first by attaching a NULL wl_buffer, update parent, + * and then destroy the sub-surface. + * + * If the parent wl_surface object is destroyed, the sub-surface is + * unmapped. + * + * A sub-surface never has the keyboard focus of any seat. + * + * The wl_surface.offset request is ignored: clients must use set_position + * instead to move the sub-surface. + */ +extern const struct wl_interface wl_subsurface_interface; +#endif +#ifndef WL_FIXES_INTERFACE +#define WL_FIXES_INTERFACE +/** + * @page page_iface_wl_fixes wl_fixes + * @section page_iface_wl_fixes_desc Description + * + * This global fixes problems with other core-protocol interfaces that + * cannot be fixed in these interfaces themselves. + * @section page_iface_wl_fixes_api API + * See @ref iface_wl_fixes. + */ +/** + * @defgroup iface_wl_fixes The wl_fixes interface + * + * This global fixes problems with other core-protocol interfaces that + * cannot be fixed in these interfaces themselves. + */ +extern const struct wl_interface wl_fixes_interface; +#endif + +#ifndef WL_DISPLAY_ERROR_ENUM +#define WL_DISPLAY_ERROR_ENUM +/** + * @ingroup iface_wl_display + * global error values + * + * These errors are global and can be emitted in response to any + * server request. + */ +enum wl_display_error { + /** + * server couldn't find object + */ + WL_DISPLAY_ERROR_INVALID_OBJECT = 0, + /** + * method doesn't exist on the specified interface or malformed request + */ + WL_DISPLAY_ERROR_INVALID_METHOD = 1, + /** + * server is out of memory + */ + WL_DISPLAY_ERROR_NO_MEMORY = 2, + /** + * implementation error in compositor + */ + WL_DISPLAY_ERROR_IMPLEMENTATION = 3, +}; +#endif /* WL_DISPLAY_ERROR_ENUM */ + +#ifndef WL_DISPLAY_ERROR_ENUM_IS_VALID +#define WL_DISPLAY_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_display + * Validate a wl_display error value. + * + * @return true on success, false on error. + * @ref wl_display_error + */ +static inline bool +wl_display_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_DISPLAY_ERROR_INVALID_OBJECT: + return version >= 1; + case WL_DISPLAY_ERROR_INVALID_METHOD: + return version >= 1; + case WL_DISPLAY_ERROR_NO_MEMORY: + return version >= 1; + case WL_DISPLAY_ERROR_IMPLEMENTATION: + return version >= 1; + default: + return false; + } +} +#endif /* WL_DISPLAY_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_display + * @struct wl_display_interface + */ +struct wl_display_interface { + /** + * asynchronous roundtrip + * + * The sync request asks the server to emit the 'done' event on + * the returned wl_callback object. Since requests are handled + * in-order and events are delivered in-order, this can be used as + * a barrier to ensure all previous requests and the resulting + * events have been handled. + * + * The object returned by this request will be destroyed by the + * compositor after the callback is fired and as such the client + * must not attempt to use it after that point. + * + * The callback_data passed in the callback is undefined and should + * be ignored. + * @param callback callback object for the sync request + */ + void (*sync)(struct wl_client *client, + struct wl_resource *resource, + uint32_t callback); + /** + * get global registry object + * + * This request creates a registry object that allows the client + * to list and bind the global objects available from the + * compositor. + * + * It should be noted that the server side resources consumed in + * response to a get_registry request can only be released when the + * client disconnects, not when the client side proxy is destroyed. + * Therefore, clients should invoke get_registry as infrequently as + * possible to avoid wasting memory. + * @param registry global registry object + */ + void (*get_registry)(struct wl_client *client, + struct wl_resource *resource, + uint32_t registry); +}; + +#define WL_DISPLAY_ERROR 0 +#define WL_DISPLAY_DELETE_ID 1 + +/** + * @ingroup iface_wl_display + */ +#define WL_DISPLAY_ERROR_SINCE_VERSION 1 +/** + * @ingroup iface_wl_display + */ +#define WL_DISPLAY_DELETE_ID_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_display + */ +#define WL_DISPLAY_SYNC_SINCE_VERSION 1 +/** + * @ingroup iface_wl_display + */ +#define WL_DISPLAY_GET_REGISTRY_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_registry + * @struct wl_registry_interface + */ +struct wl_registry_interface { + /** + * bind an object to the display + * + * Binds a new, client-created object to the server using the + * specified name as the identifier. + * @param name unique numeric name of the object + * @param interface name of the objects interface + * @param version version of the objects interface + * @param id bound object + */ + void (*bind)(struct wl_client *client, + struct wl_resource *resource, + uint32_t name, + const char *interface, uint32_t version, uint32_t id); +}; + +#define WL_REGISTRY_GLOBAL 0 +#define WL_REGISTRY_GLOBAL_REMOVE 1 + +/** + * @ingroup iface_wl_registry + */ +#define WL_REGISTRY_GLOBAL_SINCE_VERSION 1 +/** + * @ingroup iface_wl_registry + */ +#define WL_REGISTRY_GLOBAL_REMOVE_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_registry + */ +#define WL_REGISTRY_BIND_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_registry + * Sends an global event to the client owning the resource. + * @param resource_ The client's resource + * @param name numeric name of the global object + * @param interface interface implemented by the object + * @param version interface version + */ +static inline void +wl_registry_send_global(struct wl_resource *resource_, uint32_t name, const char *interface, uint32_t version) +{ + wl_resource_post_event(resource_, WL_REGISTRY_GLOBAL, name, interface, version); +} + +/** + * @ingroup iface_wl_registry + * Sends an global_remove event to the client owning the resource. + * @param resource_ The client's resource + * @param name numeric name of the global object + */ +static inline void +wl_registry_send_global_remove(struct wl_resource *resource_, uint32_t name) +{ + wl_resource_post_event(resource_, WL_REGISTRY_GLOBAL_REMOVE, name); +} + +#define WL_CALLBACK_DONE 0 + +/** + * @ingroup iface_wl_callback + */ +#define WL_CALLBACK_DONE_SINCE_VERSION 1 + + +/** + * @ingroup iface_wl_callback + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + * @param callback_data request-specific data for the callback + */ +static inline void +wl_callback_send_done(struct wl_resource *resource_, uint32_t callback_data) +{ + wl_resource_post_event(resource_, WL_CALLBACK_DONE, callback_data); +} + +/** + * @ingroup iface_wl_compositor + * @struct wl_compositor_interface + */ +struct wl_compositor_interface { + /** + * create new surface + * + * Ask the compositor to create a new surface. + * @param id the new surface + */ + void (*create_surface)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * create new region + * + * Ask the compositor to create a new region. + * @param id the new region + */ + void (*create_region)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * destroy wl_compositor + * + * This request destroys the wl_compositor. This has no effect on + * any other objects. + * @since 7 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_wl_compositor + */ +#define WL_COMPOSITOR_CREATE_SURFACE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_compositor + */ +#define WL_COMPOSITOR_CREATE_REGION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_compositor + */ +#define WL_COMPOSITOR_RELEASE_SINCE_VERSION 7 + +#ifndef WL_SHM_POOL_ERROR_ENUM +#define WL_SHM_POOL_ERROR_ENUM +/** + * @ingroup iface_wl_shm_pool + * wl_shm_pool error values + * + * These errors can be emitted in response to wl_shm_pool requests. + */ +enum wl_shm_pool_error { + /** + * buffer format is not known + */ + WL_SHM_POOL_ERROR_INVALID_FORMAT = 0, + /** + * invalid size or stride during buffer creation + */ + WL_SHM_POOL_ERROR_INVALID_STRIDE = 1, +}; +#endif /* WL_SHM_POOL_ERROR_ENUM */ + +#ifndef WL_SHM_POOL_ERROR_ENUM_IS_VALID +#define WL_SHM_POOL_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_shm_pool + * Validate a wl_shm_pool error value. + * + * @return true on success, false on error. + * @ref wl_shm_pool_error + */ +static inline bool +wl_shm_pool_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SHM_POOL_ERROR_INVALID_FORMAT: + return version >= 1; + case WL_SHM_POOL_ERROR_INVALID_STRIDE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SHM_POOL_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_shm_pool + * @struct wl_shm_pool_interface + */ +struct wl_shm_pool_interface { + /** + * create a buffer from the pool + * + * Create a wl_buffer object from the pool. + * + * The buffer is created offset bytes into the pool and has width + * and height as specified. The stride argument specifies the + * number of bytes from the beginning of one row to the beginning + * of the next. The format is the pixel format of the buffer and + * must be one of those advertised through the wl_shm.format event. + * + * A buffer will keep a reference to the pool it was created from + * so it is valid to destroy the pool immediately after creating a + * buffer from it. + * @param id buffer to create + * @param offset buffer byte offset within the pool + * @param width buffer width, in pixels + * @param height buffer height, in pixels + * @param stride number of bytes from the beginning of one row to the beginning of the next row + * @param format buffer pixel format + */ + void (*create_buffer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + int32_t offset, + int32_t width, + int32_t height, + int32_t stride, + uint32_t format); + /** + * destroy the pool + * + * Destroy the shared memory pool. + * + * The mmapped memory will be released when all buffers that have + * been created from this pool are gone. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * change the size of the pool mapping + * + * This request will cause the server to remap the backing memory + * for the pool from the file descriptor passed when the pool was + * created, but using the new size. This request can only be used + * to make the pool bigger. + * + * This request only changes the amount of bytes that are mmapped + * by the server and does not touch the file corresponding to the + * file descriptor passed at creation time. It is the client's + * responsibility to ensure that the file is at least as big as the + * new pool size. + * @param size new size of the pool, in bytes + */ + void (*resize)(struct wl_client *client, + struct wl_resource *resource, + int32_t size); +}; + + +/** + * @ingroup iface_wl_shm_pool + */ +#define WL_SHM_POOL_CREATE_BUFFER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shm_pool + */ +#define WL_SHM_POOL_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shm_pool + */ +#define WL_SHM_POOL_RESIZE_SINCE_VERSION 1 + +#ifndef WL_SHM_ERROR_ENUM +#define WL_SHM_ERROR_ENUM +/** + * @ingroup iface_wl_shm + * wl_shm error values + * + * These errors can be emitted in response to wl_shm requests. + */ +enum wl_shm_error { + /** + * buffer format is not known + * @deprecated Deprecated since version 3 + */ + WL_SHM_ERROR_INVALID_FORMAT = 0, + /** + * invalid size or stride during pool creation + */ + WL_SHM_ERROR_INVALID_STRIDE = 1, + /** + * mmapping the file descriptor failed + */ + WL_SHM_ERROR_INVALID_FD = 2, +}; +#endif /* WL_SHM_ERROR_ENUM */ + +#ifndef WL_SHM_ERROR_ENUM_IS_VALID +#define WL_SHM_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_shm + * Validate a wl_shm error value. + * + * @return true on success, false on error. + * @ref wl_shm_error + */ +static inline bool +wl_shm_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SHM_ERROR_INVALID_FORMAT: + return version >= 1; + case WL_SHM_ERROR_INVALID_STRIDE: + return version >= 1; + case WL_SHM_ERROR_INVALID_FD: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SHM_ERROR_ENUM_IS_VALID */ + +#ifndef WL_SHM_FORMAT_ENUM +#define WL_SHM_FORMAT_ENUM +/** + * @ingroup iface_wl_shm + * pixel formats + * + * This describes the memory layout of an individual pixel. + * + * All renderers should support argb8888 and xrgb8888 but any other + * formats are optional and may not be supported by the particular + * renderer in use. + * + * The drm format codes match the macros defined in drm_fourcc.h, except + * argb8888 and xrgb8888. The formats actually supported by the compositor + * will be reported by the format event. See drm_fourcc.h for more detailed + * format descriptions. + * + * For all wl_shm formats and unless specified in another protocol + * extension, pre-multiplied alpha is used for pixel values. + */ +enum wl_shm_format { + /** + * 32-bit ARGB format, [31:0] A:R:G:B 8:8:8:8 little endian + */ + WL_SHM_FORMAT_ARGB8888 = 0, + /** + * 32-bit RGB format, [31:0] x:R:G:B 8:8:8:8 little endian + */ + WL_SHM_FORMAT_XRGB8888 = 1, + /** + * 8-bit color index format, [7:0] C + */ + WL_SHM_FORMAT_C8 = 0x20203843, + /** + * 8-bit RGB format, [7:0] R:G:B 3:3:2 + */ + WL_SHM_FORMAT_RGB332 = 0x38424752, + /** + * 8-bit BGR format, [7:0] B:G:R 2:3:3 + */ + WL_SHM_FORMAT_BGR233 = 0x38524742, + /** + * 16-bit xRGB format, [15:0] x:R:G:B 4:4:4:4 little endian + */ + WL_SHM_FORMAT_XRGB4444 = 0x32315258, + /** + * 16-bit xBGR format, [15:0] x:B:G:R 4:4:4:4 little endian + */ + WL_SHM_FORMAT_XBGR4444 = 0x32314258, + /** + * 16-bit RGBx format, [15:0] R:G:B:x 4:4:4:4 little endian + */ + WL_SHM_FORMAT_RGBX4444 = 0x32315852, + /** + * 16-bit BGRx format, [15:0] B:G:R:x 4:4:4:4 little endian + */ + WL_SHM_FORMAT_BGRX4444 = 0x32315842, + /** + * 16-bit ARGB format, [15:0] A:R:G:B 4:4:4:4 little endian + */ + WL_SHM_FORMAT_ARGB4444 = 0x32315241, + /** + * 16-bit ABGR format, [15:0] A:B:G:R 4:4:4:4 little endian + */ + WL_SHM_FORMAT_ABGR4444 = 0x32314241, + /** + * 16-bit RGBA format, [15:0] R:G:B:A 4:4:4:4 little endian + */ + WL_SHM_FORMAT_RGBA4444 = 0x32314152, + /** + * 16-bit BGRA format, [15:0] B:G:R:A 4:4:4:4 little endian + */ + WL_SHM_FORMAT_BGRA4444 = 0x32314142, + /** + * 16-bit xRGB format, [15:0] x:R:G:B 1:5:5:5 little endian + */ + WL_SHM_FORMAT_XRGB1555 = 0x35315258, + /** + * 16-bit xBGR 1555 format, [15:0] x:B:G:R 1:5:5:5 little endian + */ + WL_SHM_FORMAT_XBGR1555 = 0x35314258, + /** + * 16-bit RGBx 5551 format, [15:0] R:G:B:x 5:5:5:1 little endian + */ + WL_SHM_FORMAT_RGBX5551 = 0x35315852, + /** + * 16-bit BGRx 5551 format, [15:0] B:G:R:x 5:5:5:1 little endian + */ + WL_SHM_FORMAT_BGRX5551 = 0x35315842, + /** + * 16-bit ARGB 1555 format, [15:0] A:R:G:B 1:5:5:5 little endian + */ + WL_SHM_FORMAT_ARGB1555 = 0x35315241, + /** + * 16-bit ABGR 1555 format, [15:0] A:B:G:R 1:5:5:5 little endian + */ + WL_SHM_FORMAT_ABGR1555 = 0x35314241, + /** + * 16-bit RGBA 5551 format, [15:0] R:G:B:A 5:5:5:1 little endian + */ + WL_SHM_FORMAT_RGBA5551 = 0x35314152, + /** + * 16-bit BGRA 5551 format, [15:0] B:G:R:A 5:5:5:1 little endian + */ + WL_SHM_FORMAT_BGRA5551 = 0x35314142, + /** + * 16-bit RGB 565 format, [15:0] R:G:B 5:6:5 little endian + */ + WL_SHM_FORMAT_RGB565 = 0x36314752, + /** + * 16-bit BGR 565 format, [15:0] B:G:R 5:6:5 little endian + */ + WL_SHM_FORMAT_BGR565 = 0x36314742, + /** + * 24-bit RGB format, [23:0] R:G:B little endian + */ + WL_SHM_FORMAT_RGB888 = 0x34324752, + /** + * 24-bit BGR format, [23:0] B:G:R little endian + */ + WL_SHM_FORMAT_BGR888 = 0x34324742, + /** + * 32-bit xBGR format, [31:0] x:B:G:R 8:8:8:8 little endian + */ + WL_SHM_FORMAT_XBGR8888 = 0x34324258, + /** + * 32-bit RGBx format, [31:0] R:G:B:x 8:8:8:8 little endian + */ + WL_SHM_FORMAT_RGBX8888 = 0x34325852, + /** + * 32-bit BGRx format, [31:0] B:G:R:x 8:8:8:8 little endian + */ + WL_SHM_FORMAT_BGRX8888 = 0x34325842, + /** + * 32-bit ABGR format, [31:0] A:B:G:R 8:8:8:8 little endian + */ + WL_SHM_FORMAT_ABGR8888 = 0x34324241, + /** + * 32-bit RGBA format, [31:0] R:G:B:A 8:8:8:8 little endian + */ + WL_SHM_FORMAT_RGBA8888 = 0x34324152, + /** + * 32-bit BGRA format, [31:0] B:G:R:A 8:8:8:8 little endian + */ + WL_SHM_FORMAT_BGRA8888 = 0x34324142, + /** + * 32-bit xRGB format, [31:0] x:R:G:B 2:10:10:10 little endian + */ + WL_SHM_FORMAT_XRGB2101010 = 0x30335258, + /** + * 32-bit xBGR format, [31:0] x:B:G:R 2:10:10:10 little endian + */ + WL_SHM_FORMAT_XBGR2101010 = 0x30334258, + /** + * 32-bit RGBx format, [31:0] R:G:B:x 10:10:10:2 little endian + */ + WL_SHM_FORMAT_RGBX1010102 = 0x30335852, + /** + * 32-bit BGRx format, [31:0] B:G:R:x 10:10:10:2 little endian + */ + WL_SHM_FORMAT_BGRX1010102 = 0x30335842, + /** + * 32-bit ARGB format, [31:0] A:R:G:B 2:10:10:10 little endian + */ + WL_SHM_FORMAT_ARGB2101010 = 0x30335241, + /** + * 32-bit ABGR format, [31:0] A:B:G:R 2:10:10:10 little endian + */ + WL_SHM_FORMAT_ABGR2101010 = 0x30334241, + /** + * 32-bit RGBA format, [31:0] R:G:B:A 10:10:10:2 little endian + */ + WL_SHM_FORMAT_RGBA1010102 = 0x30334152, + /** + * 32-bit BGRA format, [31:0] B:G:R:A 10:10:10:2 little endian + */ + WL_SHM_FORMAT_BGRA1010102 = 0x30334142, + /** + * packed YCbCr format, [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian + */ + WL_SHM_FORMAT_YUYV = 0x56595559, + /** + * packed YCbCr format, [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian + */ + WL_SHM_FORMAT_YVYU = 0x55595659, + /** + * packed YCbCr format, [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian + */ + WL_SHM_FORMAT_UYVY = 0x59565955, + /** + * packed YCbCr format, [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian + */ + WL_SHM_FORMAT_VYUY = 0x59555956, + /** + * packed AYCbCr format, [31:0] A:Y:Cb:Cr 8:8:8:8 little endian + */ + WL_SHM_FORMAT_AYUV = 0x56555941, + /** + * 2 plane YCbCr Cr:Cb format, 2x2 subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV12 = 0x3231564e, + /** + * 2 plane YCbCr Cb:Cr format, 2x2 subsampled Cb:Cr plane + */ + WL_SHM_FORMAT_NV21 = 0x3132564e, + /** + * 2 plane YCbCr Cr:Cb format, 2x1 subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV16 = 0x3631564e, + /** + * 2 plane YCbCr Cb:Cr format, 2x1 subsampled Cb:Cr plane + */ + WL_SHM_FORMAT_NV61 = 0x3136564e, + /** + * 3 plane YCbCr format, 4x4 subsampled Cb (1) and Cr (2) planes + */ + WL_SHM_FORMAT_YUV410 = 0x39565559, + /** + * 3 plane YCbCr format, 4x4 subsampled Cr (1) and Cb (2) planes + */ + WL_SHM_FORMAT_YVU410 = 0x39555659, + /** + * 3 plane YCbCr format, 4x1 subsampled Cb (1) and Cr (2) planes + */ + WL_SHM_FORMAT_YUV411 = 0x31315559, + /** + * 3 plane YCbCr format, 4x1 subsampled Cr (1) and Cb (2) planes + */ + WL_SHM_FORMAT_YVU411 = 0x31315659, + /** + * 3 plane YCbCr format, 2x2 subsampled Cb (1) and Cr (2) planes + */ + WL_SHM_FORMAT_YUV420 = 0x32315559, + /** + * 3 plane YCbCr format, 2x2 subsampled Cr (1) and Cb (2) planes + */ + WL_SHM_FORMAT_YVU420 = 0x32315659, + /** + * 3 plane YCbCr format, 2x1 subsampled Cb (1) and Cr (2) planes + */ + WL_SHM_FORMAT_YUV422 = 0x36315559, + /** + * 3 plane YCbCr format, 2x1 subsampled Cr (1) and Cb (2) planes + */ + WL_SHM_FORMAT_YVU422 = 0x36315659, + /** + * 3 plane YCbCr format, non-subsampled Cb (1) and Cr (2) planes + */ + WL_SHM_FORMAT_YUV444 = 0x34325559, + /** + * 3 plane YCbCr format, non-subsampled Cr (1) and Cb (2) planes + */ + WL_SHM_FORMAT_YVU444 = 0x34325659, + /** + * [7:0] R + */ + WL_SHM_FORMAT_R8 = 0x20203852, + /** + * [15:0] R little endian + */ + WL_SHM_FORMAT_R16 = 0x20363152, + /** + * [15:0] R:G 8:8 little endian + */ + WL_SHM_FORMAT_RG88 = 0x38384752, + /** + * [15:0] G:R 8:8 little endian + */ + WL_SHM_FORMAT_GR88 = 0x38385247, + /** + * [31:0] R:G 16:16 little endian + */ + WL_SHM_FORMAT_RG1616 = 0x32334752, + /** + * [31:0] G:R 16:16 little endian + */ + WL_SHM_FORMAT_GR1616 = 0x32335247, + /** + * [63:0] x:R:G:B 16:16:16:16 little endian + */ + WL_SHM_FORMAT_XRGB16161616F = 0x48345258, + /** + * [63:0] x:B:G:R 16:16:16:16 little endian + */ + WL_SHM_FORMAT_XBGR16161616F = 0x48344258, + /** + * [63:0] A:R:G:B 16:16:16:16 little endian + */ + WL_SHM_FORMAT_ARGB16161616F = 0x48345241, + /** + * [63:0] A:B:G:R 16:16:16:16 little endian + */ + WL_SHM_FORMAT_ABGR16161616F = 0x48344241, + /** + * [31:0] X:Y:Cb:Cr 8:8:8:8 little endian + */ + WL_SHM_FORMAT_XYUV8888 = 0x56555958, + /** + * [23:0] Cr:Cb:Y 8:8:8 little endian + */ + WL_SHM_FORMAT_VUY888 = 0x34325556, + /** + * Y followed by U then V, 10:10:10. Non-linear modifier only + */ + WL_SHM_FORMAT_VUY101010 = 0x30335556, + /** + * [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 10:6:10:6:10:6:10:6 little endian per 2 Y pixels + */ + WL_SHM_FORMAT_Y210 = 0x30313259, + /** + * [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 12:4:12:4:12:4:12:4 little endian per 2 Y pixels + */ + WL_SHM_FORMAT_Y212 = 0x32313259, + /** + * [63:0] Cr0:Y1:Cb0:Y0 16:16:16:16 little endian per 2 Y pixels + */ + WL_SHM_FORMAT_Y216 = 0x36313259, + /** + * [31:0] A:Cr:Y:Cb 2:10:10:10 little endian + */ + WL_SHM_FORMAT_Y410 = 0x30313459, + /** + * [63:0] A:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian + */ + WL_SHM_FORMAT_Y412 = 0x32313459, + /** + * [63:0] A:Cr:Y:Cb 16:16:16:16 little endian + */ + WL_SHM_FORMAT_Y416 = 0x36313459, + /** + * [31:0] X:Cr:Y:Cb 2:10:10:10 little endian + */ + WL_SHM_FORMAT_XVYU2101010 = 0x30335658, + /** + * [63:0] X:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian + */ + WL_SHM_FORMAT_XVYU12_16161616 = 0x36335658, + /** + * [63:0] X:Cr:Y:Cb 16:16:16:16 little endian + */ + WL_SHM_FORMAT_XVYU16161616 = 0x38345658, + /** + * [63:0] A3:A2:Y3:0:Cr0:0:Y2:0:A1:A0:Y1:0:Cb0:0:Y0:0 1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian + */ + WL_SHM_FORMAT_Y0L0 = 0x304c3059, + /** + * [63:0] X3:X2:Y3:0:Cr0:0:Y2:0:X1:X0:Y1:0:Cb0:0:Y0:0 1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian + */ + WL_SHM_FORMAT_X0L0 = 0x304c3058, + /** + * [63:0] A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0 1:1:10:10:10:1:1:10:10:10 little endian + */ + WL_SHM_FORMAT_Y0L2 = 0x324c3059, + /** + * [63:0] X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0 1:1:10:10:10:1:1:10:10:10 little endian + */ + WL_SHM_FORMAT_X0L2 = 0x324c3058, + WL_SHM_FORMAT_YUV420_8BIT = 0x38305559, + WL_SHM_FORMAT_YUV420_10BIT = 0x30315559, + WL_SHM_FORMAT_XRGB8888_A8 = 0x38415258, + WL_SHM_FORMAT_XBGR8888_A8 = 0x38414258, + WL_SHM_FORMAT_RGBX8888_A8 = 0x38415852, + WL_SHM_FORMAT_BGRX8888_A8 = 0x38415842, + WL_SHM_FORMAT_RGB888_A8 = 0x38413852, + WL_SHM_FORMAT_BGR888_A8 = 0x38413842, + WL_SHM_FORMAT_RGB565_A8 = 0x38413552, + WL_SHM_FORMAT_BGR565_A8 = 0x38413542, + /** + * non-subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV24 = 0x3432564e, + /** + * non-subsampled Cb:Cr plane + */ + WL_SHM_FORMAT_NV42 = 0x3234564e, + /** + * 2x1 subsampled Cr:Cb plane, 10 bit per channel + */ + WL_SHM_FORMAT_P210 = 0x30313250, + /** + * 2x2 subsampled Cr:Cb plane 10 bits per channel + */ + WL_SHM_FORMAT_P010 = 0x30313050, + /** + * 2x2 subsampled Cr:Cb plane 12 bits per channel + */ + WL_SHM_FORMAT_P012 = 0x32313050, + /** + * 2x2 subsampled Cr:Cb plane 16 bits per channel + */ + WL_SHM_FORMAT_P016 = 0x36313050, + /** + * [63:0] A:x:B:x:G:x:R:x 10:6:10:6:10:6:10:6 little endian + */ + WL_SHM_FORMAT_AXBXGXRX106106106106 = 0x30314241, + /** + * 2x2 subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV15 = 0x3531564e, + WL_SHM_FORMAT_Q410 = 0x30313451, + WL_SHM_FORMAT_Q401 = 0x31303451, + /** + * [63:0] x:R:G:B 16:16:16:16 little endian + */ + WL_SHM_FORMAT_XRGB16161616 = 0x38345258, + /** + * [63:0] x:B:G:R 16:16:16:16 little endian + */ + WL_SHM_FORMAT_XBGR16161616 = 0x38344258, + /** + * [63:0] A:R:G:B 16:16:16:16 little endian + */ + WL_SHM_FORMAT_ARGB16161616 = 0x38345241, + /** + * [63:0] A:B:G:R 16:16:16:16 little endian + */ + WL_SHM_FORMAT_ABGR16161616 = 0x38344241, + /** + * [7:0] C0:C1:C2:C3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte + */ + WL_SHM_FORMAT_C1 = 0x20203143, + /** + * [7:0] C0:C1:C2:C3 2:2:2:2 four pixels/byte + */ + WL_SHM_FORMAT_C2 = 0x20203243, + /** + * [7:0] C0:C1 4:4 two pixels/byte + */ + WL_SHM_FORMAT_C4 = 0x20203443, + /** + * [7:0] D0:D1:D2:D3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte + */ + WL_SHM_FORMAT_D1 = 0x20203144, + /** + * [7:0] D0:D1:D2:D3 2:2:2:2 four pixels/byte + */ + WL_SHM_FORMAT_D2 = 0x20203244, + /** + * [7:0] D0:D1 4:4 two pixels/byte + */ + WL_SHM_FORMAT_D4 = 0x20203444, + /** + * [7:0] D + */ + WL_SHM_FORMAT_D8 = 0x20203844, + /** + * [7:0] R0:R1:R2:R3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte + */ + WL_SHM_FORMAT_R1 = 0x20203152, + /** + * [7:0] R0:R1:R2:R3 2:2:2:2 four pixels/byte + */ + WL_SHM_FORMAT_R2 = 0x20203252, + /** + * [7:0] R0:R1 4:4 two pixels/byte + */ + WL_SHM_FORMAT_R4 = 0x20203452, + /** + * [15:0] x:R 6:10 little endian + */ + WL_SHM_FORMAT_R10 = 0x20303152, + /** + * [15:0] x:R 4:12 little endian + */ + WL_SHM_FORMAT_R12 = 0x20323152, + /** + * [31:0] A:Cr:Cb:Y 8:8:8:8 little endian + */ + WL_SHM_FORMAT_AVUY8888 = 0x59555641, + /** + * [31:0] X:Cr:Cb:Y 8:8:8:8 little endian + */ + WL_SHM_FORMAT_XVUY8888 = 0x59555658, + /** + * 2x2 subsampled Cr:Cb plane 10 bits per channel packed + */ + WL_SHM_FORMAT_P030 = 0x30333050, + /** + * [47:0] R:G:B 16:16:16 little endian + */ + WL_SHM_FORMAT_RGB161616 = 0x38344752, + /** + * [47:0] B:G:R 16:16:16 little endian + */ + WL_SHM_FORMAT_BGR161616 = 0x38344742, + /** + * [15:0] R 16 little endian + */ + WL_SHM_FORMAT_R16F = 0x48202052, + /** + * [31:0] G:R 16:16 little endian + */ + WL_SHM_FORMAT_GR1616F = 0x48205247, + /** + * [47:0] B:G:R 16:16:16 little endian + */ + WL_SHM_FORMAT_BGR161616F = 0x48524742, + /** + * [31:0] R 32 little endian + */ + WL_SHM_FORMAT_R32F = 0x46202052, + /** + * [63:0] G:R 32:32 little endian + */ + WL_SHM_FORMAT_GR3232F = 0x46205247, + /** + * [95:0] B:G:R 32:32:32 little endian + */ + WL_SHM_FORMAT_BGR323232F = 0x46524742, + /** + * [127:0] A:B:G:R 32:32:32:32 little endian + */ + WL_SHM_FORMAT_ABGR32323232F = 0x46384241, + /** + * 2x1 subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV20 = 0x3032564e, + /** + * non-subsampled Cr:Cb plane + */ + WL_SHM_FORMAT_NV30 = 0x3033564e, + /** + * 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel + */ + WL_SHM_FORMAT_S010 = 0x30313053, + /** + * 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel + */ + WL_SHM_FORMAT_S210 = 0x30313253, + /** + * non-subsampled Cb (1) and Cr (2) planes 10 bits per channel + */ + WL_SHM_FORMAT_S410 = 0x30313453, + /** + * 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel + */ + WL_SHM_FORMAT_S012 = 0x32313053, + /** + * 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel + */ + WL_SHM_FORMAT_S212 = 0x32313253, + /** + * non-subsampled Cb (1) and Cr (2) planes 12 bits per channel + */ + WL_SHM_FORMAT_S412 = 0x32313453, + /** + * 2x2 subsampled Cb (1) and Cr (2) planes 16 bits per channel + */ + WL_SHM_FORMAT_S016 = 0x36313053, + /** + * 2x1 subsampled Cb (1) and Cr (2) planes 16 bits per channel + */ + WL_SHM_FORMAT_S216 = 0x36313253, + /** + * non-subsampled Cb (1) and Cr (2) planes 16 bits per channel + */ + WL_SHM_FORMAT_S416 = 0x36313453, + /** + * [31:0] x:Cr:Cb:Y 2:10:10:10 little endian + */ + WL_SHM_FORMAT_XVUY2101010 = 0x30335958, + /** + * 2x1 subsampled Cr:Cb plane 10 bits per channel packed + */ + WL_SHM_FORMAT_P230 = 0x30333250, + WL_SHM_FORMAT_T430 = 0x30333454, + /** + * 8-bit Y-only + */ + WL_SHM_FORMAT_Y8 = 0x59455247, + /** + * [31:0] x:Y2:Y1:Y0 2:10:10:10 little endian + */ + WL_SHM_FORMAT_XYYY2101010 = 0x34415059, +}; +#endif /* WL_SHM_FORMAT_ENUM */ + +#ifndef WL_SHM_FORMAT_ENUM_IS_VALID +#define WL_SHM_FORMAT_ENUM_IS_VALID +/** + * @ingroup iface_wl_shm + * Validate a wl_shm format value. + * + * @return true on success, false on error. + * @ref wl_shm_format + */ +static inline bool +wl_shm_format_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SHM_FORMAT_ARGB8888: + return version >= 1; + case WL_SHM_FORMAT_XRGB8888: + return version >= 1; + case WL_SHM_FORMAT_C8: + return version >= 1; + case WL_SHM_FORMAT_RGB332: + return version >= 1; + case WL_SHM_FORMAT_BGR233: + return version >= 1; + case WL_SHM_FORMAT_XRGB4444: + return version >= 1; + case WL_SHM_FORMAT_XBGR4444: + return version >= 1; + case WL_SHM_FORMAT_RGBX4444: + return version >= 1; + case WL_SHM_FORMAT_BGRX4444: + return version >= 1; + case WL_SHM_FORMAT_ARGB4444: + return version >= 1; + case WL_SHM_FORMAT_ABGR4444: + return version >= 1; + case WL_SHM_FORMAT_RGBA4444: + return version >= 1; + case WL_SHM_FORMAT_BGRA4444: + return version >= 1; + case WL_SHM_FORMAT_XRGB1555: + return version >= 1; + case WL_SHM_FORMAT_XBGR1555: + return version >= 1; + case WL_SHM_FORMAT_RGBX5551: + return version >= 1; + case WL_SHM_FORMAT_BGRX5551: + return version >= 1; + case WL_SHM_FORMAT_ARGB1555: + return version >= 1; + case WL_SHM_FORMAT_ABGR1555: + return version >= 1; + case WL_SHM_FORMAT_RGBA5551: + return version >= 1; + case WL_SHM_FORMAT_BGRA5551: + return version >= 1; + case WL_SHM_FORMAT_RGB565: + return version >= 1; + case WL_SHM_FORMAT_BGR565: + return version >= 1; + case WL_SHM_FORMAT_RGB888: + return version >= 1; + case WL_SHM_FORMAT_BGR888: + return version >= 1; + case WL_SHM_FORMAT_XBGR8888: + return version >= 1; + case WL_SHM_FORMAT_RGBX8888: + return version >= 1; + case WL_SHM_FORMAT_BGRX8888: + return version >= 1; + case WL_SHM_FORMAT_ABGR8888: + return version >= 1; + case WL_SHM_FORMAT_RGBA8888: + return version >= 1; + case WL_SHM_FORMAT_BGRA8888: + return version >= 1; + case WL_SHM_FORMAT_XRGB2101010: + return version >= 1; + case WL_SHM_FORMAT_XBGR2101010: + return version >= 1; + case WL_SHM_FORMAT_RGBX1010102: + return version >= 1; + case WL_SHM_FORMAT_BGRX1010102: + return version >= 1; + case WL_SHM_FORMAT_ARGB2101010: + return version >= 1; + case WL_SHM_FORMAT_ABGR2101010: + return version >= 1; + case WL_SHM_FORMAT_RGBA1010102: + return version >= 1; + case WL_SHM_FORMAT_BGRA1010102: + return version >= 1; + case WL_SHM_FORMAT_YUYV: + return version >= 1; + case WL_SHM_FORMAT_YVYU: + return version >= 1; + case WL_SHM_FORMAT_UYVY: + return version >= 1; + case WL_SHM_FORMAT_VYUY: + return version >= 1; + case WL_SHM_FORMAT_AYUV: + return version >= 1; + case WL_SHM_FORMAT_NV12: + return version >= 1; + case WL_SHM_FORMAT_NV21: + return version >= 1; + case WL_SHM_FORMAT_NV16: + return version >= 1; + case WL_SHM_FORMAT_NV61: + return version >= 1; + case WL_SHM_FORMAT_YUV410: + return version >= 1; + case WL_SHM_FORMAT_YVU410: + return version >= 1; + case WL_SHM_FORMAT_YUV411: + return version >= 1; + case WL_SHM_FORMAT_YVU411: + return version >= 1; + case WL_SHM_FORMAT_YUV420: + return version >= 1; + case WL_SHM_FORMAT_YVU420: + return version >= 1; + case WL_SHM_FORMAT_YUV422: + return version >= 1; + case WL_SHM_FORMAT_YVU422: + return version >= 1; + case WL_SHM_FORMAT_YUV444: + return version >= 1; + case WL_SHM_FORMAT_YVU444: + return version >= 1; + case WL_SHM_FORMAT_R8: + return version >= 1; + case WL_SHM_FORMAT_R16: + return version >= 1; + case WL_SHM_FORMAT_RG88: + return version >= 1; + case WL_SHM_FORMAT_GR88: + return version >= 1; + case WL_SHM_FORMAT_RG1616: + return version >= 1; + case WL_SHM_FORMAT_GR1616: + return version >= 1; + case WL_SHM_FORMAT_XRGB16161616F: + return version >= 1; + case WL_SHM_FORMAT_XBGR16161616F: + return version >= 1; + case WL_SHM_FORMAT_ARGB16161616F: + return version >= 1; + case WL_SHM_FORMAT_ABGR16161616F: + return version >= 1; + case WL_SHM_FORMAT_XYUV8888: + return version >= 1; + case WL_SHM_FORMAT_VUY888: + return version >= 1; + case WL_SHM_FORMAT_VUY101010: + return version >= 1; + case WL_SHM_FORMAT_Y210: + return version >= 1; + case WL_SHM_FORMAT_Y212: + return version >= 1; + case WL_SHM_FORMAT_Y216: + return version >= 1; + case WL_SHM_FORMAT_Y410: + return version >= 1; + case WL_SHM_FORMAT_Y412: + return version >= 1; + case WL_SHM_FORMAT_Y416: + return version >= 1; + case WL_SHM_FORMAT_XVYU2101010: + return version >= 1; + case WL_SHM_FORMAT_XVYU12_16161616: + return version >= 1; + case WL_SHM_FORMAT_XVYU16161616: + return version >= 1; + case WL_SHM_FORMAT_Y0L0: + return version >= 1; + case WL_SHM_FORMAT_X0L0: + return version >= 1; + case WL_SHM_FORMAT_Y0L2: + return version >= 1; + case WL_SHM_FORMAT_X0L2: + return version >= 1; + case WL_SHM_FORMAT_YUV420_8BIT: + return version >= 1; + case WL_SHM_FORMAT_YUV420_10BIT: + return version >= 1; + case WL_SHM_FORMAT_XRGB8888_A8: + return version >= 1; + case WL_SHM_FORMAT_XBGR8888_A8: + return version >= 1; + case WL_SHM_FORMAT_RGBX8888_A8: + return version >= 1; + case WL_SHM_FORMAT_BGRX8888_A8: + return version >= 1; + case WL_SHM_FORMAT_RGB888_A8: + return version >= 1; + case WL_SHM_FORMAT_BGR888_A8: + return version >= 1; + case WL_SHM_FORMAT_RGB565_A8: + return version >= 1; + case WL_SHM_FORMAT_BGR565_A8: + return version >= 1; + case WL_SHM_FORMAT_NV24: + return version >= 1; + case WL_SHM_FORMAT_NV42: + return version >= 1; + case WL_SHM_FORMAT_P210: + return version >= 1; + case WL_SHM_FORMAT_P010: + return version >= 1; + case WL_SHM_FORMAT_P012: + return version >= 1; + case WL_SHM_FORMAT_P016: + return version >= 1; + case WL_SHM_FORMAT_AXBXGXRX106106106106: + return version >= 1; + case WL_SHM_FORMAT_NV15: + return version >= 1; + case WL_SHM_FORMAT_Q410: + return version >= 1; + case WL_SHM_FORMAT_Q401: + return version >= 1; + case WL_SHM_FORMAT_XRGB16161616: + return version >= 1; + case WL_SHM_FORMAT_XBGR16161616: + return version >= 1; + case WL_SHM_FORMAT_ARGB16161616: + return version >= 1; + case WL_SHM_FORMAT_ABGR16161616: + return version >= 1; + case WL_SHM_FORMAT_C1: + return version >= 1; + case WL_SHM_FORMAT_C2: + return version >= 1; + case WL_SHM_FORMAT_C4: + return version >= 1; + case WL_SHM_FORMAT_D1: + return version >= 1; + case WL_SHM_FORMAT_D2: + return version >= 1; + case WL_SHM_FORMAT_D4: + return version >= 1; + case WL_SHM_FORMAT_D8: + return version >= 1; + case WL_SHM_FORMAT_R1: + return version >= 1; + case WL_SHM_FORMAT_R2: + return version >= 1; + case WL_SHM_FORMAT_R4: + return version >= 1; + case WL_SHM_FORMAT_R10: + return version >= 1; + case WL_SHM_FORMAT_R12: + return version >= 1; + case WL_SHM_FORMAT_AVUY8888: + return version >= 1; + case WL_SHM_FORMAT_XVUY8888: + return version >= 1; + case WL_SHM_FORMAT_P030: + return version >= 1; + case WL_SHM_FORMAT_RGB161616: + return version >= 1; + case WL_SHM_FORMAT_BGR161616: + return version >= 1; + case WL_SHM_FORMAT_R16F: + return version >= 1; + case WL_SHM_FORMAT_GR1616F: + return version >= 1; + case WL_SHM_FORMAT_BGR161616F: + return version >= 1; + case WL_SHM_FORMAT_R32F: + return version >= 1; + case WL_SHM_FORMAT_GR3232F: + return version >= 1; + case WL_SHM_FORMAT_BGR323232F: + return version >= 1; + case WL_SHM_FORMAT_ABGR32323232F: + return version >= 1; + case WL_SHM_FORMAT_NV20: + return version >= 1; + case WL_SHM_FORMAT_NV30: + return version >= 1; + case WL_SHM_FORMAT_S010: + return version >= 1; + case WL_SHM_FORMAT_S210: + return version >= 1; + case WL_SHM_FORMAT_S410: + return version >= 1; + case WL_SHM_FORMAT_S012: + return version >= 1; + case WL_SHM_FORMAT_S212: + return version >= 1; + case WL_SHM_FORMAT_S412: + return version >= 1; + case WL_SHM_FORMAT_S016: + return version >= 1; + case WL_SHM_FORMAT_S216: + return version >= 1; + case WL_SHM_FORMAT_S416: + return version >= 1; + case WL_SHM_FORMAT_XVUY2101010: + return version >= 1; + case WL_SHM_FORMAT_P230: + return version >= 1; + case WL_SHM_FORMAT_T430: + return version >= 1; + case WL_SHM_FORMAT_Y8: + return version >= 1; + case WL_SHM_FORMAT_XYYY2101010: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SHM_FORMAT_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_shm + * @struct wl_shm_interface + */ +struct wl_shm_interface { + /** + * create a shm pool + * + * Create a new wl_shm_pool object. + * + * The pool can be used to create shared memory based buffer + * objects. The server will mmap size bytes of the passed file + * descriptor, to use as backing memory for the pool. + * @param id pool to create + * @param fd file descriptor for the pool + * @param size pool size, in bytes + */ + void (*create_pool)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + int32_t fd, + int32_t size); + /** + * release the shm object + * + * Using this request a client can tell the server that it is not + * going to use the shm object anymore. + * + * Objects created via this interface remain unaffected. + * @since 2 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_SHM_FORMAT 0 + +/** + * @ingroup iface_wl_shm + */ +#define WL_SHM_FORMAT_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_shm + */ +#define WL_SHM_CREATE_POOL_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shm + */ +#define WL_SHM_RELEASE_SINCE_VERSION 2 + +/** + * @ingroup iface_wl_shm + * Sends an format event to the client owning the resource. + * @param resource_ The client's resource + * @param format buffer pixel format + */ +static inline void +wl_shm_send_format(struct wl_resource *resource_, uint32_t format) +{ + wl_resource_post_event(resource_, WL_SHM_FORMAT, format); +} + +/** + * @ingroup iface_wl_buffer + * @struct wl_buffer_interface + */ +struct wl_buffer_interface { + /** + * destroy a buffer + * + * Destroy a buffer. If and how you need to release the backing + * storage is defined by the buffer factory interface. + * + * For possible side-effects to a surface, see wl_surface.attach. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_BUFFER_RELEASE 0 + +/** + * @ingroup iface_wl_buffer + */ +#define WL_BUFFER_RELEASE_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_buffer + */ +#define WL_BUFFER_DESTROY_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_buffer + * Sends an release event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_buffer_send_release(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_BUFFER_RELEASE); +} + +#ifndef WL_DATA_OFFER_ERROR_ENUM +#define WL_DATA_OFFER_ERROR_ENUM +enum wl_data_offer_error { + /** + * finish request was called untimely + */ + WL_DATA_OFFER_ERROR_INVALID_FINISH = 0, + /** + * action mask contains invalid values + */ + WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK = 1, + /** + * action argument has an invalid value + */ + WL_DATA_OFFER_ERROR_INVALID_ACTION = 2, + /** + * offer doesn't accept this request + */ + WL_DATA_OFFER_ERROR_INVALID_OFFER = 3, +}; +#endif /* WL_DATA_OFFER_ERROR_ENUM */ + +#ifndef WL_DATA_OFFER_ERROR_ENUM_IS_VALID +#define WL_DATA_OFFER_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_data_offer + * Validate a wl_data_offer error value. + * + * @return true on success, false on error. + * @ref wl_data_offer_error + */ +static inline bool +wl_data_offer_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_DATA_OFFER_ERROR_INVALID_FINISH: + return version >= 1; + case WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK: + return version >= 1; + case WL_DATA_OFFER_ERROR_INVALID_ACTION: + return version >= 1; + case WL_DATA_OFFER_ERROR_INVALID_OFFER: + return version >= 1; + default: + return false; + } +} +#endif /* WL_DATA_OFFER_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_data_offer + * @struct wl_data_offer_interface + */ +struct wl_data_offer_interface { + /** + * accept one of the offered mime types + * + * Indicate that the client can accept the given mime type, or + * NULL for not accepted. + * + * For objects of version 2 or older, this request is used by the + * client to give feedback whether the client can receive the given + * mime type, or NULL if none is accepted; the feedback does not + * determine whether the drag-and-drop operation succeeds or not. + * + * For objects of version 3 or newer, this request determines the + * final result of the drag-and-drop operation. If the end result + * is that no mime types were accepted, the drag-and-drop operation + * will be cancelled and the corresponding drag source will receive + * wl_data_source.cancelled. Clients may still use this event in + * conjunction with wl_data_source.action for feedback. + * @param serial serial number of the accept request + * @param mime_type mime type accepted by the client + */ + void (*accept)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + const char *mime_type); + /** + * request that the data is transferred + * + * To transfer the offered data, the client issues this request + * and indicates the mime type it wants to receive. The transfer + * happens through the passed file descriptor (typically created + * with the pipe system call). The source client writes the data in + * the mime type representation requested and then closes the file + * descriptor. + * + * The receiving client reads from the read end of the pipe until + * EOF and then closes its end, at which point the transfer is + * complete. + * + * This request may happen multiple times for different mime types, + * both before and after wl_data_device.drop. Drag-and-drop + * destination clients may preemptively fetch data or examine it + * more closely to determine acceptance. + * @param mime_type mime type desired by receiver + * @param fd file descriptor for data transfer + */ + void (*receive)(struct wl_client *client, + struct wl_resource *resource, + const char *mime_type, + int32_t fd); + /** + * destroy data offer + * + * Destroy the data offer. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * the offer will no longer be used + * + * Notifies the compositor that the drag destination successfully + * finished the drag-and-drop operation. + * + * Upon receiving this request, the compositor will emit + * wl_data_source.dnd_finished on the drag source client. + * + * It is a client error to perform other requests than + * wl_data_offer.destroy after this one. It is also an error to + * perform this request after a NULL mime type has been set in + * wl_data_offer.accept or no action was received through + * wl_data_offer.action. + * + * If wl_data_offer.finish request is received for a non drag and + * drop operation, the invalid_finish protocol error is raised. + * @since 3 + */ + void (*finish)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the available/preferred drag-and-drop actions + * + * Sets the actions that the destination side client supports for + * this operation. This request may trigger the emission of + * wl_data_source.action and wl_data_offer.action events if the + * compositor needs to change the selected action. + * + * This request can be called multiple times throughout the + * drag-and-drop operation, typically in response to + * wl_data_device.enter or wl_data_device.motion events. + * + * This request determines the final result of the drag-and-drop + * operation. If the end result is that no action is accepted, the + * drag source will receive wl_data_source.cancelled. + * + * The dnd_actions argument must contain only values expressed in + * the wl_data_device_manager.dnd_actions enum, and the + * preferred_action argument must only contain one of those values + * set, otherwise it will result in a protocol error. + * + * While managing an "ask" action, the destination drag-and-drop + * client may perform further wl_data_offer.receive requests, and + * is expected to perform one last wl_data_offer.set_actions + * request with a preferred action other than "ask" (and optionally + * wl_data_offer.accept) before requesting wl_data_offer.finish, in + * order to convey the action selected by the user. If the + * preferred action is not in the wl_data_offer.source_actions + * mask, an error will be raised. + * + * If the "ask" action is dismissed (e.g. user cancellation), the + * client is expected to perform wl_data_offer.destroy right away. + * + * This request can only be made on drag-and-drop offers, a + * protocol error will be raised otherwise. + * @param dnd_actions actions supported by the destination client + * @param preferred_action action preferred by the destination client + * @since 3 + */ + void (*set_actions)(struct wl_client *client, + struct wl_resource *resource, + uint32_t dnd_actions, + uint32_t preferred_action); +}; + +#define WL_DATA_OFFER_OFFER 0 +#define WL_DATA_OFFER_SOURCE_ACTIONS 1 +#define WL_DATA_OFFER_ACTION 2 + +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_OFFER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_SOURCE_ACTIONS_SINCE_VERSION 3 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_ACTION_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_ACCEPT_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_RECEIVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_FINISH_SINCE_VERSION 3 +/** + * @ingroup iface_wl_data_offer + */ +#define WL_DATA_OFFER_SET_ACTIONS_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_data_offer + * Sends an offer event to the client owning the resource. + * @param resource_ The client's resource + * @param mime_type offered mime type + */ +static inline void +wl_data_offer_send_offer(struct wl_resource *resource_, const char *mime_type) +{ + wl_resource_post_event(resource_, WL_DATA_OFFER_OFFER, mime_type); +} + +/** + * @ingroup iface_wl_data_offer + * Sends an source_actions event to the client owning the resource. + * @param resource_ The client's resource + * @param source_actions actions offered by the data source + */ +static inline void +wl_data_offer_send_source_actions(struct wl_resource *resource_, uint32_t source_actions) +{ + wl_resource_post_event(resource_, WL_DATA_OFFER_SOURCE_ACTIONS, source_actions); +} + +/** + * @ingroup iface_wl_data_offer + * Sends an action event to the client owning the resource. + * @param resource_ The client's resource + * @param dnd_action action selected by the compositor + */ +static inline void +wl_data_offer_send_action(struct wl_resource *resource_, uint32_t dnd_action) +{ + wl_resource_post_event(resource_, WL_DATA_OFFER_ACTION, dnd_action); +} + +#ifndef WL_DATA_SOURCE_ERROR_ENUM +#define WL_DATA_SOURCE_ERROR_ENUM +enum wl_data_source_error { + /** + * action mask contains invalid values + */ + WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK = 0, + /** + * source doesn't accept this request + */ + WL_DATA_SOURCE_ERROR_INVALID_SOURCE = 1, +}; +#endif /* WL_DATA_SOURCE_ERROR_ENUM */ + +#ifndef WL_DATA_SOURCE_ERROR_ENUM_IS_VALID +#define WL_DATA_SOURCE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_data_source + * Validate a wl_data_source error value. + * + * @return true on success, false on error. + * @ref wl_data_source_error + */ +static inline bool +wl_data_source_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK: + return version >= 1; + case WL_DATA_SOURCE_ERROR_INVALID_SOURCE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_DATA_SOURCE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_data_source + * @struct wl_data_source_interface + */ +struct wl_data_source_interface { + /** + * add an offered mime type + * + * This request adds a mime type to the set of mime types + * advertised to targets. Can be called several times to offer + * multiple types. + * @param mime_type mime type offered by the data source + */ + void (*offer)(struct wl_client *client, + struct wl_resource *resource, + const char *mime_type); + /** + * destroy the data source + * + * Destroy the data source. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the available drag-and-drop actions + * + * Sets the actions that the source side client supports for this + * operation. This request may trigger wl_data_source.action and + * wl_data_offer.action events if the compositor needs to change + * the selected action. + * + * The dnd_actions argument must contain only values expressed in + * the wl_data_device_manager.dnd_actions enum, otherwise it will + * result in a protocol error. + * + * This request must be made once only, and can only be made on + * sources used in drag-and-drop, so it must be performed before + * wl_data_device.start_drag. Attempting to use the source other + * than for drag-and-drop will raise a protocol error. + * @param dnd_actions actions supported by the data source + * @since 3 + */ + void (*set_actions)(struct wl_client *client, + struct wl_resource *resource, + uint32_t dnd_actions); +}; + +#define WL_DATA_SOURCE_TARGET 0 +#define WL_DATA_SOURCE_SEND 1 +#define WL_DATA_SOURCE_CANCELLED 2 +#define WL_DATA_SOURCE_DND_DROP_PERFORMED 3 +#define WL_DATA_SOURCE_DND_FINISHED 4 +#define WL_DATA_SOURCE_ACTION 5 + +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_TARGET_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_SEND_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_CANCELLED_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION 3 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_DND_FINISHED_SINCE_VERSION 3 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_ACTION_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_OFFER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_source + */ +#define WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_data_source + * Sends an target event to the client owning the resource. + * @param resource_ The client's resource + * @param mime_type mime type accepted by the target + */ +static inline void +wl_data_source_send_target(struct wl_resource *resource_, const char *mime_type) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_TARGET, mime_type); +} + +/** + * @ingroup iface_wl_data_source + * Sends an send event to the client owning the resource. + * @param resource_ The client's resource + * @param mime_type mime type for the data + * @param fd file descriptor for the data + */ +static inline void +wl_data_source_send_send(struct wl_resource *resource_, const char *mime_type, int32_t fd) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_SEND, mime_type, fd); +} + +/** + * @ingroup iface_wl_data_source + * Sends an cancelled event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_data_source_send_cancelled(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_CANCELLED); +} + +/** + * @ingroup iface_wl_data_source + * Sends an dnd_drop_performed event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_data_source_send_dnd_drop_performed(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_DND_DROP_PERFORMED); +} + +/** + * @ingroup iface_wl_data_source + * Sends an dnd_finished event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_data_source_send_dnd_finished(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_DND_FINISHED); +} + +/** + * @ingroup iface_wl_data_source + * Sends an action event to the client owning the resource. + * @param resource_ The client's resource + * @param dnd_action action selected by the compositor + */ +static inline void +wl_data_source_send_action(struct wl_resource *resource_, uint32_t dnd_action) +{ + wl_resource_post_event(resource_, WL_DATA_SOURCE_ACTION, dnd_action); +} + +#ifndef WL_DATA_DEVICE_ERROR_ENUM +#define WL_DATA_DEVICE_ERROR_ENUM +enum wl_data_device_error { + /** + * given wl_surface has another role + */ + WL_DATA_DEVICE_ERROR_ROLE = 0, + /** + * source has already been used + */ + WL_DATA_DEVICE_ERROR_USED_SOURCE = 1, +}; +#endif /* WL_DATA_DEVICE_ERROR_ENUM */ + +#ifndef WL_DATA_DEVICE_ERROR_ENUM_IS_VALID +#define WL_DATA_DEVICE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_data_device + * Validate a wl_data_device error value. + * + * @return true on success, false on error. + * @ref wl_data_device_error + */ +static inline bool +wl_data_device_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_DATA_DEVICE_ERROR_ROLE: + return version >= 1; + case WL_DATA_DEVICE_ERROR_USED_SOURCE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_DATA_DEVICE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_data_device + * @struct wl_data_device_interface + */ +struct wl_data_device_interface { + /** + * start drag-and-drop operation + * + * This request asks the compositor to start a drag-and-drop + * operation on behalf of the client. + * + * The source argument is the data source that provides the data + * for the eventual data transfer. If source is NULL, enter, leave + * and motion events are sent only to the client that initiated the + * drag and the client is expected to handle the data passing + * internally. If source is destroyed, the drag-and-drop session + * will be cancelled. + * + * The origin surface is the surface where the drag originates and + * the client must have an active implicit grab that matches the + * serial. + * + * The icon surface is an optional (can be NULL) surface that + * provides an icon to be moved around with the cursor. Initially, + * the top-left corner of the icon surface is placed at the cursor + * hotspot, but subsequent wl_surface.offset requests can move the + * relative position. Attach requests must be confirmed with + * wl_surface.commit as usual. The icon surface is given the role + * of a drag-and-drop icon. If the icon surface already has another + * role, it raises a protocol error. + * + * The input region is ignored for wl_surfaces with the role of a + * drag-and-drop icon. + * + * The given source may not be used in any further set_selection or + * start_drag requests. Attempting to reuse a previously-used + * source may send a used_source error. + * @param source data source for the eventual transfer + * @param origin surface where the drag originates + * @param icon drag-and-drop icon surface + * @param serial serial number of the implicit grab on the origin + */ + void (*start_drag)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *source, + struct wl_resource *origin, + struct wl_resource *icon, + uint32_t serial); + /** + * copy data to the selection + * + * This request asks the compositor to set the selection to the + * data from the source on behalf of the client. + * + * To unset the selection, set the source to NULL. + * + * The given source may not be used in any further set_selection or + * start_drag requests. Attempting to reuse a previously-used + * source may send a used_source error. + * @param source data source for the selection + * @param serial serial number of the event that triggered this request + */ + void (*set_selection)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *source, + uint32_t serial); + /** + * destroy data device + * + * This request destroys the data device. + * @since 2 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_DATA_DEVICE_DATA_OFFER 0 +#define WL_DATA_DEVICE_ENTER 1 +#define WL_DATA_DEVICE_LEAVE 2 +#define WL_DATA_DEVICE_MOTION 3 +#define WL_DATA_DEVICE_DROP 4 +#define WL_DATA_DEVICE_SELECTION 5 + +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_DATA_OFFER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_MOTION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_DROP_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_SELECTION_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_START_DRAG_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_SET_SELECTION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device + */ +#define WL_DATA_DEVICE_RELEASE_SINCE_VERSION 2 + +/** + * @ingroup iface_wl_data_device + * Sends an data_offer event to the client owning the resource. + * @param resource_ The client's resource + * @param id the new data_offer object + */ +static inline void +wl_data_device_send_data_offer(struct wl_resource *resource_, struct wl_resource *id) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_DATA_OFFER, id); +} + +/** + * @ingroup iface_wl_data_device + * Sends an enter event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the enter event + * @param surface client surface entered + * @param x surface-local x coordinate + * @param y surface-local y coordinate + * @param id source data_offer object + */ +static inline void +wl_data_device_send_enter(struct wl_resource *resource_, uint32_t serial, struct wl_resource *surface, wl_fixed_t x, wl_fixed_t y, struct wl_resource *id) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_ENTER, serial, surface, x, y, id); +} + +/** + * @ingroup iface_wl_data_device + * Sends an leave event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_data_device_send_leave(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_LEAVE); +} + +/** + * @ingroup iface_wl_data_device + * Sends an motion event to the client owning the resource. + * @param resource_ The client's resource + * @param time timestamp with millisecond granularity + * @param x surface-local x coordinate + * @param y surface-local y coordinate + */ +static inline void +wl_data_device_send_motion(struct wl_resource *resource_, uint32_t time, wl_fixed_t x, wl_fixed_t y) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_MOTION, time, x, y); +} + +/** + * @ingroup iface_wl_data_device + * Sends an drop event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_data_device_send_drop(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_DROP); +} + +/** + * @ingroup iface_wl_data_device + * Sends an selection event to the client owning the resource. + * @param resource_ The client's resource + * @param id selection data_offer object + */ +static inline void +wl_data_device_send_selection(struct wl_resource *resource_, struct wl_resource *id) +{ + wl_resource_post_event(resource_, WL_DATA_DEVICE_SELECTION, id); +} + +#ifndef WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM +#define WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM +/** + * @ingroup iface_wl_data_device_manager + * drag and drop actions + * + * This is a bitmask of the available/preferred actions in a + * drag-and-drop operation. + * + * In the compositor, the selected action is a result of matching the + * actions offered by the source and destination sides. "action" events + * with a "none" action will be sent to both source and destination if + * there is no match. All further checks will effectively happen on + * (source actions ∩ destination actions). + * + * In addition, compositors may also pick different actions in + * reaction to key modifiers being pressed. One common design that + * is used in major toolkits (and the behavior recommended for + * compositors) is: + * + * - If no modifiers are pressed, the first match (in bit order) + * will be used. + * - Pressing Shift selects "move", if enabled in the mask. + * - Pressing Control selects "copy", if enabled in the mask. + * + * Behavior beyond that is considered implementation-dependent. + * Compositors may for example bind other modifiers (like Alt/Meta) + * or drags initiated with other buttons than BTN_LEFT to specific + * actions (e.g. "ask"). + */ +enum wl_data_device_manager_dnd_action { + /** + * no action + */ + WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE = 0, + /** + * copy action + */ + WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY = 1, + /** + * move action + */ + WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE = 2, + /** + * ask action + */ + WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK = 4, +}; +#endif /* WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM */ + +#ifndef WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM_IS_VALID +#define WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM_IS_VALID +/** + * @ingroup iface_wl_data_device_manager + * Validate a wl_data_device_manager dnd_action value. + * + * @return true on success, false on error. + * @ref wl_data_device_manager_dnd_action + */ +static inline bool +wl_data_device_manager_dnd_action_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE; + if (version >= 1) + valid |= WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY; + if (version >= 1) + valid |= WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE; + if (version >= 1) + valid |= WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK; + return (value & ~valid) == 0; +} +#endif /* WL_DATA_DEVICE_MANAGER_DND_ACTION_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_data_device_manager + * @struct wl_data_device_manager_interface + */ +struct wl_data_device_manager_interface { + /** + * create a new data source + * + * Create a new data source. + * @param id data source to create + */ + void (*create_data_source)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * create a new data device + * + * Create a new data device for a given seat. + * @param id data device to create + * @param seat seat associated with the data device + */ + void (*get_data_device)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *seat); + /** + * destroy wl_data_device_manager + * + * This request destroys the wl_data_device_manager. This has no + * effect on any other objects. + * @since 4 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_wl_data_device_manager + */ +#define WL_DATA_DEVICE_MANAGER_CREATE_DATA_SOURCE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device_manager + */ +#define WL_DATA_DEVICE_MANAGER_GET_DATA_DEVICE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_data_device_manager + */ +#define WL_DATA_DEVICE_MANAGER_RELEASE_SINCE_VERSION 4 + +#ifndef WL_SHELL_ERROR_ENUM +#define WL_SHELL_ERROR_ENUM +enum wl_shell_error { + /** + * given wl_surface has another role + */ + WL_SHELL_ERROR_ROLE = 0, +}; +#endif /* WL_SHELL_ERROR_ENUM */ + +#ifndef WL_SHELL_ERROR_ENUM_IS_VALID +#define WL_SHELL_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_shell + * Validate a wl_shell error value. + * + * @return true on success, false on error. + * @ref wl_shell_error + */ +static inline bool +wl_shell_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SHELL_ERROR_ROLE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SHELL_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_shell + * @struct wl_shell_interface + */ +struct wl_shell_interface { + /** + * create a shell surface from a surface + * + * Create a shell surface for an existing surface. This gives the + * wl_surface the role of a shell surface. If the wl_surface + * already has another role, it raises a protocol error. + * + * Only one shell surface can be associated with a given surface. + * @param id shell surface to create + * @param surface surface to be given the shell surface role + */ + void (*get_shell_surface)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface); +}; + + +/** + * @ingroup iface_wl_shell + */ +#define WL_SHELL_GET_SHELL_SURFACE_SINCE_VERSION 1 + +#ifndef WL_SHELL_SURFACE_RESIZE_ENUM +#define WL_SHELL_SURFACE_RESIZE_ENUM +/** + * @ingroup iface_wl_shell_surface + * edge values for resizing + * + * These values are used to indicate which edge of a surface + * is being dragged in a resize operation. The server may + * use this information to adapt its behavior, e.g. choose + * an appropriate cursor image. + */ +enum wl_shell_surface_resize { + /** + * no edge + */ + WL_SHELL_SURFACE_RESIZE_NONE = 0, + /** + * top edge + */ + WL_SHELL_SURFACE_RESIZE_TOP = 1, + /** + * bottom edge + */ + WL_SHELL_SURFACE_RESIZE_BOTTOM = 2, + /** + * left edge + */ + WL_SHELL_SURFACE_RESIZE_LEFT = 4, + /** + * top and left edges + */ + WL_SHELL_SURFACE_RESIZE_TOP_LEFT = 5, + /** + * bottom and left edges + */ + WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT = 6, + /** + * right edge + */ + WL_SHELL_SURFACE_RESIZE_RIGHT = 8, + /** + * top and right edges + */ + WL_SHELL_SURFACE_RESIZE_TOP_RIGHT = 9, + /** + * bottom and right edges + */ + WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT = 10, +}; +#endif /* WL_SHELL_SURFACE_RESIZE_ENUM */ + +#ifndef WL_SHELL_SURFACE_RESIZE_ENUM_IS_VALID +#define WL_SHELL_SURFACE_RESIZE_ENUM_IS_VALID +/** + * @ingroup iface_wl_shell_surface + * Validate a wl_shell_surface resize value. + * + * @return true on success, false on error. + * @ref wl_shell_surface_resize + */ +static inline bool +wl_shell_surface_resize_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_NONE; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_TOP; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_BOTTOM; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_LEFT; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_TOP_LEFT; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_RIGHT; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_TOP_RIGHT; + if (version >= 1) + valid |= WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT; + return (value & ~valid) == 0; +} +#endif /* WL_SHELL_SURFACE_RESIZE_ENUM_IS_VALID */ + +#ifndef WL_SHELL_SURFACE_TRANSIENT_ENUM +#define WL_SHELL_SURFACE_TRANSIENT_ENUM +/** + * @ingroup iface_wl_shell_surface + * details of transient behaviour + * + * These flags specify details of the expected behaviour + * of transient surfaces. Used in the set_transient request. + */ +enum wl_shell_surface_transient { + /** + * do not set keyboard focus + */ + WL_SHELL_SURFACE_TRANSIENT_INACTIVE = 0x1, +}; +#endif /* WL_SHELL_SURFACE_TRANSIENT_ENUM */ + +#ifndef WL_SHELL_SURFACE_TRANSIENT_ENUM_IS_VALID +#define WL_SHELL_SURFACE_TRANSIENT_ENUM_IS_VALID +/** + * @ingroup iface_wl_shell_surface + * Validate a wl_shell_surface transient value. + * + * @return true on success, false on error. + * @ref wl_shell_surface_transient + */ +static inline bool +wl_shell_surface_transient_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE; + return (value & ~valid) == 0; +} +#endif /* WL_SHELL_SURFACE_TRANSIENT_ENUM_IS_VALID */ + +#ifndef WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM +#define WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM +/** + * @ingroup iface_wl_shell_surface + * different method to set the surface fullscreen + * + * Hints to indicate to the compositor how to deal with a conflict + * between the dimensions of the surface and the dimensions of the + * output. The compositor is free to ignore this parameter. + */ +enum wl_shell_surface_fullscreen_method { + /** + * no preference, apply default policy + */ + WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT = 0, + /** + * scale, preserve the surface's aspect ratio and center on output + */ + WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE = 1, + /** + * switch output mode to the smallest mode that can fit the surface, add black borders to compensate size mismatch + */ + WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER = 2, + /** + * no upscaling, center on output and add black borders to compensate size mismatch + */ + WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL = 3, +}; +#endif /* WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM */ + +#ifndef WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM_IS_VALID +#define WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM_IS_VALID +/** + * @ingroup iface_wl_shell_surface + * Validate a wl_shell_surface fullscreen_method value. + * + * @return true on success, false on error. + * @ref wl_shell_surface_fullscreen_method + */ +static inline bool +wl_shell_surface_fullscreen_method_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: + return version >= 1; + case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: + return version >= 1; + case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: + return version >= 1; + case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SHELL_SURFACE_FULLSCREEN_METHOD_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_shell_surface + * @struct wl_shell_surface_interface + */ +struct wl_shell_surface_interface { + /** + * respond to a ping event + * + * A client must respond to a ping event with a pong request or + * the client may be deemed unresponsive. + * @param serial serial number of the ping event + */ + void (*pong)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial); + /** + * start an interactive move + * + * Start a pointer-driven move of the surface. + * + * This request must be used in response to a button press event. + * The server may ignore move requests depending on the state of + * the surface (e.g. fullscreen or maximized). + * @param seat seat whose pointer is used + * @param serial serial number of the implicit grab on the pointer + */ + void (*move)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial); + /** + * start an interactive resize + * + * Start a pointer-driven resizing of the surface. + * + * This request must be used in response to a button press event. + * The server may ignore resize requests depending on the state of + * the surface (e.g. fullscreen or maximized). + * @param seat seat whose pointer is used + * @param serial serial number of the implicit grab on the pointer + * @param edges which edge or corner is being dragged + */ + void (*resize)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial, + uint32_t edges); + /** + * make the surface a toplevel surface + * + * Map the surface as a toplevel surface. + * + * A toplevel surface is not fullscreen, maximized or transient. + */ + void (*set_toplevel)(struct wl_client *client, + struct wl_resource *resource); + /** + * make the surface a transient surface + * + * Map the surface relative to an existing surface. + * + * The x and y arguments specify the location of the upper left + * corner of the surface relative to the upper left corner of the + * parent surface, in surface-local coordinates. + * + * The flags argument controls details of the transient behaviour. + * @param parent parent surface + * @param x surface-local x coordinate + * @param y surface-local y coordinate + * @param flags transient surface behavior + */ + void (*set_transient)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *parent, + int32_t x, + int32_t y, + uint32_t flags); + /** + * make the surface a fullscreen surface + * + * Map the surface as a fullscreen surface. + * + * If an output parameter is given then the surface will be made + * fullscreen on that output. If the client does not specify the + * output then the compositor will apply its policy - usually + * choosing the output on which the surface has the biggest surface + * area. + * + * The client may specify a method to resolve a size conflict + * between the output size and the surface size - this is provided + * through the method parameter. + * + * The framerate parameter is used only when the method is set to + * "driver", to indicate the preferred framerate. A value of 0 + * indicates that the client does not care about framerate. The + * framerate is specified in mHz, that is framerate of 60000 is + * 60Hz. + * + * A method of "scale" or "driver" implies a scaling operation of + * the surface, either via a direct scaling operation or a change + * of the output mode. This will override any kind of output + * scaling, so that mapping a surface with a buffer size equal to + * the mode can fill the screen independent of buffer_scale. + * + * A method of "fill" means we don't scale up the buffer, however + * any output scale is applied. This means that you may run into an + * edge case where the application maps a buffer with the same size + * of the output mode but buffer_scale 1 (thus making a surface + * larger than the output). In this case it is allowed to downscale + * the results to fit the screen. + * + * The compositor must reply to this request with a configure event + * with the dimensions for the output on which the surface will be + * made fullscreen. + * @param method method for resolving size conflict + * @param framerate framerate in mHz + * @param output output on which the surface is to be fullscreen + */ + void (*set_fullscreen)(struct wl_client *client, + struct wl_resource *resource, + uint32_t method, + uint32_t framerate, + struct wl_resource *output); + /** + * make the surface a popup surface + * + * Map the surface as a popup. + * + * A popup surface is a transient surface with an added pointer + * grab. + * + * An existing implicit grab will be changed to owner-events mode, + * and the popup grab will continue after the implicit grab ends + * (i.e. releasing the mouse button does not cause the popup to be + * unmapped). + * + * The popup grab continues until the window is destroyed or a + * mouse button is pressed in any other client's window. A click in + * any of the client's surfaces is reported as normal, however, + * clicks in other clients' surfaces will be discarded and trigger + * the callback. + * + * The x and y arguments specify the location of the upper left + * corner of the surface relative to the upper left corner of the + * parent surface, in surface-local coordinates. + * @param seat seat whose pointer is used + * @param serial serial number of the implicit grab on the pointer + * @param parent parent surface + * @param x surface-local x coordinate + * @param y surface-local y coordinate + * @param flags transient surface behavior + */ + void (*set_popup)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *seat, + uint32_t serial, + struct wl_resource *parent, + int32_t x, + int32_t y, + uint32_t flags); + /** + * make the surface a maximized surface + * + * Map the surface as a maximized surface. + * + * If an output parameter is given then the surface will be + * maximized on that output. If the client does not specify the + * output then the compositor will apply its policy - usually + * choosing the output on which the surface has the biggest surface + * area. + * + * The compositor will reply with a configure event telling the + * expected new surface size. The operation is completed on the + * next buffer attach to this surface. + * + * A maximized surface typically fills the entire output it is + * bound to, except for desktop elements such as panels. This is + * the main difference between a maximized shell surface and a + * fullscreen shell surface. + * + * The details depend on the compositor implementation. + * @param output output on which the surface is to be maximized + */ + void (*set_maximized)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *output); + /** + * set surface title + * + * Set a short title for the surface. + * + * This string may be used to identify the surface in a task bar, + * window list, or other user interface elements provided by the + * compositor. + * + * The string must be encoded in UTF-8. + * @param title surface title + */ + void (*set_title)(struct wl_client *client, + struct wl_resource *resource, + const char *title); + /** + * set surface class + * + * Set a class for the surface. + * + * The surface class identifies the general class of applications + * to which the surface belongs. A common convention is to use the + * file name (or the full path if it is a non-standard location) of + * the application's .desktop file as the class. + * @param class_ surface class + */ + void (*set_class)(struct wl_client *client, + struct wl_resource *resource, + const char *class_); +}; + +#define WL_SHELL_SURFACE_PING 0 +#define WL_SHELL_SURFACE_CONFIGURE 1 +#define WL_SHELL_SURFACE_POPUP_DONE 2 + +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_PING_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_CONFIGURE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_POPUP_DONE_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_PONG_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_MOVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_RESIZE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_TOPLEVEL_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_TRANSIENT_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_FULLSCREEN_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_POPUP_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_TITLE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_shell_surface + */ +#define WL_SHELL_SURFACE_SET_CLASS_SINCE_VERSION 1 + +/** + * @ingroup iface_wl_shell_surface + * Sends an ping event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the ping + */ +static inline void +wl_shell_surface_send_ping(struct wl_resource *resource_, uint32_t serial) +{ + wl_resource_post_event(resource_, WL_SHELL_SURFACE_PING, serial); +} + +/** + * @ingroup iface_wl_shell_surface + * Sends an configure event to the client owning the resource. + * @param resource_ The client's resource + * @param edges how the surface was resized + * @param width new width of the surface + * @param height new height of the surface + */ +static inline void +wl_shell_surface_send_configure(struct wl_resource *resource_, uint32_t edges, int32_t width, int32_t height) +{ + wl_resource_post_event(resource_, WL_SHELL_SURFACE_CONFIGURE, edges, width, height); +} + +/** + * @ingroup iface_wl_shell_surface + * Sends an popup_done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_shell_surface_send_popup_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_SHELL_SURFACE_POPUP_DONE); +} + +#ifndef WL_SURFACE_ERROR_ENUM +#define WL_SURFACE_ERROR_ENUM +/** + * @ingroup iface_wl_surface + * wl_surface error values + * + * These errors can be emitted in response to wl_surface requests. + */ +enum wl_surface_error { + /** + * buffer scale value is invalid + */ + WL_SURFACE_ERROR_INVALID_SCALE = 0, + /** + * buffer transform value is invalid + */ + WL_SURFACE_ERROR_INVALID_TRANSFORM = 1, + /** + * buffer size is invalid + */ + WL_SURFACE_ERROR_INVALID_SIZE = 2, + /** + * buffer offset is invalid + */ + WL_SURFACE_ERROR_INVALID_OFFSET = 3, + /** + * surface was destroyed before its role object + */ + WL_SURFACE_ERROR_DEFUNCT_ROLE_OBJECT = 4, + /** + * no buffer was attached + */ + WL_SURFACE_ERROR_NO_BUFFER = 5, +}; +#endif /* WL_SURFACE_ERROR_ENUM */ + +#ifndef WL_SURFACE_ERROR_ENUM_IS_VALID +#define WL_SURFACE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_surface + * Validate a wl_surface error value. + * + * @return true on success, false on error. + * @ref wl_surface_error + */ +static inline bool +wl_surface_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SURFACE_ERROR_INVALID_SCALE: + return version >= 1; + case WL_SURFACE_ERROR_INVALID_TRANSFORM: + return version >= 1; + case WL_SURFACE_ERROR_INVALID_SIZE: + return version >= 1; + case WL_SURFACE_ERROR_INVALID_OFFSET: + return version >= 1; + case WL_SURFACE_ERROR_DEFUNCT_ROLE_OBJECT: + return version >= 1; + case WL_SURFACE_ERROR_NO_BUFFER: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SURFACE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_surface + * @struct wl_surface_interface + */ +struct wl_surface_interface { + /** + * delete surface + * + * Deletes the surface and invalidates its object ID. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * set the surface contents + * + * Set a buffer as the content of this surface. + * + * The new size of the surface is calculated based on the buffer + * size transformed by the inverse buffer_transform and the inverse + * buffer_scale. This means that at commit time the supplied buffer + * size must be an integer multiple of the buffer_scale. If that's + * not the case, an invalid_size error is sent. + * + * The x and y arguments specify the location of the new pending + * buffer's upper left corner, relative to the current buffer's + * upper left corner, in surface-local coordinates. In other words, + * the x and y, combined with the new surface size define in which + * directions the surface's size changes. Setting anything other + * than 0 as x and y arguments is discouraged, and should instead + * be replaced with using the separate wl_surface.offset request. + * + * When the bound wl_surface version is 5 or higher, passing any + * non-zero x or y is a protocol violation, and will result in an + * 'invalid_offset' error being raised. The x and y arguments are + * ignored and do not change the pending state. To achieve + * equivalent semantics, use wl_surface.offset. + * + * Surface contents are double-buffered state, see + * wl_surface.commit. + * + * The initial surface contents are void; there is no content. + * wl_surface.attach assigns the given wl_buffer as the pending + * wl_buffer. wl_surface.commit makes the pending wl_buffer the new + * surface contents, and the size of the surface becomes the size + * calculated from the wl_buffer, as described above. After commit, + * there is no pending buffer until the next attach. + * + * Committing a pending wl_buffer allows the compositor to read the + * pixels in the wl_buffer. The compositor may access the pixels at + * any time after the wl_surface.commit request. When the + * compositor will not access the pixels anymore, it will send the + * wl_buffer.release event. Only after receiving wl_buffer.release, + * the client may reuse the wl_buffer. A wl_buffer that has been + * attached and then replaced by another attach instead of + * committed will not receive a release event, and is not used by + * the compositor. + * + * If a pending wl_buffer has been committed to more than one + * wl_surface, the delivery of wl_buffer.release events becomes + * undefined. A well behaved client should not rely on + * wl_buffer.release events in this case. Instead, clients hitting + * this case should use wl_surface.get_release or use a protocol + * extension providing per-commit release notifications (if none of + * these options are available, a fallback can be implemented by + * creating multiple wl_buffer objects from the same backing + * storage). + * + * Destroying the wl_buffer after wl_buffer.release does not change + * the surface contents. Destroying the wl_buffer before + * wl_buffer.release is allowed as long as the underlying buffer + * storage isn't re-used (this can happen e.g. on client process + * termination). However, if the client destroys the wl_buffer + * before receiving the wl_buffer.release event and mutates the + * underlying buffer storage, the surface contents become undefined + * immediately. + * + * If wl_surface.attach is sent with a NULL wl_buffer, the + * following wl_surface.commit will remove the surface content. + * + * If a pending wl_buffer has been destroyed, the result is not + * specified. Many compositors are known to remove the surface + * content on the following wl_surface.commit, but this behaviour + * is not universal. Clients seeking to maximise compatibility + * should not destroy pending buffers and should ensure that they + * explicitly remove content from surfaces, even after destroying + * buffers. + * @param buffer buffer of surface contents + * @param x surface-local x coordinate + * @param y surface-local y coordinate + */ + void (*attach)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *buffer, + int32_t x, + int32_t y); + /** + * mark part of the surface damaged + * + * This request is used to describe the regions where the pending + * buffer is different from the current surface contents, and where + * the surface therefore needs to be repainted. The compositor + * ignores the parts of the damage that fall outside of the + * surface. + * + * Damage is double-buffered state, see wl_surface.commit. + * + * The damage rectangle is specified in surface-local coordinates, + * where x and y specify the upper left corner of the damage + * rectangle. + * + * The initial value for pending damage is empty: no damage. + * wl_surface.damage adds pending damage: the new pending damage is + * the union of old pending damage and the given rectangle. + * + * wl_surface.commit assigns pending damage as the current damage, + * and clears pending damage. The server will clear the current + * damage as it repaints the surface. + * + * Note! New clients should not use this request. Instead damage + * can be posted with wl_surface.damage_buffer which uses buffer + * coordinates instead of surface coordinates. + * @param x surface-local x coordinate + * @param y surface-local y coordinate + * @param width width of damage rectangle + * @param height height of damage rectangle + */ + void (*damage)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * request a frame throttling hint + * + * Request a notification when it is a good time to start drawing + * a new frame, by creating a frame callback. This is useful for + * throttling redrawing operations, and driving animations. + * + * When a client is animating on a wl_surface, it can use the + * 'frame' request to get notified when it is a good time to draw + * and commit the next frame of animation. If the client commits an + * update earlier than that, it is likely that some updates will + * not make it to the display, and the client is wasting resources + * by drawing too often. + * + * The frame request will take effect on the next + * wl_surface.commit. The notification will only be posted for one + * frame unless requested again. For a wl_surface, the + * notifications are posted in the order the frame requests were + * committed. + * + * The server must send the notifications so that a client will not + * send excessive updates, while still allowing the highest + * possible update rate for clients that wait for the reply before + * drawing again. The server should give some time for the client + * to draw and commit after sending the frame callback events to + * let it hit the next output refresh. + * + * A server should avoid signaling the frame callbacks if the + * surface is not visible in any way, e.g. the surface is + * off-screen, or completely obscured by other opaque surfaces. + * + * The object returned by this request will be destroyed by the + * compositor after the callback is fired and as such the client + * must not attempt to use it after that point. + * + * The callback_data passed in the callback is the current time, in + * milliseconds, with an undefined base. + * @param callback callback object for the frame request + */ + void (*frame)(struct wl_client *client, + struct wl_resource *resource, + uint32_t callback); + /** + * set opaque region + * + * This request sets the region of the surface that contains + * opaque content. + * + * The opaque region is an optimization hint for the compositor + * that lets it optimize the redrawing of content behind opaque + * regions. Setting an opaque region is not required for correct + * behaviour, but marking transparent content as opaque will result + * in repaint artifacts. + * + * The opaque region is specified in surface-local coordinates. + * + * The compositor ignores the parts of the opaque region that fall + * outside of the surface. + * + * Opaque region is double-buffered state, see wl_surface.commit. + * + * wl_surface.set_opaque_region changes the pending opaque region. + * wl_surface.commit copies the pending region to the current + * region. Otherwise, the pending and current regions are never + * changed. + * + * The initial value for an opaque region is empty. Setting the + * pending opaque region has copy semantics, and the wl_region + * object can be destroyed immediately. A NULL wl_region causes the + * pending opaque region to be set to empty. + * @param region opaque region of the surface + */ + void (*set_opaque_region)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region); + /** + * set input region + * + * This request sets the region of the surface that can receive + * pointer and touch events. + * + * Input events happening outside of this region will try the next + * surface in the server surface stack. The compositor ignores the + * parts of the input region that fall outside of the surface. + * + * The input region is specified in surface-local coordinates. + * + * Input region is double-buffered state, see wl_surface.commit. + * + * wl_surface.set_input_region changes the pending input region. + * wl_surface.commit copies the pending region to the current + * region. Otherwise the pending and current regions are never + * changed, except cursor and icon surfaces are special cases, see + * wl_pointer.set_cursor and wl_data_device.start_drag. + * + * The initial value for an input region is infinite. That means + * the whole surface will accept input. Setting the pending input + * region has copy semantics, and the wl_region object can be + * destroyed immediately. A NULL wl_region causes the input region + * to be set to infinite. + * @param region input region of the surface + */ + void (*set_input_region)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *region); + /** + * commit pending surface state + * + * Surface state (input, opaque, and damage regions, attached + * buffers, etc.) is double-buffered. Protocol requests modify the + * pending state, as opposed to the active state in use by the + * compositor. + * + * All requests that need a commit to become effective are + * documented to affect double-buffered state. + * + * Other interfaces may add further double-buffered surface state. + * + * A commit request atomically creates a Content Update (CU) from + * the pending state, even if the pending state has not been + * touched. The content update is placed at the end of a + * per-surface queue until it becomes active. After commit, the new + * pending state is as documented for each related request. + * + * A CU is either a Desync Content Update (DCU) or a Sync Content + * Update (SCU). If the surface is effectively synchronized at the + * commit request, it is a SCU, otherwise a DCU. + * + * When a surface transitions from effectively synchronized to + * effectively desynchronized, all SCUs in its queue which are not + * reachable by any DCU become DCUs and dependency edges from + * outside the queue to these CUs are removed. + * + * See wl_subsurface for the definition of 'effectively + * synchronized' and 'effectively desynchronized'. + * + * When a CU is placed in the queue, the CU has a dependency on the + * CU in front of it and to the SCU at end of the queue of every + * direct child surface if that SCU exists and does not have + * another dependent. This can form a directed acyclic graph of CUs + * with dependencies as edges. + * + * In addition to surface state, the CU can have constraints that + * must be satisfied before it can be applied. Other interfaces may + * add CU constraints. + * + * All DCUs which do not have a SCU in front of themselves in their + * queue, are candidates. If the graph that's reachable by a + * candidate does not have any unsatisfied constraints, the entire + * graph must be applied atomically. + * + * When a CU is applied, the wl_buffer is applied before all other + * state. This means that all coordinates in double-buffered state + * are relative to the newly attached wl_buffers, except for + * wl_surface.attach itself. If there is no newly attached + * wl_buffer, the coordinates are relative to the previous content + * update. + */ + void (*commit)(struct wl_client *client, + struct wl_resource *resource); + /** + * sets the buffer transformation + * + * This request sets the transformation that the client has + * already applied to the content of the buffer. The accepted + * values for the transform parameter are the values for + * wl_output.transform. + * + * The compositor applies the inverse of this transformation + * whenever it uses the buffer contents. + * + * Buffer transform is double-buffered state, see + * wl_surface.commit. + * + * A newly created surface has its buffer transformation set to + * normal. + * + * wl_surface.set_buffer_transform changes the pending buffer + * transformation. wl_surface.commit copies the pending buffer + * transformation to the current one. Otherwise, the pending and + * current values are never changed. + * + * The purpose of this request is to allow clients to render + * content according to the output transform, thus permitting the + * compositor to use certain optimizations even if the display is + * rotated. Using hardware overlays and scanning out a client + * buffer for fullscreen surfaces are examples of such + * optimizations. Those optimizations are highly dependent on the + * compositor implementation, so the use of this request should be + * considered on a case-by-case basis. + * + * Note that if the transform value includes 90 or 270 degree + * rotation, the width of the buffer will become the surface height + * and the height of the buffer will become the surface width. + * + * If transform is not one of the values from the + * wl_output.transform enum the invalid_transform protocol error is + * raised. + * @param transform transform for interpreting buffer contents + * @since 2 + */ + void (*set_buffer_transform)(struct wl_client *client, + struct wl_resource *resource, + int32_t transform); + /** + * sets the buffer scaling factor + * + * This request sets an optional scaling factor on how the + * compositor interprets the contents of the buffer attached to the + * window. + * + * Buffer scale is double-buffered state, see wl_surface.commit. + * + * A newly created surface has its buffer scale set to 1. + * + * wl_surface.set_buffer_scale changes the pending buffer scale. + * wl_surface.commit copies the pending buffer scale to the current + * one. Otherwise, the pending and current values are never + * changed. + * + * The purpose of this request is to allow clients to supply higher + * resolution buffer data for use on high resolution outputs. It is + * intended that you pick the same buffer scale as the scale of the + * output that the surface is displayed on. This means the + * compositor can avoid scaling when rendering the surface on that + * output. + * + * Note that if the scale is larger than 1, then you have to attach + * a buffer that is larger (by a factor of scale in each dimension) + * than the desired surface size. + * + * If scale is not greater than 0 the invalid_scale protocol error + * is raised. + * @param scale scale for interpreting buffer contents + * @since 3 + */ + void (*set_buffer_scale)(struct wl_client *client, + struct wl_resource *resource, + int32_t scale); + /** + * mark part of the surface damaged using buffer coordinates + * + * This request is used to describe the regions where the pending + * buffer is different from the current surface contents, and where + * the surface therefore needs to be repainted. The compositor + * ignores the parts of the damage that fall outside of the + * surface. + * + * Damage is double-buffered state, see wl_surface.commit. + * + * The damage rectangle is specified in buffer coordinates, where x + * and y specify the upper left corner of the damage rectangle. + * + * The initial value for pending damage is empty: no damage. + * wl_surface.damage_buffer adds pending damage: the new pending + * damage is the union of old pending damage and the given + * rectangle. + * + * wl_surface.commit assigns pending damage as the current damage, + * and clears pending damage. The server will clear the current + * damage as it repaints the surface. + * + * This request differs from wl_surface.damage in only one way - it + * takes damage in buffer coordinates instead of surface-local + * coordinates. While this generally is more intuitive than surface + * coordinates, it is especially desirable when using wp_viewport + * or when a drawing library (like EGL) is unaware of buffer scale + * and buffer transform. + * + * Note: Because buffer transformation changes and damage requests + * may be interleaved in the protocol stream, it is impossible to + * determine the actual mapping between surface and buffer damage + * until wl_surface.commit time. Therefore, compositors wishing to + * take both kinds of damage into account will have to accumulate + * damage from the two requests separately and only transform from + * one to the other after receiving the wl_surface.commit. + * @param x buffer-local x coordinate + * @param y buffer-local y coordinate + * @param width width of damage rectangle + * @param height height of damage rectangle + * @since 4 + */ + void (*damage_buffer)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * set the surface contents offset + * + * The x and y arguments specify the location of the new pending + * buffer's upper left corner, relative to the current buffer's + * upper left corner, in surface-local coordinates. In other words, + * the x and y, combined with the new surface size define in which + * directions the surface's size changes. + * + * The exact semantics of wl_surface.offset are role-specific. + * Refer to the documentation of specific roles for more + * information. + * + * Surface location offset is double-buffered state, see + * wl_surface.commit. + * + * This request is semantically equivalent to and the replaces the + * x and y arguments in the wl_surface.attach request in wl_surface + * versions prior to 5. See wl_surface.attach for details. + * @param x surface-local x coordinate + * @param y surface-local y coordinate + * @since 5 + */ + void (*offset)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y); + /** + * get a release callback + * + * Create a callback for the release of the buffer attached by + * the client with wl_surface.attach. + * + * The compositor will release the buffer when it has finished its + * usage of the underlying storage for the relevant commit. Once + * the client receives this event, and assuming the associated + * buffer is not pending release from other wl_surface.commit + * requests, the client can safely re-use the buffer. + * + * Release callbacks are double-buffered state, and will be + * associated with the pending buffer at wl_surface.commit time. + * + * The callback_data passed in the wl_callback.done event is unused + * and is always zero. + * + * Sending this request without attaching a non-null buffer in the + * same content update is a protocol error. The compositor will + * send the no_buffer error in this case. + * @param callback callback object for the release + * @since 7 + */ + void (*get_release)(struct wl_client *client, + struct wl_resource *resource, + uint32_t callback); +}; + +#define WL_SURFACE_ENTER 0 +#define WL_SURFACE_LEAVE 1 +#define WL_SURFACE_PREFERRED_BUFFER_SCALE 2 +#define WL_SURFACE_PREFERRED_BUFFER_TRANSFORM 3 + +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION 6 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_PREFERRED_BUFFER_TRANSFORM_SINCE_VERSION 6 + +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_ATTACH_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_DAMAGE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_FRAME_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_SET_OPAQUE_REGION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_SET_INPUT_REGION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_COMMIT_SINCE_VERSION 1 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_SET_BUFFER_TRANSFORM_SINCE_VERSION 2 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION 3 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION 4 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_OFFSET_SINCE_VERSION 5 +/** + * @ingroup iface_wl_surface + */ +#define WL_SURFACE_GET_RELEASE_SINCE_VERSION 7 + +/** + * @ingroup iface_wl_surface + * Sends an enter event to the client owning the resource. + * @param resource_ The client's resource + * @param output output entered by the surface + */ +static inline void +wl_surface_send_enter(struct wl_resource *resource_, struct wl_resource *output) +{ + wl_resource_post_event(resource_, WL_SURFACE_ENTER, output); +} + +/** + * @ingroup iface_wl_surface + * Sends an leave event to the client owning the resource. + * @param resource_ The client's resource + * @param output output left by the surface + */ +static inline void +wl_surface_send_leave(struct wl_resource *resource_, struct wl_resource *output) +{ + wl_resource_post_event(resource_, WL_SURFACE_LEAVE, output); +} + +/** + * @ingroup iface_wl_surface + * Sends an preferred_buffer_scale event to the client owning the resource. + * @param resource_ The client's resource + * @param factor preferred scaling factor + */ +static inline void +wl_surface_send_preferred_buffer_scale(struct wl_resource *resource_, int32_t factor) +{ + wl_resource_post_event(resource_, WL_SURFACE_PREFERRED_BUFFER_SCALE, factor); +} + +/** + * @ingroup iface_wl_surface + * Sends an preferred_buffer_transform event to the client owning the resource. + * @param resource_ The client's resource + * @param transform preferred transform + */ +static inline void +wl_surface_send_preferred_buffer_transform(struct wl_resource *resource_, uint32_t transform) +{ + wl_resource_post_event(resource_, WL_SURFACE_PREFERRED_BUFFER_TRANSFORM, transform); +} + +#ifndef WL_SEAT_CAPABILITY_ENUM +#define WL_SEAT_CAPABILITY_ENUM +/** + * @ingroup iface_wl_seat + * seat capability bitmask + * + * This is a bitmask of capabilities this seat has; if a member is + * set, then it is present on the seat. + */ +enum wl_seat_capability { + /** + * the seat has pointer devices + */ + WL_SEAT_CAPABILITY_POINTER = 1, + /** + * the seat has one or more keyboards + */ + WL_SEAT_CAPABILITY_KEYBOARD = 2, + /** + * the seat has touch devices + */ + WL_SEAT_CAPABILITY_TOUCH = 4, +}; +#endif /* WL_SEAT_CAPABILITY_ENUM */ + +#ifndef WL_SEAT_CAPABILITY_ENUM_IS_VALID +#define WL_SEAT_CAPABILITY_ENUM_IS_VALID +/** + * @ingroup iface_wl_seat + * Validate a wl_seat capability value. + * + * @return true on success, false on error. + * @ref wl_seat_capability + */ +static inline bool +wl_seat_capability_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WL_SEAT_CAPABILITY_POINTER; + if (version >= 1) + valid |= WL_SEAT_CAPABILITY_KEYBOARD; + if (version >= 1) + valid |= WL_SEAT_CAPABILITY_TOUCH; + return (value & ~valid) == 0; +} +#endif /* WL_SEAT_CAPABILITY_ENUM_IS_VALID */ + +#ifndef WL_SEAT_ERROR_ENUM +#define WL_SEAT_ERROR_ENUM +/** + * @ingroup iface_wl_seat + * wl_seat error values + * + * These errors can be emitted in response to wl_seat requests. + */ +enum wl_seat_error { + /** + * get_pointer, get_keyboard or get_touch called on seat without the matching capability + */ + WL_SEAT_ERROR_MISSING_CAPABILITY = 0, +}; +#endif /* WL_SEAT_ERROR_ENUM */ + +#ifndef WL_SEAT_ERROR_ENUM_IS_VALID +#define WL_SEAT_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_seat + * Validate a wl_seat error value. + * + * @return true on success, false on error. + * @ref wl_seat_error + */ +static inline bool +wl_seat_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SEAT_ERROR_MISSING_CAPABILITY: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SEAT_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_seat + * @struct wl_seat_interface + */ +struct wl_seat_interface { + /** + * return pointer object + * + * The ID provided will be initialized to the wl_pointer + * interface for this seat. + * + * This request only takes effect if the seat has the pointer + * capability, or has had the pointer capability in the past. It is + * a protocol violation to issue this request on a seat that has + * never had the pointer capability. The missing_capability error + * will be sent in this case. + * @param id seat pointer + */ + void (*get_pointer)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * return keyboard object + * + * The ID provided will be initialized to the wl_keyboard + * interface for this seat. + * + * This request only takes effect if the seat has the keyboard + * capability, or has had the keyboard capability in the past. It + * is a protocol violation to issue this request on a seat that has + * never had the keyboard capability. The missing_capability error + * will be sent in this case. + * @param id seat keyboard + */ + void (*get_keyboard)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * return touch object + * + * The ID provided will be initialized to the wl_touch interface + * for this seat. + * + * This request only takes effect if the seat has the touch + * capability, or has had the touch capability in the past. It is a + * protocol violation to issue this request on a seat that has + * never had the touch capability. The missing_capability error + * will be sent in this case. + * @param id seat touch interface + */ + void (*get_touch)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id); + /** + * release the seat object + * + * Using this request a client can tell the server that it is not + * going to use the seat object anymore. + * @since 5 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_SEAT_CAPABILITIES 0 +#define WL_SEAT_NAME 1 + +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_CAPABILITIES_SINCE_VERSION 1 +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_NAME_SINCE_VERSION 2 + +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_GET_POINTER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_GET_KEYBOARD_SINCE_VERSION 1 +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_GET_TOUCH_SINCE_VERSION 1 +/** + * @ingroup iface_wl_seat + */ +#define WL_SEAT_RELEASE_SINCE_VERSION 5 + +/** + * @ingroup iface_wl_seat + * Sends an capabilities event to the client owning the resource. + * @param resource_ The client's resource + * @param capabilities capabilities of the seat + */ +static inline void +wl_seat_send_capabilities(struct wl_resource *resource_, uint32_t capabilities) +{ + wl_resource_post_event(resource_, WL_SEAT_CAPABILITIES, capabilities); +} + +/** + * @ingroup iface_wl_seat + * Sends an name event to the client owning the resource. + * @param resource_ The client's resource + * @param name seat identifier + */ +static inline void +wl_seat_send_name(struct wl_resource *resource_, const char *name) +{ + wl_resource_post_event(resource_, WL_SEAT_NAME, name); +} + +#ifndef WL_POINTER_ERROR_ENUM +#define WL_POINTER_ERROR_ENUM +enum wl_pointer_error { + /** + * given wl_surface has another role + */ + WL_POINTER_ERROR_ROLE = 0, +}; +#endif /* WL_POINTER_ERROR_ENUM */ + +#ifndef WL_POINTER_ERROR_ENUM_IS_VALID +#define WL_POINTER_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_pointer + * Validate a wl_pointer error value. + * + * @return true on success, false on error. + * @ref wl_pointer_error + */ +static inline bool +wl_pointer_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_POINTER_ERROR_ROLE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_POINTER_ERROR_ENUM_IS_VALID */ + +#ifndef WL_POINTER_BUTTON_STATE_ENUM +#define WL_POINTER_BUTTON_STATE_ENUM +/** + * @ingroup iface_wl_pointer + * physical button state + * + * Describes the physical state of a button that produced the button + * event. + */ +enum wl_pointer_button_state { + /** + * the button is not pressed + */ + WL_POINTER_BUTTON_STATE_RELEASED = 0, + /** + * the button is pressed + */ + WL_POINTER_BUTTON_STATE_PRESSED = 1, +}; +#endif /* WL_POINTER_BUTTON_STATE_ENUM */ + +#ifndef WL_POINTER_BUTTON_STATE_ENUM_IS_VALID +#define WL_POINTER_BUTTON_STATE_ENUM_IS_VALID +/** + * @ingroup iface_wl_pointer + * Validate a wl_pointer button_state value. + * + * @return true on success, false on error. + * @ref wl_pointer_button_state + */ +static inline bool +wl_pointer_button_state_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_POINTER_BUTTON_STATE_RELEASED: + return version >= 1; + case WL_POINTER_BUTTON_STATE_PRESSED: + return version >= 1; + default: + return false; + } +} +#endif /* WL_POINTER_BUTTON_STATE_ENUM_IS_VALID */ + +#ifndef WL_POINTER_AXIS_ENUM +#define WL_POINTER_AXIS_ENUM +/** + * @ingroup iface_wl_pointer + * axis types + * + * Describes the axis types of scroll events. + */ +enum wl_pointer_axis { + /** + * vertical axis + */ + WL_POINTER_AXIS_VERTICAL_SCROLL = 0, + /** + * horizontal axis + */ + WL_POINTER_AXIS_HORIZONTAL_SCROLL = 1, +}; +#endif /* WL_POINTER_AXIS_ENUM */ + +#ifndef WL_POINTER_AXIS_ENUM_IS_VALID +#define WL_POINTER_AXIS_ENUM_IS_VALID +/** + * @ingroup iface_wl_pointer + * Validate a wl_pointer axis value. + * + * @return true on success, false on error. + * @ref wl_pointer_axis + */ +static inline bool +wl_pointer_axis_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_POINTER_AXIS_VERTICAL_SCROLL: + return version >= 1; + case WL_POINTER_AXIS_HORIZONTAL_SCROLL: + return version >= 1; + default: + return false; + } +} +#endif /* WL_POINTER_AXIS_ENUM_IS_VALID */ + +#ifndef WL_POINTER_AXIS_SOURCE_ENUM +#define WL_POINTER_AXIS_SOURCE_ENUM +/** + * @ingroup iface_wl_pointer + * axis source types + * + * Describes the source types for axis events. This indicates to the + * client how an axis event was physically generated; a client may + * adjust the user interface accordingly. For example, scroll events + * from a "finger" source may be in a smooth coordinate space with + * kinetic scrolling whereas a "wheel" source may be in discrete steps + * of a number of lines. + * + * The "continuous" axis source is a device generating events in a + * continuous coordinate space, but using something other than a + * finger. One example for this source is button-based scrolling where + * the vertical motion of a device is converted to scroll events while + * a button is held down. + * + * The "wheel tilt" axis source indicates that the actual device is a + * wheel but the scroll event is not caused by a rotation but a + * (usually sideways) tilt of the wheel. + */ +enum wl_pointer_axis_source { + /** + * a physical wheel rotation + */ + WL_POINTER_AXIS_SOURCE_WHEEL = 0, + /** + * finger on a touch surface + */ + WL_POINTER_AXIS_SOURCE_FINGER = 1, + /** + * continuous coordinate space + */ + WL_POINTER_AXIS_SOURCE_CONTINUOUS = 2, + /** + * a physical wheel tilt + * @since 6 + */ + WL_POINTER_AXIS_SOURCE_WHEEL_TILT = 3, +}; +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_SOURCE_WHEEL_TILT_SINCE_VERSION 6 +#endif /* WL_POINTER_AXIS_SOURCE_ENUM */ + +#ifndef WL_POINTER_AXIS_SOURCE_ENUM_IS_VALID +#define WL_POINTER_AXIS_SOURCE_ENUM_IS_VALID +/** + * @ingroup iface_wl_pointer + * Validate a wl_pointer axis_source value. + * + * @return true on success, false on error. + * @ref wl_pointer_axis_source + */ +static inline bool +wl_pointer_axis_source_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_POINTER_AXIS_SOURCE_WHEEL: + return version >= 1; + case WL_POINTER_AXIS_SOURCE_FINGER: + return version >= 1; + case WL_POINTER_AXIS_SOURCE_CONTINUOUS: + return version >= 1; + case WL_POINTER_AXIS_SOURCE_WHEEL_TILT: + return version >= 6; + default: + return false; + } +} +#endif /* WL_POINTER_AXIS_SOURCE_ENUM_IS_VALID */ + +#ifndef WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM +#define WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM +/** + * @ingroup iface_wl_pointer + * axis relative direction + * + * This specifies the direction of the physical motion that caused a + * wl_pointer.axis event, relative to the wl_pointer.axis direction. + */ +enum wl_pointer_axis_relative_direction { + /** + * physical motion matches axis direction + */ + WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL = 0, + /** + * physical motion is the inverse of the axis direction + */ + WL_POINTER_AXIS_RELATIVE_DIRECTION_INVERTED = 1, +}; +#endif /* WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM */ + +#ifndef WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM_IS_VALID +#define WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM_IS_VALID +/** + * @ingroup iface_wl_pointer + * Validate a wl_pointer axis_relative_direction value. + * + * @return true on success, false on error. + * @ref wl_pointer_axis_relative_direction + */ +static inline bool +wl_pointer_axis_relative_direction_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL: + return version >= 1; + case WL_POINTER_AXIS_RELATIVE_DIRECTION_INVERTED: + return version >= 1; + default: + return false; + } +} +#endif /* WL_POINTER_AXIS_RELATIVE_DIRECTION_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_pointer + * @struct wl_pointer_interface + */ +struct wl_pointer_interface { + /** + * set the pointer surface + * + * Set the pointer surface, i.e., the surface that contains the + * pointer image (cursor). This request gives the surface the role + * of a cursor. If the surface already has another role, it raises + * a protocol error. + * + * The cursor actually changes only if the pointer focus for this + * device is one of the requesting client's surfaces or the surface + * parameter is the current pointer surface. If there was a + * previous surface set with this request it is replaced. If + * surface is NULL, the pointer image is hidden. + * + * The parameters hotspot_x and hotspot_y define the position of + * the pointer surface relative to the pointer location. Its + * top-left corner is always at (x, y) - (hotspot_x, hotspot_y), + * where (x, y) are the coordinates of the pointer location, in + * surface-local coordinates. + * + * On wl_surface.offset requests to the pointer surface, hotspot_x + * and hotspot_y are decremented by the x and y parameters passed + * to the request. The offset must be applied by wl_surface.commit + * as usual. + * + * The hotspot can also be updated by passing the currently set + * pointer surface to this request with new values for hotspot_x + * and hotspot_y. + * + * The input region is ignored for wl_surfaces with the role of a + * cursor. When the use as a cursor ends, the wl_surface is + * unmapped. + * + * The serial parameter must match the latest wl_pointer.enter + * serial number sent to the client. Otherwise the request will be + * ignored. + * @param serial serial number of the enter event + * @param surface pointer surface + * @param hotspot_x surface-local x coordinate + * @param hotspot_y surface-local y coordinate + */ + void (*set_cursor)(struct wl_client *client, + struct wl_resource *resource, + uint32_t serial, + struct wl_resource *surface, + int32_t hotspot_x, + int32_t hotspot_y); + /** + * release the pointer object + * + * Using this request a client can tell the server that it is not + * going to use the pointer object anymore. + * + * This request destroys the pointer proxy object, so clients must + * not call wl_pointer_destroy() after using this request. + * @since 3 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_POINTER_ENTER 0 +#define WL_POINTER_LEAVE 1 +#define WL_POINTER_MOTION 2 +#define WL_POINTER_BUTTON 3 +#define WL_POINTER_AXIS 4 +#define WL_POINTER_FRAME 5 +#define WL_POINTER_AXIS_SOURCE 6 +#define WL_POINTER_AXIS_STOP 7 +#define WL_POINTER_AXIS_DISCRETE 8 +#define WL_POINTER_AXIS_VALUE120 9 +#define WL_POINTER_AXIS_RELATIVE_DIRECTION 10 +#define WL_POINTER_WARP 11 + +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_MOTION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_BUTTON_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_FRAME_SINCE_VERSION 5 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_SOURCE_SINCE_VERSION 5 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_STOP_SINCE_VERSION 5 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_DISCRETE_SINCE_VERSION 5 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_VALUE120_SINCE_VERSION 8 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_AXIS_RELATIVE_DIRECTION_SINCE_VERSION 9 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_WARP_SINCE_VERSION 11 + +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_SET_CURSOR_SINCE_VERSION 1 +/** + * @ingroup iface_wl_pointer + */ +#define WL_POINTER_RELEASE_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_pointer + * Sends an enter event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the enter event + * @param surface surface entered by the pointer + * @param surface_x surface-local x coordinate + * @param surface_y surface-local y coordinate + */ +static inline void +wl_pointer_send_enter(struct wl_resource *resource_, uint32_t serial, struct wl_resource *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) +{ + wl_resource_post_event(resource_, WL_POINTER_ENTER, serial, surface, surface_x, surface_y); +} + +/** + * @ingroup iface_wl_pointer + * Sends an leave event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the leave event + * @param surface surface left by the pointer + */ +static inline void +wl_pointer_send_leave(struct wl_resource *resource_, uint32_t serial, struct wl_resource *surface) +{ + wl_resource_post_event(resource_, WL_POINTER_LEAVE, serial, surface); +} + +/** + * @ingroup iface_wl_pointer + * Sends an motion event to the client owning the resource. + * @param resource_ The client's resource + * @param time timestamp with millisecond granularity + * @param surface_x surface-local x coordinate + * @param surface_y surface-local y coordinate + */ +static inline void +wl_pointer_send_motion(struct wl_resource *resource_, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) +{ + wl_resource_post_event(resource_, WL_POINTER_MOTION, time, surface_x, surface_y); +} + +/** + * @ingroup iface_wl_pointer + * Sends an button event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the button event + * @param time timestamp with millisecond granularity + * @param button button that produced the event + * @param state physical state of the button + */ +static inline void +wl_pointer_send_button(struct wl_resource *resource_, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) +{ + wl_resource_post_event(resource_, WL_POINTER_BUTTON, serial, time, button, state); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis event to the client owning the resource. + * @param resource_ The client's resource + * @param time timestamp with millisecond granularity + * @param axis axis type + * @param value length of vector in surface-local coordinate space + */ +static inline void +wl_pointer_send_axis(struct wl_resource *resource_, uint32_t time, uint32_t axis, wl_fixed_t value) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS, time, axis, value); +} + +/** + * @ingroup iface_wl_pointer + * Sends an frame event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_pointer_send_frame(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_POINTER_FRAME); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis_source event to the client owning the resource. + * @param resource_ The client's resource + * @param axis_source source of the axis event + */ +static inline void +wl_pointer_send_axis_source(struct wl_resource *resource_, uint32_t axis_source) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS_SOURCE, axis_source); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis_stop event to the client owning the resource. + * @param resource_ The client's resource + * @param time timestamp with millisecond granularity + * @param axis the axis stopped with this event + */ +static inline void +wl_pointer_send_axis_stop(struct wl_resource *resource_, uint32_t time, uint32_t axis) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS_STOP, time, axis); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis_discrete event to the client owning the resource. + * @param resource_ The client's resource + * @param axis axis type + * @param discrete number of steps + */ +static inline void +wl_pointer_send_axis_discrete(struct wl_resource *resource_, uint32_t axis, int32_t discrete) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS_DISCRETE, axis, discrete); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis_value120 event to the client owning the resource. + * @param resource_ The client's resource + * @param axis axis type + * @param value120 scroll distance as fraction of 120 + */ +static inline void +wl_pointer_send_axis_value120(struct wl_resource *resource_, uint32_t axis, int32_t value120) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS_VALUE120, axis, value120); +} + +/** + * @ingroup iface_wl_pointer + * Sends an axis_relative_direction event to the client owning the resource. + * @param resource_ The client's resource + * @param axis axis type + * @param direction physical direction relative to axis motion + */ +static inline void +wl_pointer_send_axis_relative_direction(struct wl_resource *resource_, uint32_t axis, uint32_t direction) +{ + wl_resource_post_event(resource_, WL_POINTER_AXIS_RELATIVE_DIRECTION, axis, direction); +} + +/** + * @ingroup iface_wl_pointer + * Sends an warp event to the client owning the resource. + * @param resource_ The client's resource + * @param surface_x surface-local x coordinate + * @param surface_y surface-local y coordinate + */ +static inline void +wl_pointer_send_warp(struct wl_resource *resource_, wl_fixed_t surface_x, wl_fixed_t surface_y) +{ + wl_resource_post_event(resource_, WL_POINTER_WARP, surface_x, surface_y); +} + +#ifndef WL_KEYBOARD_KEYMAP_FORMAT_ENUM +#define WL_KEYBOARD_KEYMAP_FORMAT_ENUM +/** + * @ingroup iface_wl_keyboard + * keyboard mapping format + * + * This specifies the format of the keymap provided to the + * client with the wl_keyboard.keymap event. + */ +enum wl_keyboard_keymap_format { + /** + * no keymap; client must understand how to interpret the raw keycode + */ + WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP = 0, + /** + * libxkbcommon compatible, null-terminated string; to determine the xkb keycode, clients must add 8 to the key event keycode + */ + WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 = 1, +}; +#endif /* WL_KEYBOARD_KEYMAP_FORMAT_ENUM */ + +#ifndef WL_KEYBOARD_KEYMAP_FORMAT_ENUM_IS_VALID +#define WL_KEYBOARD_KEYMAP_FORMAT_ENUM_IS_VALID +/** + * @ingroup iface_wl_keyboard + * Validate a wl_keyboard keymap_format value. + * + * @return true on success, false on error. + * @ref wl_keyboard_keymap_format + */ +static inline bool +wl_keyboard_keymap_format_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP: + return version >= 1; + case WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1: + return version >= 1; + default: + return false; + } +} +#endif /* WL_KEYBOARD_KEYMAP_FORMAT_ENUM_IS_VALID */ + +#ifndef WL_KEYBOARD_KEY_STATE_ENUM +#define WL_KEYBOARD_KEY_STATE_ENUM +/** + * @ingroup iface_wl_keyboard + * physical key state + * + * Describes the physical state of a key that produced the key event. + * + * Since version 10, the key can be in a "repeated" pseudo-state which + * means the same as "pressed", but is used to signal repetition in the + * key event. + * + * The key may only enter the repeated state after entering the pressed + * state and before entering the released state. This event may be + * generated multiple times while the key is down. + */ +enum wl_keyboard_key_state { + /** + * key is not pressed + */ + WL_KEYBOARD_KEY_STATE_RELEASED = 0, + /** + * key is pressed + */ + WL_KEYBOARD_KEY_STATE_PRESSED = 1, + /** + * key was repeated + * @since 10 + */ + WL_KEYBOARD_KEY_STATE_REPEATED = 2, +}; +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_KEY_STATE_REPEATED_SINCE_VERSION 10 +#endif /* WL_KEYBOARD_KEY_STATE_ENUM */ + +#ifndef WL_KEYBOARD_KEY_STATE_ENUM_IS_VALID +#define WL_KEYBOARD_KEY_STATE_ENUM_IS_VALID +/** + * @ingroup iface_wl_keyboard + * Validate a wl_keyboard key_state value. + * + * @return true on success, false on error. + * @ref wl_keyboard_key_state + */ +static inline bool +wl_keyboard_key_state_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_KEYBOARD_KEY_STATE_RELEASED: + return version >= 1; + case WL_KEYBOARD_KEY_STATE_PRESSED: + return version >= 1; + case WL_KEYBOARD_KEY_STATE_REPEATED: + return version >= 10; + default: + return false; + } +} +#endif /* WL_KEYBOARD_KEY_STATE_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_keyboard + * @struct wl_keyboard_interface + */ +struct wl_keyboard_interface { + /** + * release the keyboard object + * + * + * @since 3 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_KEYBOARD_KEYMAP 0 +#define WL_KEYBOARD_ENTER 1 +#define WL_KEYBOARD_LEAVE 2 +#define WL_KEYBOARD_KEY 3 +#define WL_KEYBOARD_MODIFIERS 4 +#define WL_KEYBOARD_REPEAT_INFO 5 + +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_KEYMAP_SINCE_VERSION 1 +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_KEY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_MODIFIERS_SINCE_VERSION 1 +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION 4 + +/** + * @ingroup iface_wl_keyboard + */ +#define WL_KEYBOARD_RELEASE_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_keyboard + * Sends an keymap event to the client owning the resource. + * @param resource_ The client's resource + * @param format keymap format + * @param fd keymap file descriptor + * @param size keymap size, in bytes + */ +static inline void +wl_keyboard_send_keymap(struct wl_resource *resource_, uint32_t format, int32_t fd, uint32_t size) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_KEYMAP, format, fd, size); +} + +/** + * @ingroup iface_wl_keyboard + * Sends an enter event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the enter event + * @param surface surface gaining keyboard focus + * @param keys the keys currently logically down + */ +static inline void +wl_keyboard_send_enter(struct wl_resource *resource_, uint32_t serial, struct wl_resource *surface, struct wl_array *keys) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_ENTER, serial, surface, keys); +} + +/** + * @ingroup iface_wl_keyboard + * Sends an leave event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the leave event + * @param surface surface that lost keyboard focus + */ +static inline void +wl_keyboard_send_leave(struct wl_resource *resource_, uint32_t serial, struct wl_resource *surface) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_LEAVE, serial, surface); +} + +/** + * @ingroup iface_wl_keyboard + * Sends an key event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the key event + * @param time timestamp with millisecond granularity + * @param key key that produced the event + * @param state physical state of the key + */ +static inline void +wl_keyboard_send_key(struct wl_resource *resource_, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_KEY, serial, time, key, state); +} + +/** + * @ingroup iface_wl_keyboard + * Sends an modifiers event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the modifiers event + * @param mods_depressed depressed modifiers + * @param mods_latched latched modifiers + * @param mods_locked locked modifiers + * @param group keyboard layout + */ +static inline void +wl_keyboard_send_modifiers(struct wl_resource *resource_, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_MODIFIERS, serial, mods_depressed, mods_latched, mods_locked, group); +} + +/** + * @ingroup iface_wl_keyboard + * Sends an repeat_info event to the client owning the resource. + * @param resource_ The client's resource + * @param rate the rate of repeating keys in characters per second + * @param delay delay in milliseconds since key down until repeating starts + */ +static inline void +wl_keyboard_send_repeat_info(struct wl_resource *resource_, int32_t rate, int32_t delay) +{ + wl_resource_post_event(resource_, WL_KEYBOARD_REPEAT_INFO, rate, delay); +} + +/** + * @ingroup iface_wl_touch + * @struct wl_touch_interface + */ +struct wl_touch_interface { + /** + * release the touch object + * + * + * @since 3 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_TOUCH_DOWN 0 +#define WL_TOUCH_UP 1 +#define WL_TOUCH_MOTION 2 +#define WL_TOUCH_FRAME 3 +#define WL_TOUCH_CANCEL 4 +#define WL_TOUCH_SHAPE 5 +#define WL_TOUCH_ORIENTATION 6 + +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_DOWN_SINCE_VERSION 1 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_UP_SINCE_VERSION 1 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_MOTION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_FRAME_SINCE_VERSION 1 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_CANCEL_SINCE_VERSION 1 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_SHAPE_SINCE_VERSION 6 +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_ORIENTATION_SINCE_VERSION 6 + +/** + * @ingroup iface_wl_touch + */ +#define WL_TOUCH_RELEASE_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_touch + * Sends an down event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the touch down event + * @param time timestamp with millisecond granularity + * @param surface surface touched + * @param id the unique ID of this touch point + * @param x surface-local x coordinate + * @param y surface-local y coordinate + */ +static inline void +wl_touch_send_down(struct wl_resource *resource_, uint32_t serial, uint32_t time, struct wl_resource *surface, int32_t id, wl_fixed_t x, wl_fixed_t y) +{ + wl_resource_post_event(resource_, WL_TOUCH_DOWN, serial, time, surface, id, x, y); +} + +/** + * @ingroup iface_wl_touch + * Sends an up event to the client owning the resource. + * @param resource_ The client's resource + * @param serial serial number of the touch up event + * @param time timestamp with millisecond granularity + * @param id the unique ID of this touch point + */ +static inline void +wl_touch_send_up(struct wl_resource *resource_, uint32_t serial, uint32_t time, int32_t id) +{ + wl_resource_post_event(resource_, WL_TOUCH_UP, serial, time, id); +} + +/** + * @ingroup iface_wl_touch + * Sends an motion event to the client owning the resource. + * @param resource_ The client's resource + * @param time timestamp with millisecond granularity + * @param id the unique ID of this touch point + * @param x surface-local x coordinate + * @param y surface-local y coordinate + */ +static inline void +wl_touch_send_motion(struct wl_resource *resource_, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y) +{ + wl_resource_post_event(resource_, WL_TOUCH_MOTION, time, id, x, y); +} + +/** + * @ingroup iface_wl_touch + * Sends an frame event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_touch_send_frame(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_TOUCH_FRAME); +} + +/** + * @ingroup iface_wl_touch + * Sends an cancel event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_touch_send_cancel(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_TOUCH_CANCEL); +} + +/** + * @ingroup iface_wl_touch + * Sends an shape event to the client owning the resource. + * @param resource_ The client's resource + * @param id the unique ID of this touch point + * @param major length of the major axis in surface-local coordinates + * @param minor length of the minor axis in surface-local coordinates + */ +static inline void +wl_touch_send_shape(struct wl_resource *resource_, int32_t id, wl_fixed_t major, wl_fixed_t minor) +{ + wl_resource_post_event(resource_, WL_TOUCH_SHAPE, id, major, minor); +} + +/** + * @ingroup iface_wl_touch + * Sends an orientation event to the client owning the resource. + * @param resource_ The client's resource + * @param id the unique ID of this touch point + * @param orientation angle between major axis and positive surface y-axis in degrees + */ +static inline void +wl_touch_send_orientation(struct wl_resource *resource_, int32_t id, wl_fixed_t orientation) +{ + wl_resource_post_event(resource_, WL_TOUCH_ORIENTATION, id, orientation); +} + +#ifndef WL_OUTPUT_SUBPIXEL_ENUM +#define WL_OUTPUT_SUBPIXEL_ENUM +/** + * @ingroup iface_wl_output + * subpixel geometry information + * + * This enumeration describes how the physical + * pixels on an output are laid out. + */ +enum wl_output_subpixel { + /** + * unknown geometry + */ + WL_OUTPUT_SUBPIXEL_UNKNOWN = 0, + /** + * no geometry + */ + WL_OUTPUT_SUBPIXEL_NONE = 1, + /** + * horizontal RGB + */ + WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB = 2, + /** + * horizontal BGR + */ + WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR = 3, + /** + * vertical RGB + */ + WL_OUTPUT_SUBPIXEL_VERTICAL_RGB = 4, + /** + * vertical BGR + */ + WL_OUTPUT_SUBPIXEL_VERTICAL_BGR = 5, +}; +#endif /* WL_OUTPUT_SUBPIXEL_ENUM */ + +#ifndef WL_OUTPUT_SUBPIXEL_ENUM_IS_VALID +#define WL_OUTPUT_SUBPIXEL_ENUM_IS_VALID +/** + * @ingroup iface_wl_output + * Validate a wl_output subpixel value. + * + * @return true on success, false on error. + * @ref wl_output_subpixel + */ +static inline bool +wl_output_subpixel_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_OUTPUT_SUBPIXEL_UNKNOWN: + return version >= 1; + case WL_OUTPUT_SUBPIXEL_NONE: + return version >= 1; + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: + return version >= 1; + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: + return version >= 1; + case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: + return version >= 1; + case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: + return version >= 1; + default: + return false; + } +} +#endif /* WL_OUTPUT_SUBPIXEL_ENUM_IS_VALID */ + +#ifndef WL_OUTPUT_TRANSFORM_ENUM +#define WL_OUTPUT_TRANSFORM_ENUM +/** + * @ingroup iface_wl_output + * transformation applied to buffer contents + * + * This describes transformations that clients and compositors apply to + * buffer contents. + * + * The flipped values correspond to an initial flip around a + * vertical axis followed by rotation. + * + * The purpose is mainly to allow clients to render accordingly and + * tell the compositor, so that for fullscreen surfaces, the + * compositor will still be able to scan out directly from client + * surfaces. + */ +enum wl_output_transform { + /** + * no transform + */ + WL_OUTPUT_TRANSFORM_NORMAL = 0, + /** + * 90 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_90 = 1, + /** + * 180 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_180 = 2, + /** + * 270 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_270 = 3, + /** + * 180 degree flip around a vertical axis + */ + WL_OUTPUT_TRANSFORM_FLIPPED = 4, + /** + * flip and rotate 90 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_FLIPPED_90 = 5, + /** + * flip and rotate 180 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_FLIPPED_180 = 6, + /** + * flip and rotate 270 degrees counter-clockwise + */ + WL_OUTPUT_TRANSFORM_FLIPPED_270 = 7, +}; +#endif /* WL_OUTPUT_TRANSFORM_ENUM */ + +#ifndef WL_OUTPUT_TRANSFORM_ENUM_IS_VALID +#define WL_OUTPUT_TRANSFORM_ENUM_IS_VALID +/** + * @ingroup iface_wl_output + * Validate a wl_output transform value. + * + * @return true on success, false on error. + * @ref wl_output_transform + */ +static inline bool +wl_output_transform_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_OUTPUT_TRANSFORM_NORMAL: + return version >= 1; + case WL_OUTPUT_TRANSFORM_90: + return version >= 1; + case WL_OUTPUT_TRANSFORM_180: + return version >= 1; + case WL_OUTPUT_TRANSFORM_270: + return version >= 1; + case WL_OUTPUT_TRANSFORM_FLIPPED: + return version >= 1; + case WL_OUTPUT_TRANSFORM_FLIPPED_90: + return version >= 1; + case WL_OUTPUT_TRANSFORM_FLIPPED_180: + return version >= 1; + case WL_OUTPUT_TRANSFORM_FLIPPED_270: + return version >= 1; + default: + return false; + } +} +#endif /* WL_OUTPUT_TRANSFORM_ENUM_IS_VALID */ + +#ifndef WL_OUTPUT_MODE_ENUM +#define WL_OUTPUT_MODE_ENUM +/** + * @ingroup iface_wl_output + * mode information + * + * These flags describe properties of an output mode. + * They are used in the flags bitfield of the mode event. + */ +enum wl_output_mode { + /** + * indicates this is the current mode + */ + WL_OUTPUT_MODE_CURRENT = 0x1, + /** + * indicates this is the preferred mode + */ + WL_OUTPUT_MODE_PREFERRED = 0x2, +}; +#endif /* WL_OUTPUT_MODE_ENUM */ + +#ifndef WL_OUTPUT_MODE_ENUM_IS_VALID +#define WL_OUTPUT_MODE_ENUM_IS_VALID +/** + * @ingroup iface_wl_output + * Validate a wl_output mode value. + * + * @return true on success, false on error. + * @ref wl_output_mode + */ +static inline bool +wl_output_mode_is_valid(uint32_t value, uint32_t version) { + uint32_t valid = 0; + if (version >= 1) + valid |= WL_OUTPUT_MODE_CURRENT; + if (version >= 1) + valid |= WL_OUTPUT_MODE_PREFERRED; + return (value & ~valid) == 0; +} +#endif /* WL_OUTPUT_MODE_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_output + * @struct wl_output_interface + */ +struct wl_output_interface { + /** + * release the output object + * + * Using this request a client can tell the server that it is not + * going to use the output object anymore. + * @since 3 + */ + void (*release)(struct wl_client *client, + struct wl_resource *resource); +}; + +#define WL_OUTPUT_GEOMETRY 0 +#define WL_OUTPUT_MODE 1 +#define WL_OUTPUT_DONE 2 +#define WL_OUTPUT_SCALE 3 +#define WL_OUTPUT_NAME 4 +#define WL_OUTPUT_DESCRIPTION 5 + +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_GEOMETRY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_MODE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_DONE_SINCE_VERSION 2 +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_SCALE_SINCE_VERSION 2 +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_NAME_SINCE_VERSION 4 +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_DESCRIPTION_SINCE_VERSION 4 + +/** + * @ingroup iface_wl_output + */ +#define WL_OUTPUT_RELEASE_SINCE_VERSION 3 + +/** + * @ingroup iface_wl_output + * Sends an geometry event to the client owning the resource. + * @param resource_ The client's resource + * @param x x position within the global compositor space + * @param y y position within the global compositor space + * @param physical_width width in millimeters of the output + * @param physical_height height in millimeters of the output + * @param subpixel subpixel orientation of the output + * @param make textual description of the manufacturer + * @param model textual description of the model + * @param transform additional transformation applied to buffer contents during presentation + */ +static inline void +wl_output_send_geometry(struct wl_resource *resource_, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform) +{ + wl_resource_post_event(resource_, WL_OUTPUT_GEOMETRY, x, y, physical_width, physical_height, subpixel, make, model, transform); +} + +/** + * @ingroup iface_wl_output + * Sends an mode event to the client owning the resource. + * @param resource_ The client's resource + * @param flags bitfield of mode flags + * @param width width of the mode in hardware units + * @param height height of the mode in hardware units + * @param refresh vertical refresh rate in mHz + */ +static inline void +wl_output_send_mode(struct wl_resource *resource_, uint32_t flags, int32_t width, int32_t height, int32_t refresh) +{ + wl_resource_post_event(resource_, WL_OUTPUT_MODE, flags, width, height, refresh); +} + +/** + * @ingroup iface_wl_output + * Sends an done event to the client owning the resource. + * @param resource_ The client's resource + */ +static inline void +wl_output_send_done(struct wl_resource *resource_) +{ + wl_resource_post_event(resource_, WL_OUTPUT_DONE); +} + +/** + * @ingroup iface_wl_output + * Sends an scale event to the client owning the resource. + * @param resource_ The client's resource + * @param factor scaling factor of output + */ +static inline void +wl_output_send_scale(struct wl_resource *resource_, int32_t factor) +{ + wl_resource_post_event(resource_, WL_OUTPUT_SCALE, factor); +} + +/** + * @ingroup iface_wl_output + * Sends an name event to the client owning the resource. + * @param resource_ The client's resource + * @param name output name + */ +static inline void +wl_output_send_name(struct wl_resource *resource_, const char *name) +{ + wl_resource_post_event(resource_, WL_OUTPUT_NAME, name); +} + +/** + * @ingroup iface_wl_output + * Sends an description event to the client owning the resource. + * @param resource_ The client's resource + * @param description output description + */ +static inline void +wl_output_send_description(struct wl_resource *resource_, const char *description) +{ + wl_resource_post_event(resource_, WL_OUTPUT_DESCRIPTION, description); +} + +/** + * @ingroup iface_wl_region + * @struct wl_region_interface + */ +struct wl_region_interface { + /** + * destroy region + * + * Destroy the region. This will invalidate the object ID. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * add rectangle to region + * + * Add the specified rectangle to the region. + * @param x region-local x coordinate + * @param y region-local y coordinate + * @param width rectangle width + * @param height rectangle height + */ + void (*add)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); + /** + * subtract rectangle from region + * + * Subtract the specified rectangle from the region. + * @param x region-local x coordinate + * @param y region-local y coordinate + * @param width rectangle width + * @param height rectangle height + */ + void (*subtract)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y, + int32_t width, + int32_t height); +}; + + +/** + * @ingroup iface_wl_region + */ +#define WL_REGION_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_region + */ +#define WL_REGION_ADD_SINCE_VERSION 1 +/** + * @ingroup iface_wl_region + */ +#define WL_REGION_SUBTRACT_SINCE_VERSION 1 + +#ifndef WL_SUBCOMPOSITOR_ERROR_ENUM +#define WL_SUBCOMPOSITOR_ERROR_ENUM +enum wl_subcompositor_error { + /** + * the to-be sub-surface is invalid + */ + WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE = 0, + /** + * the to-be sub-surface parent is invalid + */ + WL_SUBCOMPOSITOR_ERROR_BAD_PARENT = 1, +}; +#endif /* WL_SUBCOMPOSITOR_ERROR_ENUM */ + +#ifndef WL_SUBCOMPOSITOR_ERROR_ENUM_IS_VALID +#define WL_SUBCOMPOSITOR_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_subcompositor + * Validate a wl_subcompositor error value. + * + * @return true on success, false on error. + * @ref wl_subcompositor_error + */ +static inline bool +wl_subcompositor_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE: + return version >= 1; + case WL_SUBCOMPOSITOR_ERROR_BAD_PARENT: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SUBCOMPOSITOR_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_subcompositor + * @struct wl_subcompositor_interface + */ +struct wl_subcompositor_interface { + /** + * unbind from the subcompositor interface + * + * Informs the server that the client will not be using this + * protocol object anymore. This does not affect any other objects, + * wl_subsurface objects included. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * give a surface the role sub-surface + * + * Create a sub-surface interface for the given surface, and + * associate it with the given parent surface. This turns a plain + * wl_surface into a sub-surface. + * + * The to-be sub-surface must not already have another role, and it + * must not have an existing wl_subsurface object. Otherwise the + * bad_surface protocol error is raised. + * + * Adding sub-surfaces to a parent is a double-buffered operation + * on the parent (see wl_surface.commit). The effect of adding a + * sub-surface becomes visible on the next time the state of the + * parent surface is applied. + * + * The parent surface must not be one of the child surface's + * descendants, and the parent must be different from the child + * surface, otherwise the bad_parent protocol error is raised. + * + * This request modifies the behaviour of wl_surface.commit request + * on the sub-surface, see the documentation on wl_subsurface + * interface. + * @param id the new sub-surface object ID + * @param surface the surface to be turned into a sub-surface + * @param parent the parent surface + */ + void (*get_subsurface)(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, + struct wl_resource *surface, + struct wl_resource *parent); +}; + + +/** + * @ingroup iface_wl_subcompositor + */ +#define WL_SUBCOMPOSITOR_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subcompositor + */ +#define WL_SUBCOMPOSITOR_GET_SUBSURFACE_SINCE_VERSION 1 + +#ifndef WL_SUBSURFACE_ERROR_ENUM +#define WL_SUBSURFACE_ERROR_ENUM +enum wl_subsurface_error { + /** + * wl_surface is not a sibling or the parent + */ + WL_SUBSURFACE_ERROR_BAD_SURFACE = 0, +}; +#endif /* WL_SUBSURFACE_ERROR_ENUM */ + +#ifndef WL_SUBSURFACE_ERROR_ENUM_IS_VALID +#define WL_SUBSURFACE_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_subsurface + * Validate a wl_subsurface error value. + * + * @return true on success, false on error. + * @ref wl_subsurface_error + */ +static inline bool +wl_subsurface_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_SUBSURFACE_ERROR_BAD_SURFACE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_SUBSURFACE_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_subsurface + * @struct wl_subsurface_interface + */ +struct wl_subsurface_interface { + /** + * remove sub-surface interface + * + * The sub-surface interface is removed from the wl_surface + * object that was turned into a sub-surface with a + * wl_subcompositor.get_subsurface request. The wl_surface's + * association to the parent is deleted. The wl_surface is unmapped + * immediately. + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * reposition the sub-surface + * + * This sets the position of the sub-surface, relative to the + * parent surface. + * + * The sub-surface will be moved so that its origin (top left + * corner pixel) will be at the location x, y of the parent surface + * coordinate system. The coordinates are not restricted to the + * parent surface area. Negative values are allowed. + * + * The initial position is 0, 0. + * + * Position is double-buffered state on the parent surface, see + * wl_subsurface and wl_surface.commit for more information. + * @param x x coordinate in the parent surface + * @param y y coordinate in the parent surface + */ + void (*set_position)(struct wl_client *client, + struct wl_resource *resource, + int32_t x, + int32_t y); + /** + * restack the sub-surface + * + * This sub-surface is taken from the stack, and put back just + * above the reference surface, changing the z-order of the + * sub-surfaces. The reference surface must be one of the sibling + * surfaces, or the parent surface. Using any other surface, + * including this sub-surface, will cause a protocol error. + * + * A new sub-surface is initially added as the top-most in the + * stack of its siblings and parent. + * + * Z-order is double-buffered state on the parent surface, see + * wl_subsurface and wl_surface.commit for more information. + * @param sibling the reference surface + */ + void (*place_above)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *sibling); + /** + * restack the sub-surface + * + * The sub-surface is placed just below the reference surface. + * + * See wl_subsurface.place_above. + * @param sibling the reference surface + */ + void (*place_below)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *sibling); + /** + * set sub-surface to synchronized mode + * + * Change the commit behaviour of the sub-surface to synchronized + * mode. + * + * See wl_subsurface and wl_surface.commit for more information. + */ + void (*set_sync)(struct wl_client *client, + struct wl_resource *resource); + /** + * set sub-surface to desynchronized mode + * + * Change the commit behaviour of the sub-surface to + * desynchronized mode. + * + * See wl_subsurface and wl_surface.commit for more information. + */ + void (*set_desync)(struct wl_client *client, + struct wl_resource *resource); +}; + + +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_SET_POSITION_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_PLACE_ABOVE_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_PLACE_BELOW_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_SET_SYNC_SINCE_VERSION 1 +/** + * @ingroup iface_wl_subsurface + */ +#define WL_SUBSURFACE_SET_DESYNC_SINCE_VERSION 1 + +#ifndef WL_FIXES_ERROR_ENUM +#define WL_FIXES_ERROR_ENUM +/** + * @ingroup iface_wl_fixes + * wl_fixes error values + * + * These errors can be emitted in response to wl_fixes requests. + */ +enum wl_fixes_error { + /** + * unknown global or the global is not removed + */ + WL_FIXES_ERROR_INVALID_ACK_REMOVE = 0, +}; +#endif /* WL_FIXES_ERROR_ENUM */ + +#ifndef WL_FIXES_ERROR_ENUM_IS_VALID +#define WL_FIXES_ERROR_ENUM_IS_VALID +/** + * @ingroup iface_wl_fixes + * Validate a wl_fixes error value. + * + * @return true on success, false on error. + * @ref wl_fixes_error + */ +static inline bool +wl_fixes_error_is_valid(uint32_t value, uint32_t version) { + switch (value) { + case WL_FIXES_ERROR_INVALID_ACK_REMOVE: + return version >= 1; + default: + return false; + } +} +#endif /* WL_FIXES_ERROR_ENUM_IS_VALID */ + +/** + * @ingroup iface_wl_fixes + * @struct wl_fixes_interface + */ +struct wl_fixes_interface { + /** + * destroys this object + * + * + */ + void (*destroy)(struct wl_client *client, + struct wl_resource *resource); + /** + * destroy a wl_registry + * + * This request destroys a wl_registry object. + * + * The client should no longer use the wl_registry after making + * this request. + * + * The compositor will emit a wl_display.delete_id event with the + * object ID of the registry and will no longer emit any events on + * the registry. The client should re-use the object ID once it + * receives the wl_display.delete_id event. + * @param registry the registry to destroy + */ + void (*destroy_registry)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *registry); + /** + * acknowledge global removal + * + * Acknowledge the removal of the specified global. + * + * If no global with the specified name exists or the global is not + * removed, the wl_fixes.invalid_ack_remove protocol error will be + * posted. + * + * Due to the Wayland protocol being asynchronous, the wl_global + * objects cannot be destroyed immediately. For example, if a + * wl_global is removed and a client attempts to bind that global + * around same time, it can result in a protocol error due to an + * unknown global name in the bind request. + * + * In order to avoid crashing clients, the compositor should remove + * the wl_global once it is guaranteed that no more bind requests + * will come. + * + * The wl_fixes.ack_global_remove() request is used to signal to + * the compositor that the client will not bind the given global + * anymore. After all clients acknowledge the removal of the + * global, the compositor can safely destroy it. + * + * The client must call the wl_fixes.ack_global_remove() request in + * response to a wl_registry.global_remove() event even if it did + * not bind the corresponding global. + * @param registry the registry object + * @param name unique name of the global + * @since 2 + */ + void (*ack_global_remove)(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *registry, + uint32_t name); +}; + + +/** + * @ingroup iface_wl_fixes + */ +#define WL_FIXES_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_fixes + */ +#define WL_FIXES_DESTROY_REGISTRY_SINCE_VERSION 1 +/** + * @ingroup iface_wl_fixes + */ +#define WL_FIXES_ACK_GLOBAL_REMOVE_SINCE_VERSION 2 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server.h b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server.h new file mode 100644 index 0000000000..48fab1ddac --- /dev/null +++ b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-server.h @@ -0,0 +1,111 @@ +/* + * Copyright © 2008 Kristian Høgsberg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** \file + * + * \brief Include the server API, deprecations and protocol C API. + * + * \warning Use of this header file is discouraged. Prefer including + * wayland-server-core.h instead, which does not include the + * server protocol header and as such only defines the library + * API, excluding the deprecated API below. + */ + +#ifndef WAYLAND_SERVER_H +#define WAYLAND_SERVER_H + +#include <stdint.h> +#include "wayland-server-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The user can set this macro to hide the wl_object, wl_resource and wl_buffer + * objects alongside the associated API. + * + * The structs were meant to be opaque, although we missed that in the early days. + * + * NOTE: the list of structs, functions, etc in this section MUST NEVER GROW. + * Otherwise we will break forward compatibility and applications that used to + * build fine will no longer be able to do so. + */ +#ifndef WL_HIDE_DEPRECATED + +struct wl_object { + const struct wl_interface *interface; + const void *implementation; + uint32_t id; +}; + +struct wl_resource { + struct wl_object object; + wl_resource_destroy_func_t destroy; + struct wl_list link; + struct wl_signal destroy_signal; + struct wl_client *client; + void *data; +}; + +WL_DEPRECATED +uint32_t +wl_client_add_resource(struct wl_client *client, + struct wl_resource *resource); + +WL_DEPRECATED +struct wl_resource * +wl_client_add_object(struct wl_client *client, + const struct wl_interface *interface, + const void *implementation, + uint32_t id, void *data); + +WL_DEPRECATED +struct wl_resource * +wl_client_new_object(struct wl_client *client, + const struct wl_interface *interface, + const void *implementation, void *data); + +WL_DEPRECATED +struct wl_global * +wl_display_add_global(struct wl_display *display, + const struct wl_interface *interface, + void *data, + wl_global_bind_func_t bind); + +WL_DEPRECATED +void +wl_display_remove_global(struct wl_display *display, + struct wl_global *global); + +#endif + +#ifdef __cplusplus +} +#endif + +#include "wayland-server-protocol.h" + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-util.h b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-util.h new file mode 100644 index 0000000000..98c72fdeda --- /dev/null +++ b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-util.h @@ -0,0 +1,768 @@ +/* + * Copyright © 2008 Kristian Høgsberg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** \file wayland-util.h + * + * \brief Utility classes, functions, and macros. + */ + +#ifndef WAYLAND_UTIL_H +#define WAYLAND_UTIL_H + +#include <math.h> +#include <stddef.h> +#include <inttypes.h> +#include <stdarg.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** Visibility attribute */ +#if defined(__GNUC__) && __GNUC__ >= 4 +#define WL_EXPORT __attribute__ ((visibility("default"))) +#else +#define WL_EXPORT +#endif + +/** Deprecated attribute */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || (defined(__cplusplus) && __cplusplus >= 201402L) +#define WL_DEPRECATED [[deprecated]] +#elif defined(__GNUC__) && __GNUC__ >= 4 +#define WL_DEPRECATED __attribute__ ((deprecated)) +#else +#define WL_DEPRECATED +#endif + +/** + * Printf-style argument attribute + * + * \param x Ordinality of the format string argument + * \param y Ordinality of the argument to check against the format string + * + * \sa https://gcc.gnu.org/onlinedocs/gcc-3.2.1/gcc/Function-Attributes.html + */ +#if defined(__GNUC__) && __GNUC__ >= 4 +#define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y))) +#else +#define WL_PRINTF(x, y) +#endif + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define WL_TYPEOF(expr) typeof(expr) +#else +#define WL_TYPEOF(expr) __typeof__(expr) +#endif + +/** \class wl_object + * + * \brief A protocol object. + * + * A `wl_object` is an opaque struct identifying the protocol object + * underlying a `wl_proxy` or `wl_resource`. + * + * \note Functions accessing a `wl_object` are not normally used by client code. + * Clients should normally use the higher level interface generated by the + * scanner to interact with compositor objects. + * + */ +struct wl_object; + +/** + * The maximum size of a protocol message. + * + * If a message size exceeds this value, the connection will be dropped. + * Servers will send an invalid_method error before disconnecting. + */ +#define WL_MAX_MESSAGE_SIZE 4096 + +/** + * Protocol message signature + * + * A wl_message describes the signature of an actual protocol message, such as a + * request or event, that adheres to the Wayland protocol wire format. The + * protocol implementation uses a wl_message within its demarshal machinery for + * decoding messages between a compositor and its clients. In a sense, a + * wl_message is to a protocol message like a class is to an object. + * + * The `name` of a wl_message is the name of the corresponding protocol message. + * + * The `signature` is an ordered list of symbols representing the data types + * of message arguments and, optionally, a protocol version and indicators for + * nullability. A leading integer in the `signature` indicates the _since_ + * version of the protocol message. A `?` preceding a data type symbol indicates + * that the following argument type is nullable. While it is a protocol violation + * to send messages with non-nullable arguments set to `NULL`, event handlers in + * clients might still get called with non-nullable object arguments set to + * `NULL`. This can happen when the client destroyed the object being used as + * argument on its side and an event referencing that object was sent before the + * server knew about its destruction. As this race cannot be prevented, clients + * should - as a general rule - program their event handlers such that they can + * handle object arguments declared non-nullable being `NULL` gracefully. + * + * When no arguments accompany a message, `signature` is an empty string. + * + * Symbols: + * + * * `i`: int + * * `u`: uint + * * `f`: fixed + * * `s`: string + * * `o`: object + * * `n`: new_id + * * `a`: array + * * `h`: fd + * * `?`: following argument (`o` or `s`) is nullable + * + * While demarshaling primitive arguments is straightforward, when demarshaling + * messages containing `object` or `new_id` arguments, the protocol + * implementation often must determine the type of the object. The `types` of a + * wl_message is an array of wl_interface references that correspond to `o` and + * `n` arguments in `signature`, with `NULL` placeholders for arguments with + * non-object types. + * + * Consider the protocol event wl_display `delete_id` that has a single `uint` + * argument. The wl_message is: + * + * \code + * { "delete_id", "u", [NULL] } + * \endcode + * + * Here, the message `name` is `"delete_id"`, the `signature` is `"u"`, and the + * argument `types` is `[NULL]`, indicating that the `uint` argument has no + * corresponding wl_interface since it is a primitive argument. + * + * In contrast, consider a `wl_foo` interface supporting protocol request `bar` + * that has existed since version 2, and has two arguments: a `uint` and an + * object of type `wl_baz_interface` that may be `NULL`. Such a `wl_message` + * might be: + * + * \code + * { "bar", "2u?o", [NULL, &wl_baz_interface] } + * \endcode + * + * Here, the message `name` is `"bar"`, and the `signature` is `"2u?o"`. Notice + * how the `2` indicates the protocol version, the `u` indicates the first + * argument type is `uint`, and the `?o` indicates that the second argument + * is an object that may be `NULL`. Lastly, the argument `types` array indicates + * that no wl_interface corresponds to the first argument, while the type + * `wl_baz_interface` corresponds to the second argument. + * + * \sa wl_argument + * \sa wl_interface + * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Wire-Format">Wire Format</a> + */ +struct wl_message { + /** Message name */ + const char *name; + /** Message signature */ + const char *signature; + /** Object argument interfaces */ + const struct wl_interface **types; +}; + +/** + * Protocol object interface + * + * A wl_interface describes the API of a protocol object defined in the Wayland + * protocol specification. The protocol implementation uses a wl_interface + * within its marshalling machinery for encoding client requests. + * + * The `name` of a wl_interface is the name of the corresponding protocol + * interface, and `version` represents the version of the interface. The members + * `method_count` and `event_count` represent the number of `methods` (requests) + * and `events` in the respective wl_message members. + * + * For example, consider a protocol interface `foo`, marked as version `1`, with + * two requests and one event. + * + * \code{.xml} + * <interface name="foo" version="1"> + * <request name="a"></request> + * <request name="b"></request> + * <event name="c"></event> + * </interface> + * \endcode + * + * Given two wl_message arrays `foo_requests` and `foo_events`, a wl_interface + * for `foo` might be: + * + * \code + * struct wl_interface foo_interface = { + * "foo", 1, + * 2, foo_requests, + * 1, foo_events + * }; + * \endcode + * + * \note The server side of the protocol may define interface <em>implementation + * types</em> that incorporate the term `interface` in their name. Take + * care to not confuse these server-side `struct`s with a wl_interface + * variable whose name also ends in `interface`. For example, while the + * server may define a type `struct wl_foo_interface`, the client may + * define a `struct wl_interface wl_foo_interface`. + * + * \sa wl_message + * \sa wl_proxy + * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Interfaces">Interfaces</a> + * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-Versioning">Versioning</a> + */ +struct wl_interface { + /** Interface name */ + const char *name; + /** Interface version */ + int version; + /** Number of methods (requests) */ + int method_count; + /** Method (request) signatures */ + const struct wl_message *methods; + /** Number of events */ + int event_count; + /** Event signatures */ + const struct wl_message *events; +}; + +/** \class wl_list + * + * \brief Doubly-linked list + * + * On its own, an instance of `struct wl_list` represents the sentinel head of + * a doubly-linked list, and must be initialized using wl_list_init(). + * When empty, the list head's `next` and `prev` members point to the list head + * itself, otherwise `next` references the first element in the list, and `prev` + * refers to the last element in the list. + * + * Use the `struct wl_list` type to represent both the list head and the links + * between elements within the list. Use wl_list_empty() to determine if the + * list is empty in O(1). + * + * All elements in the list must be of the same type. The element type must have + * a `struct wl_list` member, often named `link` by convention. Prior to + * insertion, there is no need to initialize an element's `link` - invoking + * wl_list_init() on an individual list element's `struct wl_list` member is + * unnecessary if the very next operation is wl_list_insert(). However, a + * common idiom is to initialize an element's `link` prior to removal - ensure + * safety by invoking wl_list_init() before wl_list_remove(). + * + * Consider a list reference `struct wl_list foo_list`, an element type as + * `struct element`, and an element's link member as `struct wl_list link`. + * + * The following code initializes a list and adds three elements to it. + * + * \code + * struct wl_list foo_list; + * + * struct element { + * int foo; + * struct wl_list link; + * }; + * struct element e1, e2, e3; + * + * wl_list_init(&foo_list); + * wl_list_insert(&foo_list, &e1.link); // e1 is the first element + * wl_list_insert(&foo_list, &e2.link); // e2 is now the first element + * wl_list_insert(&e2.link, &e3.link); // insert e3 after e2 + * \endcode + * + * The list now looks like <em>[e2, e3, e1]</em>. + * + * The `wl_list` API provides some iterator macros. For example, to iterate + * a list in ascending order: + * + * \code + * struct element *e; + * wl_list_for_each(e, foo_list, link) { + * do_something_with_element(e); + * } + * \endcode + * + * See the documentation of each iterator for details. + * \sa http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h + */ +struct wl_list { + /** Previous list element */ + struct wl_list *prev; + /** Next list element */ + struct wl_list *next; +}; + +/** + * Initializes the list. + * + * \param list List to initialize + * + * \memberof wl_list + */ +void +wl_list_init(struct wl_list *list); + +/** + * Inserts an element into the list, after the element represented by \p list. + * When \p list is a reference to the list itself (the head), set the containing + * struct of \p elm as the first element in the list. + * + * \note If \p elm is already part of a list, inserting it again will lead to + * list corruption. + * + * \param list List element after which the new element is inserted + * \param elm Link of the containing struct to insert into the list + * + * \memberof wl_list + */ +void +wl_list_insert(struct wl_list *list, struct wl_list *elm); + +/** + * Removes an element from the list. + * + * \note This operation leaves \p elm in an invalid state. + * + * \param elm Link of the containing struct to remove from the list + * + * \memberof wl_list + */ +void +wl_list_remove(struct wl_list *elm); + +/** + * Determines the length of the list. + * + * \note This is an O(n) operation. + * + * \param list List whose length is to be determined + * + * \return Number of elements in the list + * + * \memberof wl_list + */ +int +wl_list_length(const struct wl_list *list); + +/** + * Determines if the list is empty. + * + * \param list List whose emptiness is to be determined + * + * \return 1 if empty, or 0 if not empty + * + * \memberof wl_list + */ +int +wl_list_empty(const struct wl_list *list); + +/** + * Inserts all of the elements of one list into another, after the element + * represented by \p list. + * + * \note This leaves \p other in an invalid state. + * + * \param list List element after which the other list elements will be inserted + * \param other List of elements to insert + * + * \memberof wl_list + */ +void +wl_list_insert_list(struct wl_list *list, struct wl_list *other); + +/** + * Retrieves a pointer to a containing struct, given a member name. + * + * This macro allows "conversion" from a pointer to a member to its containing + * struct. This is useful if you have a contained item like a wl_list, + * wl_listener, or wl_signal, provided via a callback or other means, and would + * like to retrieve the struct that contains it. + * + * To demonstrate, the following example retrieves a pointer to + * `example_container` given only its `destroy_listener` member: + * + * \code + * struct example_container { + * struct wl_listener destroy_listener; + * // other members... + * }; + * + * void example_container_destroy(struct wl_listener *listener, void *data) + * { + * struct example_container *ctr; + * + * ctr = wl_container_of(listener, ctr, destroy_listener); + * // destroy ctr... + * } + * \endcode + * + * \note `sample` need not be a valid pointer. A null or uninitialised pointer + * is sufficient. + * + * \param ptr Valid pointer to the contained member + * \param sample Pointer to a struct whose type contains \p ptr + * \param member Named location of \p ptr within the \p sample type + * + * \return The container for the specified pointer + */ +#define wl_container_of(ptr, sample, member) \ + (WL_TYPEOF(sample))((char *)(ptr) - \ + offsetof(WL_TYPEOF(*sample), member)) + +/** + * Iterates over a list. + * + * This macro expresses a for-each iterator for wl_list. Given a list and + * wl_list link member name (often named `link` by convention), this macro + * assigns each element in the list to \p pos, which can then be referenced in + * a trailing code block. For example, given a wl_list of `struct message` + * elements: + * + * \code + * struct message { + * char *contents; + * wl_list link; + * }; + * + * struct wl_list *message_list; + * // Assume message_list now "contains" many messages + * + * struct message *m; + * wl_list_for_each(m, message_list, link) { + * do_something_with_message(m); + * } + * \endcode + * + * \param pos Cursor that each list element will be assigned to + * \param head Head of the list to iterate over + * \param member Name of the link member within the element struct + * + * \relates wl_list + */ +#define wl_list_for_each(pos, head, member) \ + for (pos = wl_container_of((head)->next, pos, member); \ + &pos->member != (head); \ + pos = wl_container_of(pos->member.next, pos, member)) + +/** + * Iterates over a list, safe against removal of the list element. + * + * \note Only removal of the current element, \p pos, is safe. Removing + * any other element during traversal may lead to a loop malfunction. + * + * \sa wl_list_for_each() + * + * \param pos Cursor that each list element will be assigned to + * \param tmp Temporary pointer of the same type as \p pos + * \param head Head of the list to iterate over + * \param member Name of the link member within the element struct + * + * \relates wl_list + */ +#define wl_list_for_each_safe(pos, tmp, head, member) \ + for (pos = wl_container_of((head)->next, pos, member), \ + tmp = wl_container_of((pos)->member.next, tmp, member); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = wl_container_of(pos->member.next, tmp, member)) + +/** + * Iterates backwards over a list. + * + * \sa wl_list_for_each() + * + * \param pos Cursor that each list element will be assigned to + * \param head Head of the list to iterate over + * \param member Name of the link member within the element struct + * + * \relates wl_list + */ +#define wl_list_for_each_reverse(pos, head, member) \ + for (pos = wl_container_of((head)->prev, pos, member); \ + &pos->member != (head); \ + pos = wl_container_of(pos->member.prev, pos, member)) + +/** + * Iterates backwards over a list, safe against removal of the list element. + * + * \note Only removal of the current element, \p pos, is safe. Removing + * any other element during traversal may lead to a loop malfunction. + * + * \sa wl_list_for_each() + * + * \param pos Cursor that each list element will be assigned to + * \param tmp Temporary pointer of the same type as \p pos + * \param head Head of the list to iterate over + * \param member Name of the link member within the element struct + * + * \relates wl_list + */ +#define wl_list_for_each_reverse_safe(pos, tmp, head, member) \ + for (pos = wl_container_of((head)->prev, pos, member), \ + tmp = wl_container_of((pos)->member.prev, tmp, member); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = wl_container_of(pos->member.prev, tmp, member)) + +/** + * \class wl_array + * + * Dynamic array + * + * A wl_array is a dynamic array that can only grow until released. It is + * intended for relatively small allocations whose size is variable or not known + * in advance. While construction of a wl_array does not require all elements to + * be of the same size, wl_array_for_each() does require all elements to have + * the same type and size. + * + */ +struct wl_array { + /** Array size */ + size_t size; + /** Allocated space */ + size_t alloc; + /** Array data */ + void *data; +}; + +/** + * Initializes the array. + * + * \param array Array to initialize + * + * \memberof wl_array + */ +void +wl_array_init(struct wl_array *array); + +/** + * Releases the array data. + * + * \note Leaves the array in an invalid state. + * + * \param array Array whose data is to be released + * + * \memberof wl_array + */ +void +wl_array_release(struct wl_array *array); + +/** + * Increases the size of the array by \p size bytes. + * + * \param array Array whose size is to be increased + * \param size Number of bytes to increase the size of the array by + * + * \return A pointer to the beginning of the newly appended space, or NULL when + * resizing fails. + * + * \memberof wl_array + */ +void * +wl_array_add(struct wl_array *array, size_t size); + +/** + * Copies the contents of \p source to \p array. + * + * \param array Destination array to copy to + * \param source Source array to copy from + * + * \return 0 on success, or -1 on failure + * + * \memberof wl_array + */ +int +wl_array_copy(struct wl_array *array, struct wl_array *source); + +/** + * Iterates over an array. + * + * This macro expresses a for-each iterator for wl_array. It assigns each + * element in the array to \p pos, which can then be referenced in a trailing + * code block. \p pos must be a pointer to the array element type, and all + * array elements must be of the same type and size. + * + * \param pos Cursor that each array element will be assigned to + * \param array Array to iterate over + * + * \relates wl_array + * \sa wl_list_for_each() + */ +#define wl_array_for_each(pos, array) \ + for (pos = (array)->data; \ + (array)->size != 0 && \ + (const char *) pos < ((const char *) (array)->data + (array)->size); \ + (pos)++) + +/** + * Fixed-point number + * + * A `wl_fixed_t` is a 24.8 signed fixed-point number with a sign bit, 23 bits + * of integer precision and 8 bits of decimal precision. Consider `wl_fixed_t` + * as an opaque struct with methods that facilitate conversion to and from + * `double` and `int` types. + */ +typedef int32_t wl_fixed_t; + +/** + * Converts a fixed-point number to a floating-point number. + * + * \param f Fixed-point number to convert + * + * \return Floating-point representation of the fixed-point argument + */ +static inline double +wl_fixed_to_double(wl_fixed_t f) +{ + return f / 256.0; +} + +/** + * Converts a floating-point number to a fixed-point number. + * + * \param d Floating-point number to convert + * + * \return Fixed-point representation of the floating-point argument + */ +static inline wl_fixed_t +wl_fixed_from_double(double d) +{ + return (wl_fixed_t) (round(d * 256.0)); +} + +/** + * Converts a fixed-point number to an integer. + * + * \param f Fixed-point number to convert + * + * \return Integer component of the fixed-point argument + */ +static inline int +wl_fixed_to_int(wl_fixed_t f) +{ + return f / 256; +} + +/** + * Converts an integer to a fixed-point number. + * + * \param i Integer to convert + * + * \return Fixed-point representation of the integer argument + */ +static inline wl_fixed_t +wl_fixed_from_int(int i) +{ + return i * 256; +} + +/** + * Protocol message argument data types + * + * This union represents all of the argument types in the Wayland protocol wire + * format. The protocol implementation uses wl_argument within its marshalling + * machinery for dispatching messages between a client and a compositor. + * + * \sa wl_message + * \sa wl_interface + * \sa <a href="https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-wire-Format">Wire Format</a> + */ +union wl_argument { + int32_t i; /**< `int` */ + uint32_t u; /**< `uint` */ + wl_fixed_t f; /**< `fixed` */ + const char *s; /**< `string` */ + struct wl_object *o; /**< `object` */ + uint32_t n; /**< `new_id` */ + struct wl_array *a; /**< `array` */ + int32_t h; /**< `fd` */ +}; + +/** + * Dispatcher function type alias + * + * A dispatcher is a function that handles the emitting of callbacks in client + * code. For programs directly using the C library, this is done by using + * libffi to call function pointers. When binding to languages other than C, + * dispatchers provide a way to abstract the function calling process to be + * friendlier to other function calling systems. + * + * A dispatcher takes five arguments: The first is the dispatcher-specific + * implementation associated with the target object. The second is the object + * upon which the callback is being invoked (either wl_proxy or wl_resource). + * The third and fourth arguments are the opcode and the wl_message + * corresponding to the callback. The final argument is an array of arguments + * received from the other process via the wire protocol. + * + * \param user_data Dispatcher-specific implementation data + * \param target Callback invocation target (wl_proxy or `wl_resource`) + * \param opcode Callback opcode + * \param msg Callback message signature + * \param args Array of received arguments + * + * \return 0 on success, or -1 on failure + */ +typedef int (*wl_dispatcher_func_t)(const void *user_data, void *target, + uint32_t opcode, const struct wl_message *msg, + union wl_argument *args); + +/** + * Log function type alias + * + * The C implementation of the Wayland protocol abstracts the details of + * logging. Users may customize the logging behavior, with a function conforming + * to the `wl_log_func_t` type, via `wl_log_set_handler_client` and + * `wl_log_set_handler_server`. + * + * A `wl_log_func_t` must conform to the expectations of `vprintf`, and + * expects two arguments: a string to write and a corresponding variable + * argument list. While the string to write may contain format specifiers and + * use values in the variable argument list, the behavior of any `wl_log_func_t` + * depends on the implementation. + * + * \note Take care to not confuse this with `wl_protocol_logger_func_t`, which + * is a specific server-side logger for requests and events. + * + * \param fmt String to write to the log, containing optional format + * specifiers + * \param args Variable argument list + * + * \sa wl_log_set_handler_client + * \sa wl_log_set_handler_server + */ +typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0); + +/** + * Return value of an iterator function + * + * \sa wl_client_for_each_resource_iterator_func_t + * \sa wl_client_for_each_resource + */ +enum wl_iterator_result { + /** Stop the iteration */ + WL_ITERATOR_STOP, + /** Continue the iteration */ + WL_ITERATOR_CONTINUE +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-version.h b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-version.h new file mode 100644 index 0000000000..c7e04c2cd4 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/prebuilt/include/wayland-version.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef WAYLAND_VERSION_H +#define WAYLAND_VERSION_H + +#define WAYLAND_VERSION_MAJOR 1 +#define WAYLAND_VERSION_MINOR 26 +#define WAYLAND_VERSION_MICRO 0 +#define WAYLAND_VERSION "1.26.0" + +#endif diff --git a/app/src/main/cpp/waylandcomp/prebuilt/lib/libwayland-server.so b/app/src/main/cpp/waylandcomp/prebuilt/lib/libwayland-server.so new file mode 100755 index 0000000000..4eda476851 Binary files /dev/null and b/app/src/main/cpp/waylandcomp/prebuilt/lib/libwayland-server.so differ diff --git a/app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml b/app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml new file mode 100644 index 0000000000..1560c8f7cb --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/banner-ahb-v1.xml @@ -0,0 +1,105 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="banner_ahb_v1"> + <copyright> + Copyright 2026 The412Banner + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="banner_ahb_v1" version="2"> + <description summary="Android gralloc buffers behind dma-buf wl_buffers"> + Zero-copy window layers on Android. A Vulkan swapchain image that the + client allocated as an Android AHardwareBuffer (gralloc) is still shared + as a dma-buf through zwp_linux_dmabuf_v1, so the compositor can import + and draw it the usual way. This interface additionally hands the + compositor the AHardwareBuffer itself, once per wl_buffer, so the + compositor can put the buffer straight on an Android SurfaceControl + layer (SurfaceFlinger / the display hardware composite it) without + copying it. + + The AHardwareBuffer travels over a Unix socket: the client creates a + socketpair, writes the buffer's handle into one end with + AHardwareBuffer_sendHandleToUnixSocket, then sends the other end in the + attach request. The compositor reads it with + AHardwareBuffer_recvHandleFromUnixSocket and closes the socket. Its + reference to the AHardwareBuffer lives as long as the wl_buffer (plus + whatever the display still holds). + + The compositor advertises this global whenever it can put buffers on a + display layer at all; whether it WANTS gralloc buffers right now is the + mode event (version 2), sent on bind and every time the user switches + zero-copy on or off during the session. A client decides per swapchain, + when it creates the swapchain, from the last mode it received, and a + client whose live swapchain was built for the other mode retires it + (VK_ERROR_OUT_OF_DATE_KHR on its next acquire or present) so the program + rebuilds it for the new mode. Buffers of the old swapchain stay fully + presentable until then: an attached AHardwareBuffer keeps its association + for the wl_buffer's lifetime whatever the mode is now. A version 1 + client (no mode event) keeps deciding from its own environment. A + client that does not see the global (or does not want it) allocates + swapchain images the standard way; nothing else changes. + + Synchronisation stays implicit: the dma-buf carries the client's render + fence (DMA_BUF_IOCTL_IMPORT_SYNC_FILE by the client's driver), the + compositor exports it as the layer's acquire fence, and the compositor + imports the display's release fence into the dma-buf before it sends + wl_buffer.release, so the client's next acquire waits on it. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the object"> + Buffers already attached keep their AHardwareBuffer association. + </description> + </request> + + <request name="attach"> + <description summary="hand the compositor a buffer's AHardwareBuffer"> + Associates the AHardwareBuffer readable from socket with the + (already created) dma-buf wl_buffer. width, height and stride + (pixels) describe the gralloc allocation; modifier_hi/lo is the DRM + format modifier the dma-buf was shared with (the same value passed to + zwp_linux_buffer_params_v1.add); image_count is the number of images + in the swapchain this buffer belongs to (for the compositor's log). + Sent once per wl_buffer, before the buffer is first attached to a + surface. + </description> + <arg name="buffer" type="object" interface="wl_buffer" summary="the dma-buf wl_buffer"/> + <arg name="socket" type="fd" summary="socket the AHardwareBuffer handle was written to"/> + <arg name="width" type="uint" summary="buffer width in pixels"/> + <arg name="height" type="uint" summary="buffer height in pixels"/> + <arg name="stride" type="uint" summary="gralloc row stride in pixels"/> + <arg name="modifier_hi" type="uint" summary="high 32 bits of the DRM format modifier"/> + <arg name="modifier_lo" type="uint" summary="low 32 bits of the DRM format modifier"/> + <arg name="image_count" type="uint" summary="images in the client's swapchain"/> + </request> + + <event name="mode" since="2"> + <description summary="whether the compositor wants gralloc swapchain images now"> + Sent once right after bind and again whenever the compositor's + zero-copy state flips (the in-game switch). enabled = 1: swapchains + created from now on should use gralloc AHardwareBuffers and attach + them; 0: standard buffers. A live swapchain built for the other value + should be retired by the client (out of date) so the program rebuilds + it; until it is, its buffers are shown as before. + </description> + <arg name="enabled" type="uint" summary="1 = gralloc swapchain images wanted, 0 = not"/> + </event> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/banner-desktop-v1.xml b/app/src/main/cpp/waylandcomp/protocols/banner-desktop-v1.xml new file mode 100644 index 0000000000..7c62b2a2e2 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/banner-desktop-v1.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="banner_desktop_v1"> + <copyright> + Copyright 2026 The412Banner + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="banner_desktop_v1" version="1"> + <description summary="Windows virtual desktop layout"> + Each Wine process is a separate Wayland client, so a Windows virtual + desktop can't be built from subsurfaces. Instead the process that owns + the desktop window marks one surface as the desktop, and every process + reports where its top-level windows sit on that desktop and the global + window stacking order. The compositor draws the desktop at the bottom, + the windows at the reported positions, and sends pointer and keyboard + input to the desktop surface; Wine routes it to the right window. + </description> + + <request name="destroy" type="destructor"/> + + <request name="set_desktop"> + <description summary="mark a surface as the virtual desktop"> + The surface is drawn at the origin, below every window, and sets the + size of the desktop. + </description> + <arg name="surface" type="object" interface="wl_surface"/> + </request> + + <request name="set_window"> + <description summary="place a top-level window on the desktop"> + Position of the top-left corner of the surface in desktop + coordinates, and the window handle used by set_zorder. + </description> + <arg name="surface" type="object" interface="wl_surface"/> + <arg name="hwnd" type="uint"/> + <arg name="x" type="int"/> + <arg name="y" type="int"/> + </request> + + <request name="set_zorder"> + <description summary="report the desktop's window stacking order"> + Visible top-level window handles as 32-bit values, topmost first. + </description> + <arg name="hwnds" type="array"/> + </request> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/color-management-v1.xml b/app/src/main/cpp/waylandcomp/protocols/color-management-v1.xml new file mode 100644 index 0000000000..7f8da78f12 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/color-management-v1.xml @@ -0,0 +1,1631 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="color_management_v1"> + <copyright> + Copyright 2019 Sebastian Wick + Copyright 2019 Erwin Burema + Copyright 2020 AMD + Copyright 2020-2024 Collabora, Ltd. + Copyright 2024 Xaver Hugl + Copyright 2022-2025 Red Hat, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="color management protocol"> + The aim of the color management extension is to allow clients to know + the color properties of outputs, and to tell the compositor about the color + properties of their content on surfaces. Doing this enables a compositor + to perform automatic color management of content for different outputs + according to how content is intended to look like. + + The color properties are represented as an image description object which + is immutable after it has been created. A wl_output always has an + associated image description that clients can observe. A wl_surface + always has an associated preferred image description as a hint chosen by + the compositor that clients can also observe. Clients can set an image + description on a wl_surface to denote the color characteristics of the + surface contents. + + An image description includes SDR and HDR colorimetry and encoding, HDR + metadata, and viewing environment parameters. An image description does + not include the properties set through color-representation extension. + It is expected that the color-representation extension is used in + conjunction with the color management extension when necessary, + particularly with the YUV family of pixel formats. + + Recommendation ITU-T H.273 + "Coding-independent code points for video signal type identification" + shall be referred to as simply H.273 here. + + The color-and-hdr repository + (https://gitlab.freedesktop.org/pq/color-and-hdr) contains + background information on the protocol design and legacy color management. + It also contains a glossary, learning resources for digital color, tools, + samples and more. + + The terminology used in this protocol is based on common color science and + color encoding terminology where possible. The glossary in the color-and-hdr + repository shall be the authority on the definition of terms in this + protocol. + + Warning! The protocol described in this file is currently in the testing + phase. Backward compatible changes may be added together with the + corresponding interface version bump. Backward incompatible changes can + only be done by creating a new major version of the extension. + </description> + + <interface name="wp_color_manager_v1" version="1"> + <description summary="color manager singleton"> + A singleton global interface used for getting color management extensions + for wl_surface and wl_output objects, and for creating client defined + image description objects. The extension interfaces allow + getting the image description of outputs and setting the image + description of surfaces. + + Compositors should never remove this global. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the color manager"> + Destroy the wp_color_manager_v1 object. This does not affect any other + objects in any way. + </description> + </request> + + <enum name="error"> + <entry name="unsupported_feature" value="0" + summary="request not supported"/> + <entry name="surface_exists" value="1" + summary="color management surface exists already"/> + </enum> + + <enum name="render_intent"> + <description summary="rendering intents"> + See the ICC.1:2022 specification from the International Color Consortium + for more details about rendering intents. + + The principles of ICC defined rendering intents apply with all types of + image descriptions, not only those with ICC file profiles. + + Compositors must support the perceptual rendering intent. Other + rendering intents are optional. + </description> + + <entry name="perceptual" value="0" + summary="perceptual"/> + <entry name="relative" value="1" + summary="media-relative colorimetric"/> + <entry name="saturation" value="2" + summary="saturation"/> + <entry name="absolute" value="3" + summary="ICC-absolute colorimetric"/> + <entry name="relative_bpc" value="4" + summary="media-relative colorimetric + black point compensation"/> + </enum> + + <enum name="feature"> + <description summary="compositor supported features"/> + + <entry name="icc_v2_v4" value="0" + summary="create_icc_creator request"/> + <entry name="parametric" value="1" + summary="create_parametric_creator request"/> + <entry name="set_primaries" value="2" + summary="parametric set_primaries request"/> + <entry name="set_tf_power" value="3" + summary="parametric set_tf_power request"/> + <entry name="set_luminances" value="4" + summary="parametric set_luminances request"/> + <entry name="set_mastering_display_primaries" value="5"> + <description summary="parametric set_mastering_display_primaries request"> + The compositor supports set_mastering_display_primaries request with a + target color volume fully contained inside the primary color volume. + </description> + </entry> + <entry name="extended_target_volume" value="6"> + <description summary="parametric target exceeds primary color volume"> + The compositor additionally supports target color volumes that + extend outside of the primary color volume. + + This can only be advertised if feature set_mastering_display_primaries + is supported as well. + </description> + </entry> + <entry name="windows_scrgb" value="7" + summary="get_windows_scrgb request"/> + </enum> + + <enum name="primaries"> + <description summary="named color primaries"> + Named color primaries used to encode well-known sets of primaries. H.273 + is the authority, when it comes to the exact values of primaries and + authoritative specifications, where an equivalent code point exists. + + A value of 0 is invalid and will never be present in the list of enums. + + Descriptions do list the specifications for convenience. + </description> + + <entry name="srgb" value="1"> + <description summary="Color primaries for the sRGB color space as defined by the BT.709 standard"> + Color primaries as defined by + - Rec. ITU-R BT.709-6 + - Rec. ITU-R BT.1361-0 conventional colour gamut system and extended + colour gamut system (historical) + - IEC 61966-2-1 sRGB or sYCC + - IEC 61966-2-4 + - Society of Motion Picture and Television Engineers (SMPTE) RP 177 + (1993) Annex B + Equivalent to H.273 ColourPrimaries code point 1. + </description> + </entry> + <entry name="pal_m" value="2"> + <description summary="Color primaries for PAL-M as defined by the BT.470 standard"> + Color primaries as defined by + - Rec. ITU-R BT.470-6 System M (historical) + - United States National Television System Committee 1953 + Recommendation for transmission standards for color television + - United States Federal Communications Commission (2003) Title 47 Code + of Federal Regulations 73.682 (a)(20) + Equivalent to H.273 ColourPrimaries code point 4. + </description> + </entry> + <entry name="pal" value="3"> + <description summary="Color primaries for PAL as defined by the BT.601 standard"> + Color primaries as defined by + - Rec. ITU-R BT.470-6 System B, G (historical) + - Rec. ITU-R BT.601-7 625 + - Rec. ITU-R BT.1358-0 625 (historical) + - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM + Equivalent to H.273 ColourPrimaries code point 5. + </description> + </entry> + <entry name="ntsc" value="4"> + <description summary="Color primaries for NTSC as defined by the BT.601 standard"> + Color primaries as defined by + - Rec. ITU-R BT.601-7 525 + - Rec. ITU-R BT.1358-1 525 or 625 (historical) + - Rec. ITU-R BT.1700-0 NTSC + - SMPTE 170M (2004) + - SMPTE 240M (1999) (historical) + Equivalent to H.273 ColourPrimaries code point 6 and 7. + </description> + </entry> + <entry name="generic_film" value="5"> + <description summary="Generic film with colour filters using Illuminant C"> + Color primaries as defined by H.273 for generic film. + Equivalent to H.273 ColourPrimaries code point 8. + </description> + </entry> + <entry name="bt2020" value="6"> + <description summary="Color primaries as defined by the BT.2020 and BT.2100 standard"> + Color primaries as defined by + - Rec. ITU-R BT.2020-2 + - Rec. ITU-R BT.2100-0 + Equivalent to H.273 ColourPrimaries code point 9. + </description> + </entry> + <entry name="cie1931_xyz" value="7"> + <description summary="Color primaries of the full CIE 1931 XYZ color space"> + Color primaries as defined as the maximum of the CIE 1931 XYZ color + space by + - SMPTE ST 428-1 + - (CIE 1931 XYZ as in ISO 11664-1) + Equivalent to H.273 ColourPrimaries code point 10. + </description> + </entry> + <entry name="dci_p3" value="8"> + <description summary="Color primaries of the DCI P3 color space as defined by the SMPTE RP 431 standard"> + Color primaries as defined by Digital Cinema System and published in + SMPTE RP 431-2 (2011). Equivalent to H.273 ColourPrimaries code point + 11. + </description> + </entry> + <entry name="display_p3" value="9"> + <description summary="Color primaries of Display P3 variant of the DCI-P3 color space as defined by the SMPTE EG 432 standard"> + Color primaries as defined by Digital Cinema System and published in + SMPTE EG 432-1 (2010). + Equivalent to H.273 ColourPrimaries code point 12. + </description> + </entry> + <entry name="adobe_rgb" value="10"> + <description summary="Color primaries of the Adobe RGB color space as defined by the ISO 12640 standard"> + Color primaries as defined by Adobe as "Adobe RGB" and later published + by ISO 12640-4 (2011). + </description> + </entry> + </enum> + + <enum name="transfer_function"> + <description summary="named transfer functions"> + Named transfer functions used to represent well-known transfer + characteristics. H.273 is the authority, when it comes to the exact + formulas and authoritative specifications, where an equivalent code + point exists. + + A value of 0 is invalid and will never be present in the list of enums. + + Descriptions do list the specifications for convenience. + </description> + + <entry name="bt1886" value="1"> + <description summary="BT.1886 display transfer characteristic"> + Rec. ITU-R BT.1886 is the display transfer characteristic assumed by + - Rec. ITU-R BT.601-7 525 and 625 + - Rec. ITU-R BT.709-6 + - Rec. ITU-R BT.2020-2 + These recommendations are referred to by H.273 TransferCharacteristics + code points 1, 6, 14, and 15, which are all equivalent. + + This TF implies these default luminances from Rec. ITU-R BT.2035: + - primary color volume minimum: 0.01 cd/m² + - primary color volume maximum: 100 cd/m² + - reference white: 100 cd/m² + </description> + </entry> + <entry name="gamma22" value="2"> + <description summary="Assumed display gamma 2.2 transfer function"> + Transfer characteristics as defined by + - Rec. ITU-R BT.470-6 System M (historical) + - United States National Television System Committee 1953 + Recommendation for transmission standards for color television + - United States Federal Communications Commission (2003) Title 47 Code + of Federal Regulations 73.682 (a) (20) + - Rec. ITU-R BT.1700-0 625 PAL and 625 SECAM + Equivalent to H.273 TransferCharacteristics code point 4. + </description> + </entry> + <entry name="gamma28" value="3"> + <description summary="Assumed display gamma 2.8 transfer function"> + Transfer characteristics as defined by + - Rec. ITU-R BT.470-6 System B, G (historical) + Equivalent to H.273 TransferCharacteristics code point 5. + </description> + </entry> + <entry name="st240" value="4"> + <description summary="SMPTE ST 240 transfer function"> + Transfer characteristics as defined by + - SMPTE ST 240 (1999) + Equivalent to H.273 TransferCharacteristics code point 7. + </description> + </entry> + <entry name="ext_linear" value="5"> + <description summary="extended linear transfer function"> + Linear transfer function defined over all real numbers. + Normalised electrical values are equal the normalised optical values. + + The differences to H.273 TransferCharacteristics code point 8 are + the definition over all real numbers. + </description> + </entry> + <entry name="log_100" value="6"> + <description summary="logarithmic 100:1 transfer function"> + Logarithmic transfer characteristic (100:1 range). + Equivalent to H.273 TransferCharacteristics code point 9. + </description> + </entry> + <entry name="log_316" value="7"> + <description summary="logarithmic (100*Sqrt(10) : 1) transfer function"> + Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range). + Equivalent to H.273 TransferCharacteristics code point 10. + </description> + </entry> + <entry name="xvycc" value="8"> + <description summary="IEC 61966-2-4 transfer function"> + Transfer characteristics as defined by + - IEC 61966-2-4 + Equivalent to H.273 TransferCharacteristics code point 11. + </description> + </entry> + <entry name="srgb" value="9"> + <description summary="sRGB piece-wise transfer function"> + Transfer characteristics as defined by + - IEC 61966-2-1 sRGB + Equivalent to H.273 TransferCharacteristics code point 13 with + MatrixCoefficients set to 0. + </description> + </entry> + <entry name="ext_srgb" value="10"> + <description summary="Extended sRGB piece-wise transfer function"> + Transfer characteristics as defined by + - IEC 61966-2-1 sYCC + Equivalent to H.273 TransferCharacteristics code point 13 with + MatrixCoefficients set to anything but 0. + </description> + </entry> + <entry name="st2084_pq" value="11"> + <description summary="perceptual quantizer transfer function"> + Transfer characteristics as defined by + - SMPTE ST 2084 (2014) for 10-, 12-, 14- and 16-bit systems + - Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system + Equivalent to H.273 TransferCharacteristics code point 16. + + This TF implies these default luminances + - primary color volume minimum: 0.005 cd/m² + - primary color volume maximum: 10000 cd/m² + - reference white: 203 cd/m² + + The difference between the primary color volume minimum and maximum + must be approximately 10000 cd/m² as that is the swing of the EOTF + defined by ST 2084 and BT.2100. The default value for the + reference white is a protocol addition: it is suggested by + Report ITU-R BT.2408-7 and is not part of ST 2084 or BT.2100. + </description> + </entry> + <entry name="st428" value="12"> + <description summary="SMPTE ST 428 transfer function"> + Transfer characteristics as defined by + - SMPTE ST 428-1 (2019) + Equivalent to H.273 TransferCharacteristics code point 17. + </description> + </entry> + <entry name="hlg" value="13"> + <description summary="hybrid log-gamma transfer function"> + Transfer characteristics as defined by + - ARIB STD-B67 (2015) + - Rec. ITU-R BT.2100-2 hybrid log-gamma (HLG) system + Equivalent to H.273 TransferCharacteristics code point 18. + + This TF implies these default luminances + - primary color volume minimum: 0.005 cd/m² + - primary color volume maximum: 1000 cd/m² + - reference white: 203 cd/m² + + HLG is a relative display-referred signal with a specified + non-linear mapping to the display peak luminance (the HLG OOTF). + All absolute luminance values used here for HLG assume a 1000 cd/m² + peak display. + + The default value for the reference white is a protocol addition: + it is suggested by Report ITU-R BT.2408-7 and is not part of + ARIB STD-B67 or BT.2100. + </description> + </entry> + </enum> + + <request name="get_output"> + <description summary="create a color management interface for a wl_output"> + This creates a new wp_color_management_output_v1 object for the + given wl_output. + + See the wp_color_management_output_v1 interface for more details. + </description> + + <arg name="id" type="new_id" interface="wp_color_management_output_v1"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <request name="get_surface"> + <description summary="create a color management interface for a wl_surface"> + If a wp_color_management_surface_v1 object already exists for the given + wl_surface, the protocol error surface_exists is raised. + + This creates a new color wp_color_management_surface_v1 object for the + given wl_surface. + + See the wp_color_management_surface_v1 interface for more details. + </description> + + <arg name="id" type="new_id" interface="wp_color_management_surface_v1"/> + <arg name="surface" type="object" interface="wl_surface"/> + </request> + + <request name="get_surface_feedback"> + <description summary="create a color management feedback interface"> + This creates a new color wp_color_management_surface_feedback_v1 object + for the given wl_surface. + + See the wp_color_management_surface_feedback_v1 interface for more + details. + </description> + + <arg name="id" type="new_id" + interface="wp_color_management_surface_feedback_v1"/> + <arg name="surface" type="object" interface="wl_surface"/> + </request> + + <request name="create_icc_creator"> + <description summary="make a new ICC-based image description creator object"> + Makes a new ICC-based image description creator object with all + properties initially unset. The client can then use the object's + interface to define all the required properties for an image description + and finally create a wp_image_description_v1 object. + + This request can be used when the compositor advertises + wp_color_manager_v1.feature.icc_v2_v4. + Otherwise this request raises the protocol error unsupported_feature. + </description> + + <arg name="obj" + type="new_id" interface="wp_image_description_creator_icc_v1" + summary="the new creator object"/> + </request> + + <request name="create_parametric_creator"> + <description summary="make a new parametric image description creator object"> + Makes a new parametric image description creator object with all + properties initially unset. The client can then use the object's + interface to define all the required properties for an image description + and finally create a wp_image_description_v1 object. + + This request can be used when the compositor advertises + wp_color_manager_v1.feature.parametric. + Otherwise this request raises the protocol error unsupported_feature. + </description> + + <arg name="obj" + type="new_id" interface="wp_image_description_creator_params_v1" + summary="the new creator object"/> + </request> + + <request name="create_windows_scrgb"> + <description summary="create Windows-scRGB image description object"> + This creates a pre-defined image description for the so-called + Windows-scRGB stimulus encoding. This comes from the Windows 10 handling + of its own definition of an scRGB color space for an HDR screen + driven in BT.2100/PQ signalling mode. + + Windows-scRGB uses sRGB (BT.709) color primaries and white point. + The transfer characteristic is extended linear. + + The nominal color channel value range is extended, meaning it includes + negative and greater than 1.0 values. Negative values are used to + escape the sRGB color gamut boundaries. To make use of the extended + range, the client needs to use a pixel format that can represent those + values, e.g. floating-point 16 bits per channel. + + Nominal color value R=G=B=0.0 corresponds to BT.2100/PQ system + 0 cd/m², and R=G=B=1.0 corresponds to BT.2100/PQ system 80 cd/m². + The maximum is R=G=B=125.0 corresponding to 10k cd/m². + + Windows-scRGB is displayed by Windows 10 by converting it to + BT.2100/PQ, maintaining the CIE 1931 chromaticity and mapping the + luminance as above. No adjustment is made to the signal to account + for the viewing conditions. + + The reference white level of Windows-scRGB is unknown. If a + reference white level must be assumed for compositor processing, it + should be R=G=B=2.5375 corresponding to 203 cd/m² of Report ITU-R + BT.2408-7. + + The target color volume of Windows-scRGB is unknown. The color gamut + may be anything between sRGB and BT.2100. + + Note: EGL_EXT_gl_colorspace_scrgb_linear definition differs from + Windows-scRGB by using R=G=B=1.0 as the reference white level, while + Windows-scRGB reference white level is unknown or varies. However, + it seems probable that Windows implements both + EGL_EXT_gl_colorspace_scrgb_linear and Vulkan + VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT as Windows-scRGB. + + This request can be used when the compositor advertises + wp_color_manager_v1.feature.windows_scrgb. + Otherwise this request raises the protocol error unsupported_feature. + + The resulting image description object does not allow get_information + request. The wp_image_description_v1.ready event shall be sent. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + + <event name="supported_intent"> + <description summary="supported rendering intent"> + When this object is created, it shall immediately send this event once + for each rendering intent the compositor supports. + </description> + + <arg name="render_intent" type="uint" enum="render_intent" + summary="rendering intent"/> + </event> + + <event name="supported_feature"> + <description summary="supported features"> + When this object is created, it shall immediately send this event once + for each compositor supported feature listed in the enumeration. + </description> + + <arg name="feature" type="uint" enum="feature" + summary="supported feature"/> + </event> + + <event name="supported_tf_named"> + <description summary="supported named transfer characteristic"> + When this object is created, it shall immediately send this event once + for each named transfer function the compositor supports with the + parametric image description creator. + </description> + + <arg name="tf" type="uint" enum="transfer_function" + summary="Named transfer function"/> + </event> + + <event name="supported_primaries_named"> + <description summary="supported named primaries"> + When this object is created, it shall immediately send this event once + for each named set of primaries the compositor supports with the + parametric image description creator. + </description> + + <arg name="primaries" type="uint" enum="primaries" + summary="Named color primaries"/> + </event> + + <event name="done"> + <description summary="all features have been sent"> + This event is sent when all supported rendering intents, features, + transfer functions and named primaries have been sent. + </description> + </event> + </interface> + + <interface name="wp_color_management_output_v1" version="1"> + <description summary="output color properties"> + A wp_color_management_output_v1 describes the color properties of an + output. + + The wp_color_management_output_v1 is associated with the wl_output global + underlying the wl_output object. Therefore the client destroying the + wl_output object has no impact, but the compositor removing the output + global makes the wp_color_management_output_v1 object inert. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the color management output"> + Destroy the color wp_color_management_output_v1 object. This does not + affect any remaining protocol objects. + </description> + </request> + + <event name="image_description_changed"> + <description summary="image description changed"> + This event is sent whenever the image description of the output changed, + followed by one wl_output.done event common to output events across all + extensions. + + If the client wants to use the updated image description, it needs to do + get_image_description again, because image description objects are + immutable. + </description> + </event> + + <request name="get_image_description"> + <description summary="get the image description of the output"> + This creates a new wp_image_description_v1 object for the current image + description of the output. There always is exactly one image description + active for an output so the client should destroy the image description + created by earlier invocations of this request. This request is usually + sent as a reaction to the image_description_changed event or when + creating a wp_color_management_output_v1 object. + + The image description of an output represents the color encoding the + output expects. There might be performance and power advantages, as well + as improved color reproduction, if a content update matches the image + description of the output it is being shown on. If a content update is + shown on any other output than the one it matches the image description + of, then the color reproduction on those outputs might be considerably + worse. + + The created wp_image_description_v1 object preserves the image + description of the output from the time the object was created. + + The resulting image description object allows get_information request. + + If this protocol object is inert, the resulting image description object + shall immediately deliver the wp_image_description_v1.failed event with + the no_output cause. + + If the interface version is inadequate for the output's image + description, meaning that the client does not support all the events + needed to deliver the crucial information, the resulting image + description object shall immediately deliver the + wp_image_description_v1.failed event with the low_version cause. + + Otherwise the object shall immediately deliver the ready event. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + </interface> + + <interface name="wp_color_management_surface_v1" version="1"> + <description summary="color management extension to a surface"> + A wp_color_management_surface_v1 allows the client to set the color + space and HDR properties of a surface. + + If the wl_surface associated with the wp_color_management_surface_v1 is + destroyed, the wp_color_management_surface_v1 object becomes inert. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the color management interface for a surface"> + Destroy the wp_color_management_surface_v1 object and do the same as + unset_image_description. + </description> + </request> + + <enum name="error"> + <description summary="protocol errors"/> + <entry name="render_intent" value="0" + summary="unsupported rendering intent"/> + <entry name="image_description" value="1" + summary="invalid image description"/> + <entry name="inert" value="2" + summary="forbidden request on inert object"/> + </enum> + + <request name="set_image_description"> + <description summary="set the surface image description"> + If this protocol object is inert, the protocol error inert is raised. + + Set the image description of the underlying surface. The image + description and rendering intent are double-buffered state, see + wl_surface.commit. + + It is the client's responsibility to understand the image description + it sets on a surface, and to provide content that matches that image + description. Compositors might convert images to match their own or any + other image descriptions. + + Image descriptions which are not ready (see wp_image_description_v1) + are forbidden in this request, and in such case the protocol error + image_description is raised. + + All image descriptions which are ready (see wp_image_description_v1) + are allowed and must always be accepted by the compositor. + + A rendering intent provides the client's preference on how content + colors should be mapped to each output. The render_intent value must + be one advertised by the compositor with + wp_color_manager_v1.render_intent event, otherwise the protocol error + render_intent is raised. + + When an image description is set on a surface, the Transfer + Characteristics of the image description defines the valid range of + the nominal (real-valued) color channel values. The processing of + out-of-range color channel values is undefined, but compositors are + recommended to clamp the values to the valid range when possible. + + By default, a surface does not have an associated image description + nor a rendering intent. The handling of color on such surfaces is + compositor implementation defined. Compositors should handle such + surfaces as sRGB, but may handle them differently if they have specific + requirements. + + Setting the image description has copy semantics; after this request, + the image description can be immediately destroyed without affecting + the pending state of the surface. + </description> + + <arg name="image_description" + type="object" interface="wp_image_description_v1"/> + <arg name="render_intent" + type="uint" enum="wp_color_manager_v1.render_intent" + summary="rendering intent"/> + </request> + + <request name="unset_image_description"> + <description summary="remove the surface image description"> + If this protocol object is inert, the protocol error inert is raised. + + This request removes any image description from the surface. See + set_image_description for how a compositor handles a surface without + an image description. This is double-buffered state, see + wl_surface.commit. + </description> + </request> + </interface> + + <interface name="wp_color_management_surface_feedback_v1" version="1"> + <description summary="color management extension to a surface"> + A wp_color_management_surface_feedback_v1 allows the client to get the + preferred image description of a surface. + + If the wl_surface associated with this object is destroyed, the + wp_color_management_surface_feedback_v1 object becomes inert. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the color management interface for a surface"> + Destroy the wp_color_management_surface_feedback_v1 object. + </description> + </request> + + <enum name="error"> + <description summary="protocol errors"/> + <entry name="inert" value="0" + summary="forbidden request on inert object"/> + <entry name="unsupported_feature" value="1" + summary="attempted to use an unsupported feature"/> + </enum> + + <event name="preferred_changed"> + <description summary="the preferred image description changed"> + The preferred image description is the one which likely has the most + performance and/or quality benefits for the compositor if used by the + client for its wl_surface contents. This event is sent whenever the + compositor changes the wl_surface's preferred image description. + + This event sends the identity of the new preferred state as the argument, + so clients who are aware of the image description already can reuse it. + Otherwise, if the client client wants to know what the preferred image + description is, it shall use the get_preferred request. + + The preferred image description is not automatically used for anything. + It is only a hint, and clients may set any valid image description with + set_image_description, but there might be performance and color accuracy + improvements by providing the wl_surface contents in the preferred + image description. Therefore clients that can, should render according + to the preferred image description + </description> + + <arg name="identity" type="uint" summary="image description id number"/> + </event> + + <request name="get_preferred"> + <description summary="get the preferred image description"> + If this protocol object is inert, the protocol error inert is raised. + + The preferred image description represents the compositor's preferred + color encoding for this wl_surface at the current time. There might be + performance and power advantages, as well as improved color + reproduction, if the image description of a content update matches the + preferred image description. + + This creates a new wp_image_description_v1 object for the currently + preferred image description for the wl_surface. The client should + stop using and destroy the image descriptions created by earlier + invocations of this request for the associated wl_surface. + This request is usually sent as a reaction to the preferred_changed + event or when creating a wp_color_management_surface_feedback_v1 object + if the client is capable of adapting to image descriptions. + + The created wp_image_description_v1 object preserves the preferred image + description of the wl_surface from the time the object was created. + + The resulting image description object allows get_information request. + + If the image description is parametric, the client should set it on its + wl_surface only if the image description is an exact match with the + client content. Particularly if everything else matches, but the target + color volume is greater than what the client needs, the client should + create its own parameric image description with its exact parameters. + + If the interface version is inadequate for the preferred image + description, meaning that the client does not support all the + events needed to deliver the crucial information, the resulting image + description object shall immediately deliver the + wp_image_description_v1.failed event with the low_version cause, + otherwise the object shall immediately deliver the ready event. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + + <request name="get_preferred_parametric"> + <description summary="get the preferred image description"> + The same description as for get_preferred applies, except the returned + image description is guaranteed to be parametric. This is meant for + clients that can only deal with parametric image descriptions. + + If the compositor doesn't support parametric image descriptions, the + unsupported_feature error is emitted. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + </interface> + + <interface name="wp_image_description_creator_icc_v1" version="1"> + <description summary="holder of image description ICC information"> + This type of object is used for collecting all the information required + to create a wp_image_description_v1 object from an ICC file. A complete + set of required parameters consists of these properties: + - ICC file + + Each required property must be set exactly once if the client is to create + an image description. The set requests verify that a property was not + already set. The create request verifies that all required properties are + set. There may be several alternative requests for setting each property, + and in that case the client must choose one of them. + + Once all properties have been set, the create request must be used to + create the image description object, destroying the creator in the + process. + </description> + + <enum name="error"> + <description summary="protocol errors"/> + + <entry name="incomplete_set" value="0" + summary="incomplete parameter set"/> + <entry name="already_set" value="1" + summary="property already set"/> + <entry name="bad_fd" value="2" + summary="fd not seekable and readable"/> + <entry name="bad_size" value="3" + summary="no or too much data"/> + <entry name="out_of_file" value="4" + summary="offset + length exceeds file size"/> + </enum> + + <request name="create" type="destructor"> + <description summary="Create the image description object from ICC data"> + Create an image description object based on the ICC information + previously set on this object. A compositor must parse the ICC data in + some undefined but finite amount of time. + + The completeness of the parameter set is verified. If the set is not + complete, the protocol error incomplete_set is raised. For the + definition of a complete set, see the description of this interface. + + If the particular combination of the information is not supported + by the compositor, the resulting image description object shall + immediately deliver the wp_image_description_v1.failed event with the + 'unsupported' cause. If a valid image description was created from the + information, the wp_image_description_v1.ready event will eventually + be sent instead. + + This request destroys the wp_image_description_creator_icc_v1 object. + + The resulting image description object does not allow get_information + request. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + + <request name="set_icc_file"> + <description summary="set the ICC profile file"> + Sets the ICC profile file to be used as the basis of the image + description. + + The data shall be found through the given fd at the given offset, having + the given length. The fd must be seekable and readable. Violating these + requirements raises the bad_fd protocol error. + + If reading the data fails due to an error independent of the client, the + compositor shall send the wp_image_description_v1.failed event on the + created wp_image_description_v1 with the 'operating_system' cause. + + The maximum size of the ICC profile is 32 MB. If length is greater than + that or zero, the protocol error bad_size is raised. If offset + length + exceeds the file size, the protocol error out_of_file is raised. + + A compositor may read the file at any time starting from this request + and only until whichever happens first: + - If create request was issued, the wp_image_description_v1 object + delivers either failed or ready event; or + - if create request was not issued, this + wp_image_description_creator_icc_v1 object is destroyed. + + A compositor shall not modify the contents of the file, and the fd may + be sealed for writes and size changes. The client must ensure to its + best ability that the data does not change while the compositor is + reading it. + + The data must represent a valid ICC profile. The ICC profile version + must be 2 or 4, it must be a 3 channel profile and the class must be + Display or ColorSpace. Violating these requirements will not result in a + protocol error, but will eventually send the + wp_image_description_v1.failed event on the created + wp_image_description_v1 with the 'unsupported' cause. + + See the International Color Consortium specification ICC.1:2022 for more + details about ICC profiles. + + If ICC file has already been set on this object, the protocol error + already_set is raised. + </description> + + <arg name="icc_profile" type="fd" + summary="ICC profile"/> + <arg name="offset" type="uint" + summary="byte offset in fd to start of ICC data"/> + <arg name="length" type="uint" + summary="length of ICC data in bytes"/> + </request> + </interface> + + <interface name="wp_image_description_creator_params_v1" version="1"> + <description summary="holder of image description parameters"> + This type of object is used for collecting all the parameters required + to create a wp_image_description_v1 object. A complete set of required + parameters consists of these properties: + - transfer characteristic function (tf) + - chromaticities of primaries and white point (primary color volume) + + The following properties are optional and have a well-defined default + if not explicitly set: + - primary color volume luminance range + - reference white luminance level + - mastering display primaries and white point (target color volume) + - mastering luminance range + + The following properties are optional and will be ignored + if not explicitly set: + - maximum content light level + - maximum frame-average light level + + Each required property must be set exactly once if the client is to create + an image description. The set requests verify that a property was not + already set. The create request verifies that all required properties are + set. There may be several alternative requests for setting each property, + and in that case the client must choose one of them. + + Once all properties have been set, the create request must be used to + create the image description object, destroying the creator in the + process. + </description> + + <enum name="error"> + <description summary="protocol errors"/> + + <entry name="incomplete_set" value="0" + summary="incomplete parameter set"/> + <entry name="already_set" value="1" + summary="property already set"/> + <entry name="unsupported_feature" value="2" + summary="request not supported"/> + <entry name="invalid_tf" value="3" + summary="invalid transfer characteristic"/> + <entry name="invalid_primaries_named" value="4" + summary="invalid primaries named"/> + <entry name="invalid_luminance" value="5" + summary="invalid luminance value or range"/> + </enum> + + <request name="create" type="destructor"> + <description summary="Create the image description object using params"> + Create an image description object based on the parameters previously + set on this object. + + The completeness of the parameter set is verified. If the set is not + complete, the protocol error incomplete_set is raised. For the + definition of a complete set, see the description of this interface. + + The protocol error invalid_luminance is raised if any of the following + requirements is not met: + - When max_cll is set, it must be greater than min L and less or equal + to max L of the mastering luminance range. + - When max_fall is set, it must be greater than min L and less or equal + to max L of the mastering luminance range. + - When both max_cll and max_fall are set, max_fall must be less or equal + to max_cll. + + If the particular combination of the parameter set is not supported + by the compositor, the resulting image description object shall + immediately deliver the wp_image_description_v1.failed event with the + 'unsupported' cause. If a valid image description was created from the + parameter set, the wp_image_description_v1.ready event will eventually + be sent instead. + + This request destroys the wp_image_description_creator_params_v1 + object. + + The resulting image description object does not allow get_information + request. + </description> + + <arg name="image_description" + type="new_id" interface="wp_image_description_v1"/> + </request> + + <request name="set_tf_named"> + <description summary="named transfer characteristic"> + Sets the transfer characteristic using explicitly enumerated named + functions. + + When the resulting image description is attached to an image, the + content should be encoded and decoded according to the industry standard + practices for the transfer characteristic. + + Only names advertised with wp_color_manager_v1 event supported_tf_named + are allowed. Other values shall raise the protocol error invalid_tf. + + If transfer characteristic has already been set on this object, the + protocol error already_set is raised. + </description> + + <arg name="tf" type="uint" enum="wp_color_manager_v1.transfer_function" + summary="named transfer function"/> + </request> + + <request name="set_tf_power"> + <description summary="transfer characteristic as a power curve"> + Sets the color component transfer characteristic to a power curve with + the given exponent. Negative values are handled by mirroring the + positive half of the curve through the origin. The valid domain and + range of the curve are all finite real numbers. This curve represents + the conversion from electrical to optical color channel values. + + When the resulting image description is attached to an image, the + content should be encoded with the inverse of the power curve. + + The curve exponent shall be multiplied by 10000 to get the argument eexp + value to carry the precision of 4 decimals. + + The curve exponent must be at least 1.0 and at most 10.0. Otherwise the + protocol error invalid_tf is raised. + + If transfer characteristic has already been set on this object, the + protocol error already_set is raised. + + This request can be used when the compositor advertises + wp_color_manager_v1.feature.set_tf_power. Otherwise this request raises + the protocol error unsupported_feature. + </description> + + <arg name="eexp" type="uint" summary="the exponent * 10000"/> + </request> + + <request name="set_primaries_named"> + <description summary="named primaries"> + Sets the color primaries and white point using explicitly named sets. + This describes the primary color volume which is the basis for color + value encoding. + + Only names advertised with wp_color_manager_v1 event + supported_primaries_named are allowed. Other values shall raise the + protocol error invalid_primaries_named. + + If primaries have already been set on this object, the protocol error + already_set is raised. + </description> + + <arg name="primaries" type="uint" enum="wp_color_manager_v1.primaries" + summary="named primaries"/> + </request> + + <request name="set_primaries"> + <description summary="primaries as chromaticity coordinates"> + Sets the color primaries and white point using CIE 1931 xy chromaticity + coordinates. This describes the primary color volume which is the basis + for color value encoding. + + Each coordinate value is multiplied by 1 million to get the argument + value to carry precision of 6 decimals. + + If primaries have already been set on this object, the protocol error + already_set is raised. + + This request can be used if the compositor advertises + wp_color_manager_v1.feature.set_primaries. Otherwise this request raises + the protocol error unsupported_feature. + </description> + + <arg name="r_x" type="int" summary="Red x * 1M"/> + <arg name="r_y" type="int" summary="Red y * 1M"/> + <arg name="g_x" type="int" summary="Green x * 1M"/> + <arg name="g_y" type="int" summary="Green y * 1M"/> + <arg name="b_x" type="int" summary="Blue x * 1M"/> + <arg name="b_y" type="int" summary="Blue y * 1M"/> + <arg name="w_x" type="int" summary="White x * 1M"/> + <arg name="w_y" type="int" summary="White y * 1M"/> + </request> + + <request name="set_luminances"> + <description summary="primary color volume luminance range and reference white"> + Sets the primary color volume luminance range and the reference white + luminance level. These values include the minimum display emission + and ambient flare luminances, assumed to be optically additive and have + the chromaticity of the primary color volume white point. + + The default luminances from + https://www.color.org/chardata/rgb/srgb.xalter are + - primary color volume minimum: 0.2 cd/m² + - primary color volume maximum: 80 cd/m² + - reference white: 80 cd/m² + + Setting a named transfer characteristic can imply other default + luminances. + + The default luminances get overwritten when this request is used. + With transfer_function.st2084_pq the given 'max_lum' value is ignored, + and 'max_lum' is taken as 'min_lum' + 10000 cd/m². + + 'min_lum' and 'max_lum' specify the minimum and maximum luminances of + the primary color volume as reproduced by the targeted display. + + 'reference_lum' specifies the luminance of the reference white as + reproduced by the targeted display, and reflects the targeted viewing + environment. + + Compositors should make sure that all content is anchored, meaning that + an input signal level of 'reference_lum' on one image description and + another input signal level of 'reference_lum' on another image + description should produce the same output level, even though the + 'reference_lum' on both image representations can be different. + + 'reference_lum' may be higher than 'max_lum'. In that case reaching + the reference white output level in image content requires the + 'extended_target_volume' feature support. + + If 'max_lum' or 'reference_lum' are less than or equal to 'min_lum', + the protocol error invalid_luminance is raised. + + The minimum luminance is multiplied by 10000 to get the argument + 'min_lum' value and carries precision of 4 decimals. The maximum + luminance and reference white luminance values are unscaled. + + If the primary color volume luminance range and the reference white + luminance level have already been set on this object, the protocol error + already_set is raised. + + This request can be used if the compositor advertises + wp_color_manager_v1.feature.set_luminances. Otherwise this request + raises the protocol error unsupported_feature. + </description> + + <arg name="min_lum" type="uint" + summary="minimum luminance (cd/m²) * 10000"/> + <arg name="max_lum" type="uint" + summary="maximum luminance (cd/m²)"/> + <arg name="reference_lum" type="uint" + summary="reference white luminance (cd/m²)"/> + </request> + + <request name="set_mastering_display_primaries"> + <description summary="mastering display primaries as chromaticity coordinates"> + Provides the color primaries and white point of the mastering display + using CIE 1931 xy chromaticity coordinates. This is compatible with the + SMPTE ST 2086 definition of HDR static metadata. + + The mastering display primaries and mastering display luminances define + the target color volume. + + If mastering display primaries are not explicitly set, the target color + volume is assumed to have the same primaries as the primary color volume. + + The target color volume is defined by all tristimulus values between 0.0 + and 1.0 (inclusive) of the color space defined by the given mastering + display primaries and white point. The colorimetry is identical between + the container color space and the mastering display color space, + including that no chromatic adaptation is applied even if the white + points differ. + + The target color volume can exceed the primary color volume to allow for + a greater color volume with an existing color space definition (for + example scRGB). It can be smaller than the primary color volume to + minimize gamut and tone mapping distances for big color spaces (HDR + metadata). + + To make use of the entire target color volume a suitable pixel format + has to be chosen (e.g. floating point to exceed the primary color + volume, or abusing limited quantization range as with xvYCC). + + Each coordinate value is multiplied by 1 million to get the argument + value to carry precision of 6 decimals. + + If mastering display primaries have already been set on this object, the + protocol error already_set is raised. + + This request can be used if the compositor advertises + wp_color_manager_v1.feature.set_mastering_display_primaries. Otherwise + this request raises the protocol error unsupported_feature. The + advertisement implies support only for target color volumes fully + contained within the primary color volume. + + If a compositor additionally supports target color volume exceeding the + primary color volume, it must advertise + wp_color_manager_v1.feature.extended_target_volume. If a client uses + target color volume exceeding the primary color volume and the + compositor does not support it, the result is implementation defined. + Compositors are recommended to detect this case and fail the image + description gracefully, but it may as well result in color artifacts. + </description> + + <arg name="r_x" type="int" summary="Red x * 1M"/> + <arg name="r_y" type="int" summary="Red y * 1M"/> + <arg name="g_x" type="int" summary="Green x * 1M"/> + <arg name="g_y" type="int" summary="Green y * 1M"/> + <arg name="b_x" type="int" summary="Blue x * 1M"/> + <arg name="b_y" type="int" summary="Blue y * 1M"/> + <arg name="w_x" type="int" summary="White x * 1M"/> + <arg name="w_y" type="int" summary="White y * 1M"/> + </request> + + <request name="set_mastering_luminance"> + <description summary="display mastering luminance range"> + Sets the luminance range that was used during the content mastering + process as the minimum and maximum absolute luminance L. These values + include the minimum display emission and ambient flare luminances, + assumed to be optically additive and have the chromaticity of the + primary color volume white point. This should be + compatible with the SMPTE ST 2086 definition of HDR static metadata. + + The mastering display primaries and mastering display luminances define + the target color volume. + + If mastering luminances are not explicitly set, the target color volume + is assumed to have the same min and max luminances as the primary color + volume. + + If max L is less than or equal to min L, the protocol error + invalid_luminance is raised. + + Min L value is multiplied by 10000 to get the argument min_lum value + and carry precision of 4 decimals. Max L value is unscaled for max_lum. + + This request can be used if the compositor advertises + wp_color_manager_v1.feature.set_mastering_display_primaries. Otherwise + this request raises the protocol error unsupported_feature. The + advertisement implies support only for target color volumes fully + contained within the primary color volume. + + If a compositor additionally supports target color volume exceeding the + primary color volume, it must advertise + wp_color_manager_v1.feature.extended_target_volume. If a client uses + target color volume exceeding the primary color volume and the + compositor does not support it, the result is implementation defined. + Compositors are recommended to detect this case and fail the image + description gracefully, but it may as well result in color artifacts. + </description> + + <arg name="min_lum" type="uint" summary="min L (cd/m²) * 10000"/> + <arg name="max_lum" type="uint" summary="max L (cd/m²)"/> + </request> + + <request name="set_max_cll"> + <description summary="maximum content light level"> + Sets the maximum content light level (max_cll) as defined by CTA-861-H. + + max_cll is undefined by default. + </description> + + <arg name="max_cll" type="uint" summary="Maximum content light level (cd/m²)"/> + </request> + + <request name="set_max_fall"> + <description summary="maximum frame-average light level"> + Sets the maximum frame-average light level (max_fall) as defined by + CTA-861-H. + + max_fall is undefined by default. + </description> + + <arg name="max_fall" type="uint" summary="Maximum frame-average light level (cd/m²)"/> + </request> + </interface> + + <interface name="wp_image_description_v1" version="1"> + <description summary="Colorimetric image description"> + An image description carries information about the color encoding used on + a surface when attached to a wl_surface via + wp_color_management_surface_v1.set_image_description. A compositor can use + this information to decode pixel values into colorimetrically meaningful + quantities. + + Note, that the wp_image_description_v1 object is not ready to be used + immediately after creation. The object eventually delivers either the + 'ready' or the 'failed' event, specified in all requests creating it. The + object is deemed "ready" after receiving the 'ready' event. + + An object which is not ready is illegal to use, it can only be destroyed. + Any other request in this interface shall result in the 'not_ready' + protocol error. Attempts to use an object which is not ready through other + interfaces shall raise protocol errors defined there. + + Once created and regardless of how it was created, a + wp_image_description_v1 object always refers to one fixed image + description. It cannot change after creation. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the image description"> + Destroy this object. It is safe to destroy an object which is not ready. + + Destroying a wp_image_description_v1 object has no side-effects, not + even if a wp_color_management_surface_v1.set_image_description has not + yet been followed by a wl_surface.commit. + </description> + </request> + + <enum name="error"> + <description summary="protocol errors"/> + + <entry name="not_ready" value="0" + summary="attempted to use an object which is not ready"/> + <entry name="no_information" value="1" + summary="get_information not allowed"/> + </enum> + + <enum name="cause"> + <description summary="generic reason for failure"/> + + <entry name="low_version" value="0" + summary="interface version too low"/> + <entry name="unsupported" value="1" + summary="unsupported image description data"/> + <entry name="operating_system" value="2" + summary="error independent of the client"/> + <entry name="no_output" value="3" + summary="the relevant output no longer exists"/> + </enum> + + <event name="failed"> + <description summary="graceful error on creating the image description"> + If creating a wp_image_description_v1 object fails for a reason that is + not defined as a protocol error, this event is sent. + + The requests that create image description objects define whether and + when this can occur. Only such creation requests can trigger this event. + This event cannot be triggered after the image description was + successfully formed. + + Once this event has been sent, the wp_image_description_v1 object will + never become ready and it can only be destroyed. + </description> + + <arg name="cause" type="uint" enum="cause" + summary="generic reason"/> + <arg name="msg" type="string" + summary="ad hoc human-readable explanation"/> + </event> + + <event name="ready"> + <description summary="indication that the object is ready to be used"> + Once this event has been sent, the wp_image_description_v1 object is + deemed "ready". Ready objects can be used to send requests and can be + used through other interfaces. + + Every ready wp_image_description_v1 protocol object refers to an + underlying image description record in the compositor. Multiple protocol + objects may end up referring to the same record. Clients may identify + these "copies" by comparing their id numbers: if the numbers from two + protocol objects are identical, the protocol objects refer to the same + image description record. Two different image description records + cannot have the same id number simultaneously. The id number does not + change during the lifetime of the image description record. + + The id number is valid only as long as the protocol object is alive. If + all protocol objects referring to the same image description record are + destroyed, the id number may be recycled for a different image + description record. + + Image description id number is not a protocol object id. Zero is + reserved as an invalid id number. It shall not be possible for a client + to refer to an image description by its id number in protocol. The id + numbers might not be portable between Wayland connections. A compositor + shall not send an invalid id number. + + This identity allows clients to de-duplicate image description records + and avoid get_information request if they already have the image + description information. + </description> + + <arg name="identity" type="uint" summary="image description id number"/> + </event> + + <request name="get_information"> + <description summary="get information about the image description"> + Creates a wp_image_description_info_v1 object which delivers the + information that makes up the image description. + + Not all image description protocol objects allow get_information + request. Whether it is allowed or not is defined by the request that + created the object. If get_information is not allowed, the protocol + error no_information is raised. + </description> + + <arg name="information" + type="new_id" interface="wp_image_description_info_v1"/> + </request> + </interface> + + <interface name="wp_image_description_info_v1" version="1"> + <description summary="Colorimetric image description information"> + Sends all matching events describing an image description object exactly + once and finally sends the 'done' event. + + This means + - if the image description is parametric, it must send + - primaries + - named_primaries, if applicable + - at least one of tf_power and tf_named, as applicable + - luminances + - target_primaries + - target_luminance + - if the image description is parametric, it may send, if applicable, + - target_max_cll + - target_max_fall + - if the image description contains an ICC profile, it must send the + icc_file event + + Once a wp_image_description_info_v1 object has delivered a 'done' event it + is automatically destroyed. + + Every wp_image_description_info_v1 created from the same + wp_image_description_v1 shall always return the exact same data. + </description> + + <event name="done" type="destructor"> + <description summary="end of information"> + Signals the end of information events and destroys the object. + </description> + </event> + + <event name="icc_file"> + <description summary="ICC profile matching the image description"> + The icc argument provides a file descriptor to the client which may be + memory-mapped to provide the ICC profile matching the image description. + The fd is read-only, and if mapped then it must be mapped with + MAP_PRIVATE by the client. + + The ICC profile version and other details are determined by the + compositor. There is no provision for a client to ask for a specific + kind of a profile. + </description> + + <arg name="icc" type="fd" summary="ICC profile file descriptor"/> + <arg name="icc_size" type="uint" summary="ICC profile size, in bytes"/> + <!-- Offset always 0, compositor must not expose unnecessary data. --> + </event> + + <event name="primaries"> + <description summary="primaries as chromaticity coordinates"> + Delivers the primary color volume primaries and white point using CIE + 1931 xy chromaticity coordinates. + + Each coordinate value is multiplied by 1 million to get the argument + value to carry precision of 6 decimals. + </description> + + <arg name="r_x" type="int" summary="Red x * 1M"/> + <arg name="r_y" type="int" summary="Red y * 1M"/> + <arg name="g_x" type="int" summary="Green x * 1M"/> + <arg name="g_y" type="int" summary="Green y * 1M"/> + <arg name="b_x" type="int" summary="Blue x * 1M"/> + <arg name="b_y" type="int" summary="Blue y * 1M"/> + <arg name="w_x" type="int" summary="White x * 1M"/> + <arg name="w_y" type="int" summary="White y * 1M"/> + </event> + + <event name="primaries_named"> + <description summary="named primaries"> + Delivers the primary color volume primaries and white point using an + explicitly enumerated named set. + </description> + + <arg name="primaries" type="uint" enum="wp_color_manager_v1.primaries" + summary="named primaries"/> + </event> + + <event name="tf_power"> + <description summary="transfer characteristic as a power curve"> + The color component transfer characteristic of this image description is + a pure power curve. This event provides the exponent of the power + function. This curve represents the conversion from electrical to + optical pixel or color values. + + The curve exponent has been multiplied by 10000 to get the argument eexp + value to carry the precision of 4 decimals. + </description> + + <arg name="eexp" type="uint" summary="the exponent * 10000"/> + </event> + + <event name="tf_named"> + <description summary="named transfer characteristic"> + Delivers the transfer characteristic using an explicitly enumerated + named function. + </description> + + <arg name="tf" type="uint" enum="wp_color_manager_v1.transfer_function" + summary="named transfer function"/> + </event> + + <event name="luminances"> + <description summary="primary color volume luminance range and reference white"> + Delivers the primary color volume luminance range and the reference + white luminance level. These values include the minimum display emission + and ambient flare luminances, assumed to be optically additive and have + the chromaticity of the primary color volume white point. + + The minimum luminance is multiplied by 10000 to get the argument + 'min_lum' value and carries precision of 4 decimals. The maximum + luminance and reference white luminance values are unscaled. + </description> + + <arg name="min_lum" type="uint" + summary="minimum luminance (cd/m²) * 10000"/> + <arg name="max_lum" type="uint" + summary="maximum luminance (cd/m²)"/> + <arg name="reference_lum" type="uint" + summary="reference white luminance (cd/m²)"/> + </event> + + <event name="target_primaries"> + <description summary="target primaries as chromaticity coordinates"> + Provides the color primaries and white point of the target color volume + using CIE 1931 xy chromaticity coordinates. This is compatible with the + SMPTE ST 2086 definition of HDR static metadata for mastering displays. + + While primary color volume is about how color is encoded, the target + color volume is the actually displayable color volume. If target color + volume is equal to the primary color volume, then this event is not + sent. + + Each coordinate value is multiplied by 1 million to get the argument + value to carry precision of 6 decimals. + </description> + + <arg name="r_x" type="int" summary="Red x * 1M"/> + <arg name="r_y" type="int" summary="Red y * 1M"/> + <arg name="g_x" type="int" summary="Green x * 1M"/> + <arg name="g_y" type="int" summary="Green y * 1M"/> + <arg name="b_x" type="int" summary="Blue x * 1M"/> + <arg name="b_y" type="int" summary="Blue y * 1M"/> + <arg name="w_x" type="int" summary="White x * 1M"/> + <arg name="w_y" type="int" summary="White y * 1M"/> + </event> + + <event name="target_luminance"> + <description summary="target luminance range"> + Provides the luminance range that the image description is targeting as + the minimum and maximum absolute luminance L. These values include the + minimum display emission and ambient flare luminances, assumed to be + optically additive and have the chromaticity of the primary color + volume white point. This should be compatible with the SMPTE ST 2086 + definition of HDR static metadata. + + This luminance range is only theoretical and may not correspond to the + luminance of light emitted on an actual display. + + Min L value is multiplied by 10000 to get the argument min_lum value and + carry precision of 4 decimals. Max L value is unscaled for max_lum. + </description> + + <arg name="min_lum" type="uint" summary="min L (cd/m²) * 10000"/> + <arg name="max_lum" type="uint" summary="max L (cd/m²)"/> + </event> + + <event name="target_max_cll"> + <description summary="target maximum content light level"> + Provides the targeted max_cll of the image description. max_cll is + defined by CTA-861-H. + + This luminance is only theoretical and may not correspond to the + luminance of light emitted on an actual display. + </description> + + <arg name="max_cll" type="uint" + summary="Maximum content light-level (cd/m²)"/> + </event> + + <event name="target_max_fall"> + <description summary="target maximum frame-average light level"> + Provides the targeted max_fall of the image description. max_fall is + defined by CTA-861-H. + + This luminance is only theoretical and may not correspond to the + luminance of light emitted on an actual display. + </description> + + <arg name="max_fall" type="uint" + summary="Maximum frame-average light level (cd/m²)"/> + </event> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/linux-dmabuf-v1.xml b/app/src/main/cpp/waylandcomp/protocols/linux-dmabuf-v1.xml new file mode 100644 index 0000000000..733717545a --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/linux-dmabuf-v1.xml @@ -0,0 +1,628 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="linux_dmabuf_v1"> + + <copyright> + Copyright © 2014, 2015 Collabora, Ltd. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="zwp_linux_dmabuf_v1" version="6"> + <description summary="factory for creating dmabuf-based wl_buffers"> + This interface offers ways to create generic dmabuf-based wl_buffers. + + For more information about dmabuf, see: + https://www.kernel.org/doc/html/next/userspace-api/dma-buf-alloc-exchange.html + + Clients can use the get_surface_feedback request to get dmabuf feedback + for a particular surface. If the client wants to retrieve feedback not + tied to a surface, they can use the get_default_feedback request. + + The following are required from clients: + + - Clients must ensure that either all data in the dma-buf is + coherent for all subsequent read access or that coherency is + correctly handled by the underlying kernel-side dma-buf + implementation. + + - Don't make any more attachments after sending the buffer to the + compositor. Making more attachments later increases the risk of + the compositor not being able to use (re-import) an existing + dmabuf-based wl_buffer. + + The underlying graphics stack must ensure the following: + + - The dmabuf file descriptors relayed to the server will stay valid + for the whole lifetime of the wl_buffer. This means the server may + at any time use those fds to import the dmabuf into any kernel + sub-system that might accept it. + + However, when the underlying graphics stack fails to deliver the + promise, because of e.g. a device hot-unplug which raises internal + errors, after the wl_buffer has been successfully created the + compositor must not raise protocol errors to the client when dmabuf + import later fails. + + To create a wl_buffer from one or more dmabufs, a client creates a + zwp_linux_buffer_params_v1 object with a zwp_linux_dmabuf_v1.create_params + request. All planes required by the intended format are added with + the 'add' request. Finally, a 'create' or 'create_immed' request is + issued, which has the following outcome depending on the import success. + + The 'create' request, + - on success, triggers a 'created' event which provides the final + wl_buffer to the client. + - on failure, triggers a 'failed' event to convey that the server + cannot use the dmabufs received from the client. + + For the 'create_immed' request, + - on success, the server immediately imports the added dmabufs to + create a wl_buffer. No event is sent from the server in this case. + - on failure, the server can choose to either: + - terminate the client by raising a fatal error. + - mark the wl_buffer as failed, and send a 'failed' event to the + client. If the client uses a failed wl_buffer as an argument to any + request, the behaviour is compositor implementation-defined. + + For all DRM formats and unless specified in another protocol extension, + pre-multiplied alpha is used for pixel values. + + Unless specified otherwise in another protocol extension, implicit + synchronization is used. In other words, compositors and clients must + wait and signal fences implicitly passed via the DMA-BUF's reservation + mechanism. + </description> + + <request name="destroy" type="destructor"> + <description summary="unbind the factory"> + Objects created through this interface, especially wl_buffers, will + remain valid. + </description> + </request> + + <request name="create_params"> + <description summary="create a temporary object for buffer parameters"> + This temporary object is used to collect multiple dmabuf handles into + a single batch to create a wl_buffer. It can only be used once and + should be destroyed after a 'created' or 'failed' event has been + received. + </description> + <arg name="params_id" type="new_id" interface="zwp_linux_buffer_params_v1" + summary="id for the newly created zwp_linux_buffer_params_v1"/> + </request> + + <event name="format" deprecated-since="4"> + <description summary="supported buffer format"> + This event advertises one buffer format that the server supports. + All the supported formats are advertised once when the client + binds to this interface. A roundtrip after binding guarantees + that the client has received all supported formats. + + For the definition of the format codes, see the + zwp_linux_buffer_params_v1::create request. + + Starting version 4, the format event is deprecated and must not be + sent by compositors. Instead, use get_default_feedback or + get_surface_feedback. + </description> + <arg name="format" type="uint" summary="DRM_FORMAT code"/> + </event> + + <event name="modifier" since="3" deprecated-since="4"> + <description summary="supported buffer format modifier"> + This event advertises the formats that the server supports, along with + the modifiers supported for each format. All the supported modifiers + for all the supported formats are advertised once when the client + binds to this interface. A roundtrip after binding guarantees that + the client has received all supported format-modifier pairs. + + For legacy support, DRM_FORMAT_MOD_INVALID (that is, modifier_hi == + 0x00ffffff and modifier_lo == 0xffffffff) is allowed in this event. + It indicates that the server can support the format with an implicit + modifier. When a plane has DRM_FORMAT_MOD_INVALID as its modifier, it + is as if no explicit modifier is specified. The effective modifier + will be derived from the dmabuf. + + A compositor that sends valid modifiers and DRM_FORMAT_MOD_INVALID for + a given format supports both explicit modifiers and implicit modifiers. + + For the definition of the format and modifier codes, see the + zwp_linux_buffer_params_v1::create and zwp_linux_buffer_params_v1::add + requests. + + Starting version 4, the modifier event is deprecated and must not be + sent by compositors. Instead, use get_default_feedback or + get_surface_feedback. + </description> + <arg name="format" type="uint" summary="DRM_FORMAT code"/> + <arg name="modifier_hi" type="uint" + summary="high 32 bits of layout modifier"/> + <arg name="modifier_lo" type="uint" + summary="low 32 bits of layout modifier"/> + </event> + + <!-- Version 4 additions --> + + <request name="get_default_feedback" since="4"> + <description summary="get default feedback"> + This request creates a new zwp_linux_dmabuf_feedback_v1 object not bound + to a particular surface. This object will deliver feedback about dmabuf + parameters to use if the client doesn't support per-surface feedback + (see get_surface_feedback). + </description> + <arg name="id" type="new_id" interface="zwp_linux_dmabuf_feedback_v1"/> + </request> + + <request name="get_surface_feedback" since="4"> + <description summary="get feedback for a surface"> + This request creates a new zwp_linux_dmabuf_feedback_v1 object for the + specified wl_surface. This object will deliver feedback about dmabuf + parameters to use for buffers attached to this surface. + + If the surface is destroyed before the zwp_linux_dmabuf_feedback_v1 object, + the feedback object becomes inert. + </description> + <arg name="id" type="new_id" interface="zwp_linux_dmabuf_feedback_v1"/> + <arg name="surface" type="object" interface="wl_surface"/> + </request> + </interface> + + <interface name="zwp_linux_buffer_params_v1" version="6"> + <description summary="parameters for creating a dmabuf-based wl_buffer"> + This temporary object is a collection of dmabufs and other + parameters that together form a single logical buffer. The temporary + object may eventually create one wl_buffer unless cancelled by + destroying it before requesting 'create'. + + Single-planar formats only require one dmabuf, however + multi-planar formats may require more than one dmabuf. For all + formats, an 'add' request must be called once per plane (even if the + underlying dmabuf fd is identical). + + You must use consecutive plane indices ('plane_idx' argument for 'add') + from zero to the number of planes used by the drm_fourcc format code. + All planes required by the format must be given exactly once, but can + be given in any order. Each plane index can only be set once; subsequent + calls with a plane index which has already been set will result in a + plane_set error being generated. + </description> + + <enum name="error"> + <entry name="already_used" value="0" + summary="the zwp_linux_buffer_params_v1 object has already been used to create a wl_buffer"/> + <entry name="plane_idx" value="1" + summary="plane index out of bounds"/> + <entry name="plane_set" value="2" + summary="the plane index was already set"/> + <entry name="incomplete" value="3" + summary="missing or too many planes to create a buffer"/> + <entry name="invalid_format" value="4" + summary="format not supported"/> + <entry name="invalid_dimensions" value="5" + summary="invalid width or height"/> + <entry name="out_of_bounds" value="6" + summary="offset + stride * height goes out of dmabuf bounds"/> + <entry name="invalid_wl_buffer" value="7" + summary="invalid wl_buffer resulted from importing dmabufs via + the create_immed request on given buffer_params"/> + <entry name="invalid_dev_t_size" value="8" + summary="an array with mismatching size for a dev_t was used"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="delete this object, used or not"> + Cleans up the temporary data sent to the server for dmabuf-based + wl_buffer creation. + </description> + </request> + + <request name="add"> + <description summary="add a dmabuf to the temporary set"> + This request adds one dmabuf to the set in this + zwp_linux_buffer_params_v1. + + The 64-bit unsigned value combined from modifier_hi and modifier_lo + is the dmabuf layout modifier. DRM AddFB2 ioctl calls this the + fb modifier, which is defined in drm_mode.h of Linux UAPI. + This is an opaque token. Drivers use this token to express tiling, + compression, etc. driver-specific modifications to the base format + defined by the DRM fourcc code. + + Starting from version 4, the invalid_format protocol error is sent if + the format + modifier pair was not advertised as supported. + + Starting from version 5, the invalid_format protocol error is sent if + all planes don't use the same modifier. + + This request raises the PLANE_IDX error if plane_idx is too large. + The error PLANE_SET is raised if attempting to set a plane that + was already set. + </description> + <arg name="fd" type="fd" summary="dmabuf fd"/> + <arg name="plane_idx" type="uint" summary="plane index"/> + <arg name="offset" type="uint" summary="offset in bytes"/> + <arg name="stride" type="uint" summary="stride in bytes"/> + <arg name="modifier_hi" type="uint" + summary="high 32 bits of layout modifier"/> + <arg name="modifier_lo" type="uint" + summary="low 32 bits of layout modifier"/> + </request> + + <enum name="flags" bitfield="true"> + <entry name="y_invert" value="1" summary="contents are y-inverted"/> + <entry name="interlaced" value="2" summary="content is interlaced"/> + <entry name="bottom_first" value="4" summary="bottom field first"/> + </enum> + + <request name="create"> + <description summary="create a wl_buffer from the given dmabufs"> + This asks for creation of a wl_buffer from the added dmabuf + buffers. The wl_buffer is not created immediately but returned via + the 'created' event if the dmabuf sharing succeeds. The sharing + may fail at runtime for reasons a client cannot predict, in + which case the 'failed' event is triggered. + + The 'format' argument is a DRM_FORMAT code, as defined by the + libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the + authoritative source on how the format codes should work. + + The 'flags' is a bitfield of the flags defined in enum "flags". + 'y_invert' means that the image needs to be y-flipped. + + Flag 'interlaced' means that the frame in the buffer is not + progressive as usual, but interlaced. An interlaced buffer as + supported here must always contain both top and bottom fields. + The top field always begins on the first pixel row. The temporal + ordering between the two fields is top field first, unless + 'bottom_first' is specified. It is undefined whether 'bottom_first' + is ignored if 'interlaced' is not set. + + This protocol does not convey any information about field rate, + duration, or timing, other than the relative ordering between the + two fields in one buffer. A compositor may have to estimate the + intended field rate from the incoming buffer rate. It is undefined + whether the time of receiving wl_surface.commit with a new buffer + attached, applying the wl_surface state, wl_surface.frame callback + trigger, presentation, or any other point in the compositor cycle + is used to measure the frame or field times. There is no support + for detecting missed or late frames/fields/buffers either, and + there is no support whatsoever for cooperating with interlaced + compositor output. + + The composited image quality resulting from the use of interlaced + buffers is explicitly undefined. A compositor may use elaborate + hardware features or software to deinterlace and create progressive + output frames from a sequence of interlaced input buffers, or it + may produce substandard image quality. However, compositors that + cannot guarantee reasonable image quality in all cases are recommended + to just reject all interlaced buffers. + + Any argument errors, including non-positive width or height, + mismatch between the number of planes and the format, bad + format, bad offset or stride, may be indicated by fatal protocol + errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, + OUT_OF_BOUNDS. + + Dmabuf import errors in the server that are not obvious client + bugs are returned via the 'failed' event as non-fatal. This + allows attempting dmabuf sharing and falling back in the client + if it fails. + + This request can be sent only once in the object's lifetime, after + which the only legal request is destroy. This object should be + destroyed after issuing a 'create' request. Attempting to use this + object after issuing 'create' raises the ALREADY_USED protocol error. + + It is not mandatory to issue 'create'. If a client wants to + cancel the buffer creation, it can just destroy this object. + </description> + <arg name="width" type="int" summary="base plane width in pixels"/> + <arg name="height" type="int" summary="base plane height in pixels"/> + <arg name="format" type="uint" summary="DRM_FORMAT code"/> + <arg name="flags" type="uint" enum="flags" summary="see enum flags"/> + </request> + + <event name="created"> + <description summary="buffer creation succeeded"> + This event indicates that the attempted buffer creation was + successful. It provides the new wl_buffer referencing the dmabuf(s). + + Upon receiving this event, the client should destroy the + zwp_linux_buffer_params_v1 object. + </description> + <arg name="buffer" type="new_id" interface="wl_buffer" + summary="id for the the newly created wl_buffer"/> + </event> + + <event name="failed"> + <description summary="buffer creation failed"> + This event indicates that the attempted buffer creation has + failed. It usually means that one of the dmabuf constraints + has not been fulfilled. + + Upon receiving this event, the client should destroy the + zwp_linux_buffer_params_v1 object. + </description> + </event> + + <request name="create_immed" since="2"> + <description summary="immediately create a wl_buffer from the given + dmabufs"> + This asks for immediate creation of a wl_buffer by importing the + added dmabufs. + + In case of import success, no event is sent from the server, and the + wl_buffer is ready to be used by the client. + + Upon import failure, either of the following may happen, as seen fit + by the implementation: + - the client is terminated with one of the following fatal protocol + errors: + - INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS, OUT_OF_BOUNDS, + in case of argument errors such as mismatch between the number + of planes and the format, bad format, non-positive width or + height, or bad offset or stride. + - INVALID_WL_BUFFER, in case the cause for failure is unknown or + platform specific. + - the server creates an invalid wl_buffer, marks it as failed and + sends a 'failed' event to the client. The result of using this + invalid wl_buffer as an argument in any request by the client is + defined by the compositor implementation. + + This takes the same arguments as a 'create' request, and obeys the + same restrictions. + </description> + <arg name="buffer_id" type="new_id" interface="wl_buffer" + summary="id for the newly created wl_buffer"/> + <arg name="width" type="int" summary="base plane width in pixels"/> + <arg name="height" type="int" summary="base plane height in pixels"/> + <arg name="format" type="uint" summary="DRM_FORMAT code"/> + <arg name="flags" type="uint" enum="flags" summary="see enum flags"/> + </request> + + <request name="set_sampling_device" since="6"> + <description summary="set the target device of the wl_buffer"> + Set the device the compositor should import the dmabufs to for sampling + in the next create or create_immed request. + + To avoid race conditions when the compositor removes a device from the + tranches, it is not a protocol error if the device hasn't been advertised + by the compositor in a tranche with the sampling flag, but the import is + likely to fail in that case. + + If the client doesn't know a suitable target device, it shouldn't set one, + and the compositor should attempt import on all devices it supports. + + If the array is too small to contain a dev_t or larger than required, the + invalid_dev_t_size error will be emitted. + </description> + <arg name="device" type="array" summary="device dev_t value"/> + </request> + </interface> + + <interface name="zwp_linux_dmabuf_feedback_v1" version="6"> + <description summary="dmabuf feedback"> + This object advertises dmabuf parameters feedback. This includes the + preferred devices and the supported formats/modifiers. + + The parameters are sent once when this object is created and whenever they + change. The done event is always sent once after all parameters have been + sent. When a single parameter changes, all parameters are re-sent by the + compositor. + + Compositors can re-send the parameters when the current client buffer + allocations are sub-optimal. Compositors should not re-send the + parameters if re-allocating the buffers would not result in a more optimal + configuration. In particular, compositors should avoid sending the exact + same parameters multiple times in a row. + + The tranche_target_device and tranche_formats events are grouped by + tranches of preference. For each tranche, a tranche_target_device, one + tranche_flags and one or more tranche_formats events are sent, followed + by a tranche_done event finishing the list. The tranches are sent in + descending order of preference. All formats and modifiers in the same + tranche have the same preference. + + To send parameters, the compositor sends one main_device event (unless + the client bound version 6 or above), tranches (each consisting of one + tranche_target_device event, one tranche_flags event, tranche_formats + events and then a tranche_done event), then one done event. + + With version 6 and above, the compositor must always advertise at least + one tranche with the sampling flag set. + + The compositor sends a format_table event at least once for each dmabuf + parameters feedback object, before any tranche events. Unless the format + table contents change later, the compositor is free not to send another + format_table event for the same dmabuf parameters feedback object. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the feedback object"> + Using this request a client can tell the server that it is not going to + use the zwp_linux_dmabuf_feedback_v1 object anymore. + </description> + </request> + + <event name="done"> + <description summary="all feedback has been sent"> + This event is sent after all parameters of a zwp_linux_dmabuf_feedback_v1 + object have been sent. + + This allows changes to the zwp_linux_dmabuf_feedback_v1 parameters to be + seen as atomic, even if they happen via multiple events. + </description> + </event> + + <event name="format_table"> + <description summary="format and modifier table"> + This event provides a file descriptor which can be memory-mapped to + access the format and modifier table. + + The table contains a tightly packed array of consecutive format + + modifier pairs. Each pair is 16 bytes wide. It contains a format as a + 32-bit unsigned integer, followed by 4 bytes of unused padding, and a + modifier as a 64-bit unsigned integer. The native endianness is used. + + The client must map the file descriptor in read-only private mode. + + Compositors are not allowed to mutate the table file contents once this + event has been sent. Instead, compositors must create a new, separate + table file and re-send feedback parameters. Compositors are allowed to + store duplicate format + modifier pairs in the table. + </description> + <arg name="fd" type="fd" summary="table file descriptor"/> + <arg name="size" type="uint" summary="table size, in bytes"/> + </event> + + <event name="main_device" deprecated-since="6"> + <description summary="preferred main device"> + This event advertises the main device that the server prefers to use + when direct scan-out to the target device isn't possible. The + advertised main device may be different for each + zwp_linux_dmabuf_feedback_v1 object, and may change over time. + + There is exactly one main device. The compositor must send at least + one preference tranche with tranche_target_device equal to main_device. + + Clients need to create buffers that the main device can import and + read from, otherwise creating the dmabuf wl_buffer will fail (see the + zwp_linux_buffer_params_v1.create and create_immed requests for details). + The main device will also likely be kept active by the compositor, + so clients can use it instead of waking up another device for power + savings. + + In general the device is a DRM node. The DRM node type (primary vs. + render) is unspecified. Clients must not rely on the compositor sending + a particular node type. Clients cannot check two devices for equality + by comparing the dev_t value. + + If explicit modifiers are not supported and the client performs buffer + allocations on a different device than the main device, then the client + must force the buffer to have a linear layout. + + With version 6 and above, this event is no longer sent. Clients should + use a device with the sampling flag in the tranches instead. + </description> + <arg name="device" type="array" summary="device dev_t value"/> + </event> + + <event name="tranche_done"> + <description summary="a preference tranche has been sent"> + This event splits tranche_target_device and tranche_formats events into + preference tranches. It is sent after a set of tranche_target_device + and tranche_formats events; it represents the end of a tranche. The + next tranche will have a lower preference. + </description> + </event> + + <event name="tranche_target_device"> + <description summary="target device"> + This event advertises the target device that the server prefers to use + for a buffer created given this tranche. The advertised target device + may be different for each preference tranche, and may change over time. + + There is exactly one target device per tranche. + + The target device may be a scan-out device, for example if the + compositor prefers to directly scan-out a buffer created given this + tranche. The target device may be a rendering device, for example if + the compositor prefers to texture from said buffer. + + The client can use this hint to allocate the buffer in a way that makes + it accessible from the target device, ideally directly. The buffer must + still be accessible from a device with the sampling flag, either through + direct import or a potentially more expensive fallback path. If the + buffer can't be directly imported for sampling, then clients must be + prepared for the compositor changing the tranche priority or making + wl_buffer creation fail (see the zwp_linux_buffer_params_v1.create and + create_immed requests for details). + + If the device is a DRM node, the DRM node type (primary vs. render) is + unspecified. Clients must not rely on the compositor sending a + particular node type. Clients cannot check two devices for equality by + comparing the dev_t value. + + This event is tied to a preference tranche, see the tranche_done event. + </description> + <arg name="device" type="array" summary="device dev_t value"/> + </event> + + <event name="tranche_formats"> + <description summary="supported buffer format modifiers"> + This event advertises the format + modifier combinations that the + compositor supports. + + It carries an array of indices, each referring to a format + modifier + pair in the last received format table (see the format_table event). + Each index is a 16-bit unsigned integer in native endianness. + + For legacy support, DRM_FORMAT_MOD_INVALID is an allowed modifier. + It indicates that the server can support the format with an implicit + modifier. When a buffer has DRM_FORMAT_MOD_INVALID as its modifier, it + is as if no explicit modifier is specified. The effective modifier + will be derived from the dmabuf. + + A compositor that sends valid modifiers and DRM_FORMAT_MOD_INVALID for + a given format supports both explicit modifiers and implicit modifiers. + + Compositors must not send duplicate format + modifier pairs within the + same tranche or across two different tranches with the same target + device and flags. + + This event is tied to a preference tranche, see the tranche_done event. + + For the definition of the format and modifier codes, see the + zwp_linux_buffer_params_v1.create request. + </description> + <arg name="indices" type="array" summary="array of 16-bit indexes"/> + </event> + + <enum name="tranche_flags" bitfield="true"> + <entry name="scanout" value="1" since="4"> + <description summary="direct scan-out tranche"> + The scanout flag is a hint that direct scan-out may be attempted by + the compositor on the target device if the client appropriately + allocates a buffer. How to allocate a buffer that can be scanned out + on the target device is implementation-defined. + </description> + </entry> + <entry name="sampling" value="2" since="6"> + <description summary="sampling tranche"> + The sampling flag describes that the compositor is able to efficiently + sample from buffers imported to the target device if the client + appropriately allocates a buffer. How to allocate a buffer that can be + efficiently sampled on the target device is implementation defined. + </description> + </entry> + </enum> + + <event name="tranche_flags"> + <description summary="tranche flags"> + This event sets tranche-specific flags. This event is tied to a + preference tranche, see the tranche_done event. + With version 6 and above, the compositor must set at least one flag + in each tranche. + </description> + <arg name="flags" type="uint" enum="tranche_flags" summary="tranche flags"/> + </event> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/pointer-constraints-unstable-v1.xml b/app/src/main/cpp/waylandcomp/protocols/pointer-constraints-unstable-v1.xml new file mode 100644 index 0000000000..efd64b6603 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/pointer-constraints-unstable-v1.xml @@ -0,0 +1,339 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="pointer_constraints_unstable_v1"> + + <copyright> + Copyright © 2014 Jonas Ådahl + Copyright © 2015 Red Hat Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="protocol for constraining pointer motions"> + This protocol specifies a set of interfaces used for adding constraints to + the motion of a pointer. Possible constraints include confining pointer + motions to a given region, or locking it to its current position. + + In order to constrain the pointer, a client must first bind the global + interface "wp_pointer_constraints" which, if a compositor supports pointer + constraints, is exposed by the registry. Using the bound global object, the + client uses the request that corresponds to the type of constraint it wants + to make. See wp_pointer_constraints for more details. + + Warning! The protocol described in this file is experimental and backward + incompatible changes may be made. Backward compatible changes may be added + together with the corresponding interface version bump. Backward + incompatible changes are done by bumping the version number in the protocol + and interface names and resetting the interface version. Once the protocol + is to be declared stable, the 'z' prefix and the version number in the + protocol and interface names are removed and the interface version number is + reset. + </description> + + <interface name="zwp_pointer_constraints_v1" version="1"> + <description summary="constrain the movement of a pointer"> + The global interface exposing pointer constraining functionality. It + exposes two requests: lock_pointer for locking the pointer to its + position, and confine_pointer for locking the pointer to a region. + + The lock_pointer and confine_pointer requests create the objects + wp_locked_pointer and wp_confined_pointer respectively, and the client can + use these objects to interact with the lock. + + For any surface, only one lock or confinement may be active across all + wl_pointer objects of the same seat. If a lock or confinement is requested + when another lock or confinement is active or requested on the same surface + and with any of the wl_pointer objects of the same seat, an + 'already_constrained' error will be raised. + </description> + + <enum name="error"> + <description summary="wp_pointer_constraints error values"> + These errors can be emitted in response to wp_pointer_constraints + requests. + </description> + <entry name="already_constrained" value="1" + summary="pointer constraint already requested on that surface"/> + </enum> + + <enum name="lifetime"> + <description summary="constraint lifetime"> + These values represent different lifetime semantics. They are passed + as arguments to the factory requests to specify how the constraint + lifetimes should be managed. + </description> + <entry name="oneshot" value="1"> + <description summary="the pointer constraint is defunct once deactivated"> + A oneshot pointer constraint will never reactivate once it has been + deactivated. See the corresponding deactivation event + (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for + details. + </description> + </entry> + <entry name="persistent" value="2"> + <description summary="the pointer constraint may reactivate"> + A persistent pointer constraint may again reactivate once it has + been deactivated. See the corresponding deactivation event + (wp_locked_pointer.unlocked and wp_confined_pointer.unconfined) for + details. + </description> + </entry> + </enum> + + <request name="destroy" type="destructor"> + <description summary="destroy the pointer constraints manager object"> + Used by the client to notify the server that it will no longer use this + pointer constraints object. + </description> + </request> + + <request name="lock_pointer"> + <description summary="lock pointer to a position"> + The lock_pointer request lets the client request to disable movements of + the virtual pointer (i.e. the cursor), effectively locking the pointer + to a position. This request may not take effect immediately; in the + future, when the compositor deems implementation-specific constraints + are satisfied, the pointer lock will be activated and the compositor + sends a locked event. + + The protocol provides no guarantee that the constraints are ever + satisfied, and does not require the compositor to send an error if the + constraints cannot ever be satisfied. It is thus possible to request a + lock that will never activate. + + There may not be another pointer constraint of any kind requested or + active on the surface for any of the wl_pointer objects of the seat of + the passed pointer when requesting a lock. If there is, an error will be + raised. See general pointer lock documentation for more details. + + The intersection of the region passed with this request and the input + region of the surface is used to determine where the pointer must be + in order for the lock to activate. It is up to the compositor whether to + warp the pointer or require some kind of user interaction for the lock + to activate. If the region is null the surface input region is used. + + A surface may receive pointer focus without the lock being activated. + + The request creates a new object wp_locked_pointer which is used to + interact with the lock as well as receive updates about its state. See + the the description of wp_locked_pointer for further information. + + Note that while a pointer is locked, the wl_pointer objects of the + corresponding seat will not emit any wl_pointer.motion events, but + relative motion events will still be emitted via wp_relative_pointer + objects of the same seat. wl_pointer.axis and wl_pointer.button events + are unaffected. + </description> + <arg name="id" type="new_id" interface="zwp_locked_pointer_v1"/> + <arg name="surface" type="object" interface="wl_surface" + summary="surface to lock pointer to"/> + <arg name="pointer" type="object" interface="wl_pointer" + summary="the pointer that should be locked"/> + <arg name="region" type="object" interface="wl_region" allow-null="true" + summary="region of surface"/> + <arg name="lifetime" type="uint" enum="lifetime" summary="lock lifetime"/> + </request> + + <request name="confine_pointer"> + <description summary="confine pointer to a region"> + The confine_pointer request lets the client request to confine the + pointer cursor to a given region. This request may not take effect + immediately; in the future, when the compositor deems implementation- + specific constraints are satisfied, the pointer confinement will be + activated and the compositor sends a confined event. + + The intersection of the region passed with this request and the input + region of the surface is used to determine where the pointer must be + in order for the confinement to activate. It is up to the compositor + whether to warp the pointer or require some kind of user interaction for + the confinement to activate. If the region is null the surface input + region is used. + + The request will create a new object wp_confined_pointer which is used + to interact with the confinement as well as receive updates about its + state. See the the description of wp_confined_pointer for further + information. + </description> + <arg name="id" type="new_id" interface="zwp_confined_pointer_v1"/> + <arg name="surface" type="object" interface="wl_surface" + summary="surface to lock pointer to"/> + <arg name="pointer" type="object" interface="wl_pointer" + summary="the pointer that should be confined"/> + <arg name="region" type="object" interface="wl_region" allow-null="true" + summary="region of surface"/> + <arg name="lifetime" type="uint" enum="lifetime" summary="confinement lifetime"/> + </request> + </interface> + + <interface name="zwp_locked_pointer_v1" version="1"> + <description summary="receive relative pointer motion events"> + The wp_locked_pointer interface represents a locked pointer state. + + While the lock of this object is active, the wl_pointer objects of the + associated seat will not emit any wl_pointer.motion events. + + This object will send the event 'locked' when the lock is activated. + Whenever the lock is activated, it is guaranteed that the locked surface + will already have received pointer focus and that the pointer will be + within the region passed to the request creating this object. + + To unlock the pointer, send the destroy request. This will also destroy + the wp_locked_pointer object. + + If the compositor decides to unlock the pointer the unlocked event is + sent. See wp_locked_pointer.unlock for details. + + When unlocking, the compositor may warp the cursor position to the set + cursor position hint. If it does, it will not result in any relative + motion events emitted via wp_relative_pointer. + + If the surface the lock was requested on is destroyed and the lock is not + yet activated, the wp_locked_pointer object is now defunct and must be + destroyed. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the locked pointer object"> + Destroy the locked pointer object. If applicable, the compositor will + unlock the pointer. + </description> + </request> + + <request name="set_cursor_position_hint"> + <description summary="set the pointer cursor position hint"> + Set the cursor position hint relative to the top left corner of the + surface. + + If the client is drawing its own cursor, it should update the position + hint to the position of its own cursor. A compositor may use this + information to warp the pointer upon unlock in order to avoid pointer + jumps. + + The cursor position hint is double buffered. The new hint will only take + effect when the associated surface gets it pending state applied. See + wl_surface.commit for details. + </description> + <arg name="surface_x" type="fixed" + summary="surface-local x coordinate"/> + <arg name="surface_y" type="fixed" + summary="surface-local y coordinate"/> + </request> + + <request name="set_region"> + <description summary="set a new lock region"> + Set a new region used to lock the pointer. + + The new lock region is double-buffered. The new lock region will + only take effect when the associated surface gets its pending state + applied. See wl_surface.commit for details. + + For details about the lock region, see wp_locked_pointer. + </description> + <arg name="region" type="object" interface="wl_region" allow-null="true" + summary="region of surface"/> + </request> + + <event name="locked"> + <description summary="lock activation event"> + Notification that the pointer lock of the seat's pointer is activated. + </description> + </event> + + <event name="unlocked"> + <description summary="lock deactivation event"> + Notification that the pointer lock of the seat's pointer is no longer + active. If this is a oneshot pointer lock (see + wp_pointer_constraints.lifetime) this object is now defunct and should + be destroyed. If this is a persistent pointer lock (see + wp_pointer_constraints.lifetime) this pointer lock may again + reactivate in the future. + </description> + </event> + </interface> + + <interface name="zwp_confined_pointer_v1" version="1"> + <description summary="confined pointer object"> + The wp_confined_pointer interface represents a confined pointer state. + + This object will send the event 'confined' when the confinement is + activated. Whenever the confinement is activated, it is guaranteed that + the surface the pointer is confined to will already have received pointer + focus and that the pointer will be within the region passed to the request + creating this object. It is up to the compositor to decide whether this + requires some user interaction and if the pointer will warp to within the + passed region if outside. + + To unconfine the pointer, send the destroy request. This will also destroy + the wp_confined_pointer object. + + If the compositor decides to unconfine the pointer the unconfined event is + sent. The wp_confined_pointer object is at this point defunct and should + be destroyed. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the confined pointer object"> + Destroy the confined pointer object. If applicable, the compositor will + unconfine the pointer. + </description> + </request> + + <request name="set_region"> + <description summary="set a new confine region"> + Set a new region used to confine the pointer. + + The new confine region is double-buffered. The new confine region will + only take effect when the associated surface gets its pending state + applied. See wl_surface.commit for details. + + If the confinement is active when the new confinement region is applied + and the pointer ends up outside of newly applied region, the pointer may + warped to a position within the new confinement region. If warped, a + wl_pointer.motion event will be emitted, but no + wp_relative_pointer.relative_motion event. + + The compositor may also, instead of using the new region, unconfine the + pointer. + + For details about the confine region, see wp_confined_pointer. + </description> + <arg name="region" type="object" interface="wl_region" allow-null="true" + summary="region of surface"/> + </request> + + <event name="confined"> + <description summary="pointer confined"> + Notification that the pointer confinement of the seat's pointer is + activated. + </description> + </event> + + <event name="unconfined"> + <description summary="pointer unconfined"> + Notification that the pointer confinement of the seat's pointer is no + longer active. If this is a oneshot pointer confinement (see + wp_pointer_constraints.lifetime) this object is now defunct and should + be destroyed. If this is a persistent pointer confinement (see + wp_pointer_constraints.lifetime) this pointer confinement may again + reactivate in the future. + </description> + </event> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/presentation-time.xml b/app/src/main/cpp/waylandcomp/protocols/presentation-time.xml new file mode 100644 index 0000000000..c2431c5003 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/presentation-time.xml @@ -0,0 +1,268 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="presentation_time"> +<!-- wrap:70 --> + + <copyright> + Copyright © 2013-2014 Collabora, Ltd. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="wp_presentation" version="2"> + <description summary="timed presentation related wl_surface requests"> + +<!-- Introduction --> + + The main feature of this interface is accurate presentation + timing feedback to ensure smooth video playback while maintaining + audio/video synchronization. Some features use the concept of a + presentation clock, which is defined in the + presentation.clock_id event. + + A content update for a wl_surface is submitted by a + wl_surface.commit request. Request 'feedback' associates with + the wl_surface.commit and provides feedback on the content + update, particularly the final realized presentation time. + +<!-- Completing presentation --> + + When the final realized presentation time is available, e.g. + after a framebuffer flip completes, the requested + presentation_feedback.presented events are sent. The final + presentation time can differ from the compositor's predicted + display update time and the update's target time, especially + when the compositor misses its target vertical blanking period. + </description> + + <enum name="error"> + <description summary="fatal presentation errors"> + These fatal protocol errors may be emitted in response to + illegal presentation requests. + </description> + <entry name="invalid_timestamp" value="0" + summary="invalid value in tv_nsec"/> + <entry name="invalid_flag" value="1" + summary="invalid flag"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="unbind from the presentation interface"> + Informs the server that the client will no longer be using + this protocol object. Existing objects created by this object + are not affected. + </description> + </request> + + <request name="feedback"> + <description summary="request presentation feedback information"> + Request presentation feedback for the current content submission + on the given surface. This creates a new presentation_feedback + object, which will deliver the feedback information once. If + multiple presentation_feedback objects are created for the same + submission, they will all deliver the same information. + + For details on what information is returned, see the + presentation_feedback interface. + </description> + <arg name="surface" type="object" interface="wl_surface" + summary="target surface"/> + <arg name="callback" type="new_id" interface="wp_presentation_feedback" + summary="new feedback object"/> + </request> + + <event name="clock_id"> + <description summary="clock ID for timestamps"> + This event tells the client in which clock domain the + compositor interprets the timestamps used by the presentation + extension. This clock is called the presentation clock. + + The compositor sends this event when the client binds to the + presentation interface. The presentation clock does not change + during the lifetime of the client connection. + + The clock identifier is platform dependent. On POSIX platforms, the + identifier value is one of the clockid_t values accepted by + clock_gettime(). clock_gettime() is defined by POSIX.1-2001. + + Timestamps in this clock domain are expressed as tv_sec_hi, + tv_sec_lo, tv_nsec triples, each component being an unsigned + 32-bit value. Whole seconds are in tv_sec which is a 64-bit + value combined from tv_sec_hi and tv_sec_lo, and the + additional fractional part in tv_nsec as nanoseconds. Hence, + for valid timestamps tv_nsec must be in [0, 999999999]. + + Note that clock_id applies only to the presentation clock, + and implies nothing about e.g. the timestamps used in the + Wayland core protocol input events. + + Compositors should prefer a clock which does not jump and is + not slewed e.g. by NTP. The absolute value of the clock is + irrelevant. Precision of one millisecond or better is + recommended. Clients must be able to query the current clock + value directly, not by asking the compositor. + </description> + <arg name="clk_id" type="uint" summary="platform clock identifier"/> + </event> + + </interface> + + <interface name="wp_presentation_feedback" version="2"> + <description summary="presentation time feedback event"> + A presentation_feedback object returns an indication that a + wl_surface content update has become visible to the user. + One object corresponds to one content update submission + (wl_surface.commit). There are two possible outcomes: the + content update is presented to the user, and a presentation + timestamp delivered; or, the user did not see the content + update because it was superseded or its surface destroyed, + and the content update is discarded. + + Once a presentation_feedback object has delivered a 'presented' + or 'discarded' event it is automatically destroyed. + </description> + + <event name="sync_output"> + <description summary="presentation synchronized to this output"> + As presentation can be synchronized to only one output at a + time, this event tells which output it was. This event is only + sent prior to the presented event. + + As clients may bind to the same global wl_output multiple + times, this event is sent for each bound instance that matches + the synchronized output. If a client has not bound to the + right wl_output global at all, this event is not sent. + </description> + <arg name="output" type="object" interface="wl_output" + summary="presentation output"/> + </event> + + <enum name="kind" bitfield="true"> + <description summary="bitmask of flags in presented event"> + These flags provide information about how the presentation of + the related content update was done. The intent is to help + clients assess the reliability of the feedback and the visual + quality with respect to possible tearing and timings. + </description> + <entry name="vsync" value="0x1"> + <description summary="presentation was vsync'd"> + The presentation was synchronized to the "vertical retrace" by + the display hardware such that tearing does not happen. + Relying on software scheduling is not acceptable for this + flag. If presentation is done by a copy to the active + frontbuffer, then it must guarantee that tearing cannot + happen. + </description> + </entry> + <entry name="hw_clock" value="0x2"> + <description summary="hardware provided the presentation timestamp"> + The display hardware provided measurements that the hardware + driver converted into a presentation timestamp. Sampling a + clock in software is not acceptable for this flag. + </description> + </entry> + <entry name="hw_completion" value="0x4"> + <description summary="hardware signalled the start of the presentation"> + The display hardware signalled that it started using the new + image content. The opposite of this is e.g. a timer being used + to guess when the display hardware has switched to the new + image content. + </description> + </entry> + <entry name="zero_copy" value="0x8"> + <description summary="presentation was done zero-copy"> + The presentation of this update was done zero-copy. This means + the buffer from the client was given to display hardware as + is, without copying it. Compositing with OpenGL counts as + copying, even if textured directly from the client buffer. + Possible zero-copy cases include direct scanout of a + fullscreen surface and a surface on a hardware overlay. + </description> + </entry> + </enum> + + <event name="presented" type="destructor"> + <description summary="the content update was displayed"> + The associated content update was displayed to the user at the + indicated time (tv_sec_hi/lo, tv_nsec). For the interpretation of + the timestamp, see presentation.clock_id event. + + The timestamp corresponds to the time when the content update + turned into light the first time on the surface's main output. + Compositors may approximate this from the framebuffer flip + completion events from the system, and the latency of the + physical display path if known. + + This event is preceded by all related sync_output events + telling which output's refresh cycle the feedback corresponds + to, i.e. the main output for the surface. Compositors are + recommended to choose the output containing the largest part + of the wl_surface, or keeping the output they previously + chose. Having a stable presentation output association helps + clients predict future output refreshes (vblank). + + The 'refresh' argument gives the compositor's prediction of how + many nanoseconds after tv_sec, tv_nsec the very next output + refresh may occur. This is to further aid clients in + predicting future refreshes, i.e., estimating the timestamps + targeting the next few vblanks. If such prediction cannot + usefully be done, the argument is zero. + + For version 2 and later, if the output does not have a constant + refresh rate, explicit video mode switches excluded, then the + refresh argument must be either an appropriate rate picked by the + compositor (e.g. fastest rate), or 0 if no such rate exists. + For version 1, if the output does not have a constant refresh rate, + the refresh argument must be zero. + + The 64-bit value combined from seq_hi and seq_lo is the value + of the output's vertical retrace counter when the content + update was first scanned out to the display. This value must + be compatible with the definition of MSC in + GLX_OML_sync_control specification. Note, that if the display + path has a non-zero latency, the time instant specified by + this counter may differ from the timestamp's. + + If the output does not have a concept of vertical retrace or a + refresh cycle, or the output device is self-refreshing without + a way to query the refresh count, then the arguments seq_hi + and seq_lo must be zero. + </description> + <arg name="tv_sec_hi" type="uint" + summary="high 32 bits of the seconds part of the presentation timestamp"/> + <arg name="tv_sec_lo" type="uint" + summary="low 32 bits of the seconds part of the presentation timestamp"/> + <arg name="tv_nsec" type="uint" + summary="nanoseconds part of the presentation timestamp"/> + <arg name="refresh" type="uint" summary="nanoseconds till next refresh"/> + <arg name="seq_hi" type="uint" + summary="high 32 bits of refresh counter"/> + <arg name="seq_lo" type="uint" + summary="low 32 bits of refresh counter"/> + <arg name="flags" type="uint" enum="kind" summary="combination of 'kind' values"/> + </event> + + <event name="discarded" type="destructor"> + <description summary="the content update was not displayed"> + The content update was never displayed to the user. + </description> + </event> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/relative-pointer-unstable-v1.xml b/app/src/main/cpp/waylandcomp/protocols/relative-pointer-unstable-v1.xml new file mode 100644 index 0000000000..ca6f81d12a --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/relative-pointer-unstable-v1.xml @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="relative_pointer_unstable_v1"> + + <copyright> + Copyright © 2014 Jonas Ådahl + Copyright © 2015 Red Hat Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="protocol for relative pointer motion events"> + This protocol specifies a set of interfaces used for making clients able to + receive relative pointer events not obstructed by barriers (such as the + monitor edge or other pointer barriers). + + To start receiving relative pointer events, a client must first bind the + global interface "wp_relative_pointer_manager" which, if a compositor + supports relative pointer motion events, is exposed by the registry. After + having created the relative pointer manager proxy object, the client uses + it to create the actual relative pointer object using the + "get_relative_pointer" request given a wl_pointer. The relative pointer + motion events will then, when applicable, be transmitted via the proxy of + the newly created relative pointer object. See the documentation of the + relative pointer interface for more details. + + Warning! The protocol described in this file is experimental and backward + incompatible changes may be made. Backward compatible changes may be added + together with the corresponding interface version bump. Backward + incompatible changes are done by bumping the version number in the protocol + and interface names and resetting the interface version. Once the protocol + is to be declared stable, the 'z' prefix and the version number in the + protocol and interface names are removed and the interface version number is + reset. + </description> + + <interface name="zwp_relative_pointer_manager_v1" version="1"> + <description summary="get relative pointer objects"> + A global interface used for getting the relative pointer object for a + given pointer. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the relative pointer manager object"> + Used by the client to notify the server that it will no longer use this + relative pointer manager object. + </description> + </request> + + <request name="get_relative_pointer"> + <description summary="get a relative pointer object"> + Create a relative pointer interface given a wl_pointer object. See the + wp_relative_pointer interface for more details. + </description> + <arg name="id" type="new_id" interface="zwp_relative_pointer_v1"/> + <arg name="pointer" type="object" interface="wl_pointer"/> + </request> + </interface> + + <interface name="zwp_relative_pointer_v1" version="1"> + <description summary="relative pointer object"> + A wp_relative_pointer object is an extension to the wl_pointer interface + used for emitting relative pointer events. It shares the same focus as + wl_pointer objects of the same seat and will only emit events when it has + focus. + </description> + + <request name="destroy" type="destructor"> + <description summary="release the relative pointer object"/> + </request> + + <event name="relative_motion"> + <description summary="relative pointer motion"> + Relative x/y pointer motion from the pointer of the seat associated with + this object. + + A relative motion is in the same dimension as regular wl_pointer motion + events, except they do not represent an absolute position. For example, + moving a pointer from (x, y) to (x', y') would have the equivalent + relative motion (x' - x, y' - y). If a pointer motion caused the + absolute pointer position to be clipped by for example the edge of the + monitor, the relative motion is unaffected by the clipping and will + represent the unclipped motion. + + This event also contains non-accelerated motion deltas. The + non-accelerated delta is, when applicable, the regular pointer motion + delta as it was before having applied motion acceleration and other + transformations such as normalization. + + Note that the non-accelerated delta does not represent 'raw' events as + they were read from some device. Pointer motion acceleration is device- + and configuration-specific and non-accelerated deltas and accelerated + deltas may have the same value on some devices. + + Relative motions are not coupled to wl_pointer.motion events, and can be + sent in combination with such events, but also independently. There may + also be scenarios where wl_pointer.motion is sent, but there is no + relative motion. The order of an absolute and relative motion event + originating from the same physical motion is not guaranteed. + + If the client needs button events or focus state, it can receive them + from a wl_pointer object of the same seat that the wp_relative_pointer + object is associated with. + </description> + <arg name="utime_hi" type="uint" + summary="high 32 bits of a 64 bit timestamp with microsecond granularity"/> + <arg name="utime_lo" type="uint" + summary="low 32 bits of a 64 bit timestamp with microsecond granularity"/> + <arg name="dx" type="fixed" + summary="the x component of the motion vector"/> + <arg name="dy" type="fixed" + summary="the y component of the motion vector"/> + <arg name="dx_unaccel" type="fixed" + summary="the x component of the unaccelerated motion vector"/> + <arg name="dy_unaccel" type="fixed" + summary="the y component of the unaccelerated motion vector"/> + </event> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/text-input-unstable-v3.xml b/app/src/main/cpp/waylandcomp/protocols/text-input-unstable-v3.xml new file mode 100644 index 0000000000..01c1e21042 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/text-input-unstable-v3.xml @@ -0,0 +1,604 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<protocol name="text_input_unstable_v3"> + <copyright> + Copyright © 2012, 2013 Intel Corporation + Copyright © 2015, 2016 Jan Arne Petersen + Copyright © 2017, 2018 Red Hat, Inc. + Copyright © 2018 Purism SPC + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + </copyright> + + <description summary="Protocol for composing text"> + This protocol allows compositors to act as input methods and to send text + to applications. A text input object is used to manage state of what are + typically text entry fields in the application. + + This document adheres to the RFC 2119 when using words like "must", + "should", "may", etc. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + </description> + + <interface name="zwp_text_input_v3" version="2"> + <description summary="text input"> + The zwp_text_input_v3 interface represents text input and input methods + associated with a seat. It provides enter/leave events to follow the + text input focus for a seat. + + Requests are used to enable/disable the text-input object and set + state information like surrounding and selected text or the content type. + The information about the entered text is sent to the text-input object + via the preedit_string and commit_string events. + + Text is valid UTF-8 encoded, indices and lengths are in bytes. Indices + must not point to middle bytes inside a code point: they must either + point to the first byte of a code point or to the end of the buffer. + Lengths must be measured between two valid indices. + + Focus moving throughout surfaces will result in the emission of + zwp_text_input_v3.enter and zwp_text_input_v3.leave events. The focused + surface must commit zwp_text_input_v3.enable and + zwp_text_input_v3.disable requests as the keyboard focus moves across + editable and non-editable elements of the UI. Those two requests are not + expected to be paired with each other, the compositor must be able to + handle consecutive series of the same request. + + State is sent by the state requests (set_surrounding_text, + set_content_type and set_cursor_rectangle) and a commit request. After an + enter event or disable request all state information is invalidated and + needs to be resent by the client. + </description> + + <request name="destroy" type="destructor"> + <description summary="Destroy the wp_text_input"> + Destroy the wp_text_input object. Also disables all surfaces enabled + through this wp_text_input object. + </description> + </request> + + <request name="enable"> + <description summary="Request text input to be enabled"> + Requests text input on the surface previously obtained from the enter + event. + + This request must be issued every time the focused text input changes + to a new one, including within the current surface. Use + zwp_text_input_v3.disable when there is no longer any input focus on + the current surface. + + Clients must not enable more than one text input on the single seat + and should disable the current text input before enabling the new one. + Requests to enable a text input when another text input is enabled + on the same seat must be ignored by compositor. + + This request resets all state associated with previous enable, disable, + set_surrounding_text, set_text_change_cause, set_content_type, and + set_cursor_rectangle requests, as well as the state associated with + preedit_string, commit_string, and delete_surrounding_text events. + + The set_surrounding_text, set_content_type and set_cursor_rectangle + requests must follow if the text input supports the necessary + functionality. + + State set with this request is double-buffered. It will get applied on + the next zwp_text_input_v3.commit request, and stay valid until the + next committed enable or disable request. + + The changes must be applied by the compositor after issuing a + zwp_text_input_v3.commit request. + </description> + </request> + + <request name="disable"> + <description summary="Disable text input on a surface"> + Explicitly disable text input on the current surface (typically when + there is no focus on any text entry inside the surface). + + State set with this request is double-buffered. It will get applied on + the next zwp_text_input_v3.commit request. + </description> + </request> + + <request name="set_surrounding_text"> + <description summary="sets the surrounding text"> + Sets the surrounding plain text around the input, excluding the preedit + text. + + The client should notify the compositor of any changes in any of the + values carried with this request, including changes caused by handling + incoming text-input events as well as changes caused by other + mechanisms like keyboard typing. + + If the client is unaware of the text around the cursor, it should not + issue this request, to signify lack of support to the compositor. + + Text is UTF-8 encoded, and should include the cursor position, the + complete selection and additional characters before and after them. + There is a maximum length of wayland messages, so text can not be + longer than 4000 bytes. + + Cursor is the byte offset of the cursor within text buffer. + + Anchor is the byte offset of the selection anchor within text buffer. + If there is no selected text, anchor is the same as cursor. + + If any preedit text is present, it is replaced with a cursor for the + purpose of this event. + + Values set with this request are double-buffered. They will get applied + on the next zwp_text_input_v3.commit request, and stay valid until the + next committed enable or disable request. + + The initial state for affected fields is empty, meaning that the text + input does not support sending surrounding text. If the empty values + get applied, subsequent attempts to change them may have no effect. + </description> + <arg name="text" type="string"/> + <arg name="cursor" type="int"/> + <arg name="anchor" type="int"/> + </request> + + <enum name="change_cause"> + <description summary="text change reason"> + Reason for the change of surrounding text or cursor posision. + </description> + <entry name="input_method" value="0" summary="input method caused the change"/> + <entry name="other" value="1" summary="something else than the input method caused the change"/> + </enum> + + <request name="set_text_change_cause"> + <description summary="indicates the cause of surrounding text change"> + Tells the compositor why the text surrounding the cursor changed. + + Whenever the client detects an external change in text, cursor, or + anchor posision, it must issue this request to the compositor. This + request is intended to give the input method a chance to update the + preedit text in an appropriate way, e.g. by removing it when the user + starts typing with a keyboard. + + cause describes the source of the change. + + The value set with this request is double-buffered. It must be applied + and reset to initial at the next zwp_text_input_v3.commit request. + + The initial value of cause is input_method. + </description> + <arg name="cause" type="uint" enum="change_cause"/> + </request> + + <enum name="content_hint" bitfield="true"> + <description summary="content hint"> + Content hint is a bitmask to allow to modify the behavior of the text + input. + </description> + <entry name="none" value="0x0" summary="no special behavior"/> + <entry name="completion" value="0x1" summary="suggest word completions"/> + <entry name="spellcheck" value="0x2" summary="suggest word corrections"/> + <entry name="auto_capitalization" value="0x4" summary="switch to uppercase letters at the start of a sentence"/> + <entry name="lowercase" value="0x8" summary="prefer lowercase letters"/> + <entry name="uppercase" value="0x10" summary="prefer uppercase letters"/> + <entry name="titlecase" value="0x20" summary="prefer casing for titles and headings (can be language dependent)"/> + <entry name="hidden_text" value="0x40" summary="characters should be hidden"/> + <entry name="sensitive_data" value="0x80" summary="typed text should not be stored"/> + <entry name="latin" value="0x100" summary="just Latin characters should be entered"/> + <entry name="multiline" value="0x200" summary="the text input is multiline"/> + <entry + name="on_screen_input_provided" value="0x400" since="2" + summary="an on-screen way to fill in the input is already provided by the client"/> + <entry + name="no_emoji" value="0x800" since="2" + summary="prefer not offering emoji support"/> + <entry + name="preedit_shown" value="0x1000" since="2" + summary="the text input will display preedit text in place"/> + </enum> + + <enum name="content_purpose"> + <description summary="content purpose"> + The content purpose allows to specify the primary purpose of a text + input. + + This allows an input method to show special purpose input panels with + extra characters or to disallow some characters. + </description> + <entry name="normal" value="0" summary="default input, allowing all characters"/> + <entry name="alpha" value="1" summary="allow only alphabetic characters"/> + <entry name="digits" value="2" summary="allow only digits"/> + <entry name="number" value="3" summary="input a number (including decimal separator and sign)"/> + <entry name="phone" value="4" summary="input a phone number"/> + <entry name="url" value="5" summary="input an URL"/> + <entry name="email" value="6" summary="input an email address"/> + <entry name="name" value="7" summary="input a name of a person"/> + <entry name="password" value="8" summary="input a password (combine with sensitive_data hint)"/> + <entry name="pin" value="9" summary="input is a numeric password (combine with sensitive_data hint)"/> + <entry name="date" value="10" summary="input a date"/> + <entry name="time" value="11" summary="input a time"/> + <entry name="datetime" value="12" summary="input a date and time"/> + <entry name="terminal" value="13" summary="input for a terminal"/> + </enum> + + <request name="set_content_type"> + <description summary="set content purpose and hint"> + Sets the content purpose and content hint. While the purpose is the + basic purpose of an input field, the hint flags allow to modify some of + the behavior. + + Values set with this request are double-buffered. They will get applied + on the next zwp_text_input_v3.commit request. + Subsequent attempts to update them may have no effect. The values + remain valid until the next committed enable or disable request. + + The initial value for hint is none, and the initial value for purpose + is normal. + </description> + <arg name="hint" type="uint" enum="content_hint"/> + <arg name="purpose" type="uint" enum="content_purpose"/> + </request> + + <request name="set_cursor_rectangle"> + <description summary="set cursor position"> + Marks an area around the cursor as a x, y, width, height rectangle in + surface local coordinates. + + Allows the compositor to put a window with word suggestions near the + cursor, without obstructing the text being input. + + If the client is unaware of the position of edited text, it should not + issue this request, to signify lack of support to the compositor. + + Values set with this request are double-buffered. They will get applied + on the next zwp_text_input_v3.commit request, and stay valid until the + next committed enable or disable request. + + The initial values describing a cursor rectangle are empty. That means + the text input does not support describing the cursor area. If the + empty values get applied, subsequent attempts to change them may have + no effect. + + As of version 2, the zwp_text_input_v3.commit request does not apply + values sent with this request. Instead, it stores them in a separate + "committed" area. The committed values, if still valid, get applied on + the next wl_surface.commit request on the surface with text-input focus. + Both committed and applied values get invalidated on: + + - the next committed enable or disable request, or + - a change of the focused surface of the text-input (leave or enter events). + + This double stage application allows the compositor to position + the input method popup in the same frame as the contents + of the text on the surface are updated. + </description> + <arg name="x" type="int"/> + <arg name="y" type="int"/> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + </request> + + <request name="commit"> + <description summary="commit state"> + Atomically applies state changes recently sent to the compositor. + + The commit request establishes and updates the state of the client, and + must be issued after any changes to apply them. + + Text input state (enabled status, content purpose, content hint, + surrounding text and change cause, cursor rectangle) is conceptually + double-buffered within the context of a text input, i.e. between a + committed enable request and the following committed enable or disable + request. + + Protocol requests modify the pending state, as opposed to the current + state in use by the input method. A commit request atomically applies + all pending state, replacing the current state. After commit, the new + pending state is as documented for each related request. + + Requests are applied in the order of arrival. + + Neither current nor pending state are modified unless noted otherwise. + + The compositor must count the number of commit requests coming from + each zwp_text_input_v3 object and use the count as the serial in done + events. + </description> + </request> + + <event name="enter"> + <description summary="enter event"> + Notification that this seat's text-input focus is on a certain surface. + + If client has created multiple text input objects, compositor must send + this event to all of them. + + When the seat has the keyboard capability the text-input focus follows + the keyboard focus. This event sets the current surface for the + text-input object. + </description> + <arg name="surface" type="object" interface="wl_surface"/> + </event> + + <event name="leave"> + <description summary="leave event"> + Notification that this seat's text-input focus is no longer on a + certain surface. The client should reset any preedit string previously + set. + + The leave notification clears the current surface. It is sent before + the enter notification for the new focus. After leave event, compositor + must ignore requests from any text input instances until next enter + event. + + When the seat has the keyboard capability the text-input focus follows + the keyboard focus. + </description> + <arg name="surface" type="object" interface="wl_surface"/> + </event> + + <event name="preedit_string"> + <description summary="pre-edit"> + Notify when a new composing text (pre-edit) should be set at the + current cursor position. Any previously set composing text must be + removed. Any previously existing selected text must be removed. + + The argument text contains the pre-edit string buffer. + + The parameters cursor_begin and cursor_end are counted in bytes + relative to the beginning of the submitted text buffer. Cursor should + be hidden when both are equal to -1. + + They could be represented by the client as a line if both values are + the same, or as a text highlight otherwise. + + Values set with this event are double-buffered. They must be applied + and reset to initial on the next zwp_text_input_v3.done event. + + The initial value of text is an empty string, and cursor_begin, + cursor_end and cursor_hidden are all 0. + </description> + <arg name="text" type="string" allow-null="true"/> + <arg name="cursor_begin" type="int"/> + <arg name="cursor_end" type="int"/> + </event> + + <event name="commit_string"> + <description summary="text commit"> + Notify when text should be inserted into the editor widget. The text to + commit could be either just a single character after a key press or the + result of some composing (pre-edit). + + Values set with this event are double-buffered. They must be applied + and reset to initial on the next zwp_text_input_v3.done event. + + The initial value of text is an empty string. + </description> + <arg name="text" type="string" allow-null="true"/> + </event> + + <event name="delete_surrounding_text"> + <description summary="delete surrounding text"> + Notify when the text around the current cursor position should be + deleted. + + Before_length and after_length are the number of bytes before and after + the current cursor index (excluding the selection) to delete. + + If a preedit text is present, in effect before_length is counted from + the beginning of it, and after_length from its end (see done event + sequence). + + Values set with this event are double-buffered. They must be applied + and reset to initial on the next zwp_text_input_v3.done event. + + The initial values of both before_length and after_length are 0. + </description> + <arg name="before_length" type="uint" summary="length of text before current cursor position"/> + <arg name="after_length" type="uint" summary="length of text after current cursor position"/> + </event> + + <event name="done"> + <description summary="apply changes"> + Instruct the application to apply changes to state requested by the + preedit_string, commit_string delete_surrounding_text, and action + events. + + The state relating to these events is double-buffered, and each one + modifies the pending state. This event replaces the current state with + the pending state. + + The application must proceed by evaluating the changes in the following + order: + + 1. Replace existing preedit string with the cursor. + 2. Delete requested surrounding text. + 3. Insert commit string with the cursor at its end. + 4. Calculate surrounding text to send. + 5. Insert new preedit text in cursor position. + 6. Place cursor inside preedit text. + 7. Perform the requested action. + + The serial number reflects the last state of the zwp_text_input_v3 + object known to the compositor. The value of the serial argument must + be equal to the number of commit requests already issued on that object. + + When the client receives a done event with a serial different than the + number of past commit requests, it must proceed with evaluating and + applying the changes as normal, except it should not change the current + state of the zwp_text_input_v3 object. All pending state requests + (set_surrounding_text, set_content_type and set_cursor_rectangle) on + the zwp_text_input_v3 object should be sent and committed after + receiving a zwp_text_input_v3.done event with a matching serial. + </description> + <arg name="serial" type="uint"/> + </event> + + <!-- Version 2 additions --> + <enum name="error" since="2"> + <entry name="invalid_action" value="0" summary="an invalid or duplicate action was specified"/> + </enum> + + <enum name="action" since="2"> + <description summary="action"> + A possible action to perform on a text input. + + The submit action is intended for input entries that expect some sort of + activation after user interaction, e.g. the URL entry in a browser. + </description> + <entry name="none" value="0" summary="no action"/> + <entry name="submit" value="1" summary="the action is submitted"/> + </enum> + + <event name="action" since="2"> + <description summary="action performed"> + An action was performed on this text input. + + Values set with this event are double-buffered. They must be applied + and reset to initial on the next zwp_text_input_v3.done event. + + The initial value of action is none. + </description> + <arg name="action" type="uint" enum="action" summary="action performed"/> + <arg name="serial" type="uint" summary="serial number of the action event"/> + </event> + + <event name="language" since="2"> + <description summary="notify of language selection"> + Notify the application of language used by the input method. + + This event will be sent on creation if known and for all subsequent changes. + + The language should be specified as an IETF BCP 47 tag. + Setting an empty string will reset any known language back to the default unknown state. + </description> + <arg name="language" type="string" summary="new language set by IME"/> + </event> + + <request name="set_available_actions" since="2"> + <description summary="set the available actions"> + Set the actions available for this text input. + + Values set with this request are double-buffered. They will get applied + on the next zwp_text_input_v3.commit request. + + If the available_actions array contains the none action, or contains the + same action multiple times, the compositor must raise the invalid_action + protocol error. + + Initially, no actions are available. + </description> + <arg name="available_actions" type="array" summary="available actions"/> + </request> + + <request name="show_input_panel" since="2"> + <description summary="show input panel"> + Requests an input panel to be shown (e.g. a on-screen keyboard). + + This request only hints the desired interaction pattern from the + client side, and its effect may be ignored by compositors given + other environmental factors. Repeated calls will be ignored. + </description> + </request> + + <request name="hide_input_panel" since="2"> + <description summary="hide input panel"> + Requests an input panel to be hidden. + + This request only hints the desired interaction pattern from the + client side, and its effect may be ignored by compositors given + other environmental factors. Repeated calls will be ignored. + </description> + </request> + + <enum name="preedit_hint"> + <description summary="preedit style hint"> + Style hints for the preedit string. + </description> + <entry name="whole" value="1" summary="simple pre-edit text style, typically underlined"/> + <entry name="selection" value="2" + summary="hint for a selected piece of text, e.g. per-character navigation and composition"/> + <entry name="prediction" value="3" summary="predicted text, not typed by the user"/> + <entry name="prefix" value="4" + summary="prefixed text not being currently edited, e.g. prior to a 'selection' section"/> + <entry name="suffix" value="5" + summary="suffixed text not being currently edited, e.g. after a 'selection' section"/> + <entry name="spelling_error" value="6" summary="spelling error"/> + <entry name="compose_error" value="7" + summary="wrong composition, e.g. user input that can not be transliterated"/> + </enum> + + <event name="preedit_hint" since="2"> + <description summary="pre-edit"> + Notify of contextual hints for the pre-edit string. This + event is always sent together with a zwp_text_input_v3.preedit_string + event. + + The parameters start and end are counted in bytes relative to the + beginning of the text buffer submitted through + zwp_text_input_v3.preedit_string, and represent the substring in the + pre-edit text affected by the hint. + + Multiple events may be submitted if the preedit string has different + sections. The extent of hints may overlap. The parts of the preedit + string that are not covered by any zwp_text_input_v3.preedit_hint event, + the text will be considered unhinted. This is also the case if no + preedit_hint event is sent. + + Clients should provide recognizable visuals to these hints. if they are + unable to comply with this requisition, it may be preferable for them + keep the preedit_shown content hint disabled. + + Values set with this event are double-buffered. They must be applied + and reset on the next zwp_text_input_v3.done event. + </description> + <arg name="start" type="uint" summary="starting point of the affected substring"/> + <arg name="end" type="uint" summary="end point of the affected substring"/> + <arg name="hint" type="uint" enum="preedit_hint" summary="hint to apply"/> + </event> + </interface> + + <interface name="zwp_text_input_manager_v3" version="2"> + <description summary="text input manager"> + A factory for text-input objects. This object is a global singleton. + </description> + + <request name="destroy" type="destructor"> + <description summary="Destroy the wp_text_input_manager"> + Destroy the wp_text_input_manager object. + </description> + </request> + + <request name="get_text_input"> + <description summary="create a new text input object"> + Creates a new text-input object for a given seat. + </description> + <arg name="id" type="new_id" interface="zwp_text_input_v3"/> + <arg name="seat" type="object" interface="wl_seat"/> + </request> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/viewporter.xml b/app/src/main/cpp/waylandcomp/protocols/viewporter.xml new file mode 100644 index 0000000000..d1048d1f33 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/viewporter.xml @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="viewporter"> + + <copyright> + Copyright © 2013-2016 Collabora, Ltd. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="wp_viewporter" version="1"> + <description summary="surface cropping and scaling"> + The global interface exposing surface cropping and scaling + capabilities is used to instantiate an interface extension for a + wl_surface object. This extended interface will then allow + cropping and scaling the surface contents, effectively + disconnecting the direct relationship between the buffer and the + surface size. + </description> + + <request name="destroy" type="destructor"> + <description summary="unbind from the cropping and scaling interface"> + Informs the server that the client will not be using this + protocol object anymore. This does not affect any other objects, + wp_viewport objects included. + </description> + </request> + + <enum name="error"> + <entry name="viewport_exists" value="0" + summary="the surface already has a viewport object associated"/> + </enum> + + <request name="get_viewport"> + <description summary="extend surface interface for crop and scale"> + Instantiate an interface extension for the given wl_surface to + crop and scale its content. If the given wl_surface already has + a wp_viewport object associated, the viewport_exists + protocol error is raised. + </description> + <arg name="id" type="new_id" interface="wp_viewport" + summary="the new viewport interface id"/> + <arg name="surface" type="object" interface="wl_surface" + summary="the surface"/> + </request> + </interface> + + <interface name="wp_viewport" version="1"> + <description summary="crop and scale interface to a wl_surface"> + An additional interface to a wl_surface object, which allows the + client to specify the cropping and scaling of the surface + contents. + + This interface works with two concepts: the source rectangle (src_x, + src_y, src_width, src_height), and the destination size (dst_width, + dst_height). The contents of the source rectangle are scaled to the + destination size, and content outside the source rectangle is ignored. + This state is double-buffered, and is applied on the next + wl_surface.commit. + + The two parts of crop and scale state are independent: the source + rectangle, and the destination size. Initially both are unset, that + is, no scaling is applied. The whole of the current wl_buffer is + used as the source, and the surface size is as defined in + wl_surface.attach. + + If the destination size is set, it causes the surface size to become + dst_width, dst_height. The source (rectangle) is scaled to exactly + this size. This overrides whatever the attached wl_buffer size is, + unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface + has no content and therefore no size. Otherwise, the size is always + at least 1x1 in surface local coordinates. + + If the source rectangle is set, it defines what area of the wl_buffer is + taken as the source. If the source rectangle is set and the destination + size is not set, then src_width and src_height must be integers, and the + surface size becomes the source rectangle size. This results in cropping + without scaling. If src_width or src_height are not integers and + destination size is not set, the bad_size protocol error is raised when + the surface state is applied. + + The coordinate transformations from buffer pixel coordinates up to + the surface-local coordinates happen in the following order: + 1. buffer_transform (wl_surface.set_buffer_transform) + 2. buffer_scale (wl_surface.set_buffer_scale) + 3. crop and scale (wp_viewport.set*) + This means, that the source rectangle coordinates of crop and scale + are given in the coordinates after the buffer transform and scale, + i.e. in the coordinates that would be the surface-local coordinates + if the crop and scale was not applied. + + If src_x or src_y are negative, the bad_value protocol error is raised. + Otherwise, if the source rectangle is partially or completely outside of + the non-NULL wl_buffer, then the out_of_buffer protocol error is raised + when the surface state is applied. A NULL wl_buffer does not raise the + out_of_buffer error. + + If the wl_surface associated with the wp_viewport is destroyed, + all wp_viewport requests except 'destroy' raise the protocol error + no_surface. + + If the wp_viewport object is destroyed, the crop and scale + state is removed from the wl_surface. The change will be applied + on the next wl_surface.commit. + </description> + + <request name="destroy" type="destructor"> + <description summary="remove scaling and cropping from the surface"> + The associated wl_surface's crop and scale state is removed. + The change is applied on the next wl_surface.commit. + </description> + </request> + + <enum name="error"> + <entry name="bad_value" value="0" + summary="negative or zero values in width or height"/> + <entry name="bad_size" value="1" + summary="destination size is not integer"/> + <entry name="out_of_buffer" value="2" + summary="source rectangle extends outside of the content area"/> + <entry name="no_surface" value="3" + summary="the wl_surface was destroyed"/> + </enum> + + <request name="set_source"> + <description summary="set the source rectangle for cropping"> + Set the source rectangle of the associated wl_surface. See + wp_viewport for the description, and relation to the wl_buffer + size. + + If all of x, y, width and height are -1.0, the source rectangle is + unset instead. Any other set of values where width or height are zero + or negative, or x or y are negative, raise the bad_value protocol + error. + + The crop and scale state is double-buffered state, and will be + applied on the next wl_surface.commit. + </description> + <arg name="x" type="fixed" summary="source rectangle x"/> + <arg name="y" type="fixed" summary="source rectangle y"/> + <arg name="width" type="fixed" summary="source rectangle width"/> + <arg name="height" type="fixed" summary="source rectangle height"/> + </request> + + <request name="set_destination"> + <description summary="set the surface size for scaling"> + Set the destination size of the associated wl_surface. See + wp_viewport for the description, and relation to the wl_buffer + size. + + If width is -1 and height is -1, the destination size is unset + instead. Any other pair of values for width and height that + contains zero or negative values raises the bad_value protocol + error. + + The crop and scale state is double-buffered state, and will be + applied on the next wl_surface.commit. + </description> + <arg name="width" type="int" summary="surface width"/> + <arg name="height" type="int" summary="surface height"/> + </request> + </interface> + +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/wlr-data-control-unstable-v1.xml b/app/src/main/cpp/waylandcomp/protocols/wlr-data-control-unstable-v1.xml new file mode 100644 index 0000000000..567a09e529 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/wlr-data-control-unstable-v1.xml @@ -0,0 +1,281 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="wlr_data_control_unstable_v1"> + <copyright> + Copyright © 2018 Simon Ser + Copyright © 2019 Ivan Molodetskikh + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + </copyright> + + <description summary="control data devices"> + This protocol allows a privileged client to control data devices. In + particular, the client will be able to manage the current selection and take + the role of a clipboard manager. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + + Note! This protocol is deprecated and not intended for production use. + For clipboard management, use the ext-data-control-v1 protocol. + </description> + + <interface name="zwlr_data_control_manager_v1" version="2"> + <description summary="manager to control data devices"> + This interface is a manager that allows creating per-seat data device + controls. + </description> + + <request name="create_data_source"> + <description summary="create a new data source"> + Create a new data source. + </description> + <arg name="id" type="new_id" interface="zwlr_data_control_source_v1" + summary="data source to create"/> + </request> + + <request name="get_data_device"> + <description summary="get a data device for a seat"> + Create a data device that can be used to manage a seat's selection. + </description> + <arg name="id" type="new_id" interface="zwlr_data_control_device_v1"/> + <arg name="seat" type="object" interface="wl_seat"/> + </request> + + <request name="destroy" type="destructor"> + <description summary="destroy the manager"> + All objects created by the manager will still remain valid, until their + appropriate destroy request has been called. + </description> + </request> + </interface> + + <interface name="zwlr_data_control_device_v1" version="2"> + <description summary="manage a data device for a seat"> + This interface allows a client to manage a seat's selection. + + When the seat is destroyed, this object becomes inert. + </description> + + <request name="set_selection"> + <description summary="copy data to the selection"> + This request asks the compositor to set the selection to the data from + the source on behalf of the client. + + The given source may not be used in any further set_selection or + set_primary_selection requests. Attempting to use a previously used + source is a protocol error. + + To unset the selection, set the source to NULL. + </description> + <arg name="source" type="object" interface="zwlr_data_control_source_v1" + allow-null="true"/> + </request> + + <request name="destroy" type="destructor"> + <description summary="destroy this data device"> + Destroys the data device object. + </description> + </request> + + <event name="data_offer"> + <description summary="introduce a new wlr_data_control_offer"> + The data_offer event introduces a new wlr_data_control_offer object, + which will subsequently be used in either the + wlr_data_control_device.selection event (for the regular clipboard + selections) or the wlr_data_control_device.primary_selection event (for + the primary clipboard selections). Immediately following the + wlr_data_control_device.data_offer event, the new data_offer object + will send out wlr_data_control_offer.offer events to describe the MIME + types it offers. + </description> + <arg name="id" type="new_id" interface="zwlr_data_control_offer_v1"/> + </event> + + <event name="selection"> + <description summary="advertise new selection"> + The selection event is sent out to notify the client of a new + wlr_data_control_offer for the selection for this device. The + wlr_data_control_device.data_offer and the wlr_data_control_offer.offer + events are sent out immediately before this event to introduce the data + offer object. The selection event is sent to a client when a new + selection is set. The wlr_data_control_offer is valid until a new + wlr_data_control_offer or NULL is received. The client must destroy the + previous selection wlr_data_control_offer, if any, upon receiving this + event. + + The first selection event is sent upon binding the + wlr_data_control_device object. + </description> + <arg name="id" type="object" interface="zwlr_data_control_offer_v1" + allow-null="true"/> + </event> + + <event name="finished"> + <description summary="this data control is no longer valid"> + This data control object is no longer valid and should be destroyed by + the client. + </description> + </event> + + <!-- Version 2 additions --> + + <event name="primary_selection" since="2"> + <description summary="advertise new primary selection"> + The primary_selection event is sent out to notify the client of a new + wlr_data_control_offer for the primary selection for this device. The + wlr_data_control_device.data_offer and the wlr_data_control_offer.offer + events are sent out immediately before this event to introduce the data + offer object. The primary_selection event is sent to a client when a + new primary selection is set. The wlr_data_control_offer is valid until + a new wlr_data_control_offer or NULL is received. The client must + destroy the previous primary selection wlr_data_control_offer, if any, + upon receiving this event. + + If the compositor supports primary selection, the first + primary_selection event is sent upon binding the + wlr_data_control_device object. + </description> + <arg name="id" type="object" interface="zwlr_data_control_offer_v1" + allow-null="true"/> + </event> + + <request name="set_primary_selection" since="2"> + <description summary="copy data to the primary selection"> + This request asks the compositor to set the primary selection to the + data from the source on behalf of the client. + + The given source may not be used in any further set_selection or + set_primary_selection requests. Attempting to use a previously used + source is a protocol error. + + To unset the primary selection, set the source to NULL. + + The compositor will ignore this request if it does not support primary + selection. + </description> + <arg name="source" type="object" interface="zwlr_data_control_source_v1" + allow-null="true"/> + </request> + + <enum name="error" since="2"> + <entry name="used_source" value="1" + summary="source given to set_selection or set_primary_selection was already used before"/> + </enum> + </interface> + + <interface name="zwlr_data_control_source_v1" version="1"> + <description summary="offer to transfer data"> + The wlr_data_control_source object is the source side of a + wlr_data_control_offer. It is created by the source client in a data + transfer and provides a way to describe the offered data and a way to + respond to requests to transfer the data. + </description> + + <enum name="error"> + <entry name="invalid_offer" value="1" + summary="offer sent after wlr_data_control_device.set_selection"/> + </enum> + + <request name="offer"> + <description summary="add an offered MIME type"> + This request adds a MIME type to the set of MIME types advertised to + targets. Can be called several times to offer multiple types. + + Calling this after wlr_data_control_device.set_selection is a protocol + error. + </description> + <arg name="mime_type" type="string" + summary="MIME type offered by the data source"/> + </request> + + <request name="destroy" type="destructor"> + <description summary="destroy this source"> + Destroys the data source object. + </description> + </request> + + <event name="send"> + <description summary="send the data"> + Request for data from the client. Send the data as the specified MIME + type over the passed file descriptor, then close it. + </description> + <arg name="mime_type" type="string" summary="MIME type for the data"/> + <arg name="fd" type="fd" summary="file descriptor for the data"/> + </event> + + <event name="cancelled"> + <description summary="selection was cancelled"> + This data source is no longer valid. The data source has been replaced + by another data source. + + The client should clean up and destroy this data source. + </description> + </event> + </interface> + + <interface name="zwlr_data_control_offer_v1" version="1"> + <description summary="offer to transfer data"> + A wlr_data_control_offer represents a piece of data offered for transfer + by another client (the source client). The offer describes the different + MIME types that the data can be converted to and provides the mechanism + for transferring the data directly from the source client. + </description> + + <request name="receive"> + <description summary="request that the data is transferred"> + To transfer the offered data, the client issues this request and + indicates the MIME type it wants to receive. The transfer happens + through the passed file descriptor (typically created with the pipe + system call). The source client writes the data in the MIME type + representation requested and then closes the file descriptor. + + The receiving client reads from the read end of the pipe until EOF and + then closes its end, at which point the transfer is complete. + + This request may happen multiple times for different MIME types. + </description> + <arg name="mime_type" type="string" + summary="MIME type desired by receiver"/> + <arg name="fd" type="fd" summary="file descriptor for data transfer"/> + </request> + + <request name="destroy" type="destructor"> + <description summary="destroy this offer"> + Destroys the data offer object. + </description> + </request> + + <event name="offer"> + <description summary="advertise offered MIME type"> + Sent immediately after creating the wlr_data_control_offer object. + One event per offered MIME type. + </description> + <arg name="mime_type" type="string" summary="offered MIME type"/> + </event> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/xdg-shell.xml b/app/src/main/cpp/waylandcomp/protocols/xdg-shell.xml new file mode 100644 index 0000000000..1df7001460 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/xdg-shell.xml @@ -0,0 +1,1351 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="xdg_shell"> + + <copyright> + Copyright © 2008-2013 Kristian Høgsberg + Copyright © 2013 Rafael Antognolli + Copyright © 2013 Jasper St. Pierre + Copyright © 2010-2013 Intel Corporation + Copyright © 2015-2017 Samsung Electronics Co., Ltd + Copyright © 2015-2017 Red Hat Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="xdg_wm_base" version="5"> + <description summary="create desktop-style surfaces"> + The xdg_wm_base interface is exposed as a global object enabling clients + to turn their wl_surfaces into windows in a desktop environment. It + defines the basic functionality needed for clients and the compositor to + create windows that can be dragged, resized, maximized, etc, as well as + creating transient windows such as popup menus. + </description> + + <enum name="error"> + <entry name="role" value="0" summary="given wl_surface has another role"/> + <entry name="defunct_surfaces" value="1" + summary="xdg_wm_base was destroyed before children"/> + <entry name="not_the_topmost_popup" value="2" + summary="the client tried to map or destroy a non-topmost popup"/> + <entry name="invalid_popup_parent" value="3" + summary="the client specified an invalid popup parent surface"/> + <entry name="invalid_surface_state" value="4" + summary="the client provided an invalid surface state"/> + <entry name="invalid_positioner" value="5" + summary="the client provided an invalid positioner"/> + <entry name="unresponsive" value="6" + summary="the client didn’t respond to a ping event in time"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="destroy xdg_wm_base"> + Destroy this xdg_wm_base object. + + Destroying a bound xdg_wm_base object while there are surfaces + still alive created by this xdg_wm_base object instance is illegal + and will result in a defunct_surfaces error. + </description> + </request> + + <request name="create_positioner"> + <description summary="create a positioner object"> + Create a positioner object. A positioner object is used to position + surfaces relative to some parent surface. See the interface description + and xdg_surface.get_popup for details. + </description> + <arg name="id" type="new_id" interface="xdg_positioner"/> + </request> + + <request name="get_xdg_surface"> + <description summary="create a shell surface from a surface"> + This creates an xdg_surface for the given surface. While xdg_surface + itself is not a role, the corresponding surface may only be assigned + a role extending xdg_surface, such as xdg_toplevel or xdg_popup. It is + illegal to create an xdg_surface for a wl_surface which already has an + assigned role and this will result in a role error. + + This creates an xdg_surface for the given surface. An xdg_surface is + used as basis to define a role to a given surface, such as xdg_toplevel + or xdg_popup. It also manages functionality shared between xdg_surface + based surface roles. + + See the documentation of xdg_surface for more details about what an + xdg_surface is and how it is used. + </description> + <arg name="id" type="new_id" interface="xdg_surface"/> + <arg name="surface" type="object" interface="wl_surface"/> + </request> + + <request name="pong"> + <description summary="respond to a ping event"> + A client must respond to a ping event with a pong request or + the client may be deemed unresponsive. See xdg_wm_base.ping + and xdg_wm_base.error.unresponsive. + </description> + <arg name="serial" type="uint" summary="serial of the ping event"/> + </request> + + <event name="ping"> + <description summary="check if the client is alive"> + The ping event asks the client if it's still alive. Pass the + serial specified in the event back to the compositor by sending + a "pong" request back with the specified serial. See xdg_wm_base.pong. + + Compositors can use this to determine if the client is still + alive. It's unspecified what will happen if the client doesn't + respond to the ping request, or in what timeframe. Clients should + try to respond in a reasonable amount of time. The “unresponsive” + error is provided for compositors that wish to disconnect unresponsive + clients. + + A compositor is free to ping in any way it wants, but a client must + always respond to any xdg_wm_base object it created. + </description> + <arg name="serial" type="uint" summary="pass this to the pong request"/> + </event> + </interface> + + <interface name="xdg_positioner" version="5"> + <description summary="child surface positioner"> + The xdg_positioner provides a collection of rules for the placement of a + child surface relative to a parent surface. Rules can be defined to ensure + the child surface remains within the visible area's borders, and to + specify how the child surface changes its position, such as sliding along + an axis, or flipping around a rectangle. These positioner-created rules are + constrained by the requirement that a child surface must intersect with or + be at least partially adjacent to its parent surface. + + See the various requests for details about possible rules. + + At the time of the request, the compositor makes a copy of the rules + specified by the xdg_positioner. Thus, after the request is complete the + xdg_positioner object can be destroyed or reused; further changes to the + object will have no effect on previous usages. + + For an xdg_positioner object to be considered complete, it must have a + non-zero size set by set_size, and a non-zero anchor rectangle set by + set_anchor_rect. Passing an incomplete xdg_positioner object when + positioning a surface raises an invalid_positioner error. + </description> + + <enum name="error"> + <entry name="invalid_input" value="0" summary="invalid input provided"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="destroy the xdg_positioner object"> + Notify the compositor that the xdg_positioner will no longer be used. + </description> + </request> + + <request name="set_size"> + <description summary="set the size of the to-be positioned rectangle"> + Set the size of the surface that is to be positioned with the positioner + object. The size is in surface-local coordinates and corresponds to the + window geometry. See xdg_surface.set_window_geometry. + + If a zero or negative size is set the invalid_input error is raised. + </description> + <arg name="width" type="int" summary="width of positioned rectangle"/> + <arg name="height" type="int" summary="height of positioned rectangle"/> + </request> + + <request name="set_anchor_rect"> + <description summary="set the anchor rectangle within the parent surface"> + Specify the anchor rectangle within the parent surface that the child + surface will be placed relative to. The rectangle is relative to the + window geometry as defined by xdg_surface.set_window_geometry of the + parent surface. + + When the xdg_positioner object is used to position a child surface, the + anchor rectangle may not extend outside the window geometry of the + positioned child's parent surface. + + If a negative size is set the invalid_input error is raised. + </description> + <arg name="x" type="int" summary="x position of anchor rectangle"/> + <arg name="y" type="int" summary="y position of anchor rectangle"/> + <arg name="width" type="int" summary="width of anchor rectangle"/> + <arg name="height" type="int" summary="height of anchor rectangle"/> + </request> + + <enum name="anchor"> + <entry name="none" value="0"/> + <entry name="top" value="1"/> + <entry name="bottom" value="2"/> + <entry name="left" value="3"/> + <entry name="right" value="4"/> + <entry name="top_left" value="5"/> + <entry name="bottom_left" value="6"/> + <entry name="top_right" value="7"/> + <entry name="bottom_right" value="8"/> + </enum> + + <request name="set_anchor"> + <description summary="set anchor rectangle anchor"> + Defines the anchor point for the anchor rectangle. The specified anchor + is used derive an anchor point that the child surface will be + positioned relative to. If a corner anchor is set (e.g. 'top_left' or + 'bottom_right'), the anchor point will be at the specified corner; + otherwise, the derived anchor point will be centered on the specified + edge, or in the center of the anchor rectangle if no edge is specified. + </description> + <arg name="anchor" type="uint" enum="anchor" + summary="anchor"/> + </request> + + <enum name="gravity"> + <entry name="none" value="0"/> + <entry name="top" value="1"/> + <entry name="bottom" value="2"/> + <entry name="left" value="3"/> + <entry name="right" value="4"/> + <entry name="top_left" value="5"/> + <entry name="bottom_left" value="6"/> + <entry name="top_right" value="7"/> + <entry name="bottom_right" value="8"/> + </enum> + + <request name="set_gravity"> + <description summary="set child surface gravity"> + Defines in what direction a surface should be positioned, relative to + the anchor point of the parent surface. If a corner gravity is + specified (e.g. 'bottom_right' or 'top_left'), then the child surface + will be placed towards the specified gravity; otherwise, the child + surface will be centered over the anchor point on any axis that had no + gravity specified. If the gravity is not in the ‘gravity’ enum, an + invalid_input error is raised. + </description> + <arg name="gravity" type="uint" enum="gravity" + summary="gravity direction"/> + </request> + + <enum name="constraint_adjustment" bitfield="true"> + <description summary="constraint adjustments"> + The constraint adjustment value define ways the compositor will adjust + the position of the surface, if the unadjusted position would result + in the surface being partly constrained. + + Whether a surface is considered 'constrained' is left to the compositor + to determine. For example, the surface may be partly outside the + compositor's defined 'work area', thus necessitating the child surface's + position be adjusted until it is entirely inside the work area. + + The adjustments can be combined, according to a defined precedence: 1) + Flip, 2) Slide, 3) Resize. + </description> + <entry name="none" value="0"> + <description summary="don't move the child surface when constrained"> + Don't alter the surface position even if it is constrained on some + axis, for example partially outside the edge of an output. + </description> + </entry> + <entry name="slide_x" value="1"> + <description summary="move along the x axis until unconstrained"> + Slide the surface along the x axis until it is no longer constrained. + + First try to slide towards the direction of the gravity on the x axis + until either the edge in the opposite direction of the gravity is + unconstrained or the edge in the direction of the gravity is + constrained. + + Then try to slide towards the opposite direction of the gravity on the + x axis until either the edge in the direction of the gravity is + unconstrained or the edge in the opposite direction of the gravity is + constrained. + </description> + </entry> + <entry name="slide_y" value="2"> + <description summary="move along the y axis until unconstrained"> + Slide the surface along the y axis until it is no longer constrained. + + First try to slide towards the direction of the gravity on the y axis + until either the edge in the opposite direction of the gravity is + unconstrained or the edge in the direction of the gravity is + constrained. + + Then try to slide towards the opposite direction of the gravity on the + y axis until either the edge in the direction of the gravity is + unconstrained or the edge in the opposite direction of the gravity is + constrained. + </description> + </entry> + <entry name="flip_x" value="4"> + <description summary="invert the anchor and gravity on the x axis"> + Invert the anchor and gravity on the x axis if the surface is + constrained on the x axis. For example, if the left edge of the + surface is constrained, the gravity is 'left' and the anchor is + 'left', change the gravity to 'right' and the anchor to 'right'. + + If the adjusted position also ends up being constrained, the resulting + position of the flip_x adjustment will be the one before the + adjustment. + </description> + </entry> + <entry name="flip_y" value="8"> + <description summary="invert the anchor and gravity on the y axis"> + Invert the anchor and gravity on the y axis if the surface is + constrained on the y axis. For example, if the bottom edge of the + surface is constrained, the gravity is 'bottom' and the anchor is + 'bottom', change the gravity to 'top' and the anchor to 'top'. + + The adjusted position is calculated given the original anchor + rectangle and offset, but with the new flipped anchor and gravity + values. + + If the adjusted position also ends up being constrained, the resulting + position of the flip_y adjustment will be the one before the + adjustment. + </description> + </entry> + <entry name="resize_x" value="16"> + <description summary="horizontally resize the surface"> + Resize the surface horizontally so that it is completely + unconstrained. + </description> + </entry> + <entry name="resize_y" value="32"> + <description summary="vertically resize the surface"> + Resize the surface vertically so that it is completely unconstrained. + </description> + </entry> + </enum> + + <request name="set_constraint_adjustment"> + <description summary="set the adjustment to be done when constrained"> + Specify how the window should be positioned if the originally intended + position caused the surface to be constrained, meaning at least + partially outside positioning boundaries set by the compositor. The + adjustment is set by constructing a bitmask describing the adjustment to + be made when the surface is constrained on that axis. + + If no bit for one axis is set, the compositor will assume that the child + surface should not change its position on that axis when constrained. + + If more than one bit for one axis is set, the order of how adjustments + are applied is specified in the corresponding adjustment descriptions. + + The default adjustment is none. + </description> + <arg name="constraint_adjustment" type="uint" + summary="bit mask of constraint adjustments"/> + </request> + + <request name="set_offset"> + <description summary="set surface position offset"> + Specify the surface position offset relative to the position of the + anchor on the anchor rectangle and the anchor on the surface. For + example if the anchor of the anchor rectangle is at (x, y), the surface + has the gravity bottom|right, and the offset is (ox, oy), the calculated + surface position will be (x + ox, y + oy). The offset position of the + surface is the one used for constraint testing. See + set_constraint_adjustment. + + An example use case is placing a popup menu on top of a user interface + element, while aligning the user interface element of the parent surface + with some user interface element placed somewhere in the popup surface. + </description> + <arg name="x" type="int" summary="surface position x offset"/> + <arg name="y" type="int" summary="surface position y offset"/> + </request> + + <!-- Version 3 additions --> + + <request name="set_reactive" since="3"> + <description summary="continuously reconstrain the surface"> + When set reactive, the surface is reconstrained if the conditions used + for constraining changed, e.g. the parent window moved. + + If the conditions changed and the popup was reconstrained, an + xdg_popup.configure event is sent with updated geometry, followed by an + xdg_surface.configure event. + </description> + </request> + + <request name="set_parent_size" since="3"> + <description summary=""> + Set the parent window geometry the compositor should use when + positioning the popup. The compositor may use this information to + determine the future state the popup should be constrained using. If + this doesn't match the dimension of the parent the popup is eventually + positioned against, the behavior is undefined. + + The arguments are given in the surface-local coordinate space. + </description> + <arg name="parent_width" type="int" + summary="future window geometry width of parent"/> + <arg name="parent_height" type="int" + summary="future window geometry height of parent"/> + </request> + + <request name="set_parent_configure" since="3"> + <description summary="set parent configure this is a response to"> + Set the serial of an xdg_surface.configure event this positioner will be + used in response to. The compositor may use this information together + with set_parent_size to determine what future state the popup should be + constrained using. + </description> + <arg name="serial" type="uint" + summary="serial of parent configure event"/> + </request> + </interface> + + <interface name="xdg_surface" version="5"> + <description summary="desktop user interface surface base interface"> + An interface that may be implemented by a wl_surface, for + implementations that provide a desktop-style user interface. + + It provides a base set of functionality required to construct user + interface elements requiring management by the compositor, such as + toplevel windows, menus, etc. The types of functionality are split into + xdg_surface roles. + + Creating an xdg_surface does not set the role for a wl_surface. In order + to map an xdg_surface, the client must create a role-specific object + using, e.g., get_toplevel, get_popup. The wl_surface for any given + xdg_surface can have at most one role, and may not be assigned any role + not based on xdg_surface. + + A role must be assigned before any other requests are made to the + xdg_surface object. + + The client must call wl_surface.commit on the corresponding wl_surface + for the xdg_surface state to take effect. + + Creating an xdg_surface from a wl_surface which has a buffer attached or + committed is a client error, and any attempts by a client to attach or + manipulate a buffer prior to the first xdg_surface.configure call must + also be treated as errors. + + After creating a role-specific object and setting it up, the client must + perform an initial commit without any buffer attached. The compositor + will reply with an xdg_surface.configure event. The client must + acknowledge it and is then allowed to attach a buffer to map the surface. + + Mapping an xdg_surface-based role surface is defined as making it + possible for the surface to be shown by the compositor. Note that + a mapped surface is not guaranteed to be visible once it is mapped. + + For an xdg_surface to be mapped by the compositor, the following + conditions must be met: + (1) the client has assigned an xdg_surface-based role to the surface + (2) the client has set and committed the xdg_surface state and the + role-dependent state to the surface + (3) the client has committed a buffer to the surface + + A newly-unmapped surface is considered to have met condition (1) out + of the 3 required conditions for mapping a surface if its role surface + has not been destroyed, i.e. the client must perform the initial commit + again before attaching a buffer. + </description> + + <enum name="error"> + <entry name="not_constructed" value="1" + summary="Surface was not fully constructed"/> + <entry name="already_constructed" value="2" + summary="Surface was already constructed"/> + <entry name="unconfigured_buffer" value="3" + summary="Attaching a buffer to an unconfigured surface"/> + <entry name="invalid_serial" value="4" + summary="Invalid serial number when acking a configure event"/> + <entry name="invalid_size" value="5" + summary="Width or height was zero or negative"/> + <entry name="defunct_role_object" value="6" + summary="Surface was destroyed before its role object"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="destroy the xdg_surface"> + Destroy the xdg_surface object. An xdg_surface must only be destroyed + after its role object has been destroyed, otherwise + a defunct_role_object error is raised. + </description> + </request> + + <request name="get_toplevel"> + <description summary="assign the xdg_toplevel surface role"> + This creates an xdg_toplevel object for the given xdg_surface and gives + the associated wl_surface the xdg_toplevel role. + + See the documentation of xdg_toplevel for more details about what an + xdg_toplevel is and how it is used. + </description> + <arg name="id" type="new_id" interface="xdg_toplevel"/> + </request> + + <request name="get_popup"> + <description summary="assign the xdg_popup surface role"> + This creates an xdg_popup object for the given xdg_surface and gives + the associated wl_surface the xdg_popup role. + + If null is passed as a parent, a parent surface must be specified using + some other protocol, before committing the initial state. + + See the documentation of xdg_popup for more details about what an + xdg_popup is and how it is used. + </description> + <arg name="id" type="new_id" interface="xdg_popup"/> + <arg name="parent" type="object" interface="xdg_surface" allow-null="true"/> + <arg name="positioner" type="object" interface="xdg_positioner"/> + </request> + + <request name="set_window_geometry"> + <description summary="set the new window geometry"> + The window geometry of a surface is its "visible bounds" from the + user's perspective. Client-side decorations often have invisible + portions like drop-shadows which should be ignored for the + purposes of aligning, placing and constraining windows. + + The window geometry is double buffered, and will be applied at the + time wl_surface.commit of the corresponding wl_surface is called. + + When maintaining a position, the compositor should treat the (x, y) + coordinate of the window geometry as the top left corner of the window. + A client changing the (x, y) window geometry coordinate should in + general not alter the position of the window. + + Once the window geometry of the surface is set, it is not possible to + unset it, and it will remain the same until set_window_geometry is + called again, even if a new subsurface or buffer is attached. + + If never set, the value is the full bounds of the surface, + including any subsurfaces. This updates dynamically on every + commit. This unset is meant for extremely simple clients. + + The arguments are given in the surface-local coordinate space of + the wl_surface associated with this xdg_surface. + + The width and height must be greater than zero. Setting an invalid size + will raise an invalid_size error. When applied, the effective window + geometry will be the set window geometry clamped to the bounding + rectangle of the combined geometry of the surface of the xdg_surface and + the associated subsurfaces. + </description> + <arg name="x" type="int"/> + <arg name="y" type="int"/> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + </request> + + <request name="ack_configure"> + <description summary="ack a configure event"> + When a configure event is received, if a client commits the + surface in response to the configure event, then the client + must make an ack_configure request sometime before the commit + request, passing along the serial of the configure event. + + For instance, for toplevel surfaces the compositor might use this + information to move a surface to the top left only when the client has + drawn itself for the maximized or fullscreen state. + + If the client receives multiple configure events before it + can respond to one, it only has to ack the last configure event. + Acking a configure event that was never sent raises an invalid_serial + error. + + A client is not required to commit immediately after sending + an ack_configure request - it may even ack_configure several times + before its next surface commit. + + A client may send multiple ack_configure requests before committing, but + only the last request sent before a commit indicates which configure + event the client really is responding to. + + Sending an ack_configure request consumes the serial number sent with + the request, as well as serial numbers sent by all configure events + sent on this xdg_surface prior to the configure event referenced by + the committed serial. + + It is an error to issue multiple ack_configure requests referencing a + serial from the same configure event, or to issue an ack_configure + request referencing a serial from a configure event issued before the + event identified by the last ack_configure request for the same + xdg_surface. Doing so will raise an invalid_serial error. + </description> + <arg name="serial" type="uint" summary="the serial from the configure event"/> + </request> + + <event name="configure"> + <description summary="suggest a surface change"> + The configure event marks the end of a configure sequence. A configure + sequence is a set of one or more events configuring the state of the + xdg_surface, including the final xdg_surface.configure event. + + Where applicable, xdg_surface surface roles will during a configure + sequence extend this event as a latched state sent as events before the + xdg_surface.configure event. Such events should be considered to make up + a set of atomically applied configuration states, where the + xdg_surface.configure commits the accumulated state. + + Clients should arrange their surface for the new states, and then send + an ack_configure request with the serial sent in this configure event at + some point before committing the new surface. + + If the client receives multiple configure events before it can respond + to one, it is free to discard all but the last event it received. + </description> + <arg name="serial" type="uint" summary="serial of the configure event"/> + </event> + + </interface> + + <interface name="xdg_toplevel" version="5"> + <description summary="toplevel surface"> + This interface defines an xdg_surface role which allows a surface to, + among other things, set window-like properties such as maximize, + fullscreen, and minimize, set application-specific metadata like title and + id, and well as trigger user interactive operations such as interactive + resize and move. + + Unmapping an xdg_toplevel means that the surface cannot be shown + by the compositor until it is explicitly mapped again. + All active operations (e.g., move, resize) are canceled and all + attributes (e.g. title, state, stacking, ...) are discarded for + an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to + the state it had right after xdg_surface.get_toplevel. The client + can re-map the toplevel by performing a commit without any buffer + attached, waiting for a configure event and handling it as usual (see + xdg_surface description). + + Attaching a null buffer to a toplevel unmaps the surface. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the xdg_toplevel"> + This request destroys the role surface and unmaps the surface; + see "Unmapping" behavior in interface section for details. + </description> + </request> + + <enum name="error"> + <entry name="invalid_resize_edge" value="0" summary="provided value is + not a valid variant of the resize_edge enum"/> + <entry name="invalid_parent" value="1" + summary="invalid parent toplevel"/> + <entry name="invalid_size" value="2" + summary="client provided an invalid min or max size"/> + </enum> + + <request name="set_parent"> + <description summary="set the parent of this surface"> + Set the "parent" of this surface. This surface should be stacked + above the parent surface and all other ancestor surfaces. + + Parent surfaces should be set on dialogs, toolboxes, or other + "auxiliary" surfaces, so that the parent is raised when the dialog + is raised. + + Setting a null parent for a child surface unsets its parent. Setting + a null parent for a surface which currently has no parent is a no-op. + + Only mapped surfaces can have child surfaces. Setting a parent which + is not mapped is equivalent to setting a null parent. If a surface + becomes unmapped, its children's parent is set to the parent of + the now-unmapped surface. If the now-unmapped surface has no parent, + its children's parent is unset. If the now-unmapped surface becomes + mapped again, its parent-child relationship is not restored. + + The parent toplevel must not be one of the child toplevel's + descendants, and the parent must be different from the child toplevel, + otherwise the invalid_parent protocol error is raised. + </description> + <arg name="parent" type="object" interface="xdg_toplevel" allow-null="true"/> + </request> + + <request name="set_title"> + <description summary="set surface title"> + Set a short title for the surface. + + This string may be used to identify the surface in a task bar, + window list, or other user interface elements provided by the + compositor. + + The string must be encoded in UTF-8. + </description> + <arg name="title" type="string"/> + </request> + + <request name="set_app_id"> + <description summary="set application ID"> + Set an application identifier for the surface. + + The app ID identifies the general class of applications to which + the surface belongs. The compositor can use this to group multiple + surfaces together, or to determine how to launch a new application. + + For D-Bus activatable applications, the app ID is used as the D-Bus + service name. + + The compositor shell will try to group application surfaces together + by their app ID. As a best practice, it is suggested to select app + ID's that match the basename of the application's .desktop file. + For example, "org.freedesktop.FooViewer" where the .desktop file is + "org.freedesktop.FooViewer.desktop". + + Like other properties, a set_app_id request can be sent after the + xdg_toplevel has been mapped to update the property. + + See the desktop-entry specification [0] for more details on + application identifiers and how they relate to well-known D-Bus + names and .desktop files. + + [0] https://standards.freedesktop.org/desktop-entry-spec/ + </description> + <arg name="app_id" type="string"/> + </request> + + <request name="show_window_menu"> + <description summary="show the window menu"> + Clients implementing client-side decorations might want to show + a context menu when right-clicking on the decorations, giving the + user a menu that they can use to maximize or minimize the window. + + This request asks the compositor to pop up such a window menu at + the given position, relative to the local surface coordinates of + the parent surface. There are no guarantees as to what menu items + the window menu contains, or even if a window menu will be drawn + at all. + + This request must be used in response to some sort of user action + like a button press, key press, or touch down event. + </description> + <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/> + <arg name="serial" type="uint" summary="the serial of the user event"/> + <arg name="x" type="int" summary="the x position to pop up the window menu at"/> + <arg name="y" type="int" summary="the y position to pop up the window menu at"/> + </request> + + <request name="move"> + <description summary="start an interactive move"> + Start an interactive, user-driven move of the surface. + + This request must be used in response to some sort of user action + like a button press, key press, or touch down event. The passed + serial is used to determine the type of interactive move (touch, + pointer, etc). + + The server may ignore move requests depending on the state of + the surface (e.g. fullscreen or maximized), or if the passed serial + is no longer valid. + + If triggered, the surface will lose the focus of the device + (wl_pointer, wl_touch, etc) used for the move. It is up to the + compositor to visually indicate that the move is taking place, such as + updating a pointer cursor, during the move. There is no guarantee + that the device focus will return when the move is completed. + </description> + <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/> + <arg name="serial" type="uint" summary="the serial of the user event"/> + </request> + + <enum name="resize_edge"> + <description summary="edge values for resizing"> + These values are used to indicate which edge of a surface + is being dragged in a resize operation. + </description> + <entry name="none" value="0"/> + <entry name="top" value="1"/> + <entry name="bottom" value="2"/> + <entry name="left" value="4"/> + <entry name="top_left" value="5"/> + <entry name="bottom_left" value="6"/> + <entry name="right" value="8"/> + <entry name="top_right" value="9"/> + <entry name="bottom_right" value="10"/> + </enum> + + <request name="resize"> + <description summary="start an interactive resize"> + Start a user-driven, interactive resize of the surface. + + This request must be used in response to some sort of user action + like a button press, key press, or touch down event. The passed + serial is used to determine the type of interactive resize (touch, + pointer, etc). + + The server may ignore resize requests depending on the state of + the surface (e.g. fullscreen or maximized). + + If triggered, the client will receive configure events with the + "resize" state enum value and the expected sizes. See the "resize" + enum value for more details about what is required. The client + must also acknowledge configure events using "ack_configure". After + the resize is completed, the client will receive another "configure" + event without the resize state. + + If triggered, the surface also will lose the focus of the device + (wl_pointer, wl_touch, etc) used for the resize. It is up to the + compositor to visually indicate that the resize is taking place, + such as updating a pointer cursor, during the resize. There is no + guarantee that the device focus will return when the resize is + completed. + + The edges parameter specifies how the surface should be resized, and + is one of the values of the resize_edge enum. Values not matching + a variant of the enum will cause a protocol error. The compositor + may use this information to update the surface position for example + when dragging the top left corner. The compositor may also use + this information to adapt its behavior, e.g. choose an appropriate + cursor image. + </description> + <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/> + <arg name="serial" type="uint" summary="the serial of the user event"/> + <arg name="edges" type="uint" enum="resize_edge" summary="which edge or corner is being dragged"/> + </request> + + <enum name="state"> + <description summary="types of state on the surface"> + The different state values used on the surface. This is designed for + state values like maximized, fullscreen. It is paired with the + configure event to ensure that both the client and the compositor + setting the state can be synchronized. + + States set in this way are double-buffered. They will get applied on + the next commit. + </description> + <entry name="maximized" value="1" summary="the surface is maximized"> + <description summary="the surface is maximized"> + The surface is maximized. The window geometry specified in the configure + event must be obeyed by the client. + + The client should draw without shadow or other + decoration outside of the window geometry. + </description> + </entry> + <entry name="fullscreen" value="2" summary="the surface is fullscreen"> + <description summary="the surface is fullscreen"> + The surface is fullscreen. The window geometry specified in the + configure event is a maximum; the client cannot resize beyond it. For + a surface to cover the whole fullscreened area, the geometry + dimensions must be obeyed by the client. For more details, see + xdg_toplevel.set_fullscreen. + </description> + </entry> + <entry name="resizing" value="3" summary="the surface is being resized"> + <description summary="the surface is being resized"> + The surface is being resized. The window geometry specified in the + configure event is a maximum; the client cannot resize beyond it. + Clients that have aspect ratio or cell sizing configuration can use + a smaller size, however. + </description> + </entry> + <entry name="activated" value="4" summary="the surface is now activated"> + <description summary="the surface is now activated"> + Client window decorations should be painted as if the window is + active. Do not assume this means that the window actually has + keyboard or pointer focus. + </description> + </entry> + <entry name="tiled_left" value="5" since="2"> + <description summary="the surface’s left edge is tiled"> + The window is currently in a tiled layout and the left edge is + considered to be adjacent to another part of the tiling grid. + </description> + </entry> + <entry name="tiled_right" value="6" since="2"> + <description summary="the surface’s right edge is tiled"> + The window is currently in a tiled layout and the right edge is + considered to be adjacent to another part of the tiling grid. + </description> + </entry> + <entry name="tiled_top" value="7" since="2"> + <description summary="the surface’s top edge is tiled"> + The window is currently in a tiled layout and the top edge is + considered to be adjacent to another part of the tiling grid. + </description> + </entry> + <entry name="tiled_bottom" value="8" since="2"> + <description summary="the surface’s bottom edge is tiled"> + The window is currently in a tiled layout and the bottom edge is + considered to be adjacent to another part of the tiling grid. + </description> + </entry> + </enum> + + <request name="set_max_size"> + <description summary="set the maximum size"> + Set a maximum size for the window. + + The client can specify a maximum size so that the compositor does + not try to configure the window beyond this size. + + The width and height arguments are in window geometry coordinates. + See xdg_surface.set_window_geometry. + + Values set in this way are double-buffered. They will get applied + on the next commit. + + The compositor can use this information to allow or disallow + different states like maximize or fullscreen and draw accurate + animations. + + Similarly, a tiling window manager may use this information to + place and resize client windows in a more effective way. + + The client should not rely on the compositor to obey the maximum + size. The compositor may decide to ignore the values set by the + client and request a larger size. + + If never set, or a value of zero in the request, means that the + client has no expected maximum size in the given dimension. + As a result, a client wishing to reset the maximum size + to an unspecified state can use zero for width and height in the + request. + + Requesting a maximum size to be smaller than the minimum size of + a surface is illegal and will result in an invalid_size error. + + The width and height must be greater than or equal to zero. Using + strictly negative values for width or height will result in a + invalid_size error. + </description> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + </request> + + <request name="set_min_size"> + <description summary="set the minimum size"> + Set a minimum size for the window. + + The client can specify a minimum size so that the compositor does + not try to configure the window below this size. + + The width and height arguments are in window geometry coordinates. + See xdg_surface.set_window_geometry. + + Values set in this way are double-buffered. They will get applied + on the next commit. + + The compositor can use this information to allow or disallow + different states like maximize or fullscreen and draw accurate + animations. + + Similarly, a tiling window manager may use this information to + place and resize client windows in a more effective way. + + The client should not rely on the compositor to obey the minimum + size. The compositor may decide to ignore the values set by the + client and request a smaller size. + + If never set, or a value of zero in the request, means that the + client has no expected minimum size in the given dimension. + As a result, a client wishing to reset the minimum size + to an unspecified state can use zero for width and height in the + request. + + Requesting a minimum size to be larger than the maximum size of + a surface is illegal and will result in an invalid_size error. + + The width and height must be greater than or equal to zero. Using + strictly negative values for width and height will result in a + invalid_size error. + </description> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + </request> + + <request name="set_maximized"> + <description summary="maximize the window"> + Maximize the surface. + + After requesting that the surface should be maximized, the compositor + will respond by emitting a configure event. Whether this configure + actually sets the window maximized is subject to compositor policies. + The client must then update its content, drawing in the configured + state. The client must also acknowledge the configure when committing + the new content (see ack_configure). + + It is up to the compositor to decide how and where to maximize the + surface, for example which output and what region of the screen should + be used. + + If the surface was already maximized, the compositor will still emit + a configure event with the "maximized" state. + + If the surface is in a fullscreen state, this request has no direct + effect. It may alter the state the surface is returned to when + unmaximized unless overridden by the compositor. + </description> + </request> + + <request name="unset_maximized"> + <description summary="unmaximize the window"> + Unmaximize the surface. + + After requesting that the surface should be unmaximized, the compositor + will respond by emitting a configure event. Whether this actually + un-maximizes the window is subject to compositor policies. + If available and applicable, the compositor will include the window + geometry dimensions the window had prior to being maximized in the + configure event. The client must then update its content, drawing it in + the configured state. The client must also acknowledge the configure + when committing the new content (see ack_configure). + + It is up to the compositor to position the surface after it was + unmaximized; usually the position the surface had before maximizing, if + applicable. + + If the surface was already not maximized, the compositor will still + emit a configure event without the "maximized" state. + + If the surface is in a fullscreen state, this request has no direct + effect. It may alter the state the surface is returned to when + unmaximized unless overridden by the compositor. + </description> + </request> + + <request name="set_fullscreen"> + <description summary="set the window as fullscreen on an output"> + Make the surface fullscreen. + + After requesting that the surface should be fullscreened, the + compositor will respond by emitting a configure event. Whether the + client is actually put into a fullscreen state is subject to compositor + policies. The client must also acknowledge the configure when + committing the new content (see ack_configure). + + The output passed by the request indicates the client's preference as + to which display it should be set fullscreen on. If this value is NULL, + it's up to the compositor to choose which display will be used to map + this surface. + + If the surface doesn't cover the whole output, the compositor will + position the surface in the center of the output and compensate with + with border fill covering the rest of the output. The content of the + border fill is undefined, but should be assumed to be in some way that + attempts to blend into the surrounding area (e.g. solid black). + + If the fullscreened surface is not opaque, the compositor must make + sure that other screen content not part of the same surface tree (made + up of subsurfaces, popups or similarly coupled surfaces) are not + visible below the fullscreened surface. + </description> + <arg name="output" type="object" interface="wl_output" allow-null="true"/> + </request> + + <request name="unset_fullscreen"> + <description summary="unset the window as fullscreen"> + Make the surface no longer fullscreen. + + After requesting that the surface should be unfullscreened, the + compositor will respond by emitting a configure event. + Whether this actually removes the fullscreen state of the client is + subject to compositor policies. + + Making a surface unfullscreen sets states for the surface based on the following: + * the state(s) it may have had before becoming fullscreen + * any state(s) decided by the compositor + * any state(s) requested by the client while the surface was fullscreen + + The compositor may include the previous window geometry dimensions in + the configure event, if applicable. + + The client must also acknowledge the configure when committing the new + content (see ack_configure). + </description> + </request> + + <request name="set_minimized"> + <description summary="set the window as minimized"> + Request that the compositor minimize your surface. There is no + way to know if the surface is currently minimized, nor is there + any way to unset minimization on this surface. + + If you are looking to throttle redrawing when minimized, please + instead use the wl_surface.frame event for this, as this will + also work with live previews on windows in Alt-Tab, Expose or + similar compositor features. + </description> + </request> + + <event name="configure"> + <description summary="suggest a surface change"> + This configure event asks the client to resize its toplevel surface or + to change its state. The configured state should not be applied + immediately. See xdg_surface.configure for details. + + The width and height arguments specify a hint to the window + about how its surface should be resized in window geometry + coordinates. See set_window_geometry. + + If the width or height arguments are zero, it means the client + should decide its own window dimension. This may happen when the + compositor needs to configure the state of the surface but doesn't + have any information about any previous or expected dimension. + + The states listed in the event specify how the width/height + arguments should be interpreted, and possibly how it should be + drawn. + + Clients must send an ack_configure in response to this event. See + xdg_surface.configure and xdg_surface.ack_configure for details. + </description> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + <arg name="states" type="array"/> + </event> + + <event name="close"> + <description summary="surface wants to be closed"> + The close event is sent by the compositor when the user + wants the surface to be closed. This should be equivalent to + the user clicking the close button in client-side decorations, + if your application has any. + + This is only a request that the user intends to close the + window. The client may choose to ignore this request, or show + a dialog to ask the user to save their data, etc. + </description> + </event> + + <!-- Version 4 additions --> + + <event name="configure_bounds" since="4"> + <description summary="recommended window geometry bounds"> + The configure_bounds event may be sent prior to a xdg_toplevel.configure + event to communicate the bounds a window geometry size is recommended + to constrain to. + + The passed width and height are in surface coordinate space. If width + and height are 0, it means bounds is unknown and equivalent to as if no + configure_bounds event was ever sent for this surface. + + The bounds can for example correspond to the size of a monitor excluding + any panels or other shell components, so that a surface isn't created in + a way that it cannot fit. + + The bounds may change at any point, and in such a case, a new + xdg_toplevel.configure_bounds will be sent, followed by + xdg_toplevel.configure and xdg_surface.configure. + </description> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + </event> + + <!-- Version 5 additions --> + + <enum name="wm_capabilities" since="5"> + <entry name="window_menu" value="1" summary="show_window_menu is available"/> + <entry name="maximize" value="2" summary="set_maximized and unset_maximized are available"/> + <entry name="fullscreen" value="3" summary="set_fullscreen and unset_fullscreen are available"/> + <entry name="minimize" value="4" summary="set_minimized is available"/> + </enum> + + <event name="wm_capabilities" since="5"> + <description summary="compositor capabilities"> + This event advertises the capabilities supported by the compositor. If + a capability isn't supported, clients should hide or disable the UI + elements that expose this functionality. For instance, if the + compositor doesn't advertise support for minimized toplevels, a button + triggering the set_minimized request should not be displayed. + + The compositor will ignore requests it doesn't support. For instance, + a compositor which doesn't advertise support for minimized will ignore + set_minimized requests. + + Compositors must send this event once before the first + xdg_surface.configure event. When the capabilities change, compositors + must send this event again and then send an xdg_surface.configure + event. + + The configured state should not be applied immediately. See + xdg_surface.configure for details. + + The capabilities are sent as an array of 32-bit unsigned integers in + native endianness. + </description> + <arg name="capabilities" type="array" summary="array of 32-bit capabilities"/> + </event> + </interface> + + <interface name="xdg_popup" version="5"> + <description summary="short-lived, popup surfaces for menus"> + A popup surface is a short-lived, temporary surface. It can be used to + implement for example menus, popovers, tooltips and other similar user + interface concepts. + + A popup can be made to take an explicit grab. See xdg_popup.grab for + details. + + When the popup is dismissed, a popup_done event will be sent out, and at + the same time the surface will be unmapped. See the xdg_popup.popup_done + event for details. + + Explicitly destroying the xdg_popup object will also dismiss the popup and + unmap the surface. Clients that want to dismiss the popup when another + surface of their own is clicked should dismiss the popup using the destroy + request. + + A newly created xdg_popup will be stacked on top of all previously created + xdg_popup surfaces associated with the same xdg_toplevel. + + The parent of an xdg_popup must be mapped (see the xdg_surface + description) before the xdg_popup itself. + + The client must call wl_surface.commit on the corresponding wl_surface + for the xdg_popup state to take effect. + </description> + + <enum name="error"> + <entry name="invalid_grab" value="0" + summary="tried to grab after being mapped"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="remove xdg_popup interface"> + This destroys the popup. Explicitly destroying the xdg_popup + object will also dismiss the popup, and unmap the surface. + + If this xdg_popup is not the "topmost" popup, a protocol error + will be sent. + </description> + </request> + + <request name="grab"> + <description summary="make the popup take an explicit grab"> + This request makes the created popup take an explicit grab. An explicit + grab will be dismissed when the user dismisses the popup, or when the + client destroys the xdg_popup. This can be done by the user clicking + outside the surface, using the keyboard, or even locking the screen + through closing the lid or a timeout. + + If the compositor denies the grab, the popup will be immediately + dismissed. + + This request must be used in response to some sort of user action like a + button press, key press, or touch down event. The serial number of the + event should be passed as 'serial'. + + The parent of a grabbing popup must either be an xdg_toplevel surface or + another xdg_popup with an explicit grab. If the parent is another + xdg_popup it means that the popups are nested, with this popup now being + the topmost popup. + + Nested popups must be destroyed in the reverse order they were created + in, e.g. the only popup you are allowed to destroy at all times is the + topmost one. + + When compositors choose to dismiss a popup, they may dismiss every + nested grabbing popup as well. When a compositor dismisses popups, it + will follow the same dismissing order as required from the client. + + If the topmost grabbing popup is destroyed, the grab will be returned to + the parent of the popup, if that parent previously had an explicit grab. + + If the parent is a grabbing popup which has already been dismissed, this + popup will be immediately dismissed. If the parent is a popup that did + not take an explicit grab, an error will be raised. + + During a popup grab, the client owning the grab will receive pointer + and touch events for all their surfaces as normal (similar to an + "owner-events" grab in X11 parlance), while the top most grabbing popup + will always have keyboard focus. + </description> + <arg name="seat" type="object" interface="wl_seat" + summary="the wl_seat of the user event"/> + <arg name="serial" type="uint" summary="the serial of the user event"/> + </request> + + <event name="configure"> + <description summary="configure the popup surface"> + This event asks the popup surface to configure itself given the + configuration. The configured state should not be applied immediately. + See xdg_surface.configure for details. + + The x and y arguments represent the position the popup was placed at + given the xdg_positioner rule, relative to the upper left corner of the + window geometry of the parent surface. + + For version 2 or older, the configure event for an xdg_popup is only + ever sent once for the initial configuration. Starting with version 3, + it may be sent again if the popup is setup with an xdg_positioner with + set_reactive requested, or in response to xdg_popup.reposition requests. + </description> + <arg name="x" type="int" + summary="x position relative to parent surface window geometry"/> + <arg name="y" type="int" + summary="y position relative to parent surface window geometry"/> + <arg name="width" type="int" summary="window geometry width"/> + <arg name="height" type="int" summary="window geometry height"/> + </event> + + <event name="popup_done"> + <description summary="popup interaction is done"> + The popup_done event is sent out when a popup is dismissed by the + compositor. The client should destroy the xdg_popup object at this + point. + </description> + </event> + + <!-- Version 3 additions --> + + <request name="reposition" since="3"> + <description summary="recalculate the popup's location"> + Reposition an already-mapped popup. The popup will be placed given the + details in the passed xdg_positioner object, and a + xdg_popup.repositioned followed by xdg_popup.configure and + xdg_surface.configure will be emitted in response. Any parameters set + by the previous positioner will be discarded. + + The passed token will be sent in the corresponding + xdg_popup.repositioned event. The new popup position will not take + effect until the corresponding configure event is acknowledged by the + client. See xdg_popup.repositioned for details. The token itself is + opaque, and has no other special meaning. + + If multiple reposition requests are sent, the compositor may skip all + but the last one. + + If the popup is repositioned in response to a configure event for its + parent, the client should send an xdg_positioner.set_parent_configure + and possibly an xdg_positioner.set_parent_size request to allow the + compositor to properly constrain the popup. + + If the popup is repositioned together with a parent that is being + resized, but not in response to a configure event, the client should + send an xdg_positioner.set_parent_size request. + </description> + <arg name="positioner" type="object" interface="xdg_positioner"/> + <arg name="token" type="uint" summary="reposition request token"/> + </request> + + <event name="repositioned" since="3"> + <description summary="signal the completion of a repositioned request"> + The repositioned event is sent as part of a popup configuration + sequence, together with xdg_popup.configure and lastly + xdg_surface.configure to notify the completion of a reposition request. + + The repositioned event is to notify about the completion of a + xdg_popup.reposition request. The token argument is the token passed + in the xdg_popup.reposition request. + + Immediately after this event is emitted, xdg_popup.configure and + xdg_surface.configure will be sent with the updated size and position, + as well as a new configure serial. + + The client should optionally update the content of the popup, but must + acknowledge the new popup configuration for the new position to take + effect. See xdg_surface.ack_configure for details. + </description> + <arg name="token" type="uint" summary="reposition request token"/> + </event> + + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/protocols/xdg-toplevel-icon-v1.xml b/app/src/main/cpp/waylandcomp/protocols/xdg-toplevel-icon-v1.xml new file mode 100644 index 0000000000..985c3f3da6 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/protocols/xdg-toplevel-icon-v1.xml @@ -0,0 +1,205 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="xdg_toplevel_icon_v1"> + + <copyright> + Copyright © 2023-2024 Matthias Klumpp + Copyright © 2024 David Edmundson + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <description summary="protocol to assign icons to toplevels"> + This protocol allows clients to set icons for their toplevel surfaces + either via the XDG icon stock (using an icon name), or from pixel data. + + A toplevel icon represents the individual toplevel (unlike the application + or launcher icon, which represents the application as a whole), and may be + shown in window switchers, window overviews and taskbars that list + individual windows. + + This document adheres to RFC 2119 when using words like "must", + "should", "may", etc. + + Warning! The protocol described in this file is currently in the testing + phase. Backward compatible changes may be added together with the + corresponding interface version bump. Backward incompatible changes can + only be done by creating a new major version of the extension. + </description> + + <interface name="xdg_toplevel_icon_manager_v1" version="1"> + <description summary="interface to manage toplevel icons"> + This interface allows clients to create toplevel window icons and set + them on toplevel windows to be displayed to the user. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the toplevel icon manager"> + Destroy the toplevel icon manager. + This does not destroy objects created with the manager. + </description> + </request> + + <request name="create_icon"> + <description summary="create a new icon instance"> + Creates a new icon object. This icon can then be attached to a + xdg_toplevel via the 'set_icon' request. + </description> + <arg name="id" type="new_id" interface="xdg_toplevel_icon_v1"/> + </request> + + <request name="set_icon"> + <description summary="set an icon on a toplevel window"> + This request assigns the icon 'icon' to 'toplevel', or clears the + toplevel icon if 'icon' was null. + This state is double-buffered and is applied on the next + wl_surface.commit of the toplevel. + + After making this call, the xdg_toplevel_icon_v1 provided as 'icon' + can be destroyed by the client without 'toplevel' losing its icon. + The xdg_toplevel_icon_v1 is immutable from this point, and any + future attempts to change it must raise the + 'xdg_toplevel_icon_v1.immutable' protocol error. + + The compositor must set the toplevel icon from either the pixel data + the icon provides, or by loading a stock icon using the icon name. + See the description of 'xdg_toplevel_icon_v1' for details. + + If 'icon' is set to null, the icon of the respective toplevel is reset + to its default icon (usually the icon of the application, derived from + its desktop-entry file, or a placeholder icon). + If this request is passed an icon with no pixel buffers or icon name + assigned, the icon must be reset just like if 'icon' was null. + </description> + <arg name="toplevel" type="object" interface="xdg_toplevel" summary="the toplevel to act on"/> + <arg name="icon" type="object" interface="xdg_toplevel_icon_v1" allow-null="true"/> + </request> + + <event name="icon_size"> + <description summary="describes a supported & preferred icon size"> + This event indicates an icon size the compositor prefers to be + available if the client has scalable icons and can render to any size. + + When the 'xdg_toplevel_icon_manager_v1' object is created, the + compositor may send one or more 'icon_size' events to describe the list + of preferred icon sizes. If the compositor has no size preference, it + may not send any 'icon_size' event, and it is up to the client to + decide a suitable icon size. + + A sequence of 'icon_size' events must be finished with a 'done' event. + If the compositor has no size preferences, it must still send the + 'done' event, without any preceding 'icon_size' events. + </description> + <arg name="size" type="int" + summary="the edge size of the square icon in surface-local coordinates, e.g. 64"/> + </event> + + <event name="done"> + <description summary="all information has been sent"> + This event is sent after all 'icon_size' events have been sent. + </description> + </event> + </interface> + + <interface name="xdg_toplevel_icon_v1" version="1"> + <description summary="a toplevel window icon"> + This interface defines a toplevel icon. + An icon can have a name, and multiple buffers. + In order to be applied, the icon must have either a name, or at least + one buffer assigned. Applying an empty icon (with no buffer or name) to + a toplevel should reset its icon to the default icon. + + It is up to compositor policy whether to prefer using a buffer or loading + an icon via its name. See 'set_name' and 'add_buffer' for details. + </description> + + <enum name="error"> + <entry name="invalid_buffer" + summary="the provided buffer does not satisfy requirements" + value="1"/> + <entry name="immutable" + summary="the icon has already been assigned to a toplevel and must not be changed" + value="2"/> + <entry name="no_buffer" + summary="the provided buffer has been destroyed before the toplevel icon" + value="3"/> + </enum> + + <request name="destroy" type="destructor"> + <description summary="destroy the icon object"> + Destroys the 'xdg_toplevel_icon_v1' object. + The icon must still remain set on every toplevel it was assigned to, + until the toplevel icon is reset explicitly. + </description> + </request> + + <request name="set_name"> + <description summary="set an icon name"> + This request assigns an icon name to this icon. + Any previously set name is overridden. + + The compositor must resolve 'icon_name' according to the lookup rules + described in the XDG icon theme specification[1] using the + environment's current icon theme. + + If the compositor does not support icon names or cannot resolve + 'icon_name' according to the XDG icon theme specification it must + fall back to using pixel buffer data instead. + + If this request is made after the icon has been assigned to a toplevel + via 'set_icon', an 'immutable' error must be raised. + + [1]: https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html + </description> + <arg name="icon_name" type="string"/> + </request> + + <request name="add_buffer"> + <description summary="add icon data from a pixel buffer"> + This request adds pixel data supplied as wl_buffer to the icon. + + The client should add pixel data for all icon sizes and scales that + it can provide, or which are explicitly requested by the compositor + via 'icon_size' events on xdg_toplevel_icon_manager_v1. + + The wl_buffer supplying pixel data as 'buffer' must be backed by wl_shm + and must be a square (width and height being equal). + If any of these buffer requirements are not fulfilled, a 'invalid_buffer' + error must be raised. + + If this icon instance already has a buffer of the same size and scale + from a previous 'add_buffer' request, data from the last request + overrides the preexisting pixel data. + + The wl_buffer must be kept alive for as long as the xdg_toplevel_icon + it is associated with is not destroyed, otherwise a 'no_buffer' error + is raised. The buffer contents must not be modified after it was + assigned to the icon. As a result, the region of the wl_shm_pool's + backing storage used for the wl_buffer must not be modified after this + request is sent. The wl_buffer.release event is unused. + + If this request is made after the icon has been assigned to a toplevel + via 'set_icon', an 'immutable' error must be raised. + </description> + <arg name="buffer" type="object" interface="wl_buffer"/> + <arg name="scale" type="int" + summary="the scaling factor of the icon, e.g. 1"/> + </request> + </interface> +</protocol> diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c new file mode 100644 index 0000000000..a697ab19b4 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.c @@ -0,0 +1,426 @@ +/* Zero-copy game frames: banner_ahb_v1 + the game's AHardwareBuffers on the sc_layer SurfaceControl. + * See ahb_swapchain.h and ZERO_COPY_SPIKE.md. */ +#define _GNU_SOURCE +#include "ahb_swapchain.h" +#include "banner_color.h" +#include "banner_ext.h" +#include "sc_layer.h" +#include "vk_present.h" +#include "banner-ahb-v1-server-protocol.h" +#include <android/hardware_buffer.h> +#include <errno.h> +#include <fcntl.h> +#include <poll.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <time.h> +#include <unistd.h> + +#define MOD_QCOM_COMPRESSED 0x0500000000000001ULL /* DRM_FORMAT_MOD_QCOM_COMPRESSED (UBWC) */ + +/* linux/dma-buf.h (not in the NDK sysroot's older headers): sync_file export / import. */ +struct banner_dma_buf_sync_file { uint32_t flags; int32_t fd; }; +#define BANNER_DMA_BUF_SYNC_READ 1u +#define BANNER_DMA_BUF_IOCTL_EXPORT_SYNC_FILE _IOWR('b', 2, struct banner_dma_buf_sync_file) +#define BANNER_DMA_BUF_IOCTL_IMPORT_SYNC_FILE _IOW('b', 3, struct banner_dma_buf_sync_file) + +extern volatile int g_zero_copy; + +/* One per wl_buffer the game attached an AHardwareBuffer to. Lives while the wl_buffer exists or + * the buffer is still on the layer / held by SurfaceFlinger, whichever is longer. */ +struct ahb_buf { + uint64_t id; /* the token sc_layer.c hands back */ + struct dmabuf_buffer *b; /* one reference held for the life of this record */ + AHardwareBuffer *ahb; /* our reference to the game's buffer */ + int w, h; + uint32_t stride, image_count; + uint32_t format; /* AHARDWAREBUFFER_FORMAT_* gralloc gave it (10-bit for HDR10) */ + uint64_t modifier; + struct wl_client *client; + struct wl_resource *resource; /* the wl_buffer; NULL once the client destroyed it */ + struct wl_listener resource_destroy; + int on_layer; /* set on the SurfaceControl (or not yet released by SurfaceFlinger) */ + int release_pending; /* the surface let go of it while on the layer */ + int64_t deferred_ns; /* when it did (the perf line: how long the display kept it) */ + struct surface *surface; /* for the paced release; NULL = release at once */ + struct wl_event_source *fence_src; /* fallback: waiting the release fence in the event loop */ + int fence_fd; + struct wl_list link; +}; + +static struct wl_list g_bufs; +static struct wl_list g_clients; /* bound banner_ahb_v1 resources (wl_resource links) */ +static uint64_t g_next_id = 1; +static struct wl_event_loop *g_loop; +static unsigned g_stat_zero_copy; +static int g_export_failed_logged, g_import_failed_logged; +static int g_advertised; /* the global exists */ +static int g_mode_sent = -1; /* the mode clients were last told (-1 = none yet) */ +static struct surface *g_announced; /* "presenting X without a copy" said for this surface */ +static volatile int64_t g_last_zero_copy_ns; /* when a frame last went on the layer without a copy */ + +/* SurfaceFlinger's callback thread -> compositor thread: released tokens + their fences. */ +struct released { uint64_t id; int fd; }; +static pthread_mutex_t g_rel_lock = PTHREAD_MUTEX_INITIALIZER; +static struct released *g_rel; +static int g_rel_n, g_rel_cap; +static int g_rel_pipe[2] = {-1, -1}; + +/* Which swapchains were announced (one log line per swapchain, not per image). */ +struct chain_seen { struct wl_client *client; int w, h; uint32_t image_count; uint64_t modifier; uint32_t format; }; +static struct chain_seen g_last_chain; + +static int64_t now_ns(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +static struct ahb_buf *find_buf(uint64_t id) { + struct ahb_buf *ab; + wl_list_for_each(ab, &g_bufs, link) + if (ab->id == id) return ab; + return NULL; +} + +static void buf_free(struct ahb_buf *ab) { + if (ab->resource) { wl_list_remove(&ab->resource_destroy.link); ab->resource = NULL; } + if (ab->fence_src) { wl_event_source_remove(ab->fence_src); ab->fence_src = NULL; } + if (ab->fence_fd >= 0) { close(ab->fence_fd); ab->fence_fd = -1; } + wl_list_remove(&ab->link); + *banner_dmabuf_ahb_slot(ab->b) = NULL; + AHardwareBuffer_release(ab->ahb); + banner_dmabuf_unref(ab->b); + free(ab); +} + +/* Free once neither the client (wl_buffer) nor the display (layer) refers to it. */ +static void maybe_free(struct ahb_buf *ab) { + if (!ab->resource && !ab->on_layer && !ab->fence_src) buf_free(ab); +} + +static void on_buffer_resource_destroyed(struct wl_listener *l, void *data) { + struct ahb_buf *ab = wl_container_of(l, ab, resource_destroy); + wl_list_remove(&ab->resource_destroy.link); + ab->resource = NULL; + ab->release_pending = 0; /* nothing left to release to */ + maybe_free(ab); +} + +/* ---- release: SurfaceFlinger is done with the buffer -> the game's next acquire waits, then wl_buffer.release */ + +static void send_deferred_release(struct ahb_buf *ab) { + if (ab->release_pending && ab->resource) + banner_release_buffer(ab->surface, ab->resource, ab->surface != NULL, ab->deferred_ns); + ab->release_pending = 0; + ab->surface = NULL; +} + +static int on_fence_readable(int fd, uint32_t mask, void *data) { + struct ahb_buf *ab = data; + wl_event_source_remove(ab->fence_src); + ab->fence_src = NULL; + close(ab->fence_fd); + ab->fence_fd = -1; + send_deferred_release(ab); + maybe_free(ab); + return 0; +} + +/* Compositor thread. Puts the display's release fence into the dma-buf so the game's driver waits + * on it before rendering into the buffer again (Mesa exports every fence of the dma-buf as the + * acquire semaphore), then gives the buffer back. If the kernel refuses the import, the release + * itself waits for the fence instead. */ +static void handle_released(uint64_t id, int fd) { + struct ahb_buf *ab = find_buf(id); + if (!ab) { if (fd >= 0) close(fd); return; } + ab->on_layer = 0; + if (fd >= 0) { + struct banner_dma_buf_sync_file imp = {.flags = BANNER_DMA_BUF_SYNC_READ, .fd = fd}; + int dmabuf_fd = banner_dmabuf_fd(ab->b); + if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, BANNER_DMA_BUF_IOCTL_IMPORT_SYNC_FILE, &imp) == 0) { + close(fd); + } else { + if (!g_import_failed_logged) { + g_import_failed_logged = 1; + banner_log("layer", "zero-copy: DMA_BUF_IOCTL_IMPORT_SYNC_FILE failed (%s): releases wait for the display's fence here instead", + strerror(errno)); + } + /* Wait it out in the event loop (a sync_file is readable once signalled). */ + struct pollfd p = {.fd = fd, .events = POLLIN}; + if (poll(&p, 1, 0) > 0) { + close(fd); + } else { + ab->fence_fd = fd; + ab->fence_src = wl_event_loop_add_fd(g_loop, fd, WL_EVENT_READABLE, on_fence_readable, ab); + if (!ab->fence_src) { close(fd); ab->fence_fd = -1; } + else return; /* released from on_fence_readable */ + } + } + } + send_deferred_release(ab); + maybe_free(ab); +} + +static int on_release_pipe(int fd, uint32_t mask, void *data) { + char buf[64]; + while (read(fd, buf, sizeof(buf)) > 0) {} + for (;;) { + struct released r; + pthread_mutex_lock(&g_rel_lock); + if (g_rel_n == 0) { pthread_mutex_unlock(&g_rel_lock); break; } + r = g_rel[0]; + memmove(g_rel, g_rel + 1, (size_t)(--g_rel_n) * sizeof(*g_rel)); + pthread_mutex_unlock(&g_rel_lock); + handle_released(r.id, r.fd); + } + return 0; +} + +/* SurfaceFlinger's callback thread. */ +void ahb_swapchain_layer_released(void *token, int release_fd) { + pthread_mutex_lock(&g_rel_lock); + if (g_rel_n == g_rel_cap) { + int cap = g_rel_cap ? g_rel_cap * 2 : 16; + struct released *n = realloc(g_rel, (size_t)cap * sizeof(*n)); + if (!n) { pthread_mutex_unlock(&g_rel_lock); if (release_fd >= 0) close(release_fd); return; } + g_rel = n; g_rel_cap = cap; + } + g_rel[g_rel_n++] = (struct released){(uint64_t)(uintptr_t)token, release_fd}; + pthread_mutex_unlock(&g_rel_lock); + if (g_rel_pipe[1] >= 0) { char c = 1; if (write(g_rel_pipe[1], &c, 1) < 0) {} } +} + +/* ---- present */ + +int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b) { + return b && *banner_dmabuf_ahb_slot((struct dmabuf_buffer *)b) != NULL; +} + +int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h) { + struct ahb_buf *ab = b ? *banner_dmabuf_ahb_slot(b) : NULL; + if (!ab) return -1; + int dmabuf_fd = banner_dmabuf_fd(b); + /* Acquire fence: the game's render fence, which its driver put into the dma-buf before the + * commit (Mesa's implicit sync). The display waits on it, not the CPU. */ + int acquire = -1; + struct banner_dma_buf_sync_file exp = {.flags = BANNER_DMA_BUF_SYNC_READ, .fd = -1}; + if (dmabuf_fd >= 0 && ioctl(dmabuf_fd, BANNER_DMA_BUF_IOCTL_EXPORT_SYNC_FILE, &exp) == 0 && exp.fd >= 0) { + acquire = exp.fd; + } else if (dmabuf_fd >= 0) { + if (!g_export_failed_logged) { + g_export_failed_logged = 1; + banner_log("layer", "zero-copy: DMA_BUF_IOCTL_EXPORT_SYNC_FILE failed (%s): waiting for each frame on the CPU instead", + strerror(errno)); + } + struct pollfd p = {.fd = dmabuf_fd, .events = POLLIN}; /* readable = the writers are done */ + int r; + do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); + } + int r = sc_layer_present_ahb(ab->ahb, ab->w, ab->h, acquire, (void *)(uintptr_t)ab->id, scene_w, scene_h, + s ? banner_surface_color(s) : NULL, ab->format); + if (r < 0) return -1; + if (r == 1) return 0; /* nothing of it on screen: not on the layer, nothing to release later */ + if (!ab->on_layer) { + ab->on_layer = 1; + g_stat_zero_copy++; + g_last_zero_copy_ns = now_ns(); + } + if (s && g_announced != s) { + char name[160]; + g_announced = s; + banner_surface_describe(s, name, sizeof(name)); + banner_log("layer", "zero-copy: presenting %s without a copy", name); + } + return 0; +} + +int ahb_swapchain_last_frame_age_ms(void) { + int64_t t = g_last_zero_copy_ns; + if (!t) return -1; + int64_t age = (now_ns() - t) / 1000000LL; + return age > INT32_MAX ? INT32_MAX : (int)age; +} + +int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buffer, struct surface *s, int paced) { + struct ahb_buf *ab = b ? *banner_dmabuf_ahb_slot(b) : NULL; + if (!ab || !ab->on_layer || !buffer || ab->resource != buffer) return 0; + ab->release_pending = 1; + ab->deferred_ns = now_ns(); + ab->surface = paced ? s : NULL; + return 1; +} + +void ahb_swapchain_surface_gone(struct surface *s) { + struct ahb_buf *ab; + wl_list_for_each(ab, &g_bufs, link) + if (ab->surface == s) ab->surface = NULL; +} + +unsigned ahb_swapchain_stats_take(void) { + unsigned n = g_stat_zero_copy; + g_stat_zero_copy = 0; + return n; +} + +int ahb_swapchain_advertised(void) { return g_advertised; } + +uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b) { + struct ahb_buf *ab = b ? *banner_dmabuf_ahb_slot((struct dmabuf_buffer *)b) : NULL; + return ab ? ab->format : 0; +} + +/* ---- banner_ahb_v1 */ + +static void ahb_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } + +static void ahb_attach(struct wl_client *c, struct wl_resource *r, struct wl_resource *buffer, int32_t sock, + uint32_t width, uint32_t height, uint32_t stride, uint32_t mod_hi, uint32_t mod_lo, + uint32_t image_count) { + struct dmabuf_buffer *b = banner_dmabuf_from_resource(buffer); + uint64_t modifier = ((uint64_t)mod_hi << 32) | mod_lo; + if (!b) { + banner_log("layer", "zero-copy: %s attached an AHardwareBuffer to a non-dma-buf wl_buffer, ignored", banner_client_name(c)); + close(sock); + return; + } + void **slot = banner_dmabuf_ahb_slot(b); + if (*slot) { close(sock); return; } /* once per buffer */ + + /* The handle was written into the socket before the request was sent; a short wait is just + * insurance against a slow sender. */ + struct pollfd p = {.fd = sock, .events = POLLIN}; + int pr; + do { pr = poll(&p, 1, 1000); } while (pr < 0 && errno == EINTR); + AHardwareBuffer *ahb = NULL; + int rc = pr > 0 ? AHardwareBuffer_recvHandleFromUnixSocket(sock, &ahb) : -1; + close(sock); + if (rc != 0 || !ahb) { + banner_log("layer", "zero-copy: receiving %s's AHardwareBuffer failed (%s)", banner_client_name(c), + pr > 0 ? "recvHandleFromUnixSocket" : "nothing on the socket"); + return; + } + AHardwareBuffer_Desc d; + AHardwareBuffer_describe(ahb, &d); + int bw, bh; + banner_dmabuf_size(b, &bw, &bh); + if ((int)d.width != bw || (int)d.height != bh || (int)width != bw || (int)height != bh) { + banner_log("layer", "zero-copy: %s's AHardwareBuffer is %ux%u but its wl_buffer %dx%d, ignored", + banner_client_name(c), d.width, d.height, bw, bh); + AHardwareBuffer_release(ahb); + return; + } + + struct ahb_buf *ab = calloc(1, sizeof(*ab)); + if (!ab) { AHardwareBuffer_release(ahb); wl_client_post_no_memory(c); return; } + ab->id = g_next_id++; + ab->b = b; + banner_dmabuf_ref(b); + ab->ahb = ahb; + ab->w = bw; ab->h = bh; + ab->stride = d.stride ? d.stride : stride; + ab->image_count = image_count; + ab->format = d.format; + ab->modifier = modifier; + ab->client = c; + ab->resource = buffer; + ab->resource_destroy.notify = on_buffer_resource_destroyed; + wl_resource_add_destroy_listener(buffer, &ab->resource_destroy); + ab->fence_fd = -1; + wl_list_insert(g_bufs.prev, &ab->link); + *slot = ab; + + if (g_last_chain.client != c || g_last_chain.w != bw || g_last_chain.h != bh || + g_last_chain.image_count != image_count || g_last_chain.modifier != modifier || g_last_chain.format != d.format) { + g_last_chain = (struct chain_seen){c, bw, bh, image_count, modifier, d.format}; + banner_log("layer", "zero-copy: AHB swapchain from %s (%u images, %dx%d, %s, %s, stride %u px)", banner_client_name(c), + image_count, bw, bh, banner_ahb_format_name(d.format), modifier == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" + : modifier == 0 ? "linear" : "unknown modifier", ab->stride); + } +} + +static const struct banner_ahb_v1_interface ahb_impl = { + .destroy = ahb_destroy, + .attach = ahb_attach, +}; + +static void on_client_resource_destroyed(struct wl_resource *r) { + wl_list_remove(wl_resource_get_link(r)); +} + +static void bind_ahb(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + static struct wl_client *last_named; + if (ver > 2) ver = 2; + struct wl_resource *r = wl_resource_create(c, &banner_ahb_v1_interface, (int)ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &ahb_impl, NULL, on_client_resource_destroyed); + wl_list_insert(&g_clients, wl_resource_get_link(r)); + /* The mode travels with the bind, so the client's registry roundtrip already has it when it + * decides about its first swapchain. */ + if (ver >= BANNER_AHB_V1_MODE_SINCE_VERSION) banner_ahb_v1_send_mode(r, g_zero_copy ? 1u : 0u); + /* One line per program, not per surface-format query (each binds its own). */ + if (last_named != c) { + last_named = c; + banner_log("layer", "zero-copy: %s bound banner_ahb_v1 version %u (%s)", banner_client_name(c), ver, + ver >= 2 ? "follows the live switch" : "version 1: decides from its launch environment only"); + } +} + +void ahb_swapchain_set_mode(int on, int live) { + on = on ? 1 : 0; + g_zero_copy = on; + if (!g_advertised) { + if (live) banner_log("layer", "zero-copy switched %s from the drawer, but no display layer is available on this device: no change", + on ? "on" : "off"); + return; + } + if (g_mode_sent == on) return; + g_mode_sent = on; + int told = 0; + struct wl_resource *r; + wl_resource_for_each(r, &g_clients) { + if (wl_resource_get_version(r) >= BANNER_AHB_V1_MODE_SINCE_VERSION) { + banner_ahb_v1_send_mode(r, (uint32_t)on); + told++; + } + } + /* The next chain and the next fullscreen frame get announced again. */ + memset(&g_last_chain, 0, sizeof(g_last_chain)); + g_announced = NULL; + if (live) + banner_log("layer", "zero-copy switched %s from the drawer: %d bound program%s told to rebuild their swapchains%s", + on ? "on" : "off", told, told == 1 ? "" : "s", + on ? "; frames go on the display layer once the new gralloc swapchain is up" + : "; gralloc frames still in flight stay on the layer (or take the copy path) until then"); + else + banner_log("layer", "zero-copy: %s at launch (%s)", on ? "on" : "off", + on ? "BANNER_WAYLAND_ZERO_COPY=1: games present their own gralloc buffers on the display layer" + : "the drawer's Zero-copy presentation switch turns it on live"); + if (live) wl_display_flush_clients(banner_get_display()); + banner_request_redraw(); +} + +void ahb_swapchain_init(struct wl_display *display) { + wl_list_init(&g_bufs); + wl_list_init(&g_clients); + if (!sc_layer_available()) { + banner_log("layer", "zero-copy: no display layer on this device (see the line above): banner_ahb_v1 not advertised"); + return; + } + g_loop = wl_display_get_event_loop(display); + if (pipe2(g_rel_pipe, O_CLOEXEC | O_NONBLOCK) != 0) { + banner_log("error", "zero-copy: release pipe creation failed (%s); zero-copy presents disabled", strerror(errno)); + g_rel_pipe[0] = g_rel_pipe[1] = -1; + return; + } + wl_event_loop_add_fd(g_loop, g_rel_pipe[0], WL_EVENT_READABLE, on_release_pipe, NULL); + if (!wl_global_create(display, &banner_ahb_v1_interface, 2, NULL, bind_ahb)) { + banner_log("error", "zero-copy: banner_ahb_v1 global creation failed"); + return; + } + g_advertised = 1; + banner_log("layer", "zero-copy: banner_ahb_v1 version 2 advertised (games built for it present their own gralloc buffers while the switch is on)"); + ahb_swapchain_set_mode(g_zero_copy, 0); +} diff --git a/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h new file mode 100644 index 0000000000..fff1bf2f7b --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/ahb_swapchain.h @@ -0,0 +1,83 @@ +#ifndef AHB_SWAPCHAIN_H +#define AHB_SWAPCHAIN_H +/* + * Zero-copy game frames (layer mode, BANNER_WAYLAND_ZERO_COPY=1 at launch, the drawer's "Zero-copy + * presentation" switch live): the guest half of the design in ZERO_COPY_SPIKE.md. Our Wayland Turnip + * (banners-turnip-wayland, patches/wayland/banner_ahb_wsi.py) binds the private global banner_ahb_v1 + * (version 2), which this compositor advertises on every session where a display layer is possible, + * and follows its `mode` event: while the mode is on, each swapchain the game creates has its images + * allocated as gralloc AHardwareBuffers, shared as dma-bufs through zwp_linux_dmabuf_v1 as before (so + * the blit path still works) and handed to us once per wl_buffer over a socketpair + * (banner_ahb_v1.attach). When such a buffer is the one fullscreen frame, it goes straight onto the + * sc_layer SurfaceControl: SurfaceFlinger / the display scan out the game's own buffer, no copy + * anywhere. A mode flip (ahb_swapchain_set_mode, from the drawer through the host queue) is + * broadcast to every bound client; a client whose live swapchain was built for the other mode + * retires it (VK_ERROR_OUT_OF_DATE_KHR) so the program rebuilds it, and until then its buffers keep + * presenting as before: an attached AHardwareBuffer stays with its wl_buffer whatever the mode is. + * + * Fences stay implicit, in the dma-buf itself: Mesa imports the render fence into the dma-buf + * before it commits, we export it as the layer's acquire fence (DMA_BUF_IOCTL_EXPORT_SYNC_FILE), + * and import SurfaceFlinger's release fence back (DMA_BUF_IOCTL_IMPORT_SYNC_FILE) before sending + * wl_buffer.release, so Mesa's acquire (wsi_create_sync_for_dma_buf_wait) waits for the display. + * + * Compositor thread unless noted. Without a usable display layer (sc_layer_available() == 0) the + * global is not created and nothing here runs. + */ +#include <stddef.h> +#include <stdint.h> +#include <wayland-server.h> + +struct dmabuf_buffer; +struct surface; + +/* ---- compositor.c -> ahb_swapchain.c */ +/* Create the banner_ahb_v1 global (when a display layer is possible at all) and the release queue. */ +void ahb_swapchain_init(struct wl_display *display); +/* Zero-copy on/off, live: sets g_zero_copy, tells every bound client (banner_ahb_v1.mode) and logs + * it (live = 1: a drawer switch mid-session; 0: the launch default). Compositor thread. */ +void ahb_swapchain_set_mode(int on, int live); +/* Milliseconds since a game frame was last put on the layer without a copy (-1 = never). Any thread: + * the drawer's status line. */ +int ahb_swapchain_last_frame_age_ms(void); +/* 1 if the buffer carries an AHardwareBuffer from the game. */ +int ahb_swapchain_has_ahb(const struct dmabuf_buffer *b); +/* Show b (the topmost fullscreen frame, shown by surface s) on the layer without a copy. + * 0 = done (or the same frame is already up), -1 = unavailable (draw the old way). */ +int ahb_swapchain_present(struct dmabuf_buffer *b, struct surface *s, int scene_w, int scene_h); +/* Surface s lets go of buffer b (its wl_buffer `buffer`, NULL if the client destroyed it); paced = + * the limiter's cadence applies. Returns 1 when the buffer is on the layer: the release is sent + * from here once SurfaceFlinger's release fence is known. 0 = the caller releases as usual. */ +int ahb_swapchain_defer_release(struct dmabuf_buffer *b, struct wl_resource *buffer, struct surface *s, int paced); +/* s is being destroyed: forget it (its deferred releases still go out, unpaced). */ +void ahb_swapchain_surface_gone(struct surface *s); +/* Zero-copy frames since the last call (the 10 s summary). */ +unsigned ahb_swapchain_stats_take(void); +/* 1 when the banner_ahb_v1 global exists (a display layer is possible): part of the HDR gate. */ +int ahb_swapchain_advertised(void); +/* The AHARDWAREBUFFER_FORMAT_* of the game's buffer behind b, 0 when it has none. */ +uint32_t ahb_swapchain_ahb_format(const struct dmabuf_buffer *b); + +/* ---- sc_layer.c -> ahb_swapchain.c (SurfaceFlinger's callback thread): the layer let go of the + * buffer behind `token`; release_fd (owned by the callee, -1 = none) signals when the display is + * done reading it. */ +void ahb_swapchain_layer_released(void *token, int release_fd); + +/* ---- ahb_swapchain.c -> compositor.c (hooks) */ +struct dmabuf_buffer *banner_dmabuf_from_resource(struct wl_resource *buffer); +int banner_dmabuf_fd(const struct dmabuf_buffer *b); /* plane 0's dma-buf */ +void banner_dmabuf_size(const struct dmabuf_buffer *b, int *w, int *h); +void **banner_dmabuf_ahb_slot(struct dmabuf_buffer *b); /* this module's per-buffer state */ +void banner_dmabuf_ref(struct dmabuf_buffer *b); +void banner_dmabuf_unref(struct dmabuf_buffer *b); +/* Give a wl_buffer back to its client now (paced = 0) or on the FPS limiter's cadence (s != NULL). + * since_ns = when the compositor let go of it (CLOCK_MONOTONIC; the perf line's release latency). */ +void banner_release_buffer(struct surface *s, struct wl_resource *buffer, int paced, int64_t since_ns); +/* Redraw the scene on the next tick (the present path may have changed). */ +void banner_request_redraw(void); +/* "<title>" (program) of the window a surface belongs to, for the log. */ +void banner_surface_describe(const struct surface *s, char *out, size_t size); +/* The surface's current image description (banner_color.h), NULL = none / HDR gate closed. */ +struct banner_color; +const struct banner_color *banner_surface_color(const struct surface *s); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/banner_color.h b/app/src/main/cpp/waylandcomp/src/banner_color.h new file mode 100644 index 0000000000..fc9f62cd07 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/banner_color.h @@ -0,0 +1,150 @@ +#ifndef BANNER_COLOR_H +#define BANNER_COLOR_H +/* + * HDR10 output on the Wayland backend (opt-in) — the compositor half of HDR_RECON.md Phase A (round 1) + * plus HDR-aware composition (round 2, hdr_compose.h), implemented in wl_color_mgmt.c. The game half + * already ships: Mesa's Wayland WSI in our Turnip is a wp_color_manager_v1 client and exposes + * VK_COLOR_SPACE_HDR10_ST2084_EXT as soon as a compositor advertises BT.2020 + ST 2084; DXVK takes it + * with DXVK_HDR=1 (the app exports it when the setting is on). + * + * THE GATE. Nothing here exists for a session unless all of these hold when the compositor starts: + * - the container's / game's "HDR output" setting is on, or BANNER_WAYLAND_HDR=1 in their + * environment (which overrides the setting either way); + * - the display the game is on lists HDR10 among its supported HDR types (read by the app from + * android.view.Display — a property of the connector, not of the device); + * - display layers with dataspace control (ASurfaceTransaction_setBufferDataSpace, Android 10+) + * and the zero-copy global (banner_ahb_v1): the HDR frame (or the composed HDR picture) is shown + * on the game's own display layer, tagged BT2020_PQ. + * In game, the drawer's HDR output switch (banner_color_set_output) flips between that and the same + * frames tone-mapped to SDR, live; the gate itself never changes during a session. + * A closed gate advertises nothing — no colour-management global, no 10-bit dma-buf formats — so the + * session is byte-for-byte what it was before this file existed, and the session log says why. + * BANNER_WAYLAND_HDR=force skips the display check only (testing the negotiation on an SDR panel; + * SurfaceFlinger then tone-maps the layer, and says so in its composition type). + * + * WHAT AN OPEN GATE OFFERS (exactly the subset Mesa binds, HDR_RECON.md §2.2): wp_color_manager_v1 + * version 1 with the perceptual intent, the parametric creator + mastering-display metadata, + * BT.2020 primaries and the ST 2084 (PQ) transfer function; zwp_linux_dmabuf_v1 adds AB30/XB30 + * (A2B10G10R10, the only 10-bit layout our zero-copy WSI can put in a gralloc buffer). A surface's + * image description is double-buffered on wl_surface.commit; its frames go onto the game's display + * layer tagged BT2020_PQ with the game's SMPTE 2086 / CTA-861.3 metadata (sc_layer.c). + * + * Compositor thread unless noted. + */ +#include <stdint.h> +#include <wayland-server.h> + +/* ADataSpace values (NDK <android/data_space.h>) the layer path emits. */ +#define BANNER_ADATASPACE_UNKNOWN 0 +#define BANNER_ADATASPACE_BT2020_PQ 163971072 /* STANDARD_BT2020 | TRANSFER_ST2084 | RANGE_FULL = 0x09c60000 */ +#define BANNER_ADATASPACE_BT2020_HLG 168165376 /* STANDARD_BT2020 | TRANSFER_HLG | RANGE_FULL */ + +/* One image description as the program made it, and what it becomes on a display layer. Immutable: + * a changed description is a new record with a new identity. */ +struct banner_color { + uint32_t identity; /* the id the `ready` event carried (never 0) */ + uint32_t primaries, tf; /* wp_color_manager_v1 named values */ + int32_t dataspace; /* ADataSpace on a display layer; 0 = none (treated as sRGB) */ + int has_st2086; /* SMPTE ST 2086: mastering display primaries + luminance */ + float red[2], green[2], blue[2], white[2]; /* CIE 1931 xy */ + float max_lum, min_lum; /* nits */ + int has_cta861; /* CTA-861.3 */ + float max_cll, max_fall; /* nits; 0 = not given */ + char text[256]; /* the session log's one-line summary of it */ +}; + +/* ---- app -> compositor (JNI, any thread) */ +/* mode 0 = off, 1 = BANNER_WAYLAND_HDR=1, 2 = BANNER_WAYLAND_HDR=force (testing). source names where + * the switch came from; dxvk_hdr = DXVK_HDR=1 is in the game's environment; zero_copy_forced = the + * app turned zero-copy presentation on for this session because HDR needs it. Before the start. */ +void banner_color_set_request(int mode, const char *source, int dxvk_hdr, int zero_copy_forced); +/* The display the game is on, as android.view.Display reports it. Before the start (it feeds the + * gate) and again whenever it changes (logged; the gate is decided once per session). */ +void banner_color_set_display(int id, const char *name, const char *formats, int hdr10, float max_lum, + float max_avg, float min_lum, int ratio_available, float ratio, int api); +/* One reading of Display.getHdrSdrRatio() (API 34+; < 0 = not available). listener = it came from + * the display's ratio listener rather than the app's periodic sampler. */ +void banner_color_ratio_sample(float ratio, int listener); +/* Milliseconds since an HDR frame last went onto a display layer; -1 = none this session. */ +int banner_color_last_frame_age_ms(void); +/* -1 = the compositor has not decided yet, 0 = closed, 1 = open. */ +int banner_color_gate_state(void); +/* The session is ending: write the summary line ("HDR on screen: …"). */ +void banner_color_session_end(void); +/* 1 while HDR frames are really on screen: a frame tagged BT2020_PQ reached a display layer or the HDR + * swapchain in the last 1.5 s AND, where the display reports an HDR/SDR ratio, its last reading is + * above 1.01 (the HUD badge). */ +int banner_color_hdr_on_screen(void); +/* The HUD / drawer state: 0 = no HDR frames on screen (or not confirmed yet), 1 = HDR frames on screen + * with headroom (as banner_color_hdr_on_screen), 2 = HDR frames on screen but the display has given + * them NO headroom (ratio <= 1.01) for 5 s or more - the brightness slider at maximum, or a screen + * recording (Android turns HDR headroom off while the screen is recorded). */ +int banner_color_hdr_state(void); +/* Nits SDR content is placed at inside an HDR picture (default 203, BT.2408); any thread. */ +void banner_color_set_sdr_white(float nits); +float banner_color_sdr_white(void); +/* The HDR session was asked for (BANNER_WAYLAND_HDR / the setting resolved on or force) — known before + * the compositor starts, so the Vulkan instance can enable VK_EXT_swapchain_colorspace for it. */ +int banner_color_requested(void); +/* The drawer's live "HDR output" switch, per session, starting ON. On = HDR frames go to the display as + * HDR; off = the SAME frames are composed tone-mapped to SDR (hdr_compose.h) - the game is told nothing + * and keeps rendering HDR (DXVK_HDR and the colour-manager offer were decided at launch). Compositor + * thread (the app posts it through banner_host_hdr_output); logs the flip and redraws. */ +void banner_color_set_output(int on); +/* 1 = HDR output on (any thread). */ +int banner_color_output(void); +/* 1 while an HDR game's frames are being shown tone-mapped to SDR (the last one < 1.5 s ago); any thread. */ +int banner_color_tonemapped_on_screen(void); +/* Device evidence beside the HDR/SDR headroom (the app, non-root APIs; any thread; HDR sessions only): + * PowerManager thermal status (0..6, -1 unknown) + getThermalHeadroom(10) (< 0 = not available), + * Settings.System SCREEN_BRIGHTNESS (0..255, -1 unknown) + SCREEN_BRIGHTNESS_MODE (1 auto, 0 manual). + * Changes of status and brightness are logged; every no-headroom line, the 10 s line and the verdict + * carry the last values. */ +void banner_color_env_sample(int thermal, float headroom, int brightness, int bmode); + +/* ---- the explicit HDR headroom request (Android 15+: ASurfaceTransaction_setDesiredHdrHeadroom on the game + * layer, SurfaceView.setDesiredHdrHeadroom on the screen surface). Some phones only boost HDR when asked. */ +/* The ratio to ask for an HDR frame of `c`: content peak (max CLL, else mastering max, else the display's + * peak) / SDR white (203), capped at the display's highest ratio when it reports one; 0 = ask nothing + * (not HDR, or the display reports it cannot boost). `why` gets the one-line reason. Any thread. */ +float banner_color_desired_headroom(const struct banner_color *c, char *why, size_t n); +/* What was last asked for (> 0 the ratio, 0 nothing, -1 the API is missing): for the no-headroom lines. */ +void banner_color_note_headroom_request(float ratio); +/* Display.getHighestHdrSdrRatio() (Android 16+; <= 0 = not reported). Any thread; logged when it arrives. */ +void banner_color_set_highest_ratio(float ratio); +/* The headroom the SCREEN surface should ask for (frames through the HDR10 swapchain in the last 1.5 s), + * 0 = none; `why` gets the reason. The app polls it and applies it. Any thread. */ +float banner_color_screen_headroom(char *why, size_t n); + +/* ---- compositor.c -> here */ +/* Decide the gate (call after ahb_swapchain_init) and create the global when it is open. */ +void banner_color_init(struct wl_display *display); +/* The gate is open: the 10-bit dma-buf formats may be advertised, descriptions may exist. */ +int banner_color_hdr_open(void); +/* wl_surface.commit: the pending image description (if any request touched it) becomes current. */ +void banner_color_commit(struct wl_resource *surface); +/* The surface's current image description; NULL = none (sRGB, today's default). */ +const struct banner_color *banner_color_of(struct wl_resource *surface); +/* A program disconnected: if it presented HDR, its part of the summary is written now. */ +void banner_color_client_gone(struct wl_client *client); +/* The 10 s summary tick (one `color` line when anything HDR happened in the window). */ +void banner_color_stats_tick(void); +/* A frame of an HDR-described surface went through the compositor's own 8-bit sRGB pass this scene + * (who = the window, reason = why it did not get the display layer). Shown untone-mapped. */ +void banner_color_frame_copied(const char *who, const char *reason); + +/* ---- sc_layer.c / compositor.c -> here: a NEW frame of an HDR-described surface was shown, and how */ +enum banner_hdr_path { + BANNER_HDR_ZERO_COPY = 0, /* the game's own gralloc buffer on its display layer, tagged */ + BANNER_HDR_LAYER_COPY, /* one 8-bit copy of the game's frame on its layer, tagged */ + BANNER_HDR_COMPOSED, /* the whole scene composed into one PQ picture on the game layer (hdr_compose.h) */ + BANNER_HDR_SWAPCHAIN, /* composed into PQ and presented through an HDR10 swapchain (frame generation) */ + BANNER_HDR_TONEMAPPED, /* composed and tone-mapped to SDR (HDR output switched off, or a present that + * cannot carry HDR) - NOT HDR */ +}; +/* ahb_format = the buffer's AHARDWAREBUFFER_FORMAT_* where one exists (0 otherwise). */ +void banner_color_frame_shown(const struct banner_color *c, int path, uint32_t ahb_format); +/* "RGBA1010102 (10-bit)" etc. for an AHARDWAREBUFFER_FORMAT_* value (static buffer). */ +const char *banner_ahb_format_name(uint32_t format); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/banner_ext.c b/app/src/main/cpp/waylandcomp/src/banner_ext.c new file mode 100644 index 0000000000..9204da68de --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/banner_ext.c @@ -0,0 +1,125 @@ +/* + * Host → compositor message queue plus the init of the extension modules. + * + * The app's threads (UI thread, clipboard listener) hand text to the compositor through + * banner_host_* ; the messages are queued under a mutex and a pipe byte wakes the wl event + * loop, which drains them on the compositor thread — the only thread that may touch + * wl_resources. + */ +#define _GNU_SOURCE 1 +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <pthread.h> +#include <android/log.h> +#include "banner_ext.h" +#include "ahb_swapchain.h" +#include "banner_color.h" + +enum host_kind { HOST_CLIPBOARD = 1, HOST_TEXT_COMMIT, HOST_TEXT_PREEDIT, HOST_TEXT_DELETE, HOST_ZERO_COPY, HOST_HDR_OUTPUT }; + +struct host_msg { + enum host_kind kind; + char *text; + size_t len; + int a, b; + struct host_msg *next; +}; + +static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; +static struct host_msg *g_head, *g_tail; +static int g_wake[2] = {-1, -1}; + +static void host_post(enum host_kind kind, const char *text, size_t len, int a, int b) { + struct host_msg *m = calloc(1, sizeof(*m)); + if (!m) return; + m->kind = kind; + m->a = a; m->b = b; + if (text && len) { + if (!(m->text = malloc(len + 1))) { free(m); return; } + memcpy(m->text, text, len); + m->text[len] = 0; + m->len = len; + } + pthread_mutex_lock(&g_mu); + if (g_tail) g_tail->next = m; else g_head = m; + g_tail = m; + pthread_mutex_unlock(&g_mu); + if (g_wake[1] >= 0) { + char c = 1; + ssize_t n = write(g_wake[1], &c, 1); + (void)n; + } +} + +void banner_host_clipboard_text(const char *utf8, int len) { + host_post(HOST_CLIPBOARD, utf8, len > 0 ? (size_t)len : 0, 0, 0); +} +void banner_host_text_commit(const char *utf8, int len) { + host_post(HOST_TEXT_COMMIT, utf8, len > 0 ? (size_t)len : 0, 0, 0); +} +void banner_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end) { + host_post(HOST_TEXT_PREEDIT, utf8, len > 0 ? (size_t)len : 0, cursor_begin, cursor_end); +} +void banner_host_text_delete(int before, int after) { + host_post(HOST_TEXT_DELETE, NULL, 0, before, after); +} +void banner_host_zero_copy(int on, int live) { + host_post(HOST_ZERO_COPY, NULL, 0, on, live); +} +void banner_host_hdr_output(int on) { + host_post(HOST_HDR_OUTPUT, NULL, 0, on, 0); +} + +static int on_wake(int fd, uint32_t mask, void *data) { + char buf[64]; + while (read(fd, buf, sizeof(buf)) > 0) {} + for (;;) { + pthread_mutex_lock(&g_mu); + struct host_msg *m = g_head; + if (m) { g_head = m->next; if (!g_head) g_tail = NULL; } + pthread_mutex_unlock(&g_mu); + if (!m) break; + switch (m->kind) { + case HOST_CLIPBOARD: + clipboard_host_text(m->text, m->len); /* takes the buffer */ + m->text = NULL; + break; + case HOST_TEXT_COMMIT: + text_input_host_commit(m->text ? m->text : "", m->len); + break; + case HOST_TEXT_PREEDIT: + text_input_host_preedit(m->text ? m->text : "", m->len, m->a, m->b); + break; + case HOST_TEXT_DELETE: + text_input_host_delete(m->a, m->b); + break; + case HOST_ZERO_COPY: + ahb_swapchain_set_mode(m->a, m->b); + break; + case HOST_HDR_OUTPUT: + banner_color_set_output(m->a); + break; + } + free(m->text); + free(m); + } + wl_display_flush_clients(banner_get_display()); + return 0; +} + +void banner_ext_init(struct wl_display *display) { + struct wl_event_loop *loop = wl_display_get_event_loop(display); + if (pipe2(g_wake, O_CLOEXEC | O_NONBLOCK) == 0) { + wl_event_loop_add_fd(loop, g_wake[0], WL_EVENT_READABLE, on_wake, NULL); + pthread_mutex_lock(&g_mu); + int queued = g_head != NULL; /* posted before the loop existed (clipboard refresh) */ + pthread_mutex_unlock(&g_mu); + if (queued) { char c = 1; ssize_t n = write(g_wake[1], &c, 1); (void)n; } + } else + __android_log_print(ANDROID_LOG_ERROR, "BannerWayland", "host queue pipe failed"); + clipboard_init(display); + text_input_init(display); + toplevel_icon_init(display); +} diff --git a/app/src/main/cpp/waylandcomp/src/banner_ext.h b/app/src/main/cpp/waylandcomp/src/banner_ext.h new file mode 100644 index 0000000000..f982b95332 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/banner_ext.h @@ -0,0 +1,50 @@ +/* + * Interface between compositor.c and the extension modules that live in their own files: + * wl_clipboard.c wl_data_device_manager + zwlr_data_control_manager_v1 (selection only) + * wl_text_input.c zwp_text_input_manager_v3 (host IME / soft keyboard) + * wl_toplevel_icon.c xdg_toplevel_icon_manager_v1 (accepted, not rendered) + * banner_ext.c the host→compositor message queue shared by the modules + * Everything here runs on the compositor (dispatch) thread unless noted. + */ +#pragma once +#include <stdint.h> +#include <wayland-server.h> + +void banner_log(const char *tag, const char *fmt, ...); + +/* ---- compositor.c → modules */ +void banner_ext_init(struct wl_display *display); /* creates the globals + host queue */ +void banner_clipboard_keyboard_focus(struct wl_client *client); /* keyboard focus moved; NULL = none */ +void banner_text_input_refocus(void); /* the text-input target may have changed */ +void banner_text_input_surface_gone(struct wl_resource *surface); + +/* ---- modules → compositor.c */ +const char *banner_client_name(struct wl_client *client); +struct wl_display *banner_get_display(void); +/* The surface text input follows (the last clicked window, else the topmost program window). */ +struct wl_resource *banner_ime_target(void); +/* Scene (virtual desktop) origin of a toplevel surface; 0,0 when unknown. */ +void banner_surface_scene_origin(struct wl_resource *surface, int *x, int *y); +/* Deliver a key press/release through the wl_keyboard path as if typed. */ +void banner_inject_key(uint32_t evdev, int pressed); + +/* ---- modules → app (JNI upcalls; waylandcomp_jni.c) */ +void banner_on_clipboard_text(const char *utf8, int len); +void banner_on_text_input(int enabled, const char *program, int x, int y, int w, int h); + +/* ---- app → modules (callable from any thread; queued to the compositor thread) */ +void banner_host_clipboard_text(const char *utf8, int len); /* len 0 = clear */ +void banner_host_text_commit(const char *utf8, int len); +void banner_host_text_preedit(const char *utf8, int len, int cursor_begin, int cursor_end); +void banner_host_text_delete(int before, int after); +void banner_host_zero_copy(int on, int live); /* the drawer's zero-copy switch (ahb_swapchain_set_mode) */ +void banner_host_hdr_output(int on); /* the drawer's HDR output switch (banner_color_set_output) */ + +/* ---- module internals reached through the queue (banner_ext.c → modules) */ +void clipboard_init(struct wl_display *display); +void clipboard_host_text(char *utf8, size_t len); /* takes ownership of utf8 */ +void text_input_init(struct wl_display *display); +void text_input_host_commit(const char *utf8, size_t len); +void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end); +void text_input_host_delete(int before, int after); +void toplevel_icon_init(struct wl_display *display); diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c new file mode 100644 index 0000000000..291ec91fbc --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -0,0 +1,3264 @@ +/* + * bannerlator-wayland — the embedded compositor of the Wayland display path. + * + * Clients are the Wine processes of a container (winewayland.drv) and, through them, + * Mesa's Vulkan WSI. Each process is its own client, so a Windows virtual desktop is + * described with banner_desktop_v1: the desktop owner marks one surface as the desktop, + * and every process reports its top-level windows' desktop positions and the Windows + * stacking order. + * + * The scene is the desktop surface at the bottom, then every mapped xdg_toplevel at its + * reported position in stacking order, each with its subsurface tree (a game's Vulkan + * swapchain is a subsurface of its window) and wp_viewport crop/scale applied. It is + * redrawn once per event-loop pass after any commit or layout change, stretched to the + * Android surface. + * + * Input goes to the desktop surface in desktop coordinates: the Wine server routes it to + * the window under the pointer (or the focus window) in whichever process owns it, the + * same as winex11's virtual desktop. Without a desktop (a client that doesn't speak + * banner_desktop_v1) the topmost window under the pointer gets it. + */ +#define _GNU_SOURCE 1 +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdint.h> +#include <fcntl.h> +#include <time.h> +#include <stdarg.h> +#include <errno.h> +#include <sys/timerfd.h> +#include <sys/syscall.h> +#include <sys/sysmacros.h> +#include <android/log.h> +#include <wayland-server.h> + +#include "xdg-shell-server-protocol.h" +#include "linux-dmabuf-v1-server-protocol.h" +#include "sc_layer.h" +#include "ahb_swapchain.h" +#include "viewporter-server-protocol.h" +#include "banner-desktop-v1-server-protocol.h" +#include "presentation-time-server-protocol.h" +#include "pointer-constraints-unstable-v1-server-protocol.h" +#include "relative-pointer-unstable-v1-server-protocol.h" +#include "vk_present.h" +#include "framegen_bridge.h" +#include <pthread.h> +#include "effects_chain.h" +#include "banner_ext.h" +#include "banner_color.h" + +#define WLOGI(...) __android_log_print(ANDROID_LOG_INFO, "BannerWayland", __VA_ARGS__) +#define WLOGE(...) __android_log_print(ANDROID_LOG_ERROR, "BannerWayland", __VA_ARGS__) + +/* ------------------------------------------------------------------ session log + * One readable, time-stamped file per Wayland session in Download/Wayland-logs, also + * mirrored to logcat: which programs connect, the desktop, windows opening and closing, + * Vulkan frames arriving, a frame-rate summary every 10 seconds, and errors. */ + +#define SESSION_LOG_DIR "/storage/emulated/0/Download/Wayland-logs" + +static FILE *g_log; + +/* Lines logged before the session file exists are kept here and written into it, in order, the + * moment it opens — the compositor runs on its own thread, so anything the app reports as that + * thread starts (the display's HDR capability, for one) would otherwise only reach logcat. The + * lock also serialises the file writes, which now come from the app's threads too. */ +#define PRELOG_MAX 32 +static pthread_mutex_t g_log_lock = PTHREAD_MUTEX_INITIALIZER; +static char *g_prelog[PRELOG_MAX]; +static int g_prelog_n; + +void banner_log(const char *tag, const char *fmt, ...) { + char msg[512]; + va_list ap; + va_start(ap, fmt); + vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + WLOGI("[%s] %s", tag, msg); + struct timespec ts; + struct tm tm; + clock_gettime(CLOCK_REALTIME, &ts); + localtime_r(&ts.tv_sec, &tm); + char line[640]; + snprintf(line, sizeof(line), "%02d:%02d:%02d.%03ld %-9s %s\n", tm.tm_hour, tm.tm_min, tm.tm_sec, + ts.tv_nsec / 1000000, tag, msg); + pthread_mutex_lock(&g_log_lock); + if (g_log) fputs(line, g_log); + else if (g_prelog_n < PRELOG_MAX) g_prelog[g_prelog_n++] = strdup(line); + pthread_mutex_unlock(&g_log_lock); +} + +static void open_session_log(void) { + char path[256], stamp[32]; + time_t now = time(NULL); + struct tm tm; + FILE *f; + + localtime_r(&now, &tm); + strftime(stamp, sizeof(stamp), "%Y-%m-%d_%H-%M-%S", &tm); + mkdir("/storage/emulated/0/Download", 0775); + if (mkdir(SESSION_LOG_DIR, 0775) != 0 && errno != EEXIST) + WLOGE("can't create %s: %s", SESSION_LOG_DIR, strerror(errno)); + snprintf(path, sizeof(path), "%s/wayland-%s.log", SESSION_LOG_DIR, stamp); + if (!(f = fopen(path, "w"))) { + WLOGE("can't open session log %s: %s", path, strerror(errno)); + return; + } + setvbuf(f, NULL, _IOLBF, 0); + strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M:%S", &tm); + fprintf(f, + "Bannerlator Wayland session\n" + "===========================\n" + "Started %s\n" + "Display Wayland: Windows programs draw through the Bannerlator compositor.\n" + " No X server is used for this session.\n" + "Log %s\n\n" + "Time Area Event\n" + "------------ -------- -----------------------------------------------------\n", + stamp, path); + /* Publish the file and flush anything logged before it existed, in one critical section, so a + * line from another thread can never land ahead of the header or be dropped between the two. */ + pthread_mutex_lock(&g_log_lock); + for (int i = 0; i < g_prelog_n; i++) { fputs(g_prelog[i], f); free(g_prelog[i]); g_prelog[i] = NULL; } + g_prelog_n = 0; + g_log = f; + pthread_mutex_unlock(&g_log_lock); + WLOGI("session log: %s", path); +} + +/* At most ~10 lines a second for chatty events (window moves), so a drag can't flood logcat. */ +static int log_budget(void) { + static struct timespec window; + static int used; + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec != window.tv_sec) { window = now; used = 0; } + return used++ < 10; +} + +#ifndef BTN_LEFT +#define BTN_LEFT 0x110 /* linux/input-event-codes.h */ +#endif +#ifndef BTN_RIGHT +#define BTN_RIGHT 0x111 +#endif + +/* Java sends pointer coordinates in this space, covering the whole output surface. */ +#define INPUT_SPACE_W 1920 +#define INPUT_SPACE_H 1080 + +static struct wl_display *g_display; + +/* Which program each Wayland client is (from /proc/<pid>/cmdline), for the session log. */ +struct client_info { + struct wl_client *client; + struct wl_listener destroy; + pid_t pid; + char name[64]; + /* An OpenGL program whose EGL gave up on the GPU: it asked for dma-buf feedback (EGL's + * Wayland GPU path always does), never made a dma-buf buffer, and draws wl_shm frames. */ + unsigned asked_feedback : 1, shm_gl_said : 1; + unsigned dmabuf_buffers, shm_frames; + struct client_info *next; +}; +static struct client_info *g_clients; + +static struct client_info *client_info_of(struct wl_client *client) { + for (struct client_info *ci = g_clients; ci; ci = ci->next) + if (ci->client == client) return ci; + return NULL; +} + +static const char *client_name(struct wl_client *client) { + struct client_info *ci = client_info_of(client); + return ci ? ci->name : "a program"; +} + +static void on_client_destroyed(struct wl_listener *l, void *data) { + struct client_info *ci = wl_container_of(l, ci, destroy), **pp; + banner_log("program", "disconnected: %s (pid %d)", ci->name, (int)ci->pid); + banner_color_client_gone(ci->client); /* HDR summary for a program that presented HDR (gate open only) */ + for (pp = &g_clients; *pp; pp = &(*pp)->next) + if (*pp == ci) { *pp = ci->next; break; } + free(ci); +} + +static void on_client_created(struct wl_listener *l, void *data) { + struct wl_client *client = data; + struct client_info *ci = calloc(1, sizeof(*ci)); + char path[64], buf[256]; + uid_t uid; gid_t gid; + int fd; + ssize_t n; + + if (!ci) return; + ci->client = client; + wl_client_get_credentials(client, &ci->pid, &uid, &gid); + snprintf(ci->name, sizeof(ci->name), "pid %d", (int)ci->pid); + snprintf(path, sizeof(path), "/proc/%d/cmdline", (int)ci->pid); + if ((fd = open(path, O_RDONLY | O_CLOEXEC)) >= 0) { + if ((n = read(fd, buf, sizeof(buf) - 1)) > 0) { + char *base = buf, *p; + buf[n] = 0; /* argv[0] only; Wine puts the Windows program path there */ + for (p = buf; *p; p++) if (*p == '\\' || *p == '/') base = p + 1; + if (*base) snprintf(ci->name, sizeof(ci->name), "%s", base); + } + close(fd); + } + ci->destroy.notify = on_client_destroyed; + wl_client_add_destroy_listener(client, &ci->destroy); + ci->next = g_clients; + g_clients = ci; + banner_log("program", "connected over Wayland: %s (pid %d)", ci->name, (int)ci->pid); +} + +/* ------------------------------------------------------------------ surfaces */ + +enum surface_role { ROLE_NONE, ROLE_TOPLEVEL, ROLE_SUBSURFACE, ROLE_DESKTOP }; + +struct surface { + struct wl_resource *resource; + struct wl_list link; /* g_surfaces */ + + /* Pending state, applied on commit. */ + struct wl_resource *pending_buffer; + struct wl_listener pending_buffer_destroy; + int pending_attach; + int pending_src_set, pending_dst_set; + float pending_src[4]; /* x, y, w, h; w < 0 = unset */ + int pending_dst[2]; /* w, h; w < 0 = unset */ + struct wl_list pending_frames; + struct wl_list pending_feedback; /* wp_presentation feedback asked for before commit */ + + /* Current content. */ + struct vkp_image *shm_img; /* our copy of the last wl_shm buffer */ + struct wl_resource *dmabuf; /* current dmabuf wl_buffer (NULL once the client destroyed it) */ + struct dmabuf_buffer *dmabuf_buf; /* its imported image, kept until replaced or the surface goes */ + struct wl_listener dmabuf_destroy; + int buf_w, buf_h, has_content; + int src_set, dst_set; + float src[4]; + int dst[2]; + struct wl_list frames; /* frame callbacks for the next redraw */ + struct wl_list feedback; /* presentation feedback for the current content */ + int drawn; /* part of the last rendered scene */ + int64_t next_release_ns; /* FPS limiter: when this surface's last buffer goes back */ + int releases_pending; /* FPS limiter: buffers of this surface still to be released */ + + enum surface_role role; + struct wl_resource *xdg_surface, *xdg_toplevel; + struct wl_resource *viewport; + + /* Toplevel placement on the scene. */ + int mapped; /* in g_toplevels */ + struct wl_list toplevel_link; + int x, y, placed; + uint32_t hwnd; + + /* Subsurface tree. */ + struct surface *parent; + struct wl_resource *subsurface; + struct wl_list children; /* bottom to top */ + struct wl_list child_link; + int sub_x, sub_y, sub_pending_x, sub_pending_y, sub_pending; + int below_parent; + int fullscreen; /* xdg_toplevel.set_fullscreen: no client decorations */ + + char *title; /* xdg_toplevel title, for the session log */ + int announced_vulkan; /* logged its first dmabuf frame */ + uint32_t hdr_fmt_logged; /* HDR session: the buffer format last named in the log */ +}; + +static struct wl_list g_surfaces; /* every surface */ +static struct wl_list g_toplevels; /* mapped toplevels, bottom to top */ +static struct surface *g_desktop; +static uint32_t *g_zorder; /* last reported Windows stacking order, top first */ +static size_t g_zorder_count; +static struct wl_event_source *g_render_idle, *g_frame_timer; + +/* Rendering is driven by the screen's vsync (Java's Choreographer ticks, nativeVsync): one scene + * per refresh showing the newest buffers, so the event loop is never parked in the swapchain and + * clients get their buffers back as soon as they're replaced. Without ticks (an older app, no + * window) a fallback timer renders instead. */ +static int g_dirty; /* something changed since the last render */ +static int64_t g_last_vsync_ns; /* last tick, 0 = none yet */ +static int64_t g_refresh_ns = 16666667; /* measured tick interval (pacing only, never reported) */ +static struct wl_event_source *g_fallback_timer; +static int g_fallback_armed; + +/* FPS limiter (the in-game drawer's): frames per second, 0 = unlimited. Set from the app thread, + * read here. Like the X11 path, which delays the "your buffer is free" notice, the limit paces + * when a replaced buffer is released to its client, so the game itself slows to the cap. */ +volatile int g_fps_limit; + +/* Shortcut launches: explorer's windows (the desktop, taskbar, Start menu) aren't drawn, matching + * the X11 renderer's unviewable "explorer.exe". They still exist for input routing. */ +volatile int g_hide_shell; + +/* Experimental layer mode (BANNER_WAYLAND_ZERO_COPY=1 in the container's environment): a single + * fullscreen window is shown on its own Android layer (sc_layer.c) instead of being blitted into the + * screen swapchain. Set from the app before the compositor starts; read per frame. */ +volatile int g_zero_copy; +static int g_zero_copy_paused; /* effects hold the layer path off (render_scene) */ +static int g_zero_copy_fx_skip_said; + +/* Compressed (UBWC) game buffers: zwp_linux_dmabuf_v1 advertises DRM_FORMAT_MOD_QCOM_COMPRESSED next + * to LINEAR for every format the renderer's own driver can import that way, so Turnip's Wayland WSI + * in the game allocates UBWC swapchain images instead of resolving each frame to a linear copy. + * BANNER_WAYLAND_UBWC=0 in the container's environment turns the advertisement off (A/B switch). Set + * from the app before the compositor starts; read at every zwp_linux_dmabuf_v1 bind. */ +volatile int g_ubwc = 1; + +/* Debug (BANNER_WAYLAND_NO_RENDER_NODE=1): name no DRM device in the dma-buf feedback, as a phone + * that exposes no /dev/dri node to apps does, to reproduce its OpenGL path here. Set from the app + * before the compositor starts. */ +volatile int g_no_render_node; + +/* The panel's refresh rate in mHz, from the app; wl_output advertises it so Wine's display modes + * carry the real rate (games pick their saved 144 Hz mode, as on X11). 0 = 60 Hz. */ +volatile int g_output_refresh_mhz; + +/* The advertised output size: the container's screen (what the app's X server reports on X11), + * so Wine's display-mode list stops at the desktop size. 0 = 1920x1080. */ +volatile int g_output_w, g_output_h; +struct pending_release { + struct wl_resource *buffer; + struct wl_listener destroy; + struct surface *surface; /* NULL once the surface is gone */ + int64_t at_ns; + int64_t since_ns; /* when the compositor let go of it (the perf line) */ + struct wl_list link; +}; +static struct wl_list g_pending_releases; +static int g_release_timer_fd = -1; +static struct wl_event_source *g_release_source; +static int g_scene_w, g_scene_h; /* size of the last drawn scene */ +static int g_desktop_w, g_desktop_h; /* last size the desktop had content at */ +static unsigned g_stat_frames, g_stat_dmabuf, g_stat_shm; /* since the last 10 s summary */ + +/* The 10 s `perf` line (on_stats_timer): where the compositor thread's time goes and how long games + * wait for their buffers back. The driver-side times (acquire, present, fence waits) are counted in + * vk_present.c (vkp_perf_take). Compositor thread only. */ +static struct { + unsigned ticks; /* screen refreshes (Choreographer ticks) */ + unsigned scenes; /* render_scene() calls ... */ + int64_t scene_ns, scene_max_ns; /* ... and their wall time */ + unsigned copy_scenes; /* scenes drawn into the screen swapchain (the copy path) */ + unsigned releases, releases_held; /* wl_buffer.release after a replacement; held = 1 ms or more */ + int64_t release_ns, release_max_ns; /* replaced (or taken off the layer) -> released to the game */ +} g_perf; + +static void schedule_render(void); + +static int64_t now_ns(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +/* A game got a replaced buffer back; since_ns = when the compositor let go of it (0 = not counted). */ +static void perf_note_release(int64_t since_ns) { + if (since_ns <= 0) return; + int64_t d = now_ns() - since_ns; + if (d < 0) d = 0; + g_perf.releases++; + g_perf.release_ns += d; + if (d > g_perf.release_max_ns) g_perf.release_max_ns = d; + if (d >= 1000000LL) g_perf.releases_held++; +} + +/* ------------------------------------------------------------------ buffer release pacing */ + +static void pending_release_free(struct pending_release *pr) { + if (pr->surface && pr->surface->releases_pending > 0) pr->surface->releases_pending--; + wl_list_remove(&pr->destroy.link); + wl_list_remove(&pr->link); + free(pr); +} + +/* A surface is going away: its queued releases still go out on time, they just stop counting. */ +static void pending_releases_forget_surface(struct surface *s) { + struct pending_release *pr; + wl_list_for_each(pr, &g_pending_releases, link) + if (pr->surface == s) pr->surface = NULL; +} + +static void on_pending_release_buffer_destroyed(struct wl_listener *l, void *data) { + struct pending_release *pr = wl_container_of(l, pr, destroy); + pending_release_free(pr); +} + +static void arm_release_timer(void) { + struct pending_release *pr; + int64_t earliest = 0; + if (g_release_timer_fd < 0) return; + wl_list_for_each(pr, &g_pending_releases, link) + if (!earliest || pr->at_ns < earliest) earliest = pr->at_ns; + struct itimerspec its = {0}; + if (earliest) { its.it_value.tv_sec = earliest / 1000000000LL; its.it_value.tv_nsec = earliest % 1000000000LL; } + timerfd_settime(g_release_timer_fd, TFD_TIMER_ABSTIME, &its, NULL); +} + +static int on_release_timer(int fd, uint32_t mask, void *data) { + struct pending_release *pr, *tmp; + uint64_t expirations; + int64_t now = now_ns() + 300000; /* anything due within 0.3 ms goes now */ + if (read(fd, &expirations, sizeof(expirations)) < 0 && errno != EAGAIN) return 0; + wl_list_for_each_safe(pr, tmp, &g_pending_releases, link) { + if (pr->at_ns <= now) { + wl_buffer_send_release(pr->buffer); + perf_note_release(pr->since_ns); + pending_release_free(pr); + } + } + wl_display_flush_clients(g_display); + arm_release_timer(); + return 0; +} + +/* Give a replaced buffer back to its client: now, or on the limiter's cadence. + * + * Each release takes the next slot of a per-surface cadence (one slot per interval), so a game + * gets one buffer back per interval however fast it commits. The schedule is kept honest at both + * ends: a slot in the past is brought to now (the game was slower than the cap, no catch-up burst + * is owed), and it never runs further ahead than the releases actually queued — with p releases + * still pending the new one lands at most (p + 1) intervals out, nothing pending means at most + * one interval. Without that bound the schedule kept slots that were consumed but never + * delivered (a swapchain rebuild destroys buffers with queued releases) or that a coarser earlier + * limit had spaced out, and the game's first frames after that waited on empty slots. */ +static void release_buffer(struct surface *s, struct wl_resource *buffer, int64_t since_ns) { + int limit = g_fps_limit; + if (limit <= 0 || g_release_timer_fd < 0) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } + int64_t interval = 1000000000LL / limit, now = now_ns(); + int64_t at = s->next_release_ns + interval; + int64_t latest = now + interval * (int64_t)(s->releases_pending + 1); + if (at < now) at = now; + if (at > latest) at = latest; + s->next_release_ns = at; + struct pending_release *pr = calloc(1, sizeof(*pr)); + if (!pr) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } + pr->buffer = buffer; + pr->surface = s; + pr->at_ns = at; + pr->since_ns = since_ns; + pr->destroy.notify = on_pending_release_buffer_destroyed; + wl_resource_add_destroy_listener(buffer, &pr->destroy); + wl_list_insert(g_pending_releases.prev, &pr->link); + s->releases_pending++; + arm_release_timer(); +} + +/* ------------------------------------------------------------------ seat state */ + +/* Each Wine process is a separate client with its own wl_pointer / wl_keyboard. */ +struct seat_pointer { struct wl_resource *ptr; struct wl_resource *focus; }; +struct seat_keyboard { struct wl_resource *kb; struct wl_resource *focus; }; +#define MAX_PTRS 32 +static struct seat_pointer g_ptrs[MAX_PTRS]; +static int g_nptrs; +static struct seat_keyboard g_kbs[MAX_PTRS]; +static int g_nkbs; +static struct surface *g_grab; /* no-desktop fallback: surface holding the button */ +static struct surface *g_key_target; /* no-desktop fallback: last clicked surface */ +static struct surface *g_ime_click; /* last clicked program window: where text input goes */ +static int g_input_pipe[2] = {-1, -1}; +/* type 0 = pointer (p1=action 0down/1move/2up, p2=x, p3=y); type 1 = key (p1=evdev, p2=state 1down/0up) */ +struct input_msg { int type; int p1; int p2; int p3; }; + +/* Pointer constraints (zwp_pointer_constraints_v1) and relative pointers + * (zwp_relative_pointer_manager_v1); see the "pointer constraints" section. */ +struct surface; +static void constraints_surface_gone(struct surface *s); +static void constraints_surface_commit(struct surface *s); +static void constraints_pointer_gone(struct wl_resource *pointer); +static void relative_pointers_pointer_gone(struct wl_resource *pointer); +static void constraints_focus_entered(struct wl_resource *target, struct wl_client *client); + +/* ------------------------------------------------------------------ dmabuf buffers */ + +#define FOURCC(a, b, c, d) \ + ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) +#define DRM_ARGB8888 FOURCC('A', 'R', '2', '4') +#define DRM_XRGB8888 FOURCC('X', 'R', '2', '4') +#define DRM_ABGR8888 FOURCC('A', 'B', '2', '4') +#define DRM_XBGR8888 FOURCC('X', 'B', '2', '4') +#define MOD_LINEAR VKP_MOD_LINEAR +#define MOD_INVALID VKP_MOD_INVALID +#define MAX_PLANES 4 + +struct dmabuf_params { + int fd[MAX_PLANES]; + uint32_t offset[MAX_PLANES], stride[MAX_PLANES]; + uint64_t modifier[MAX_PLANES]; + int n_planes; +}; +struct dmabuf_buffer { + int fd[MAX_PLANES]; + uint32_t offset[MAX_PLANES], stride[MAX_PLANES]; + int n_planes; + int32_t width, height; + uint32_t format; + uint64_t modifier; + struct vkp_image *img; /* imported once, reused for every frame */ + int import_failed; + /* One reference for the wl_buffer resource, one per surface showing the buffer. Mesa destroys + * a swapchain's wl_buffers the moment the game rebuilds its swapchain, i.e. while the last + * committed one is still what is on screen: the import (and the dma-buf memory it pins) stays + * until the surface commits something newer, so the picture never blinks to black. */ + int refs; + void *ahb_state; /* zero-copy: ahb_swapchain.c's record (the game's AHardwareBuffer) */ +}; + +static void dmabuf_buffer_unref(struct dmabuf_buffer *b) { + if (!b || --b->refs > 0) return; + vkp_image_destroy(b->img); + for (int i = 0; i < b->n_planes; i++) + if (b->fd[i] >= 0) close(b->fd[i]); + free(b); +} + +static void dbuf_buffer_destroy_req(struct wl_client *c, struct wl_resource *r) { + wl_resource_destroy(r); +} +static const struct wl_buffer_interface dbuf_buffer_impl = { + .destroy = dbuf_buffer_destroy_req, +}; + +static struct dmabuf_buffer *get_dmabuf(struct wl_resource *buffer) { + if (buffer && wl_resource_instance_of(buffer, &wl_buffer_interface, &dbuf_buffer_impl)) + return wl_resource_get_user_data(buffer); + return NULL; +} + +/* ------------------------------------------------------------------ surface state */ + +static void surface_size(const struct surface *s, int *w, int *h) { + if (s->dst_set) { *w = s->dst[0]; *h = s->dst[1]; } + else if (s->src_set) { *w = (int)(s->src[2] + 0.5f); *h = (int)(s->src[3] + 0.5f); } + else { *w = s->buf_w; *h = s->buf_h; } +} + +/* "Title" (program) for the log; subsurfaces are named after the window they belong to. */ +static void describe(const struct surface *s, char *out, size_t size) { + const struct surface *w = s; + while (w->parent) w = w->parent; + const char *prog = client_name(wl_resource_get_client(w->resource)); + if (w->title && *w->title) snprintf(out, size, "\"%s\" (%s)", w->title, prog); + else if (w->role == ROLE_DESKTOP) snprintf(out, size, "the desktop (%s)", prog); + else snprintf(out, size, "window %#x (%s)", w->hwnd, prog); +} + +static struct surface *toplevel_by_hwnd(uint32_t hwnd) { + struct surface *s; + wl_list_for_each(s, &g_toplevels, toplevel_link) + if (s->hwnd == hwnd) return s; + return NULL; +} + +/* Reorder the mapped toplevels to match the last reported Windows z-order. Windows the + * report doesn't mention keep their relative order below the ones it does. */ +static void apply_zorder(void) { + for (size_t i = g_zorder_count; i-- > 0;) { + struct surface *s = toplevel_by_hwnd(g_zorder[i]); + if (!s) continue; + wl_list_remove(&s->toplevel_link); + wl_list_insert(g_toplevels.prev, &s->toplevel_link); + } +} + +static void map_toplevel(struct surface *s) { + int w, h; + if (s->mapped) return; + s->mapped = 1; + surface_size(s, &w, &h); + { + char name[160]; + describe(s, name, sizeof(name)); + banner_log("window", "opened %s %dx%d at %d,%d%s", name, w, h, s->x, s->y, + s->placed ? "" : " (no desktop position yet)"); + } + wl_list_insert(g_toplevels.prev, &s->toplevel_link); /* new windows start on top */ + apply_zorder(); +} + +static void unmap_toplevel(struct surface *s) { + if (!s->mapped) return; + s->mapped = 0; + { + char name[160]; + describe(s, name, sizeof(name)); + banner_log("window", "closed %s", name); + } + wl_list_remove(&s->toplevel_link); + wl_list_init(&s->toplevel_link); + if (g_ime_click == s) g_ime_click = NULL; + banner_text_input_refocus(); +} + +/* Let go of the surface's dmabuf content. paced = 1: the buffer was replaced, give it back on the + * limiter's cadence; paced = 0: the surface is going away, give it back at once (a buffer of a + * destroyed surface is not shown again and must not sit unreleased with the client). */ +static void drop_dmabuf(struct surface *s, int paced) { + if (s->dmabuf) { + wl_list_remove(&s->dmabuf_destroy.link); + /* A buffer on the zero-copy layer is the display's until SurfaceFlinger says otherwise: + * ahb_swapchain.c releases it then. */ + if (!ahb_swapchain_defer_release(s->dmabuf_buf, s->dmabuf, s, paced)) { + if (paced) release_buffer(s, s->dmabuf, now_ns()); + else wl_buffer_send_release(s->dmabuf); + } + s->dmabuf = NULL; + } + dmabuf_buffer_unref(s->dmabuf_buf); + s->dmabuf_buf = NULL; +} + +/* The client destroyed the wl_buffer we are showing (a swapchain rebuild): keep showing its + * image (s->dmabuf_buf holds it) until the next commit replaces it; only the resource is gone. */ +static void on_dmabuf_destroyed(struct wl_listener *l, void *data) { + struct surface *s = wl_container_of(l, s, dmabuf_destroy); + wl_list_remove(&s->dmabuf_destroy.link); + s->dmabuf = NULL; +} + +static void on_pending_buffer_destroyed(struct wl_listener *l, void *data) { + struct surface *s = wl_container_of(l, s, pending_buffer_destroy); + wl_list_remove(&s->pending_buffer_destroy.link); + wl_list_init(&s->pending_buffer_destroy.link); + s->pending_buffer = NULL; +} + +static void fire_frames(struct wl_list *frames) { + struct wl_resource *cb, *tmp; + uint32_t t; + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + t = (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); + wl_resource_for_each_safe(cb, tmp, frames) { + wl_callback_send_done(cb, t); + wl_resource_destroy(cb); + } +} + +/* Copy a committed wl_shm buffer into the surface's image and release the buffer. */ +static void take_shm(struct surface *s, struct wl_shm_buffer *shm, struct wl_resource *buffer) { + int32_t w = wl_shm_buffer_get_width(shm), h = wl_shm_buffer_get_height(shm); + int32_t stride = wl_shm_buffer_get_stride(shm); + + if (s->shm_img && (vkp_image_width(s->shm_img) != w || vkp_image_height(s->shm_img) != h)) { + vkp_image_destroy(s->shm_img); + s->shm_img = NULL; + } + if (!s->shm_img) s->shm_img = vkp_image_create_shm(w, h); + if (s->shm_img) { + wl_shm_buffer_begin_access(shm); + vkp_image_upload_shm(s->shm_img, wl_shm_buffer_get_data(shm), stride); + wl_shm_buffer_end_access(shm); + } + wl_buffer_send_release(buffer); + s->buf_w = w; + s->buf_h = h; + s->has_content = s->shm_img != NULL; + g_stat_shm++; + struct client_info *ci = client_info_of(wl_resource_get_client(s->resource)); + if (ci && ci->asked_feedback) ci->shm_frames++; /* since it asked for GPU buffers */ +} + +/* The window the app's performance HUD follows: the latest one to start presenting GPU frames + * (X11 binds the HUD to the _MESA_DRV window and counts X presents instead). JNI upcalls. */ +static struct surface *g_hud_surface; +extern void banner_on_game_surface(const char *window, const char *gpu); /* window NULL = gone */ +extern void banner_on_game_frame(void); +/* The program behind that window: its Linux pid (the Wayland client's credentials) and executable name + * ("" when /proc gave none) - the app arms its CPU affinity on it (X11 does that from window events). */ +extern void banner_on_game_program(int pid, const char *program); + +static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_resource *buffer) { + if (s->dmabuf != buffer || s->dmabuf_buf != b) { + drop_dmabuf(s, 1); + s->dmabuf = buffer; + s->dmabuf_buf = b; + b->refs++; + s->dmabuf_destroy.notify = on_dmabuf_destroyed; + wl_resource_add_destroy_listener(buffer, &s->dmabuf_destroy); + } + if (!b->img && !b->import_failed && b->n_planes >= 1) { + b->img = vkp_image_from_dmabuf(b->fd[0], b->format, b->modifier, b->width, b->height, + b->stride[0], b->offset[0]); + if (b->img && g_zero_copy) sc_layer_probe_dmabuf_fd(b->fd[0]); + if (!b->img) { + b->import_failed = 1; + WLOGE("dmabuf import failed (%dx%d fmt=0x%08x mod=0x%llx)", b->width, b->height, + b->format, (unsigned long long)b->modifier); + } + } + if (s->shm_img) { vkp_image_destroy(s->shm_img); s->shm_img = NULL; } + s->buf_w = b->width; + s->buf_h = b->height; + s->has_content = b->img != NULL; + g_stat_dmabuf++; + if (!s->announced_vulkan) { + char name[160]; + s->announced_vulkan = 1; + describe(s, name, sizeof(name)); + if (b->img) + /* Imported for the copy path. Whether its frames ALSO go on the display layer without a copy + * is decided per frame (fullscreen, zero-copy on) and counted in the 10 s lines. */ + banner_log("vulkan", "%s is presenting GPU frames through Wayland: %dx%d, format %c%c%c%c, %s (%s)", + name, b->width, b->height, b->format & 0xff, (b->format >> 8) & 0xff, + (b->format >> 16) & 0xff, (b->format >> 24) & 0xff, + vkp_modifier_name(b->modifier), + ahb_swapchain_has_ahb(b) ? "gralloc buffers: can go on the display layer without a copy" + : "dma-buf: copied into the screen swapchain"); + else if (ahb_swapchain_has_ahb(b)) + banner_log("vulkan", "%s is presenting GPU frames through Wayland: %dx%d on its own display layer only " + "(gralloc buffers the compositor cannot import for the copy path)", + name, b->width, b->height); + else + banner_log("error", "could not import GPU frames from %s (%dx%d, modifier %#llx)", + name, b->width, b->height, (unsigned long long)b->modifier); + /* The HUD follows the window whether its frames are copied or go straight to the layer: + * a zero-copy frame the compositor never imported is still a presented game frame. */ + if (b->img || ahb_swapchain_has_ahb(b)) { + g_hud_surface = s; + banner_on_game_surface(name, vkp_gpu_name()); + struct client_info *ci = client_info_of(wl_resource_get_client(s->resource)); + if (ci) banner_on_game_program((int)ci->pid, strncmp(ci->name, "pid ", 4) ? ci->name : ""); + } + } + /* HDR session (gate open): a DXVK game switches to HDR by REBUILDING its swapchain on the same + * surface, so the one-shot line above never sees the 10-bit buffers - name every format change. */ + if (b->format != s->hdr_fmt_logged && banner_color_hdr_open()) { + char name[160]; + uint32_t af = ahb_swapchain_ahb_format(b); + int ten = b->format == FOURCC('A', 'B', '3', '0') || b->format == FOURCC('X', 'B', '3', '0'); + describe(s, name, sizeof(name)); + banner_log("color", "%s presents %dx%d buffers in %c%c%c%c (%s), %s%s%s; %s", name, b->width, b->height, + b->format & 0xff, (b->format >> 8) & 0xff, (b->format >> 16) & 0xff, (b->format >> 24) & 0xff, + ten ? "10-bit A2B10G10R10" : "8-bit", vkp_modifier_name(b->modifier), + af ? ", gralloc " : ", no gralloc buffer (copy path only)", af ? banner_ahb_format_name(af) : "", + b->img ? "the compositor imported it" + : af ? "the compositor's driver could NOT import it (display layer only, fullscreen)" + : "the compositor's driver could NOT import it (nothing can show it)"); + s->hdr_fmt_logged = b->format; + } + /* Every buffer that reaches take_dmabuf is a presented GPU frame, so the HUD counts it. + * Asking whether the compositor could import it, as this used to, is a question about the + * copy path and not about whether a frame happened: a game whose buffers go straight to + * the display layer draws on screen while the counter sat at 0.0 fps and 1000.0 ms. */ + if (s == g_hud_surface) banner_on_game_frame(); +} + +/* ---- hooks for ahb_swapchain.c (zero-copy layers) */ +struct dmabuf_buffer *banner_dmabuf_from_resource(struct wl_resource *buffer) { return get_dmabuf(buffer); } +int banner_dmabuf_fd(const struct dmabuf_buffer *b) { return b && b->n_planes > 0 ? b->fd[0] : -1; } +void banner_dmabuf_size(const struct dmabuf_buffer *b, int *w, int *h) { *w = b->width; *h = b->height; } +void **banner_dmabuf_ahb_slot(struct dmabuf_buffer *b) { return &b->ahb_state; } +void banner_dmabuf_ref(struct dmabuf_buffer *b) { b->refs++; } +void banner_dmabuf_unref(struct dmabuf_buffer *b) { dmabuf_buffer_unref(b); } +void banner_release_buffer(struct surface *s, struct wl_resource *buffer, int paced, int64_t since_ns) { + if (paced && s) release_buffer(s, buffer, since_ns); + else { wl_buffer_send_release(buffer); perf_note_release(since_ns); } +} +void banner_surface_describe(const struct surface *s, char *out, size_t size) { describe(s, out, size); } +const struct banner_color *banner_surface_color(const struct surface *s) { + return s ? banner_color_of(s->resource) : NULL; +} + +/* ------------------------------------------------------------------ wl_surface */ + +static void surface_destroy(struct wl_client *c, struct wl_resource *r) { + wl_resource_destroy(r); +} +static void surface_attach(struct wl_client *c, struct wl_resource *r, + struct wl_resource *buffer, int32_t x, int32_t y) { + struct surface *s = wl_resource_get_user_data(r); + if (s->pending_buffer) wl_list_remove(&s->pending_buffer_destroy.link); + wl_list_init(&s->pending_buffer_destroy.link); + s->pending_buffer = buffer; + s->pending_attach = 1; + if (buffer) { + s->pending_buffer_destroy.notify = on_pending_buffer_destroyed; + wl_resource_add_destroy_listener(buffer, &s->pending_buffer_destroy); + } +} +static void surface_damage(struct wl_client *c, struct wl_resource *r, + int32_t x, int32_t y, int32_t w, int32_t h) {} +static void frame_callback_destroy(struct wl_resource *r) { + wl_list_remove(wl_resource_get_link(r)); +} + +/* wp_presentation: tells Mesa's Vulkan driver when a frame reached the screen or was replaced + * before it did. Without it the driver waits for a frame callback (one per refresh) for every + * frame, which paced games to the screen rate even in mailbox mode. */ +static void feedback_resource_destroy(struct wl_resource *r) { + wl_list_remove(wl_resource_get_link(r)); +} + +static void feedback_discard_all(struct wl_list *list) { + struct wl_resource *fb, *tmp; + wl_resource_for_each_safe(fb, tmp, list) { + wp_presentation_feedback_send_discarded(fb); + wl_resource_destroy(fb); + } +} + +/* The current mode's refresh interval in ns, from the rate the app read off the display. */ +static uint32_t nominal_refresh_ns(void) { + int mhz = g_output_refresh_mhz; + if (mhz <= 0) mhz = 60000; + return (uint32_t)(1000000000000LL / (int64_t)mhz); +} + +static void feedback_present_all(struct wl_list *list, int64_t t) { + struct wl_resource *fb, *tmp; + uint64_t sec = (uint64_t)(t / 1000000000LL); + uint32_t nsec = (uint32_t)(t % 1000000000LL); + wl_resource_for_each_safe(fb, tmp, list) { + /* The protocol's "refresh" is the NOMINAL interval of the current mode, a constant - not + * the interval this frame happened to take. Reporting the measured average instead makes a + * variable-refresh panel look like a mode change on every frame: gamescope re-derives its + * pacing each time ("Changed refresh to: 119.2 ... 121.4hz", 826 times in a minute on a + * Galaxy Z Fold, none on a fixed-refresh device). Report the panel's rate, which the app + * gives us and wl_output already advertises. */ + wp_presentation_feedback_send_presented(fb, (uint32_t)(sec >> 32), (uint32_t)sec, nsec, + nominal_refresh_ns(), 0, 0, + WP_PRESENTATION_FEEDBACK_KIND_VSYNC); + wl_resource_destroy(fb); + } +} + +static void presentation_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void presentation_feedback(struct wl_client *c, struct wl_resource *r, + struct wl_resource *surface, uint32_t id) { + struct surface *s = wl_resource_get_user_data(surface); + struct wl_resource *fb = wl_resource_create(c, &wp_presentation_feedback_interface, + wl_resource_get_version(r), id); + if (!fb) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(fb, NULL, NULL, feedback_resource_destroy); + if (!s) { wp_presentation_feedback_send_discarded(fb); wl_resource_destroy(fb); return; } + wl_list_insert(s->pending_feedback.prev, wl_resource_get_link(fb)); +} +static const struct wp_presentation_interface presentation_impl = { + .destroy = presentation_destroy, + .feedback = presentation_feedback, +}; +static void bind_presentation(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wp_presentation_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &presentation_impl, NULL, NULL); + wp_presentation_send_clock_id(r, CLOCK_MONOTONIC); +} +static void surface_frame(struct wl_client *c, struct wl_resource *r, uint32_t cb) { + struct surface *s = wl_resource_get_user_data(r); + struct wl_resource *callback = wl_resource_create(c, &wl_callback_interface, 1, cb); + if (!callback) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(callback, NULL, NULL, frame_callback_destroy); + wl_list_insert(s->pending_frames.prev, wl_resource_get_link(callback)); +} +static void surface_set_opaque(struct wl_client *c, struct wl_resource *r, + struct wl_resource *region) {} +static void surface_set_input(struct wl_client *c, struct wl_resource *r, + struct wl_resource *region) {} + +static void surface_commit(struct wl_client *c, struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + struct surface *child; + + if (s->pending_src_set) { + s->src_set = s->pending_src[2] > 0; + memcpy(s->src, s->pending_src, sizeof(s->src)); + s->pending_src_set = 0; + } + if (s->pending_dst_set) { + s->dst_set = s->pending_dst[0] > 0; + memcpy(s->dst, s->pending_dst, sizeof(s->dst)); + s->pending_dst_set = 0; + } + + if (s->pending_attach) { + struct wl_resource *buffer = s->pending_buffer; + struct dmabuf_buffer *db = get_dmabuf(buffer); + struct wl_shm_buffer *shm = buffer && !db ? wl_shm_buffer_get(buffer) : NULL; + + /* The previous content is replaced before reaching the screen. */ + feedback_discard_all(&s->feedback); + + if (buffer) { + wl_list_remove(&s->pending_buffer_destroy.link); + wl_list_init(&s->pending_buffer_destroy.link); + } + s->pending_buffer = NULL; + s->pending_attach = 0; + + if (s->role == ROLE_NONE) { + /* Cursor or role-less surface: never drawn (the app draws its own pointer). */ + if (buffer) wl_buffer_send_release(buffer); + } else if (db) { + take_dmabuf(s, db, buffer); + } else if (shm) { + drop_dmabuf(s, 1); + take_shm(s, shm, buffer); + } else { + drop_dmabuf(s, 1); + s->has_content = 0; + if (buffer) wl_buffer_send_release(buffer); + } + } + + /* Subsurface positions are applied when the parent commits. */ + wl_list_for_each(child, &s->children, child_link) { + if (child->sub_pending) { + child->sub_x = child->sub_pending_x; + child->sub_y = child->sub_pending_y; + child->sub_pending = 0; + } + } + + wl_list_insert_list(s->frames.prev, &s->pending_frames); + wl_list_init(&s->pending_frames); + wl_list_insert_list(s->feedback.prev, &s->pending_feedback); + wl_list_init(&s->pending_feedback); + constraints_surface_commit(s); + banner_color_commit(s->resource); /* wp_color_management_surface_v1 state (returns at once when HDR is off) */ + + if (s->role == ROLE_TOPLEVEL && s->xdg_toplevel) { + if (s->has_content) map_toplevel(s); + else unmap_toplevel(s); + } + schedule_render(); +} +static void surface_set_buffer_transform(struct wl_client *c, struct wl_resource *r, int32_t t) {} +static void surface_set_buffer_scale(struct wl_client *c, struct wl_resource *r, int32_t s) {} +static void surface_damage_buffer(struct wl_client *c, struct wl_resource *r, + int32_t x, int32_t y, int32_t w, int32_t h) {} +static void surface_offset(struct wl_client *c, struct wl_resource *r, int32_t x, int32_t y) {} + +static const struct wl_surface_interface surface_impl = { + .destroy = surface_destroy, + .attach = surface_attach, + .damage = surface_damage, + .frame = surface_frame, + .set_opaque_region = surface_set_opaque, + .set_input_region = surface_set_input, + .commit = surface_commit, + .set_buffer_transform = surface_set_buffer_transform, + .set_buffer_scale = surface_set_buffer_scale, + .damage_buffer = surface_damage_buffer, + .offset = surface_offset, +}; + +static void detach_from_parent(struct surface *s) { + if (!s->parent) return; + wl_list_remove(&s->child_link); + wl_list_init(&s->child_link); + s->parent = NULL; +} + +static void surface_resource_destroy(struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + struct surface *child, *tmp; + struct wl_resource *cb, *cbtmp; + + if (!s) return; + for (int i = 0; i < g_nptrs; i++) if (g_ptrs[i].focus == r) g_ptrs[i].focus = NULL; + for (int i = 0; i < g_nkbs; i++) if (g_kbs[i].focus == r) g_kbs[i].focus = NULL; + if (g_grab == s) g_grab = NULL; + if (g_key_target == s) g_key_target = NULL; + if (g_ime_click == s) g_ime_click = NULL; + banner_text_input_surface_gone(r); + if (g_desktop == s) { g_desktop = NULL; banner_log("desktop", "the desktop closed"); } + if (g_hud_surface == s) { g_hud_surface = NULL; banner_on_game_surface(NULL, NULL); } + constraints_surface_gone(s); + + unmap_toplevel(s); + detach_from_parent(s); + wl_list_for_each_safe(child, tmp, &s->children, child_link) { + wl_list_remove(&child->child_link); + wl_list_init(&child->child_link); + child->parent = NULL; + } + if (s->pending_buffer) wl_list_remove(&s->pending_buffer_destroy.link); + pending_releases_forget_surface(s); + drop_dmabuf(s, 0); + ahb_swapchain_surface_gone(s); + vkp_image_destroy(s->shm_img); + wl_resource_for_each_safe(cb, cbtmp, &s->pending_frames) wl_resource_destroy(cb); + wl_resource_for_each_safe(cb, cbtmp, &s->frames) wl_resource_destroy(cb); + feedback_discard_all(&s->pending_feedback); + feedback_discard_all(&s->feedback); + if (s->viewport) wl_resource_set_user_data(s->viewport, NULL); + if (s->subsurface) wl_resource_set_user_data(s->subsurface, NULL); + if (s->xdg_surface) wl_resource_set_user_data(s->xdg_surface, NULL); + if (s->xdg_toplevel) wl_resource_set_user_data(s->xdg_toplevel, NULL); + wl_list_remove(&s->link); + free(s->title); + free(s); + schedule_render(); +} + +/* ------------------------------------------------------------------ wl_region */ + +/* A region is kept as the bounding box of its rectangles: enough for pointer confinement, + * where winewayland sends one rectangle (the ClipCursor area). Subtractions are ignored. */ +struct region { int set; int x, y, w, h; }; + +static void region_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void region_add(struct wl_client *c, struct wl_resource *r, + int32_t x, int32_t y, int32_t w, int32_t h) { + struct region *rg = wl_resource_get_user_data(r); + if (!rg || w <= 0 || h <= 0) return; + if (!rg->set) { rg->x = x; rg->y = y; rg->w = w; rg->h = h; rg->set = 1; return; } + int x2 = rg->x + rg->w > x + w ? rg->x + rg->w : x + w; + int y2 = rg->y + rg->h > y + h ? rg->y + rg->h : y + h; + if (x < rg->x) rg->x = x; + if (y < rg->y) rg->y = y; + rg->w = x2 - rg->x; rg->h = y2 - rg->y; +} +static void region_subtract(struct wl_client *c, struct wl_resource *r, + int32_t x, int32_t y, int32_t w, int32_t h) {} +static void region_resource_destroy(struct wl_resource *r) { free(wl_resource_get_user_data(r)); } +static const struct wl_region_interface region_impl = { + .destroy = region_destroy, + .add = region_add, + .subtract = region_subtract, +}; + +/* ------------------------------------------------------------------ wl_compositor */ + +static void compositor_create_surface(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct surface *s = calloc(1, sizeof(*s)); + if (!s) { wl_client_post_no_memory(c); return; } + s->resource = wl_resource_create(c, &wl_surface_interface, wl_resource_get_version(r), id); + if (!s->resource) { free(s); wl_client_post_no_memory(c); return; } + wl_list_init(&s->pending_frames); + wl_list_init(&s->frames); + wl_list_init(&s->pending_feedback); + wl_list_init(&s->feedback); + wl_list_init(&s->children); + wl_list_init(&s->child_link); + wl_list_init(&s->toplevel_link); + wl_list_init(&s->pending_buffer_destroy.link); + wl_list_insert(&g_surfaces, &s->link); + wl_resource_set_implementation(s->resource, &surface_impl, s, surface_resource_destroy); +} +static void compositor_create_region(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *reg = wl_resource_create(c, &wl_region_interface, 1, id); + if (!reg) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(reg, ®ion_impl, calloc(1, sizeof(struct region)), + region_resource_destroy); +} +static const struct wl_compositor_interface compositor_impl = { + .create_surface = compositor_create_surface, + .create_region = compositor_create_region, +}; +static void bind_compositor(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wl_compositor_interface, ver, id); + wl_resource_set_implementation(r, &compositor_impl, NULL, NULL); +} + +/* --------------------------------------------------------------- wl_subcompositor + * winewayland puts a window's Vulkan/GL swapchain in a subsurface over the window. */ + +static void subsurface_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void subsurface_set_position(struct wl_client *c, struct wl_resource *r, int32_t x, int32_t y) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + s->sub_pending_x = x; + s->sub_pending_y = y; + s->sub_pending = 1; +} +static void restack_child(struct surface *s, struct surface *sibling, int above) { + if (!s || !s->parent || !sibling) return; + if (sibling == s->parent) { + /* Relative to the parent: directly above it or directly below it. */ + s->below_parent = !above; + wl_list_remove(&s->child_link); + if (above) wl_list_insert(&s->parent->children, &s->child_link); + else wl_list_insert(s->parent->children.prev, &s->child_link); + } else if (sibling->parent == s->parent) { + s->below_parent = sibling->below_parent; + wl_list_remove(&s->child_link); + if (above) wl_list_insert(&sibling->child_link, &s->child_link); + else wl_list_insert(sibling->child_link.prev, &s->child_link); + } + schedule_render(); +} +static void subsurface_place_above(struct wl_client *c, struct wl_resource *r, + struct wl_resource *sibling) { + restack_child(wl_resource_get_user_data(r), wl_resource_get_user_data(sibling), 1); +} +static void subsurface_place_below(struct wl_client *c, struct wl_resource *r, + struct wl_resource *sibling) { + restack_child(wl_resource_get_user_data(r), wl_resource_get_user_data(sibling), 0); +} +static void subsurface_set_sync(struct wl_client *c, struct wl_resource *r) {} +static void subsurface_set_desync(struct wl_client *c, struct wl_resource *r) {} +static const struct wl_subsurface_interface subsurface_impl = { + .destroy = subsurface_destroy, + .set_position = subsurface_set_position, + .place_above = subsurface_place_above, + .place_below = subsurface_place_below, + .set_sync = subsurface_set_sync, + .set_desync = subsurface_set_desync, +}; +static void subsurface_resource_destroy(struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + detach_from_parent(s); + s->subsurface = NULL; + s->role = ROLE_NONE; + s->has_content = 0; + drop_dmabuf(s, 1); + schedule_render(); +} + +static void subcompositor_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void subcompositor_get_subsurface(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface, struct wl_resource *parent) { + struct surface *s = wl_resource_get_user_data(surface); + struct surface *p = wl_resource_get_user_data(parent); + struct wl_resource *sub = wl_resource_create(c, &wl_subsurface_interface, wl_resource_get_version(r), id); + if (!sub) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(sub, &subsurface_impl, s, subsurface_resource_destroy); + if (!s || !p || s == p) return; + detach_from_parent(s); + s->role = ROLE_SUBSURFACE; + s->subsurface = sub; + s->parent = p; + s->below_parent = 0; + s->sub_x = s->sub_y = 0; + wl_list_insert(p->children.prev, &s->child_link); /* new subsurfaces go on top */ +} +static const struct wl_subcompositor_interface subcompositor_impl = { + .destroy = subcompositor_destroy, + .get_subsurface = subcompositor_get_subsurface, +}; +static void bind_subcompositor(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wl_subcompositor_interface, ver, id); + wl_resource_set_implementation(r, &subcompositor_impl, NULL, NULL); +} + +/* ---------------------------------------------------------------- wp_viewporter + * winewayland crops window buffers to the window size and scales swapchains to the + * client area with viewports, so they must be honoured for things to line up. */ + +static void viewport_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void viewport_set_source(struct wl_client *c, struct wl_resource *r, + wl_fixed_t x, wl_fixed_t y, wl_fixed_t w, wl_fixed_t h) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + s->pending_src[0] = (float)wl_fixed_to_double(x); + s->pending_src[1] = (float)wl_fixed_to_double(y); + s->pending_src[2] = w == wl_fixed_from_int(-1) ? -1.0f : (float)wl_fixed_to_double(w); + s->pending_src[3] = h == wl_fixed_from_int(-1) ? -1.0f : (float)wl_fixed_to_double(h); + s->pending_src_set = 1; +} +static void viewport_set_destination(struct wl_client *c, struct wl_resource *r, int32_t w, int32_t h) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + s->pending_dst[0] = w; + s->pending_dst[1] = h; + s->pending_dst_set = 1; +} +static const struct wp_viewport_interface viewport_impl = { + .destroy = viewport_destroy, + .set_source = viewport_set_source, + .set_destination = viewport_set_destination, +}; +static void viewport_resource_destroy(struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + s->viewport = NULL; + s->pending_src[2] = -1.0f; s->pending_src_set = 1; + s->pending_dst[0] = -1; s->pending_dst_set = 1; +} + +static void viewporter_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void viewporter_get_viewport(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface) { + struct surface *s = wl_resource_get_user_data(surface); + struct wl_resource *vp = wl_resource_create(c, &wp_viewport_interface, wl_resource_get_version(r), id); + if (!vp) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(vp, &viewport_impl, s, viewport_resource_destroy); + if (s) s->viewport = vp; +} +static const struct wp_viewporter_interface viewporter_impl = { + .destroy = viewporter_destroy, + .get_viewport = viewporter_get_viewport, +}; +static void bind_viewporter(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wp_viewporter_interface, ver, id); + wl_resource_set_implementation(r, &viewporter_impl, NULL, NULL); +} + +/* ------------------------------------------------------------------ xdg_shell */ + +static void xdg_toplevel_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void xdg_toplevel_noop_parent(struct wl_client *c, struct wl_resource *r, struct wl_resource *p) {} +static void xdg_toplevel_set_title(struct wl_client *c, struct wl_resource *r, const char *title) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + free(s->title); + s->title = title ? strdup(title) : NULL; +} +static void xdg_toplevel_set_app_id(struct wl_client *c, struct wl_resource *r, const char *id) {} +static void xdg_toplevel_show_menu(struct wl_client *c, struct wl_resource *r, struct wl_resource *seat, + uint32_t serial, int32_t x, int32_t y) {} +static void xdg_toplevel_move(struct wl_client *c, struct wl_resource *r, struct wl_resource *seat, + uint32_t serial) {} +static void xdg_toplevel_resize(struct wl_client *c, struct wl_resource *r, struct wl_resource *seat, + uint32_t serial, uint32_t edges) {} +static void xdg_toplevel_set_i32(struct wl_client *c, struct wl_resource *r, int32_t w, int32_t h) {} +static void xdg_toplevel_noop(struct wl_client *c, struct wl_resource *r) {} +/* Size 0x0 = the client picks; active, and fullscreen when asked. gamescope waits for the + * fullscreen state before it drops its libdecor frame, and never draws until it arrives. */ +static void send_toplevel_configure(struct surface *s) { + struct wl_array states; + wl_array_init(&states); + uint32_t *st = wl_array_add(&states, sizeof(uint32_t)); + *st = XDG_TOPLEVEL_STATE_ACTIVATED; + if (s->fullscreen) { + st = wl_array_add(&states, sizeof(uint32_t)); + *st = XDG_TOPLEVEL_STATE_FULLSCREEN; + } + xdg_toplevel_send_configure(s->xdg_toplevel, 0, 0, &states); + wl_array_release(&states); + xdg_surface_send_configure(s->xdg_surface, wl_display_next_serial(g_display)); +} +static void xdg_toplevel_set_fullscreen(struct wl_client *c, struct wl_resource *r, + struct wl_resource *output) { + struct surface *s = wl_resource_get_user_data(r); + if (!s || !s->xdg_surface || !s->xdg_toplevel || s->fullscreen) return; + s->fullscreen = 1; + send_toplevel_configure(s); +} +static void xdg_toplevel_unset_fullscreen(struct wl_client *c, struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + if (!s || !s->xdg_surface || !s->xdg_toplevel || !s->fullscreen) return; + s->fullscreen = 0; + send_toplevel_configure(s); +} +static const struct xdg_toplevel_interface xdg_toplevel_impl = { + .destroy = xdg_toplevel_destroy_req, + .set_parent = xdg_toplevel_noop_parent, + .set_title = xdg_toplevel_set_title, + .set_app_id = xdg_toplevel_set_app_id, + .show_window_menu = xdg_toplevel_show_menu, + .move = xdg_toplevel_move, + .resize = xdg_toplevel_resize, + .set_max_size = xdg_toplevel_set_i32, + .set_min_size = xdg_toplevel_set_i32, + .set_maximized = xdg_toplevel_noop, + .unset_maximized = xdg_toplevel_noop, + .set_fullscreen = xdg_toplevel_set_fullscreen, + .unset_fullscreen = xdg_toplevel_unset_fullscreen, + .set_minimized = xdg_toplevel_noop, +}; +static void xdg_toplevel_resource_destroy(struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + if (!s) return; + s->xdg_toplevel = NULL; + unmap_toplevel(s); + s->placed = 0; + s->hwnd = 0; + schedule_render(); +} + +static void xdg_surface_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void xdg_surface_get_toplevel(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct surface *s = wl_resource_get_user_data(r); + struct wl_resource *tl = wl_resource_create(c, &xdg_toplevel_interface, wl_resource_get_version(r), id); + if (!tl) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(tl, &xdg_toplevel_impl, s, xdg_toplevel_resource_destroy); + if (!s) return; + s->role = ROLE_TOPLEVEL; + s->xdg_toplevel = tl; + send_toplevel_configure(s); +} +static void xdg_surface_get_popup(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *parent, struct wl_resource *positioner) {} +static void xdg_surface_set_geometry(struct wl_client *c, struct wl_resource *r, + int32_t x, int32_t y, int32_t w, int32_t h) {} +static void xdg_surface_ack_configure(struct wl_client *c, struct wl_resource *r, uint32_t serial) {} +static const struct xdg_surface_interface xdg_surface_impl = { + .destroy = xdg_surface_destroy_req, + .get_toplevel = xdg_surface_get_toplevel, + .get_popup = xdg_surface_get_popup, + .set_window_geometry = xdg_surface_set_geometry, + .ack_configure = xdg_surface_ack_configure, +}; +static void xdg_surface_resource_destroy(struct wl_resource *r) { + struct surface *s = wl_resource_get_user_data(r); + if (s) s->xdg_surface = NULL; +} + +static void xdg_wm_base_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void xdg_wm_base_create_positioner(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *p = wl_resource_create(c, &xdg_positioner_interface, wl_resource_get_version(r), id); + if (p) wl_resource_set_implementation(p, NULL, NULL, NULL); +} +static void xdg_wm_base_get_xdg_surface(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surf) { + struct surface *s = wl_resource_get_user_data(surf); + struct wl_resource *xs = wl_resource_create(c, &xdg_surface_interface, wl_resource_get_version(r), id); + if (!xs) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(xs, &xdg_surface_impl, s, xdg_surface_resource_destroy); + if (s) s->xdg_surface = xs; +} +static void xdg_wm_base_pong(struct wl_client *c, struct wl_resource *r, uint32_t serial) {} +static const struct xdg_wm_base_interface xdg_wm_base_impl = { + .destroy = xdg_wm_base_destroy, + .create_positioner = xdg_wm_base_create_positioner, + .get_xdg_surface = xdg_wm_base_get_xdg_surface, + .pong = xdg_wm_base_pong, +}; +static void bind_xdg_wm_base(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &xdg_wm_base_interface, ver, id); + wl_resource_set_implementation(r, &xdg_wm_base_impl, NULL, NULL); +} + +/* ------------------------------------------------------------------ banner_desktop_v1 */ + +static void desktop_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void desktop_set_desktop(struct wl_client *c, struct wl_resource *r, struct wl_resource *surface) { + struct surface *s = wl_resource_get_user_data(surface); + if (!s || (s->role != ROLE_NONE && s->role != ROLE_DESKTOP)) return; + s->role = ROLE_DESKTOP; + g_desktop = s; + banner_log("desktop", "Windows virtual desktop created by %s", client_name(c)); + schedule_render(); +} +static void desktop_set_window(struct wl_client *c, struct wl_resource *r, struct wl_resource *surface, + uint32_t hwnd, int32_t x, int32_t y) { + struct surface *s = wl_resource_get_user_data(surface); + if (!s) return; + if (s->placed && (s->x != x || s->y != y) && s->mapped && log_budget()) { + char name[160]; + describe(s, name, sizeof(name)); + banner_log("window", "moved %s to %d,%d", name, x, y); + } + s->hwnd = hwnd; + s->x = x; + s->y = y; + s->placed = 1; + if (s->mapped) apply_zorder(); + schedule_render(); +} +static void desktop_set_zorder(struct wl_client *c, struct wl_resource *r, struct wl_array *hwnds) { + size_t count = hwnds->size / sizeof(uint32_t); + uint32_t *copy = count ? malloc(count * sizeof(uint32_t)) : NULL; + if (count && !copy) return; + if (count) memcpy(copy, hwnds->data, count * sizeof(uint32_t)); + free(g_zorder); + g_zorder = copy; + g_zorder_count = count; + apply_zorder(); + schedule_render(); +} +static const struct banner_desktop_v1_interface desktop_impl = { + .destroy = desktop_destroy_req, + .set_desktop = desktop_set_desktop, + .set_window = desktop_set_window, + .set_zorder = desktop_set_zorder, +}; +static void bind_desktop(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &banner_desktop_v1_interface, ver, id); + wl_resource_set_implementation(r, &desktop_impl, NULL, NULL); +} + +/* ------------------------------------------------------------ zwp_linux_dmabuf_v1 */ + +static void dbuf_buffer_resource_destroy(struct wl_resource *r) { + dmabuf_buffer_unref(wl_resource_get_user_data(r)); +} + +static void params_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void params_add(struct wl_client *c, struct wl_resource *r, int32_t fd, uint32_t plane, + uint32_t offset, uint32_t stride, uint32_t mod_hi, uint32_t mod_lo) { + struct dmabuf_params *p = wl_resource_get_user_data(r); + if (plane >= MAX_PLANES) { close(fd); return; } + if (p->fd[plane] >= 0) close(p->fd[plane]); + p->fd[plane] = fd; + p->offset[plane] = offset; + p->stride[plane] = stride; + p->modifier[plane] = ((uint64_t)mod_hi << 32) | mod_lo; + if ((int)plane + 1 > p->n_planes) p->n_planes = plane + 1; +} +static struct wl_resource *params_do_create(struct wl_client *c, struct wl_resource *r, uint32_t id, + int32_t w, int32_t h, uint32_t format, uint32_t flags) { + struct dmabuf_params *p = wl_resource_get_user_data(r); + struct dmabuf_buffer *b = calloc(1, sizeof(*b)); + if (!b) return NULL; + b->n_planes = p->n_planes; + b->refs = 1; /* the wl_buffer resource's */ + b->width = w; b->height = h; b->format = format; + b->modifier = p->modifier[0]; + for (int i = 0; i < MAX_PLANES; i++) b->fd[i] = -1; + for (int i = 0; i < p->n_planes; i++) { + b->fd[i] = p->fd[i]; + b->offset[i] = p->offset[i]; + b->stride[i] = p->stride[i]; + p->fd[i] = -1; /* ownership moves to the buffer */ + } + struct wl_resource *buf = wl_resource_create(c, &wl_buffer_interface, 1, id); + if (!buf) { + for (int i = 0; i < b->n_planes; i++) if (b->fd[i] >= 0) close(b->fd[i]); + free(b); + wl_client_post_no_memory(c); + return NULL; + } + wl_resource_set_implementation(buf, &dbuf_buffer_impl, b, dbuf_buffer_resource_destroy); + struct client_info *ci = client_info_of(c); + if (ci) ci->dmabuf_buffers++; + return buf; +} +static void params_create(struct wl_client *c, struct wl_resource *r, int32_t w, int32_t h, + uint32_t format, uint32_t flags) { + struct wl_resource *buf = params_do_create(c, r, 0, w, h, format, flags); + if (buf) zwp_linux_buffer_params_v1_send_created(r, buf); + else zwp_linux_buffer_params_v1_send_failed(r); +} +static void params_create_immed(struct wl_client *c, struct wl_resource *r, uint32_t buffer_id, + int32_t w, int32_t h, uint32_t format, uint32_t flags) { + params_do_create(c, r, buffer_id, w, h, format, flags); +} +static const struct zwp_linux_buffer_params_v1_interface params_impl = { + .destroy = params_destroy, + .add = params_add, + .create = params_create, + .create_immed = params_create_immed, +}; +static void params_resource_destroy(struct wl_resource *r) { + struct dmabuf_params *p = wl_resource_get_user_data(r); + if (!p) return; + for (int i = 0; i < MAX_PLANES; i++) + if (p->fd[i] >= 0) close(p->fd[i]); + free(p); +} + +static void dmabuf_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void dmabuf_create_params(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct dmabuf_params *p = calloc(1, sizeof(*p)); + if (!p) { wl_client_post_no_memory(c); return; } + for (int i = 0; i < MAX_PLANES; i++) p->fd[i] = -1; + struct wl_resource *pr = wl_resource_create(c, &zwp_linux_buffer_params_v1_interface, + wl_resource_get_version(r), id); + if (!pr) { free(p); wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(pr, ¶ms_impl, p, params_resource_destroy); +} +static void dmabuf_get_default_feedback(struct wl_client *c, struct wl_resource *r, uint32_t id); +static void dmabuf_get_surface_feedback(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface); +static const struct zwp_linux_dmabuf_v1_interface dmabuf_impl = { + .destroy = dmabuf_destroy, + .create_params = dmabuf_create_params, + .get_default_feedback = dmabuf_get_default_feedback, + .get_surface_feedback = dmabuf_get_surface_feedback, +}; +/* The advertised format/modifier table, built at the first bind from what the renderer's driver + * can import (vkp_dmabuf_modifiers). INVALID is always offered too (Mesa drops it; other clients + * may use it for the implicit path). Without a renderer the list is LINEAR + INVALID, as before. */ +/* The last two rows are HDR10's (banner_color.h): A2B10G10R10 as AB30 (alpha) + XB30 (opaque) - Mesa + * lists a VkFormat only when both are advertised, and it is the one 10-bit layout our zero-copy WSI + * can put in a gralloc buffer (AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM). They are advertised ONLY + * while the HDR gate is open, and after the 8-bit rows, so every other session - and every client that + * takes the first format it sees - gets exactly the table it always had. */ +#define DMABUF_NFMT_MAX 6 +#define DMABUF_NFMT_SDR 4 +#define DMABUF_NMOD 4 +#define DRM_ABGR2101010 FOURCC('A', 'B', '3', '0') +#define DRM_XBGR2101010 FOURCC('X', 'B', '3', '0') +static struct { uint32_t fmt; uint64_t mods[DMABUF_NMOD]; int n; } g_dmabuf_fmts[DMABUF_NFMT_MAX] = { + {DRM_ARGB8888}, {DRM_XRGB8888}, {DRM_ABGR8888}, {DRM_XBGR8888}, {DRM_ABGR2101010}, {DRM_XBGR2101010}}; +static int g_dmabuf_nfmt = DMABUF_NFMT_SDR; /* rows advertised: the SDR four, + 2 with the HDR gate open */ +static int g_dmabuf_fmts_ready; +static void dmabuf_build_feedback(void); + +static void dmabuf_build_formats(void) { + char line[320]; + int pos = 0, compressed = 0; + g_dmabuf_fmts_ready = 1; + g_dmabuf_nfmt = banner_color_hdr_open() ? DMABUF_NFMT_MAX : DMABUF_NFMT_SDR; + for (int f = 0; f < g_dmabuf_nfmt; f++) { + uint64_t got[DMABUF_NMOD]; + int n = vkp_dmabuf_modifiers(g_dmabuf_fmts[f].fmt, got, DMABUF_NMOD), k = 0; + /* LINEAR first: it is the layout every client and the shm fallback agree on, and the one + * we advertised before this table existed. */ + g_dmabuf_fmts[f].mods[k++] = MOD_LINEAR; + for (int i = 0; i < n && k < DMABUF_NMOD - 1; i++) { + if (got[i] == MOD_LINEAR) continue; + if (got[i] == VKP_MOD_QCOM_COMPRESSED && !g_ubwc) continue; + g_dmabuf_fmts[f].mods[k++] = got[i]; + if (got[i] == VKP_MOD_QCOM_COMPRESSED) compressed++; + } + g_dmabuf_fmts[f].mods[k++] = MOD_INVALID; + g_dmabuf_fmts[f].n = k; + uint32_t fmt = g_dmabuf_fmts[f].fmt; + pos += snprintf(line + pos, sizeof(line) - (size_t)pos, "%s%c%c%c%c", f ? ", " : "", + fmt & 0xff, (fmt >> 8) & 0xff, (fmt >> 16) & 0xff, (fmt >> 24) & 0xff); + for (int i = 0; i < k - 1 && pos < (int)sizeof(line); i++) + pos += snprintf(line + pos, sizeof(line) - (size_t)pos, "%s%s", i ? "+" : " ", + vkp_modifier_name(g_dmabuf_fmts[f].mods[i])); + if (pos >= (int)sizeof(line)) pos = (int)sizeof(line) - 1; + } + banner_log("dmabuf", "formats: %s%s", line, + !g_ubwc ? " (BANNER_WAYLAND_UBWC=0: qcom_compressed not advertised)" : ""); + if (g_ubwc && !compressed) + banner_log("dmabuf", "the compositor's driver (%s) reports no importable qcom_compressed layout: " + "game swapchains stay linear", vkp_gpu_name()); + if (g_dmabuf_nfmt > DMABUF_NFMT_SDR) { + /* The rows above always carry LINEAR; say what the compositor's own driver can really import + * for 10-bit, since a gralloc buffer it cannot import is shown on the display layer only. */ + uint64_t got[DMABUF_NMOD]; + int n = vkp_dmabuf_modifiers(DRM_XBGR2101010, got, DMABUF_NMOD), ubwc10 = 0; + for (int i = 0; i < n; i++) if (got[i] == VKP_MOD_QCOM_COMPRESSED) ubwc10 = 1; + banner_log("color", "10-bit dma-buf formats AB30/XB30 advertised for HDR10; the compositor's driver (%s) " + "imports XB30 %s", vkp_gpu_name(), + n == 0 ? "with no layout it reports (copy path unlikely; display layer only)" + : ubwc10 ? "linear and UBWC" : "linear only (UBWC 10-bit frames: display layer only)"); + } + dmabuf_build_feedback(); +} + +/* ---- dmabuf feedback (zwp_linux_dmabuf_v1 version 4) + * + * Turnip's Vulkan WSI is happy with the version 3 format/modifier events, so every Vulkan game + * worked while we only advertised 3. Mesa's EGL is not: its Wayland platform only takes the GPU + * (kopper/Zink) path when it can bind this interface with FEEDBACK, and with 3 it silently drops + * to its wl_shm software path. On this Proton layer that path has no software rasteriser to fall + * back to (the gallium build is zink+kopper+swrast, no llvmpipe), so the shm buffer it commits is + * never written: a native OpenGL window came out solid black, ~30 shm commits/s and no GPU frame + * at all (Wizardry: The Labyrinth of Lost Souls). Feedback is what makes that path work. + * + * What a client needs from us is one tranche describing "everything the compositor can import": + * a format table it mmaps read-only, the device to allocate on, and the indices it may use. + * Clients binding versions 1-3 keep getting the old format/modifier events instead. */ + +#ifndef MFD_CLOEXEC +#define MFD_CLOEXEC 0x0001U +#endif +#ifndef MFD_ALLOW_SEALING +#define MFD_ALLOW_SEALING 0x0002U +#endif +#ifndef F_ADD_SEALS +#define F_ADD_SEALS 1033 +#define F_SEAL_SEAL 0x0001 +#define F_SEAL_SHRINK 0x0002 +#define F_SEAL_GROW 0x0004 +#define F_SEAL_WRITE 0x0008 +#endif + +struct dmabuf_fmt_entry { uint32_t format; uint32_t pad; uint64_t modifier; }; /* the wire layout */ + +static int g_fmt_table_fd = -1; /* sealed read-only memfd of dmabuf_fmt_entry[] */ +static size_t g_fmt_table_size; +static uint16_t g_fmt_table_n; /* entries, == the indices a tranche may name */ +static dev_t g_main_device; /* the render node clients should allocate on */ + +/* The GPU we import through is reached with KGSL, not DRM, so there is no render node of our own + * to name. Clients only use main_device to match "the same device as the compositor" and to pick + * a driver; the one DRM render node this platform has is the right answer, and Zink ignores it + * anyway (it renders on the Vulkan device it already has). 0 if the platform has none. */ +static dev_t dmabuf_render_node(void) { + static const char *nodes[] = {"/dev/dri/renderD128", "/dev/dri/renderD129", "/dev/dri/card0"}; + struct stat st; + if (g_no_render_node) return 0; + for (size_t i = 0; i < sizeof(nodes) / sizeof(nodes[0]); i++) + if (!stat(nodes[i], &st) && S_ISCHR(st.st_mode)) return st.st_rdev; + return 0; +} + +static void dmabuf_build_feedback(void) { + struct dmabuf_fmt_entry entries[DMABUF_NFMT_MAX * DMABUF_NMOD]; + int n = 0; + + g_main_device = dmabuf_render_node(); + for (int f = 0; f < g_dmabuf_nfmt; f++) + for (int m = 0; m < g_dmabuf_fmts[f].n; m++) { + if (g_dmabuf_fmts[f].mods[m] == MOD_INVALID) continue; /* never offer INVALID here */ + entries[n].format = g_dmabuf_fmts[f].fmt; + entries[n].pad = 0; + entries[n].modifier = g_dmabuf_fmts[f].mods[m]; + n++; + } + if (!n) return; + + int fd = (int)syscall(__NR_memfd_create, "banner-dmabuf-formats", + MFD_CLOEXEC | MFD_ALLOW_SEALING); + if (fd < 0) { WLOGE("dmabuf feedback: memfd_create failed (%s)", strerror(errno)); return; } + size_t size = (size_t)n * sizeof(entries[0]); + if (write(fd, entries, size) != (ssize_t)size) { + WLOGE("dmabuf feedback: could not write the format table (%s)", strerror(errno)); + close(fd); + return; + } + /* The client mmaps this read-only and trusts it not to change under it. */ + fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE); + g_fmt_table_fd = fd; + g_fmt_table_size = size; + g_fmt_table_n = (uint16_t)n; + banner_log("dmabuf", "feedback ready: %d format/modifier pairs, main device %u:%u", + n, (unsigned)major(g_main_device), (unsigned)minor(g_main_device)); + /* Vulkan games never need the node. Mesa's EGL did until Wayland layer versionCode 9: without + * one it fell back to a software path that draws nothing here (black window, sound plays). */ + if (!g_main_device) + banner_log("dmabuf", "%s: OpenGL games need Wayland layer versionCode 9 or newer, " + "which runs OpenGL on the GPU without a DRM node; older layers show a black window", + g_no_render_node ? "no DRM device named (forced by BANNER_WAYLAND_NO_RENDER_NODE=1)" + : "this device gives apps no display (DRM) device (/dev/dri)"); +} + +/* One tranche: our device, every pair in the table, no scanout flag. */ +static void dmabuf_feedback_send(struct wl_resource *fb) { + struct wl_array dev, idx; + uint16_t *ind; + + if (g_fmt_table_fd < 0) { zwp_linux_dmabuf_feedback_v1_send_done(fb); return; } + + zwp_linux_dmabuf_feedback_v1_send_format_table(fb, g_fmt_table_fd, (uint32_t)g_fmt_table_size); + + wl_array_init(&dev); + memcpy(wl_array_add(&dev, sizeof(dev_t)), &g_main_device, sizeof(dev_t)); + zwp_linux_dmabuf_feedback_v1_send_main_device(fb, &dev); + zwp_linux_dmabuf_feedback_v1_send_tranche_target_device(fb, &dev); + wl_array_release(&dev); + + wl_array_init(&idx); + ind = wl_array_add(&idx, (size_t)g_fmt_table_n * sizeof(uint16_t)); + if (ind) for (uint16_t i = 0; i < g_fmt_table_n; i++) ind[i] = i; + zwp_linux_dmabuf_feedback_v1_send_tranche_formats(fb, &idx); + wl_array_release(&idx); + + zwp_linux_dmabuf_feedback_v1_send_tranche_flags(fb, 0); + zwp_linux_dmabuf_feedback_v1_send_tranche_done(fb); + zwp_linux_dmabuf_feedback_v1_send_done(fb); +} + +static void dmabuf_feedback_destroy(struct wl_client *c, struct wl_resource *r) { + wl_resource_destroy(r); +} +static const struct zwp_linux_dmabuf_feedback_v1_interface dmabuf_feedback_impl = { + .destroy = dmabuf_feedback_destroy, +}; + +static void dmabuf_new_feedback(struct wl_client *c, struct wl_resource *parent, uint32_t id) { + struct wl_resource *fb = wl_resource_create(c, &zwp_linux_dmabuf_feedback_v1_interface, + wl_resource_get_version(parent), id); + if (!fb) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(fb, &dmabuf_feedback_impl, NULL, NULL); + if (!g_dmabuf_fmts_ready) dmabuf_build_formats(); + dmabuf_feedback_send(fb); +} + +static void dmabuf_get_default_feedback(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct client_info *ci = client_info_of(c); + if (ci) ci->asked_feedback = 1; + dmabuf_new_feedback(c, r, id); +} +/* Per-surface feedback would let us hint a different tranche for a window on its own display + * layer; we have nothing better to say per surface, so it is the default one. */ +static void dmabuf_get_surface_feedback(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface) { + dmabuf_new_feedback(c, r, id); +} + +static void bind_dmabuf(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &zwp_linux_dmabuf_v1_interface, ver, id); + wl_resource_set_implementation(r, &dmabuf_impl, NULL, NULL); + if (!g_dmabuf_fmts_ready) dmabuf_build_formats(); + /* From version 4 the format and modifier events are gone: the client asks for feedback + * instead, and sending both would only confuse it about which list is authoritative. */ + if (ver >= 4) return; + for (int f = 0; f < g_dmabuf_nfmt; f++) { + zwp_linux_dmabuf_v1_send_format(r, g_dmabuf_fmts[f].fmt); + if (ver >= 3) + for (int m = 0; m < g_dmabuf_fmts[f].n; m++) + zwp_linux_dmabuf_v1_send_modifier(r, g_dmabuf_fmts[f].fmt, + (uint32_t)(g_dmabuf_fmts[f].mods[m] >> 32), + (uint32_t)(g_dmabuf_fmts[f].mods[m] & 0xffffffff)); + } +} + +/* ------------------------------------------------------------------ wl_output */ + +static void bind_output(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wl_output_interface, ver, id); + wl_resource_set_implementation(r, NULL, NULL, NULL); + wl_output_send_geometry(r, 0, 0, 340, 190, WL_OUTPUT_SUBPIXEL_UNKNOWN, + "Bannerlator", "Wayland", WL_OUTPUT_TRANSFORM_NORMAL); + wl_output_send_mode(r, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, + g_output_w > 0 ? g_output_w : 1920, g_output_h > 0 ? g_output_h : 1080, + g_output_refresh_mhz > 0 ? g_output_refresh_mhz : 60000); + if (ver >= WL_OUTPUT_NAME_SINCE_VERSION) { + wl_output_send_name(r, "Bannerlator-1"); + wl_output_send_description(r, "Bannerlator display"); + } + if (ver >= 2) { + wl_output_send_scale(r, 1); + wl_output_send_done(r); + } +} + +/* ------------------------------------------------------------------ rendering */ + +struct draw_list { struct vkp_draw *d; int n, cap; }; + +static struct vkp_image *surface_image(struct surface *s) { + if (!s->has_content) return NULL; + if (s->shm_img) return s->shm_img; + return s->dmabuf_buf ? s->dmabuf_buf->img : NULL; +} + +/* HDR (gate open) only: the scene's HDR surface whose current frame is one of the game's gralloc buffers + * that the compositor's own driver could NOT import (a 10-bit UBWC layout it does not take, say). Such a + * frame has no draw, so neither layer_candidate() nor ahb_layer_only_candidate() (toplevels only) can + * find it - and a Vulkan game's swapchain is a SUBSURFACE of its window. Remembered here while the scene + * is built so it can still go on the display layer, which never needed the import. Reset per scene; + * never set while the HDR gate is closed. */ +static struct surface *g_hdr_unimported; +static int g_hdr_unimported_rect[4], g_hdr_unimported_below; /* scene x,y,w,h; draws under it */ + +static void note_hdr_unimported(const struct draw_list *dl, struct surface *s, int ox, int oy) { + if (!s->dmabuf_buf || s->dmabuf_buf->img || !ahb_swapchain_has_ahb(s->dmabuf_buf)) return; + const struct banner_color *c = banner_color_of(s->resource); + if (!c || !c->dataspace) return; + if (s->src_set && (s->src[0] != 0 || s->src[1] != 0 || (int)(s->src[2] + 0.5f) != s->buf_w || + (int)(s->src[3] + 0.5f) != s->buf_h)) return; /* cropped: the layer shows whole buffers */ + int dw, dh; + surface_size(s, &dw, &dh); + g_hdr_unimported = s; + g_hdr_unimported_rect[0] = ox; g_hdr_unimported_rect[1] = oy; + g_hdr_unimported_rect[2] = dw; g_hdr_unimported_rect[3] = dh; + g_hdr_unimported_below = dl->n; +} + +static void add_surface(struct draw_list *dl, struct surface *s, int ox, int oy) { + struct vkp_image *img = surface_image(s); + float sx = 0, sy = 0, sw = (float)s->buf_w, sh = (float)s->buf_h; + int dw, dh; + + if (!img) { + if (g_zero_copy && banner_color_hdr_open()) note_hdr_unimported(dl, s, ox, oy); + return; + } + if (s->src_set) { sx = s->src[0]; sy = s->src[1]; sw = s->src[2]; sh = s->src[3]; } + surface_size(s, &dw, &dh); + if (dw <= 0 || dh <= 0 || sw <= 0 || sh <= 0) return; + if (dl->n == dl->cap) { + int cap = dl->cap ? dl->cap * 2 : 32; + struct vkp_draw *d = realloc(dl->d, (size_t)cap * sizeof(*d)); + if (!d) return; + dl->d = d; + dl->cap = cap; + } + dl->d[dl->n++] = (struct vkp_draw){img, sx, sy, sw, sh, ox, oy, dw, dh}; + s->drawn = 1; +} + +static void add_tree(struct draw_list *dl, struct surface *s, int ox, int oy, int depth) { + struct surface *c; + if (depth > 8) return; + wl_list_for_each(c, &s->children, child_link) + if (c->below_parent) add_tree(dl, c, ox + c->sub_x, oy + c->sub_y, depth + 1); + add_surface(dl, s, ox, oy); + wl_list_for_each(c, &s->children, child_link) + if (!c->below_parent) add_tree(dl, c, ox + c->sub_x, oy + c->sub_y, depth + 1); +} + +/* Scene size: the desktop's, or without one the largest window's (a single + * fullscreen game then fills the screen exactly as before). */ +static void scene_size(int *w, int *h) { + struct surface *s; + long long best = 0; + + if (g_desktop && g_desktop->has_content) { + surface_size(g_desktop, w, h); + g_desktop_w = *w; + g_desktop_h = *h; + return; + } + if (g_desktop && g_desktop_w > 0) { *w = g_desktop_w; *h = g_desktop_h; return; } + *w = *h = 0; + wl_list_for_each(s, &g_toplevels, toplevel_link) { + int sw, sh; + surface_size(s, &sw, &sh); + if ((long long)sw * sh > best) { best = (long long)sw * sh; *w = sw; *h = sh; } + } + if (*w <= 0 || *h <= 0) { *w = INPUT_SPACE_W; *h = INPUT_SPACE_H; } +} + +static void fire_all_frames(void) { + struct surface *s; + wl_list_for_each(s, &g_surfaces, link) fire_frames(&s->frames); +} + +/* With no output window (the app is in the background, or the SurfaceView is being rebuilt) + * nothing gets drawn, but the clients must not be left waiting on us. A FIFO swapchain blocks + * in its present until its wp_presentation feedback and frame callback arrive, and a client + * blocked there stops pumping messages: winhandler.exe then wedges behind it and the app + * concludes the program has exited and closes the whole session. (DXVK's mailbox presents + * never wait, which is why only OpenGL/Zink clients died on a background/resume.) Answer every + * pending frame and feedback as discarded, and keep doing so until a window is back. */ +static void pace_without_output(void) { + struct surface *s; + wl_list_for_each(s, &g_surfaces, link) { + fire_frames(&s->frames); + feedback_discard_all(&s->feedback); + } + wl_display_flush_clients(g_display); +} + +static int on_frame_timer(void *data) { + pace_without_output(); + if (vkp_has_window()) schedule_render(); /* it is back: draw the current scene */ + else if (g_frame_timer) wl_event_source_timer_update(g_frame_timer, 16); + return 0; +} + +/* Layer mode: the index of a draw that shows a whole client GPU frame over the whole scene (one + * fullscreen game), or -1. Only the top two positions are looked at: the game must be the topmost + * draw, or have exactly ONE draw above it, which then goes on the overlay layer (sc_layer.h). + * Anything deeper would need more display layers than HWC will compose. */ +static int layer_candidate(const struct draw_list *dl, int scene_w, int scene_h) { + for (int i = dl->n - 1; i >= 0 && i >= dl->n - 2; i--) { + const struct vkp_draw *d = &dl->d[i]; + if (!vkp_image_is_dmabuf(d->img)) continue; + if (d->dx != 0 || d->dy != 0 || d->dw != scene_w || d->dh != scene_h) continue; + if (d->sx != 0 || d->sy != 0 || (int)d->sw != vkp_image_width(d->img) || + (int)d->sh != vkp_image_height(d->img)) continue; + return i; + } + return -1; +} + +/* Zero-copy: the surface whose current GPU frame `img` is (layer_candidate found the draw). */ +static struct surface *surface_for_image(const struct vkp_image *img) { + struct surface *s; + wl_list_for_each(s, &g_surfaces, link) + if (s->dmabuf_buf && s->dmabuf_buf->img == img) return s; + return NULL; +} + +/* Zero-copy: the topmost window whose frame is one of the game's AHardwareBuffers that this + * renderer could NOT import (so it has no draw), covering the whole scene at 0,0 with nothing of + * its own above it: it can only be shown on the layer. NULL otherwise. */ +static struct surface *ahb_layer_only_candidate(int scene_w, int scene_h) { + struct surface *s; + int w, h; + if (wl_list_empty(&g_toplevels)) return NULL; + s = wl_container_of(g_toplevels.prev, s, toplevel_link); + if (!s->dmabuf_buf || s->dmabuf_buf->img || !ahb_swapchain_has_ahb(s->dmabuf_buf)) return NULL; + if ((g_desktop && !s->placed) || s->x != 0 || s->y != 0 || s->src_set || s->dst_set) return NULL; + if (!wl_list_empty(&s->children)) return NULL; + if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) return NULL; + surface_size(s, &w, &h); + if (w != scene_w || h != scene_h || s->buf_w != scene_w || s->buf_h != scene_h) return NULL; + return s; +} + +/* ---- HDR (banner_color.h) in the scene + * An HDR frame is only right on the game's own display layer: everything the compositor draws itself - + * the scene blit, the effects chain, frame generation, its swapchain - is 8-bit sRGB, and a PQ-encoded + * frame pushed through it as it stands comes out washed out. So a scene with HDR in it takes one of + * three routes (hdr_plan): + * 0 the HDR game ALONE on its display layer (zero-copy, or one copy) - with at most one SDR window + * above it on the overlay layer where this display can compose that. Best: nothing is converted. + * 1 the HDR PICTURE: everything else without frame generation - screen effects on, a window above + * the game on a display that cannot take a second layer, a windowed game, zero-copy off. The whole + * scene is composed into ONE 10-bit PQ BT.2020 picture (SDR content placed at the SDR white; the + * effects run on it in 10-bit) and put on the game layer tagged BT2020_PQ (hdr_compose.h). + * 2 frame generation: its extra frames need presents of their own, so the scene is composed into PQ + * and presented through an HDR10 swapchain - or, where the screen surface offers none, + * tone-mapped to SDR (correct colours instead of washed out). + * 3 a frame the compositor could not import: only its display layer can show it, so effects and + * frame generation are skipped for it (said in the log). + * The drawer's HDR output switch (banner_color_output) OFF: the same routes, tone-mapped - route 0 + * becomes route 1 (the whole scene composed, tone-mapped to sRGB, onto the game layer UNtagged), route 2 + * tone-maps into an SDR swapchain, route 3 cannot (nothing can read those frames) and stays HDR, said + * in the log. The game is told nothing; it keeps rendering HDR. + * Nothing here runs while the HDR gate is closed. */ + +struct hdr_scene { + struct vkp_hdr_frame hf; + unsigned char *is_hdr; /* per draw (calloc'd; free after the frame) */ + int n_hdr; + const struct banner_color *color; /* the topmost HDR draw's description: what the picture is tagged */ + struct surface *who; /* its surface, for the log */ + const char *why; /* route 1: why the game cannot be alone on its layer */ +}; + +/* The HDR surface note_hdr_unimported() saw in THIS scene, when it covers the whole scene at 0,0 and + * nothing is drawn above it: the display layer is the only place its frame can be shown. */ +static struct surface *hdr_unimported_fullscreen(const struct draw_list *dl, int w, int h) { + if (!g_hdr_unimported || g_hdr_unimported_below != dl->n) return NULL; + if (g_hdr_unimported_rect[0] != 0 || g_hdr_unimported_rect[1] != 0 || + g_hdr_unimported_rect[2] != w || g_hdr_unimported_rect[3] != h) return NULL; + return g_hdr_unimported; +} + +static int is_hdr_surface(struct surface *s) { + const struct banner_color *c = s ? banner_color_of(s->resource) : NULL; + return c && c->dataspace; +} + +/* Which route this scene takes (see above); fills hs. 0 whenever the gate is closed or no HDR is drawn. */ +static int hdr_plan(const struct draw_list *dl, int w, int h, int fx_on, int framegen, struct hdr_scene *hs) { + memset(hs, 0, sizeof(*hs)); + if (!banner_color_hdr_open()) return 0; + /* A fullscreen HDR frame this compositor could not import has no draw: layer only (route 3). */ + struct surface *un = hdr_unimported_fullscreen(dl, w, h); + if (!un) { + struct surface *lo = ahb_layer_only_candidate(w, h); + if (lo && is_hdr_surface(lo)) un = lo; + } + if (un && g_zero_copy) { hs->color = banner_color_of(un->resource); hs->who = un; return 3; } + hs->hf.tonemap = !banner_color_output(); + if (dl->n <= 0 || !(hs->is_hdr = calloc((size_t)dl->n, 1))) return 0; + for (int i = 0; i < dl->n; i++) { + struct surface *s = surface_for_image(dl->d[i].img); + if (!is_hdr_surface(s)) continue; + hs->is_hdr[i] = 1; + hs->n_hdr++; + hs->color = banner_color_of(s->resource); /* later draws are above: the topmost wins */ + hs->who = s; + } + if (!hs->n_hdr) { free(hs->is_hdr); hs->is_hdr = NULL; return 0; } + hs->hf.is_hdr = hs->is_hdr; + hs->hf.color = hs->color; + hs->hf.peak_nits = hs->color->max_cll > 0.0f ? hs->color->max_cll + : hs->color->has_st2086 ? hs->color->max_lum : 1000.0f; + if (framegen) return 2; + /* Route 0 when the game can be alone on its layer: no effects, zero-copy on, the fullscreen draw + * is the HDR game, and above it nothing - or one window the overlay layer can carry. Not while the + * HDR output switch is off: its frame as it stands is PQ, and only the composition can tone-map it. */ + int li = g_zero_copy ? layer_candidate(dl, w, h) : -1; + int over = li >= 0 ? dl->n - 1 - li : 0; + if (!hs->hf.tonemap && !fx_on && li >= 0 && hs->is_hdr[li] && + (over == 0 || (over == 1 && sc_layer_overlay_affordable()))) + return 0; + hs->why = hs->hf.tonemap ? "HDR output is switched off in the drawer" + : fx_on ? "screen effects are on" + : !g_zero_copy ? "zero-copy presentation is off" + : (li >= 0 && hs->is_hdr[li]) ? "a window is above the game and this display cannot compose a second layer" + : "the HDR game is not one fullscreen window"; + return 1; +} + +/* One line per change of route (and of its reason, and of the HDR output switch). */ +static void hdr_note_route(int route, const struct hdr_scene *hs) { + static int said = -1, said_tm = -1; + static const char *said_why; + const int tm = route != 0 && !banner_color_output(); /* route 0 never runs with the switch off */ + if (route == said && tm == said_tm && (route != 1 || hs->why == said_why)) return; + int was = said; + said = route; said_why = hs->why; said_tm = tm; + char name[160] = "the HDR game"; + if (hs->who) describe(hs->who, name, sizeof(name)); + switch (route) { + case 1: + if (tm) + banner_log("color", "tone-mapped picture for %s: %s - the whole scene is composed and tone-mapped to SDR " + "(HDR peak %.0f nits rolled off to SDR white, screen effects applied after it) on the game's " + "display layer, untagged", name, hs->why ? hs->why : "?", hs->hf.peak_nits); + else + banner_log("color", "HDR picture for %s: %s - the whole scene is composed into one 10-bit PQ BT.2020 picture " + "(SDR content at %.0f nits, screen effects applied in 10-bit) on the game's display layer, tagged " + "BT2020_PQ", name, hs->why ? hs->why : "?", banner_color_sdr_white()); + break; + case 2: + if (tm) + banner_log("color", "HDR with frame generation for %s, HDR output switched off: the scene is tone-mapped to " + "SDR and presented through an SDR screen swapchain", name); + else + banner_log("color", "HDR with frame generation for %s: the scene is composed into PQ and presented through " + "the screen swapchain (HDR10 where the surface offers it, else tone-mapped to SDR)", name); + break; + case 3: + if (tm) + banner_log("color", "HDR output is switched off, but %s's HDR frames cannot be imported by the compositor, " + "so nothing can tone-map them: they stay HDR on its own display layer", name); + break; /* otherwise hdr_note_precedence says it */ + default: + if (was == 1 || was == 2) + banner_log("color", "%s is back on its own display layer (no composition needed)", name); + break; + } +} + +/* Say when effects / frame generation start or stop being skipped for an HDR game (once per change). */ +static void hdr_note_precedence(struct surface *hs, int fx_on, int framegen) { + static int fx_said = -1, fg_said = -1; + int fx_skip = hs && fx_on, fg_skip = hs && framegen; + char name[160] = "the game"; + if (hs) describe(hs, name, sizeof(name)); + if (fx_skip != fx_said) { + if (fx_skip) + banner_log("color", "screen effects are NOT applied to %s: its HDR frames cannot be imported by the " + "compositor, so only its own display layer can show them (as they are)", name); + else if (fx_said == 1) + banner_log("color", "screen effects apply to the scene again (no HDR game on its layer, or effects off)"); + fx_said = fx_skip; + } + if (fg_skip != fg_said) { + if (fg_skip) + banner_log("color", "frame generation is NOT applied to %s: its HDR frames cannot be imported by the " + "compositor, so only its own display layer can show them (as they are)", name); + else if (fg_said == 1) + banner_log("color", "frame generation applies again (no HDR game on its layer, or frame generation off)"); + fg_said = fg_skip; + } +} + +/* This scene went through the copy path: count every HDR-described surface in it, with the reason. */ +static void hdr_count_copied(const struct draw_list *dl, const char *reason) { + for (int i = 0; i < dl->n; i++) { + struct surface *s = surface_for_image(dl->d[i].img); + const struct banner_color *c = s ? banner_color_of(s->resource) : NULL; + if (!c || !c->dataspace) continue; + char name[160]; + describe(s, name, sizeof(name)); + banner_color_frame_copied(name, reason); + } +} + +static void render_scene(void) { + struct draw_list dl = {0}; + struct surface *s; + int w, h; + const int64_t t_scene = now_ns(); + int copy = 0; /* this scene went through the screen swapchain (the perf line's "copy") */ + + g_dirty = 0; + g_hdr_unimported = NULL; /* found again while the scene is built (HDR gate open only) */ + wl_list_for_each(s, &g_surfaces, link) s->drawn = 0; + scene_size(&w, &h); + if (w != g_scene_w || h != g_scene_h) { + if (g_desktop) banner_log("desktop", "size %dx%d", w, h); + else banner_log("desktop", "no desktop: showing %dx%d (largest window)", w, h); + g_scene_w = w; + g_scene_h = h; + } + if (g_desktop && !g_hide_shell) add_tree(&dl, g_desktop, 0, 0, 0); + wl_list_for_each(s, &g_toplevels, toplevel_link) { + if (g_desktop && !s->placed) continue; /* wait for its position */ + if (g_hide_shell && !strcmp(client_name(wl_resource_get_client(s->resource)), "explorer.exe")) continue; + add_tree(&dl, s, s->placed ? s->x : 0, s->placed ? s->y : 0, 0); + } + + int rendered = 0; + int fx_on = vkp_effects_active(); + int framegen = vkp_framegen_active(); + /* HDR (see hdr_plan): route 0 = the old paths below; 1 / 2 = composed; 3 = layer only, effects and + * frame generation skipped. Always 0 while the HDR gate is closed: nothing changes for that session. */ + struct hdr_scene hs; + int hdr_route = hdr_plan(&dl, w, h, fx_on, framegen, &hs); + const char *hdr_copy = NULL; /* why this scene's HDR frames (if any) took the copy path */ + if (banner_color_hdr_open()) { + hdr_note_route(hdr_route, &hs); + hdr_note_precedence(hdr_route == 3 ? hs.who : NULL, fx_on, framegen); + } + if (hdr_route == 3) { fx_on = 0; framegen = 0; } + if (hdr_route == 1) { + static int fell_back; + vkp_apply_window_request(); + sc_layer_hide_overlay(); + if (sc_layer_present_hdr_scene(dl.d, dl.n, &hs.hf, w, h, hs.color) == 0) { + rendered = vkp_base_black(w, h) == 0; /* black under the composed picture, presented only when it is not already */ + if (fell_back) { fell_back = 0; banner_log("color", "the composed picture is on the game's display layer again"); } + } else { + hdr_route = 2; /* no layer this frame: the picture goes through the swapchain instead */ + if (!fell_back) { + fell_back = 1; + banner_log("color", "the composed picture could not go on the game's display layer (no layer, or the " + "10-bit pass failed): it goes through the screen swapchain instead until that changes"); + } + } + } + if (hdr_route == 2) { + int how = 0; + sc_layer_hide(); + rendered = vkp_render_hdr(w, h, dl.d, dl.n, &hs.hf, &how) == 0; + copy = 1; + if (rendered && how == 1) banner_color_frame_shown(hs.color, BANNER_HDR_SWAPCHAIN, 0); + else if (rendered && how == 2) banner_color_frame_shown(hs.color, BANNER_HDR_TONEMAPPED, 0); + else if (rendered) hdr_copy = "the HDR composition pass is unavailable on this driver"; + } + if (hdr_route == 0 || hdr_route == 3) { + /* What still forces the whole scene back through the compositor pass (and so through the app's + * own swapchain), and what no longer does: + * - frame generation ALWAYS does: its extra frames each need a present of their own on + * consecutive vblanks, and a display layer latches one buffer per refresh; + * - screen effects do NOT any more when the game is alone on screen - the chain runs and its + * result is copied into the game layer's own gralloc buffer (sc_layer_present_pass), so the + * game keeps its layer and the display does the scene -> output mapping; + * - screen effects DO when a window is drawn above the game: the chain has to see the whole + * scene to look the way it does on the copy path, and here the game is only part of it. */ + const int pass_on = fx_on || framegen; + int li = (g_zero_copy && !framegen) ? layer_candidate(&dl, w, h) : -1; + int over = li >= 0 ? dl.n - 1 - li : 0; /* draws above the fullscreen game (0 or 1) */ + const int fx_blocks = (li >= 0 && fx_on && over > 0); + if (fx_blocks) { li = -1; over = 0; } + /* A window above the game needs a SECOND display layer, and on some displays that costs the + * hardware composition the first layer was worth having (sc_layer_overlay_affordable). Where it + * does, the whole scene goes down the copy path exactly as it did before the layer set existed. + * Decided HERE, before the game is committed to a layer: deciding it after the present would + * show the game layer and hide it again on every frame. */ + const int ov_blocks = (li >= 0 && over > 0 && !fx_blocks && !sc_layer_overlay_affordable()); + if (ov_blocks) { li = -1; over = 0; } + const int blocked = framegen ? 1 : (fx_blocks ? 2 : (ov_blocks ? 3 : 0)); + if (g_zero_copy && blocked != g_zero_copy_paused) { + g_zero_copy_paused = blocked; + if (blocked == 1) + banner_log("framegen", "zero-copy paused: frame generation needs the compositor pass"); + else if (blocked == 2) + banner_log("effects", "zero-copy paused: a window above the game needs the compositor pass for the whole scene"); + else if (blocked == 3) + banner_log("layer", "zero-copy paused: a window above the game would need a second display layer, " + "which this display cannot compose in hardware - whole scene on the copy path"); + else + banner_log("effects", "zero-copy resumed: the game is back on its own display layer"); + } + struct surface *ls = li >= 0 ? surface_for_image(dl.d[li].img) : NULL; + /* A frame this renderer could not import can only be shown on the layer, effects or not. */ + if (li < 0) ls = ahb_layer_only_candidate(w, h); + /* HDR: the same, for a game's SUBSURFACE swapchain whose 10-bit frame the compositor could not + * import (NULL whenever the HDR gate is closed - nothing is ever noted then). */ + if (li < 0 && !ls) ls = hdr_unimported_fullscreen(&dl, w, h); + if (ls && pass_on && li < 0 && !g_zero_copy_fx_skip_said) { + g_zero_copy_fx_skip_said = 1; + banner_log(framegen ? "framegen" : "effects", + "the game's frames cannot be imported by the compositor: shown zero-copy, %s skipped", + framegen ? "frame generation" : "effects"); + } + if (li >= 0 || ls) { + /* Layer mode: the fullscreen window goes on the game layer and (at most) one window above + * it on the overlay layer; whatever is under the game is hidden by it, so the screen + * surface only needs to be black. The game's frame goes on its layer as is when it is one + * of the game's own AHardwareBuffers (zero-copy, ahb_swapchain.c), through the effects + * chain's result when a Look is on, else through one blit into the pool. If a layer can't + * take its frame, the whole scene is drawn the usual way. */ + /* The layers go up FIRST and the base surface's black frame is presented after them. The + * order matters: a present holds an acquired swapchain image, and the acquire semaphore is + * a vblank gate - putting the effects chain or the layer transaction behind it costs a + * whole refresh (measured on the Pocket FIT: 72 fps that way, 111 fps this way, with Retro + * CRT at 1920x1080). The window request the app may have left is applied here instead, + * since vkp_render no longer runs before the layer path. */ + vkp_apply_window_request(); + int r = -1; + /* The game's own buffer can only go on the layer AS IS - with a Look on, the frame has to + * go through the chain first, so the raw buffer is skipped in favour of the pass (a frame + * this renderer could not import has no draw, li < 0, and stays zero-copy with the effects + * skipped, said once above). */ + if (!(fx_on && li >= 0) && ls && ls->dmabuf_buf && ahb_swapchain_has_ahb(ls->dmabuf_buf)) + r = ahb_swapchain_present(ls->dmabuf_buf, ls, w, h); + if (r != 0 && li >= 0) + r = fx_on ? sc_layer_present_pass(&dl.d[li], 1, w, h) + : sc_layer_present(dl.d[li].img, w, h, ls ? banner_surface_color(ls) : NULL); + if (r == 0) { + if (ls) ls->drawn = 1; + /* The one window above the game keeps the game off the copy path entirely: it goes on + * its own layer, cropped and placed by the display. */ + int go[8], ov = 0; + if (over == 1 && li >= 0 && vkp_map_draw(&dl.d[li + 1], go)) + ov = sc_layer_present_overlay(dl.d[li + 1].img, go) == 0 ? 1 : -1; + if (ov <= 0) sc_layer_hide_overlay(); + if (ov < 0) { /* the overlay layer refused it: draw the whole scene the old way */ + sc_layer_hide(); + rendered = vkp_render(w, h, dl.d, dl.n) == 0; + copy = 1; + hdr_copy = "the overlay layer refused the window above it"; + } else { + /* Black under the opaque layers. It is a plain black frame (no effects, no frame + * generation on it: they would only run on black), and it is presented only when the + * base surface does not already show one - entering layer mode, after a copy-path or + * frame-generation frame, after a swapchain rebuild. Every other layer frame draws and + * presents nothing here: the display layers are all that changes on screen. This loop + * is paced by the Choreographer's ticks (on_vsync), not by this present. */ + rendered = vkp_base_black(w, h) == 0; + } + } else { + rendered = vkp_render(w, h, dl.d, dl.n) == 0; + copy = 1; + hdr_copy = "its display layer was unavailable this frame"; + } + } else { + sc_layer_hide(); + rendered = vkp_render(w, h, dl.d, dl.n) == 0; + copy = 1; + hdr_copy = ov_blocks ? "a window is above it and this display cannot compose a second layer in hardware" + : fx_blocks ? "a window is above it and screen effects need the whole scene" + : !g_zero_copy ? "zero-copy presentation is off" + : framegen ? "frame generation needs the compositor pass" + : "it is not the one fullscreen window (only that one gets its own display layer)"; + } + } /* routes 0 and 3 */ + free(hs.is_hdr); + if (hdr_copy && rendered && banner_color_hdr_open()) hdr_count_copied(&dl, hdr_copy); + if (rendered) { + int64_t t = now_ns(); + g_stat_frames++; + /* A surface outside the scene (role-less, not placed yet, a hidden helper window such + * as wined3d's device window) was not shown, so its feedback is discarded rather than + * left pending: a FIFO present waits on it, and a client blocked there never commits + * again. */ + wl_list_for_each(s, &g_surfaces, link) { + if (s->drawn) feedback_present_all(&s->feedback, t); + else feedback_discard_all(&s->feedback); + } + fire_all_frames(); + } else { + /* No output surface yet (or it went away): keep clients paced without it, now and on a + * timer that re-arms itself until a window is back (see pace_without_output). */ + pace_without_output(); + if (!g_frame_timer) + g_frame_timer = wl_event_loop_add_timer(wl_display_get_event_loop(g_display), + on_frame_timer, NULL); + if (g_frame_timer) wl_event_source_timer_update(g_frame_timer, 16); + } + free(dl.d); + wl_display_flush_clients(g_display); + if (rendered && copy) g_perf.copy_scenes++; + g_perf.scenes++; + const int64_t scene_ns = now_ns() - t_scene; + g_perf.scene_ns += scene_ns; + if (scene_ns > g_perf.scene_max_ns) g_perf.scene_max_ns = scene_ns; +} + +static int on_fallback_timer(void *data) { + g_fallback_armed = 0; + if (g_dirty) render_scene(); + return 0; +} + +static void schedule_render(void) { + g_dirty = 1; + if (!g_display) return; + /* With vsync ticks flowing the next tick renders; otherwise render on a timer. */ + if (g_last_vsync_ns && now_ns() - g_last_vsync_ns < 100000000LL) return; + if (g_fallback_armed) return; + if (!g_fallback_timer) + g_fallback_timer = wl_event_loop_add_timer(wl_display_get_event_loop(g_display), + on_fallback_timer, NULL); + if (!g_fallback_timer) return; + g_fallback_armed = 1; + wl_event_source_timer_update(g_fallback_timer, 8); +} + +/* A screen refresh (Choreographer tick): draw the newest state once. */ +static void on_vsync(int64_t frame_time_ns) { + int64_t now = now_ns(); + g_perf.ticks++; + if (g_last_vsync_ns) { + int64_t d = now - g_last_vsync_ns; + if (d > 3000000LL && d < 40000000LL) g_refresh_ns = (g_refresh_ns * 7 + d) / 8; + } + g_last_vsync_ns = now; + (void)frame_time_ns; + /* The app's surface may have been replaced or taken away since the last frame: apply that now + * (the app never waits for us), and redraw the scene onto a new one. */ + if (vkp_apply_window_request()) g_dirty = 1; + /* A screen-effect setting changed (JNI, any thread): redraw so it shows on a static scene too. */ + if (vkp_effects_sync()) g_dirty = 1; + if (g_dirty) render_scene(); +} + +/* ------------------------------------------------------------------ wl_seat */ + +static uint32_t now_ms(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); +} + +static void pointer_set_cursor(struct wl_client *c, struct wl_resource *r, uint32_t serial, + struct wl_resource *surface, int32_t hx, int32_t hy) { + /* The app draws its own pointer; cursor surfaces stay role-less and aren't drawn. */ +} +static void pointer_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct wl_pointer_interface pointer_impl = { + .set_cursor = pointer_set_cursor, .release = pointer_release, +}; +static void pointer_res_destroy(struct wl_resource *r) { + constraints_pointer_gone(r); + relative_pointers_pointer_gone(r); + for (int i = 0; i < g_nptrs; i++) + if (g_ptrs[i].ptr == r) { g_ptrs[i] = g_ptrs[--g_nptrs]; break; } +} + +static void keyboard_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct wl_keyboard_interface keyboard_impl = { .release = keyboard_release }; +static void keyboard_res_destroy(struct wl_resource *r) { + for (int i = 0; i < g_nkbs; i++) + if (g_kbs[i].kb == r) { g_kbs[i] = g_kbs[--g_nkbs]; break; } +} +static void touch_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct wl_touch_interface touch_impl = { .release = touch_release }; + +static void seat_get_pointer(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *p = wl_resource_create(c, &wl_pointer_interface, wl_resource_get_version(r), id); + if (!p) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(p, &pointer_impl, NULL, pointer_res_destroy); + if (g_nptrs < MAX_PTRS) { g_ptrs[g_nptrs].ptr = p; g_ptrs[g_nptrs].focus = NULL; g_nptrs++; } +} +static void seat_get_keyboard(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *k = wl_resource_create(c, &wl_keyboard_interface, wl_resource_get_version(r), id); + if (!k) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(k, &keyboard_impl, NULL, keyboard_res_destroy); + if (g_nkbs < MAX_PTRS) { g_kbs[g_nkbs].kb = k; g_kbs[g_nkbs].focus = NULL; g_nkbs++; } + /* Send the xkb keymap the app extracted to $XDG_RUNTIME_DIR/keymap.xkb. Without a keymap the + * client can't interpret our evdev key codes. */ + const char *rt = getenv("XDG_RUNTIME_DIR"); + char path[512]; + snprintf(path, sizeof(path), "%s/keymap.xkb", rt ? rt : "."); + int fd = open(path, O_RDONLY | O_CLOEXEC); + if (fd >= 0) { + struct stat st; + if (fstat(fd, &st) == 0 && st.st_size > 0) + wl_keyboard_send_keymap(k, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, fd, (uint32_t)st.st_size); + close(fd); + } else { + WLOGE("keymap open failed: %s", path); + } + if (wl_resource_get_version(k) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) + wl_keyboard_send_repeat_info(k, 25, 500); +} +static void seat_get_touch(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *t = wl_resource_create(c, &wl_touch_interface, wl_resource_get_version(r), id); + if (t) wl_resource_set_implementation(t, &touch_impl, NULL, NULL); +} +static void seat_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct wl_seat_interface seat_impl = { + .get_pointer = seat_get_pointer, .get_keyboard = seat_get_keyboard, + .get_touch = seat_get_touch, .release = seat_release, +}; +static void bind_seat(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wl_seat_interface, ver, id); + wl_resource_set_implementation(r, &seat_impl, NULL, NULL); + wl_seat_send_capabilities(r, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD); + if (ver >= 2) wl_seat_send_name(r, "bannerlator-seat"); +} + +static struct seat_pointer *pointer_for(struct wl_client *client) { + for (int i = 0; i < g_nptrs; i++) + if (wl_resource_get_client(g_ptrs[i].ptr) == client) return &g_ptrs[i]; + return NULL; +} +static struct seat_keyboard *keyboard_for(struct wl_client *client) { + for (int i = 0; i < g_nkbs; i++) + if (wl_resource_get_client(g_kbs[i].kb) == client) return &g_kbs[i]; + return NULL; +} + +/* A client may hold more than one wl_pointer/wl_keyboard: gamescope creates a second pair and + * reads input on its own thread, so an event sent only to the first object is never seen. + * Every delivery below walks all of the client's objects. */ +#define for_each_pointer_of(client, sp) \ + for (int _i = 0; _i < g_nptrs; _i++) \ + if (((sp) = &g_ptrs[_i]), wl_resource_get_client((sp)->ptr) == (client)) +#define for_each_keyboard_of(client, sk) \ + for (int _i = 0; _i < g_nkbs; _i++) \ + if (((sk) = &g_kbs[_i]), wl_resource_get_client((sk)->kb) == (client)) + +/* Topmost window whose scene rectangle contains the point (no-desktop fallback). */ +static struct surface *toplevel_at(double x, double y) { + struct surface *s; + wl_list_for_each_reverse(s, &g_toplevels, toplevel_link) { + int w, h, sx = s->placed ? s->x : 0, sy = s->placed ? s->y : 0; + surface_size(s, &w, &h); + if (x >= sx && y >= sy && x < sx + w && y < sy + h) return s; + } + return NULL; +} + +static void pointer_focus(struct wl_resource *target, wl_fixed_t fx, wl_fixed_t fy) { + struct wl_client *client = wl_resource_get_client(target); + for (int i = 0; i < g_nptrs; i++) { + if (!g_ptrs[i].focus || g_ptrs[i].focus == target) continue; + wl_pointer_send_leave(g_ptrs[i].ptr, wl_display_next_serial(g_display), g_ptrs[i].focus); + if (wl_resource_get_version(g_ptrs[i].ptr) >= WL_POINTER_FRAME_SINCE_VERSION) + wl_pointer_send_frame(g_ptrs[i].ptr); + g_ptrs[i].focus = NULL; + } + struct seat_pointer *sp; + int entered = 0; + for_each_pointer_of(client, sp) { + if (sp->focus == target) continue; + sp->focus = target; + wl_pointer_send_enter(sp->ptr, wl_display_next_serial(g_display), target, fx, fy); + entered = 1; + } + if (entered) constraints_focus_entered(target, client); +} + +static void keyboard_focus(struct wl_resource *target) { + struct wl_client *client = wl_resource_get_client(target); + struct seat_keyboard *sk; + int need = 0; + for_each_keyboard_of(client, sk) if (sk->focus != target) need = 1; + if (!need) return; + for (int i = 0; i < g_nkbs; i++) { + if (!g_kbs[i].focus || g_kbs[i].focus == target) continue; + wl_keyboard_send_leave(g_kbs[i].kb, wl_display_next_serial(g_display), g_kbs[i].focus); + g_kbs[i].focus = NULL; + } + struct wl_array keys; + wl_array_init(&keys); + for_each_keyboard_of(client, sk) { + if (sk->focus == target) continue; + sk->focus = target; + wl_keyboard_send_enter(sk->kb, wl_display_next_serial(g_display), target, &keys); + /* Baseline modifiers = none; Shift/Ctrl arrive as their own key events. */ + wl_keyboard_send_modifiers(sk->kb, wl_display_next_serial(g_display), 0, 0, 0, 0); + } + wl_array_release(&keys); + banner_clipboard_keyboard_focus(client); /* wl_data_device selection follows focus */ +} + +/* ------------------------------------------------------------------ pointer constraints + * zwp_pointer_constraints_v1 and zwp_relative_pointer_manager_v1: what winewayland uses for + * SetCursorPos, ClipCursor and hidden-cursor (mouse-look) games. + * + * A lock freezes the pointer where it is: no wl_pointer.motion is sent while it holds, and + * every input delta (a relative event from the app, or the difference between absolute + * positions) reaches the locking program as zwp_relative_pointer_v1.relative_motion. A confine + * clamps the pointer to the surface (and the program's region inside it). Relative motion is + * also sent while unlocked, to any program holding a relative pointer. + * + * Input normally goes to the desktop surface; while a constraint holds, pointer focus moves + * to the constrained surface, so the constraining program receives the events itself + * (winewayland only enables relative motion for a window its pointer has entered). One + * constraint holds at a time; a newer request ends the older one. A lock's cursor position + * hint is applied on the surface's commit and is where the pointer ends up when the lock + * ends (winewayland's SetCursorPos: lock, hint, commit, unlock). */ + +struct constraint { + struct wl_list link; /* g_constraints */ + struct wl_resource *resource; /* zwp_locked_pointer_v1 or zwp_confined_pointer_v1 */ + struct wl_resource *pointer; /* the program's wl_pointer; NULL once released */ + struct surface *surface; /* NULL once the surface is gone */ + int is_lock; + uint32_t lifetime; + int active; + int defunct; /* a oneshot that ended, or surface/pointer gone */ + struct region region, pending_region; /* confine area, surface-local; unset = whole surface */ + int pending_region_set; + int hint_set, pending_hint_set; /* lock: cursor position hint, surface-local */ + double hint_x, hint_y, pending_hint_x, pending_hint_y; +}; +static struct wl_list g_constraints; +static struct constraint *g_active_constraint; + +struct relative_pointer { + struct wl_list link; /* g_relative_pointers */ + struct wl_resource *resource; + struct wl_resource *pointer; /* the program's wl_pointer; NULL once released */ +}; +static struct wl_list g_relative_pointers; + +/* Last pointer position in scene coordinates (buttons and scrolls from the app's X-server + * input path arrive without one). */ +static double g_ptr_x, g_ptr_y; +/* Last absolute input position: absolute input becomes deltas while the pointer is locked. */ +static double g_raw_x, g_raw_y; +static int g_raw_valid; + +/* JNI: the app switches its touch/mouse path to deltas while a lock holds and re-syncs its + * pointer to x,y when it ends. */ +extern void banner_on_pointer_lock(int locked, int x, int y); + +static void sync_lock_notify(void) { + static int last; + int locked = g_active_constraint && g_active_constraint->is_lock; + if (locked == last) return; + last = locked; + banner_on_pointer_lock(locked, (int)g_ptr_x, (int)g_ptr_y); +} + +static void constraint_describe(const struct constraint *k, char *out, size_t size) { + if (k->surface) describe(k->surface, out, size); + else snprintf(out, size, "a closed window"); +} + +/* Scene position of the constrained surface. */ +static void constraint_origin(const struct constraint *k, int *x, int *y) { + *x = *y = 0; + if (k->surface && k->surface != g_desktop && k->surface->placed) { *x = k->surface->x; *y = k->surface->y; } +} + +/* Keep x,y (scene coordinates) inside the confine area. */ +static void confine_clamp(const struct constraint *k, double *x, double *y) { + int ox, oy, w, h, rx = 0, ry = 0, rw, rh; + if (!k->surface) return; + constraint_origin(k, &ox, &oy); + surface_size(k->surface, &w, &h); + rw = w; rh = h; + if (k->region.set) { + int x2 = rx + rw < k->region.x + k->region.w ? rx + rw : k->region.x + k->region.w; + int y2 = ry + rh < k->region.y + k->region.h ? ry + rh : k->region.y + k->region.h; + if (k->region.x > rx) rx = k->region.x; + if (k->region.y > ry) ry = k->region.y; + rw = x2 - rx; rh = y2 - ry; + } + if (rw <= 0 || rh <= 0) return; + if (*x < ox + rx) *x = ox + rx; + if (*x > ox + rx + rw - 1) *x = ox + rx + rw - 1; + if (*y < oy + ry) *y = oy + ry; + if (*y > oy + ry + rh - 1) *y = oy + ry + rh - 1; +} + +static void constraint_send_state(struct constraint *k, int on) { + if (k->is_lock) { + if (on) zwp_locked_pointer_v1_send_locked(k->resource); + else zwp_locked_pointer_v1_send_unlocked(k->resource); + } else { + if (on) zwp_confined_pointer_v1_send_confined(k->resource); + else zwp_confined_pointer_v1_send_unconfined(k->resource); + } +} + +/* A constraint stops holding. tell_client = 0 when its resource is being destroyed. */ +static void constraint_end(struct constraint *k, int tell_client, const char *why) { + char name[160]; + if (!k->active) return; + k->active = 0; + if (g_active_constraint == k) g_active_constraint = NULL; + if (k->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) k->defunct = 1; + if (k->is_lock && k->hint_set && k->surface) { + int ox, oy; + constraint_origin(k, &ox, &oy); + g_ptr_x = ox + k->hint_x; + g_ptr_y = oy + k->hint_y; + } + g_raw_valid = 0; + if (tell_client) constraint_send_state(k, 0); + constraint_describe(k, name, sizeof(name)); + banner_log("pointer", "%s: %s (%s), pointer at %d,%d", k->is_lock ? "unlocked" : "unconfined", + name, why, (int)g_ptr_x, (int)g_ptr_y); + sync_lock_notify(); +} + +static void constraint_activate(struct constraint *k) { + char name[160]; + int ox, oy; + if (k->active || k->defunct || !k->surface || !k->pointer) return; + if (g_active_constraint && g_active_constraint != k) + constraint_end(g_active_constraint, 1, "replaced by a newer request"); + k->active = 1; + g_active_constraint = k; + if (!k->is_lock) confine_clamp(k, &g_ptr_x, &g_ptr_y); + /* Pointer focus follows the constraint: the program gets the events itself. */ + constraint_origin(k, &ox, &oy); + pointer_focus(k->surface->resource, wl_fixed_from_double(g_ptr_x - ox), wl_fixed_from_double(g_ptr_y - oy)); + constraint_send_state(k, 1); + constraint_describe(k, name, sizeof(name)); + if (k->is_lock) + banner_log("pointer", "locked: %s (%s), pointer frozen at %d,%d", name, + k->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT ? "oneshot" : "persistent", + (int)g_ptr_x, (int)g_ptr_y); + else if (k->region.set) + banner_log("pointer", "confined: %s (%s) to %dx%d at %d,%d of the window", name, + k->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT ? "oneshot" : "persistent", + k->region.w, k->region.h, k->region.x, k->region.y); + else + banner_log("pointer", "confined: %s (%s) to the whole window", name, + k->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT ? "oneshot" : "persistent"); + sync_lock_notify(); + wl_display_flush_clients(g_display); +} + +/* Pointer focus entered target: a persistent constraint waiting on it takes hold again. */ +static void constraints_focus_entered(struct wl_resource *target, struct wl_client *client) { + struct constraint *k; + if (g_active_constraint) return; + wl_list_for_each(k, &g_constraints, link) { + if (k->active || k->defunct || !k->surface || !k->pointer) continue; + if (k->surface->resource != target || wl_resource_get_client(k->pointer) != client) continue; + constraint_activate(k); + return; + } +} + +static void constraints_surface_gone(struct surface *s) { + struct constraint *k; + wl_list_for_each(k, &g_constraints, link) { + if (k->surface != s) continue; + constraint_end(k, 1, "window closed"); + k->surface = NULL; + k->defunct = 1; + } +} + +static void constraints_pointer_gone(struct wl_resource *pointer) { + struct constraint *k; + wl_list_for_each(k, &g_constraints, link) { + if (k->pointer != pointer) continue; + constraint_end(k, 1, "pointer released"); + k->pointer = NULL; + k->defunct = 1; + } +} + +/* Double-buffered state (position hint, confine region) applies on the surface's commit. */ +static void constraints_surface_commit(struct surface *s) { + struct constraint *k; + wl_list_for_each(k, &g_constraints, link) { + if (k->surface != s) continue; + if (k->pending_hint_set) { + k->hint_set = 1; + k->hint_x = k->pending_hint_x; + k->hint_y = k->pending_hint_y; + k->pending_hint_set = 0; + if (k->active && k->is_lock) { + int ox, oy; + constraint_origin(k, &ox, &oy); + g_ptr_x = ox + k->hint_x; + g_ptr_y = oy + k->hint_y; + if (log_budget()) + banner_log("pointer", "position hint: pointer moved to %d,%d", (int)g_ptr_x, (int)g_ptr_y); + } + } + if (k->pending_region_set) { + k->region = k->pending_region; + k->pending_region_set = 0; + if (k->active && !k->is_lock) confine_clamp(k, &g_ptr_x, &g_ptr_y); + } + } +} + +static void constraint_resource_destroy(struct wl_resource *r) { + struct constraint *k = wl_resource_get_user_data(r); + if (!k) return; + constraint_end(k, 0, "released by the program"); + wl_list_remove(&k->link); + free(k); +} + +static void constraint_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void locked_pointer_set_cursor_position_hint(struct wl_client *c, struct wl_resource *r, + wl_fixed_t x, wl_fixed_t y) { + struct constraint *k = wl_resource_get_user_data(r); + if (!k) return; + k->pending_hint_set = 1; + k->pending_hint_x = wl_fixed_to_double(x); + k->pending_hint_y = wl_fixed_to_double(y); +} +static void locked_pointer_set_region(struct wl_client *c, struct wl_resource *r, struct wl_resource *region) { + /* A lock's region only says where it may take hold; a lock here takes hold anywhere. */ +} +static const struct zwp_locked_pointer_v1_interface locked_pointer_impl = { + .destroy = constraint_destroy_req, + .set_cursor_position_hint = locked_pointer_set_cursor_position_hint, + .set_region = locked_pointer_set_region, +}; +static void confined_pointer_set_region(struct wl_client *c, struct wl_resource *r, struct wl_resource *region) { + struct constraint *k = wl_resource_get_user_data(r); + struct region *rg = region ? wl_resource_get_user_data(region) : NULL; + if (!k) return; + k->pending_region_set = 1; + if (rg) k->pending_region = *rg; + else memset(&k->pending_region, 0, sizeof(k->pending_region)); +} +static const struct zwp_confined_pointer_v1_interface confined_pointer_impl = { + .destroy = constraint_destroy_req, + .set_region = confined_pointer_set_region, +}; + +static void constraint_create(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface_res, struct wl_resource *pointer_res, + struct wl_resource *region_res, uint32_t lifetime, int is_lock) { + struct surface *s = wl_resource_get_user_data(surface_res); + struct constraint *k; + struct wl_resource *res; + char name[160]; + + wl_list_for_each(k, &g_constraints, link) { + if (k->defunct || k->surface != s || k->pointer != pointer_res) continue; + wl_resource_post_error(r, ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED, + "the surface already has a pointer constraint for this pointer"); + return; + } + res = wl_resource_create(c, is_lock ? &zwp_locked_pointer_v1_interface : &zwp_confined_pointer_v1_interface, + wl_resource_get_version(r), id); + if (!res || !(k = calloc(1, sizeof(*k)))) { wl_client_post_no_memory(c); return; } + k->resource = res; + k->pointer = pointer_res; + k->surface = s; + k->is_lock = is_lock; + k->lifetime = lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT + ? ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT : ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT; + if (!is_lock && region_res) { + struct region *rg = wl_resource_get_user_data(region_res); + if (rg) k->region = *rg; + } + wl_resource_set_implementation(res, is_lock ? (const void *)&locked_pointer_impl : (const void *)&confined_pointer_impl, + k, constraint_resource_destroy); + wl_list_insert(g_constraints.prev, &k->link); + if (!s) { k->defunct = 1; return; } + constraint_describe(k, name, sizeof(name)); + banner_log("pointer", "%s requested by %s for %s", is_lock ? "lock" : "confine", client_name(c), name); + constraint_activate(k); +} + +static void pointer_constraints_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void pointer_constraints_lock_pointer(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface, struct wl_resource *pointer, + struct wl_resource *region, uint32_t lifetime) { + constraint_create(c, r, id, surface, pointer, region, lifetime, 1); +} +static void pointer_constraints_confine_pointer(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *surface, struct wl_resource *pointer, + struct wl_resource *region, uint32_t lifetime) { + constraint_create(c, r, id, surface, pointer, region, lifetime, 0); +} +static const struct zwp_pointer_constraints_v1_interface pointer_constraints_impl = { + .destroy = pointer_constraints_destroy, + .lock_pointer = pointer_constraints_lock_pointer, + .confine_pointer = pointer_constraints_confine_pointer, +}; +static void bind_pointer_constraints(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &zwp_pointer_constraints_v1_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &pointer_constraints_impl, NULL, NULL); +} + +/* --- relative pointers --- */ + +static void relative_pointer_resource_destroy(struct wl_resource *r) { + struct relative_pointer *rp = wl_resource_get_user_data(r); + if (!rp) return; + banner_log("pointer", "relative pointer released by %s", client_name(wl_resource_get_client(r))); + wl_list_remove(&rp->link); + free(rp); +} +static void relative_pointer_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct zwp_relative_pointer_v1_interface relative_pointer_impl = { + .destroy = relative_pointer_destroy_req, +}; + +static void relative_pointer_manager_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void relative_pointer_manager_get(struct wl_client *c, struct wl_resource *r, uint32_t id, + struct wl_resource *pointer) { + struct wl_resource *res = wl_resource_create(c, &zwp_relative_pointer_v1_interface, wl_resource_get_version(r), id); + struct relative_pointer *rp; + if (!res || !(rp = calloc(1, sizeof(*rp)))) { wl_client_post_no_memory(c); return; } + rp->resource = res; + rp->pointer = pointer; + wl_resource_set_implementation(res, &relative_pointer_impl, rp, relative_pointer_resource_destroy); + wl_list_insert(g_relative_pointers.prev, &rp->link); + banner_log("pointer", "relative pointer created for %s (motion arrives as deltas)", client_name(c)); +} +static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_impl = { + .destroy = relative_pointer_manager_destroy, + .get_relative_pointer = relative_pointer_manager_get, +}; +static void bind_relative_pointer_manager(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &zwp_relative_pointer_manager_v1_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &relative_pointer_manager_impl, NULL, NULL); +} + +static void relative_pointers_pointer_gone(struct wl_resource *pointer) { + struct relative_pointer *rp; + wl_list_for_each(rp, &g_relative_pointers, link) + if (rp->pointer == pointer) rp->pointer = NULL; +} + +/* relative_motion to every relative pointer of the program owning the focus (winewayland wants + * it whenever it holds one, locked or not). Returns whether any was sent. */ +static int send_relative_motion(struct wl_client *client, double dx, double dy) { + struct relative_pointer *rp; + struct timespec ts; + uint64_t ut; + int sent = 0; + if (dx == 0 && dy == 0) return 0; + clock_gettime(CLOCK_MONOTONIC, &ts); + ut = (uint64_t)ts.tv_sec * 1000000ULL + (uint64_t)ts.tv_nsec / 1000; + wl_list_for_each(rp, &g_relative_pointers, link) { + if (!rp->pointer || wl_resource_get_client(rp->pointer) != client) continue; + zwp_relative_pointer_v1_send_relative_motion(rp->resource, (uint32_t)(ut >> 32), (uint32_t)ut, + wl_fixed_from_double(dx), wl_fixed_from_double(dy), + wl_fixed_from_double(dx), wl_fixed_from_double(dy)); + sent = 1; + } + return sent; +} + +/* ------------------------------------------------------------------ pointer events */ + +/* One pointer event: a motion, then an optional button change (button 0 = none). Absolute + * x,y are scene coordinates; with `relative` they are a delta. While a lock holds the pointer + * stays put and the delta (or the change between absolute positions) becomes relative motion + * for the locking program; a confine keeps the pointer inside its area. */ +static void pointer_input(double x, double y, int relative, uint32_t button, int pressed) { + struct surface *target; + struct constraint *k = g_active_constraint; + double dx, dy; + + if (relative) { + dx = x; dy = y; + } else { + dx = g_raw_valid ? x - g_raw_x : 0; + dy = g_raw_valid ? y - g_raw_y : 0; + g_raw_x = x; g_raw_y = y; g_raw_valid = 1; + } + + if (k && k->is_lock) { + target = k->surface; + } else { + if (relative) { + int w, h; + scene_size(&w, &h); + x = g_ptr_x + dx; y = g_ptr_y + dy; + if (x < 0) x = 0; + if (y < 0) y = 0; + if (x > w - 1) x = w - 1; + if (y > h - 1) y = h - 1; + } + if (k) confine_clamp(k, &x, &y); + g_ptr_x = x; g_ptr_y = y; + if (k) { + target = k->surface; + } else if (g_desktop) { + target = g_desktop; + } else { + target = g_grab ? g_grab : toplevel_at(x, y); + if (button && pressed) { g_grab = target; g_key_target = target; } + if (button && !pressed) g_grab = NULL; + } + } + if (!target) return; + + struct wl_client *client = wl_resource_get_client(target->resource); + struct seat_pointer *sp; + if (!pointer_for(client)) return; + int tx = 0, ty = 0; + if (target != g_desktop && target->placed) { tx = target->x; ty = target->y; } + wl_fixed_t fx = wl_fixed_from_double(g_ptr_x - tx), fy = wl_fixed_from_double(g_ptr_y - ty); + uint32_t t = now_ms(); + + pointer_focus(target->resource, fx, fy); + if (!(k && k->is_lock)) + for_each_pointer_of(client, sp) wl_pointer_send_motion(sp->ptr, t, fx, fy); + send_relative_motion(client, dx, dy); + for_each_pointer_of(client, sp) { + if (button) + wl_pointer_send_button(sp->ptr, wl_display_next_serial(g_display), t, button, + pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED); + if (wl_resource_get_version(sp->ptr) >= WL_POINTER_FRAME_SINCE_VERSION) + wl_pointer_send_frame(sp->ptr); + } + /* A click lands text input (the soft keyboard's IME text) on the window under the pointer: + * that's where Wine's focus goes, and winewayland routes IME updates per process. */ + if (button && pressed && !(k && k->is_lock)) { + struct surface *clicked = toplevel_at(g_ptr_x, g_ptr_y); + if (clicked) g_ime_click = clicked; + banner_text_input_refocus(); + } + wl_display_flush_clients(g_display); +} + +/* Absolute motion to scene x,y, then an optional button change. */ +static void pointer_event(double x, double y, uint32_t button, int pressed) { + pointer_input(x, y, 0, button, pressed); +} + +/* A delta from the app's relative input path (Relative Mouse, captured mouse, stick-as-mouse). */ +static void pointer_delta(double dx, double dy) { + pointer_input(dx, dy, 1, 0, 0); +} + +/* A button change at the current pointer position. */ +static void pointer_button(uint32_t button, int pressed) { + pointer_input(0, 0, 1, button, pressed); +} + +/* Java touch events arrive in INPUT_SPACE over the whole output: action 0=press, 1=move, 2=release. + * Output pixels go through the inverse of the scale mode's mapping (letterbox bars, FILL crop, a + * TOP/BOTTOM half), so the touch lands on the scene pixel that is drawn under the finger. */ +static void deliver_pointer(const struct input_msg *m) { + int w, h, ow, oh; + double x, y; + scene_size(&w, &h); + vkp_output_size(&ow, &oh); + if (ow <= 0 || oh <= 0 || + !vkp_output_to_scene((double)m->p2 * ow / INPUT_SPACE_W, (double)m->p3 * oh / INPUT_SPACE_H, &x, &y)) { + x = (double)m->p2 * w / INPUT_SPACE_W; /* nothing drawn yet: plain stretch */ + y = (double)m->p3 * h / INPUT_SPACE_H; + } + if (x < 0) x = 0; + if (y < 0) y = 0; + if (x > w - 1) x = w - 1; + if (y > h - 1) y = h - 1; + pointer_event(x, y, m->p1 == 1 ? 0 : BTN_LEFT, m->p1 == 0); +} + +static void key_event(uint32_t evdev, int pressed); +struct wl_resource *banner_ime_target(void); +static void deliver_key(const struct input_msg *m) { + key_event((uint32_t)m->p1, m->p2); +} + +/* Vertical wheel steps (negative = up) at the current pointer position. */ +static void scroll_event(int steps) { + struct surface *target = g_active_constraint ? g_active_constraint->surface + : g_desktop ? g_desktop : (g_grab ? g_grab : toplevel_at(g_ptr_x, g_ptr_y)); + if (!target || !steps) return; + struct wl_client *client = wl_resource_get_client(target->resource); + struct seat_pointer *sp; + if (!pointer_for(client)) return; + int tx = 0, ty = 0; + if (target != g_desktop && target->placed) { tx = target->x; ty = target->y; } + uint32_t t = now_ms(); + pointer_focus(target->resource, wl_fixed_from_double(g_ptr_x - tx), wl_fixed_from_double(g_ptr_y - ty)); + for_each_pointer_of(client, sp) { + /* From version 8 the discrete event is replaced by value120 and must not be sent. */ + if (wl_resource_get_version(sp->ptr) >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION) + wl_pointer_send_axis_value120(sp->ptr, WL_POINTER_AXIS_VERTICAL_SCROLL, steps * 120); + else if (wl_resource_get_version(sp->ptr) >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) + wl_pointer_send_axis_discrete(sp->ptr, WL_POINTER_AXIS_VERTICAL_SCROLL, steps); + wl_pointer_send_axis(sp->ptr, t, WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(steps * 10)); + if (wl_resource_get_version(sp->ptr) >= WL_POINTER_FRAME_SINCE_VERSION) + wl_pointer_send_frame(sp->ptr); + } + wl_display_flush_clients(g_display); +} + +static void key_event(uint32_t evdev, int pressed) { + /* Keys go to the program window the user last clicked (else the topmost non-shell window), + * never to Wine's desktop surface: winewayland hands each key to the hwnd of the surface that + * holds keyboard focus, and a key handed to explorer's desktop hwnd is queued to explorer's + * thread, not to the foreground program (X11 delivers keys to the focused app window, so + * this mirrors it). The desktop itself is the last resort. */ + struct surface *target = NULL; + struct wl_resource *ime = banner_ime_target(); + if (ime) target = wl_resource_get_user_data(ime); + if (!target && g_key_target && g_key_target->mapped && g_key_target != g_desktop) target = g_key_target; + if (!target) target = g_desktop; + if (!target) { + struct surface *s; + wl_list_for_each_reverse(s, &g_toplevels, toplevel_link) { target = s; break; } + } + if (!target) return; + struct wl_client *client = wl_resource_get_client(target->resource); + struct seat_keyboard *sk; + if (!keyboard_for(client)) return; + keyboard_focus(target->resource); + for_each_keyboard_of(client, sk) + wl_keyboard_send_key(sk->kb, wl_display_next_serial(g_display), now_ms(), evdev, + pressed ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED); + wl_display_flush_clients(g_display); +} + +/* wl event-loop callback: drain queued input events written by the Android UI thread. */ +static int on_input_readable(int fd, uint32_t mask, void *data) { + struct input_msg m; + while (read(fd, &m, sizeof(m)) == (ssize_t)sizeof(m)) { + switch (m.type) { + case 1: deliver_key(&m); break; + case 2: pointer_event(m.p1, m.p2, 0, 0); break; /* scene motion */ + case 3: pointer_button(m.p1, m.p2); break; /* button at pointer */ + case 4: scroll_event(m.p1); break; + case 5: on_vsync(((int64_t)m.p1 << 32) | (uint32_t)m.p2); break; + case 6: pointer_delta(m.p1 / 256.0, m.p2 / 256.0); break; /* relative motion, 1/256 px */ + default: deliver_pointer(&m); break; + } + } + return 0; +} + +/* Called from JNI (Android UI thread). Queues a pointer event; the compositor thread + * dispatches it. x/y are in INPUT_SPACE (0..1919, 0..1079) over the whole output. */ +void banner_wayland_send_pointer(int action, int x, int y) { + if (g_input_pipe[1] < 0) return; + struct input_msg m = { 0, action, x, y }; + ssize_t n = write(g_input_pipe[1], &m, sizeof(m)); + (void)n; +} + +/* Called from JNI. Queues a key event. evdev = Linux input keycode (e.g. KEY_A=30); state 1=down 0=up. */ +void banner_wayland_send_key(int evdev, int state) { + if (g_input_pipe[1] < 0) return; + struct input_msg m = { 1, evdev, state, 0 }; + ssize_t n = write(g_input_pipe[1], &m, sizeof(m)); + (void)n; +} + +/* Called from JNI on every screen refresh (Choreographer). */ +void banner_wayland_vsync(int64_t frame_time_ns) { + if (g_input_pipe[1] < 0) return; + struct input_msg m = { 5, (int)(frame_time_ns >> 32), (int)(uint32_t)frame_time_ns, 0 }; + ssize_t n = write(g_input_pipe[1], &m, sizeof(m)); + (void)n; +} + +/* Called from JNI with the app's X-server input (on-screen controls, mouse): type 2 = motion + * to scene x,y; 3 = evdev button a pressed/released (b); 4 = a wheel steps (negative = up); + * 6 = relative motion by a,b in 1/256 pixel (the app's Relative Mouse / captured-mouse path). */ +void banner_wayland_send_scene_input(int type, int a, int b) { + if (g_input_pipe[1] < 0) return; + struct input_msg m = { type, a, b, 0 }; + ssize_t n = write(g_input_pipe[1], &m, sizeof(m)); + (void)n; +} + +/* ------------------------------------------------------------------ extension module hooks + * What wl_clipboard.c / wl_text_input.c need from the scene (see banner_ext.h). */ + +const char *banner_client_name(struct wl_client *client) { return client_name(client); } +struct wl_display *banner_get_display(void) { return g_display; } +void banner_request_redraw(void) { schedule_render(); } + +/* The surface text input follows: the last clicked mapped program window, else the topmost + * mapped window not owned by the desktop's process (explorer). NULL when there is none. */ +struct wl_resource *banner_ime_target(void) { + struct surface *s; + if (g_ime_click && g_ime_click->mapped) return g_ime_click->resource; + struct wl_client *shell = g_desktop ? wl_resource_get_client(g_desktop->resource) : NULL; + wl_list_for_each_reverse(s, &g_toplevels, toplevel_link) + if (!shell || wl_resource_get_client(s->resource) != shell) return s->resource; + return NULL; +} + +void banner_surface_scene_origin(struct wl_resource *surface, int *x, int *y) { + struct surface *s = surface ? wl_resource_get_user_data(surface) : NULL; + *x = 0; *y = 0; + if (s && s->placed) { *x = s->x; *y = s->y; } +} + +void banner_inject_key(uint32_t evdev, int pressed) { key_event(evdev, pressed); } + +/* ------------------------------------------------------------------ 10 s summary */ + +static struct wl_event_source *g_stats_timer; +/* The last window's zero-copy count, kept for the app (WaylandCompositor.nativeZeroCopyFrames). */ +volatile unsigned g_zero_copy_last; + +static int on_stats_timer(void *data) { + int windows = 0; + struct surface *s; + wl_list_for_each(s, &g_toplevels, toplevel_link) windows++; + unsigned zero_copy = ahb_swapchain_stats_take(); + unsigned layer_frames = sc_layer_frames_take(); + g_zero_copy_last = zero_copy; + /* Interpolated frames the compositor added (framegen_bridge.c). They are on screen, so they + * count there; they are NOT GPU frames from games and never inflate that number. */ + unsigned generated = vkp_framegen_stats_take(); + if (g_stat_frames || g_stat_dmabuf || g_stat_shm || generated) { + char extra[160] = ""; + int off = 0; + if (g_zero_copy || zero_copy) off += snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u zero-copy frames", zero_copy); + /* Frames the compositor put on a display layer through one of its OWN gralloc buffers (the + * plain layer blit, or the effects chain's result): still hardware-composed, but not + * zero-copy, so they are counted apart from the line above. */ + if (layer_frames) off += snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u layer frames", layer_frames); + if (generated) snprintf(extra + off, sizeof(extra) - (size_t)off, " | %u generated frames", generated); + banner_log("stats", "last 10 s: %u frames on screen (%.1f fps) | %u GPU frames from games | %u window redraws | %d windows open%s", + g_stat_frames + generated, (g_stat_frames + generated) / 10.0, g_stat_dmabuf, g_stat_shm, windows, extra); + } + /* The perf line, next to the stats line and only when something happened: the compositor thread's + * time per scene and inside the driver (avg/max), what the base surface did, and how long games + * waited for their buffers back. See the audit memory for how to read it. */ + { + struct vkp_perf vp; + vkp_perf_take(&vp); + const unsigned drops = sc_layer_drops_take(); +#define PERF_MS(sum, n) ((n) ? (double)(sum) / 1e6 / (double)(n) : 0.0) + if (g_perf.scenes || vp.presents || g_perf.releases || drops) + banner_log("perf", "last 10 s: %u ticks, %u scenes, %u on screen (copy %u, zero-copy %u, layer copy %u) | " + "render_scene %.2f/%.2f ms | base %u black kept, %u presented | acquire %.2f/%.2f ms | " + "present %.2f/%.2f ms (%u) | fence wait %.2f/%.2f ms (%u, %u GPU release waits) | " + "release %.2f/%.2f ms (%u, %u held) | %u pool drops", + g_perf.ticks, g_perf.scenes, g_stat_frames, g_perf.copy_scenes, zero_copy, layer_frames, + PERF_MS(g_perf.scene_ns, g_perf.scenes), (double)g_perf.scene_max_ns / 1e6, + vp.base_kept, vp.base_presents, + PERF_MS(vp.acquire_ns, vp.acquires), (double)vp.acquire_max_ns / 1e6, + PERF_MS(vp.present_ns, vp.presents), (double)vp.present_max_ns / 1e6, vp.presents, + PERF_MS(vp.wait_ns, vp.waits), (double)vp.wait_max_ns / 1e6, vp.waits, vp.gpu_release_waits, + PERF_MS(g_perf.release_ns, g_perf.releases), (double)g_perf.release_max_ns / 1e6, + g_perf.releases, g_perf.releases_held, drops); +#undef PERF_MS + memset(&g_perf, 0, sizeof(g_perf)); + } + g_stat_frames = g_stat_dmabuf = g_stat_shm = 0; + banner_color_stats_tick(); /* HDR evidence for the same window (nothing when the HDR gate is closed) */ + /* A program that asked for dma-buf feedback (EGL's GPU path does, first thing) but has drawn + * only wl_shm frames since is an OpenGL program whose EGL gave up on the GPU. The software + * path it fell to has no rasteriser in the Wayland layers, so what it commits is black. */ + for (struct client_info *ci = g_clients; ci; ci = ci->next) { + if (!ci->asked_feedback || ci->dmabuf_buffers || ci->shm_gl_said || ci->shm_frames < 150) + continue; + ci->shm_gl_said = 1; + banner_log("opengl", "%s asked for GPU buffers but has drawn only software (shared-memory) " + "frames: its OpenGL fell back to software rendering, which the Wayland layer cannot " + "draw - expect a black picture (main device %u:%u)", ci->name, + (unsigned)major(g_main_device), (unsigned)minor(g_main_device)); + } + wl_event_source_timer_update(g_stats_timer, 10000); + return 0; +} + +/* ------------------------------------------------------------------ test input + * $XDG_RUNTIME_DIR/test-input is a FIFO for scripted testing from a root shell, in scene + * (desktop) coordinates: "move X Y", "click X Y", "rclick X Y", "dclick X Y", "down X Y", + * "up X Y", "rdown X Y", "rup X Y", "rel DX DY" (relative motion, like the app's Relative + * Mouse path), "key CODE" (evdev), "keydown CODE", "keyup CODE". + * It lives in the app's private directory, so only the app and root can reach it. */ + +static char g_test_buf[512]; +static size_t g_test_len; + +static void test_input_line(const char *line) { + double x, y; + unsigned code; + char cmd[16]; + int n = sscanf(line, "%15s %lf %lf", cmd, &x, &y); + + if (n < 2) return; + banner_log("test", "input: %s", line); + if (!strcmp(cmd, "key") || !strcmp(cmd, "keydown") || !strcmp(cmd, "keyup")) { + code = (unsigned)x; + if (strcmp(cmd, "keyup")) key_event(code, 1); + if (strcmp(cmd, "keydown")) key_event(code, 0); + return; + } + if (n < 3) return; + if (!strcmp(cmd, "move")) pointer_event(x, y, 0, 0); + else if (!strcmp(cmd, "rel")) pointer_delta(x, y); + else if (!strcmp(cmd, "down")) pointer_event(x, y, BTN_LEFT, 1); + else if (!strcmp(cmd, "up")) pointer_event(x, y, BTN_LEFT, 0); + else if (!strcmp(cmd, "rdown")) pointer_event(x, y, BTN_RIGHT, 1); + else if (!strcmp(cmd, "rup")) pointer_event(x, y, BTN_RIGHT, 0); + else if (!strcmp(cmd, "click") || !strcmp(cmd, "rclick") || !strcmp(cmd, "dclick")) { + uint32_t button = cmd[0] == 'r' ? BTN_RIGHT : BTN_LEFT; + int times = cmd[0] == 'd' ? 2 : 1; + pointer_event(x, y, 0, 0); + for (int i = 0; i < times; i++) { + pointer_event(x, y, button, 1); + pointer_event(x, y, button, 0); + } + } +} + +static int on_test_input(int fd, uint32_t mask, void *data) { + ssize_t r; + while ((r = read(fd, g_test_buf + g_test_len, sizeof(g_test_buf) - 1 - g_test_len)) > 0) { + char *start = g_test_buf, *nl; + g_test_len += (size_t)r; + g_test_buf[g_test_len] = 0; + while ((nl = strchr(start, '\n'))) { + *nl = 0; + test_input_line(start); + start = nl + 1; + } + g_test_len = strlen(start); + memmove(g_test_buf, start, g_test_len); + if (g_test_len >= sizeof(g_test_buf) - 1) g_test_len = 0; /* overlong line: drop */ + } + return 0; +} + +static void start_test_input(struct wl_event_loop *loop) { + const char *rt = getenv("XDG_RUNTIME_DIR"); + char path[512]; + int fd; + + if (!rt || !*rt) return; + snprintf(path, sizeof(path), "%s/test-input", rt); + unlink(path); + if (mkfifo(path, 0600) != 0) return; + /* O_RDWR keeps a writer open ourselves, so a closing test shell never leaves us at EOF. */ + if ((fd = open(path, O_RDWR | O_NONBLOCK | O_CLOEXEC)) < 0) return; + wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, on_test_input, NULL); +} + +/* ------------------------------------------------------------------ entry + * Blocks in the wl event loop, so the JNI wrapper runs it on a dedicated thread. + * XDG_RUNTIME_DIR must be set by the caller before this runs. */ + +static struct wl_listener g_client_created = { .notify = on_client_created }; + +int banner_wayland_run(void) { + wl_list_init(&g_surfaces); + wl_list_init(&g_toplevels); + wl_list_init(&g_constraints); + wl_list_init(&g_relative_pointers); + open_session_log(); + + /* Bring the GPU up before any client can connect: loading Turnip the first time + * can take many seconds, and it must not stall a client mid-handshake. */ + if (vkp_ready() != 0) WLOGE("renderer unavailable; clients will connect but nothing is drawn"); + + struct wl_display *display = wl_display_create(); + if (!display) { + WLOGE("wl_display_create failed"); + return 1; + } + + /* Use a FIXED socket name so it always matches the guest's WAYLAND_DISPLAY=wayland-0 + * (wl_display_add_socket_auto would drift to wayland-1/2/… if a stale socket exists, + * and the guest only ever looks for wayland-0). Unlink any stale socket+lock first so + * a previous run that didn't clean up can't block the bind. */ + const char *rt = getenv("XDG_RUNTIME_DIR"); + if (rt && *rt) { + char p[512]; + snprintf(p, sizeof(p), "%s/wayland-0", rt); unlink(p); + snprintf(p, sizeof(p), "%s/wayland-0.lock", rt); unlink(p); + } + if (wl_display_add_socket(display, "wayland-0") != 0) { + WLOGE("add_socket(wayland-0) failed in XDG_RUNTIME_DIR=%s (errno path/perms?)", + rt ? rt : "(null)"); + return 1; + } + banner_log("display", "Wayland compositor listening on %s/wayland-0", rt ? rt : "?"); + wl_display_add_client_created_listener(display, &g_client_created); + + wl_global_create(display, &wl_compositor_interface, 6, NULL, bind_compositor); + wl_global_create(display, &wl_subcompositor_interface, 1, NULL, bind_subcompositor); + wl_global_create(display, &wp_viewporter_interface, 1, NULL, bind_viewporter); + wl_display_init_shm(display); /* wl_shm global + pool/buffer handling */ + /* libdecor binds wl_output at 4; a lower version is a protocol error for the client. */ + wl_global_create(display, &wl_output_interface, 4, NULL, bind_output); + wl_global_create(display, &xdg_wm_base_interface, 1, NULL, bind_xdg_wm_base); + wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf); + /* gamescope's Wayland backend refuses a seat older than 8. */ + wl_global_create(display, &wl_seat_interface, 9, NULL, bind_seat); + wl_global_create(display, &banner_desktop_v1_interface, 1, NULL, bind_desktop); + wl_global_create(display, &wp_presentation_interface, 2, NULL, bind_presentation); + wl_global_create(display, &zwp_pointer_constraints_v1_interface, 1, NULL, bind_pointer_constraints); + wl_global_create(display, &zwp_relative_pointer_manager_v1_interface, 1, NULL, bind_relative_pointer_manager); + banner_ext_init(display); /* clipboard, text input, toplevel icons (own files, see banner_ext.h) */ + ahb_swapchain_init(display); /* zero-copy layers: banner_ahb_v1, advertised whenever a display + * layer is possible; the mode event carries the live switch + * (ahb_swapchain.h) */ + banner_color_init(display); /* HDR10 (opt-in): decides the gate from the app's request + the + * display + the layer path above; creates wp_color_manager_v1 + * only when it is open (banner_color.h). Before any client can + * bind zwp_linux_dmabuf_v1, whose table it widens. */ + wl_list_init(&g_pending_releases); + g_release_timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); + if (g_release_timer_fd >= 0) + g_release_source = wl_event_loop_add_fd(wl_display_get_event_loop(display), g_release_timer_fd, + WL_EVENT_READABLE, on_release_timer, NULL); + + /* Input injection: the Android UI thread writes events to g_input_pipe[1]; + * the wl event loop drains them on this thread. */ + g_display = display; + if (pipe2(g_input_pipe, O_CLOEXEC | O_NONBLOCK) == 0) { + wl_event_loop_add_fd(wl_display_get_event_loop(display), g_input_pipe[0], + WL_EVENT_READABLE, on_input_readable, NULL); + } else { + WLOGE("input pipe creation failed"); + } + start_test_input(wl_display_get_event_loop(display)); + if ((g_stats_timer = wl_event_loop_add_timer(wl_display_get_event_loop(display), on_stats_timer, NULL))) + wl_event_source_timer_update(g_stats_timer, 10000); + + wl_display_run(display); /* blocks, dispatches the event loop */ + + wl_display_destroy(display); + return 0; +} diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.c b/app/src/main/cpp/waylandcomp/src/effects_chain.c new file mode 100644 index 0000000000..549cbd6f09 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.c @@ -0,0 +1,654 @@ +/* Screen-effect chain — see effects_chain.h. Compositor thread unless noted. */ +#define _POSIX_C_SOURCE 200809L +#include "effects_chain.h" +#include "vk_loader.h" +#include "vk_present.h" /* banner_log */ +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* The X11 Vulkan renderer's SPIR-V, pre-compiled by app/src/main/cpp/winlator/gen_shaders.sh + * (glslangValidator --vn) and committed next to the GLSL: the NDK build compiles no shaders, so + * there is no build-time tooling for CI to break. Same bytes as the X11 chain runs. */ +#include "upscale_vert.h" +#include "sgsr_frag.h" +#include "sgsr_quality_frag.h" +#include "nis_frag.h" +#include "fsr_easu_frag.h" +#include "fsr_rcas_frag.h" +#include "cas_frag.h" +#include "color_frag.h" +#include "fxaa_frag.h" +#include "toon_frag.h" +#include "hdr_frag.h" +#include "ntsc_frag.h" +#include "crt_frag.h" +#include "deband_frag.h" + +#define FX_FORMAT VK_FORMAT_R8G8B8A8_UNORM /* the default: every SDR frame */ +/* The chain's target format and the scene's view format. R8G8B8A8 always, except while an HDR scene + * runs through the chain (hdr_compose.h): then the scene and the targets are A2B10G10R10, so a PQ + * picture keeps 10 bits through every pass. A change rebuilds the chain's objects once + * (vkp_effects_set_formats). */ +static VkFormat g_fx_fmt = FX_FORMAT, g_scene_fmt = FX_FORMAT; +#define FX_MAX_DIM 4096 /* a FILL-mapped scene can exceed the panel; cap the chain resolution */ + +/* ------------------------------------------------------------------ settings */ + +struct fx_settings { + int scaling; /* 0..8 */ + int sharp_pct; /* 0..100, the upscaler's own slider */ + int cas_on, cas_pct; + int hdr_on; + int deband_on, deband_pct; /* 0..200 */ + int color_on; /* derived: grade not neutral */ + float brightness, contrast, gamma, saturation; /* shader units (already mapped/clamped) */ + float b_raw, c_raw, s_raw; /* slider units, for the log */ + int fxaa, toon, crt, ntsc; + char look[48]; +}; + +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; +static struct fx_settings g_set = { + .scaling = 0, .sharp_pct = 75, .cas_on = 0, .cas_pct = 60, .deband_pct = 100, + .gamma = 1.0f, .saturation = 1.0f, .s_raw = 100.0f, .look = "Off"}; +static volatile int g_changed; +static struct fx_settings g_cur; /* the compositor thread's per-frame snapshot */ +static int g_cur_valid; + +static void set_begin(void) { pthread_mutex_lock(&g_lock); } +static void set_end(void) { g_changed = 1; pthread_mutex_unlock(&g_lock); } + +void vkp_effects_set_scaling(int mode) { + if (mode < 0 || mode > 8) mode = 0; + set_begin(); g_set.scaling = mode; set_end(); +} +void vkp_effects_set_upscale_sharpness(int pct) { + if (pct < 0) pct = 0; + if (pct > 100) pct = 100; + set_begin(); g_set.sharp_pct = pct; set_end(); +} +void vkp_effects_set_cas(int enabled, int pct) { + if (pct < 0) pct = 0; + if (pct > 100) pct = 100; + set_begin(); g_set.cas_on = enabled ? 1 : 0; g_set.cas_pct = pct; set_end(); +} +void vkp_effects_set_hdr(int enabled) { set_begin(); g_set.hdr_on = enabled ? 1 : 0; set_end(); } +void vkp_effects_set_deband(int enabled, int pct) { + if (pct < 0) pct = 0; + if (pct > 200) pct = 200; + set_begin(); g_set.deband_on = enabled ? 1 : 0; g_set.deband_pct = pct; set_end(); +} +static float clampf(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; } +void vkp_effects_set_screen(float brightness, float contrast, float gamma, float saturation, + int fxaa, int toon, int crt, int ntsc) { + /* Same mapping as VulkanRendererContext::setColorGrade (GL ColorEffect clamps). */ + int on = !(brightness == 0.0f && contrast == 0.0f && gamma == 1.0f && saturation == 100.0f); + set_begin(); + g_set.color_on = on; + g_set.b_raw = brightness; g_set.c_raw = contrast; g_set.s_raw = saturation; + g_set.brightness = clampf(brightness / 100.0f, -1.0f, 1.0f); + g_set.contrast = clampf(contrast / 100.0f, 0.0f, 2.0f); + g_set.saturation = clampf(saturation / 100.0f, 0.0f, 2.0f); + g_set.gamma = clampf(gamma, 0.1f, 5.0f); + g_set.fxaa = fxaa ? 1 : 0; g_set.toon = toon ? 1 : 0; g_set.crt = crt ? 1 : 0; g_set.ntsc = ntsc ? 1 : 0; + set_end(); +} +void vkp_effects_set_look(const char *name) { + set_begin(); + snprintf(g_set.look, sizeof(g_set.look), "%s", name && *name ? name : "Custom"); + set_end(); +} + +static const char *scaling_name(int m) { + static const char *n[] = {"None", "Linear", "Nearest", "SGSR", "FSR", "FSR Fit", "Sharpen", "NIS", "SGSR HQ"}; + return (m >= 0 && m <= 8) ? n[m] : "?"; +} +static int spatial_mode(int m) { return m >= 3 && m <= 8; } +static int cas_active(const struct fx_settings *s) { return s->cas_on && s->cas_pct > 0; } +static int effect_count(const struct fx_settings *s) { + return s->fxaa + s->toon + s->color_on + cas_active(s) + s->hdr_on + s->ntsc + s->crt + s->deband_on; +} + +static void log_settings(const struct fx_settings *s) { + char line[400]; + int n; + if (!spatial_mode(s->scaling) && !effect_count(s)) { + banner_log("effects", "all off: scaling=%s (plain blit)", scaling_name(s->scaling)); + return; + } + n = snprintf(line, sizeof(line), "scaling=%s", scaling_name(s->scaling)); + if (spatial_mode(s->scaling)) n += snprintf(line + n, sizeof(line) - n, " %d%%", s->sharp_pct); + if (cas_active(s)) n += snprintf(line + n, sizeof(line) - n, ", CAS on %d%%", s->cas_pct); + else n += snprintf(line + n, sizeof(line) - n, ", CAS off"); + n += snprintf(line + n, sizeof(line) - n, ", Look=\"%s\"", s->look); + if (s->color_on) + n += snprintf(line + n, sizeof(line) - n, ", colour b=%+.0f c=%+.0f g=%.2f s=%.0f%%", + s->b_raw, s->c_raw, s->gamma, s->s_raw); + if (s->fxaa) n += snprintf(line + n, sizeof(line) - n, ", FXAA on"); + if (s->toon) n += snprintf(line + n, sizeof(line) - n, ", Toon on"); + if (s->hdr_on) n += snprintf(line + n, sizeof(line) - n, ", HDR on"); + if (s->ntsc) n += snprintf(line + n, sizeof(line) - n, ", NTSC on"); + if (s->crt) n += snprintf(line + n, sizeof(line) - n, ", CRT on"); + if (s->deband_on) n += snprintf(line + n, sizeof(line) - n, ", Deband on %d%%", s->deband_pct); + (void)n; + banner_log("effects", "%s", line); +} + +int vkp_effects_sync(void) { + if (!g_changed && g_cur_valid) return 0; + pthread_mutex_lock(&g_lock); + g_changed = 0; + g_cur = g_set; + pthread_mutex_unlock(&g_lock); + g_cur_valid = 1; + log_settings(&g_cur); + return 1; +} + +int vkp_effects_active(void) { + vkp_effects_sync(); + return spatial_mode(g_cur.scaling) || effect_count(&g_cur) > 0; +} + +VkFilter vkp_effects_blit_filter(void) { + vkp_effects_sync(); + return g_cur.scaling == 2 ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; +} + +/* ------------------------------------------------------------------ push constants + * Byte-identical to VulkanRendererContext.h: vec4 ndc first (upscale.vert), the rest fragment-only. */ +struct pc_sgsr { float ndc[4]; float vp[4]; float edge; }; /* also NIS: vp + sharpness */ +struct pc_easu { float ndc[4]; uint32_t con0[4], con1[4], con2[4], con3[4]; float outW, outH; }; +struct pc_rcas { float ndc[4]; uint32_t con[4]; float outW, outH; }; +struct pc_res { float ndc[4]; float res[2]; float extra; float pad; }; /* fxaa/toon/hdr/crt (res), cas (sharpness), ntsc (frameCount), deband (strength) */ +struct pc_color { float ndc[4]; float b, c, g, s; }; +#define PC_MAX_SIZE sizeof(struct pc_easu) /* 88 bytes, the largest */ + +static uint32_t packf(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } + +/* Mirrors ffx_fsr1.h FsrEasuCon / FsrRcasCon exactly as the X11 renderer packs them. */ +static void easu_con(struct pc_easu *e, float inW, float inH, float outW, float outH) { + e->con0[0] = packf(inW / outW); e->con0[1] = packf(inH / outH); + e->con0[2] = packf(0.5f * inW / outW - 0.5f); e->con0[3] = packf(0.5f * inH / outH - 0.5f); + e->con1[0] = packf(1.0f / inW); e->con1[1] = packf(1.0f / inH); + e->con1[2] = packf(1.0f / inW); e->con1[3] = packf(-1.0f / inH); + e->con2[0] = packf(-1.0f / inW); e->con2[1] = packf(2.0f / inH); + e->con2[2] = packf(1.0f / inW); e->con2[3] = packf(2.0f / inH); + e->con3[0] = packf(0.0f); e->con3[1] = packf(4.0f / inH); + e->con3[2] = 0; e->con3[3] = 0; +} +static void rcas_con(struct pc_rcas *r, float scale01) { + r->con[0] = packf(scale01); r->con[1] = 0; r->con[2] = 0; r->con[3] = 0; +} + +/* ------------------------------------------------------------------ Vulkan objects */ + +struct fx_target { + VkImage img; VkDeviceMemory mem; VkImageView view; VkFramebuffer fb; VkDescriptorSet ds; + int w, h; +}; + +static VkDevice g_dev; +static VkPhysicalDevice g_pd; +static VkPhysicalDeviceMemoryProperties g_mp; +static int g_ready; /* 0 = objects not built, 1 = ok, -1 = failed (chain disabled, said once) */ +static VkRenderPass g_rp; +static VkDescriptorSetLayout g_dsl; +static VkPipelineLayout g_pl; +static VkDescriptorPool g_dpool; +static VkSampler g_sampler; /* linear, clamp-to-edge: what the X11 chain samples its targets with */ +enum { P_SGSR, P_SGSR_HQ, P_NIS, P_EASU, P_RCAS, P_CAS, P_COLOR, P_FXAA, P_TOON, P_HDR, P_NTSC, P_CRT, P_DEBAND, P_COUNT }; +static VkPipeline g_pipe[P_COUNT]; +static struct fx_target g_t[2], g_mid; /* ping-pong pair + the EASU output (FSR only) */ +/* The scene image belongs to vk_present; only its view + descriptor live here. */ +static struct { VkImage img; VkImageView view; VkDescriptorSet ds; int w, h; } g_scene; +static uint32_t g_ntsc_frame; + +void vkp_effects_bind_device(VkDevice dev, VkPhysicalDevice pd, + const VkPhysicalDeviceMemoryProperties *memprops) { + g_dev = dev; g_pd = pd; g_mp = *memprops; +} + +static int memtype(uint32_t bits, VkMemoryPropertyFlags want) { + for (uint32_t i = 0; i < g_mp.memoryTypeCount; i++) + if ((bits & (1u << i)) && (g_mp.memoryTypes[i].propertyFlags & want) == want) return (int)i; + return -1; +} + +static VkDescriptorSet alloc_ds(VkImageView view) { + VkDescriptorSet ds = VK_NULL_HANDLE; + VkDescriptorSetAllocateInfo ai = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + .descriptorPool = g_dpool, .descriptorSetCount = 1, .pSetLayouts = &g_dsl}; + if (g_vk.AllocateDescriptorSets(g_dev, &ai, &ds) != VK_SUCCESS) return VK_NULL_HANDLE; + VkDescriptorImageInfo ii = {.sampler = g_sampler, .imageView = view, + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}; + VkWriteDescriptorSet wr = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .dstSet = ds, .dstBinding = 0, + .descriptorCount = 1, .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .pImageInfo = &ii}; + g_vk.UpdateDescriptorSets(g_dev, 1, &wr, 0, NULL); + return ds; +} + +static VkImageView make_view(VkImage img, VkFormat fmt) { + VkImageView v = VK_NULL_HANDLE; + VkImageViewCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .image = img, + .viewType = VK_IMAGE_VIEW_TYPE_2D, .format = fmt, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + if (g_vk.CreateImageView(g_dev, &ci, NULL, &v) != VK_SUCCESS) return VK_NULL_HANDLE; + return v; +} + +static void target_destroy(struct fx_target *t) { + if (t->ds) g_vk.FreeDescriptorSets(g_dev, g_dpool, 1, &t->ds); + if (t->fb) g_vk.DestroyFramebuffer(g_dev, t->fb, NULL); + if (t->view) g_vk.DestroyImageView(g_dev, t->view, NULL); + if (t->img) g_vk.DestroyImage(g_dev, t->img, NULL); + if (t->mem) g_vk.FreeMemory(g_dev, t->mem, NULL); + memset(t, 0, sizeof(*t)); +} + +/* A chain target: rendered into (colour attachment), sampled by the next pass, and blitted to + * the swapchain when it ends up holding the result. Frames are fenced, so a resize never races + * the GPU. 0 = ok. */ +static int target_ensure(struct fx_target *t, int w, int h, const char *what) { + if (t->img && t->w == w && t->h == h) return 0; + target_destroy(t); + VkImageCreateInfo ii = {.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, + .format = g_fx_fmt, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, + .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + VkResult r = g_vk.CreateImage(g_dev, &ii, NULL, &t->img); + if (r != VK_SUCCESS) { banner_log("error", "effects: %s image %dx%d: vkCreateImage %d", what, w, h, (int)r); return -1; } + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, t->img, &req); + int idx = memtype(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (idx < 0) idx = memtype(req.memoryTypeBits, 0); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, + .memoryTypeIndex = (uint32_t)(idx < 0 ? 0 : idx)}; + r = g_vk.AllocateMemory(g_dev, &mai, NULL, &t->mem); + if (r != VK_SUCCESS) { + banner_log("error", "effects: %s image %dx%d (%llu bytes): vkAllocateMemory %d", what, w, h, + (unsigned long long)req.size, (int)r); + target_destroy(t); return -1; + } + g_vk.BindImageMemory(g_dev, t->img, t->mem, 0); + if (!(t->view = make_view(t->img, g_fx_fmt))) { target_destroy(t); return -1; } + VkFramebufferCreateInfo fi = {.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .renderPass = g_rp, + .attachmentCount = 1, .pAttachments = &t->view, .width = (uint32_t)w, + .height = (uint32_t)h, .layers = 1}; + if (g_vk.CreateFramebuffer(g_dev, &fi, NULL, &t->fb) != VK_SUCCESS) { target_destroy(t); return -1; } + if (!(t->ds = alloc_ds(t->view))) { target_destroy(t); return -1; } + t->w = w; t->h = h; + return 0; +} + +static void scene_release(void) { + if (g_scene.ds) g_vk.FreeDescriptorSets(g_dev, g_dpool, 1, &g_scene.ds); + if (g_scene.view) g_vk.DestroyImageView(g_dev, g_scene.view, NULL); + memset(&g_scene, 0, sizeof(g_scene)); +} + +static int scene_ensure(VkImage img, int w, int h) { + if (g_scene.img == img && g_scene.w == w && g_scene.h == h && g_scene.ds) return 0; + scene_release(); + if (!(g_scene.view = make_view(img, g_scene_fmt))) return -1; + if (!(g_scene.ds = alloc_ds(g_scene.view))) { scene_release(); return -1; } + g_scene.img = img; g_scene.w = w; g_scene.h = h; + return 0; +} + +static VkShaderModule shader(const uint32_t *code, size_t size) { + VkShaderModule m = VK_NULL_HANDLE; + VkShaderModuleCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, .codeSize = size, .pCode = code}; + if (g_vk.CreateShaderModule(g_dev, &ci, NULL, &m) != VK_SUCCESS) return VK_NULL_HANDLE; + return m; +} + +/* One full-quad post pipeline: upscale.vert + the effect's fragment shader, opaque, dynamic + * viewport/scissor — the X11 renderer's createPostPipeline. */ +static VkPipeline post_pipeline(VkShaderModule vert, const uint32_t *frag_code, size_t frag_size, const char *name) { + VkShaderModule frag = shader(frag_code, frag_size); + if (!frag) { banner_log("error", "effects: %s: vkCreateShaderModule failed", name); return VK_NULL_HANDLE; } + VkPipelineShaderStageCreateInfo st[2] = { + {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, .module = vert, .pName = "main"}, + {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, .module = frag, .pName = "main"}}; + VkPipelineVertexInputStateCreateInfo vi = {.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; + VkPipelineInputAssemblyStateCreateInfo ia = {.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP}; + VkDynamicState dyn[2] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; + VkPipelineDynamicStateCreateInfo ds = {.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = 2, .pDynamicStates = dyn}; + VkPipelineViewportStateCreateInfo vp = {.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + .viewportCount = 1, .scissorCount = 1}; + VkPipelineRasterizationStateCreateInfo rs = {.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, + .polygonMode = VK_POLYGON_MODE_FILL, .cullMode = VK_CULL_MODE_NONE, + .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, .lineWidth = 1.0f}; + VkPipelineMultisampleStateCreateInfo ms = {.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, + .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT}; + VkPipelineColorBlendAttachmentState ba = {.blendEnable = VK_FALSE, .colorWriteMask = 0xF}; + VkPipelineColorBlendStateCreateInfo cb = {.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, + .attachmentCount = 1, .pAttachments = &ba}; + VkGraphicsPipelineCreateInfo pi = {.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .stageCount = 2, + .pStages = st, .pVertexInputState = &vi, .pInputAssemblyState = &ia, + .pViewportState = &vp, .pRasterizationState = &rs, .pMultisampleState = &ms, + .pColorBlendState = &cb, .pDynamicState = &ds, .layout = g_pl, + .renderPass = g_rp, .subpass = 0}; + VkPipeline p = VK_NULL_HANDLE; + VkResult r = g_vk.CreateGraphicsPipelines(g_dev, VK_NULL_HANDLE, 1, &pi, NULL, &p); + g_vk.DestroyShaderModule(g_dev, frag, NULL); + if (r != VK_SUCCESS) { banner_log("error", "effects: %s: vkCreateGraphicsPipelines %d", name, (int)r); return VK_NULL_HANDLE; } + return p; +} + +static void objects_destroy(void) { + if (!g_dev) return; + scene_release(); + target_destroy(&g_t[0]); target_destroy(&g_t[1]); target_destroy(&g_mid); + for (int i = 0; i < P_COUNT; i++) { if (g_pipe[i]) g_vk.DestroyPipeline(g_dev, g_pipe[i], NULL); g_pipe[i] = VK_NULL_HANDLE; } + if (g_dpool) g_vk.DestroyDescriptorPool(g_dev, g_dpool, NULL); + if (g_pl) g_vk.DestroyPipelineLayout(g_dev, g_pl, NULL); + if (g_dsl) g_vk.DestroyDescriptorSetLayout(g_dev, g_dsl, NULL); + if (g_sampler) g_vk.DestroySampler(g_dev, g_sampler, NULL); + if (g_rp) g_vk.DestroyRenderPass(g_dev, g_rp, NULL); + g_dpool = VK_NULL_HANDLE; g_pl = VK_NULL_HANDLE; g_dsl = VK_NULL_HANDLE; g_sampler = VK_NULL_HANDLE; g_rp = VK_NULL_HANDLE; + g_ready = 0; +} + +void vkp_effects_destroy(void) { objects_destroy(); g_dev = VK_NULL_HANDLE; } + +void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt) { + if (target_fmt != g_fx_fmt) { + /* The render pass, the pipelines and the targets are built for one format: start over. */ + if (g_ready) objects_destroy(); + g_fx_fmt = target_fmt; + g_scene_fmt = scene_fmt; + if (g_dev) + banner_log("effects", "chain now works in %s (%s)", + target_fmt == FX_FORMAT ? "8-bit RGBA" + : target_fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? "FP16 RGBA" : "10-bit RGB", + target_fmt == FX_FORMAT ? "SDR frames" + : target_fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? "the HDR picture for frame generation" + : "the HDR composition's picture: PQ, or tone-mapped SDR with HDR output off"); + } else if (scene_fmt != g_scene_fmt) { + scene_release(); + g_scene_fmt = scene_fmt; + } +} + +/* Build every device object once, on the first active frame. 0 = ok, -1 = the chain is + * unavailable for this session (logged once; frames fall back to the plain blit). */ +static int objects_ensure(void) { + if (g_ready) return g_ready == 1 ? 0 : -1; + if (!g_dev || !g_vk.CreateGraphicsPipelines) { g_ready = -1; banner_log("error", "effects: no device for the chain"); return -1; } + /* Render pass: one colour target, overwritten whole (DONT_CARE), left SHADER_READ_ONLY for the + * next pass. The dependencies order this pass after whoever read the target last (previous + * pass / previous frame's blit) and before whoever samples or blits it next. */ + VkAttachmentDescription att = {.format = g_fx_fmt, .samples = VK_SAMPLE_COUNT_1_BIT, + .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, .finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}; + VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; + VkSubpassDescription sub = {.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .colorAttachmentCount = 1, .pColorAttachments = &ref}; + VkSubpassDependency deps[2] = { + {.srcSubpass = VK_SUBPASS_EXTERNAL, .dstSubpass = 0, + .srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + .srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT, + .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT}, + {.srcSubpass = 0, .dstSubpass = VK_SUBPASS_EXTERNAL, + .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + .dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT}}; + VkRenderPassCreateInfo rci = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, .attachmentCount = 1, .pAttachments = &att, + .subpassCount = 1, .pSubpasses = &sub, .dependencyCount = 2, .pDependencies = deps}; + if (g_vk.CreateRenderPass(g_dev, &rci, NULL, &g_rp) != VK_SUCCESS) goto fail; + + VkSamplerCreateInfo sci = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .magFilter = VK_FILTER_LINEAR, + .minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, + .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE}; + if (g_vk.CreateSampler(g_dev, &sci, NULL, &g_sampler) != VK_SUCCESS) goto fail; + + VkDescriptorSetLayoutBinding b = {.binding = 0, .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT}; + VkDescriptorSetLayoutCreateInfo dli = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .bindingCount = 1, .pBindings = &b}; + if (g_vk.CreateDescriptorSetLayout(g_dev, &dli, NULL, &g_dsl) != VK_SUCCESS) goto fail; + VkPushConstantRange pcr = {.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, .offset = 0, .size = PC_MAX_SIZE}; + VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 1, .pSetLayouts = &g_dsl, + .pushConstantRangeCount = 1, .pPushConstantRanges = &pcr}; + if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl) != VK_SUCCESS) goto fail; + VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 8}; + VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, + .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = 8, + .poolSizeCount = 1, .pPoolSizes = &ps}; + if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail; + + VkShaderModule vert = shader(upscale_vert_code, sizeof(upscale_vert_code)); + if (!vert) goto fail; +#define MK(slot, code, name) do { g_pipe[slot] = post_pipeline(vert, code, sizeof(code), name); if (!g_pipe[slot]) { g_vk.DestroyShaderModule(g_dev, vert, NULL); goto fail; } } while (0) + MK(P_SGSR, sgsr_code, "sgsr"); + MK(P_SGSR_HQ, sgsr_quality_code, "sgsr_quality"); + MK(P_NIS, nis_code, "nis"); + MK(P_EASU, fsr_easu_code, "fsr_easu"); + MK(P_RCAS, fsr_rcas_code, "fsr_rcas"); + MK(P_CAS, cas_code, "cas"); + MK(P_COLOR, color_code, "color"); + MK(P_FXAA, fxaa_code, "fxaa"); + MK(P_TOON, toon_code, "toon"); + MK(P_HDR, hdr_code, "hdr"); + MK(P_NTSC, ntsc_code, "ntsc"); + MK(P_CRT, crt_code, "crt"); + MK(P_DEBAND, deband_code, "deband"); +#undef MK + g_vk.DestroyShaderModule(g_dev, vert, NULL); + g_ready = 1; + banner_log("effects", "chain ready: 13 passes (SGSR, SGSR HQ, NIS, FSR EASU+RCAS, CAS, colour, FXAA, Toon, HDR, NTSC, CRT, deband) on %s", vkp_gpu_name()); + return 0; +fail: + objects_destroy(); + g_ready = -1; + banner_log("error", "effects: the screen-effect chain could not be built on this driver; effects are off for this session"); + return -1; +} + +/* ------------------------------------------------------------------ recording */ + +static void barrier(VkCommandBuffer cmd, VkImage img, VkImageLayout from, VkImageLayout to, + VkPipelineStageFlags src_stage, VkAccessFlags src_access, + VkPipelineStageFlags dst_stage, VkAccessFlags dst_access) { + VkImageMemoryBarrier b = {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = from, .newLayout = to, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = img, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}, + .srcAccessMask = src_access, .dstAccessMask = dst_access}; + g_vk.CmdPipelineBarrier(cmd, src_stage, dst_stage, 0, 0, NULL, 0, NULL, 1, &b); +} + +/* One pass: sample `src` (a descriptor in SHADER_READ_ONLY_OPTIMAL), draw the full quad into `dst`. */ +static void pass(VkCommandBuffer cmd, VkPipeline p, struct fx_target *dst, VkDescriptorSet src, + const void *pc, uint32_t pcsz) { + VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_rp, .framebuffer = dst->fb, + .renderArea = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}}; + VkViewport vp = {0, 0, (float)dst->w, (float)dst->h, 0, 1}; + VkRect2D sc = {{0, 0}, {(uint32_t)dst->w, (uint32_t)dst->h}}; + g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE); + g_vk.CmdSetViewport(cmd, 0, 1, &vp); + g_vk.CmdSetScissor(cmd, 0, 1, &sc); + g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, p); + g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 1, &src, 0, NULL); + g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, pcsz, pc); + g_vk.CmdDraw(cmd, 4, 1, 0, 0); + g_vk.CmdEndRenderPass(cmd); +} + +static const float FULL_NDC[4] = {-1.0f, -1.0f, 1.0f, 1.0f}; +#define SET_NDC(pc) memcpy((pc).ndc, FULL_NDC, sizeof(FULL_NDC)) + +VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, + int out_w, int out_h, int *res_w, int *res_h) { + const struct fx_settings *s; + vkp_effects_sync(); + s = &g_cur; + *res_w = scene_w; *res_h = scene_h; + + /* The chain's resolution: the scene's mapped size (X11 runs its effects at the output extent, + * with the scene already scaled by the base sampler). Clamped so a FILL-mapped 4K scene does + * not allocate beyond reason; the final blit resizes the remainder. */ + int cw = out_w > 0 ? out_w : scene_w, ch = out_h > 0 ? out_h : scene_h; + if (cw > FX_MAX_DIM) cw = FX_MAX_DIM; + if (ch > FX_MAX_DIM) ch = FX_MAX_DIM; + if (cw < 1) cw = 1; + if (ch < 1) ch = 1; + /* Spatial upscalers only have work when the scene is shown larger than it is (the X11 + * renderer's "render below display" gate); Sharpen (RCAS) runs at any size. */ + const int upscaling = cw > scene_w || ch > scene_h; + int spatial = 0; + if (spatial_mode(s->scaling) && (s->scaling == 6 || upscaling)) spatial = s->scaling; + const int nfx = effect_count(s); + const int resize = cw != scene_w || ch != scene_h; + /* Passes that write the ping-pong pair: the scaling/resize stage (if any) + the effects. + * Two targets are needed once any pass reads what an earlier one wrote. */ + const int npasses = ((spatial || resize) ? 1 : 0) + nfx; + + if ((spatial || nfx) && objects_ensure() == 0 && scene_ensure(scene, scene_w, scene_h) == 0 && + target_ensure(&g_t[0], cw, ch, "chain") == 0 && (npasses < 2 || target_ensure(&g_t[1], cw, ch, "chain") == 0) && + (!(spatial == 4 || spatial == 5) || target_ensure(&g_mid, cw, ch, "EASU") == 0)) { + /* `cur` = the image the next pass samples; `cur_ds` its descriptor. Every pass writes the + * target that is not being read (the pair alternates; the scene is read only first). */ + VkDescriptorSet cur_ds; + struct fx_target *cur = NULL; /* NULL = the scene image */ +#define FREE_TARGET() ((cur == &g_t[0]) ? &g_t[1] : &g_t[0]) + const float sharp01 = (float)s->sharp_pct / 100.0f; + + /* ---- stage 1: scaling (scene -> chain res) */ + if (spatial) { + barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); + struct fx_target *dst = FREE_TARGET(); + if (spatial == 3 || spatial == 8 || spatial == 7) { + struct pc_sgsr pc = {0}; + SET_NDC(pc); + pc.vp[0] = 1.0f / (float)scene_w; pc.vp[1] = 1.0f / (float)scene_h; + pc.vp[2] = (float)scene_w; pc.vp[3] = (float)scene_h; + /* SGSR EdgeSharpness 0.5 (slider 0) .. 4.5 (slider 100); NIS takes the slider as is. */ + pc.edge = spatial == 7 ? sharp01 : 0.5f + sharp01 * 4.0f; + pass(cmd, g_pipe[spatial == 3 ? P_SGSR : spatial == 8 ? P_SGSR_HQ : P_NIS], dst, g_scene.ds, &pc, sizeof(pc)); + } else if (spatial == 6) { + /* Sharpen: RCAS fetches the scene 1:1 (outputSize = scene size) while the quad + * covers the chain target = nearest scale + sharpen, as the X11 renderer does. */ + struct pc_rcas pc = {0}; + SET_NDC(pc); + rcas_con(&pc, sharp01); + pc.outW = (float)scene_w; pc.outH = (float)scene_h; + pass(cmd, g_pipe[P_RCAS], dst, g_scene.ds, &pc, sizeof(pc)); + } else { /* FSR (4) / FSR Fit (5): EASU scene -> mid, RCAS mid -> dst, both at chain res. + * Fill vs fit is the Fullscreen Mode's business here (the mapping), so both + * run the same EASU+RCAS pair. */ + struct pc_easu e = {0}; + struct pc_rcas r = {0}; + SET_NDC(e); + easu_con(&e, (float)scene_w, (float)scene_h, (float)cw, (float)ch); + e.outW = (float)cw; e.outH = (float)ch; + pass(cmd, g_pipe[P_EASU], &g_mid, g_scene.ds, &e, sizeof(e)); + SET_NDC(r); + rcas_con(&r, sharp01); + r.outW = (float)cw; r.outH = (float)ch; + pass(cmd, g_pipe[P_RCAS], dst, g_mid.ds, &r, sizeof(r)); + } + cur = dst; cur_ds = dst->ds; + } else if (resize) { + /* No spatial pass: a plain filtered resize to the chain resolution first (Linear or + * Nearest per the scaling mode), so the effects run at output resolution like X11. */ + struct fx_target *dst = FREE_TARGET(); + barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); + barrier(cmd, dst->img, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT); + VkImageBlit bl = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .srcOffsets = {{0, 0, 0}, {scene_w, scene_h, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstOffsets = {{0, 0, 0}, {cw, ch, 1}}}; + g_vk.CmdBlitImage(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst->img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, &bl, vkp_effects_blit_filter()); + barrier(cmd, dst->img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); + cur = dst; cur_ds = dst->ds; + } else { + /* Scene already at output size: the first effect samples it directly. */ + barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT); + cur = NULL; cur_ds = g_scene.ds; + } + + /* ---- stage 2: the effects, in the X11 renderer's locked order + * FXAA -> Toon -> Colour -> CAS -> HDR -> NTSC -> CRT -> Debanding (terminal dither). + * Each writes the free ping-pong target; the one just read becomes free. */ + enum { FX_FXAA, FX_TOON, FX_COLOR, FX_CAS, FX_HDR, FX_NTSC, FX_CRT, FX_DEBAND }; + int order[8], n = 0; + if (s->fxaa) order[n++] = FX_FXAA; + if (s->toon) order[n++] = FX_TOON; + if (s->color_on) order[n++] = FX_COLOR; + if (cas_active(s)) order[n++] = FX_CAS; + if (s->hdr_on) order[n++] = FX_HDR; + if (s->ntsc) order[n++] = FX_NTSC; + if (s->crt) order[n++] = FX_CRT; + if (s->deband_on) order[n++] = FX_DEBAND; + for (int i = 0; i < n; i++) { + struct fx_target *dst = FREE_TARGET(); + struct pc_res pr = {0}; + SET_NDC(pr); + pr.res[0] = (float)cw; pr.res[1] = (float)ch; + switch (order[i]) { + case FX_FXAA: pass(cmd, g_pipe[P_FXAA], dst, cur_ds, &pr, sizeof(pr)); break; + case FX_TOON: pass(cmd, g_pipe[P_TOON], dst, cur_ds, &pr, sizeof(pr)); break; + case FX_COLOR: { + struct pc_color pc = {0}; + SET_NDC(pc); + pc.b = s->brightness; pc.c = s->contrast; pc.g = s->gamma; pc.s = s->saturation; + pass(cmd, g_pipe[P_COLOR], dst, cur_ds, &pc, sizeof(pc)); + break; + } + case FX_CAS: pr.extra = (float)s->cas_pct / 100.0f; pass(cmd, g_pipe[P_CAS], dst, cur_ds, &pr, sizeof(pr)); break; + case FX_HDR: pass(cmd, g_pipe[P_HDR], dst, cur_ds, &pr, sizeof(pr)); break; + case FX_NTSC: + /* cos/sin(chromaPhase*0.5) has period 4 in the counter: mod 4 keeps the shimmer exact. */ + pr.extra = (float)(g_ntsc_frame++ & 3u); + pass(cmd, g_pipe[P_NTSC], dst, cur_ds, &pr, sizeof(pr)); + break; + case FX_CRT: pass(cmd, g_pipe[P_CRT], dst, cur_ds, &pr, sizeof(pr)); break; + case FX_DEBAND: pr.extra = (float)s->deband_pct / 100.0f; pass(cmd, g_pipe[P_DEBAND], dst, cur_ds, &pr, sizeof(pr)); break; + } + cur = dst; cur_ds = dst->ds; + } + +#undef FREE_TARGET + if (cur) { + /* The result: written by the last render pass, now for the output blit. */ + barrier(cmd, cur->img, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); + *res_w = cur->w; *res_h = cur->h; + return cur->img; + } + /* Nothing ran after all (cannot happen with nfx > 0): the scene was moved to + * SHADER_READ_ONLY above; bring it to TRANSFER_SRC for the blit. */ + barrier(cmd, scene, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_SHADER_READ_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); + return scene; + } + + /* Nothing to do (a spatial mode with no room to upscale and no effect), or the chain is + * unavailable: present the scene as composited. */ + barrier(cmd, scene, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_READ_BIT); + return scene; +} diff --git a/app/src/main/cpp/waylandcomp/src/effects_chain.h b/app/src/main/cpp/waylandcomp/src/effects_chain.h new file mode 100644 index 0000000000..3ceb979e84 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/effects_chain.h @@ -0,0 +1,81 @@ +#ifndef EFFECTS_CHAIN_H +#define EFFECTS_CHAIN_H +/* + * Screen-effect chain for the embedded Wayland compositor: the X11 Vulkan renderer's post + * chain (the .frag files in app/src/main/cpp/winlator, VulkanRendererContext::recordUpscalePasses) run + * between the composited scene and the output blit, with the same SPIR-V, push-constant + * layouts, uniform ranges and pass order, so a saved preset looks the same on both backends. + * + * Present-pass hook order (vk_present.c, vkp_render): + * scene (all draws blitted 1:1 into a scene-sized image) + * -> vkp_effects_run() this file: scaling -> effects, in the X11 order + * -> vkp_framegen_run() frame generation (feat/wayland-framegen; inserted after this) + * -> update_map / blit Fullscreen Mode + Screen Alignment, onto the swapchain image + * -> present + * When nothing is on, vkp_effects_active() is 0 and vkp_render keeps its plain path (the draws + * are blitted straight through the mapping; only the blit filter follows Linear/Nearest). + * + * Pass order (LOCKED to the X11 Vulkan renderer): + * scaling (SGSR / SGSR HQ / NIS / FSR EASU+RCAS / Sharpen=RCAS; None/Linear/Nearest = a + * filtered resize) -> FXAA -> Toon -> Colour -> CAS -> HDR -> NTSC -> CRT -> Debanding. + * Scaling resizes the scene to its mapped output size (there is no render scale on Wayland); + * every later pass runs at that resolution and ping-pongs between two targets. + * + * Settings come from any thread (JNI); the compositor thread snapshots them once per frame and + * logs one `effects` line per change. Vulkan objects are created lazily on the first active frame. + */ +#define VK_USE_PLATFORM_ANDROID_KHR +#include <vulkan/vulkan.h> + +/* Compositor thread, from dev_init: the device the chain builds its objects on. */ +void vkp_effects_bind_device(VkDevice dev, VkPhysicalDevice pd, + const VkPhysicalDeviceMemoryProperties *memprops); + +/* Compositor thread: pick up settings changed since the last call. Returns 1 when something + * changed (the caller redraws even a static scene); logs the `effects` line. */ +int vkp_effects_sync(void); + +/* Compositor thread: 1 when the frame must go through the scene image + chain (any effect on, + * or a spatial scaling mode). Modes None/Linear/Nearest alone are NOT active: the plain blit + * handles them through vkp_effects_blit_filter(). */ +int vkp_effects_active(void); + +/* The filter for the scene -> output resize: NEAREST for scaling mode 2, else LINEAR. */ +VkFilter vkp_effects_blit_filter(void); + +/* THE HOOK. Records the chain into `cmd`. `scene` (scene_w x scene_h, R8G8B8A8_UNORM, in + * TRANSFER_DST_OPTIMAL after the composite) -> the image to present, returned in + * TRANSFER_SRC_OPTIMAL with its size in res_w / res_h. out_w/out_h = the scene's mapped size on + * the output (what the scaling modes resize to; the caller maps the result over the whole scene + * afterwards, so Fullscreen Mode / Alignment still apply after the chain). Returns `scene` itself + * (transitioned to TRANSFER_SRC_OPTIMAL) when there is nothing to do or the chain is unavailable. */ +VkImage vkp_effects_run(VkCommandBuffer cmd, VkImage scene, int scene_w, int scene_h, + int out_w, int out_h, int *res_w, int *res_h); + +/* Compositor thread: drop every Vulkan object (device teardown / device lost). */ +void vkp_effects_destroy(void); + +/* Compositor thread, before vkp_effects_run(): the format of the scene image it will be handed and the + * format its own targets use. R8G8B8A8 / R8G8B8A8 for every SDR frame (the default); A2B10G10R10 / + * A2B10G10R10 while an HDR picture runs through it (hdr_compose.h). A target-format change rebuilds the + * chain's objects on its next run (once per switch). */ +void vkp_effects_set_formats(VkFormat scene_fmt, VkFormat target_fmt); + +/* ---- settings (any thread; values 1:1 with the X11 Vulkan renderer's setters) ---- */ +/* 0=None 1=Linear 2=Nearest 3=SGSR 4=FSR 5=FSR Fit 6=Sharpen 7=NIS 8=SGSR HQ */ +void vkp_effects_set_scaling(int mode); +/* Slider 0..100: RCAS lobe scale (FSR/Sharpen), SGSR EdgeSharpness 0.5..4.5, NIS sharpness. */ +void vkp_effects_set_upscale_sharpness(int pct); +/* CAS toggle + slider 0..100 (0 = the pass is off). */ +void vkp_effects_set_cas(int enabled, int pct); +void vkp_effects_set_hdr(int enabled); +/* Terminal dither: slider 0..200 -> strength/100 LSBs. */ +void vkp_effects_set_deband(int enabled, int pct); +/* Colour grade in slider units (brightness/contrast -100..100, gamma 0.5..3, saturation 0..200 + * percent; neutral = 0,0,1,100 turns the pass off) + the four shader toggles. */ +void vkp_effects_set_screen(float brightness, float contrast, float gamma, float saturation, + int fxaa, int toon, int crt, int ntsc); +/* The Look the current controls match ("Custom" when none), for the log line only. */ +void vkp_effects_set_look(const char *name); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c new file mode 100644 index 0000000000..43b94987f1 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c @@ -0,0 +1,455 @@ +/* Frame generation on the Wayland backend - see framegen_bridge.h. */ +#define _POSIX_C_SOURCE 200809L +#include "framegen_bridge.h" +#include "framegen_engine.h" +#include "vk_loader.h" +#include <pthread.h> +#include <stdatomic.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <android/log.h> + +void banner_log(const char *tag, const char *fmt, ...) __attribute__((format(printf, 2, 3))); +#define FGLOG(...) banner_log("framegen", __VA_ARGS__) +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "BannerWayland", __VA_ARGS__) + +/* ---- app controls (written from any thread, read on the compositor thread) ------------- */ +static _Atomic int g_kind = VKP_FG_ENGINE_LSFG; +static _Atomic int g_armed; +static _Atomic int g_mult = 2; +static _Atomic int g_model = 3; +static _Atomic int g_preset = 2; +static _Atomic int g_cfg_dirty = 1; +static float g_flow = 0.8f, g_refresh_hz; /* under g_lock */ +static char *g_cache_path; /* under g_lock */ +static _Atomic int g_cache_gen; /* bumps when the path changes */ +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; + +/* ---- device -------------------------------------------------------------------------- */ +static VkDevice g_dev; +static VkInstance g_inst; +static PFN_vkGetInstanceProcAddr g_gipa; +static VkPhysicalDevice g_pd; +static VkQueue g_queue; +static uint32_t g_qfam; +static int g_dev_ready, g_dev_lost, g_features_enabled; +static VkPhysicalDeviceMemoryProperties g_memprops; +static struct { + PFN_vkCreateImage CreateImage; + PFN_vkDestroyImage DestroyImage; + PFN_vkCreateImageView CreateImageView; + PFN_vkDestroyImageView DestroyImageView; + PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements; + PFN_vkAllocateMemory AllocateMemory; + PFN_vkFreeMemory FreeMemory; + PFN_vkBindImageMemory BindImageMemory; + PFN_vkCmdPipelineBarrier CmdPipelineBarrier; + PFN_vkDeviceWaitIdle DeviceWaitIdle; +} vk; + +/* ---- engine + generation ring (compositor thread) ------------------------------------ */ +static int g_engine_kind = -1; /* kind of the running engine, -1 = none */ +static int g_engine_ok; +/* The engine of this kind (with this cache) could not start or build its chain; not retried + * every frame - a new engine selection or a new cache clears it. */ +static _Atomic int g_failed_kind = -1; +static _Atomic int g_failed_cache_gen = -1; + +struct ring_image { VkImage img; VkDeviceMemory mem; VkImageView view; int fresh; }; +static struct ring_image g_ring[VKP_FG_MAX_GENERATIONS]; +static uint32_t g_ring_n, g_ring_w, g_ring_h; +static VkFormat g_ring_fmt; + +static uint64_t g_source_frames; +static uint32_t g_planned; /* generations planned for the current source frame */ +static int g_was_armed, g_generating_logged; +static uint32_t g_built_w, g_built_h; +static VkFormat g_built_fmt; +/* Deeper formats (FP16 for HDR frames) the engine failed to build its chain in this session. */ +static VkFormat g_refused_fmt[4]; +static int g_refused_n; +static int format_refused(VkFormat f) { + for (int i = 0; i < g_refused_n; i++) if (g_refused_fmt[i] == f) return 1; + return 0; +} + +/* ---- stats ------------------------------------------------------------------------- */ +static _Atomic unsigned g_stat_generated; /* since the last stats_take */ +static uint64_t g_total_generated; +static float g_presented_rate, g_source_rate; /* smoothed, 0.5 s windows */ +static uint32_t g_present_accum, g_source_accum; +static int64_t g_window_start_ns; + +static int64_t now_ns(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +/* ====================================================================== app controls */ + +void vkp_framegen_set_engine(int kind) { + if (kind != VKP_FG_ENGINE_LSFG && kind != VKP_FG_ENGINE_WINFG) kind = VKP_FG_ENGINE_LSFG; + atomic_store(&g_kind, kind); + atomic_store(&g_cfg_dirty, 1); +} + +void vkp_framegen_set_armed(int armed, int multiplier) { + if (multiplier < 2) multiplier = 2; + if (multiplier > VKP_FG_MAX_GENERATIONS + 1) multiplier = VKP_FG_MAX_GENERATIONS + 1; + if (atomic_exchange(&g_mult, multiplier) != multiplier) atomic_store(&g_cfg_dirty, 1); + atomic_store(&g_armed, armed ? 1 : 0); + LOGD("framegen: set_armed(%d, x%d)", armed, multiplier); +} + +void vkp_framegen_set_lsfg_cache_path(const char *path) { + pthread_mutex_lock(&g_lock); + int changed = (path == NULL) != (g_cache_path == NULL) || + (path && g_cache_path && strcmp(path, g_cache_path) != 0); + if (changed) { + free(g_cache_path); + g_cache_path = path ? strdup(path) : NULL; + atomic_fetch_add(&g_cache_gen, 1); + } + pthread_mutex_unlock(&g_lock); +} + +void vkp_framegen_set_tuning(float flow_scale, float refresh_hz) { + if (flow_scale < 0.25f) flow_scale = 0.25f; + if (flow_scale > 1.0f) flow_scale = 1.0f; + pthread_mutex_lock(&g_lock); + g_flow = flow_scale; + g_refresh_hz = refresh_hz > 1.0f ? refresh_hz : 0.0f; + pthread_mutex_unlock(&g_lock); + atomic_store(&g_cfg_dirty, 1); +} + +void vkp_framegen_set_winfg_tuning(int model, int perf_preset) { + atomic_store(&g_model, model == 3 ? 3 : 4); + atomic_store(&g_preset, perf_preset < 0 ? 0 : perf_preset > 2 ? 2 : perf_preset); + atomic_store(&g_cfg_dirty, 1); +} + +static int start_failed_for(int kind) { + return atomic_load(&g_failed_kind) == kind && atomic_load(&g_failed_cache_gen) == atomic_load(&g_cache_gen); +} + +static void mark_failed(int kind) { + atomic_store(&g_failed_cache_gen, atomic_load(&g_cache_gen)); + atomic_store(&g_failed_kind, kind); +} + +/* Same codes as VulkanRenderer.getFrameGenProblem(); computed from the live state so an engine + * switch from the app is answered at once. */ +int vkp_framegen_problem(void) { + if (!g_dev_ready) return -1; + int kind = atomic_load(&g_kind); + if (!fge_caps_ok(kind)) return 1; + if (start_failed_for(kind)) return 2; + if (g_engine_ok && g_engine_kind == kind && fge_unavailable()) return 2; + return 0; +} +const char *vkp_framegen_caps_reason(void) { return fge_caps_reason(); } + +void vkp_framegen_stats(float out[6]) { + float accepted = 0.0f, src = 0.0f, thermal = -1.0f; + if (g_engine_ok) fge_telemetry(&accepted, &src, &thermal); + /* Planned is what is generated; the governor is off on both paths. Our own measured + * source rate serves both engines (Win-FG measures none). */ + out[0] = (float)g_planned; + out[1] = (float)g_planned; + out[2] = g_source_rate; + out[3] = g_presented_rate; + out[4] = thermal; + out[5] = -1.0f; +} + +unsigned vkp_framegen_stats_take(void) { return atomic_exchange(&g_stat_generated, 0u); } + +/* ====================================================================== device setup */ + +const void *vkp_framegen_device_features(VkInstance inst, PFN_vkGetInstanceProcAddr gipa, + VkPhysicalDevice pd) { + g_pd = pd; g_inst = inst; g_gipa = gipa; + return fge_probe(gipa, inst, pd, VK_FORMAT_R8G8B8A8_UNORM); +} + +void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled) { + g_dev = dev; g_queue = queue; g_qfam = qfam; g_features_enabled = features_enabled; +#define R(n) vk.n = (PFN_vk##n)g_vk.GetDeviceProcAddr(dev, "vk" #n) + R(CreateImage); R(DestroyImage); R(CreateImageView); R(DestroyImageView); + R(GetImageMemoryRequirements); R(AllocateMemory); R(FreeMemory); R(BindImageMemory); + R(CmdPipelineBarrier); R(DeviceWaitIdle); +#undef R + g_vk.GetPhysicalDeviceMemoryProperties(g_pd, &g_memprops); + fge_device_ready(g_gipa, g_inst, g_pd, dev, queue, qfam, features_enabled); + g_dev_ready = vk.CreateImage && vk.CreateImageView && vk.CmdPipelineBarrier; + FGLOG("engines ready on the compositor's device: LSFG Native %s (%s), Win-FG Native %s", + fge_caps_ok(VKP_FG_ENGINE_LSFG) ? "available" : "unavailable", fge_caps_reason(), + fge_caps_ok(VKP_FG_ENGINE_WINFG) ? "available" : "unavailable"); +} + +void vkp_framegen_device_lost(void) { g_dev_lost = 1; } + +/* ====================================================================== ring */ + +static void destroy_ring(void) { + if (!g_ring_n) return; + if (vk.DeviceWaitIdle) vk.DeviceWaitIdle(g_dev); + for (uint32_t i = 0; i < g_ring_n; i++) { + if (g_ring[i].view) vk.DestroyImageView(g_dev, g_ring[i].view, NULL); + if (g_ring[i].img) vk.DestroyImage(g_dev, g_ring[i].img, NULL); + if (g_ring[i].mem) vk.FreeMemory(g_dev, g_ring[i].mem, NULL); + memset(&g_ring[i], 0, sizeof(g_ring[i])); + } + g_ring_n = 0; + if (g_engine_ok) fge_forget_targets(); +} + +static int memory_type(uint32_t bits, VkMemoryPropertyFlags want) { + for (uint32_t i = 0; i < g_memprops.memoryTypeCount; i++) + if ((bits & (1u << i)) && (g_memprops.memoryTypes[i].propertyFlags & want) == want) return (int)i; + return -1; +} + +/* The generation targets: written by the chain through a storage view, read by the screen + * blit. Kept in GENERAL for their whole life (both uses allow it), so there is no layout dance + * per frame - only access barriers. */ +static int ensure_ring(uint32_t w, uint32_t h, VkFormat fmt, uint32_t n) { + if (n > VKP_FG_MAX_GENERATIONS) n = VKP_FG_MAX_GENERATIONS; + if (g_ring_n == n && g_ring_w == w && g_ring_h == h && g_ring_fmt == fmt) return 1; + destroy_ring(); + for (uint32_t i = 0; i < n; i++) { + struct ring_image *r = &g_ring[i]; + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, .format = fmt, + .extent = {w, h, 1}, .mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + if (vk.CreateImage(g_dev, &ici, NULL, &r->img) != VK_SUCCESS) { destroy_ring(); return 0; } + VkMemoryRequirements req; + vk.GetImageMemoryRequirements(g_dev, r->img, &req); + int idx = memory_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx}; + if (idx < 0 || vk.AllocateMemory(g_dev, &mai, NULL, &r->mem) != VK_SUCCESS) { destroy_ring(); return 0; } + vk.BindImageMemory(g_dev, r->img, r->mem, 0); + VkImageViewCreateInfo vci = { + .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .image = r->img, + .viewType = VK_IMAGE_VIEW_TYPE_2D, .format = fmt, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + if (vk.CreateImageView(g_dev, &vci, NULL, &r->view) != VK_SUCCESS) { destroy_ring(); return 0; } + r->fresh = 1; + g_ring_n = i + 1; + } + g_ring_w = w; g_ring_h = h; g_ring_fmt = fmt; + LOGD("framegen: generation ring %ux%u x%u", w, h, n); + return 1; +} + +/* ====================================================================== present path */ + +static int engine_usable(void) { + int kind = atomic_load(&g_kind); + return g_dev_ready && !g_dev_lost && fge_caps_ok(kind) && !start_failed_for(kind); +} + +int vkp_framegen_format_ok(VkFormat fmt) { + if (fmt == VK_FORMAT_R8G8B8A8_UNORM) return 1; + if (!g_dev_ready || g_dev_lost || format_refused(fmt)) return 0; + return fge_format_ok(fmt); +} + +/* The engine could not build its chain in a deeper format: refuse the format for the session and + * restart the engine on the next frame (a failed build is sticky inside both engines). */ +static void refuse_format(VkFormat fmt, int kind, int w, int h, const char *what) { + if (g_refused_n < (int)(sizeof(g_refused_fmt) / sizeof(g_refused_fmt[0]))) g_refused_fmt[g_refused_n++] = fmt; + FGLOG("%s could not %s in format %d (the HDR picture's FP16) at %dx%d: it restarts, and HDR frames go through " + "it in 8 bits from the next frame", fge_engine_name(kind), what, (int)fmt, w, h); + destroy_ring(); + fge_stop(); + g_engine_ok = 0; g_engine_kind = -1; +} + +int vkp_framegen_active(void) { + return atomic_load(&g_armed) && engine_usable(); +} + +int vkp_framegen_extra_images(void) { + if (!vkp_framegen_active()) return 0; + int m = atomic_load(&g_mult); + return m - 1 > VKP_FG_MAX_GENERATIONS ? VKP_FG_MAX_GENERATIONS : m - 1; +} + +static int ensure_engine(int kind) { + if (g_engine_ok && g_engine_kind == kind) return 1; + if (start_failed_for(kind)) return 0; + if (g_engine_ok) { destroy_ring(); fge_stop(); g_engine_ok = 0; g_engine_kind = -1; } + char *path = NULL; + pthread_mutex_lock(&g_lock); + if (g_cache_path) path = strdup(g_cache_path); + pthread_mutex_unlock(&g_lock); + if (kind == VKP_FG_ENGINE_LSFG && !path) { + FGLOG("LSFG Native can't start: no shader cache (import Lossless.dll in Settings)"); + mark_failed(kind); + return 0; + } + int r = fge_start(kind, path); + free(path); + if (r != 0) { + FGLOG("%s failed to start on the compositor's driver; frame generation stays off", + fge_engine_name(kind)); + mark_failed(kind); + return 0; + } + g_engine_ok = 1; g_engine_kind = kind; + atomic_store(&g_cfg_dirty, 1); + g_built_w = g_built_h = 0; + FGLOG("%s engine ready (%s)", fge_engine_name(kind), fge_build_info()); + return 1; +} + +static int g_logged_mult; +static void log_arm_transition(int armed, int kind, int mult) { + if (armed == g_was_armed) { + if (armed && mult != g_logged_mult) { + g_logged_mult = mult; + FGLOG("%s multiplier changed to x%d (%d interpolated frames per game frame)", fge_engine_name(kind), mult, mult - 1); + } + return; + } + g_was_armed = armed; + if (armed) { + g_logged_mult = mult; + float flow, hz; + pthread_mutex_lock(&g_lock); flow = g_flow; hz = g_refresh_hz; pthread_mutex_unlock(&g_lock); + FGLOG("%s x%d armed (flow scale %.2f, panel %.0f Hz): real frames are presented one slot late " + "with the interpolated frames ahead of them", fge_engine_name(kind), mult, (double)flow, (double)hz); + } else { + FGLOG("frame generation off (%llu frames generated this session)", (unsigned long long)g_total_generated); + g_generating_logged = 0; + } +} + +int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h, + VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]) { + (void)scene_view; + int kind = atomic_load(&g_kind); + int armed = atomic_load(&g_armed); + int mult = atomic_load(&g_mult); + g_planned = 0; + if (!armed || !engine_usable() || w <= 0 || h <= 0) { log_arm_transition(0, kind, mult); return 0; } + if (!ensure_engine(kind)) { log_arm_transition(0, kind, mult); return 0; } + log_arm_transition(1, kind, mult); + + if (atomic_exchange(&g_cfg_dirty, 0)) { + float flow, hz; + pthread_mutex_lock(&g_lock); flow = g_flow; hz = g_refresh_hz; pthread_mutex_unlock(&g_lock); + fge_configure((uint32_t)mult, flow, hz, atomic_load(&g_model), atomic_load(&g_preset)); + } + if (!fge_prepare((uint32_t)w, (uint32_t)h, fmt)) { + if (fmt != VK_FORMAT_R8G8B8A8_UNORM && fge_unavailable()) { + refuse_format(fmt, kind, w, h, "build its chain"); + return 0; + } + if (fge_unavailable()) { + FGLOG("%s could not build its chain at %dx%d; frame generation stays off", fge_engine_name(kind), w, h); + mark_failed(kind); + } + return 0; + } + if (g_built_w != (uint32_t)w || g_built_h != (uint32_t)h || g_built_fmt != fmt) { + g_built_w = (uint32_t)w; g_built_h = (uint32_t)h; g_built_fmt = fmt; + g_generating_logged = 0; + } + uint32_t want = (uint32_t)(mult - 1); + if (!ensure_ring((uint32_t)w, (uint32_t)h, fmt, want)) { + if (fmt != VK_FORMAT_R8G8B8A8_UNORM) { refuse_format(fmt, kind, w, h, "make its generation ring"); return 0; } + FGLOG("no memory for the generation ring (%dx%d x%u); frame generation stays off", w, h, want); + mark_failed(kind); + return 0; + } + + uint32_t n_gen = fge_plan(g_ring_n, ++g_source_frames, g_presented_rate); + if (n_gen > g_ring_n) n_gen = g_ring_n; + g_planned = n_gen; + + /* The scene image was just written (blits, and whatever the effects chain did); make that + * visible to the engine's copy (TRANSFER) and shaders (COMPUTE). Fresh ring images get their + * one UNDEFINED -> GENERAL transition here; the others need TRANSFER-read -> COMPUTE-write. */ + VkImageMemoryBarrier bars[1 + VKP_FG_MAX_GENERATIONS]; + uint32_t nb = 0; + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT, + .oldLayout = VK_IMAGE_LAYOUT_GENERAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = scene, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + for (uint32_t g = 0; g < n_gen; g++) { + struct ring_image *r = &g_ring[g]; + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = r->fresh ? 0 : VK_ACCESS_TRANSFER_READ_BIT, + .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT, + .oldLayout = r->fresh ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_GENERAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = r->img, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + r->fresh = 0; + } + vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, 0, NULL, 0, NULL, nb, bars); + + /* Frame N in; the shared passes (the whole flow pyramid) run only when generating. */ + fge_process(cmd, scene, (uint32_t)w, (uint32_t)h, n_gen); + for (uint32_t g = 0; g < n_gen; g++) { + fge_generate(cmd, g, n_gen, g_ring[g].img, g_ring[g].view, (uint32_t)w, (uint32_t)h); + gens[g] = g_ring[g].img; + } + if (n_gen) { + /* Compute writes -> the screen blits (this command buffer and the later per-present ones; + * a barrier's first scope covers everything submitted earlier on the queue). */ + nb = 0; + for (uint32_t g = 0; g < n_gen; g++) + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, + .oldLayout = VK_IMAGE_LAYOUT_GENERAL, .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = g_ring[g].img, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, nb, bars); + if (!g_generating_logged) { + g_generating_logged = 1; + FGLOG("generating: %s x%d at %dx%d (%u interpolated frame%s per game frame%s)", + fge_engine_name(kind), mult, w, h, n_gen, n_gen == 1 ? "" : "s", + fmt == VK_FORMAT_R16G16B16A16_SFLOAT ? ", FP16: the HDR picture" : ""); + } + } + return (int)n_gen; +} + +void vkp_framegen_presented(int generated) { + if (generated < 0) generated = 0; + int64_t now = now_ns(); + if (!g_window_start_ns) { g_window_start_ns = now; g_present_accum = 0; g_source_accum = 0; } + g_present_accum += (uint32_t)generated + 1u; + g_source_accum += 1u; + if (generated) { + atomic_fetch_add(&g_stat_generated, (unsigned)generated); + g_total_generated += (uint64_t)generated; + } + float elapsed = (float)(now - g_window_start_ns) / 1e9f; + if (elapsed < 0.5f) return; /* half-second window, like the X11 renderer */ + float rate = (float)g_present_accum / elapsed, src = (float)g_source_accum / elapsed; + g_presented_rate = g_presented_rate > 0.0f ? g_presented_rate + (rate - g_presented_rate) * 0.25f : rate; + g_source_rate = g_source_rate > 0.0f ? g_source_rate + (src - g_source_rate) * 0.25f : src; + g_window_start_ns = now; + g_present_accum = 0; + g_source_accum = 0; +} diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.h b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h new file mode 100644 index 0000000000..a0fe1c4eb3 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.h @@ -0,0 +1,90 @@ +#ifndef FRAMEGEN_BRIDGE_H +#define FRAMEGEN_BRIDGE_H +/* + * Frame generation on the Wayland backend (feat/wayland-framegen). + * + * The two NATIVE engines the X11 renderer runs inside libwinlator's compositor - LSFG Native + * (the user's Lossless.dll chain, lsfg/) and Win-FG Native (our own FSR3-derived optical-flow + * chain, winfg/) - are hosted here inside the Wayland compositor's Turnip device. Both consume + * consecutive presented frames and emit interpolated frames between them; the guest never + * sees any of it. bionic-fg (the guest-side win-fg Vulkan layer) is X11-only and is not + * ported: its frames are born inside the guest and have nothing to attach to here. + * + * Present order per scene frame (vk_present.c): + * scene -> effects -> FRAME GENERATION -> mapping/blit -> swapchain + * The scene is composed 1:1 into an off-screen image, the effects chain runs on it, then + * vkp_framegen_run() (the one hook) feeds that image to the engine and hands back up to three + * generated images. vk_present.c blits the generated frames to the screen FIRST and the real + * frame LAST (interpolation produces frames that belong between N-1 and N), one FIFO present + * each, so the panel shows them on consecutive vblanks - the same pacing the X11 native path + * is device-proven with. No sleeps, no host-side pacer. + * + * Threads: the set_* controls are called from the app (JNI, any thread) and only store + * values; everything that touches Vulkan runs on the compositor thread inside vkp_render(). + */ +#include <stdint.h> +#ifndef VK_USE_PLATFORM_ANDROID_KHR +#define VK_USE_PLATFORM_ANDROID_KHR +#endif +#include <vulkan/vulkan.h> + +enum { VKP_FG_ENGINE_LSFG = 0, VKP_FG_ENGINE_WINFG = 1 }; +/* Hard ceiling on generated frames per source frame (2x..4x -> 1..3), as on X11. */ +#define VKP_FG_MAX_GENERATIONS 3 + +/* ---- app controls (any thread) ------------------------------------------------------- */ +void vkp_framegen_set_engine(int kind); +/* multiplier 2..4; armed = 0 stops generating (the ring and the engine stay for a re-arm). */ +void vkp_framegen_set_armed(int armed, int multiplier); +/* LSFG Native: the SPIR-V cache built from the user's Lossless.dll (LsfgNative.ensureCache). */ +void vkp_framegen_set_lsfg_cache_path(const char *path); +/* Flow scale 0.25..1.0 and the panel's real refresh rate (the pacer never generates above it). */ +void vkp_framegen_set_tuning(float flow_scale, float refresh_hz); +/* Win-FG Native: interpolation model (3/4) and performance preset (0..2). */ +void vkp_framegen_set_winfg_tuning(int model, int perf_preset); +/* Same codes as VulkanRenderer.getFrameGenProblem(): -1 not known yet (device not up), 0 fine, + * 1 the driver lacks what the selected engine needs (vkp_framegen_caps_reason says what), + * 2 the engine failed to start / build its chain. */ +int vkp_framegen_problem(void); +const char *vkp_framegen_caps_reason(void); +/* Same shape as VulkanRenderer.getFrameGenStats(): {generations trusted, generations planned, + * real (source) fps, presented fps incl. generated frames, thermal (-1 = none), ms per + * generated frame (-1 = unknown)}. */ +void vkp_framegen_stats(float out[6]); +/* Generated frames presented since the last call (compositor.c, the 10 s stats line). */ +unsigned vkp_framegen_stats_take(void); + +/* ---- vk_present.c: device setup (compositor thread) ----------------------------------- */ +/* Before vkCreateDevice: probe what the engines need on this physical device and return the + * pNext chain to hang on VkDeviceCreateInfo (NULL when the device cannot run the LSFG chain - + * Win-FG needs no feature). Owned by the bridge, valid until the next call. */ +const void *vkp_framegen_device_features(VkInstance inst, PFN_vkGetInstanceProcAddr gipa, + VkPhysicalDevice pd); +/* After the device exists (features_enabled = the chain above was accepted). */ +void vkp_framegen_device_ready(VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled); +/* VK_ERROR_DEVICE_LOST: never touch the device again. */ +void vkp_framegen_device_lost(void); + +/* ---- vk_present.c: present path (compositor thread) ------------------------------------ */ +/* 1 when this frame must go through the compositor pass (armed and the engine can run). Safe + * before the device is up (0). */ +int vkp_framegen_active(void); +/* Extra swapchain images wanted so every present of one scene frame is queued without waiting + * for a vblank: multiplier - 1 while armed, 0 otherwise. A change means "rebuild the swapchain". */ +int vkp_framegen_extra_images(void); +/* THE hook. Called once per composed scene frame, after the effects hook, with the scene image + * (GENERAL, w x h, fmt, TRANSFER_SRC|SAMPLED). Records the engine's chain into `cmd` and + * returns how many generated frames (0..VKP_FG_MAX_GENERATIONS) it produced, their images in + * gens[] (GENERAL, w x h, already made visible to TRANSFER reads). 0 = present the scene alone. */ +int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, int w, int h, + VkFormat fmt, VkImage gens[VKP_FG_MAX_GENERATIONS]); +/* After the presents of one scene frame: how many generated frames actually reached the + * swapchain (rate tracking + the stats counters). */ +void vkp_framegen_presented(int generated); +/* 1 when vkp_framegen_run can be fed `fmt` (the 8-bit scene always; FP16 for HDR frames where the + * device can generate in it and the engine has not refused it this session). A chain that fails to + * build in a deeper format is not an engine failure: the engine restarts and the format is refused, + * so the caller goes back to 8 bits. */ +int vkp_framegen_format_ok(VkFormat fmt); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp b/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp new file mode 100644 index 0000000000..dd1b82a333 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine.cpp @@ -0,0 +1,250 @@ +// C++ side of the Wayland frame-generation bridge - see framegen_engine.h. +// +// Hosts the SAME engine objects the X11 renderer drives (lsfg::Engine, winfg::Engine), fed from +// the compositor's own Turnip entry points. Nothing in winlator/lsfg or winlator/winfg is +// modified: the engines take a VkTable (VulkanRendererContext.h) for their dispatch, and one is +// filled here by name from the compositor's vkGetInstanceProcAddr / vkGetDeviceProcAddr. +#include "framegen_engine.h" + +#include <cstdio> +#include <cstring> +#include <memory> +#include <string> +#include <vector> + +#include <android/log.h> + +#include "VulkanRendererContext.h" // VkTable +#include "lsfg/lsfg_engine.h" +#include "lsfg/lsfg_probe.h" +#include "lsfg/lsfg_vkd.h" +#include "winfg/winfg_engine.h" + +#define ELOG(...) __android_log_print(ANDROID_LOG_INFO, "BannerWayland", "framegen: " __VA_ARGS__) +#define ELOGE(...) __android_log_print(ANDROID_LOG_ERROR, "BannerWayland", "framegen: " __VA_ARGS__) + +namespace { + +VkTable g_table{}; +lsfg::Caps g_caps{}; +VkPhysicalDeviceVulkan12Features g_v12{}; +VkPhysicalDeviceFeatures2 g_f2{}; +VkPhysicalDevice g_pd = VK_NULL_HANDLE; +VkDevice g_dev = VK_NULL_HANDLE; +VkQueue g_queue = VK_NULL_HANDLE; +uint32_t g_qfam = 0; +bool g_probed = false, g_ready = false; + +std::unique_ptr<lsfg::Engine> g_lsfg; +std::unique_ptr<winfg::Engine> g_winfg; +int g_kind = -1; +char g_build[96] = ""; + +// Instance-level entry points the engines and the probe use. +#define FGE_INSTANCE_FUNCS(X) \ + X(GetPhysicalDeviceProperties) X(GetPhysicalDeviceMemoryProperties) \ + X(GetPhysicalDeviceFeatures2) X(GetPhysicalDeviceFormatProperties) \ + X(GetPhysicalDeviceQueueFamilyProperties) X(GetDeviceProcAddr) +// Device-level: the LSFG chain's 34 (lsfg_vkd.h), win-fg's extras (winfg_vkd.cpp) and the +// generic set either may reach for. Anything left null in VkTable is never called. +#define FGE_DEVICE_FUNCS(X) \ + X(AllocateDescriptorSets) X(AllocateMemory) X(BindBufferMemory) X(BindImageMemory) \ + X(CmdBindDescriptorSets) X(CmdBindPipeline) X(CmdCopyImage) X(CmdDispatch) \ + X(CmdPipelineBarrier) X(CreateBuffer) X(CreateComputePipelines) X(CreateDescriptorPool) \ + X(CreateDescriptorSetLayout) X(CreateImage) X(CreateImageView) X(CreatePipelineLayout) \ + X(CreateSampler) X(CreateShaderModule) X(DestroyBuffer) X(DestroyDescriptorPool) \ + X(DestroyDescriptorSetLayout) X(DestroyImage) X(DestroyImageView) X(DestroyPipeline) \ + X(DestroyPipelineLayout) X(DestroySampler) X(DestroyShaderModule) X(FreeMemory) \ + X(GetBufferMemoryRequirements) X(GetImageMemoryRequirements) X(MapMemory) X(UnmapMemory) \ + X(UpdateDescriptorSets) X(CmdClearColorImage) X(DeviceWaitIdle) X(ResetDescriptorPool) \ + X(QueueSubmit) X(CreateFence) X(DestroyFence) X(WaitForFences) \ + X(ResetFences) X(GetFenceStatus) X(CreateSemaphore) X(DestroySemaphore) \ + X(CreateCommandPool) X(DestroyCommandPool) X(AllocateCommandBuffers) \ + X(FreeCommandBuffers) X(BeginCommandBuffer) X(EndCommandBuffer) X(ResetCommandBuffer) \ + X(CmdBlitImage) X(CmdCopyBufferToImage) X(FreeDescriptorSets) X(FlushMappedMemoryRanges) \ + X(GetDeviceQueue) X(CreateQueryPool) X(DestroyQueryPool) X(CmdResetQueryPool) \ + X(CmdWriteTimestamp) X(GetQueryPoolResults) + +void fill_instance(PFN_vkGetInstanceProcAddr gipa, VkInstance inst) { +#define X(n) g_table.n = reinterpret_cast<PFN_vk##n>(gipa(inst, "vk" #n)); + FGE_INSTANCE_FUNCS(X) +#undef X +} + +void fill_device(VkDevice dev) { + if (!g_table.GetDeviceProcAddr) return; +#define X(n) g_table.n = reinterpret_cast<PFN_vk##n>(g_table.GetDeviceProcAddr(dev, "vk" #n)); + FGE_DEVICE_FUNCS(X) +#undef X +} + +} // namespace + +extern "C" { + +const void *fge_probe(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkFormat ring_fmt) { + g_pd = pd; + fill_instance(gipa, inst); + std::vector<VkExtensionProperties> exts; + auto enumExts = reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>( + gipa(inst, "vkEnumerateDeviceExtensionProperties")); + if (enumExts) { + uint32_t n = 0; + enumExts(pd, nullptr, &n, nullptr); + exts.resize(n); + if (n) enumExts(pd, nullptr, &n, exts.data()); + } + g_caps = lsfg::Caps{}; + // No Vulkan 1.1 compat here: the Wayland compositor only ever runs on Turnip (adrenotools), + // which reports 1.3+; the stock-driver case the compat flag exists for cannot reach it. + g_caps.features = lsfg::queryFeatures(g_table, pd, exts, /*allowVk11=*/false); + g_caps.probedFormat = ring_fmt; + g_caps.storageOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties + ? lsfg::probeStorageFormat(g_table, pd, ring_fmt) : false; + g_caps.linearBlitOnSwapchainFormat = g_table.GetPhysicalDeviceFormatProperties + ? lsfg::probeLinearBlit(g_table, pd, ring_fmt) : false; + g_probed = true; + if (!g_caps.features.deviceGatesPass()) { + lsfg::explain(g_caps); + ELOG("device gates for the LSFG chain fail: %s", g_caps.reason); + return nullptr; + } + // Same chain VulkanRendererContext::createLogicalDevice hangs on its device. + g_v12 = VkPhysicalDeviceVulkan12Features{}; + g_v12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES; + g_v12.vulkanMemoryModel = VK_TRUE; + g_v12.vulkanMemoryModelDeviceScope = + g_caps.features.vulkanMemoryModelDeviceScope ? VK_TRUE : VK_FALSE; + g_f2 = VkPhysicalDeviceFeatures2{}; + g_f2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; + g_f2.pNext = &g_v12; + g_f2.features.shaderStorageImageWriteWithoutFormat = VK_TRUE; + g_f2.features.shaderStorageImageExtendedFormats = VK_TRUE; + return &g_f2; +} + +void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled) { + if (!g_probed) fill_instance(gipa, inst); + g_pd = pd; g_dev = dev; g_queue = queue; g_qfam = qfam; + fill_device(dev); + g_caps.featuresEnabled = features_enabled != 0; + lsfg::explain(g_caps); + g_ready = true; + ELOG("device ready: lsfg caps '%s', storage on ring format %d", g_caps.reason, + (int)g_caps.storageOnSwapchainFormat); +} + +int fge_caps_ok(int kind) { + if (!g_ready) return 0; + if (kind == 1) return g_caps.storageOnSwapchainFormat ? 1 : 0; + return g_caps.supported() ? 1 : 0; +} + +const char *fge_caps_reason(void) { return g_caps.reason; } + +int fge_format_ok(VkFormat fmt) { + if (!g_ready || !g_table.GetPhysicalDeviceFormatProperties || fmt == VK_FORMAT_UNDEFINED) return 0; + return lsfg::probeStorageFormat(g_table, g_pd, fmt) && lsfg::probeLinearBlit(g_table, g_pd, fmt) ? 1 : 0; +} + +int fge_start(int kind, const char *cache_path) { + fge_stop(); + if (!g_ready) return -1; + if (kind == 1) { + auto e = std::make_unique<winfg::Engine>(); + if (!e->init(g_table, g_pd, g_dev, g_qfam, g_queue)) { + ELOGE("winfg-native: engine init failed"); + return -1; + } + g_winfg = std::move(e); + g_kind = 1; +#if defined(WINFG_UPSTREAM) && defined(WINFG_CHAIN_HASH) + std::snprintf(g_build, sizeof(g_build), "chain %s, src %s", WINFG_UPSTREAM, WINFG_CHAIN_HASH); +#else + std::snprintf(g_build, sizeof(g_build), "embedded chain"); +#endif + return 0; + } + if (!cache_path || !*cache_path) return -1; + if (!lsfgVkdInit(g_table)) { + ELOGE("lsfg-native: dispatch incomplete"); + return -1; + } + auto e = std::make_unique<lsfg::Engine>(); + if (!e->init(g_dev, g_pd, cache_path, g_caps.features.spirvTarget)) { + ELOGE("lsfg-native: engine init failed (cache %s, spirv target 0x%x)", cache_path, + g_caps.features.spirvTarget); + return -1; + } + g_lsfg = std::move(e); + g_kind = 0; + std::snprintf(g_build, sizeof(g_build), "spirv target 0x%x, cache %s", + g_caps.features.spirvTarget, cache_path); + return 0; +} + +void fge_stop(void) { + if ((g_lsfg || g_winfg) && g_table.DeviceWaitIdle && g_dev) g_table.DeviceWaitIdle(g_dev); + g_lsfg.reset(); + g_winfg.reset(); + g_kind = -1; +} + +int fge_unavailable(void) { + if (g_kind == 1) return g_winfg && g_winfg->unavailable() ? 1 : 0; + return g_lsfg && g_lsfg->unavailable() ? 1 : 0; +} + +void fge_configure(uint32_t multiplier, float flow_scale, float refresh_hz, int model, + int perf_preset) { + if (multiplier < 2) multiplier = 2; + if (g_kind == 1 && g_winfg) g_winfg->configure(multiplier, model, perf_preset, flow_scale); + else if (g_lsfg) g_lsfg->configure(multiplier, 0, flow_scale, refresh_hz); +} + +int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) { + if (g_kind == 1) return g_winfg && g_winfg->prepare(w, h, fmt) ? 1 : 0; + if (!g_lsfg) return 0; + // The Wayland scene is the game's own size when it runs fullscreen, so the flow pyramid is + // scaled against that (X11 passes the X screen size here for the same reason). + g_lsfg->setGuestExtent(w, h); + return g_lsfg->prepare(w, h, fmt) ? 1 : 0; +} + +uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) { + if (g_kind == 1) return g_winfg ? g_winfg->plan(capacity) : 0; + if (!g_lsfg) return 0; + g_lsfg->setPresentedRate(presented_rate); + return g_lsfg->plan(capacity, source_frames); +} + +void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) { + if (g_kind == 1) { if (g_winfg) g_winfg->process(cmd, source, w, h, gens); return; } + if (g_lsfg) g_lsfg->process(cmd, source, w, h, gens); +} + +void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view, + uint32_t w, uint32_t h) { + if (g_kind == 1) { if (g_winfg) g_winfg->generateInto(cmd, g, count, img, view, w, h); return; } + if (g_lsfg) g_lsfg->generateInto(cmd, g, g, img, view, w, h); +} + +void fge_forget_targets(void) { + if (g_lsfg) g_lsfg->forgetTargets(); +} + +void fge_telemetry(float *accepted, float *source_rate, float *thermal) { + *accepted = 0.0f; *source_rate = 0.0f; *thermal = -1.0f; + if (g_kind == 0 && g_lsfg) { + *accepted = (float)g_lsfg->acceptedGenerations(); + *source_rate = g_lsfg->sourceRate(); + *thermal = (float)g_lsfg->thermalStatus(); + } +} + +const char *fge_engine_name(int kind) { return kind == 1 ? "Win-FG Native" : "LSFG Native"; } +const char *fge_build_info(void) { return g_build; } + +} // extern "C" diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine.h b/app/src/main/cpp/waylandcomp/src/framegen_engine.h new file mode 100644 index 0000000000..c7f6743e20 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine.h @@ -0,0 +1,71 @@ +#ifndef FRAMEGEN_ENGINE_H +#define FRAMEGEN_ENGINE_H +/* + * C face of the C++ frame-generation engines for framegen_bridge.c. + * + * framegen_engine.cpp wraps lsfg::Engine (winlator/lsfg) and winfg::Engine (winlator/winfg) + * unmodified - the same objects the X11 renderer (VulkanRendererContext) drives - and fills + * their dispatch tables from the compositor's own Turnip entry points. The standalone + * compositor build (no winlator tree) compiles framegen_engine_stub.c instead, which reports + * "engines not built in" and generates nothing. + * + * Every function runs on the compositor thread. + */ +#include <stdint.h> +#ifndef VK_USE_PLATFORM_ANDROID_KHR +#define VK_USE_PLATFORM_ANDROID_KHR +#endif +#include <vulkan/vulkan.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Probe the physical device and build the VkDeviceCreateInfo pNext chain the LSFG chain needs + * (vulkanMemoryModel + storage-image features; nothing for Win-FG). Returns the chain, or NULL + * when the device fails a gate. `ring_fmt` is the format the engines generate into; it must be + * storage-capable for either engine. */ +const void *fge_probe(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkFormat ring_fmt); +/* The device exists; resolve device-level entry points. features_enabled = fge_probe's chain + * was accepted by vkCreateDevice. */ +void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled); +/* 1 when engine `kind` can run on this device (its capability gates pass). */ +int fge_caps_ok(int kind); +/* Why the LSFG gates fail ("supported" when they pass); static string. */ +const char *fge_caps_reason(void); +/* 1 when the engines can generate in `fmt` on this device (storage + linear sampling), beyond the + * ring format probed at fge_probe - the FP16 scene of HDR frames (vk_present.c). */ +int fge_format_ok(VkFormat fmt); + +/* Create engine `kind` (LSFG needs the cache path; Win-FG ignores it). 0 = ready, -1 = failed. + * Only one engine holds GPU resources at a time; a different kind replaces it. */ +int fge_start(int kind, const char *cache_path); +void fge_stop(void); +/* The engine came up but later found it cannot generate (chain build failed). */ +int fge_unavailable(void); +void fge_configure(uint32_t multiplier, float flow_scale, float refresh_hz, int model, + int perf_preset); +/* Build/rebuild the chain for this extent; the guest extent for the flow pyramid is the same + * (the Wayland scene is the game's own size in fullscreen). 1 = chain valid. */ +int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt); +/* How many frames to generate for this source frame (0 until the history is valid). */ +uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate); +/* Take the scene image (GENERAL) as frame N and run the shared part of the chain. */ +void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens); +/* Synthesise generated frame g of `count` into a storage image (GENERAL). */ +void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view, + uint32_t w, uint32_t h); +/* The generation targets were recreated: drop cached descriptors. */ +void fge_forget_targets(void); +/* Engine-side telemetry: accepted generations, source rate (0 = engine has none), thermal. */ +void fge_telemetry(float *accepted, float *source_rate, float *thermal); +const char *fge_engine_name(int kind); +/* "lsfg-native"/"winfg-native" build provenance for the start log line. */ +const char *fge_build_info(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c b/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c new file mode 100644 index 0000000000..187accd60d --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_engine_stub.c @@ -0,0 +1,39 @@ +/* Stand-in for framegen_engine.cpp when the compositor is built on its own (standalone/, no + * winlator tree, no dxbc). Every engine is reported unavailable; nothing is generated. */ +#include "framegen_engine.h" + +const void *fge_probe(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkFormat ring_fmt) { + (void)gipa; (void)inst; (void)pd; (void)ring_fmt; + return NULL; +} +void fge_device_ready(PFN_vkGetInstanceProcAddr gipa, VkInstance inst, VkPhysicalDevice pd, + VkDevice dev, VkQueue queue, uint32_t qfam, int features_enabled) { + (void)gipa; (void)inst; (void)pd; (void)dev; (void)queue; (void)qfam; (void)features_enabled; +} +int fge_caps_ok(int kind) { (void)kind; return 0; } +const char *fge_caps_reason(void) { return "frame-generation engines not built into this compositor"; } +int fge_format_ok(VkFormat fmt) { (void)fmt; return 0; } +int fge_start(int kind, const char *cache_path) { (void)kind; (void)cache_path; return -1; } +void fge_stop(void) {} +int fge_unavailable(void) { return 1; } +void fge_configure(uint32_t multiplier, float flow_scale, float refresh_hz, int model, int perf_preset) { + (void)multiplier; (void)flow_scale; (void)refresh_hz; (void)model; (void)perf_preset; +} +int fge_prepare(uint32_t w, uint32_t h, VkFormat fmt) { (void)w; (void)h; (void)fmt; return 0; } +uint32_t fge_plan(uint32_t capacity, uint64_t source_frames, float presented_rate) { + (void)capacity; (void)source_frames; (void)presented_rate; return 0; +} +void fge_process(VkCommandBuffer cmd, VkImage source, uint32_t w, uint32_t h, uint32_t gens) { + (void)cmd; (void)source; (void)w; (void)h; (void)gens; +} +void fge_generate(VkCommandBuffer cmd, uint32_t g, uint32_t count, VkImage img, VkImageView view, + uint32_t w, uint32_t h) { + (void)cmd; (void)g; (void)count; (void)img; (void)view; (void)w; (void)h; +} +void fge_forget_targets(void) {} +void fge_telemetry(float *accepted, float *source_rate, float *thermal) { + *accepted = 0.0f; *source_rate = 0.0f; *thermal = -1.0f; +} +const char *fge_engine_name(int kind) { return kind == 1 ? "Win-FG Native" : "LSFG Native"; } +const char *fge_build_info(void) { return "stub"; } diff --git a/app/src/main/cpp/waylandcomp/src/framegen_jni.c b/app/src/main/cpp/waylandcomp/src/framegen_jni.c new file mode 100644 index 0000000000..3b8aaf5e96 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/framegen_jni.c @@ -0,0 +1,66 @@ +/* JNI for frame generation on the Wayland backend (WaylandCompositor.nativeFrameGen* / + * nativeSet*FrameGen* / nativeSetLsfgCachePath / nativeSetWinFgTuning). Every call only stores + * a value in framegen_bridge.c; the compositor thread picks it up on its next frame, so these + * are safe from any thread and before the compositor is up (the app arms the engine from its + * launch code while the SurfaceView is still coming). */ +#include <jni.h> +#include "framegen_bridge.h" + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetFrameGenEngine(JNIEnv *env, jclass clazz, jint kind) { + (void)env; (void)clazz; + vkp_framegen_set_engine((int)kind); +} + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetFrameGenArmed(JNIEnv *env, jclass clazz, + jboolean armed, jint multiplier) { + (void)env; (void)clazz; + vkp_framegen_set_armed(armed ? 1 : 0, (int)multiplier); +} + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetLsfgCachePath(JNIEnv *env, jclass clazz, jstring path) { + (void)clazz; + if (!path) { vkp_framegen_set_lsfg_cache_path(NULL); return; } + const char *c = (*env)->GetStringUTFChars(env, path, NULL); + vkp_framegen_set_lsfg_cache_path(c); + if (c) (*env)->ReleaseStringUTFChars(env, path, c); +} + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetFrameGenTuning(JNIEnv *env, jclass clazz, + jfloat flowScale, jfloat refreshHz) { + (void)env; (void)clazz; + vkp_framegen_set_tuning((float)flowScale, (float)refreshHz); +} + +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetWinFgTuning(JNIEnv *env, jclass clazz, + jint model, jint perfPreset) { + (void)env; (void)clazz; + vkp_framegen_set_winfg_tuning((int)model, (int)perfPreset); +} + +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeFrameGenProblem(JNIEnv *env, jclass clazz) { + (void)env; (void)clazz; + return (jint)vkp_framegen_problem(); +} + +JNIEXPORT jstring JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeFrameGenCapsReason(JNIEnv *env, jclass clazz) { + (void)clazz; + const char *r = vkp_framegen_caps_reason(); + return (*env)->NewStringUTF(env, r ? r : ""); +} + +JNIEXPORT jfloatArray JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeFrameGenStats(JNIEnv *env, jclass clazz) { + (void)clazz; + float st[6] = {0.f, 0.f, 0.f, 0.f, -1.f, -1.f}; + vkp_framegen_stats(st); + jfloatArray arr = (*env)->NewFloatArray(env, 6); + if (arr) (*env)->SetFloatArrayRegion(env, arr, 0, 6, st); + return arr; +} diff --git a/app/src/main/cpp/waylandcomp/src/hdr_compose.c b/app/src/main/cpp/waylandcomp/src/hdr_compose.c new file mode 100644 index 0000000000..c2abf7a3d8 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/hdr_compose.c @@ -0,0 +1,298 @@ +/* HDR composition: the encode pass over the mixed scene - see hdr_compose.h. Compositor thread. */ +#define _POSIX_C_SOURCE 200809L +#include "hdr_compose.h" +#include "vk_loader.h" +#include "vk_present.h" /* banner_log, vkp_gpu_name */ +#include <stdio.h> +#include <string.h> + +/* SPIR-V, pre-compiled (glslangValidator -V hdr_encode.frag --vn hdr_encode_code) and committed next + * to the GLSL, like every other shader of the compositor: the NDK build compiles no shaders. The quad + * is the effect chain's upscale.vert (same bytes, from app/src/main/cpp/winlator). */ +/* The headers define plain (external) arrays and effects_chain.c includes upscale_vert.h too: this + * translation unit gets its own copy under another name, so the link sees no duplicate symbol. */ +#define upscale_vert_code hdrc_upscale_vert_code +#include "upscale_vert.h" +#undef upscale_vert_code +#include "hdr_encode_frag.h" + +#define MIXED_FORMAT VK_FORMAT_A2B10G10R10_UNORM_PACK32 + +struct pc_encode { float ndc[4]; float params[4]; float rects[HDRC_MAX_RECTS][4]; }; /* 128 bytes */ + +static VkDevice g_dev; +static int g_ready; /* 0 = not built, 1 = ok, -1 = unavailable (said once) */ +static VkSampler g_sampler; +static VkDescriptorSetLayout g_dsl; +static VkPipelineLayout g_pl; +static VkDescriptorPool g_dpool; +static VkShaderModule g_vert, g_frag; + +/* One render pass + pipeline per output format: the HDR picture is 10-bit, frame generation's scene + * 8-bit - or FP16 where the engine takes it (vk_present.c FG_HDR_FMT). */ +#define NFMT 3 +static struct { VkFormat fmt; VkRenderPass rp; VkPipeline pipe; } g_out[NFMT] = { + {VK_FORMAT_A2B10G10R10_UNORM_PACK32}, {VK_FORMAT_R8G8B8A8_UNORM}, {VK_FORMAT_R16G16B16A16_SFLOAT}}; + +/* The mixed image's view + descriptor, and each output image's view + framebuffer: kept while the + * image handle (and size) stays the same, rebuilt when vk_present re-creates the image. */ +static struct { VkImage img; int w, h; VkImageView view; VkDescriptorSet ds; } g_src; +#define NOUT 3 +static struct { VkImage img; VkFormat fmt; int w, h; VkImageView view; VkFramebuffer fb; } g_dst[NOUT]; +static int g_dst_next; + +void hdrc_bind_device(VkDevice dev, const VkPhysicalDeviceMemoryProperties *memprops) { + (void)memprops; + g_dev = dev; +} + +static void src_release(void) { + if (g_src.ds) g_vk.FreeDescriptorSets(g_dev, g_dpool, 1, &g_src.ds); + if (g_src.view) g_vk.DestroyImageView(g_dev, g_src.view, NULL); + memset(&g_src, 0, sizeof(g_src)); +} + +static void dst_release(int i) { + if (g_dst[i].fb) g_vk.DestroyFramebuffer(g_dev, g_dst[i].fb, NULL); + if (g_dst[i].view) g_vk.DestroyImageView(g_dev, g_dst[i].view, NULL); + memset(&g_dst[i], 0, sizeof(g_dst[i])); +} + +void hdrc_forget_image(VkImage img) { + if (!g_dev || !img) return; + if (g_src.img == img) src_release(); + for (int i = 0; i < NOUT; i++) if (g_dst[i].img == img) dst_release(i); +} + +void hdrc_destroy(void) { + if (!g_dev) return; + src_release(); + for (int i = 0; i < NOUT; i++) dst_release(i); + for (int i = 0; i < NFMT; i++) { + if (g_out[i].pipe) g_vk.DestroyPipeline(g_dev, g_out[i].pipe, NULL); + if (g_out[i].rp) g_vk.DestroyRenderPass(g_dev, g_out[i].rp, NULL); + g_out[i].pipe = VK_NULL_HANDLE; g_out[i].rp = VK_NULL_HANDLE; + } + if (g_vert) g_vk.DestroyShaderModule(g_dev, g_vert, NULL); + if (g_frag) g_vk.DestroyShaderModule(g_dev, g_frag, NULL); + if (g_dpool) g_vk.DestroyDescriptorPool(g_dev, g_dpool, NULL); + if (g_pl) g_vk.DestroyPipelineLayout(g_dev, g_pl, NULL); + if (g_dsl) g_vk.DestroyDescriptorSetLayout(g_dev, g_dsl, NULL); + if (g_sampler) g_vk.DestroySampler(g_dev, g_sampler, NULL); + g_vert = g_frag = VK_NULL_HANDLE; g_dpool = VK_NULL_HANDLE; g_pl = VK_NULL_HANDLE; + g_dsl = VK_NULL_HANDLE; g_sampler = VK_NULL_HANDLE; + g_ready = 0; + g_dev = VK_NULL_HANDLE; +} + +static VkShaderModule shader(const uint32_t *code, size_t size) { + VkShaderModule m = VK_NULL_HANDLE; + VkShaderModuleCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, .codeSize = size, .pCode = code}; + if (g_vk.CreateShaderModule(g_dev, &ci, NULL, &m) != VK_SUCCESS) return VK_NULL_HANDLE; + return m; +} + +/* The render pass: one colour target written whole (DONT_CARE), left in TRANSFER_DST_OPTIMAL for the + * effects chain / the copies that follow. The dependencies order it after whoever read or wrote the + * target last (last frame's blit or chain) and before whoever samples, blits or copies it next. */ +static VkRenderPass make_rp(VkFormat fmt) { + VkAttachmentDescription att = {.format = fmt, .samples = VK_SAMPLE_COUNT_1_BIT, + .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .finalLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL}; + VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; + VkSubpassDescription sub = {.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, .colorAttachmentCount = 1, + .pColorAttachments = &ref}; + VkSubpassDependency deps[2] = { + {.srcSubpass = VK_SUBPASS_EXTERNAL, .dstSubpass = 0, + .srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + .srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT}, + {.srcSubpass = 0, .dstSubpass = VK_SUBPASS_EXTERNAL, + .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + .dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT}}; + VkRenderPassCreateInfo rci = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, .attachmentCount = 1, + .pAttachments = &att, .subpassCount = 1, .pSubpasses = &sub, + .dependencyCount = 2, .pDependencies = deps}; + VkRenderPass rp = VK_NULL_HANDLE; + if (g_vk.CreateRenderPass(g_dev, &rci, NULL, &rp) != VK_SUCCESS) return VK_NULL_HANDLE; + return rp; +} + +static VkPipeline make_pipe(VkRenderPass rp) { + VkPipelineShaderStageCreateInfo st[2] = { + {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_VERTEX_BIT, + .module = g_vert, .pName = "main"}, + {.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, + .module = g_frag, .pName = "main"}}; + VkPipelineVertexInputStateCreateInfo vi = {.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO}; + VkPipelineInputAssemblyStateCreateInfo ia = {.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP}; + VkDynamicState dyn[2] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; + VkPipelineDynamicStateCreateInfo ds = {.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = 2, .pDynamicStates = dyn}; + VkPipelineViewportStateCreateInfo vp = {.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + .viewportCount = 1, .scissorCount = 1}; + VkPipelineRasterizationStateCreateInfo rs = {.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, + .polygonMode = VK_POLYGON_MODE_FILL, .cullMode = VK_CULL_MODE_NONE, + .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, .lineWidth = 1.0f}; + VkPipelineMultisampleStateCreateInfo ms = {.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, + .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT}; + VkPipelineColorBlendAttachmentState ba = {.blendEnable = VK_FALSE, .colorWriteMask = 0xF}; + VkPipelineColorBlendStateCreateInfo cb = {.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, + .attachmentCount = 1, .pAttachments = &ba}; + VkGraphicsPipelineCreateInfo pi = {.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .stageCount = 2, + .pStages = st, .pVertexInputState = &vi, .pInputAssemblyState = &ia, + .pViewportState = &vp, .pRasterizationState = &rs, .pMultisampleState = &ms, + .pColorBlendState = &cb, .pDynamicState = &ds, .layout = g_pl, + .renderPass = rp, .subpass = 0}; + VkPipeline p = VK_NULL_HANDLE; + if (g_vk.CreateGraphicsPipelines(g_dev, VK_NULL_HANDLE, 1, &pi, NULL, &p) != VK_SUCCESS) return VK_NULL_HANDLE; + return p; +} + +static int objects_ensure(void) { + if (g_ready) return g_ready == 1 ? 0 : -1; + g_ready = -1; + if (!g_dev || !g_vk.CreateGraphicsPipelines) goto fail; + VkSamplerCreateInfo sci = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .magFilter = VK_FILTER_NEAREST, + .minFilter = VK_FILTER_NEAREST, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, + .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE}; + if (g_vk.CreateSampler(g_dev, &sci, NULL, &g_sampler) != VK_SUCCESS) goto fail; + VkDescriptorSetLayoutBinding b = {.binding = 0, .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .descriptorCount = 1, .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT}; + VkDescriptorSetLayoutCreateInfo dli = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + .bindingCount = 1, .pBindings = &b}; + if (g_vk.CreateDescriptorSetLayout(g_dev, &dli, NULL, &g_dsl) != VK_SUCCESS) goto fail; + VkPushConstantRange pcr = {.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, + .offset = 0, .size = sizeof(struct pc_encode)}; + VkPipelineLayoutCreateInfo pli = {.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 1, + .pSetLayouts = &g_dsl, .pushConstantRangeCount = 1, .pPushConstantRanges = &pcr}; + if (g_vk.CreatePipelineLayout(g_dev, &pli, NULL, &g_pl) != VK_SUCCESS) goto fail; + VkDescriptorPoolSize ps = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2}; + VkDescriptorPoolCreateInfo dpi = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, + .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, .maxSets = 2, + .poolSizeCount = 1, .pPoolSizes = &ps}; + if (g_vk.CreateDescriptorPool(g_dev, &dpi, NULL, &g_dpool) != VK_SUCCESS) goto fail; + if (!(g_vert = shader(hdrc_upscale_vert_code, sizeof(hdrc_upscale_vert_code)))) goto fail; + if (!(g_frag = shader(hdr_encode_code, sizeof(hdr_encode_code)))) goto fail; + for (int i = 0; i < NFMT; i++) { + if (!(g_out[i].rp = make_rp(g_out[i].fmt))) goto fail; + if (!(g_out[i].pipe = make_pipe(g_out[i].rp))) goto fail; + } + g_ready = 1; + banner_log("color", "HDR composition ready on %s: scenes that mix HDR and SDR content are put into one " + "encoding (PQ BT.2020, or tone-mapped sRGB) instead of being shown washed out", vkp_gpu_name()); + return 0; +fail: + { + VkDevice keep = g_dev; + hdrc_destroy(); + g_dev = keep; + } + g_ready = -1; + banner_log("error", "color: the HDR composition pass could not be built on this driver; HDR scenes that cannot " + "stay on the game's own layer are shown the old way (washed out) this session"); + return -1; +} + +static VkImageView make_view(VkImage img, VkFormat fmt) { + VkImageView v = VK_NULL_HANDLE; + VkImageViewCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .image = img, + .viewType = VK_IMAGE_VIEW_TYPE_2D, .format = fmt, + .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}}; + if (g_vk.CreateImageView(g_dev, &ci, NULL, &v) != VK_SUCCESS) return VK_NULL_HANDLE; + return v; +} + +static int src_ensure(VkImage img, int w, int h) { + if (g_src.img == img && g_src.w == w && g_src.h == h && g_src.ds) return 0; + src_release(); + if (!(g_src.view = make_view(img, MIXED_FORMAT))) return -1; + VkDescriptorSetAllocateInfo ai = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, + .descriptorPool = g_dpool, .descriptorSetCount = 1, .pSetLayouts = &g_dsl}; + if (g_vk.AllocateDescriptorSets(g_dev, &ai, &g_src.ds) != VK_SUCCESS) { g_src.ds = VK_NULL_HANDLE; src_release(); return -1; } + VkDescriptorImageInfo ii = {.sampler = g_sampler, .imageView = g_src.view, + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL}; + VkWriteDescriptorSet wr = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .dstSet = g_src.ds, .dstBinding = 0, + .descriptorCount = 1, .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .pImageInfo = &ii}; + g_vk.UpdateDescriptorSets(g_dev, 1, &wr, 0, NULL); + g_src.img = img; g_src.w = w; g_src.h = h; + return 0; +} + +static int fmt_slot(VkFormat fmt) { + for (int i = 0; i < NFMT; i++) if (g_out[i].fmt == fmt) return i; + return -1; +} + +static VkFramebuffer dst_ensure(VkImage img, VkFormat fmt, int w, int h, VkRenderPass rp) { + for (int i = 0; i < NOUT; i++) + if (g_dst[i].img == img && g_dst[i].fmt == fmt && g_dst[i].w == w && g_dst[i].h == h && g_dst[i].fb) + return g_dst[i].fb; + int i = g_dst_next; + g_dst_next = (g_dst_next + 1) % NOUT; + dst_release(i); + if (!(g_dst[i].view = make_view(img, fmt))) return VK_NULL_HANDLE; + VkFramebufferCreateInfo fi = {.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .renderPass = rp, + .attachmentCount = 1, .pAttachments = &g_dst[i].view, .width = (uint32_t)w, + .height = (uint32_t)h, .layers = 1}; + if (g_vk.CreateFramebuffer(g_dev, &fi, NULL, &g_dst[i].fb) != VK_SUCCESS) { g_dst[i].fb = VK_NULL_HANDLE; dst_release(i); return VK_NULL_HANDLE; } + g_dst[i].img = img; g_dst[i].fmt = fmt; g_dst[i].w = w; g_dst[i].h = h; + return g_dst[i].fb; +} + +int hdrc_encode(VkCommandBuffer cmd, VkImage mixed, VkImage out, VkFormat out_fmt, int w, int h, + const struct hdrc_params *p) { + if (!mixed || !out || w <= 0 || h <= 0 || !p || objects_ensure() != 0) return -1; + int slot = fmt_slot(out_fmt); + if (slot < 0) return -1; + if (src_ensure(mixed, w, h) != 0) return -1; + VkFramebuffer fb = dst_ensure(out, out_fmt, w, h, g_out[slot].rp); + if (!fb) return -1; + + /* The composite blits wrote the mixed image; the pass samples it. */ + VkImageMemoryBarrier b = {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, + .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = mixed, .subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .dstAccessMask = VK_ACCESS_SHADER_READ_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, + 0, 0, NULL, 0, NULL, 1, &b); + + struct pc_encode pc; + memset(&pc, 0, sizeof(pc)); + pc.ndc[0] = -1.0f; pc.ndc[1] = -1.0f; pc.ndc[2] = 1.0f; pc.ndc[3] = 1.0f; + int count = p->count < 0 ? 0 : p->count > HDRC_MAX_RECTS ? HDRC_MAX_RECTS : p->count; + unsigned mask = p->hdr_mask & ((1u << HDRC_MAX_RECTS) - 1u); + pc.params[0] = p->sdr_white_nits > 0.0f ? p->sdr_white_nits : 203.0f; + pc.params[1] = p->peak_nits > 0.0f ? p->peak_nits : 1000.0f; + pc.params[2] = p->mode == HDRC_OUT_SDR ? 1.0f : 0.0f; + pc.params[3] = (float)count + 16.0f * (float)mask; + for (int i = 0; i < count; i++) memcpy(pc.rects[i], p->rects[i], sizeof(pc.rects[i])); + + VkRenderPassBeginInfo rpi = {.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, .renderPass = g_out[slot].rp, + .framebuffer = fb, .renderArea = {{0, 0}, {(uint32_t)w, (uint32_t)h}}}; + VkViewport vp = {0, 0, (float)w, (float)h, 0, 1}; + VkRect2D sc = {{0, 0}, {(uint32_t)w, (uint32_t)h}}; + g_vk.CmdBeginRenderPass(cmd, &rpi, VK_SUBPASS_CONTENTS_INLINE); + g_vk.CmdSetViewport(cmd, 0, 1, &vp); + g_vk.CmdSetScissor(cmd, 0, 1, &sc); + g_vk.CmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_out[slot].pipe); + g_vk.CmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, g_pl, 0, 1, &g_src.ds, 0, NULL); + g_vk.CmdPushConstants(cmd, g_pl, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(pc), &pc); + g_vk.CmdDraw(cmd, 4, 1, 0, 0); + g_vk.CmdEndRenderPass(cmd); + return 0; +} diff --git a/app/src/main/cpp/waylandcomp/src/hdr_compose.h b/app/src/main/cpp/waylandcomp/src/hdr_compose.h new file mode 100644 index 0000000000..cfeef74972 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/hdr_compose.h @@ -0,0 +1,52 @@ +#ifndef HDR_COMPOSE_H +#define HDR_COMPOSE_H +/* + * HDR composition (round 2 of HDR_RECON.md's Phase B): when an HDR game cannot be alone on its own + * display layer - screen effects on, frame generation on, a window above it on a display that cannot + * compose a second layer, a windowed game, a frame without a gralloc buffer - the whole scene is put + * into ONE encoding instead of being blitted into an 8-bit sRGB target as it stands (which shows the + * game's PQ frames washed out). + * + * vk_present.c blits every draw 1:1 into a 10-bit "mixed" image (each pixel still in its own + * encoding) and hdrc_encode() runs hdr_encode.frag over it into the output image: + * HDRC_OUT_PQ - PQ BT.2020 (SDR pixels placed at the SDR reference white): goes onto the game's + * display layer tagged BT2020_PQ (sc_layer.c), or into an HDR10 swapchain; + * HDRC_OUT_SDR - sRGB BT.709 with the HDR pixels tone-mapped: for a present that cannot carry HDR. + * Which encoding a pixel is in comes from the draws' rectangles (the topmost draw decides). + * + * Compositor thread. Objects are built lazily on the first use; if the driver refuses them, the + * encode is unavailable for the session (logged once) and the caller falls back. + */ +#define VK_USE_PLATFORM_ANDROID_KHR +#include <vulkan/vulkan.h> + +#define HDRC_MAX_RECTS 6 + +enum hdrc_mode { HDRC_OUT_PQ = 0, HDRC_OUT_SDR = 1 }; + +struct hdrc_params { + enum hdrc_mode mode; + float sdr_white_nits; /* SDR reference white inside the HDR picture (203) */ + float peak_nits; /* HDR content peak for the tone-map (max CLL / mastering max, else 1000) */ + int count; /* rects, top draw first */ + unsigned hdr_mask; /* bit i: rects[i] is an HDR draw */ + float rects[HDRC_MAX_RECTS][4]; /* scene pixels x0, y0, x1, y1 */ +}; + +/* Called from dev_init (device up). */ +void hdrc_bind_device(VkDevice dev, const VkPhysicalDeviceMemoryProperties *memprops); +/* Device teardown. */ +void hdrc_destroy(void); +/* vk_present is about to destroy `img` (a resize of the mixed / scene / picture image): drop the view, + * descriptor and framebuffer cached for it, so a later image that happens to reuse the handle value is + * never drawn through a view of the destroyed one. */ +void hdrc_forget_image(VkImage img); + +/* Record the encode: `mixed` (w x h, VK_FORMAT_A2B10G10R10_UNORM_PACK32, in TRANSFER_DST_OPTIMAL after + * the composite blits) -> `out` (w x h, out_fmt, created with COLOR_ATTACHMENT + SAMPLED usage), which + * is left in TRANSFER_DST_OPTIMAL - the layout vkp_effects_run() takes its scene in. 0 = recorded, + * -1 = unavailable (nothing recorded; `mixed` untouched). */ +int hdrc_encode(VkCommandBuffer cmd, VkImage mixed, VkImage out, VkFormat out_fmt, int w, int h, + const struct hdrc_params *p); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/hdr_encode.frag b/app/src/main/cpp/waylandcomp/src/hdr_encode.frag new file mode 100644 index 0000000000..4b75ed5861 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/hdr_encode.frag @@ -0,0 +1,129 @@ +#version 450 + +// ============================================================================= +// HDR composition: one encoding for the whole scene (waylandcomp/src/hdr_compose.c). +// +// The compositor composes with blits, which copy values and know nothing about what they mean. +// When an HDR game (PQ-encoded BT.2020 frames) shares the scene with SDR content (sRGB windows, the +// desktop, a window above the game), every draw is first blitted 1:1 into a 10-bit "mixed" image - +// each pixel still in its own encoding - and this pass turns the mixed image into ONE encoding: +// +// mode 0 (HDR out, PQ BT.2020): HDR pixels pass through; SDR pixels are decoded (sRGB), +// converted BT.709 -> BT.2020 and placed at the SDR reference white (params.x nits, +// 203 = Report ITU-R BT.2408), then PQ-encoded. +// mode 1 (SDR out, sRGB): SDR pixels pass through; HDR pixels are PQ-decoded, converted +// BT.2020 -> BT.709, tone-mapped relative to the SDR reference white (linear below a +// knee, a smooth roll-off above it that puts the content's peak, params.y nits, at 98 %) +// and sRGB-encoded - what a display that cannot take HDR gets instead of washed-out PQ. +// +// Which encoding a pixel is in: the topmost draw covering it decides. params.w packs the number of +// rects (count, 0..6) and a bitmask of which of them are HDR (count + 16 * mask); rects are scene +// pixels (x0, y0, x1, y1), TOP draw first, listed down to the lowest HDR draw (everything below +// that is SDR, and so is any pixel no listed rect covers). +// +// Conventions match upscale.vert / the effect passes: combined-image-sampler at binding 0, the +// push-constant block leads with vec4 ndc (offset 0). The target is exactly scene-sized, so +// gl_FragCoord is the scene pixel and texelFetch reads the mixed image 1:1 (no filtering). +// Float-only mask arithmetic (no bitwise ops). +// ============================================================================= + +layout(binding = 0) uniform sampler2D Mixed; + +layout(push_constant) uniform PC { + vec4 ndc; // upscale.vert's quad + vec4 params; // x = SDR white nits, y = HDR content peak nits (mode 1), z = mode, w = count + 16 * mask + vec4 rects[6]; // top-first scene rects +} pc; + +layout(location = 0) in vec2 fragTexCoord; +layout(location = 0) out vec4 outColor; + +const float PQ_M1 = 0.1593017578125; +const float PQ_M2 = 78.84375; +const float PQ_C1 = 0.8359375; +const float PQ_C2 = 18.8515625; +const float PQ_C3 = 18.6875; + +// Column-major: each group of three is one COLUMN (the coefficients of R, then of G, then of B). +const mat3 BT709_TO_BT2020 = mat3(0.6274, 0.0691, 0.0164, + 0.3293, 0.9195, 0.0880, + 0.0433, 0.0114, 0.8956); +const mat3 BT2020_TO_BT709 = mat3( 1.6605, -0.1246, -0.0182, + -0.5876, 1.1329, -0.1006, + -0.0728, -0.0083, 1.1187); + +vec3 srgbToLinear(vec3 c) { + vec3 lo = c / 12.92; + vec3 hi = pow((c + 0.055) / 1.055, vec3(2.4)); + return mix(lo, hi, step(vec3(0.04045), c)); +} + +vec3 linearToSrgb(vec3 c) { + vec3 lo = c * 12.92; + vec3 hi = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055; + return mix(lo, hi, step(vec3(0.0031308), c)); +} + +// PQ code (0..1) -> luminance / 10000 cd/m2 (SMPTE ST 2084 EOTF). +vec3 pqToLinear(vec3 e) { + vec3 p = pow(clamp(e, 0.0, 1.0), vec3(1.0 / PQ_M2)); + return pow(max(p - PQ_C1, 0.0) / max(PQ_C2 - PQ_C3 * p, 1e-6), vec3(1.0 / PQ_M1)); +} + +// luminance / 10000 cd/m2 -> PQ code (inverse EOTF). +vec3 linearToPq(vec3 y) { + vec3 p = pow(clamp(y, 0.0, 1.0), vec3(PQ_M1)); + return pow((PQ_C1 + PQ_C2 * p) / (1.0 + PQ_C3 * p), vec3(PQ_M2)); +} + +// Tone curve in units of SDR white: identity up to the knee, then an exponential roll-off towards 1 +// whose rate puts `peak` (also in SDR-white units) at 98 % of the range. +float toneCurve(float x, float peak) { + const float knee = 0.8; + if (x <= knee) return x; + float span = max(peak - knee, 0.05); + float rate = max(span / 3.912, 1.0 - knee); // ln(50) = 3.912; never steeper than the identity + return knee + (1.0 - knee) * (1.0 - exp(-(x - knee) / rate)); +} + +bool isHdrPixel(vec2 p) { + float packed = pc.params.w; + float count = mod(packed, 16.0); + float mask = floor(packed / 16.0); + for (int i = 0; i < 6; i++) { + if (float(i) >= count - 0.5) break; + vec4 r = pc.rects[i]; + if (p.x >= r.x && p.y >= r.y && p.x < r.z && p.y < r.w) { + float bit = mod(floor(mask / exp2(float(i))), 2.0); + return bit > 0.5; + } + } + return false; +} + +void main() { + vec3 c = texelFetch(Mixed, ivec2(gl_FragCoord.xy), 0).rgb; + bool hdr = isHdrPixel(gl_FragCoord.xy); + float sdrWhite = max(pc.params.x, 1.0); + vec3 outc; + if (pc.params.z < 0.5) { + // HDR out: PQ BT.2020. + if (hdr) { + outc = c; + } else { + vec3 nits = (BT709_TO_BT2020 * srgbToLinear(c)) * sdrWhite; + outc = linearToPq(nits / 10000.0); + } + } else { + // SDR out: sRGB BT.709, HDR tone-mapped. + if (!hdr) { + outc = c; + } else { + vec3 rel = max(BT2020_TO_BT709 * (pqToLinear(c) * 10000.0), 0.0) / sdrWhite; + float m = max(max(rel.r, rel.g), rel.b); + if (m > 1e-6) rel *= toneCurve(m, max(pc.params.y, sdrWhite) / sdrWhite) / m; + outc = linearToSrgb(clamp(rel, 0.0, 1.0)); + } + } + outColor = vec4(outc, 1.0); +} diff --git a/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h b/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h new file mode 100644 index 0000000000..eb1536f1f3 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/hdr_encode_frag.h @@ -0,0 +1,282 @@ + // 1116.5.0 + #pragma once +const uint32_t hdr_encode_code[] = { + 0x07230203,0x00010000,0x0008000b,0x0000018e,0x00000000,0x00020011,0x00000001,0x0006000b, + 0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001, + 0x0008000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x0000010d,0x00000186,0x0000018d, + 0x00030010,0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004, + 0x6e69616d,0x00000000,0x00070005,0x0000000b,0x62677273,0x694c6f54,0x7261656e,0x33667628, + 0x0000003b,0x00030005,0x0000000a,0x00000063,0x00070005,0x0000000e,0x656e696c,0x6f547261, + 0x62677253,0x33667628,0x0000003b,0x00030005,0x0000000d,0x00000063,0x00060005,0x00000011, + 0x6f547170,0x656e694c,0x76287261,0x003b3366,0x00030005,0x00000010,0x00000065,0x00060005, + 0x00000014,0x656e696c,0x6f547261,0x76287150,0x003b3366,0x00030005,0x00000013,0x00000079, + 0x00070005,0x0000001a,0x656e6f74,0x76727543,0x31662865,0x3b31663b,0x00000000,0x00030005, + 0x00000018,0x00000078,0x00040005,0x00000019,0x6b616570,0x00000000,0x00060005,0x00000021, + 0x64487369,0x78695072,0x76286c65,0x003b3266,0x00030005,0x00000020,0x00000070,0x00030005, + 0x00000023,0x00006f6c,0x00030005,0x00000028,0x00006968,0x00030005,0x0000003c,0x00006f6c, + 0x00030005,0x0000003f,0x00006968,0x00030005,0x00000050,0x00000070,0x00030005,0x0000006f, + 0x00000070,0x00040005,0x0000008c,0x6e617073,0x00000000,0x00040005,0x00000091,0x65746172, + 0x00000000,0x00040005,0x000000a2,0x6b636170,0x00006465,0x00030005,0x000000a7,0x00004350, + 0x00040006,0x000000a7,0x00000000,0x0063646e,0x00050006,0x000000a7,0x00000001,0x61726170, + 0x0000736d,0x00050006,0x000000a7,0x00000002,0x74636572,0x00000073,0x00030005,0x000000a9, + 0x00006370,0x00040005,0x000000b0,0x6e756f63,0x00000074,0x00040005,0x000000b4,0x6b73616d, + 0x00000000,0x00030005,0x000000b9,0x00000069,0x00030005,0x000000cd,0x00000072,0x00030005, + 0x000000f5,0x00746962,0x00030005,0x00000106,0x00000063,0x00040005,0x0000010a,0x6578694d, + 0x00000064,0x00060005,0x0000010d,0x465f6c67,0x43676172,0x64726f6f,0x00000000,0x00030005, + 0x00000116,0x00726468,0x00040005,0x00000117,0x61726170,0x0000006d,0x00050005,0x0000011b, + 0x57726473,0x65746968,0x00000000,0x00040005,0x00000127,0x6374756f,0x00000000,0x00040005, + 0x0000012a,0x7374696e,0x00000000,0x00040005,0x00000139,0x61726170,0x0000006d,0x00040005, + 0x00000143,0x61726170,0x0000006d,0x00030005,0x0000014c,0x006c6572,0x00040005,0x0000015a, + 0x61726170,0x0000006d,0x00030005,0x00000164,0x0000006d,0x00040005,0x00000177,0x61726170, + 0x0000006d,0x00040005,0x00000179,0x61726170,0x0000006d,0x00040005,0x00000183,0x61726170, + 0x0000006d,0x00050005,0x00000186,0x4374756f,0x726f6c6f,0x00000000,0x00060005,0x0000018d, + 0x67617266,0x43786554,0x64726f6f,0x00000000,0x00040047,0x000000a6,0x00000006,0x00000010, + 0x00030047,0x000000a7,0x00000002,0x00050048,0x000000a7,0x00000000,0x00000023,0x00000000, + 0x00050048,0x000000a7,0x00000001,0x00000023,0x00000010,0x00050048,0x000000a7,0x00000002, + 0x00000023,0x00000020,0x00040047,0x0000010a,0x00000021,0x00000000,0x00040047,0x0000010a, + 0x00000022,0x00000000,0x00040047,0x0000010d,0x0000000b,0x0000000f,0x00040047,0x00000186, + 0x0000001e,0x00000000,0x00040047,0x0000018d,0x0000001e,0x00000000,0x00020013,0x00000002, + 0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007, + 0x00000006,0x00000003,0x00040020,0x00000008,0x00000007,0x00000007,0x00040021,0x00000009, + 0x00000007,0x00000008,0x00040020,0x00000016,0x00000007,0x00000006,0x00050021,0x00000017, + 0x00000006,0x00000016,0x00000016,0x00040017,0x0000001c,0x00000006,0x00000002,0x00040020, + 0x0000001d,0x00000007,0x0000001c,0x00020014,0x0000001e,0x00040021,0x0000001f,0x0000001e, + 0x0000001d,0x0004002b,0x00000006,0x00000025,0x414eb852,0x0004002b,0x00000006,0x0000002a, + 0x3d6147ae,0x0004002b,0x00000006,0x0000002d,0x3f870a3d,0x0004002b,0x00000006,0x00000030, + 0x4019999a,0x0006002c,0x00000007,0x00000031,0x00000030,0x00000030,0x00000030,0x0004002b, + 0x00000006,0x00000035,0x3d25aee6,0x0006002c,0x00000007,0x00000036,0x00000035,0x00000035, + 0x00000035,0x0004002b,0x00000006,0x00000041,0x3ed55555,0x0006002c,0x00000007,0x00000042, + 0x00000041,0x00000041,0x00000041,0x0004002b,0x00000006,0x00000049,0x3b4d2e1c,0x0006002c, + 0x00000007,0x0000004a,0x00000049,0x00000049,0x00000049,0x0004002b,0x00000006,0x00000052, + 0x00000000,0x0004002b,0x00000006,0x00000053,0x3f800000,0x0004002b,0x00000006,0x00000057, + 0x3c4fcdac,0x0006002c,0x00000007,0x00000058,0x00000057,0x00000057,0x00000057,0x0004002b, + 0x00000006,0x0000005b,0x3f560000,0x0004002b,0x00000006,0x00000060,0x4196d000,0x0004002b, + 0x00000006,0x00000061,0x41958000,0x0004002b,0x00000006,0x00000066,0x358637bd,0x0004002b, + 0x00000006,0x0000006a,0x40c8e06b,0x0006002c,0x00000007,0x0000006b,0x0000006a,0x0000006a, + 0x0000006a,0x0004002b,0x00000006,0x00000074,0x3e232000,0x0006002c,0x00000007,0x00000075, + 0x00000074,0x00000074,0x00000074,0x0004002b,0x00000006,0x00000080,0x429db000,0x0006002c, + 0x00000007,0x00000081,0x00000080,0x00000080,0x00000080,0x0004002b,0x00000006,0x00000086, + 0x3f4ccccd,0x0004002b,0x00000006,0x0000008f,0x3d4ccccd,0x0004002b,0x00000006,0x00000093, + 0x407a5e35,0x0004002b,0x00000006,0x00000095,0x3e4ccccd,0x00040017,0x000000a3,0x00000006, + 0x00000004,0x00040015,0x000000a4,0x00000020,0x00000000,0x0004002b,0x000000a4,0x000000a5, + 0x00000006,0x0004001c,0x000000a6,0x000000a3,0x000000a5,0x0005001e,0x000000a7,0x000000a3, + 0x000000a3,0x000000a6,0x00040020,0x000000a8,0x00000009,0x000000a7,0x0004003b,0x000000a8, + 0x000000a9,0x00000009,0x00040015,0x000000aa,0x00000020,0x00000001,0x0004002b,0x000000aa, + 0x000000ab,0x00000001,0x0004002b,0x000000a4,0x000000ac,0x00000003,0x00040020,0x000000ad, + 0x00000009,0x00000006,0x0004002b,0x00000006,0x000000b2,0x41800000,0x00040020,0x000000b8, + 0x00000007,0x000000aa,0x0004002b,0x000000aa,0x000000ba,0x00000000,0x0004002b,0x000000aa, + 0x000000c1,0x00000006,0x0004002b,0x00000006,0x000000c6,0x3f000000,0x00040020,0x000000cc, + 0x00000007,0x000000a3,0x0004002b,0x000000aa,0x000000ce,0x00000002,0x00040020,0x000000d0, + 0x00000009,0x000000a3,0x0004002b,0x000000a4,0x000000d3,0x00000000,0x0004002b,0x000000a4, + 0x000000db,0x00000001,0x0004002b,0x000000a4,0x000000e6,0x00000002,0x0004002b,0x00000006, + 0x000000fc,0x40000000,0x0003002a,0x0000001e,0x00000103,0x00090019,0x00000107,0x00000006, + 0x00000001,0x00000000,0x00000000,0x00000000,0x00000001,0x00000000,0x0003001b,0x00000108, + 0x00000107,0x00040020,0x00000109,0x00000000,0x00000108,0x0004003b,0x00000109,0x0000010a, + 0x00000000,0x00040020,0x0000010c,0x00000001,0x000000a3,0x0004003b,0x0000010c,0x0000010d, + 0x00000001,0x00040017,0x00000110,0x000000aa,0x00000002,0x00040020,0x00000115,0x00000007, + 0x0000001e,0x00040018,0x0000012b,0x00000007,0x00000003,0x0004002b,0x00000006,0x0000012c, + 0x3f209d49,0x0004002b,0x00000006,0x0000012d,0x3d8d844d,0x0004002b,0x00000006,0x0000012e, + 0x3c86594b,0x0006002c,0x00000007,0x0000012f,0x0000012c,0x0000012d,0x0000012e,0x0004002b, + 0x00000006,0x00000130,0x3ea89a02,0x0004002b,0x00000006,0x00000131,0x3f6b645a,0x0004002b, + 0x00000006,0x00000132,0x3db43958,0x0006002c,0x00000007,0x00000133,0x00000130,0x00000131, + 0x00000132,0x0004002b,0x00000006,0x00000134,0x3d315b57,0x0004002b,0x00000006,0x00000135, + 0x3c3ac711,0x0004002b,0x00000006,0x00000136,0x3f65460b,0x0006002c,0x00000007,0x00000137, + 0x00000134,0x00000135,0x00000136,0x0006002c,0x0000012b,0x00000138,0x0000012f,0x00000133, + 0x00000137,0x0004002b,0x00000006,0x00000140,0x461c4000,0x0004002b,0x00000006,0x0000014d, + 0x3fd48b44,0x0004002b,0x00000006,0x0000014e,0xbdff2e49,0x0004002b,0x00000006,0x0000014f, + 0xbc95182b,0x0006002c,0x00000007,0x00000150,0x0000014d,0x0000014e,0x0000014f,0x0004002b, + 0x00000006,0x00000151,0xbf166cf4,0x0004002b,0x00000006,0x00000152,0x3f9102de,0x0004002b, + 0x00000006,0x00000153,0xbdce075f,0x0006002c,0x00000007,0x00000154,0x00000151,0x00000152, + 0x00000153,0x0004002b,0x00000006,0x00000155,0xbd95182b,0x0004002b,0x00000006,0x00000156, + 0xbc07fcb9,0x0004002b,0x00000006,0x00000157,0x3f8f3190,0x0006002c,0x00000007,0x00000158, + 0x00000155,0x00000156,0x00000157,0x0006002c,0x0000012b,0x00000159,0x00000150,0x00000154, + 0x00000158,0x00040020,0x00000185,0x00000003,0x000000a3,0x0004003b,0x00000185,0x00000186, + 0x00000003,0x00040020,0x0000018c,0x00000001,0x0000001c,0x0004003b,0x0000018c,0x0000018d, + 0x00000001,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005, + 0x0004003b,0x00000008,0x00000106,0x00000007,0x0004003b,0x00000115,0x00000116,0x00000007, + 0x0004003b,0x0000001d,0x00000117,0x00000007,0x0004003b,0x00000016,0x0000011b,0x00000007, + 0x0004003b,0x00000008,0x00000127,0x00000007,0x0004003b,0x00000008,0x0000012a,0x00000007, + 0x0004003b,0x00000008,0x00000139,0x00000007,0x0004003b,0x00000008,0x00000143,0x00000007, + 0x0004003b,0x00000008,0x0000014c,0x00000007,0x0004003b,0x00000008,0x0000015a,0x00000007, + 0x0004003b,0x00000016,0x00000164,0x00000007,0x0004003b,0x00000016,0x00000177,0x00000007, + 0x0004003b,0x00000016,0x00000179,0x00000007,0x0004003b,0x00000008,0x00000183,0x00000007, + 0x0004003d,0x00000108,0x0000010b,0x0000010a,0x0004003d,0x000000a3,0x0000010e,0x0000010d, + 0x0007004f,0x0000001c,0x0000010f,0x0000010e,0x0000010e,0x00000000,0x00000001,0x0004006e, + 0x00000110,0x00000111,0x0000010f,0x00040064,0x00000107,0x00000112,0x0000010b,0x0007005f, + 0x000000a3,0x00000113,0x00000112,0x00000111,0x00000002,0x000000ba,0x0008004f,0x00000007, + 0x00000114,0x00000113,0x00000113,0x00000000,0x00000001,0x00000002,0x0003003e,0x00000106, + 0x00000114,0x0004003d,0x000000a3,0x00000118,0x0000010d,0x0007004f,0x0000001c,0x00000119, + 0x00000118,0x00000118,0x00000000,0x00000001,0x0003003e,0x00000117,0x00000119,0x00050039, + 0x0000001e,0x0000011a,0x00000021,0x00000117,0x0003003e,0x00000116,0x0000011a,0x00060041, + 0x000000ad,0x0000011c,0x000000a9,0x000000ab,0x000000d3,0x0004003d,0x00000006,0x0000011d, + 0x0000011c,0x0007000c,0x00000006,0x0000011e,0x00000001,0x00000028,0x0000011d,0x00000053, + 0x0003003e,0x0000011b,0x0000011e,0x00060041,0x000000ad,0x0000011f,0x000000a9,0x000000ab, + 0x000000e6,0x0004003d,0x00000006,0x00000120,0x0000011f,0x000500b8,0x0000001e,0x00000121, + 0x00000120,0x000000c6,0x000300f7,0x00000123,0x00000000,0x000400fa,0x00000121,0x00000122, + 0x00000145,0x000200f8,0x00000122,0x0004003d,0x0000001e,0x00000124,0x00000116,0x000300f7, + 0x00000126,0x00000000,0x000400fa,0x00000124,0x00000125,0x00000129,0x000200f8,0x00000125, + 0x0004003d,0x00000007,0x00000128,0x00000106,0x0003003e,0x00000127,0x00000128,0x000200f9, + 0x00000126,0x000200f8,0x00000129,0x0004003d,0x00000007,0x0000013a,0x00000106,0x0003003e, + 0x00000139,0x0000013a,0x00050039,0x00000007,0x0000013b,0x0000000b,0x00000139,0x00050091, + 0x00000007,0x0000013c,0x00000138,0x0000013b,0x0004003d,0x00000006,0x0000013d,0x0000011b, + 0x0005008e,0x00000007,0x0000013e,0x0000013c,0x0000013d,0x0003003e,0x0000012a,0x0000013e, + 0x0004003d,0x00000007,0x0000013f,0x0000012a,0x00060050,0x00000007,0x00000141,0x00000140, + 0x00000140,0x00000140,0x00050088,0x00000007,0x00000142,0x0000013f,0x00000141,0x0003003e, + 0x00000143,0x00000142,0x00050039,0x00000007,0x00000144,0x00000014,0x00000143,0x0003003e, + 0x00000127,0x00000144,0x000200f9,0x00000126,0x000200f8,0x00000126,0x000200f9,0x00000123, + 0x000200f8,0x00000145,0x0004003d,0x0000001e,0x00000146,0x00000116,0x000400a8,0x0000001e, + 0x00000147,0x00000146,0x000300f7,0x00000149,0x00000000,0x000400fa,0x00000147,0x00000148, + 0x0000014b,0x000200f8,0x00000148,0x0004003d,0x00000007,0x0000014a,0x00000106,0x0003003e, + 0x00000127,0x0000014a,0x000200f9,0x00000149,0x000200f8,0x0000014b,0x0004003d,0x00000007, + 0x0000015b,0x00000106,0x0003003e,0x0000015a,0x0000015b,0x00050039,0x00000007,0x0000015c, + 0x00000011,0x0000015a,0x0005008e,0x00000007,0x0000015d,0x0000015c,0x00000140,0x00050091, + 0x00000007,0x0000015e,0x00000159,0x0000015d,0x00060050,0x00000007,0x0000015f,0x00000052, + 0x00000052,0x00000052,0x0007000c,0x00000007,0x00000160,0x00000001,0x00000028,0x0000015e, + 0x0000015f,0x0004003d,0x00000006,0x00000161,0x0000011b,0x00060050,0x00000007,0x00000162, + 0x00000161,0x00000161,0x00000161,0x00050088,0x00000007,0x00000163,0x00000160,0x00000162, + 0x0003003e,0x0000014c,0x00000163,0x00050041,0x00000016,0x00000165,0x0000014c,0x000000d3, + 0x0004003d,0x00000006,0x00000166,0x00000165,0x00050041,0x00000016,0x00000167,0x0000014c, + 0x000000db,0x0004003d,0x00000006,0x00000168,0x00000167,0x0007000c,0x00000006,0x00000169, + 0x00000001,0x00000028,0x00000166,0x00000168,0x00050041,0x00000016,0x0000016a,0x0000014c, + 0x000000e6,0x0004003d,0x00000006,0x0000016b,0x0000016a,0x0007000c,0x00000006,0x0000016c, + 0x00000001,0x00000028,0x00000169,0x0000016b,0x0003003e,0x00000164,0x0000016c,0x0004003d, + 0x00000006,0x0000016d,0x00000164,0x000500ba,0x0000001e,0x0000016e,0x0000016d,0x00000066, + 0x000300f7,0x00000170,0x00000000,0x000400fa,0x0000016e,0x0000016f,0x00000170,0x000200f8, + 0x0000016f,0x00060041,0x000000ad,0x00000171,0x000000a9,0x000000ab,0x000000db,0x0004003d, + 0x00000006,0x00000172,0x00000171,0x0004003d,0x00000006,0x00000173,0x0000011b,0x0007000c, + 0x00000006,0x00000174,0x00000001,0x00000028,0x00000172,0x00000173,0x0004003d,0x00000006, + 0x00000175,0x0000011b,0x00050088,0x00000006,0x00000176,0x00000174,0x00000175,0x0004003d, + 0x00000006,0x00000178,0x00000164,0x0003003e,0x00000177,0x00000178,0x0003003e,0x00000179, + 0x00000176,0x00060039,0x00000006,0x0000017a,0x0000001a,0x00000177,0x00000179,0x0004003d, + 0x00000006,0x0000017b,0x00000164,0x00050088,0x00000006,0x0000017c,0x0000017a,0x0000017b, + 0x0004003d,0x00000007,0x0000017d,0x0000014c,0x0005008e,0x00000007,0x0000017e,0x0000017d, + 0x0000017c,0x0003003e,0x0000014c,0x0000017e,0x000200f9,0x00000170,0x000200f8,0x00000170, + 0x0004003d,0x00000007,0x0000017f,0x0000014c,0x00060050,0x00000007,0x00000180,0x00000052, + 0x00000052,0x00000052,0x00060050,0x00000007,0x00000181,0x00000053,0x00000053,0x00000053, + 0x0008000c,0x00000007,0x00000182,0x00000001,0x0000002b,0x0000017f,0x00000180,0x00000181, + 0x0003003e,0x00000183,0x00000182,0x00050039,0x00000007,0x00000184,0x0000000e,0x00000183, + 0x0003003e,0x00000127,0x00000184,0x000200f9,0x00000149,0x000200f8,0x00000149,0x000200f9, + 0x00000123,0x000200f8,0x00000123,0x0004003d,0x00000007,0x00000187,0x00000127,0x00050051, + 0x00000006,0x00000188,0x00000187,0x00000000,0x00050051,0x00000006,0x00000189,0x00000187, + 0x00000001,0x00050051,0x00000006,0x0000018a,0x00000187,0x00000002,0x00070050,0x000000a3, + 0x0000018b,0x00000188,0x00000189,0x0000018a,0x00000053,0x0003003e,0x00000186,0x0000018b, + 0x000100fd,0x00010038,0x00050036,0x00000007,0x0000000b,0x00000000,0x00000009,0x00030037, + 0x00000008,0x0000000a,0x000200f8,0x0000000c,0x0004003b,0x00000008,0x00000023,0x00000007, + 0x0004003b,0x00000008,0x00000028,0x00000007,0x0004003d,0x00000007,0x00000024,0x0000000a, + 0x00060050,0x00000007,0x00000026,0x00000025,0x00000025,0x00000025,0x00050088,0x00000007, + 0x00000027,0x00000024,0x00000026,0x0003003e,0x00000023,0x00000027,0x0004003d,0x00000007, + 0x00000029,0x0000000a,0x00060050,0x00000007,0x0000002b,0x0000002a,0x0000002a,0x0000002a, + 0x00050081,0x00000007,0x0000002c,0x00000029,0x0000002b,0x00060050,0x00000007,0x0000002e, + 0x0000002d,0x0000002d,0x0000002d,0x00050088,0x00000007,0x0000002f,0x0000002c,0x0000002e, + 0x0007000c,0x00000007,0x00000032,0x00000001,0x0000001a,0x0000002f,0x00000031,0x0003003e, + 0x00000028,0x00000032,0x0004003d,0x00000007,0x00000033,0x00000023,0x0004003d,0x00000007, + 0x00000034,0x00000028,0x0004003d,0x00000007,0x00000037,0x0000000a,0x0007000c,0x00000007, + 0x00000038,0x00000001,0x00000030,0x00000036,0x00000037,0x0008000c,0x00000007,0x00000039, + 0x00000001,0x0000002e,0x00000033,0x00000034,0x00000038,0x000200fe,0x00000039,0x00010038, + 0x00050036,0x00000007,0x0000000e,0x00000000,0x00000009,0x00030037,0x00000008,0x0000000d, + 0x000200f8,0x0000000f,0x0004003b,0x00000008,0x0000003c,0x00000007,0x0004003b,0x00000008, + 0x0000003f,0x00000007,0x0004003d,0x00000007,0x0000003d,0x0000000d,0x0005008e,0x00000007, + 0x0000003e,0x0000003d,0x00000025,0x0003003e,0x0000003c,0x0000003e,0x0004003d,0x00000007, + 0x00000040,0x0000000d,0x0007000c,0x00000007,0x00000043,0x00000001,0x0000001a,0x00000040, + 0x00000042,0x0005008e,0x00000007,0x00000044,0x00000043,0x0000002d,0x00060050,0x00000007, + 0x00000045,0x0000002a,0x0000002a,0x0000002a,0x00050083,0x00000007,0x00000046,0x00000044, + 0x00000045,0x0003003e,0x0000003f,0x00000046,0x0004003d,0x00000007,0x00000047,0x0000003c, + 0x0004003d,0x00000007,0x00000048,0x0000003f,0x0004003d,0x00000007,0x0000004b,0x0000000d, + 0x0007000c,0x00000007,0x0000004c,0x00000001,0x00000030,0x0000004a,0x0000004b,0x0008000c, + 0x00000007,0x0000004d,0x00000001,0x0000002e,0x00000047,0x00000048,0x0000004c,0x000200fe, + 0x0000004d,0x00010038,0x00050036,0x00000007,0x00000011,0x00000000,0x00000009,0x00030037, + 0x00000008,0x00000010,0x000200f8,0x00000012,0x0004003b,0x00000008,0x00000050,0x00000007, + 0x0004003d,0x00000007,0x00000051,0x00000010,0x00060050,0x00000007,0x00000054,0x00000052, + 0x00000052,0x00000052,0x00060050,0x00000007,0x00000055,0x00000053,0x00000053,0x00000053, + 0x0008000c,0x00000007,0x00000056,0x00000001,0x0000002b,0x00000051,0x00000054,0x00000055, + 0x0007000c,0x00000007,0x00000059,0x00000001,0x0000001a,0x00000056,0x00000058,0x0003003e, + 0x00000050,0x00000059,0x0004003d,0x00000007,0x0000005a,0x00000050,0x00060050,0x00000007, + 0x0000005c,0x0000005b,0x0000005b,0x0000005b,0x00050083,0x00000007,0x0000005d,0x0000005a, + 0x0000005c,0x00060050,0x00000007,0x0000005e,0x00000052,0x00000052,0x00000052,0x0007000c, + 0x00000007,0x0000005f,0x00000001,0x00000028,0x0000005d,0x0000005e,0x0004003d,0x00000007, + 0x00000062,0x00000050,0x0005008e,0x00000007,0x00000063,0x00000062,0x00000061,0x00060050, + 0x00000007,0x00000064,0x00000060,0x00000060,0x00000060,0x00050083,0x00000007,0x00000065, + 0x00000064,0x00000063,0x00060050,0x00000007,0x00000067,0x00000066,0x00000066,0x00000066, + 0x0007000c,0x00000007,0x00000068,0x00000001,0x00000028,0x00000065,0x00000067,0x00050088, + 0x00000007,0x00000069,0x0000005f,0x00000068,0x0007000c,0x00000007,0x0000006c,0x00000001, + 0x0000001a,0x00000069,0x0000006b,0x000200fe,0x0000006c,0x00010038,0x00050036,0x00000007, + 0x00000014,0x00000000,0x00000009,0x00030037,0x00000008,0x00000013,0x000200f8,0x00000015, + 0x0004003b,0x00000008,0x0000006f,0x00000007,0x0004003d,0x00000007,0x00000070,0x00000013, + 0x00060050,0x00000007,0x00000071,0x00000052,0x00000052,0x00000052,0x00060050,0x00000007, + 0x00000072,0x00000053,0x00000053,0x00000053,0x0008000c,0x00000007,0x00000073,0x00000001, + 0x0000002b,0x00000070,0x00000071,0x00000072,0x0007000c,0x00000007,0x00000076,0x00000001, + 0x0000001a,0x00000073,0x00000075,0x0003003e,0x0000006f,0x00000076,0x0004003d,0x00000007, + 0x00000077,0x0000006f,0x0005008e,0x00000007,0x00000078,0x00000077,0x00000060,0x00060050, + 0x00000007,0x00000079,0x0000005b,0x0000005b,0x0000005b,0x00050081,0x00000007,0x0000007a, + 0x00000079,0x00000078,0x0004003d,0x00000007,0x0000007b,0x0000006f,0x0005008e,0x00000007, + 0x0000007c,0x0000007b,0x00000061,0x00060050,0x00000007,0x0000007d,0x00000053,0x00000053, + 0x00000053,0x00050081,0x00000007,0x0000007e,0x0000007d,0x0000007c,0x00050088,0x00000007, + 0x0000007f,0x0000007a,0x0000007e,0x0007000c,0x00000007,0x00000082,0x00000001,0x0000001a, + 0x0000007f,0x00000081,0x000200fe,0x00000082,0x00010038,0x00050036,0x00000006,0x0000001a, + 0x00000000,0x00000017,0x00030037,0x00000016,0x00000018,0x00030037,0x00000016,0x00000019, + 0x000200f8,0x0000001b,0x0004003b,0x00000016,0x0000008c,0x00000007,0x0004003b,0x00000016, + 0x00000091,0x00000007,0x0004003d,0x00000006,0x00000085,0x00000018,0x000500bc,0x0000001e, + 0x00000087,0x00000085,0x00000086,0x000300f7,0x00000089,0x00000000,0x000400fa,0x00000087, + 0x00000088,0x00000089,0x000200f8,0x00000088,0x0004003d,0x00000006,0x0000008a,0x00000018, + 0x000200fe,0x0000008a,0x000200f8,0x00000089,0x0004003d,0x00000006,0x0000008d,0x00000019, + 0x00050083,0x00000006,0x0000008e,0x0000008d,0x00000086,0x0007000c,0x00000006,0x00000090, + 0x00000001,0x00000028,0x0000008e,0x0000008f,0x0003003e,0x0000008c,0x00000090,0x0004003d, + 0x00000006,0x00000092,0x0000008c,0x00050088,0x00000006,0x00000094,0x00000092,0x00000093, + 0x0007000c,0x00000006,0x00000096,0x00000001,0x00000028,0x00000094,0x00000095,0x0003003e, + 0x00000091,0x00000096,0x0004003d,0x00000006,0x00000097,0x00000018,0x00050083,0x00000006, + 0x00000098,0x00000097,0x00000086,0x0004007f,0x00000006,0x00000099,0x00000098,0x0004003d, + 0x00000006,0x0000009a,0x00000091,0x00050088,0x00000006,0x0000009b,0x00000099,0x0000009a, + 0x0006000c,0x00000006,0x0000009c,0x00000001,0x0000001b,0x0000009b,0x00050083,0x00000006, + 0x0000009d,0x00000053,0x0000009c,0x00050085,0x00000006,0x0000009e,0x00000095,0x0000009d, + 0x00050081,0x00000006,0x0000009f,0x00000086,0x0000009e,0x000200fe,0x0000009f,0x00010038, + 0x00050036,0x0000001e,0x00000021,0x00000000,0x0000001f,0x00030037,0x0000001d,0x00000020, + 0x000200f8,0x00000022,0x0004003b,0x00000016,0x000000a2,0x00000007,0x0004003b,0x00000016, + 0x000000b0,0x00000007,0x0004003b,0x00000016,0x000000b4,0x00000007,0x0004003b,0x000000b8, + 0x000000b9,0x00000007,0x0004003b,0x000000cc,0x000000cd,0x00000007,0x0004003b,0x00000016, + 0x000000f5,0x00000007,0x00060041,0x000000ad,0x000000ae,0x000000a9,0x000000ab,0x000000ac, + 0x0004003d,0x00000006,0x000000af,0x000000ae,0x0003003e,0x000000a2,0x000000af,0x0004003d, + 0x00000006,0x000000b1,0x000000a2,0x0005008d,0x00000006,0x000000b3,0x000000b1,0x000000b2, + 0x0003003e,0x000000b0,0x000000b3,0x0004003d,0x00000006,0x000000b5,0x000000a2,0x00050088, + 0x00000006,0x000000b6,0x000000b5,0x000000b2,0x0006000c,0x00000006,0x000000b7,0x00000001, + 0x00000008,0x000000b6,0x0003003e,0x000000b4,0x000000b7,0x0003003e,0x000000b9,0x000000ba, + 0x000200f9,0x000000bb,0x000200f8,0x000000bb,0x000400f6,0x000000bd,0x000000be,0x00000000, + 0x000200f9,0x000000bf,0x000200f8,0x000000bf,0x0004003d,0x000000aa,0x000000c0,0x000000b9, + 0x000500b1,0x0000001e,0x000000c2,0x000000c0,0x000000c1,0x000400fa,0x000000c2,0x000000bc, + 0x000000bd,0x000200f8,0x000000bc,0x0004003d,0x000000aa,0x000000c3,0x000000b9,0x0004006f, + 0x00000006,0x000000c4,0x000000c3,0x0004003d,0x00000006,0x000000c5,0x000000b0,0x00050083, + 0x00000006,0x000000c7,0x000000c5,0x000000c6,0x000500be,0x0000001e,0x000000c8,0x000000c4, + 0x000000c7,0x000300f7,0x000000ca,0x00000000,0x000400fa,0x000000c8,0x000000c9,0x000000ca, + 0x000200f8,0x000000c9,0x000200f9,0x000000bd,0x000200f8,0x000000ca,0x0004003d,0x000000aa, + 0x000000cf,0x000000b9,0x00060041,0x000000d0,0x000000d1,0x000000a9,0x000000ce,0x000000cf, + 0x0004003d,0x000000a3,0x000000d2,0x000000d1,0x0003003e,0x000000cd,0x000000d2,0x00050041, + 0x00000016,0x000000d4,0x00000020,0x000000d3,0x0004003d,0x00000006,0x000000d5,0x000000d4, + 0x00050041,0x00000016,0x000000d6,0x000000cd,0x000000d3,0x0004003d,0x00000006,0x000000d7, + 0x000000d6,0x000500be,0x0000001e,0x000000d8,0x000000d5,0x000000d7,0x000300f7,0x000000da, + 0x00000000,0x000400fa,0x000000d8,0x000000d9,0x000000da,0x000200f8,0x000000d9,0x00050041, + 0x00000016,0x000000dc,0x00000020,0x000000db,0x0004003d,0x00000006,0x000000dd,0x000000dc, + 0x00050041,0x00000016,0x000000de,0x000000cd,0x000000db,0x0004003d,0x00000006,0x000000df, + 0x000000de,0x000500be,0x0000001e,0x000000e0,0x000000dd,0x000000df,0x000200f9,0x000000da, + 0x000200f8,0x000000da,0x000700f5,0x0000001e,0x000000e1,0x000000d8,0x000000ca,0x000000e0, + 0x000000d9,0x000300f7,0x000000e3,0x00000000,0x000400fa,0x000000e1,0x000000e2,0x000000e3, + 0x000200f8,0x000000e2,0x00050041,0x00000016,0x000000e4,0x00000020,0x000000d3,0x0004003d, + 0x00000006,0x000000e5,0x000000e4,0x00050041,0x00000016,0x000000e7,0x000000cd,0x000000e6, + 0x0004003d,0x00000006,0x000000e8,0x000000e7,0x000500b8,0x0000001e,0x000000e9,0x000000e5, + 0x000000e8,0x000200f9,0x000000e3,0x000200f8,0x000000e3,0x000700f5,0x0000001e,0x000000ea, + 0x000000e1,0x000000da,0x000000e9,0x000000e2,0x000300f7,0x000000ec,0x00000000,0x000400fa, + 0x000000ea,0x000000eb,0x000000ec,0x000200f8,0x000000eb,0x00050041,0x00000016,0x000000ed, + 0x00000020,0x000000db,0x0004003d,0x00000006,0x000000ee,0x000000ed,0x00050041,0x00000016, + 0x000000ef,0x000000cd,0x000000ac,0x0004003d,0x00000006,0x000000f0,0x000000ef,0x000500b8, + 0x0000001e,0x000000f1,0x000000ee,0x000000f0,0x000200f9,0x000000ec,0x000200f8,0x000000ec, + 0x000700f5,0x0000001e,0x000000f2,0x000000ea,0x000000e3,0x000000f1,0x000000eb,0x000300f7, + 0x000000f4,0x00000000,0x000400fa,0x000000f2,0x000000f3,0x000000f4,0x000200f8,0x000000f3, + 0x0004003d,0x00000006,0x000000f6,0x000000b4,0x0004003d,0x000000aa,0x000000f7,0x000000b9, + 0x0004006f,0x00000006,0x000000f8,0x000000f7,0x0006000c,0x00000006,0x000000f9,0x00000001, + 0x0000001d,0x000000f8,0x00050088,0x00000006,0x000000fa,0x000000f6,0x000000f9,0x0006000c, + 0x00000006,0x000000fb,0x00000001,0x00000008,0x000000fa,0x0005008d,0x00000006,0x000000fd, + 0x000000fb,0x000000fc,0x0003003e,0x000000f5,0x000000fd,0x0004003d,0x00000006,0x000000fe, + 0x000000f5,0x000500ba,0x0000001e,0x000000ff,0x000000fe,0x000000c6,0x000200fe,0x000000ff, + 0x000200f8,0x000000f4,0x000200f9,0x000000be,0x000200f8,0x000000be,0x0004003d,0x000000aa, + 0x00000101,0x000000b9,0x00050080,0x000000aa,0x00000102,0x00000101,0x000000ab,0x0003003e, + 0x000000b9,0x00000102,0x000200f9,0x000000bb,0x000200f8,0x000000bd,0x000200fe,0x00000103, + 0x00010038 +}; diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.c b/app/src/main/cpp/waylandcomp/src/sc_layer.c new file mode 100644 index 0000000000..48c9769bbc --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.c @@ -0,0 +1,1112 @@ +/* Layer mode: the scene on a small set of ASurfaceControl layers — see sc_layer.h and + * ZERO_COPY_SPIKE.md. The ASurfaceControl/ASurfaceTransaction API is dlsym'd from libandroid.so + * (API 29+), the same way the X11 renderers' scanout code does it, so the library still loads on + * older devices and the prototype stays off every other path. */ +#define _GNU_SOURCE +#include "sc_layer.h" +#include "ahb_swapchain.h" +#include "banner_color.h" +#include "vk_present.h" +#include <android/hardware_buffer.h> +#include <android/native_window.h> +#include <android/rect.h> +#include <dlfcn.h> +#include <errno.h> +#include <math.h> +#include <poll.h> +#include <pthread.h> +#include <stdatomic.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <time.h> +#include <unistd.h> + +#define FOURCC(a, b, c, d) \ + ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) +#define DRM_ABGR8888 FOURCC('A', 'B', '2', '4') /* R,G,B,A in memory = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM */ +#define DRM_ABGR2101010 FOURCC('A', 'B', '3', '0') /* = AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM (VK A2B10G10R10) */ +#define AHB_RGBA8 AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM +#define AHB_RGB10A2 AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM +#define MOD_LINEAR 0ULL +#define MOD_QCOM_COMPRESSED 0x0500000000000001ULL /* DRM_FORMAT_MOD_QCOM_COMPRESSED (UBWC) */ + +/* The gralloc buffer handle behind an AHardwareBuffer (AOSP cutils/native_handle.h, which the NDK + * does not ship; the layout is a stable ABI: fds first, then ints). */ +struct banner_native_handle { int version; int numFds; int numInts; int data[]; }; + +/* ---- libandroid SurfaceControl API (dlsym) ---------------------------------------------------- */ + +typedef struct ASurfaceControl ASurfaceControl; +typedef struct ASurfaceTransaction ASurfaceTransaction; +typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; +typedef void (*sc_complete_fn)(void *context, ASurfaceTransactionStats *stats); + +/* <android/hdr_metadata.h> (NDK, API 29), declared here like the rest of this table: stable ABI. */ +struct banner_color_xy { float x, y; }; +struct banner_hdr_smpte2086 { + struct banner_color_xy displayPrimaryRed, displayPrimaryGreen, displayPrimaryBlue, whitePoint; + float maxLuminance, minLuminance; +}; +struct banner_hdr_cta861_3 { float maxContentLightLevel, maxFrameAverageLightLevel; }; + +static struct { + ASurfaceControl *(*createFromWindow)(ANativeWindow *, const char *); + void (*release)(ASurfaceControl *); + ASurfaceTransaction *(*txCreate)(void); + void (*txDelete)(ASurfaceTransaction *); + void (*txApply)(ASurfaceTransaction *); + void (*setBuffer)(ASurfaceTransaction *, ASurfaceControl *, AHardwareBuffer *, int); + void (*setZOrder)(ASurfaceTransaction *, ASurfaceControl *, int32_t); + void (*setVisibility)(ASurfaceTransaction *, ASurfaceControl *, int8_t); + void (*setGeometry)(ASurfaceTransaction *, ASurfaceControl *, const ARect *, const ARect *, int32_t); + void (*setBufferTransparency)(ASurfaceTransaction *, ASurfaceControl *, int8_t); + void (*reparent)(ASurfaceTransaction *, ASurfaceControl *, ASurfaceControl *); + void (*setOnComplete)(ASurfaceTransaction *, void *, sc_complete_fn); + int (*prevReleaseFence)(ASurfaceTransactionStats *, ASurfaceControl *); + /* Display frame-rate vote for the layer (API 30 / 31). Optional: absent on older Android, where + * the layer simply carries no vote and the app's surface vote is all there is. */ + void (*setFrameRate)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t); + void (*setFrameRateStrategy)(ASurfaceTransaction *, ASurfaceControl *, float, int8_t, int8_t); + /* Colour (API 29), optional: only an HDR session ever calls them (banner_color.h's gate needs + * setBufferDataSpace; the metadata calls are sent when present). */ + void (*setBufferDataSpace)(ASurfaceTransaction *, ASurfaceControl *, int32_t); + void (*setHdrMetadata_smpte2086)(ASurfaceTransaction *, ASurfaceControl *, const struct banner_hdr_smpte2086 *); + void (*setHdrMetadata_cta861_3)(ASurfaceTransaction *, ASurfaceControl *, const struct banner_hdr_cta861_3 *); + /* Not in the public NDK headers (vndk/hardware_buffer.h) but exported by libnativewindow.so on + * every device; Mesa's Android WSI calls it for every gralloc buffer it imports. */ + const void *(*getNativeHandle)(const AHardwareBuffer *); + /* API 35: the HDR headroom this layer asks the display for (0 = no preference). Round 2e asks + * explicitly for every PQ layer - some phones only boost HDR when a layer asks. */ + void (*setDesiredHdrHeadroom)(ASurfaceTransaction *, ASurfaceControl *, float); + int state; /* 0 = untried, 1 = loaded, -1 = unavailable */ +} api; + +#define ASC_VISIBILITY_HIDE 0 +#define ASC_VISIBILITY_SHOW 1 +#define ASC_TRANSPARENCY_OPAQUE 2 + +static int load_api(void) { + if (api.state) return api.state == 1 ? 0 : -1; + api.state = -1; + void *nw = dlopen("libnativewindow.so", RTLD_NOW | RTLD_NOLOAD); + if (!nw) nw = dlopen("libnativewindow.so", RTLD_NOW); + api.getNativeHandle = nw ? dlsym(nw, "AHardwareBuffer_getNativeHandle") : NULL; + if (!api.getNativeHandle) { + banner_log("layer", "unavailable: libnativewindow.so has no AHardwareBuffer_getNativeHandle"); + return -1; + } + void *lib = dlopen("libandroid.so", RTLD_NOW | RTLD_NOLOAD); + if (!lib) lib = dlopen("libandroid.so", RTLD_NOW); + if (!lib) { banner_log("layer", "unavailable: dlopen(libandroid.so): %s", dlerror()); return -1; } +#define SYM(field, name) api.field = dlsym(lib, name) + SYM(createFromWindow, "ASurfaceControl_createFromWindow"); + SYM(release, "ASurfaceControl_release"); + SYM(txCreate, "ASurfaceTransaction_create"); + SYM(txDelete, "ASurfaceTransaction_delete"); + SYM(txApply, "ASurfaceTransaction_apply"); + SYM(setBuffer, "ASurfaceTransaction_setBuffer"); + SYM(setZOrder, "ASurfaceTransaction_setZOrder"); + SYM(setVisibility, "ASurfaceTransaction_setVisibility"); + SYM(setGeometry, "ASurfaceTransaction_setGeometry"); + SYM(setBufferTransparency, "ASurfaceTransaction_setBufferTransparency"); + SYM(reparent, "ASurfaceTransaction_reparent"); + SYM(setOnComplete, "ASurfaceTransaction_setOnComplete"); + SYM(prevReleaseFence, "ASurfaceTransactionStats_getPreviousReleaseFenceFd"); + SYM(setFrameRate, "ASurfaceTransaction_setFrameRate"); + SYM(setFrameRateStrategy, "ASurfaceTransaction_setFrameRateWithChangeStrategy"); + SYM(setBufferDataSpace, "ASurfaceTransaction_setBufferDataSpace"); + SYM(setHdrMetadata_smpte2086, "ASurfaceTransaction_setHdrMetadata_smpte2086"); + SYM(setHdrMetadata_cta861_3, "ASurfaceTransaction_setHdrMetadata_cta861_3"); + SYM(setDesiredHdrHeadroom, "ASurfaceTransaction_setDesiredHdrHeadroom"); +#undef SYM + if (!api.createFromWindow || !api.release || !api.txCreate || !api.txDelete || !api.txApply || + !api.setBuffer || !api.setZOrder || !api.setVisibility || !api.setGeometry || + !api.setBufferTransparency || !api.reparent || !api.setOnComplete || !api.prevReleaseFence) { + banner_log("layer", "unavailable: libandroid.so lacks part of the ASurfaceControl API (Android 10+)"); + return -1; + } + api.state = 1; + return 0; +} + +/* ---- display frame-rate vote (VRR / refresh-rate matching) ------------------------------------ */ +/* The app votes a panel cadence with Surface.setFrameRate on the compositor's SurfaceView, but a + * zero-copy game's frames never touch that surface - they go straight onto the GAME layer - so + * SurfaceFlinger needs the same vote there or the layer's cadence is invisible to it. The vote + * belongs to the layer the game is actually presenting on and to no other: the overlay layer + * carries a window that updates on its own (slow) schedule and is explicitly voted 0, so it never + * drags the panel. The rate is set from the app thread and applied on the compositor thread with + * the next transaction, so no transaction is ever created off-thread. 0 = no vote (panel free). */ +#define ASC_FRAME_RATE_COMPAT_DEFAULT 0 /* == ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT */ +#define ASC_CHANGE_FRAME_RATE_ALWAYS 1 /* == ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS */ + +static _Atomic float g_fps_want; /* what the app asked for (the game's cadence) */ + +void sc_layer_set_frame_rate(float fps) { + atomic_store(&g_fps_want, fps > 0.0f ? fps : 0.0f); +} + +/* ---- the layers and their buffer pools -------------------------------------------------------- */ + +/* Five for the game layer: one on screen, one queued, and the ones SurfaceFlinger has not reported + * back yet (its OnComplete for a transaction arrives only after the NEXT frame is presented), with + * room to spare, so a free buffer is nearly always one the display already let go of. With three, + * a late callback left none free ("no free layer buffer … frame dropped"). */ +#define POOL_MAX 5 + +struct slot { + AHardwareBuffer *ahb; + struct vkp_image *img; /* the AHB imported into the compositor's Turnip as a blit target */ + int w, h; + uint32_t fmt; /* AHARDWAREBUFFER_FORMAT_*: RGBA8888, or RGBA1010102 for an HDR picture */ + int release_fd; /* SurfaceFlinger's release fence: signals when it stopped reading; -1 = none */ + int busy; /* set on the layer, or still referenced by SurfaceFlinger */ +}; + +/* One Android display layer: its SurfaceControl, its own buffer pool and its own lifetime. The + * z-order is fixed by the id (game below, overlay above); nothing is ever re-ordered at runtime. */ +struct layer { + const char *name; + int32_t z; + int pool_n; /* buffers in this layer's pool (the game cycles more) */ + struct slot slots[POOL_MAX]; + ASurfaceControl *sc; + ANativeWindow *win; /* the output window sc was created on */ + int shown; + int cur_slot; /* pool slot of the buffer on the layer, -1 = none / not ours */ + void *cur_token; /* zero-copy: the game's buffer on the layer (NULL = a pool slot) */ + ARect geo_src, geo_dst; + int geo_valid; + int alloc_tier; /* how pool buffers are asked of gralloc (TIER_*), lowered on failure */ + uint64_t pool_modifier; + int first_logged; + int64_t drop_logged_ns; + unsigned drops_unlogged; /* frames dropped since the last "no free layer buffer" line */ + /* The last pool layout written to the log, so a line is written per change, not per buffer. */ + int logged_w, logged_h, logged_tier; + uint32_t logged_fmt; + uint64_t logged_mod; + int votes_rate; /* 1: this layer carries the game's cadence (the game layer) */ + float fps_applied; /* the vote the live SurfaceControl already carries (-1 = none yet) */ + int recreate_pending; /* composition recovery: swap this layer's SurfaceControl for a fresh + * one inside the next frame's transaction (see swap_sc_begin) */ + int32_t ds_applied; /* dataspace the live SurfaceControl carries; -1 = never set on it + * (untouched, today's UNKNOWN), see apply_colour */ + uint32_t md_applied; /* identity of the image description whose metadata it carries, 0 = none */ + float hr_applied; /* desired HDR headroom the live SurfaceControl carries; < 0 = never set */ +}; + +static struct layer g_layers[SC_LAYER_COUNT]; +static void apply_frame_rate(ASurfaceTransaction *tx, struct layer *l); +static void coverage_text(const struct layer *l, char *out, size_t n); +static int g_layers_ready; +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; /* pools + callback state */ +static int g_pending_cb; /* OnComplete callbacks not yet delivered */ +static unsigned g_stat_layer_frames; /* frames put on a layer through our own buffers */ +static int g_two_logged; +/* A small buffer set on a layer when it is hidden or retired, so SurfaceFlinger replaces (and + * releases, with a fence) the game's buffer instead of holding it while the layer is invisible. */ +static AHardwareBuffer *g_blank; + +static void layers_init(void) { + if (g_layers_ready) return; + g_layers_ready = 1; + g_layers[SC_LAYER_GAME] = (struct layer){.name = "banner_wayland_game", .z = 1, .pool_n = POOL_MAX, + .cur_slot = -1, .votes_rate = 1, .fps_applied = -1.0f, .hr_applied = -1.0f, + .ds_applied = -1}; + g_layers[SC_LAYER_OVERLAY] = (struct layer){.name = "banner_wayland_overlay", .z = 2, .pool_n = 3, + .cur_slot = -1, .votes_rate = 0, .fps_applied = -1.0f, + .hr_applied = -1.0f, .ds_applied = -1}; + for (int i = 0; i < SC_LAYER_COUNT; i++) + for (int j = 0; j < POOL_MAX; j++) g_layers[i].slots[j].release_fd = -1; +} + +static struct layer *layer_of(int id) { + layers_init(); + return (id >= 0 && id < SC_LAYER_COUNT) ? &g_layers[id] : NULL; +} + +struct complete_ctx { + ASurfaceControl *sc; + int layer; /* which layer's pool prev_slot belongs to */ + int prev_slot; /* pool buffer this transaction replaced: free once its release fence is known */ + void *prev_token; /* or the game's buffer it replaced: ahb_swapchain gets its release fence */ + int retire; /* release sc after this transaction (hide + reparent) */ +}; + +static int64_t now_ns(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +/* Binder thread. */ +static void on_complete(void *context, ASurfaceTransactionStats *stats) { + struct complete_ctx *ctx = context; + pthread_mutex_lock(&g_lock); + if (ctx->layer >= 0 && ctx->layer < SC_LAYER_COUNT && ctx->prev_slot >= 0 && ctx->prev_slot < POOL_MAX) { + struct slot *s = &g_layers[ctx->layer].slots[ctx->prev_slot]; + int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1; + if (s->release_fd >= 0) close(s->release_fd); + s->release_fd = fd; + s->busy = 0; + } + if (g_pending_cb > 0) g_pending_cb--; + pthread_mutex_unlock(&g_lock); + if (ctx->prev_token) { + int fd = (stats && ctx->sc) ? api.prevReleaseFence(stats, ctx->sc) : -1; + ahb_swapchain_layer_released(ctx->prev_token, fd); /* takes the fd */ + } + if (ctx->retire && ctx->sc) api.release(ctx->sc); + free(ctx); +} + +/* `sc` is the SurfaceControl the REPLACED buffer sits on, which is not always l->sc: during a + * composition-recovery swap the outgoing buffer belongs to the old SurfaceControl, and both its + * release fence and its release must be taken from that one. */ +static int add_complete_on(ASurfaceTransaction *tx, struct layer *l, ASurfaceControl *sc, + int prev_slot, void *prev_token, int retire) { + struct complete_ctx *ctx = calloc(1, sizeof(*ctx)); + if (!ctx) return -1; + ctx->sc = sc; ctx->layer = (int)(l - g_layers); ctx->prev_slot = prev_slot; + ctx->prev_token = prev_token; ctx->retire = retire; + pthread_mutex_lock(&g_lock); + g_pending_cb++; + pthread_mutex_unlock(&g_lock); + api.setOnComplete(tx, ctx, on_complete); + return 0; +} + +static int add_complete(ASurfaceTransaction *tx, struct layer *l, int prev_slot, void *prev_token, int retire) { + return add_complete_on(tx, l, l->sc, prev_slot, prev_token, retire); +} + +/* The stand-in buffer for a hidden/retired layer (allocated once, black, shared by both layers). */ +static AHardwareBuffer *blank_buffer(void) { + if (g_blank) return g_blank; + AHardwareBuffer_Desc d = { + .width = 16, .height = 16, .layers = 1, .format = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, + .usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | + AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY}; + if (AHardwareBuffer_allocate(&d, &g_blank) != 0 || !g_blank) { g_blank = NULL; return NULL; } + void *p = NULL; + if (AHardwareBuffer_lock(g_blank, AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY, -1, NULL, &p) == 0 && p) { + AHardwareBuffer_Desc got; AHardwareBuffer_describe(g_blank, &got); + memset(p, 0, (size_t)got.stride * 4 * 16); + AHardwareBuffer_unlock(g_blank, NULL); + } + return g_blank; +} + +/* Take the current buffer (pool slot or the game's) off the layer by putting the blank one on it, + * so SurfaceFlinger releases it with a fence through this transaction's callback. */ +static void replace_with_blank(ASurfaceTransaction *tx, struct layer *l) { + AHardwareBuffer *b = blank_buffer(); + if (b) api.setBuffer(tx, l->sc, b, -1); +} + +/* Everything a SurfaceControl needs on its way out, as transaction ops: give the buffer back (so + * SurfaceFlinger releases the game's, with a fence), hide it, unparent it. */ +static void retire_ops(ASurfaceTransaction *tx, ASurfaceControl *sc) { + AHardwareBuffer *b = blank_buffer(); + if (b) api.setBuffer(tx, sc, b, -1); + api.setVisibility(tx, sc, ASC_VISIBILITY_HIDE); + api.reparent(tx, sc, NULL); +} + +/* Hide + detach one layer; the SurfaceControl is released from the transaction's callback (the + * buffer on it stays referenced by SurfaceFlinger until then). */ +static void retire_sc(struct layer *l) { + if (!l->sc) return; + ASurfaceTransaction *tx = api.txCreate(); + if (tx) { + retire_ops(tx, l->sc); + if (add_complete(tx, l, l->cur_slot, l->cur_token, 1) != 0) api.release(l->sc); + api.txApply(tx); + api.txDelete(tx); + } else { + if (l->cur_token) ahb_swapchain_layer_released(l->cur_token, -1); + api.release(l->sc); + } + banner_log("layer", "%s: SurfaceControl retired (window %p)", l->name, (void *)l->win); + l->sc = NULL; l->win = NULL; + l->shown = 0; l->cur_slot = -1; l->cur_token = NULL; l->geo_valid = 0; + l->fps_applied = -1.0f; /* the next SurfaceControl carries no vote until it is re-applied */ + l->recreate_pending = 0; /* a fresh SurfaceControl is coming anyway */ + l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; /* ...and no colour tag either */ +} + +/* Wait (bounded) for SurfaceFlinger to finish with every pool buffer of every layer, then free + * the pools. */ +static void drain_and_free_pools(void) { + int64_t deadline = now_ns() + 300000000LL; + for (;;) { + pthread_mutex_lock(&g_lock); + int pending = g_pending_cb; + pthread_mutex_unlock(&g_lock); + if (!pending || now_ns() > deadline) break; + usleep(2000); + } + pthread_mutex_lock(&g_lock); + for (int i = 0; i < SC_LAYER_COUNT; i++) { + for (int j = 0; j < POOL_MAX; j++) { + struct slot *s = &g_layers[i].slots[j]; + if (s->release_fd >= 0) { struct pollfd p = {.fd = s->release_fd, .events = POLLIN}; poll(&p, 1, 100); close(s->release_fd); } + if (s->img) vkp_image_destroy(s->img); + if (s->ahb) AHardwareBuffer_release(s->ahb); + memset(s, 0, sizeof(*s)); + s->release_fd = -1; + } + g_layers[i].first_logged = 0; + g_layers[i].logged_w = g_layers[i].logged_h = 0; /* the next pool's layout is logged again */ + } + pthread_mutex_unlock(&g_lock); +} + +/* Native-handle sniff, the same one Mesa's u_gralloc fallback uses (u_gralloc_fallback.c): a QTI + * gralloc private_handle_t carries the magic 'gmsm' as its first int and the UBWC flag + * (PRIV_FLAGS_UBWC_ALIGNED, 0x08000000) in the next one. Returns 0 when the layout is unknown. */ +static int sniff_modifier(const struct banner_native_handle *h, uint64_t *mod) { + const uint32_t gmsm = ('g' << 24) | ('m' << 16) | ('s' << 8) | 'm'; + if (!h || h->numFds < 1 || h->numInts < 2) return 0; + if ((uint32_t)h->data[h->numFds] != gmsm) return 0; + *mod = (h->data[h->numFds + 1] & 0x08000000) ? MOD_QCOM_COMPRESSED : MOD_LINEAR; + return 1; +} + +static int g_alloc_failed; /* set by alloc_slot when gralloc or the import refused a buffer */ + +/* How a layer's pool buffers are asked of gralloc, best first; a layer only ever moves down. + * TIER_UBWC GPU render target + sampled + composer overlay + AHARDWAREBUFFER_USAGE_VENDOR_0 (bit 28): + * QTI gralloc's GRALLOC_USAGE_PRIVATE_ALLOC_UBWC. Without it QTI gralloc allocates LINEAR even + * for a GPU render target (gr_allocator.cpp IsUBwcEnabled: an explicit UBWC format, the + * private UBWC bit or CLIENT_TARGET, and no CPU bit). Whether gralloc really compressed the + * buffer is read back from its handle (sniff_modifier), never assumed. + * TIER_PLAIN the same without the vendor bit (a gralloc that refuses unknown bits; what we asked before). + * TIER_LINEAR plus a CPU bit, so the layout is known to be linear even when the handle is unreadable. */ +enum { TIER_UBWC, TIER_PLAIN, TIER_LINEAR }; +#define BANNER_AHB_USAGE_VENDOR_UBWC (1ULL << 28) /* AHARDWAREBUFFER_USAGE_VENDOR_0 */ + +static const char *tier_name(int tier) { + return tier == TIER_UBWC ? "asked for UBWC" : tier == TIER_PLAIN ? "no UBWC request" : "linear by request (CPU bit)"; +} + +static int alloc_slot(struct layer *l, struct slot *s, int w, int h, uint32_t fmt) { + g_alloc_failed = 0; + while (l->alloc_tier <= TIER_LINEAR) { + const int tier = l->alloc_tier; + AHardwareBuffer_Desc d = { + .width = (uint32_t)w, .height = (uint32_t)h, .layers = 1, + .format = fmt, + /* GPU render target (the blit writes it) + sampled (SurfaceFlinger's GPU fallback reads it) + + * composer overlay (the display scans it out). See the tiers above for the rest. */ + .usage = AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | + AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY | + (tier == TIER_UBWC ? BANNER_AHB_USAGE_VENDOR_UBWC : 0) | + (tier == TIER_LINEAR ? AHARDWAREBUFFER_USAGE_CPU_READ_RARELY : 0)}; + AHardwareBuffer *ahb = NULL; + if (AHardwareBuffer_allocate(&d, &ahb) != 0 || !ahb) { + if (tier < TIER_LINEAR) { + banner_log("layer", "%s: gralloc refused a %dx%d pool buffer (%s): trying %s", l->name, w, h, + tier_name(tier), tier_name(tier + 1)); + l->alloc_tier = tier + 1; + continue; + } + banner_log("error", "layer: %s: AHardwareBuffer_allocate %dx%d (format %#x) failed", l->name, w, h, fmt); + g_alloc_failed = 1; + return -1; + } + AHardwareBuffer_Desc got; AHardwareBuffer_describe(ahb, &got); + const struct banner_native_handle *nh = api.getNativeHandle(ahb); + uint64_t mod = MOD_LINEAR; + if (!sniff_modifier(nh, &mod)) { + /* Not a handle we can read: the only layout we can assume is linear, and only if the buffer + * was asked for with a CPU bit (gralloc must not have compressed it). */ + if (tier < TIER_LINEAR) { + AHardwareBuffer_release(ahb); + l->alloc_tier = TIER_LINEAR; + banner_log("layer", "%s: gralloc handle layout unknown (%d fds, %d ints): using linear pool buffers", + l->name, nh ? nh->numFds : -1, nh ? nh->numInts : -1); + continue; + } + mod = MOD_LINEAR; + } + int fd = (nh && nh->numFds > 0) ? nh->data[0] : -1; + /* The test create: vkp_image_import_dmabuf creates the image with gralloc's explicit layout, so a + * layout the compositor's Turnip refuses falls back a tier instead of drawing garbage. */ + struct vkp_image *img = fd >= 0 ? vkp_image_import_dmabuf(fd, fmt == AHB_RGB10A2 ? DRM_ABGR2101010 : DRM_ABGR8888, + mod, w, h, got.stride * 4, 0, 1) : NULL; + if (!img) { + banner_log("layer", "%s: import of a %s %dx%d pool buffer (stride %u px) into the compositor's Turnip failed", + l->name, mod == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", w, h, got.stride); + AHardwareBuffer_release(ahb); + if (tier < TIER_LINEAR) { l->alloc_tier = tier + 1; continue; } + g_alloc_failed = 1; + return -1; + } + s->ahb = ahb; s->img = img; s->w = w; s->h = h; s->fmt = fmt; s->release_fd = -1; s->busy = 0; + l->pool_modifier = mod; + if (l->logged_w != w || l->logged_h != h || l->logged_fmt != fmt || l->logged_mod != mod || + l->logged_tier != tier) { + l->logged_w = w; l->logged_h = h; l->logged_fmt = fmt; l->logged_mod = mod; l->logged_tier = tier; + banner_log("layer", "%s: pool buffers %dx%d%s: %s (%s), stride %u px, up to %d buffers (gralloc handle %d fds / %d ints)", + l->name, w, h, fmt == AHB_RGB10A2 ? " 10-bit RGBA1010102" : "", + mod == MOD_QCOM_COMPRESSED ? "UBWC (QCOM_COMPRESSED)" : "linear", tier_name(tier), + got.stride, l->pool_n, nh ? nh->numFds : -1, nh ? nh->numInts : -1); + } + return 0; + } + g_alloc_failed = 1; + return -1; +} + +/* 1 when a sync_file has signalled (the display has stopped reading that buffer). */ +static int fence_signalled(int fd) { + struct pollfd p = {.fd = fd, .events = POLLIN}; + int r; + do { r = poll(&p, 1, 0); } while (r < 0 && errno == EINTR); + return r > 0; +} + +/* A slot SurfaceFlinger has handed back, holding a w x h buffer of AHB format fmt. -1 = none free (or + * the buffer could not be made). A free slot whose release fence has already signalled is preferred; + * otherwise the fence of the first free one is handed back in *wait_fd for the copy to wait on ON THE + * GPU (vkp_blit_image / vkp_pass_copy_to consume it), so the compositor thread no longer blocks here. + * Only a driver without VK_KHR_external_semaphore_fd still waits on the CPU, bounded, as before. + * *wait_fd is -1 whenever nothing needs waiting for (and on every failure). */ +static int take_free_slot(struct layer *l, int w, int h, uint32_t fmt, int *wait_fd) { + int idx = -1, pending = -1, fd = -1; + *wait_fd = -1; + pthread_mutex_lock(&g_lock); + for (int i = 0; i < l->pool_n; i++) { + if (i == l->cur_slot || l->slots[i].busy) continue; + const int rf = l->slots[i].release_fd; + if (rf < 0 || fence_signalled(rf)) { idx = i; break; } + if (pending < 0) pending = i; + } + if (idx < 0) idx = pending; + if (idx >= 0) { fd = l->slots[idx].release_fd; l->slots[idx].release_fd = -1; } + pthread_mutex_unlock(&g_lock); + if (idx < 0) return -1; + if (fd >= 0 && fence_signalled(fd)) { close(fd); fd = -1; } + struct slot *s = &l->slots[idx]; + if (s->ahb && (s->w != w || s->h != h || s->fmt != fmt)) { + /* Size or format change: this slot is free, so it can be replaced at once (the display keeps its + * own reference to the old buffer for as long as it reads it; the new one needs no wait). */ + if (fd >= 0) { close(fd); fd = -1; } + vkp_image_destroy(s->img); AHardwareBuffer_release(s->ahb); + memset(s, 0, sizeof(*s)); s->release_fd = -1; + } + if (fd >= 0 && !vkp_can_wait_sync_fd()) { + struct pollfd p = {.fd = fd, .events = POLLIN}; + int r; + do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); + if (r == 0) { + /* Still read by the display: keep its fence with it (the next use waits again), drop this frame. */ + pthread_mutex_lock(&g_lock); + if (s->release_fd < 0) s->release_fd = fd; else close(fd); + pthread_mutex_unlock(&g_lock); + return -1; + } + close(fd); + fd = -1; + } + if (!s->ahb && alloc_slot(l, s, w, h, fmt) != 0) { + if (fd >= 0) close(fd); + return -1; + } + *wait_fd = fd; + return idx; +} + +/* ---- public --------------------------------------------------------------------------------- */ + +int sc_layer_available(void) { return load_api() == 0; } + +void sc_layer_probe_dmabuf_fd(int fd) { + static int done; + if (done || fd < 0) return; + done = 1; + struct { uint32_t flags; int32_t fd; } exp = {.flags = 1u /* DMA_BUF_SYNC_READ */, .fd = -1}; + /* DMA_BUF_IOCTL_EXPORT_SYNC_FILE = _IOWR('b', 2, struct dma_buf_export_sync_file) */ + if (ioctl(fd, _IOWR('b', 2, exp), &exp) == 0) { + banner_log("layer", "kernel exports sync_file fences from the game's dma-buf: zero-copy acquire fences can come from the buffer itself"); + if (exp.fd >= 0) close(exp.fd); + } else { + banner_log("layer", "DMA_BUF_IOCTL_EXPORT_SYNC_FILE on the game's dma-buf failed (%s): acquire fences must be exported by the game's driver (sync_fd) instead", + strerror(errno)); + } +} + +/* One layer's SurfaceControl on the current output window (created on first use, re-created after + * a window change). -1 = no window / no API. */ +static int ensure_sc(struct layer *l) { + if (load_api() != 0) return -1; + ANativeWindow *win = vkp_window(); + if (!win) return -1; + if (l->sc && l->win != win) retire_sc(l); + if (!l->sc) { + l->sc = api.createFromWindow(win, l->name); + if (!l->sc) { banner_log("error", "layer: ASurfaceControl_createFromWindow(%s) failed", l->name); return -1; } + l->win = win; + l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; + ASurfaceTransaction *tx = api.txCreate(); + if (tx) { + api.setZOrder(tx, l->sc, l->z); + api.setVisibility(tx, l->sc, ASC_VISIBILITY_HIDE); + apply_frame_rate(tx, l); + api.txApply(tx); api.txDelete(tx); + } + banner_log("layer", "SurfaceControl \"%s\" created as a child of the screen surface (z=%d)", l->name, (int)l->z); + } + return 0; +} + +/* Geometry of a w x h buffer covering the scene, through the same mapping the blit path and the + * app's touch mapping use. 1 = r filled, 0 = nothing of it is on screen, -1 = no mapping. */ +static int layer_geometry(int w, int h, int scene_w, int scene_h, int r[8]) { + if (vkp_update_map(scene_w, scene_h) != 0) return -1; + return vkp_map_rect(w, h, scene_w, scene_h, r) ? 1 : 0; +} + +/* The GAME layer's last placement, kept across SurfaceControl retires and swaps (l->geo_valid is + * per-SurfaceControl and is cleared by both). This is the src -> dst the display actually works + * with, and it is what decides whether a second layer is affordable — see overlay_affordable(). */ +static ARect g_game_src, g_game_dst; +static int g_game_geo_known; + +static void apply_geometry(ASurfaceTransaction *tx, struct layer *l, const int r[8]) { + ARect srcR = {r[0], r[1], r[2], r[3]}, dstR = {r[4], r[5], r[6], r[7]}; + if (l == &g_layers[SC_LAYER_GAME]) { g_game_src = srcR; g_game_dst = dstR; g_game_geo_known = 1; } + if (!l->geo_valid || memcmp(&srcR, &l->geo_src, sizeof(srcR)) || memcmp(&dstR, &l->geo_dst, sizeof(dstR))) { + api.setGeometry(tx, l->sc, &srcR, &dstR, 0 /* no transform: the DPU scales, never rotates */); + l->geo_src = srcR; l->geo_dst = dstR; l->geo_valid = 1; + char cov[96] = ""; + if (l->ds_applied > 0) coverage_text(l, cov, sizeof(cov)); + banner_log("layer", "%s geometry: buffer %d,%d-%d,%d -> screen %d,%d-%d,%d%s%s%s", l->name, + r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], cov[0] ? " (HDR layer " : "", cov, cov[0] ? ")" : ""); + } +} + +/* Add the vote to tx when it differs from what this layer carries (compositor thread). Only the + * layer the game presents on carries the game's rate; every other layer is voted 0, so a slow + * overlay window can never hold the panel at the game's cadence (or the game's at the overlay's). */ +static void apply_frame_rate(ASurfaceTransaction *tx, struct layer *l) { + float want = l->votes_rate ? atomic_load(&g_fps_want) : 0.0f; + if (want == l->fps_applied) return; + if (!api.setFrameRateStrategy && !api.setFrameRate) return; + if (api.setFrameRateStrategy) { + /* ALWAYS, like the app's own surface vote: the seamless-only default is ignored by a panel + * sitting at its peak rate, which is exactly the case we need to move. */ + api.setFrameRateStrategy(tx, l->sc, want, ASC_FRAME_RATE_COMPAT_DEFAULT, ASC_CHANGE_FRAME_RATE_ALWAYS); + } else { + api.setFrameRate(tx, l->sc, want, ASC_FRAME_RATE_COMPAT_DEFAULT); + } + int first = l->fps_applied < 0.0f; + l->fps_applied = want; + if (want > 0.0f) banner_log("layer", "display frame-rate vote on %s: %.2f Hz", l->name, want); + else if (!first) banner_log("layer", "display frame-rate vote on %s cleared (panel runs free)", l->name); +} + +/* ---- colour (HDR, banner_color.h) ------------------------------------------------------------- + * The layer is told what its buffer's pixels MEAN — the dataspace (BT2020_PQ for an HDR10 frame) and + * the game's mastering / content-light metadata — in the same transaction as the buffer, so the + * display never shows an HDR frame decoded as sRGB or the other way round. A layer that has never been + * tagged is never touched: sessions without an HDR description make no colour call at all. */ +/* How much of the screen the layer's picture covers ("covers 80% of the screen (1920x1080 of 2400x1080)"): + * some phones only switch to HDR for an HDR layer above a minimum area. Empty when unknown. */ +static void coverage_text(const struct layer *l, char *out, size_t n) { + int ow = 0, oh = 0; + vkp_output_size(&ow, &oh); + if (!l->geo_valid || ow <= 0 || oh <= 0) { if (n) out[0] = 0; return; } + int w = l->geo_dst.right - l->geo_dst.left, h = l->geo_dst.bottom - l->geo_dst.top; + if (w < 0) w = 0; + if (h < 0) h = 0; + const double pct = 100.0 * ((double)w * h) / ((double)ow * oh); + snprintf(out, n, "covers %.0f%% of the screen (%dx%d of %dx%d)", pct > 100.0 ? 100.0 : pct, w, h, ow, oh); +} + +/* API 35: ask the display for HDR headroom explicitly while the layer carries an HDR frame, and clear the + * request (0 = no preference) when it stops. Only on change; a layer never tagged is never touched. */ +static void apply_headroom(ASurfaceTransaction *tx, struct layer *l, const struct banner_color *c) { + static int said_missing; + if (!api.setDesiredHdrHeadroom) { + if (c && c->dataspace && !said_missing) { + said_missing = 1; + banner_color_note_headroom_request(-1.0f); + banner_log("color", "HDR headroom request not available on %s (Android < 15 has no " + "ASurfaceTransaction_setDesiredHdrHeadroom): the layer relies on Android's default", l->name); + } + return; + } + const float want = (c && c->dataspace) ? banner_color_desired_headroom(c, NULL, 0) : 0.0f; + if (l->hr_applied < 0.0f && want == 0.0f && !(c && c->dataspace)) return; /* never asked: leave it be */ + if (l->hr_applied >= 0.0f && fabsf(want - l->hr_applied) < 0.005f) return; + char why[200] = ""; + if (c && c->dataspace) banner_color_desired_headroom(c, why, sizeof(why)); + api.setDesiredHdrHeadroom(tx, l->sc, want); + const int first = l->hr_applied < 0.0f; + l->hr_applied = want; + banner_color_note_headroom_request(want); + if (want > 0.0f) + banner_log("color", "requested HDR headroom %.1fx on %s (%s)", want, l->name, why); + else if (c && c->dataspace) + banner_log("color", "no HDR headroom requested on %s: %s", l->name, why); + else if (!first) + banner_log("color", "HDR headroom request on %s cleared (no preference): the frame on the layer is not HDR", l->name); +} + +static void apply_colour(ASurfaceTransaction *tx, struct layer *l, const struct banner_color *c) { + int32_t want = c ? c->dataspace : BANNER_ADATASPACE_UNKNOWN; + uint32_t md = (c && c->dataspace) ? c->identity : 0; + if (!api.setBufferDataSpace) return; + if (l->ds_applied < 0 && want == BANNER_ADATASPACE_UNKNOWN) return; /* never tagged: leave it be */ + apply_headroom(tx, l, want ? c : NULL); + if (want == l->ds_applied && md == l->md_applied) return; + api.setBufferDataSpace(tx, l->sc, want); + struct banner_hdr_smpte2086 st; + struct banner_hdr_cta861_3 cta; + int st_on = c && c->dataspace && c->has_st2086, cta_on = c && c->dataspace && c->has_cta861; + if (st_on) { + st = (struct banner_hdr_smpte2086){ + .displayPrimaryRed = {c->red[0], c->red[1]}, .displayPrimaryGreen = {c->green[0], c->green[1]}, + .displayPrimaryBlue = {c->blue[0], c->blue[1]}, .whitePoint = {c->white[0], c->white[1]}, + .maxLuminance = c->max_lum, .minLuminance = c->min_lum}; + } + if (cta_on) cta = (struct banner_hdr_cta861_3){.maxContentLightLevel = c->max_cll, .maxFrameAverageLightLevel = c->max_fall}; + /* NULL clears what a previous description set: metadata never outlives the frame it belongs to. */ + if (api.setHdrMetadata_smpte2086) api.setHdrMetadata_smpte2086(tx, l->sc, st_on ? &st : NULL); + if (api.setHdrMetadata_cta861_3) api.setHdrMetadata_cta861_3(tx, l->sc, cta_on ? &cta : NULL); + if (want) { + char cov[96]; + coverage_text(l, cov, sizeof(cov)); + banner_log("color", "%s: dataspace %s (%#x) set on the display layer for image description #%u%s%s; SMPTE 2086 " + "%s, CTA-861.3 %s [%s]", l->name, want == BANNER_ADATASPACE_BT2020_PQ ? "BT2020_PQ" : "HDR", + (unsigned)want, c->identity, cov[0] ? ", " : "", cov, + st_on ? (api.setHdrMetadata_smpte2086 ? "sent" : "not supported by this Android") : "none given", + cta_on ? (api.setHdrMetadata_cta861_3 ? "sent" : "not supported by this Android") : "none given", + c->text); + } + else + banner_log("color", "%s: dataspace back to UNKNOWN (sRGB), HDR metadata cleared - the frame on the layer is " + "not an HDR frame", l->name); + l->ds_applied = want; + l->md_applied = md; +} + +int sc_layer_can_tag_hdr(void) { return load_api() == 0 && api.setBufferDataSpace != NULL; } + +void sc_layer_hdr_symbols(char *out, size_t size) { + if (load_api() != 0) { snprintf(out, size, "no display layers"); return; } + snprintf(out, size, "setBufferDataSpace %s, setHdrMetadata_smpte2086 %s, setHdrMetadata_cta861_3 %s, " + "setDesiredHdrHeadroom %s", api.setBufferDataSpace ? "yes" : "NO", + api.setHdrMetadata_smpte2086 ? "yes" : "no", api.setHdrMetadata_cta861_3 ? "yes" : "no", + api.setDesiredHdrHeadroom ? "yes (asked for per HDR frame: content peak / SDR white)" : "no (Android < 15)"); +} + +/* Once, when a second layer first goes up: HWC only composes a few layers before SurfaceFlinger + * falls back to GPU client composition, so the count is deliberately capped and said out loud. */ +static void log_layer_count(void) { + if (g_two_logged) return; + g_two_logged = 1; + banner_log("layer", "%d display layers in use: \"%s\" (z=%d) and \"%s\" (z=%d) above it, both children of the " + "screen surface; the app's own views (drawer, HUD, pointer) stay above both. %d is the cap - more " + "would push SurfaceFlinger into GPU client composition", + SC_LAYER_COUNT, g_layers[SC_LAYER_GAME].name, (int)g_layers[SC_LAYER_GAME].z, + g_layers[SC_LAYER_OVERLAY].name, (int)g_layers[SC_LAYER_OVERLAY].z, SC_LAYER_COUNT); +} + +/* ---- composition recovery --------------------------------------------------------------------- + * When the overlay is retired and the scene is one fullscreen window again, the game layer is + * marked for a swap and the swap rides the NEXT frame: a fresh SurfaceControl is created here, the + * frame is put on it, and the old one is hidden and unparented IN THE SAME TRANSACTION. Because + * SurfaceFlinger applies a transaction atomically there is never a composited frame with neither + * layer on it — no black frame, and no dropped frame beyond the one layer creation. The outgoing + * buffer is released through the OLD SurfaceControl's callback, which also releases it. + * + * ⚠️ MEASURED 2026-09-14, and the news is bad: on the Pocket FIT this does NOT bring hardware + * composition back. The swap fires 6 ms after the overlay goes, SurfaceFlinger really does hand out + * a new layer (its id changes), the game never drops a frame — and the composer still reports + * `DEVICE/CLIENT` 24 s later. Neither does dropping the layer path entirely and re-creating the + * SurfaceControl after a gap. The ONE thing that clears it is HOME + resume, which re-creates the + * app's whole window and SurfaceView (`VRI[XServerDisplayActivity]#0` becomes `#4`) — so the sticky + * client-composition state belongs to the PARENT surface (or the display), not to this child layer. + * The phase-4 note that "only re-creating the GAME layer's SurfaceControl clears it" was inferred + * from HOME + resume and is wrong; see sc_layer.h. The swap is kept because it is free and correct + * and the mechanism may differ on hardware that does not rotate every layer — but do not claim it + * restores DEVICE composition, and do not log as if it did. + * + * Returns the old SurfaceControl (the caller must add retire_ops for it to the same transaction and + * name it in add_complete_on), or NULL when no swap is due. Compositor thread. */ +static ASurfaceControl *swap_sc_begin(struct layer *l) { + if (!l->recreate_pending) return NULL; + l->recreate_pending = 0; + if (!l->sc) return NULL; /* nothing to swap; ensure_sc made a fresh one already */ + ANativeWindow *win = vkp_window(); + if (!win || win != l->win) return NULL; /* the window changed: ensure_sc re-creates it anyway */ + ASurfaceControl *fresh = api.createFromWindow(win, l->name); + if (!fresh) { + banner_log("error", "layer: %s: composition recovery could not create a new SurfaceControl", l->name); + return NULL; + } + ASurfaceControl *old = l->sc; + l->sc = fresh; + /* These describe the SurfaceControl, not the layer: the new one carries none of them yet. + * cur_slot / cur_token are deliberately NOT cleared — they name the buffer still on the OLD + * SurfaceControl, which is what the caller passes to add_complete_on as the one being replaced. */ + l->shown = 0; + l->geo_valid = 0; + l->fps_applied = -1.0f; + l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; + banner_log("layer", "composition recovery: %s got a fresh SurfaceControl now that nothing is above " + "the game (measured on this panel: hardware composition does NOT return from this alone)", l->name); + return old; +} + +/* The transaction that puts pool slot `idx` of layer `l` on screen at `r`, as `color` (NULL = no + * description). 0 = applied. */ +static int present_slot(struct layer *l, int idx, const int r[8], const struct banner_color *color) { + struct slot *s = &l->slots[idx]; + ASurfaceTransaction *tx = api.txCreate(); + if (!tx) return -1; + ASurfaceControl *old = swap_sc_begin(l); /* this frame carries the recovery swap, if one is due */ + if (old) api.setZOrder(tx, l->sc, l->z); + /* The blit was waited for on the CPU, so no acquire fence is needed (-1). */ + api.setBuffer(tx, l->sc, s->ahb, -1); + /* The compositor composes with blits, which overwrite: nothing is ever alpha-blended on the + * copy path either, so every layer is opaque and the picture matches it pixel for pixel. */ + api.setBufferTransparency(tx, l->sc, ASC_TRANSPARENCY_OPAQUE); + apply_geometry(tx, l, r); + apply_frame_rate(tx, l); + apply_colour(tx, l, color); + if (!l->shown) api.setVisibility(tx, l->sc, ASC_VISIBILITY_SHOW); + if (old) retire_ops(tx, old); + if (add_complete_on(tx, l, old ? old : l->sc, l->cur_slot, l->cur_token, old ? 1 : 0) != 0 && old) + api.release(old); /* no callback to retire it from (out of memory): let it go here */ + pthread_mutex_lock(&g_lock); + s->busy = 1; + pthread_mutex_unlock(&g_lock); + api.txApply(tx); + api.txDelete(tx); + l->cur_slot = idx; + l->cur_token = NULL; + if (!l->shown) { l->shown = 1; banner_log("layer", "%s: layer shown", l->name); } + g_stat_layer_frames++; + return 0; +} + +/* No free buffer this frame: the display still holds all of them. Counted for the 10 s perf line, and + * logged at most every 30 s with the number of frames dropped since the last line. */ +static unsigned g_pool_drops; +static void log_drop(struct layer *l) { + g_pool_drops++; + l->drops_unlogged++; + int64_t t = now_ns(); + if (!l->drop_logged_ns || t - l->drop_logged_ns > 30000000000LL) { + banner_log("layer", "%s: no free layer buffer (display still holds all %d): %u frame%s dropped%s", l->name, + l->pool_n, l->drops_unlogged, l->drops_unlogged == 1 ? "" : "s", + l->drop_logged_ns ? " since the last such line" : ""); + l->drop_logged_ns = t; + l->drops_unlogged = 0; + } +} + +unsigned sc_layer_drops_take(void) { + unsigned n = g_pool_drops; + g_pool_drops = 0; + return n; +} + +int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token, int scene_w, int scene_h, + const struct banner_color *color, uint32_t ahb_format) { + struct layer *l = layer_of(SC_LAYER_GAME); + int r[8]; + if (!ahb || !token || ensure_sc(l) != 0) goto unavailable; + int g = layer_geometry(w, h, scene_w, scene_h, r); + if (g < 0) goto unavailable; + if (g == 0) { if (acquire_fd >= 0) close(acquire_fd); sc_layer_hide(); return 1; } + if (token == l->cur_token && l->shown && !l->recreate_pending) { + /* The same frame again (the scene was redrawn for another reason): the display already + * has it; only the placement may have changed (or, rarely, its description). */ + if (acquire_fd >= 0) close(acquire_fd); + ASurfaceTransaction *tx = api.txCreate(); + if (tx) { + apply_geometry(tx, l, r); apply_frame_rate(tx, l); apply_colour(tx, l, color); + api.txApply(tx); api.txDelete(tx); + } + return 0; + } + ASurfaceTransaction *tx = api.txCreate(); + if (!tx) goto unavailable; + ASurfaceControl *old = swap_sc_begin(l); /* this frame carries the recovery swap, if one is due */ + if (old) api.setZOrder(tx, l->sc, l->z); + api.setBuffer(tx, l->sc, ahb, acquire_fd); /* the transaction owns the fence */ + api.setBufferTransparency(tx, l->sc, ASC_TRANSPARENCY_OPAQUE); + apply_geometry(tx, l, r); + apply_frame_rate(tx, l); + apply_colour(tx, l, color); + if (!l->shown) api.setVisibility(tx, l->sc, ASC_VISIBILITY_SHOW); + if (old) retire_ops(tx, old); + /* Same buffer, new SurfaceControl: it is NOT free, so no release is reported for it — the swap + * moved it rather than taking it off screen. */ + if (add_complete_on(tx, l, old ? old : l->sc, l->cur_slot, + l->cur_token == token ? NULL : l->cur_token, old ? 1 : 0) != 0) { + api.txDelete(tx); /* the fence went with the transaction */ + if (old) api.release(old); + l->ds_applied = -1; l->md_applied = 0; l->hr_applied = -1.0f; /* the colour tag went with it too: re-send it next time */ + return -1; + } + api.txApply(tx); + api.txDelete(tx); + l->cur_slot = -1; + l->cur_token = token; + if (!l->shown) { l->shown = 1; banner_log("layer", "%s: layer shown", l->name); } + if (!l->first_logged) { l->first_logged = 1; vkp_signal_first_frame(); } + if (color && color->dataspace) banner_color_frame_shown(color, BANNER_HDR_ZERO_COPY, ahb_format); + return 0; +unavailable: + if (acquire_fd >= 0) close(acquire_fd); + return -1; +} + +int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct banner_color *color) { + struct layer *l = layer_of(SC_LAYER_GAME); + if (!src || ensure_sc(l) != 0) return -1; + int sw = vkp_image_width(src), sh = vkp_image_height(src); + int r[8]; + int g = layer_geometry(sw, sh, scene_w, scene_h, r); + if (g < 0) return -1; + if (g == 0) { sc_layer_hide(); return 0; } /* nothing of it is on screen */ + + int wait_fd; + int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd); + if (idx < 0) { log_drop(l); return 0; } + if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1; + if (present_slot(l, idx, r, color) != 0) return -1; + if (color && color->dataspace) banner_color_frame_shown(color, BANNER_HDR_LAYER_COPY, AHB_RGBA8); + if (!l->first_logged) { + l->first_logged = 1; + banner_log("layer", "presenting %dx%d game frames on their own SurfaceControl layer (%s pool, %d buffers); " + "HUD and pointer stay Android views above it", sw, sh, + l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", l->pool_n); + vkp_signal_first_frame(); + } + return 0; +} + +int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int scene_h) { + struct layer *l = layer_of(SC_LAYER_GAME); + int rw = 0, rh = 0, r[8]; + if (!draws || n <= 0 || ensure_sc(l) != 0) return -1; + if (vkp_update_map(scene_w, scene_h) != 0) return -1; + /* Compose + run the effects chain first: the chain's result size (a scaling mode resizes to + * the scene's mapped output size) decides how big the layer buffer has to be. */ + if (vkp_pass_begin(scene_w, scene_h, draws, n, &rw, &rh) != 0) return -1; + if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } + int wait_fd; + int idx = take_free_slot(l, rw, rh, AHB_RGBA8, &wait_fd); + if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; } + if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1; + if (present_slot(l, idx, r, NULL) != 0) return -1; /* the effects chain's result is 8-bit sRGB */ + if (!l->first_logged) { + l->first_logged = 1; + banner_log("layer", "presenting %dx%d frames on their own SurfaceControl layer (%s pool, %d buffers); " + "HUD and pointer stay Android views above it", rw, rh, + l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", l->pool_n); + vkp_signal_first_frame(); + } + return 0; +} + +/* ---- the HDR picture (hdr_compose.h) ------------------------------------------------------------ + * An HDR game that cannot be alone on its layer: the WHOLE scene, composed into one 10-bit PQ BT.2020 + * picture with the effects applied, goes onto the game layer - one layer, tagged BT2020_PQ with the + * game's metadata, so the display composes it as HDR (and a window above the game never needs the + * second layer that costs this panel its hardware composition). 10-bit buffers; if gralloc or the + * import refuses those, 8-bit ones carry the same tagged picture (colours right, precision less). + * With the drawer's HDR output switch off (hf->tonemap) the same picture is composed tone-mapped to + * sRGB instead and goes on the ordinary 8-bit buffers, UNtagged - an SDR frame like any other. */ +static uint32_t g_hdr_pool_fmt = AHB_RGB10A2; + +int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, + int scene_w, int scene_h, const struct banner_color *color) { + struct layer *l = layer_of(SC_LAYER_GAME); + int rw = 0, rh = 0, r[8]; + if (!draws || n <= 0 || !hf || ensure_sc(l) != 0) return -1; + if (vkp_update_map(scene_w, scene_h) != 0) return -1; + if (vkp_pass_begin_hdr(scene_w, scene_h, draws, n, hf, &rw, &rh) != 0) return -1; + if (!vkp_map_rect(rw, rh, scene_w, scene_h, r)) { vkp_pass_abort(); sc_layer_hide(); return 0; } + const int tm = hf->tonemap; + const uint32_t fmt = tm ? AHB_RGBA8 : g_hdr_pool_fmt; + g_alloc_failed = 0; + int wait_fd; + int idx = take_free_slot(l, rw, rh, fmt, &wait_fd); + if (idx < 0 && g_alloc_failed && fmt == AHB_RGB10A2) { + g_hdr_pool_fmt = AHB_RGBA8; + banner_log("color", "%s: this device will not make a 10-bit layer buffer (RGBA1010102): the HDR picture goes " + "on 8-bit buffers instead (still tagged BT2020_PQ; less precision)", l->name); + idx = take_free_slot(l, rw, rh, g_hdr_pool_fmt, &wait_fd); + } + if (idx < 0) { vkp_pass_abort(); log_drop(l); return 0; } + if (vkp_pass_copy_to(l->slots[idx].img, wait_fd) != 0) return -1; + if (present_slot(l, idx, r, tm ? NULL : color) != 0) return -1; /* tone-mapped = plain sRGB: no tag */ + if (color && color->dataspace) + banner_color_frame_shown(color, tm ? BANNER_HDR_TONEMAPPED : BANNER_HDR_COMPOSED, tm ? AHB_RGBA8 : g_hdr_pool_fmt); + static int said = -1; + if (said != tm) { + said = tm; + if (tm) + banner_log("color", "tone-mapped picture on the game's display layer: %dx%d, %s 8-bit buffers, untagged " + "(sRGB) - HDR output is switched off", rw, rh, + l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear"); + else { + char cov[96]; + coverage_text(l, cov, sizeof(cov)); + banner_log("color", "HDR picture on its own display layer: %dx%d, %s %s buffers, tagged %s%s%s", rw, rh, + l->pool_modifier == MOD_QCOM_COMPRESSED ? "UBWC" : "linear", + g_hdr_pool_fmt == AHB_RGB10A2 ? "10-bit" : "8-bit", + color && color->dataspace == BANNER_ADATASPACE_BT2020_PQ ? "BT2020_PQ" : "HDR", + cov[0] ? ", " : "", cov); + } + } + if (!l->first_logged) { l->first_logged = 1; vkp_signal_first_frame(); } + return 0; +} + +/* ---- is a SECOND display layer affordable on this display? ----------------------------------- + * MEASURED on the Pocket FIT (2026-09-14, three times): while a second layer is up, this hardware + * composer hands the WHOLE frame back to the GPU (`DEVICE/CLIENT`), and nothing short of re-creating + * the app's window brings it back — so on this display the overlay layer costs more than it saves, + * every time, for the rest of the session. Where it costs nothing it is still the better path (the + * game keeps copy-free frames with a window on top), so this is a GATE, not a removal. + * + * The gate is read from what the layer path actually knows, never from a device or panel list: + * - rotation: vkp_surface_rotation_degrees(), i.e. VkSurfaceCapabilitiesKHR::currentTransform — + * what the presentation engine says it does to every layer we hand it; + * - scale: the GAME layer's own src -> dst rectangles, the ones passed to setGeometry. + * Rotated AND scaled is the combination that was measured to cost composition (the DPU's rotator + * has to take a scaled source); either alone, or neither, is left as it was. + * + * Why not just measure the composition type after raising the layer and back out if it comes back + * CLIENT — which would beat predicting? Because no app can read it. The composition type lives in + * the Composer HAL; ASurfaceTransactionStats exposes latch time and fences and nothing else, and + * the only place the value is published is `dumpsys android.hardware.graphics.composer3.IComposer`, + * which needs android.permission.DUMP and string-parsing. It would also arrive at least a frame + * late, so backing out would itself be the visible change we are avoiding. Hence the rule. */ +static int overlay_affordable(int *deg, int sw[2], int dw[2]) { + *deg = vkp_surface_rotation_degrees(); + sw[0] = sw[1] = dw[0] = dw[1] = 0; + if (!g_game_geo_known) return 1; /* the game has never been placed: nothing to weigh against */ + if (*deg <= 0) return 1; /* unknown (-1) or upright: leave today's behaviour alone */ + sw[0] = g_game_src.right - g_game_src.left; sw[1] = g_game_src.bottom - g_game_src.top; + dw[0] = g_game_dst.right - g_game_dst.left; dw[1] = g_game_dst.bottom - g_game_dst.top; + if (sw[0] <= 0 || sw[1] <= 0) return 1; + return !(dw[0] != sw[0] || dw[1] != sw[1]); /* rotated AND scaled -> not affordable */ +} + +/* -1 = not decided yet, 0 = raising the overlay, 1 = declining it. Logged on every change, so a + * tester's log says why they are seeing the copy path instead of two layers — and says it again if + * the placement changes the answer (e.g. a fullscreen mode that stops scaling the game). */ +static int g_overlay_declined = -1; + +int sc_layer_overlay_affordable(void) { + layers_init(); + int deg, sr[2], ds[2]; + int ok = overlay_affordable(°, sr, ds); + int want = ok ? 0 : 1; + if (want != g_overlay_declined) { + int first = g_overlay_declined < 0; + g_overlay_declined = want; + if (want) + banner_log("layer", "overlay layer declined: this display rotates every layer %d° and the game " + "layer is scaled %dx%d -> %dx%d, and on that combination a second layer drops the " + "whole frame to GPU composition for the rest of the session (measured). The window " + "above the game goes on the copy path instead - same picture, one blit.", + deg, sr[0], sr[1], ds[0], ds[1]); + else if (!first) + banner_log("layer", "overlay layer allowed again: the game layer is no longer both rotated and " + "scaled, so a second display layer costs nothing here"); + } + return ok; +} + +int sc_layer_present_overlay(struct vkp_image *src, const int geo[8]) { + struct layer *l = layer_of(SC_LAYER_OVERLAY); + if (!src || !geo) return -1; + /* The caller decides with sc_layer_overlay_affordable() BEFORE it commits the game to a layer; + * this is only a guard so the layer can never go up behind that decision's back. */ + if (!sc_layer_overlay_affordable()) return -1; + if (ensure_sc(l) != 0) return -1; + int sw = vkp_image_width(src), sh = vkp_image_height(src); + if (sw <= 0 || sh <= 0) return -1; + int wait_fd; + int idx = take_free_slot(l, sw, sh, AHB_RGBA8, &wait_fd); + if (idx < 0) { log_drop(l); return 0; } + /* The window is copied into the layer buffer 1:1; `geo` crops it and places it, so the layer + * is exactly the window's rectangle on screen and nothing else is blended anywhere. */ + if (vkp_blit_image(src, l->slots[idx].img, wait_fd) != 0) return -1; + if (present_slot(l, idx, geo, NULL) != 0) return -1; + if (!l->first_logged) { + l->first_logged = 1; + log_layer_count(); + } + return 0; +} + +/* Hide one layer: the buffer comes off with it (a hidden layer would keep the game's buffer - or + * the pool slot - referenced, and the game needs it back to keep presenting the other way). */ +static void hide_layer(struct layer *l) { + if (!l->sc || !l->shown || api.state != 1) return; + ASurfaceTransaction *tx = api.txCreate(); + if (!tx) return; + replace_with_blank(tx, l); + api.setVisibility(tx, l->sc, ASC_VISIBILITY_HIDE); + add_complete(tx, l, l->cur_slot, l->cur_token, 0); + api.txApply(tx); api.txDelete(tx); + l->shown = 0; l->cur_slot = -1; l->cur_token = NULL; +} + +void sc_layer_hide(void) { + layers_init(); + int said = g_layers[SC_LAYER_GAME].shown || g_layers[SC_LAYER_OVERLAY].sc; + /* Top down, so nothing of the scene is ever uncovered for a frame. The overlay layer is let go + * of entirely rather than hidden (same reason as sc_layer_hide_overlay: a live second + * SurfaceControl keeps SurfaceFlinger composing on the GPU); the game layer keeps its + * SurfaceControl, since it goes up and down with every effects/frame-generation toggle. */ + if (g_layers[SC_LAYER_OVERLAY].sc) sc_layer_hide_overlay(); + if (g_layers[SC_LAYER_GAME].shown) hide_layer(&g_layers[SC_LAYER_GAME]); + if (said) banner_log("layer", "layers hidden (scene is not a single fullscreen window)"); +} + +void sc_layer_hide_overlay(void) { + layers_init(); + struct layer *l = &g_layers[SC_LAYER_OVERLAY]; + if (!l->sc) return; + /* RETIRED, not just hidden, so the overlay layer lives exactly as long as the window above the + * game: a live second SurfaceControl is what puts SurfaceFlinger into GPU client composition + * on this hardware (see sc_layer.h), and a hidden one is still live. Measured caveat: letting + * it go does NOT by itself bring hardware composition back - on the Pocket FIT the fallback + * outlives the overlay and only clears when the GAME layer's SurfaceControl is re-created + * (HOME + resume). Retiring is still the right thing; it just is not the whole cure. The pool + * buffers stay allocated for the next window. */ + if (l->shown) hide_layer(l); + retire_sc(l); + banner_log("layer", "%s: gone (nothing is above the game any more)", l->name); + /* ...and that is the half the measurement said is not enough: arm the game layer's + * SurfaceControl swap, which the next frame performs (swap_sc_begin). */ + if (g_layers[SC_LAYER_GAME].sc) g_layers[SC_LAYER_GAME].recreate_pending = 1; +} + +void sc_layer_window_gone(void) { + if (api.state != 1) return; + layers_init(); + for (int i = SC_LAYER_COUNT - 1; i >= 0; i--) retire_sc(&g_layers[i]); + drain_and_free_pools(); +} + +unsigned sc_layer_frames_take(void) { + unsigned n = g_stat_layer_frames; + g_stat_layer_frames = 0; + return n; +} diff --git a/app/src/main/cpp/waylandcomp/src/sc_layer.h b/app/src/main/cpp/waylandcomp/src/sc_layer.h new file mode 100644 index 0000000000..7fe64bd249 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/sc_layer.h @@ -0,0 +1,174 @@ +#ifndef SC_LAYER_H +#define SC_LAYER_H +/* + * Layer mode (BANNER_WAYLAND_ZERO_COPY=1): the scene is handed to SurfaceFlinger as a small, + * deliberately ordered SET of Android display layers — ASurfaceControl children of the + * compositor's SurfaceView — instead of being blitted into the compositor's own swapchain. + * + * app window ......... Compose UI, the in-game drawer, the HUD, the on-screen controls and + * the pointer arrow: ordinary Android views, ALWAYS above everything + * below (the SurfaceView is not Z-on-top, so its whole subtree is under + * the window's own content). None of the layers below take input: + * an ASurfaceControl has no input channel, so touch and mouse keep + * reaching the SurfaceView exactly as they did. + * +-- SurfaceView ..... the compositor's Vulkan swapchain; black while layer mode is up + * +-- z=1 "banner_wayland_game" ...... the one fullscreen game window + * +-- z=2 "banner_wayland_overlay" ... at most one window drawn ABOVE the game + * + * TWO layers is the hard cap (SC_LAYER_COUNT), and deliberately so: HWC composes only a few + * layers before SurfaceFlinger falls back to GPU client composition, which would throw away the + * whole benefit. The count is logged when the second layer first goes up. + * + * MEASURED on the Pocket FIT (Adreno 750, portrait panel + landscape session, so every layer is + * ROT_90 + scaled), `dumpsys android.hardware.graphics.composer3.IComposer/default`: one layer is + * `composition: DEVICE/DEVICE`, effects on the layer keep it DEVICE/DEVICE — but a SECOND layer + * flips the whole frame to `DEVICE/CLIENT`. It does not come back when the overlay goes away. + * The overlay layer is retired rather than hidden for that reason, but the fallback outlives it. + * The likely mechanism is the DPU's rotator budget (one rotated+scaled layer), not the layer count + * as such, so a device or orientation needing no rotation may well take both on the DPU. Even in + * client composition the overlay layer is not a loss — SurfaceFlinger does the one blit the + * compositor would have done — but the hardware-composition win is only real for one layer. + * + * COMPOSITION RECOVERY (sc_layer.c, swap_sc_begin): retiring the overlay arms the game layer, and + * the NEXT frame is presented on a brand-new SurfaceControl while the old one is hidden and + * unparented in the SAME transaction. SurfaceFlinger applies a transaction atomically, so no + * composited frame is ever missing the game — no black frame, no dropped frame beyond the layer + * creation itself. One `layer` line is written when it happens. + * + * ⚠️ It does NOT restore hardware composition on this panel, and that was measured, not assumed + * (2026-09-14, Wizardry on the game layer + Wine's Task Manager on the overlay, reproduced twice): + * - two layers -> DEVICE/CLIENT + * - overlay retired + fresh game SurfaceControl -> still DEVICE/CLIENT, 24 s later too + * - layer path dropped entirely and re-created -> still DEVICE/CLIENT + * - drawer opened and closed, no second window -> DEVICE/DEVICE (control: the drawer is not the cause) + * - HOME + resume -> DEVICE/DEVICE + * HOME + resume re-creates the app's whole window and SurfaceView (`VRI[XServerDisplayActivity]#0` + * becomes `#4`), not just this child layer — so the sticky state belongs to the parent surface or + * the display. Re-creating the parent would cost a real black frame and a swapchain rebuild, which + * is worse than the few percent of GPU that client composition costs. The cure that actually keeps + * the win is PREVENTION, and it IS implemented: sc_layer_overlay_affordable() declines the second + * layer when the game layer is both rotated and scaled, and the window above the game goes down the + * copy path instead (what the pre-phase-4 code did) — one blit SurfaceFlinger would have done + * anyway, and the session keeps DEVICE composition throughout. Where a second layer costs nothing, + * nothing changes. + * + * What can be on the game layer, cheapest first: + * - the game's own gralloc buffer (ahb_swapchain.c, true zero-copy: no copy anywhere); + * - one blit of the game's frame into a compositor-allocated AHardwareBuffer (sc_layer_present); + * - with screen effects on, the compositor pass's result blitted into such a buffer + * (sc_layer_present_pass) — the game STAYS on its layer while a Look is applied, and the + * scene -> output mapping is done by the display (setGeometry) instead of a second GPU blit. + * The compositor never alpha-blends (it composes with blits, which overwrite), so every layer is + * marked OPAQUE and the overlay layer is cropped to the window it carries: the picture is the + * same as the copy path's, pixel for pixel. + * + * Compositor thread only, except the SurfaceFlinger OnComplete callbacks (binder threads), which + * only touch the pools under g_lock. sc_layer_hide*() is safe at any time. + */ +#include <stddef.h> +#include <stdint.h> +#include <android/hardware_buffer.h> + +struct vkp_image; +struct vkp_draw; +struct banner_color; + +/* The layers, bottom first. The z-order is the array order (z = id + 1). */ +enum sc_layer_id { SC_LAYER_GAME = 0, SC_LAYER_OVERLAY = 1, SC_LAYER_COUNT = 2 }; + +/* 1 when this device has the SurfaceControl API the layers need (Android 10+, libnativewindow's + * getNativeHandle); the reason is logged (tag `layer`) the first time it is missing. */ +int sc_layer_available(void); + +/* One-shot: does the kernel export a sync_file from the game's dma-buf (DMA_BUF_IOCTL_EXPORT_SYNC_FILE)? + * Decides where a zero-copy acquire fence can come from; result goes to the session log. */ +void sc_layer_probe_dmabuf_fd(int fd); + +/* HDR (banner_color.h): can a display layer be told its buffer's colour encoding here + * (ASurfaceTransaction_setBufferDataSpace, Android 10+)? Part of the HDR gate. */ +int sc_layer_can_tag_hdr(void); +/* Which of the colour calls this libandroid has, for the gate's log line. */ +void sc_layer_hdr_symbols(char *out, size_t size); + +/* COLOUR on the game layer: `color` is the image description of the frame being presented (NULL = + * none, i.e. sRGB). A layer that was never tagged is never touched (no setBufferDataSpace call at all: + * a session without an HDR description behaves exactly as before); once tagged, a later untagged frame + * puts the layer back to UNKNOWN. SMPTE 2086 / CTA-861.3 metadata travel with the dataspace. */ + +/* GAME layer: show `src` (the fullscreen window's imported frame, scene-sized) on it, placed + * through the current fullscreen mode / alignment mapping. 0 = shown (or deliberately dropped: no + * free buffer), -1 = the layer path is unavailable this frame and the caller must draw the old way. + * The copy into the layer buffer is 8-bit: an HDR frame keeps its tag (its colours stay right), and + * loses precision. */ +int sc_layer_present(struct vkp_image *src, int scene_w, int scene_h, const struct banner_color *color); + +/* GAME layer, screen effects on: run the compositor pass (composite `draws` + the effects chain, + * vkp_pass_begin) and put its result on the layer. Same return values as sc_layer_present. */ +int sc_layer_present_pass(const struct vkp_draw *draws, int n, int scene_w, int scene_h); + +/* GAME layer, HDR (hdr_compose.h): the whole scene - `draws`, hf->is_hdr marking the HDR ones - composed + * into one 10-bit PQ BT.2020 picture with the effects applied (vkp_pass_begin_hdr), copied into a + * 10-bit layer buffer (8-bit where gralloc refuses those) and shown tagged with `color` (the topmost HDR + * draw's description). The overlay layer is not used: the picture already holds what is above the game. + * Same return values as sc_layer_present. */ +struct vkp_hdr_frame; +int sc_layer_present_hdr_scene(const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, + int scene_w, int scene_h, const struct banner_color *color); + +/* GAME layer, zero-copy (ahb_swapchain.c): show the game's own w x h AHardwareBuffer, gated by + * acquire_fd (a sync_file the layer waits on before reading; owned by the callee, -1 = none). + * token identifies the buffer: once a later transaction replaces it (or the layer is hidden or + * retired), ahb_swapchain_layer_released(token, release_fd) reports SurfaceFlinger's release fence + * for it. Presenting the token already on the layer only updates the placement. 0 = on the layer, + * 1 = nothing of it is on screen (layer hidden, the buffer was not taken), -1 = unavailable this + * frame (the caller draws the old way). `color` / `ahb_format`: the frame's image description (NULL = + * none) and the buffer's AHARDWAREBUFFER_FORMAT_*, for the dataspace and the HDR evidence. */ +int sc_layer_present_ahb(AHardwareBuffer *ahb, int w, int h, int acquire_fd, void *token, + int scene_w, int scene_h, const struct banner_color *color, uint32_t ahb_format); + +/* Vote a panel refresh rate for the layer the game presents on (VRR / refresh-rate matching), the + * same rate and compatibility the app votes on its own surface with Surface.setFrameRate; 0 = no + * vote. Needed because a zero-copy game's frames go onto the GAME layer and never reach the app's + * surface, so the surface vote alone does not describe the game's cadence to SurfaceFlinger. Only + * the game layer ever carries it: the overlay layer is explicitly voted 0, so a window that redraws + * once a second can never hold (or drop) the panel at the game's cadence. Callable from any thread + * at any time (it only stores the rate); the compositor applies it with the layer's next + * transaction, and re-applies it whenever a SurfaceControl is re-created. A no-op on devices whose + * libandroid has no ASurfaceTransaction_setFrameRate. */ +void sc_layer_set_frame_rate(float fps); + +/* Is a SECOND display layer worth raising on THIS display? Ask before committing the game to its + * layer, not after: on a display where the answer is no, the whole scene must go down the copy path + * from the start, or the game layer would be shown and hidden again on every frame. + * + * The answer is computed from what the layer path knows — the rotation the presentation engine + * applies to everything we hand it (VkSurfaceCapabilitiesKHR::currentTransform) and the game + * layer's own src -> dst rectangles — and never from a device or panel allowlist. ROTATED AND + * SCALED is the combination measured to cost hardware composition (below); either alone is fine. + * The reason is written to the session log once, and again if the answer changes. */ +int sc_layer_overlay_affordable(void); + +/* OVERLAY layer: show `src` (one window's imported frame) above the game layer, at the placement + * `geo` = {src x0,y0,x1,y1 in image pixels, dst x0,y0,x1,y1 in output pixels} from vkp_map_draw. + * 0 = shown or dropped, -1 = unavailable (the caller must fall back to the copy path). */ +int sc_layer_present_overlay(struct vkp_image *src, const int geo[8]); + +/* The scene is not a single fullscreen window this frame: hide every layer that is up. */ +void sc_layer_hide(void); +/* Only the overlay layer: nothing is above the game any more. The game keeps its layer, but its + * SurfaceControl is swapped for a fresh one on the next frame (composition recovery, above — which + * on this panel does not in fact win hardware composition back; see the measurement there). */ +void sc_layer_hide_overlay(void); + +/* The output window changed or went away (compositor thread, from vkp_apply_window_request). */ +void sc_layer_window_gone(void); + +/* Frames the compositor put on a layer through one of its own buffers (a blit or the effects + * pass) since the last call — the zero-copy frames ahb_swapchain.c counts are NOT included. + * For the 10 s summary. */ +unsigned sc_layer_frames_take(void); +/* Frames dropped since the last call because every layer buffer was still held by the display (the + * 10 s perf line; the "no free layer buffer" log line itself is rate-limited). */ +unsigned sc_layer_drops_take(void); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/vk_import.c b/app/src/main/cpp/waylandcomp/src/vk_import.c new file mode 100644 index 0000000000..08c1351a36 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_import.c @@ -0,0 +1,167 @@ +/* Compositor-side dmabuf import into Turnip (see vk_import.h). */ +#define _POSIX_C_SOURCE 200809L +#include "vk_import.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <vulkan/vulkan.h> + +#define MOD_INVALID 0x00ffffffffffffffULL + +static int g_ready = -1; /* -1 = untried, 0 = ok, 1 = init failed */ +static VkInstance g_inst; +static VkPhysicalDevice g_pd; +static VkDevice g_dev; +static PFN_vkGetMemoryFdPropertiesKHR p_getMemFdProps; + +static int has_ext(VkExtensionProperties *e, uint32_t n, const char *name) { + for (uint32_t i = 0; i < n; i++) + if (!strcmp(e[i].extensionName, name)) return 1; + return 0; +} + +static int vk_init(void) { + if (g_ready >= 0) return g_ready == 0 ? 0 : -1; + + VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, + .pApplicationName = "spike-compositor-import", + .apiVersion = VK_API_VERSION_1_1}; + VkInstanceCreateInfo ici = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + .pApplicationInfo = &app}; + if (vkCreateInstance(&ici, NULL, &g_inst) != VK_SUCCESS) { + fprintf(stderr, "[imp] vkCreateInstance failed\n"); + g_ready = 1; return -1; + } + uint32_t npd = 0; + vkEnumeratePhysicalDevices(g_inst, &npd, NULL); + if (!npd) { g_ready = 1; return -1; } + VkPhysicalDevice pds[8]; + if (npd > 8) npd = 8; + vkEnumeratePhysicalDevices(g_inst, &npd, pds); + g_pd = pds[0]; /* Turnip is forced via VK_ICD_FILENAMES */ + + const char *want[] = {"VK_KHR_external_memory_fd", + "VK_EXT_external_memory_dma_buf", + "VK_EXT_image_drm_format_modifier", + "VK_KHR_image_format_list"}; + uint32_t ne = 0; + vkEnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL); + VkExtensionProperties *exts = calloc(ne, sizeof(*exts)); + vkEnumerateDeviceExtensionProperties(g_pd, NULL, &ne, exts); + for (unsigned i = 0; i < 4; i++) + if (!has_ext(exts, ne, want[i])) + fprintf(stderr, "[imp] WARNING device missing %s\n", want[i]); + free(exts); + + float prio = 1.0f; + VkDeviceQueueCreateInfo qci = {.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, + .queueFamilyIndex = 0, .queueCount = 1, + .pQueuePriorities = &prio}; + VkDeviceCreateInfo dci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, + .queueCreateInfoCount = 1, .pQueueCreateInfos = &qci, + .enabledExtensionCount = 4, .ppEnabledExtensionNames = want}; + if (vkCreateDevice(g_pd, &dci, NULL, &g_dev) != VK_SUCCESS) { + fprintf(stderr, "[imp] vkCreateDevice failed\n"); + g_ready = 1; return -1; + } + p_getMemFdProps = (PFN_vkGetMemoryFdPropertiesKHR)vkGetDeviceProcAddr( + g_dev, "vkGetMemoryFdPropertiesKHR"); + g_ready = 0; + fprintf(stderr, "[imp] Vulkan import device ready (Turnip)\n"); + return 0; +} + +static VkFormat drm_to_vk(uint32_t drm) { + /* XR24/AR24 (XRGB/ARGB8888, little-endian bytes B,G,R,X) -> BGRA8. */ + return VK_FORMAT_B8G8R8A8_UNORM; +} + +int vk_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h, + uint32_t stride, uint32_t offset) { + if (modifier == MOD_INVALID) { + fprintf(stderr, "[imp] skip: INVALID modifier (needs implicit path)\n"); + return -1; + } + if (vk_init() != 0) return -1; + + VkSubresourceLayout plane = {.offset = offset, .rowPitch = stride}; + VkImageDrmFormatModifierExplicitCreateInfoEXT modInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT, + .drmFormatModifier = modifier, + .drmFormatModifierPlaneCount = 1, + .pPlaneLayouts = &plane}; + VkExternalMemoryImageCreateInfo extImg = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, + .pNext = &modInfo, + .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT}; + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + .pNext = &extImg, + .imageType = VK_IMAGE_TYPE_2D, + .format = drm_to_vk(drm_format), + .extent = {w, h, 1}, + .mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT, + .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + VkImage image; + VkResult r = vkCreateImage(g_dev, &ici, NULL, &image); + if (r != VK_SUCCESS) { + fprintf(stderr, "[imp] vkCreateImage(drm_modifier) -> %d\n", r); + return -1; + } + + int dupfd = dup(fd); + uint32_t allowed_types = 0xffffffff; + if (p_getMemFdProps) { + VkMemoryFdPropertiesKHR fp = {.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR}; + if (p_getMemFdProps(g_dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + dupfd, &fp) == VK_SUCCESS) + allowed_types = fp.memoryTypeBits; + } + VkMemoryRequirements req; + vkGetImageMemoryRequirements(g_dev, image, &req); + uint32_t bits = req.memoryTypeBits & allowed_types; + int type_idx = -1; + for (int i = 0; i < 32; i++) + if (bits & (1u << i)) { type_idx = i; break; } + if (type_idx < 0) { + fprintf(stderr, "[imp] no compatible memory type\n"); + vkDestroyImage(g_dev, image, NULL); close(dupfd); return -1; + } + + VkImportMemoryFdInfoKHR imp = { + .sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + .fd = dupfd}; + VkMemoryDedicatedAllocateInfo ded = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, + .pNext = &imp, .image = image}; + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .pNext = &ded, + .allocationSize = req.size, + .memoryTypeIndex = (uint32_t)type_idx}; + VkDeviceMemory mem; + r = vkAllocateMemory(g_dev, &mai, NULL, &mem); + if (r != VK_SUCCESS) { + fprintf(stderr, "[imp] vkAllocateMemory(import fd) -> %d\n", r); + vkDestroyImage(g_dev, image, NULL); close(dupfd); return -1; + } + r = vkBindImageMemory(g_dev, image, mem, 0); + if (r != VK_SUCCESS) { + fprintf(stderr, "[imp] vkBindImageMemory -> %d\n", r); + vkFreeMemory(g_dev, mem, NULL); vkDestroyImage(g_dev, image, NULL); + return -1; + } + + fprintf(stderr, + "[imp] *** IMPORTED dmabuf -> VkImage OK (memType %d, size %llu) " + "==> compositor can turn game frames into VkImages\n", + type_idx, (unsigned long long)req.size); + /* import took ownership of dupfd; free our objects */ + vkFreeMemory(g_dev, mem, NULL); + vkDestroyImage(g_dev, image, NULL); + return 0; +} diff --git a/app/src/main/cpp/waylandcomp/src/vk_import.h b/app/src/main/cpp/waylandcomp/src/vk_import.h new file mode 100644 index 0000000000..b333e6db9c --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_import.h @@ -0,0 +1,13 @@ +#ifndef VK_IMPORT_H +#define VK_IMPORT_H +#include <stdint.h> +/* + * Import a received dmabuf into the compositor's own Vulkan (Turnip) device as a + * VkImage and bind its memory. This is the M4-import de-risk: if we can import + + * bind, sampling/blitting it to screen is standard Vulkan. Non-fatal: returns 0 + * on success, negative on failure, and logs details. Does NOT consume `fd` + * (dups internally). + */ +int vk_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, + int w, int h, uint32_t stride, uint32_t offset); +#endif diff --git a/app/src/main/cpp/waylandcomp/src/vk_loader.c b/app/src/main/cpp/waylandcomp/src/vk_loader.c new file mode 100644 index 0000000000..3038d79ae2 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_loader.c @@ -0,0 +1,61 @@ +/* See vk_loader.h. */ +#define _GNU_SOURCE +#include "vk_loader.h" +#include "../../adrenotools/include/adrenotools/driver.h" +#include <dlfcn.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <android/log.h> + +#define TAG "BannerWayland" + +struct vk_api g_vk; +static void *g_handle; +static PFN_vkGetInstanceProcAddr g_gip; + +int vk_loader_open(const char *driver_path, const char *library_name, + const char *native_lib_dir) { + if (driver_path && library_name && native_lib_dir) { + char *tmpdir = NULL; + if (asprintf(&tmpdir, "%stemp", driver_path) < 0) tmpdir = NULL; + if (tmpdir) mkdir(tmpdir, S_IRWXU | S_IRWXG); + g_handle = adrenotools_open_libvulkan( + RTLD_LOCAL | RTLD_NOW, ADRENOTOOLS_DRIVER_CUSTOM, tmpdir, + native_lib_dir, driver_path, library_name, NULL, NULL); + free(tmpdir); + __android_log_print(g_handle ? ANDROID_LOG_INFO : ANDROID_LOG_ERROR, TAG, + "adrenotools Turnip handle=%p (%s / %s)", g_handle, + driver_path, library_name); + } + if (!g_handle) { + g_handle = dlopen("libvulkan.so", RTLD_LOCAL | RTLD_NOW); + __android_log_print(ANDROID_LOG_WARN, TAG, + "no adrenotools driver -> system libvulkan handle=%p " + "(dmabuf import likely unsupported)", g_handle); + } + if (!g_handle) return -1; + g_gip = (PFN_vkGetInstanceProcAddr)dlsym(g_handle, "vkGetInstanceProcAddr"); + if (!g_gip) { + __android_log_print(ANDROID_LOG_ERROR, TAG, "no vkGetInstanceProcAddr"); + return -1; + } +#define X(n) g_vk.n = (PFN_vk##n)g_gip(NULL, "vk" #n); + VK_GLOBAL_FUNCS(X) +#undef X + return g_vk.CreateInstance ? 0 : -1; +} + +PFN_vkGetInstanceProcAddr vk_loader_gipa(void) { return g_gip; } + +void vk_loader_load_instance(VkInstance instance) { +#define X(n) g_vk.n = (PFN_vk##n)g_gip(instance, "vk" #n); + VK_INSTANCE_FUNCS(X) +#undef X +} + +void vk_loader_load_device(VkDevice device) { +#define X(n) g_vk.n = (PFN_vk##n)g_vk.GetDeviceProcAddr(device, "vk" #n); + VK_DEVICE_FUNCS(X) +#undef X +} diff --git a/app/src/main/cpp/waylandcomp/src/vk_loader.h b/app/src/main/cpp/waylandcomp/src/vk_loader.h new file mode 100644 index 0000000000..c7609d67a6 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_loader.h @@ -0,0 +1,60 @@ +#ifndef VK_LOADER_H +#define VK_LOADER_H +/* + * Loads Turnip via adrenotools (the same path the app uses for the guest renderer) + * and resolves every Vulkan entry point through its vkGetInstanceProcAddr — NOT the + * process-default system Adreno driver, which lacks VK_EXT_image_drm_format_modifier / + * dmabuf import. All compositor Vulkan calls go through g_vk.* . + */ +#define VK_USE_PLATFORM_ANDROID_KHR +#include <vulkan/vulkan.h> + +#define VK_GLOBAL_FUNCS(X) X(CreateInstance) X(EnumerateInstanceExtensionProperties) + +#define VK_INSTANCE_FUNCS(X) \ + X(EnumeratePhysicalDevices) X(GetPhysicalDeviceProperties) \ + X(GetPhysicalDeviceQueueFamilyProperties) X(GetPhysicalDeviceSurfaceSupportKHR) \ + X(GetPhysicalDeviceSurfaceCapabilitiesKHR) X(GetPhysicalDeviceSurfaceFormatsKHR) \ + X(CreateAndroidSurfaceKHR) X(DestroySurfaceKHR) X(CreateDevice) \ + X(GetDeviceProcAddr) X(EnumerateDeviceExtensionProperties) \ + X(GetPhysicalDeviceMemoryProperties) X(GetPhysicalDeviceFormatProperties2) \ + X(GetPhysicalDeviceImageFormatProperties2) + +#define VK_DEVICE_FUNCS(X) \ + X(GetDeviceQueue) X(CreateSwapchainKHR) X(DestroySwapchainKHR) X(GetSwapchainImagesKHR) \ + X(CreateCommandPool) X(AllocateCommandBuffers) X(CreateSemaphore) X(CreateFence) \ + X(DeviceWaitIdle) X(CreateImage) X(GetImageMemoryRequirements) X(AllocateMemory) \ + X(BindImageMemory) X(DestroyImage) X(FreeMemory) X(AcquireNextImageKHR) \ + X(ResetCommandBuffer) X(BeginCommandBuffer) X(CmdPipelineBarrier) X(CmdBlitImage) \ + X(EndCommandBuffer) X(ResetFences) X(QueueSubmit) X(QueuePresentKHR) X(WaitForFences) \ + X(QueueWaitIdle) X(GetMemoryFdPropertiesKHR) \ + X(GetImageSubresourceLayout) X(MapMemory) X(UnmapMemory) X(CmdClearColorImage) \ + /* screen-effect chain (effects_chain.c): graphics pipelines over full-screen quads */ \ + X(CreateShaderModule) X(DestroyShaderModule) X(CreatePipelineLayout) X(DestroyPipelineLayout) \ + X(CreateGraphicsPipelines) X(DestroyPipeline) X(CreateRenderPass) X(DestroyRenderPass) \ + X(CreateFramebuffer) X(DestroyFramebuffer) X(CreateImageView) X(DestroyImageView) \ + X(CreateSampler) X(DestroySampler) X(CreateDescriptorSetLayout) X(DestroyDescriptorSetLayout) \ + X(CreateDescriptorPool) X(DestroyDescriptorPool) X(AllocateDescriptorSets) X(FreeDescriptorSets) \ + X(UpdateDescriptorSets) X(CmdBeginRenderPass) X(CmdEndRenderPass) X(CmdBindPipeline) \ + X(CmdBindDescriptorSets) X(CmdPushConstants) X(CmdDraw) X(CmdSetViewport) X(CmdSetScissor) \ + /* frame generation (framegen_bridge.c / vk_present.c per-present sync slots) */ \ + X(DestroySemaphore) + +struct vk_api { +#define X(n) PFN_vk##n n; + VK_GLOBAL_FUNCS(X) VK_INSTANCE_FUNCS(X) VK_DEVICE_FUNCS(X) +#undef X +}; +extern struct vk_api g_vk; + +/* Open Turnip via adrenotools (falls back to system libvulkan if any arg is NULL) + * and load global entry points. Returns 0 on success. */ +int vk_loader_open(const char *driver_path, const char *library_name, + const char *native_lib_dir); +void vk_loader_load_instance(VkInstance instance); +void vk_loader_load_device(VkDevice device); +/* The driver's vkGetInstanceProcAddr (NULL before vk_loader_open): for modules that resolve their + * own entry points, e.g. the frame-generation engines (framegen_engine.cpp). */ +PFN_vkGetInstanceProcAddr vk_loader_gipa(void); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c new file mode 100644 index 0000000000..c760081162 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -0,0 +1,2108 @@ +/* Android-surface render backend — see vk_present.h. Uses Turnip via vk_loader + * (g_vk.*), not the process-default system Adreno driver. */ +#define _POSIX_C_SOURCE 200809L +#include "vk_present.h" +#include "vk_loader.h" +#include "sc_layer.h" +#include "effects_chain.h" +#include "framegen_bridge.h" +#include "hdr_compose.h" +#include "banner_color.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <poll.h> +#include <time.h> +#include <pthread.h> +#include <android/log.h> + +#define TAG "BannerWayland" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__) +#define LOGE(...) banner_log("error", __VA_ARGS__) +#define MOD_INVALID VKP_MOD_INVALID + +struct vkp_image { + VkImage image; + VkDeviceMemory mem; + int w, h; + int dmabuf; /* imported from a client; owned by the foreign queue family */ + int blit_dst; /* layer mode: a pool buffer this backend blits into (never a source) */ + void *map; /* shm images: persistently mapped linear memory */ + VkDeviceSize offset, row_pitch; + int in_general; /* shm images: moved from PREINITIALIZED to GENERAL */ +}; + +static ANativeWindow *g_window; /* the window frames go to; compositor thread only */ +static char *g_driver_path, *g_library_name, *g_native_lib_dir; +static int g_dev_state; /* 0 = not yet, 1 = ok, -1 = failed, -2 = lost (VK_ERROR_DEVICE_LOST) */ +static VkInstance g_inst; +static VkPhysicalDevice g_pd; +static VkDevice g_dev; +static VkQueue g_queue; +static uint32_t g_qfam; +static VkCommandPool g_pool; +/* One command buffer + acquire/render-done semaphore pair per PRESENT. A scene frame is one + * present, or up to 1 + VKP_FG_MAX_GENERATIONS with frame generation (the generated frames go + * out first, the real frame last), each on its own slot so no semaphore ever carries two + * pending signals. Slot 0 is also the layer-mode blit's command buffer. */ +#define MAX_PRESENTS (1 + VKP_FG_MAX_GENERATIONS) +static VkCommandBuffer g_cmds[MAX_PRESENTS]; +static VkSemaphore g_acqs[MAX_PRESENTS], g_rnds[MAX_PRESENTS]; +static VkFence g_fence; +/* Extra swapchain images this swapchain was built with (frame generation: one per generated + * frame, so all presents of a scene frame queue without waiting for a vblank). */ +static int g_swap_extra; +/* Format of the compositor pass's images (the scene image below, the effects chain's targets and + * the frame-generation ring): a blit converts every client format into it, the chains read RGBA. */ +#define SCENE_FMT VK_FORMAT_R8G8B8A8_UNORM +static VkPhysicalDeviceMemoryProperties g_memprops; + +static VkSurfaceKHR g_surface; +static VkSwapchainKHR g_swapchain; +/* The display's own rotation of everything we present (VkSurfaceCapabilitiesKHR::currentTransform), + * captured when the swapchain is built. Not a panel or device allowlist: it is what the presentation + * engine says it will do to our layers. */ +static VkSurfaceTransformFlagBitsKHR g_surface_transform; +static int g_surface_transform_known; +static VkImage *g_images; +static uint32_t g_nimg; +static VkExtent2D g_extent; + +static int g_first_frame_done; /* one-shot: fire banner_on_first_frame() on first present */ + +/* The base surface under the display layers (vkp_base_black): 1 once a plain black frame has been + * presented on the CURRENT swapchain and nothing else since. Every other present clears it, and so does + * every swapchain teardown, so the next layer frame puts one black frame back first. While it is set, + * a frame that lives entirely on the display layers draws and presents nothing here. */ +static int g_base_black; +/* The layer path presents nothing on the base surface while the game keeps its layer, so the swapchain's + * OUT_OF_DATE (a resized surface, a new transform) would never be seen there: check_surface_changed() + * asks the surface directly instead, at most every 100 ms. caps.currentExtent at the last build. */ +static VkExtent2D g_caps_extent; +static int64_t g_surface_checked_ns; + +/* Letterbox bars: vkCmdClearColorImage clears whole images only, so the bars around the picture are + * blitted from this small black image instead of clearing the whole output under a picture that covers + * most of it. Created and cleared once with the device. 1 = ready, 0/-1 = not available (whole clear). */ +#define BLACK_DIM 16 +static VkImage g_black_img; +static VkDeviceMemory g_black_mem; +static int g_black_state; + +/* The display's release fence of a layer buffer, as a GPU wait (VK_KHR_external_semaphore_fd): the + * pool's next copy into that buffer waits for it on the GPU instead of the compositor thread polling it. */ +static PFN_vkImportSemaphoreFdKHR g_import_sem_fd; +static VkSemaphore g_wait_sem; + +/* The 10 s perf line's counters (vkp_perf_take). Compositor thread only. */ +static struct vkp_perf g_perf; +static int64_t perf_now(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} +static void perf_add(int64_t *sum, int64_t *max, unsigned *count, int64_t d) { + if (d < 0) d = 0; + *sum += d; + if (d > *max) *max = d; + (*count)++; +} +/* vkWaitForFences on the compositor's own work, timed for the perf line. */ +static VkResult timed_wait(VkFence fence, uint64_t timeout) { + int64_t t0 = perf_now(); + VkResult r = g_vk.WaitForFences(g_dev, 1, &fence, VK_TRUE, timeout); + perf_add(&g_perf.wait_ns, &g_perf.wait_max_ns, &g_perf.waits, perf_now() - t0); + return r; +} + +/* The scene image (effects path only): every draw composited 1:1 at scene size, the input of the + * screen-effect chain (effects_chain.c) — and of frame generation once that lands. Recreated on a + * scene size change; frames are fenced, so never while the GPU reads it. */ +static struct { VkImage img; VkDeviceMemory mem; int w, h; } g_scene; + +/* HDR composition (hdr_compose.h): the 10-bit image every draw is blitted into 1:1 in its own encoding + * ("mixed"), and the 10-bit HDR picture the encode pass makes of it for the game's display layer. Only + * ever created while an HDR game shares the scene with something the display layer cannot show alone. */ +struct vkp_img_slot { VkImage img; VkDeviceMemory mem; int w, h; VkFormat fmt; }; +static struct vkp_img_slot g_mixed, g_hdrscene, g_fgscene; +#define HDR_FMT VK_FORMAT_A2B10G10R10_UNORM_PACK32 +/* Frame generation with HDR frames through an HDR10 swapchain: the scene, the effects and the engine's + * frames in FP16 - the format lsfg-vk itself uses for HDR - where the engine can build its chain in it, + * so the PQ picture keeps more than 8 bits through interpolation (framegen_bridge.h). */ +#define FG_HDR_FMT VK_FORMAT_R16G16B16A16_SFLOAT + +/* HDR10 swapchain (frame generation with an HDR game): VK_EXT_swapchain_colorspace is enabled on the + * instance only when the session asked for HDR; the swapchain is built as A2B10G10R10 + HDR10_ST2084 + * while such frames are being presented and the Android surface lists that pair (its WSI then sets the + * surface dataspace to BT2020_PQ). */ +static int g_colorspace_ext; /* the instance has VK_EXT_swapchain_colorspace */ +static int g_swap_hdr_want; /* the next swapchain should be HDR10 */ +static int g_swap_is_hdr; /* the live swapchain is HDR10 */ +static int g_swap_hdr_unavailable; /* this surface lists no HDR10 format: tone-map instead (said once) */ +static VkFormat g_swap_fmt; /* the live swapchain's format */ +/* VK_EXT_hdr_metadata (HDR sessions, where the device offers it): the HDR10 swapchain carries the game's + * mastering metadata, sent once per swapchain and image description. */ +static PFN_vkSetHdrMetadataEXT g_set_hdr_metadata; +static uint32_t g_swap_md_identity; +static int g_surface_formats_said; +static const char *vk_result_name(VkResult r); + +/* The Android surface is created/destroyed on the app's UI thread while the compositor thread + * may be inside a WSI call (acquire and present can block for a refresh or more). The UI thread + * therefore never touches the swapchain: it leaves the new window here and returns at once; the + * compositor thread picks it up before its next frame (vkp_apply_window_request). g_req_lock is + * only ever held for these few assignments, never across a Vulkan call. */ +static pthread_mutex_t g_req_lock = PTHREAD_MUTEX_INITIALIZER; +static ANativeWindow *g_req_window; +static int g_req_pending; + +/* Scale mode + alignment (app values, see vk_present.h); written from any thread, read per frame. */ +static volatile int g_mode = VKP_MODE_STRETCH, g_align = VKP_ALIGN_CENTER; + +/* The scene -> output mapping of the last frame (compositor thread): scene pixel (x,y) lands at + * output (off_x + x * kx, off_y + y * ky), clipped to the region rectangle. */ +static struct { + int scene_w, scene_h, out_w, out_h, mode, align; + float kx, ky, off_x, off_y; + int rx, ry, rw, rh; /* region the picture may occupy */ + int valid; +} g_map; + +/* A failed swapchain creation is retried no sooner than this (the window may be mid-teardown), + * and the failure is logged once per streak instead of every frame. */ +static int64_t g_swap_retry_at_ns; +static int g_swap_fail_logged; + +/* Implemented in waylandcomp_jni.c — notifies Java (dismiss launch overlay). */ +extern void banner_on_first_frame(void); + +static char g_gpu_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]; +const char *vkp_gpu_name(void) { return g_gpu_name; } + +/* DRM fourccs name the channels of a little-endian 32-bit word: XRGB8888 is B,G,R,X in memory + * (= VK B8G8R8A8) and XBGR8888 is R,G,B,X (= VK R8G8B8A8). Turnip's Wayland WSI sends XB24 for + * R8G8B8A8 swapchains, so reading everything as BGRA swaps red and blue. */ +static VkFormat drm_to_vk(uint32_t drm) { + switch (drm) { + case 0x34324241: /* AB24 */ + case 0x34324258: /* XB24 */ + return VK_FORMAT_R8G8B8A8_UNORM; + case 0x30334241: /* AB30 */ + case 0x30334258: /* XB30 */ + return VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case 0x30335241: /* AR30 */ + case 0x30335258: /* XR30 */ + return VK_FORMAT_A2R10G10B10_UNORM_PACK32; + case 0x48344241: /* AB4H */ + case 0x48344258: /* XB4H */ + return VK_FORMAT_R16G16B16A16_SFLOAT; + default: /* AR24 / XR24 */ + return VK_FORMAT_B8G8R8A8_UNORM; + } +} + +void vk_present_set_driver(const char *driver_path, const char *library_name, + const char *native_lib_dir) { + free(g_driver_path); free(g_library_name); free(g_native_lib_dir); + g_driver_path = driver_path ? strdup(driver_path) : NULL; + g_library_name = library_name ? strdup(library_name) : NULL; + g_native_lib_dir = native_lib_dir ? strdup(native_lib_dir) : NULL; +} + +/* Destroy and recreate every acquire/render-done semaphore. Done with the swapchain (after the + * device went idle): a frame that acquired an image and then bailed out leaves its acquire + * semaphore signalled with nothing to wait on it, and reusing it in the next acquire is invalid + * (Adreno answers OUT_OF_DATE, which rebuilds again - a loop). Fresh objects cannot carry that. */ +static void reset_sync(void) { + VkSemaphoreCreateInfo semci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; + for (int k = 0; k < MAX_PRESENTS; k++) { + if (g_acqs[k]) g_vk.DestroySemaphore(g_dev, g_acqs[k], NULL); + if (g_rnds[k]) g_vk.DestroySemaphore(g_dev, g_rnds[k], NULL); + g_vk.CreateSemaphore(g_dev, &semci, NULL, &g_acqs[k]); + g_vk.CreateSemaphore(g_dev, &semci, NULL, &g_rnds[k]); + } +} + +static void destroy_swapchain(void) { + g_base_black = 0; /* a new swapchain starts with nothing on it */ + if (g_dev_state != 1) return; + g_vk.DeviceWaitIdle(g_dev); + reset_sync(); + if (g_swapchain) g_vk.DestroySwapchainKHR(g_dev, g_swapchain, NULL); + g_swapchain = VK_NULL_HANDLE; + g_swap_md_identity = 0; /* a new swapchain gets the metadata again */ + if (g_surface) g_vk.DestroySurfaceKHR(g_inst, g_surface, NULL); + g_surface = VK_NULL_HANDLE; + free(g_images); + g_images = NULL; + g_nimg = 0; +} + +void vk_present_set_window(ANativeWindow *window) { + ANativeWindow *superseded = NULL; + pthread_mutex_lock(&g_req_lock); + /* Two requests before the compositor thread got to the first: the first window was never + * used, so its reference is dropped here. */ + if (g_req_pending && g_req_window && g_req_window != window) superseded = g_req_window; + g_req_window = window; + g_req_pending = 1; + pthread_mutex_unlock(&g_req_lock); + if (superseded) ANativeWindow_release(superseded); +} + +int vkp_apply_window_request(void) { + ANativeWindow *w; + pthread_mutex_lock(&g_req_lock); + if (!g_req_pending) { pthread_mutex_unlock(&g_req_lock); return 0; } + w = g_req_window; + g_req_window = NULL; + g_req_pending = 0; + pthread_mutex_unlock(&g_req_lock); + if (w == g_window) { + /* The same window handed over again (ANativeWindow_fromSurface adds a reference each time). */ + if (w) ANativeWindow_release(w); + return 0; + } + sc_layer_window_gone(); /* the layer (if any) belongs to the old window */ + destroy_swapchain(); /* recreated against the new window on the next frame */ + g_swap_hdr_unavailable = 0; /* a new surface (another display, say) may offer HDR10 */ + if (g_window) ANativeWindow_release(g_window); + g_window = w; + g_swap_retry_at_ns = 0; + g_swap_fail_logged = 0; + banner_log("gpu", w ? "screen surface attached" : "screen surface gone: presenting paused"); + return 1; +} + +int vkp_has_window(void) { + int r; + pthread_mutex_lock(&g_req_lock); + r = g_req_pending ? g_req_window != NULL : g_window != NULL; + pthread_mutex_unlock(&g_req_lock); + return r; +} + +int vkp_device_lost(void) { return g_dev_state == -2; } + +void vk_present_set_scale_mode(int mode, int alignment) { + if (mode < VKP_MODE_OFF || mode > VKP_MODE_INTEGER) mode = VKP_MODE_FIT; + if (alignment < VKP_ALIGN_CENTER || alignment > VKP_ALIGN_BOTTOM) alignment = VKP_ALIGN_CENTER; + g_mode = mode; + g_align = alignment; +} + +static const char *mode_name(int m) { + switch (m) { + case VKP_MODE_OFF: return "off (letterbox)"; + case VKP_MODE_FIT: return "fit"; + case VKP_MODE_STRETCH: return "stretch"; + case VKP_MODE_FILL: return "fill"; + case VKP_MODE_INTEGER: return "integer"; + default: return "?"; + } +} +static const char *align_name(int a) { + switch (a) { + case VKP_ALIGN_TOP: return "top"; + case VKP_ALIGN_BOTTOM: return "bottom"; + default: return "center"; + } +} + +/* Mirror of ViewTransformation.update(outer = output, inner = scene, mode, alignment) — keep the + * arithmetic identical: the app maps touch input through that class with the same inputs, so any + * difference here puts the pointer beside what it is pointing at. OFF and FIT are both an + * aspect-preserving letterbox (OFF only differs in the app's fullscreen gates); TOP/BOTTOM confine + * the picture to the top/bottom half of the output (the app's handheld split, #413). */ +static void update_map(int scene_w, int scene_h) { + int mode = g_mode, align = g_align; + int W = (int)g_extent.width, H = (int)g_extent.height; + if (g_map.valid && g_map.scene_w == scene_w && g_map.scene_h == scene_h && g_map.out_w == W && + g_map.out_h == H && g_map.mode == mode && g_map.align == align) + return; + g_map.scene_w = scene_w; g_map.scene_h = scene_h; g_map.out_w = W; g_map.out_h = H; + g_map.mode = mode; g_map.align = align; + + int half = H / 2; + switch (align) { + case VKP_ALIGN_TOP: g_map.rx = 0; g_map.ry = 0; g_map.rw = W; g_map.rh = half; break; + case VKP_ALIGN_BOTTOM: g_map.rx = 0; g_map.ry = half; g_map.rw = W; g_map.rh = H - half; break; + default: g_map.rx = 0; g_map.ry = 0; g_map.rw = W; g_map.rh = H; break; + } + float sx = (float)g_map.rw / scene_w, sy = (float)g_map.rh / scene_h; + if (mode == VKP_MODE_STRETCH) { + g_map.kx = sx; g_map.ky = sy; + g_map.off_x = (float)g_map.rx; g_map.off_y = (float)g_map.ry; + } else { + float aspect; + if (mode == VKP_MODE_FILL) aspect = sx > sy ? sx : sy; + else if (mode == VKP_MODE_INTEGER) { + float m = sx < sy ? sx : sy; + aspect = (float)(int)m; /* floor for m >= 1 */ + if (aspect < 1.0f) aspect = 1.0f; + } else aspect = sx < sy ? sx : sy; + g_map.kx = g_map.ky = aspect; + /* Same integer truncation as ViewTransformation's viewOffsetX/Y. */ + g_map.off_x = (float)(g_map.rx + (int)((g_map.rw - scene_w * aspect) * 0.5f)); + g_map.off_y = (float)(g_map.ry + (int)((g_map.rh - scene_h * aspect) * 0.5f)); + } + g_map.valid = 1; + banner_log("screen", "%s, %s: %dx%d scene shown %dx%d at %d,%d on the %dx%d output", + mode_name(mode), align_name(align), scene_w, scene_h, + (int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f), + (int)g_map.off_x, (int)g_map.off_y, W, H); +} + +int vkp_output_to_scene(double ox, double oy, double *sx, double *sy) { + if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) return 0; + *sx = (ox - g_map.off_x) / g_map.kx; + *sy = (oy - g_map.off_y) / g_map.ky; + return 1; +} + +void vkp_output_size(int *w, int *h) { + *w = (int)g_extent.width; + *h = (int)g_extent.height; +} + +static void init_black_image(void); + +static int has_ext(VkExtensionProperties *e, uint32_t n, const char *name) { + for (uint32_t i = 0; i < n; i++) + if (!strcmp(e[i].extensionName, name)) return 1; + return 0; +} + +/* Instance + device + command objects. Doesn't need the window. */ +static int dev_init(void) { + if (g_dev_state != 0) return g_dev_state == 1 ? 0 : -1; + + /* Load Turnip (adrenotools) and its entry points — NOT the system driver. */ + if (vk_loader_open(g_driver_path, g_library_name, g_native_lib_dir) != 0) { + LOGE("present: vk_loader_open failed"); g_dev_state = -1; return -1; + } + + const char *inst_exts[3] = {VK_KHR_SURFACE_EXTENSION_NAME, + VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, NULL}; + uint32_t n_inst_exts = 2; + /* HDR sessions only (banner_color.h): the colour-space extension lets the swapchain carry HDR10 for + * frame generation. Asked for only when the loader has it, and only when HDR was asked for, so + * every other session creates exactly the instance it always did. */ + if (banner_color_requested() && g_vk.EnumerateInstanceExtensionProperties) { + uint32_t ne = 0; + g_vk.EnumerateInstanceExtensionProperties(NULL, &ne, NULL); + VkExtensionProperties *ie = ne ? calloc(ne, sizeof(*ie)) : NULL; + if (ie && g_vk.EnumerateInstanceExtensionProperties(NULL, &ne, ie) == VK_SUCCESS) { + for (uint32_t i = 0; i < ne; i++) + if (!strcmp(ie[i].extensionName, VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME)) { + inst_exts[n_inst_exts++] = VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME; + g_colorspace_ext = 1; + break; + } + } + free(ie); + banner_log("color", "compositor instance %s VK_EXT_swapchain_colorspace (an HDR10 swapchain for frame " + "generation %s)", g_colorspace_ext ? "enables" : "has no", + g_colorspace_ext ? "is possible where the screen surface offers one" : "is not possible: tone-mapped instead"); + } + /* 1.3 like the X11 renderer's instance: the frame-generation probe (framegen_engine.cpp) + * queries VkPhysicalDeviceVulkan12Features, and a 1.1 instance may be answered as 1.1. */ + VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, + .pApplicationName = "banner-wayland-present", + .apiVersion = VK_API_VERSION_1_3}; + VkInstanceCreateInfo ici = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + .pApplicationInfo = &app, + .enabledExtensionCount = n_inst_exts, + .ppEnabledExtensionNames = inst_exts}; + if (g_vk.CreateInstance(&ici, NULL, &g_inst) != VK_SUCCESS) { + LOGE("present: vkCreateInstance failed"); g_dev_state = -1; return -1; + } + vk_loader_load_instance(g_inst); + + uint32_t npd = 0; + g_vk.EnumeratePhysicalDevices(g_inst, &npd, NULL); + if (!npd) { LOGE("present: no physical devices"); g_dev_state = -1; return -1; } + VkPhysicalDevice pds[8]; if (npd > 8) npd = 8; + g_vk.EnumeratePhysicalDevices(g_inst, &npd, pds); + g_pd = VK_NULL_HANDLE; + for (uint32_t i = 0; i < npd && g_pd == VK_NULL_HANDLE; i++) { + uint32_t nq = 0; + g_vk.GetPhysicalDeviceQueueFamilyProperties(pds[i], &nq, NULL); + VkQueueFamilyProperties qs[16]; if (nq > 16) nq = 16; + g_vk.GetPhysicalDeviceQueueFamilyProperties(pds[i], &nq, qs); + for (uint32_t q = 0; q < nq; q++) + if (qs[q].queueFlags & VK_QUEUE_GRAPHICS_BIT) { g_pd = pds[i]; g_qfam = q; break; } + } + if (g_pd == VK_NULL_HANDLE) { LOGE("present: no graphics queue"); g_dev_state = -1; return -1; } + { + VkPhysicalDeviceProperties props; + g_vk.GetPhysicalDeviceProperties(g_pd, &props); + snprintf(g_gpu_name, sizeof(g_gpu_name), "%s", props.deviceName); + banner_log("gpu", "compositor renders on %s with %s", props.deviceName, + g_library_name ? g_library_name : "the system Vulkan driver"); + if (g_driver_path) banner_log("gpu", "driver folder %s", g_driver_path); + } + g_vk.GetPhysicalDeviceMemoryProperties(g_pd, &g_memprops); + + /* Verify the dmabuf-import extensions are present, and log any that are missing. */ + const char *dev_exts[7] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, "VK_KHR_external_memory_fd", + "VK_EXT_external_memory_dma_buf", "VK_EXT_image_drm_format_modifier", + "VK_KHR_image_format_list", NULL, NULL}; + uint32_t n_dev_exts = 5; + uint32_t ne = 0; + g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL); + VkExtensionProperties *exts = calloc(ne ? ne : 1, sizeof(*exts)); + g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, exts); + for (unsigned i = 0; i < 5; i++) + if (!has_ext(exts, ne, dev_exts[i])) + LOGE("present: driver MISSING %s (dmabuf import will fail)", dev_exts[i]); + /* HDR sessions only: the HDR10 swapchain (frame generation) can carry the game's metadata. */ + int want_hdr_md = 0; + if (banner_color_requested()) { + want_hdr_md = has_ext(exts, ne, VK_EXT_HDR_METADATA_EXTENSION_NAME); + if (want_hdr_md) dev_exts[n_dev_exts++] = VK_EXT_HDR_METADATA_EXTENSION_NAME; + } + /* The layer pool's release fences as GPU waits (sync_file -> semaphore): optional, the pool falls + * back to waiting for them on the CPU without it. */ + const int want_sem_fd = has_ext(exts, ne, VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME); + if (want_sem_fd) dev_exts[n_dev_exts++] = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME; + free(exts); + + float prio = 1.0f; + VkDeviceQueueCreateInfo qci = {.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, + .queueFamilyIndex = g_qfam, .queueCount = 1, .pQueuePriorities = &prio}; + /* Frame generation (framegen_bridge.c): the LSFG chain needs the memory-model and + * storage-image features enabled at device creation; the probe hands back the pNext chain + * for them, or NULL on a device that cannot run it (then Win-FG Native alone is offered). A + * driver that rejects the chain costs nothing: retried once without it, exactly as before. */ + const void *fg_features = vkp_framegen_device_features(g_inst, vk_loader_gipa(), g_pd); + VkDeviceCreateInfo dci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = fg_features, + .queueCreateInfoCount = 1, .pQueueCreateInfos = &qci, + .enabledExtensionCount = n_dev_exts, .ppEnabledExtensionNames = dev_exts}; + VkResult dr = g_vk.CreateDevice(g_pd, &dci, NULL, &g_dev); + if (dr != VK_SUCCESS && fg_features) { + banner_log("framegen", "the driver refused the LSFG feature set (%s); device created without it", + vk_result_name(dr)); + dci.pNext = NULL; + fg_features = NULL; + dr = g_vk.CreateDevice(g_pd, &dci, NULL, &g_dev); + } + if (dr != VK_SUCCESS) { + LOGE("present: vkCreateDevice failed"); g_dev_state = -1; return -1; + } + vk_loader_load_device(g_dev); + g_vk.GetDeviceQueue(g_dev, g_qfam, 0, &g_queue); + if (want_sem_fd) { + g_import_sem_fd = (PFN_vkImportSemaphoreFdKHR)g_vk.GetDeviceProcAddr(g_dev, "vkImportSemaphoreFdKHR"); + VkSemaphoreCreateInfo wsci = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; + if (!g_import_sem_fd || g_vk.CreateSemaphore(g_dev, &wsci, NULL, &g_wait_sem) != VK_SUCCESS) { + g_import_sem_fd = NULL; + g_wait_sem = VK_NULL_HANDLE; + } + } + banner_log("perf", "layer buffers: the display's release fences are waited for %s", + g_import_sem_fd ? "on the GPU (VK_KHR_external_semaphore_fd)" + : "on the CPU (this driver has no VK_KHR_external_semaphore_fd)"); + if (want_hdr_md) + g_set_hdr_metadata = (PFN_vkSetHdrMetadataEXT)g_vk.GetDeviceProcAddr(g_dev, "vkSetHdrMetadataEXT"); + if (banner_color_requested()) + banner_log("color", "compositor device %s VK_EXT_hdr_metadata (the HDR10 swapchain for frame generation %s)", + g_set_hdr_metadata ? "enables" : "has no", + g_set_hdr_metadata ? "carries the game's mastering metadata" : "goes without the game's metadata"); + + VkCommandPoolCreateInfo pci = {.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, + .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, + .queueFamilyIndex = g_qfam}; + g_vk.CreateCommandPool(g_dev, &pci, NULL, &g_pool); + VkCommandBufferAllocateInfo cai = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + .commandPool = g_pool, + .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, .commandBufferCount = MAX_PRESENTS}; + g_vk.AllocateCommandBuffers(g_dev, &cai, g_cmds); + VkFenceCreateInfo fci = {.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; + g_vk.CreateFence(g_dev, &fci, NULL, &g_fence); + + vkp_effects_bind_device(g_dev, g_pd, &g_memprops); + hdrc_bind_device(g_dev, &g_memprops); + g_dev_state = 1; + reset_sync(); + init_black_image(); + vkp_framegen_device_ready(g_dev, g_queue, g_qfam, fg_features != NULL); + return 0; +} + +int vkp_ready(void) { return dev_init(); } + +static int swap_init_locked(void); + +static int swap_init(void) { + struct timespec ts; + int64_t now; + if (!g_window) return -1; + clock_gettime(CLOCK_MONOTONIC, &ts); + now = (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; + if (now < g_swap_retry_at_ns) return -1; + if (swap_init_locked() == 0) { + g_swap_retry_at_ns = 0; + g_swap_fail_logged = 0; + return 0; + } + destroy_swapchain(); + g_swap_retry_at_ns = now + 500000000LL; + if (!g_swap_fail_logged) { + g_swap_fail_logged = 1; + LOGE("present: no swapchain on the screen surface; retrying every 0.5 s"); + } + return -1; +} + +#define SWLOGE(...) do { if (!g_swap_fail_logged) LOGE(__VA_ARGS__); } while (0) + +/* Short names for the session log (the formats and colour spaces an Android surface lists). */ +static void vk_format_short(VkFormat f, char *out, size_t n) { + const char *s = NULL; + switch (f) { + case VK_FORMAT_R8G8B8A8_UNORM: s = "RGBA8"; break; + case VK_FORMAT_R8G8B8A8_SRGB: s = "RGBA8_SRGB"; break; + case VK_FORMAT_B8G8R8A8_UNORM: s = "BGRA8"; break; + case VK_FORMAT_B8G8R8A8_SRGB: s = "BGRA8_SRGB"; break; + case VK_FORMAT_R5G6B5_UNORM_PACK16: s = "RGB565"; break; + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: s = "A2B10G10R10"; break; + case VK_FORMAT_A2R10G10B10_UNORM_PACK32: s = "A2R10G10B10"; break; + case VK_FORMAT_R16G16B16A16_SFLOAT: s = "RGBA16F"; break; + default: break; + } + if (s) snprintf(out, n, "%s", s); else snprintf(out, n, "format%d", (int)f); +} +static int vk_format_bits(VkFormat f) { + switch (f) { + case VK_FORMAT_A2B10G10R10_UNORM_PACK32: case VK_FORMAT_A2R10G10B10_UNORM_PACK32: return 10; + case VK_FORMAT_R16G16B16A16_SFLOAT: return 16; + default: return 8; + } +} +static const char *vk_colorspace_short(VkColorSpaceKHR c) { + switch ((int)c) { + case VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: return "sRGB"; + case VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT: return "P3"; + case VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT: return "extended-sRGB-linear"; + case VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT: return "P3-linear"; + case VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT: return "DCI-P3"; + case VK_COLOR_SPACE_BT709_LINEAR_EXT: return "BT709-linear"; + case VK_COLOR_SPACE_BT709_NONLINEAR_EXT: return "BT709"; + case VK_COLOR_SPACE_BT2020_LINEAR_EXT: return "BT2020-linear"; + case VK_COLOR_SPACE_HDR10_ST2084_EXT: return "HDR10"; + case VK_COLOR_SPACE_DOLBYVISION_EXT: return "DolbyVision"; + case VK_COLOR_SPACE_HDR10_HLG_EXT: return "HLG"; + case VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT: return "AdobeRGB-linear"; + case VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT: return "AdobeRGB"; + case VK_COLOR_SPACE_PASS_THROUGH_EXT: return "pass-through"; + case VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT: return "extended-sRGB"; + default: return NULL; + } +} +/* One line: the total, how many colour spaces each format comes with, and every HDR-capable pair + * (HDR10 / HLG / extended sRGB, any format) - never "the first N pairs". */ +static int hdr_capable_space(VkColorSpaceKHR cs) { + int c = (int)cs; + return c == VK_COLOR_SPACE_HDR10_ST2084_EXT || c == VK_COLOR_SPACE_HDR10_HLG_EXT || + c == VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT || c == VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT; +} +static void log_surface_formats(const VkSurfaceFormatKHR *f, uint32_t n) { + char per[200] = "", hdr[256] = ""; + size_t pp = 0, hp = 0; + unsigned hdr_n = 0, hdr_cut = 0; + for (uint32_t i = 0; i < n; i++) { + int first = 1; + for (uint32_t j = 0; j < i; j++) if (f[j].format == f[i].format) { first = 0; break; } + if (first && pp < sizeof(per) - 32) { + unsigned cnt = 0; + for (uint32_t j = i; j < n; j++) if (f[j].format == f[i].format) cnt++; + char nm[24]; + vk_format_short(f[i].format, nm, sizeof(nm)); + pp += (size_t)snprintf(per + pp, sizeof(per) - pp, "%s%s x%u", pp ? ", " : "", nm, cnt); + } + } + /* The deep formats (10-bit, FP16) first, so a long list never pushes them out of the line. */ + for (int pass = 0; pass < 2; pass++) + for (uint32_t i = 0; i < n; i++) { + if (!hdr_capable_space(f[i].colorSpace) || (vk_format_bits(f[i].format) > 8) != (pass == 0)) continue; + hdr_n++; + char nm[24]; + vk_format_short(f[i].format, nm, sizeof(nm)); + if (hp < sizeof(hdr) - 48) + hp += (size_t)snprintf(hdr + hp, sizeof(hdr) - hp, "%s%s/%s", hp ? ", " : "", nm, + vk_colorspace_short(f[i].colorSpace)); + else hdr_cut++; + } + banner_log("color", "screen surface lists %u format/colour-space pairs (%s); HDR-capable: %s%s", n, per, + hdr_n ? hdr : "none", hdr_cut ? " (+more)" : ""); +} + +static int swap_init_locked(void) { + + VkAndroidSurfaceCreateInfoKHR aci = { + .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, .window = g_window}; + if (g_vk.CreateAndroidSurfaceKHR(g_inst, &aci, NULL, &g_surface) != VK_SUCCESS) { + SWLOGE("present: create android surface failed"); return -1; + } + VkBool32 sup = VK_FALSE; + g_vk.GetPhysicalDeviceSurfaceSupportKHR(g_pd, g_qfam, g_surface, &sup); + if (!sup) { SWLOGE("present: queue can't present to the window"); return -1; } + + VkSurfaceCapabilitiesKHR caps; + g_vk.GetPhysicalDeviceSurfaceCapabilitiesKHR(g_pd, g_surface, &caps); + /* Remembered for the layer path: currentTransform is the rotation the presentation engine (and + * therefore SurfaceFlinger and the DPU) applies to everything we put on this display. Anything + * but IDENTITY means every display layer we hand over is a ROTATED layer. sc_layer.c needs that + * to decide whether a second layer is affordable — see sc_layer_present_overlay(). */ + g_surface_transform = caps.currentTransform; + g_surface_transform_known = 1; + g_caps_extent = caps.currentExtent; /* check_surface_changed() compares against this */ + g_surface_checked_ns = perf_now(); + /* Every format/colour-space pair the surface lists. With VK_EXT_swapchain_colorspace the Android + * WSI lists each format once per colour space (the Fold: 11 per format), so a fixed-size array + * silently drops the 10-bit and FP16 rows - which is where HDR10 lives. */ + uint32_t nfmt = 0; + g_vk.GetPhysicalDeviceSurfaceFormatsKHR(g_pd, g_surface, &nfmt, NULL); + VkSurfaceFormatKHR *fmts = nfmt ? calloc(nfmt, sizeof(*fmts)) : NULL; + if (!fmts) { SWLOGE("present: the surface lists no formats"); return -1; } + if (g_vk.GetPhysicalDeviceSurfaceFormatsKHR(g_pd, g_surface, &nfmt, fmts) < 0 || !nfmt) { + free(fmts); SWLOGE("present: vkGetPhysicalDeviceSurfaceFormatsKHR failed"); return -1; + } + VkSurfaceFormatKHR chosen = fmts[0]; + const VkSurfaceFormatKHR sdr_choice = fmts[0]; + if (banner_color_requested() && (!g_surface_formats_said || g_swap_hdr_want)) { + g_surface_formats_said = 1; + log_surface_formats(fmts, nfmt); + } + /* HDR10 for frame generation with an HDR game (render_impl sets g_swap_hdr_want): the best format + * the surface lists with VK_COLOR_SPACE_HDR10_ST2084_EXT - 10-bit, then FP16, then 8-bit (still a + * PQ BT.2020 picture, with less precision). None listed -> the frames are tone-mapped into the + * ordinary swapchain, and that is said once. */ + g_swap_is_hdr = 0; + if (g_swap_hdr_want) { + static const VkFormat pref[] = {VK_FORMAT_A2B10G10R10_UNORM_PACK32, VK_FORMAT_A2R10G10B10_UNORM_PACK32, + VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R8G8B8A8_UNORM, + VK_FORMAT_B8G8R8A8_UNORM}; + int pick = -1; + for (unsigned k = 0; k < sizeof(pref) / sizeof(pref[0]) && pick < 0; k++) + for (uint32_t i = 0; i < nfmt; i++) + if (fmts[i].colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT && fmts[i].format == pref[k]) { + pick = (int)i; break; + } + if (pick >= 0) { + chosen = fmts[pick]; + g_swap_is_hdr = 1; + char fname[24]; + vk_format_short(chosen.format, fname, sizeof(fname)); + banner_log("color", "screen swapchain built as HDR10 (format %d %s, HDR10_ST2084): frame-generated HDR " + "frames reach the display as PQ BT.2020%s", (int)chosen.format, fname, + vk_format_bits(chosen.format) <= 8 ? " - an 8-bit swapchain: banding possible in smooth gradients" + : ""); + } else { + g_swap_hdr_unavailable = 1; + banner_log("color", "the screen surface lists no HDR10 swapchain format among its %u format/colour-space " + "pairs (see the line above): frames with frame generation are tone-mapped to SDR instead", + nfmt); + } + } + free(fmts); + g_swap_fmt = chosen.format; + + g_extent = caps.currentExtent; + if (g_extent.width == 0xFFFFFFFF) { + g_extent.width = ANativeWindow_getWidth(g_window); + g_extent.height = ANativeWindow_getHeight(g_window); + } + /* + one image per generated frame while frame generation is armed: every present of a scene + * frame can then be queued at once and FIFO spaces them onto consecutive vblanks. */ + g_swap_extra = vkp_framegen_extra_images(); + uint32_t want = caps.minImageCount + 1 + (uint32_t)g_swap_extra; + if (caps.maxImageCount && want > caps.maxImageCount) want = caps.maxImageCount; + + /* Use IDENTITY preTransform when the surface supports it. Setting preTransform = + * currentTransform tells the presentation engine our content is ALREADY pre-rotated by + * that amount — but our blit doesn't rotate, so on a device whose surface reports a 90° + * currentTransform the display then rotates our upright frame 90° (game shows sideways). + * IDENTITY = "don't rotate what I present", which is what we want. */ + VkSurfaceTransformFlagBitsKHR pretrans = + (caps.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) + ? VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR : caps.currentTransform; + + VkSwapchainCreateInfoKHR sci = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .surface = g_surface, + .minImageCount = want, .imageFormat = chosen.format, .imageColorSpace = chosen.colorSpace, + .imageExtent = g_extent, .imageArrayLayers = 1, + .imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, .preTransform = pretrans, + .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, + .presentMode = VK_PRESENT_MODE_FIFO_KHR, .clipped = VK_TRUE}; + VkResult cr = g_vk.CreateSwapchainKHR(g_dev, &sci, NULL, &g_swapchain); + if (cr != VK_SUCCESS && g_swap_is_hdr) { + /* The surface listed the HDR10 pair but refused the swapchain: say so, never ask again this + * surface, and build the ordinary one now (frames tone-mapped) - never a black screen. */ + banner_log("color", "the driver refused the HDR10 swapchain (%s): frames with frame generation are " + "tone-mapped to SDR instead", vk_result_name(cr)); + g_swap_is_hdr = 0; + g_swap_hdr_unavailable = 1; + g_swapchain = VK_NULL_HANDLE; + sci.imageFormat = sdr_choice.format; + sci.imageColorSpace = sdr_choice.colorSpace; + g_swap_fmt = sdr_choice.format; + cr = g_vk.CreateSwapchainKHR(g_dev, &sci, NULL, &g_swapchain); + } + if (cr != VK_SUCCESS) { + g_swapchain = VK_NULL_HANDLE; + SWLOGE("present: vkCreateSwapchainKHR failed (%d)", (int)cr); + return -1; + } + g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, NULL); + g_images = calloc(g_nimg, sizeof(VkImage)); + g_vk.GetSwapchainImagesKHR(g_dev, g_swapchain, &g_nimg, g_images); + + banner_log("gpu", "screen output %ux%u, %u buffers, vsync%s", g_extent.width, g_extent.height, g_nimg, + g_swap_extra ? " (frame generation: several presents per frame)" : ""); + return 0; +} + +static int memory_type(uint32_t bits, VkMemoryPropertyFlags want) { + for (uint32_t i = 0; i < g_memprops.memoryTypeCount; i++) + if ((bits & (1u << i)) && (g_memprops.memoryTypes[i].propertyFlags & want) == want) + return (int)i; + return -1; +} + +/* The small black image the letterbox bars are blitted from (see g_black_img): created, cleared and left + * in TRANSFER_SRC_OPTIMAL once, with a one-time submit, right after the device comes up. Any failure only + * means the bars are cleared the old way (the whole output). */ +static void init_black_image(void) { + g_black_state = -1; + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, + .format = VK_FORMAT_R8G8B8A8_UNORM, .extent = {BLACK_DIM, BLACK_DIM, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + if (g_vk.CreateImage(g_dev, &ici, NULL, &g_black_img) != VK_SUCCESS) { g_black_img = VK_NULL_HANDLE; return; } + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, g_black_img, &req); + int idx = memory_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (idx < 0) idx = memory_type(req.memoryTypeBits, 0); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, + .memoryTypeIndex = (uint32_t)(idx < 0 ? 0 : idx)}; + if (idx < 0 || g_vk.AllocateMemory(g_dev, &mai, NULL, &g_black_mem) != VK_SUCCESS) { + g_vk.DestroyImage(g_dev, g_black_img, NULL); + g_black_img = VK_NULL_HANDLE; g_black_mem = VK_NULL_HANDLE; + return; + } + g_vk.BindImageMemory(g_dev, g_black_img, g_black_mem, 0); + + VkCommandBuffer cmd = g_cmds[0]; + g_vk.ResetCommandBuffer(cmd, 0); + VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; + g_vk.BeginCommandBuffer(cmd, &bi); + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + VkImageMemoryBarrier to_dst = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_black_img, .subresourceRange = range, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &to_dst); + VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; + g_vk.CmdClearColorImage(cmd, g_black_img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); + VkImageMemoryBarrier to_src = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_black_img, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &to_src); + g_vk.EndCommandBuffer(cmd); + VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cmd}; + g_vk.ResetFences(g_dev, 1, &g_fence); + if (g_vk.QueueSubmit(g_queue, 1, &si, g_fence) == VK_SUCCESS && + g_vk.WaitForFences(g_dev, 1, &g_fence, VK_TRUE, 1000000000ULL) == VK_SUCCESS) + g_black_state = 1; + else + banner_log("gpu", "letterbox black image unavailable: the whole output is cleared every copy-path frame"); +} + +/* Blit the black image over everything of swapchain image `img` (in TRANSFER_DST_OPTIMAL) OUTSIDE the + * destination rectangle of `covered` - the letterbox bars around a picture that fills that rectangle + * completely. Up to four rectangles, one blit command. 0 = not possible (no black image): the caller + * clears the whole image instead. */ +static int record_bars_clear(VkCommandBuffer cmd, VkImage img, const VkImageBlit *covered) { + if (g_black_state != 1 || !covered) return 0; + const int W = (int)g_extent.width, H = (int)g_extent.height; + int x0 = covered->dstOffsets[0].x, x1 = covered->dstOffsets[1].x; + int y0 = covered->dstOffsets[0].y, y1 = covered->dstOffsets[1].y; + if (x0 > x1) { int t = x0; x0 = x1; x1 = t; } + if (y0 > y1) { int t = y0; y0 = y1; y1 = t; } + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 > W) x1 = W; + if (y1 > H) y1 = H; + if (x1 <= x0 || y1 <= y0) return 0; + int rects[4][4], n = 0; + if (y0 > 0) { rects[n][0] = 0; rects[n][1] = 0; rects[n][2] = W; rects[n][3] = y0; n++; } /* top */ + if (y1 < H) { rects[n][0] = 0; rects[n][1] = y1; rects[n][2] = W; rects[n][3] = H; n++; } /* bottom */ + if (x0 > 0) { rects[n][0] = 0; rects[n][1] = y0; rects[n][2] = x0; rects[n][3] = y1; n++; } /* left */ + if (x1 < W) { rects[n][0] = x1; rects[n][1] = y0; rects[n][2] = W; rects[n][3] = y1; n++; } /* right */ + if (!n) return 1; /* the picture covers the whole output: nothing to clear */ + VkImageBlit blits[4]; + for (int i = 0; i < n; i++) + blits[i] = (VkImageBlit){.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{0, 0, 0}, {BLACK_DIM, BLACK_DIM, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{rects[i][0], rects[i][1], 0}, {rects[i][2], rects[i][3], 1}}}; + g_vk.CmdBlitImage(cmd, g_black_img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, img, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (uint32_t)n, blits, VK_FILTER_NEAREST); + return 1; +} + +const char *vkp_modifier_name(uint64_t modifier) { + static char other[40]; + if (modifier == VKP_MOD_LINEAR) return "linear"; + if (modifier == VKP_MOD_QCOM_COMPRESSED) return "qcom_compressed"; + if (modifier == VKP_MOD_INVALID) return "implicit"; + snprintf(other, sizeof(other), "modifier %#llx", (unsigned long long)modifier); + return other; +} + +/* Can the driver create the image vkp_image_import_dmabuf() creates for this format+modifier + * (2D, DRM_FORMAT_MODIFIER tiling, TRANSFER_SRC, dma-buf memory) — and import it? */ +static int modifier_importable(VkFormat fmt, uint64_t modifier) { + if (!g_vk.GetPhysicalDeviceImageFormatProperties2) return 1; /* can't ask; the create will tell */ + VkPhysicalDeviceExternalImageFormatInfo ext = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT}; + VkPhysicalDeviceImageDrmFormatModifierInfoEXT mod = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT, .pNext = &ext, + .drmFormatModifier = modifier, .sharingMode = VK_SHARING_MODE_EXCLUSIVE}; + VkPhysicalDeviceImageFormatInfo2 info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, .pNext = &mod, + .format = fmt, .type = VK_IMAGE_TYPE_2D, .tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT, + .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT}; + VkExternalImageFormatProperties extp = {.sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES}; + VkImageFormatProperties2 props = {.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, .pNext = &extp}; + if (g_vk.GetPhysicalDeviceImageFormatProperties2(g_pd, &info, &props) != VK_SUCCESS) return 0; + return (extp.externalMemoryProperties.externalMemoryFeatures & + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT) != 0; +} + +int vkp_dmabuf_modifiers(uint32_t drm_format, uint64_t *out, int max) { + if (max <= 0 || dev_init() != 0 || !g_vk.GetPhysicalDeviceFormatProperties2) return 0; + VkFormat fmt = drm_to_vk(drm_format); + VkDrmFormatModifierPropertiesListEXT list = { + .sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT}; + VkFormatProperties2 fp = {.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, .pNext = &list}; + g_vk.GetPhysicalDeviceFormatProperties2(g_pd, fmt, &fp); + if (!list.drmFormatModifierCount) return 0; + VkDrmFormatModifierPropertiesEXT *props = calloc(list.drmFormatModifierCount, sizeof(*props)); + if (!props) return 0; + list.pDrmFormatModifierProperties = props; + g_vk.GetPhysicalDeviceFormatProperties2(g_pd, fmt, &fp); + + int n = 0; + for (uint32_t i = 0; i < list.drmFormatModifierCount; i++) { + uint64_t m = props[i].drmFormatModifier; + const char *why = NULL; + if (m != VKP_MOD_LINEAR && m != VKP_MOD_QCOM_COMPRESSED) why = "unknown layout"; + else if (props[i].drmFormatModifierPlaneCount != 1) why = "not single-plane"; + else if (!(props[i].drmFormatModifierTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT)) why = "no blit source"; + else if (!modifier_importable(fmt, m)) why = "not importable as a dma-buf"; + if (why) { + LOGI("dmabuf: %c%c%c%c %s reported by the driver but not advertised: %s", + drm_format & 0xff, (drm_format >> 8) & 0xff, (drm_format >> 16) & 0xff, + (drm_format >> 24) & 0xff, vkp_modifier_name(m), why); + continue; + } + if (n < max) out[n++] = m; + } + free(props); + return n; +} + +struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h, + uint32_t stride, uint32_t offset) { + return vkp_image_import_dmabuf(fd, drm_format, modifier, w, h, stride, offset, 0); +} + +int vkp_image_is_dmabuf(const struct vkp_image *img) { return img && img->dmabuf && !img->blit_dst; } + +struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h, + uint32_t stride, uint32_t offset, int as_blit_dst) { + if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL; + if (dev_init() != 0) return NULL; + + struct vkp_image *img = calloc(1, sizeof(*img)); + if (!img) return NULL; + img->w = w; img->h = h; img->dmabuf = 1; img->blit_dst = as_blit_dst ? 1 : 0; + + VkSubresourceLayout plane = {.offset = offset, .rowPitch = stride}; + VkImageDrmFormatModifierExplicitCreateInfoEXT modInfo = { + .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_EXPLICIT_CREATE_INFO_EXT, + .drmFormatModifier = modifier, .drmFormatModifierPlaneCount = 1, .pPlaneLayouts = &plane}; + VkExternalMemoryImageCreateInfo extImg = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, .pNext = &modInfo, + .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT}; + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .pNext = &extImg, + .imageType = VK_IMAGE_TYPE_2D, .format = drm_to_vk(drm_format), .extent = {w, h, 1}, + .mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT, + .usage = as_blit_dst ? VK_IMAGE_USAGE_TRANSFER_DST_BIT : VK_IMAGE_USAGE_TRANSFER_SRC_BIT, + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + VkResult cr = g_vk.CreateImage(g_dev, &ici, NULL, &img->image); + if (cr != VK_SUCCESS) { + LOGE("%s: vkCreateImage(%s, %dx%d, pitch %u, offset %u) -> %s%s", as_blit_dst ? "layer" : "dmabuf", + vkp_modifier_name(modifier), w, h, stride, offset, vk_result_name(cr), + (!as_blit_dst && modifier == VKP_MOD_QCOM_COMPRESSED) + ? ": the game's UBWC layout was refused; BANNER_WAYLAND_UBWC=0 forces linear buffers" : ""); + free(img); return NULL; + } + + int dupfd = dup(fd); + uint32_t allowed = 0xffffffff; + if (g_vk.GetMemoryFdPropertiesKHR) { + VkMemoryFdPropertiesKHR fp = {.sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR}; + if (g_vk.GetMemoryFdPropertiesKHR(g_dev, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + dupfd, &fp) == VK_SUCCESS) + allowed = fp.memoryTypeBits; + } + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, img->image, &req); + uint32_t bits = req.memoryTypeBits & allowed; + int idx = -1; + for (int i = 0; i < 32; i++) if (bits & (1u << i)) { idx = i; break; } + if (idx < 0) { + LOGE("%s: no memory type can import the %s dma-buf (image types %#x, fd types %#x)", + as_blit_dst ? "layer" : "dmabuf", vkp_modifier_name(modifier), req.memoryTypeBits, allowed); + g_vk.DestroyImage(g_dev, img->image, NULL); close(dupfd); free(img); return NULL; + } + + VkImportMemoryFdInfoKHR imp = {.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + .fd = dupfd}; + VkMemoryDedicatedAllocateInfo ded = {.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, + .pNext = &imp, .image = img->image}; + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .pNext = &ded, + .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx}; + VkResult mr = g_vk.AllocateMemory(g_dev, &mai, NULL, &img->mem); + if (mr != VK_SUCCESS) { + LOGE("%s: importing the %s dma-buf (%dx%d, %llu bytes) -> %s", as_blit_dst ? "layer" : "dmabuf", + vkp_modifier_name(modifier), w, h, (unsigned long long)req.size, vk_result_name(mr)); + g_vk.DestroyImage(g_dev, img->image, NULL); close(dupfd); free(img); return NULL; + } + VkResult br = g_vk.BindImageMemory(g_dev, img->image, img->mem, 0); + if (br != VK_SUCCESS) { + LOGE("%s: vkBindImageMemory(%s dma-buf) -> %s", as_blit_dst ? "layer" : "dmabuf", + vkp_modifier_name(modifier), vk_result_name(br)); + g_vk.FreeMemory(g_dev, img->mem, NULL); g_vk.DestroyImage(g_dev, img->image, NULL); + free(img); return NULL; + } + return img; +} + +struct vkp_image *vkp_image_create_shm(int w, int h) { + if (w <= 0 || h <= 0 || dev_init() != 0) return NULL; + + struct vkp_image *img = calloc(1, sizeof(*img)); + if (!img) return NULL; + img->w = w; img->h = h; + + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, + .format = VK_FORMAT_B8G8R8A8_UNORM, .extent = {w, h, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_LINEAR, + .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT, .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + .initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED}; + if (g_vk.CreateImage(g_dev, &ici, NULL, &img->image) != VK_SUCCESS) { free(img); return NULL; } + + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, img->image, &req); + int idx = memory_type(req.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, + .allocationSize = req.size, .memoryTypeIndex = (uint32_t)idx}; + if (idx < 0 || g_vk.AllocateMemory(g_dev, &mai, NULL, &img->mem) != VK_SUCCESS) { + g_vk.DestroyImage(g_dev, img->image, NULL); free(img); return NULL; + } + g_vk.BindImageMemory(g_dev, img->image, img->mem, 0); + + VkImageSubresource subr = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0}; + VkSubresourceLayout lay; + g_vk.GetImageSubresourceLayout(g_dev, img->image, &subr, &lay); + img->offset = lay.offset; + img->row_pitch = lay.rowPitch; + if (g_vk.MapMemory(g_dev, img->mem, 0, req.size, 0, &img->map) != VK_SUCCESS) { + vkp_image_destroy(img); return NULL; + } + return img; +} + +/* Renders are synchronous (we wait for the frame's fence), so writing between frames + * never races the GPU. */ +void vkp_image_upload_shm(struct vkp_image *img, const void *data, int stride) { + if (!img || !img->map || !data) return; + size_t rowbytes = (size_t)img->w * 4; + if ((size_t)stride < rowbytes) rowbytes = (size_t)stride; + for (int y = 0; y < img->h; y++) + memcpy((uint8_t *)img->map + img->offset + (size_t)y * img->row_pitch, + (const uint8_t *)data + (size_t)y * stride, rowbytes); +} + +int vkp_image_width(const struct vkp_image *img) { return img ? img->w : 0; } +int vkp_image_height(const struct vkp_image *img) { return img ? img->h : 0; } + +void vkp_image_destroy(struct vkp_image *img) { + if (!img) return; + if (g_dev) { + if (img->map) g_vk.UnmapMemory(g_dev, img->mem); + if (img->image) g_vk.DestroyImage(g_dev, img->image, NULL); + if (img->mem) g_vk.FreeMemory(g_dev, img->mem, NULL); + } + free(img); +} + +/* Map a draw into swapchain pixels through the scale mode, clipping the destination to the + * picture's region (the whole output, or its half on TOP/BOTTOM; FILL's overflow is cut here) + * and trimming the source to match. Returns 0 if nothing is left to draw. */ +static int map_draw(const struct vkp_draw *d, float kx, float ky, float off_x, float off_y, + float L, float T, float R, float B, VkImageBlit *blit) { + float x0 = off_x + d->dx * kx, y0 = off_y + d->dy * ky; + float x1 = off_x + (d->dx + d->dw) * kx, y1 = off_y + (d->dy + d->dh) * ky; + float sx0 = d->sx, sy0 = d->sy, sx1 = d->sx + d->sw, sy1 = d->sy + d->sh; + + if (x1 <= x0 || y1 <= y0 || sx1 <= sx0 || sy1 <= sy0) return 0; + if (x0 < L) { sx0 += (L - x0) / (x1 - x0) * (sx1 - sx0); x0 = L; } + if (y0 < T) { sy0 += (T - y0) / (y1 - y0) * (sy1 - sy0); y0 = T; } + if (x1 > R) { sx1 -= (x1 - R) / (x1 - x0) * (sx1 - sx0); x1 = R; } + if (y1 > B) { sy1 -= (y1 - B) / (y1 - y0) * (sy1 - sy0); y1 = B; } + + int ix0 = (int)(x0 + 0.5f), iy0 = (int)(y0 + 0.5f), ix1 = (int)(x1 + 0.5f), iy1 = (int)(y1 + 0.5f); + int isx0 = (int)sx0, isy0 = (int)sy0, isx1 = (int)(sx1 + 0.5f), isy1 = (int)(sy1 + 0.5f); + if (isx0 < 0) isx0 = 0; + if (isy0 < 0) isy0 = 0; + if (isx1 > d->img->w) isx1 = d->img->w; + if (isy1 > d->img->h) isy1 = d->img->h; + if (ix1 <= ix0 || iy1 <= iy0 || isx1 <= isx0 || isy1 <= isy0) return 0; + + *blit = (VkImageBlit){.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{isx0, isy0, 0}, {isx1, isy1, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{ix0, iy0, 0}, {ix1, iy1, 1}}}; + return 1; +} + +static int draw_to_blit(const struct vkp_draw *d, VkImageBlit *blit) { + float R = (float)(g_map.rx + g_map.rw), B = (float)(g_map.ry + g_map.rh); + if (R > (float)g_extent.width) R = (float)g_extent.width; + if (B > (float)g_extent.height) B = (float)g_extent.height; + return map_draw(d, g_map.kx, g_map.ky, g_map.off_x, g_map.off_y, (float)g_map.rx, (float)g_map.ry, R, B, blit); +} + +/* The same draw 1:1 into the scene image (no mapping: scene pixels are the destination). */ +static int draw_to_scene_blit(const struct vkp_draw *d, int scene_w, int scene_h, VkImageBlit *blit) { + return map_draw(d, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, (float)scene_w, (float)scene_h, blit); +} + +static void destroy_scene_image(void) { + if (g_scene.img) hdrc_forget_image(g_scene.img); /* the HDR pass may have drawn into it */ + if (g_scene.img) g_vk.DestroyImage(g_dev, g_scene.img, NULL); + if (g_scene.mem) g_vk.FreeMemory(g_dev, g_scene.mem, NULL); + memset(&g_scene, 0, sizeof(g_scene)); +} + +/* The scene image at this size (R8G8B8A8: a blit converts every client format into it, and the + * chain's shaders read it as RGBA). 0 = ready. */ +static int ensure_scene_image(int w, int h) { + if (g_scene.img && g_scene.w == w && g_scene.h == h) return 0; + destroy_scene_image(); + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, + .format = VK_FORMAT_R8G8B8A8_UNORM, .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, .arrayLayers = 1, + .samples = VK_SAMPLE_COUNT_1_BIT, .tiling = VK_IMAGE_TILING_OPTIMAL, + .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, /* the HDR encode pass writes it (frame generation) */ + .sharingMode = VK_SHARING_MODE_EXCLUSIVE, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + VkResult r = g_vk.CreateImage(g_dev, &ici, NULL, &g_scene.img); + if (r != VK_SUCCESS) { LOGE("effects: scene image %dx%d: vkCreateImage %s", w, h, vk_result_name(r)); g_scene.img = VK_NULL_HANDLE; return -1; } + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, g_scene.img, &req); + int idx = memory_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (idx < 0) idx = memory_type(req.memoryTypeBits, 0); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, + .memoryTypeIndex = (uint32_t)(idx < 0 ? 0 : idx)}; + r = g_vk.AllocateMemory(g_dev, &mai, NULL, &g_scene.mem); + if (r != VK_SUCCESS) { LOGE("effects: scene image %dx%d: vkAllocateMemory %s", w, h, vk_result_name(r)); destroy_scene_image(); return -1; } + g_vk.BindImageMemory(g_dev, g_scene.img, g_scene.mem, 0); + g_scene.w = w; g_scene.h = h; + banner_log("effects", "scene image %dx%d for the effect chain", w, h); + return 0; +} + +/* One of the HDR composition's device-local images at this size and format. 0 = ready. */ +static int ensure_img(struct vkp_img_slot *s, int w, int h, VkFormat fmt, VkImageUsageFlags usage, const char *what) { + if (s->img && s->w == w && s->h == h && s->fmt == fmt) return 0; + if (s->img) hdrc_forget_image(s->img); + if (s->img) g_vk.DestroyImage(g_dev, s->img, NULL); + if (s->mem) g_vk.FreeMemory(g_dev, s->mem, NULL); + memset(s, 0, sizeof(*s)); + VkImageCreateInfo ici = { + .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, .format = fmt, + .extent = {(uint32_t)w, (uint32_t)h, 1}, .mipLevels = 1, .arrayLayers = 1, .samples = VK_SAMPLE_COUNT_1_BIT, + .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = usage, .sharingMode = VK_SHARING_MODE_EXCLUSIVE, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED}; + VkResult r = g_vk.CreateImage(g_dev, &ici, NULL, &s->img); + if (r != VK_SUCCESS) { LOGE("color: %s image %dx%d: vkCreateImage %s", what, w, h, vk_result_name(r)); s->img = VK_NULL_HANDLE; return -1; } + VkMemoryRequirements req; + g_vk.GetImageMemoryRequirements(g_dev, s->img, &req); + int idx = memory_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (idx < 0) idx = memory_type(req.memoryTypeBits, 0); + VkMemoryAllocateInfo mai = {.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, .allocationSize = req.size, + .memoryTypeIndex = (uint32_t)(idx < 0 ? 0 : idx)}; + r = g_vk.AllocateMemory(g_dev, &mai, NULL, &s->mem); + if (r != VK_SUCCESS) { + LOGE("color: %s image %dx%d: vkAllocateMemory %s", what, w, h, vk_result_name(r)); + g_vk.DestroyImage(g_dev, s->img, NULL); + memset(s, 0, sizeof(*s)); + return -1; + } + g_vk.BindImageMemory(g_dev, s->img, s->mem, 0); + s->w = w; s->h = h; s->fmt = fmt; + char fname[24]; + vk_format_short(fmt, fname, sizeof(fname)); + banner_log("color", "%s image %dx%d (%s)", what, w, h, fname); + return 0; +} + +/* The HDR composition (hdr_compose.h): clear the mixed image, blit every draw into it 1:1 in its own + * encoding, then encode it into `out` (left in TRANSFER_DST_OPTIMAL). The caller has already taken the + * draws' images (queue-family acquire / host-write barriers). Which rectangles are HDR comes from + * hf->is_hdr: listed top draw first, down to the lowest HDR draw (everything under that is SDR). + * 0 = done, -1 = the HDR pass is unavailable (nothing was recorded into `out`). */ +static int compose_hdr(VkCommandBuffer cmd, const struct vkp_draw *draws, int n, const struct vkp_hdr_frame *hf, + int scene_w, int scene_h, VkImage out, VkFormat out_fmt, enum hdrc_mode mode) { + if (!hf || !hf->is_hdr || n <= 0) return -1; + if (ensure_img(&g_mixed, scene_w, scene_h, HDR_FMT, + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, + "HDR composition (mixed)") != 0) + return -1; + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + VkImageMemoryBarrier b = {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = g_mixed.img, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_SHADER_READ_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &b); + VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; + g_vk.CmdClearColorImage(cmd, g_mixed.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); + VkMemoryBarrier mb = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1, &mb, 0, NULL, 0, NULL); + + struct hdrc_params p = {.mode = mode, .sdr_white_nits = banner_color_sdr_white(), + .peak_nits = hf->peak_nits > 0.0f ? hf->peak_nits : 1000.0f}; + int lowest_hdr = -1; + for (int i = 0; i < n; i++) { + VkImageBlit blit; + if (!draws[i].img || !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit)) continue; + /* A blit converts UNORM to UNORM by value: 8-bit sRGB and 10-bit PQ both land unchanged. */ + g_vk.CmdBlitImage(cmd, draws[i].img->image, + draws[i].img->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + g_mixed.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_LINEAR); + if (hf->is_hdr[i] && lowest_hdr < 0) lowest_hdr = i; + } + static int truncated_said; + if (lowest_hdr >= 0) { + int i; + for (i = n - 1; i >= lowest_hdr && p.count < HDRC_MAX_RECTS; i--) { + VkImageBlit blit; + if (!draws[i].img || !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit)) continue; + p.rects[p.count][0] = (float)blit.dstOffsets[0].x; p.rects[p.count][1] = (float)blit.dstOffsets[0].y; + p.rects[p.count][2] = (float)blit.dstOffsets[1].x; p.rects[p.count][3] = (float)blit.dstOffsets[1].y; + if (hf->is_hdr[i]) p.hdr_mask |= 1u << p.count; + p.count++; + } + if (i >= lowest_hdr && !truncated_said) { + truncated_said = 1; + banner_log("color", "HDR composition: more than %d windows are stacked over the HDR game - the lowest " + "ones are treated as SDR", HDRC_MAX_RECTS); + } + } + return hdrc_encode(cmd, g_mixed.img, out, out_fmt, scene_w, scene_h, &p); +} + +/* VK_ERROR_DEVICE_LOST: nothing on this device works any more, and there is no way back short + * of a new session. Say so once and stop touching the swapchain; clients keep being paced by the + * compositor (see pace_without_output) so they don't wedge, they just aren't shown. */ +static void device_lost(const char *where) { + if (g_dev_state == -2) return; + g_dev_state = -2; + g_base_black = 0; + vkp_framegen_device_lost(); + banner_log("error", "GPU device lost (VK_ERROR_DEVICE_LOST in %s): the compositor has stopped presenting; " + "restart the session", where); + if (g_swapchain) g_vk.DestroySwapchainKHR(g_dev, g_swapchain, NULL); + g_swapchain = VK_NULL_HANDLE; + if (g_surface) g_vk.DestroySurfaceKHR(g_inst, g_surface, NULL); + g_surface = VK_NULL_HANDLE; + free(g_images); + g_images = NULL; + g_nimg = 0; +} + +static const char *vk_result_name(VkResult r) { + switch (r) { + case VK_ERROR_OUT_OF_DATE_KHR: return "OUT_OF_DATE"; + case VK_SUBOPTIMAL_KHR: return "SUBOPTIMAL"; + case VK_ERROR_SURFACE_LOST_KHR: return "SURFACE_LOST"; + case VK_ERROR_DEVICE_LOST: return "DEVICE_LOST"; + case VK_TIMEOUT: return "TIMEOUT"; + case VK_NOT_READY: return "NOT_READY"; + case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "OUT_OF_DEVICE_MEMORY"; + case VK_ERROR_OUT_OF_HOST_MEMORY: return "OUT_OF_HOST_MEMORY"; + case VK_ERROR_FORMAT_NOT_SUPPORTED: return "FORMAT_NOT_SUPPORTED"; + case VK_ERROR_INVALID_EXTERNAL_HANDLE: return "INVALID_EXTERNAL_HANDLE"; + case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT: return "INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT"; + default: { + static char other[24]; + snprintf(other, sizeof(other), "error %d", (int)r); + return other; + } + } +} + +/* ---------------------------------------------------------------- the compositor pass */ + +/* The mapping/blit stage for one present: clear the swapchain image to black (the letterbox), + * blit `src` (src_w x src_h, in GENERAL: the effects chain's result or a generated frame, either + * standing for the whole scene) through the scene -> output mapping, and leave the image ready + * to present. */ +static void record_screen_blit(VkCommandBuffer cmd, VkImage src, int src_w, int src_h, + int scene_w, int scene_h, uint32_t img, VkFilter filter) { + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + VkImageMemoryBarrier pre[2] = { + {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = g_images[img], .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}, + /* Whatever wrote src last (blits, the effects chain, a compute dispatch, in this or an + * earlier submission on this queue) must be visible to the blit's read. */ + {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_GENERAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = src, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 2, pre); + struct vkp_image tmp = {.w = src_w, .h = src_h}; /* only its size is looked at */ + struct vkp_draw d = {&tmp, 0, 0, (float)src_w, (float)src_h, 0, 0, scene_w, scene_h}; + VkImageBlit blit; + const int have_blit = draw_to_blit(&d, &blit); + /* The result fills its whole mapped rectangle, so only the letterbox bars around it need black. */ + if (!have_blit || !record_bars_clear(cmd, g_images[img], &blit)) { + VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; + g_vk.CmdClearColorImage(cmd, g_images[img], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); + } + VkMemoryBarrier mb = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 1, &mb, 0, NULL, 0, NULL); + if (have_blit) + g_vk.CmdBlitImage(cmd, src, VK_IMAGE_LAYOUT_GENERAL, g_images[img], + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, filter); + VkImageMemoryBarrier b_present = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_images[img], + .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &b_present); +} + +/* Acquire a swapchain image for present slot k. On the frame's FIRST acquire the swapchain is + * (re)created when needed and rebuilt once when the surface changed under us (OUT_OF_DATE after a + * resize/rotation, SURFACE_LOST when the window was torn down) - once, so a frame is not lost to + * a recreate that would have succeeded. Later slots have presents in flight on this swapchain, + * so they never rebuild; they fail and the frame ends early. 0 on success. */ +static int acquire_image(int k, int first, uint32_t *img, VkResult *ar_out) { + for (int attempt = 0; ; attempt++) { + if (!g_swapchain && (!first || swap_init() != 0)) return -1; + /* A bounded wait: a surface that went away without telling us must not park the + * compositor thread forever (clients are paced from this thread). */ + const int64_t t_acq = perf_now(); + VkResult ar = g_vk.AcquireNextImageKHR(g_dev, g_swapchain, 1000000000ULL, g_acqs[k], VK_NULL_HANDLE, img); + perf_add(&g_perf.acquire_ns, &g_perf.acquire_max_ns, &g_perf.acquires, perf_now() - t_acq); + if (ar == VK_SUCCESS || ar == VK_SUBOPTIMAL_KHR) { *ar_out = ar; return 0; } + if (ar == VK_ERROR_DEVICE_LOST) { device_lost("acquire"); return -1; } + if (ar == VK_ERROR_OUT_OF_DATE_KHR || ar == VK_ERROR_SURFACE_LOST_KHR) { + banner_log("gpu", "screen surface %s on acquire: rebuilding the swapchain", vk_result_name(ar)); + destroy_swapchain(); + if (first && attempt == 0) continue; + return -1; + } + banner_log("error", "present: acquire %d failed (%s %d)", k, vk_result_name(ar), (int)ar); + if (ar == VK_TIMEOUT || ar == VK_NOT_READY) return -1; + destroy_swapchain(); /* anything else: start over next frame */ + return -1; + } +} + +/* vkp_render_plain: the base surface's black frame with the compositor pass skipped (HDR game on its + * layer, compositor.c) - neither the effects chain nor frame generation runs, and so neither paces + * this loop with extra presents. */ +static int g_plain_frame; +int vkp_render_plain(int scene_w, int scene_h) { + g_plain_frame = 1; + int r = vkp_render(scene_w, scene_h, NULL, 0); + g_plain_frame = 0; + return r; +} + +/* A surface that changed size or transform under a swapchain nobody presents to (the base surface + * while the game is on its display layer) never reports OUT_OF_DATE, so ask it - at most every + * 100 ms, on the compositor thread - and tear the swapchain down when it no longer matches; the next + * frame rebuilds it (and, in layer mode, puts one black frame on it). */ +static void check_surface_changed(void) { + if (!g_swapchain || !g_surface || g_dev_state != 1) return; + const int64_t now = perf_now(); + if (now - g_surface_checked_ns < 100000000LL) return; + g_surface_checked_ns = now; + VkSurfaceCapabilitiesKHR caps; + if (g_vk.GetPhysicalDeviceSurfaceCapabilitiesKHR(g_pd, g_surface, &caps) != VK_SUCCESS) return; + if (caps.currentExtent.width == g_caps_extent.width && caps.currentExtent.height == g_caps_extent.height && + caps.currentTransform == g_surface_transform) + return; + banner_log("gpu", "screen surface changed (%ux%u -> %ux%u, transform %d -> %d): rebuilding the swapchain", + g_caps_extent.width, g_caps_extent.height, caps.currentExtent.width, caps.currentExtent.height, + (int)g_surface_transform, (int)caps.currentTransform); + destroy_swapchain(); +} + +int vkp_base_black(int scene_w, int scene_h) { + vkp_apply_window_request(); + check_surface_changed(); + if (g_base_black && g_swapchain && g_window && g_dev_state == 1) { + g_perf.base_kept++; + return 0; /* the black frame from before is still what the base surface shows */ + } + int r = vkp_render_plain(scene_w, scene_h); + if (r == 0) g_perf.base_presents++; + return r; +} + +void vkp_perf_take(struct vkp_perf *out) { + *out = g_perf; + memset(&g_perf, 0, sizeof(g_perf)); +} + +int vkp_can_wait_sync_fd(void) { return g_import_sem_fd != NULL && g_wait_sem != VK_NULL_HANDLE; } + +/* Hand a sync_file to the next submit as a GPU wait (temporary import into g_wait_sem; the driver + * owns the fd from then on). Returns 1 when the submit must wait on g_wait_sem, 0 when there is nothing + * to wait on - the fd was -1, or it could not be imported and was waited for on the CPU (bounded) and + * closed instead. -1 = the display is still reading the buffer after 100 ms: do not write it. */ +static int take_wait_fd(int fd) { + if (fd < 0) return 0; + if (vkp_can_wait_sync_fd()) { + VkImportSemaphoreFdInfoKHR ii = {.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR, + .semaphore = g_wait_sem, .flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, + .handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, .fd = fd}; + if (g_import_sem_fd(g_dev, &ii) == VK_SUCCESS) { + g_perf.gpu_release_waits++; + return 1; + } + static int said; + if (!said) { + said = 1; + banner_log("perf", "layer buffers: importing a release fence as a GPU wait failed; waiting for it on the CPU"); + } + } + struct pollfd p = {.fd = fd, .events = POLLIN}; + int r; + do { r = poll(&p, 1, 100); } while (r < 0 && errno == EINTR); + close(fd); + return r == 0 ? -1 : 0; +} + +/* The HDR10 swapchain's metadata: the game's SMPTE 2086 / CTA-861.3 values (its image description) via + * VK_EXT_hdr_metadata, once per swapchain and description. A game that gave none gets none. */ +static void send_hdr_metadata(const struct banner_color *c) { + static int said_none, said_nodesc; + if (!c) return; + if (!g_set_hdr_metadata) { + if (!said_none) { said_none = 1; banner_log("color", "HDR10 swapchain without the game's metadata: this device " + "has no VK_EXT_hdr_metadata (the display uses its defaults)"); } + return; + } + if (!c->has_st2086 && !c->has_cta861) { + if (said_nodesc != (int)c->identity) { + said_nodesc = (int)c->identity; + banner_log("color", "HDR10 swapchain: image description #%u carries no HDR metadata (the game sent none), " + "so none is set - the display uses its defaults", c->identity); + } + return; + } + VkHdrMetadataEXT md = {.sType = VK_STRUCTURE_TYPE_HDR_METADATA_EXT}; + if (c->has_st2086) { + md.displayPrimaryRed = (VkXYColorEXT){c->red[0], c->red[1]}; + md.displayPrimaryGreen = (VkXYColorEXT){c->green[0], c->green[1]}; + md.displayPrimaryBlue = (VkXYColorEXT){c->blue[0], c->blue[1]}; + md.whitePoint = (VkXYColorEXT){c->white[0], c->white[1]}; + md.maxLuminance = c->max_lum; + md.minLuminance = c->min_lum; + } + if (c->has_cta861) { + md.maxContentLightLevel = c->max_cll; + md.maxFrameAverageLightLevel = c->max_fall; + } + g_set_hdr_metadata(g_dev, 1, &g_swapchain, &md); + banner_log("color", "HDR10 swapchain: the game's metadata set via VK_EXT_hdr_metadata (image description #%u: %s)", + c->identity, c->text); +} + +/* The whole present: vkp_render (hf == NULL, exactly as it always was) and vkp_render_hdr (a scene with + * HDR draws: composed into one encoding, hdr_compose.h). */ +static int render_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *how) { + if (how) *how = 0; + vkp_apply_window_request(); + if (g_dev_state == -2) return -1; + if (dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1; + + /* Frame generation queues several presents per scene frame and needs swapchain images for + * them: rebuild when that changes (armed, disarmed, another multiplier). */ + if (g_swapchain && vkp_framegen_extra_images() != g_swap_extra) { + banner_log("gpu", "frame generation now wants %d present%s per frame: rebuilding the swapchain", + 1 + vkp_framegen_extra_images(), vkp_framegen_extra_images() ? "s" : ""); + destroy_swapchain(); + } + /* HDR frames presented here (frame generation with an HDR game) want an HDR10 swapchain - unless the + * drawer's HDR output switch is off (tone-mapped) - nothing else does. A change of that rebuilds the + * swapchain (only in HDR sessions: g_colorspace_ext). */ + const int want_hdr = hf && !hf->tonemap && g_colorspace_ext && !g_swap_hdr_unavailable; + if (g_swapchain && want_hdr != g_swap_is_hdr) { + banner_log("color", want_hdr ? "HDR frames with frame generation: rebuilding the screen swapchain as HDR10" + : hf ? "HDR output switched off: rebuilding the screen swapchain as SDR (frames tone-mapped)" + : "no HDR frames through the screen swapchain any more: rebuilding it as SDR"); + destroy_swapchain(); + } + g_swap_hdr_want = want_hdr; + + uint32_t img = 0; + VkResult ar; + if (acquire_image(0, 1, &img, &ar) != 0) return -1; + update_map(scene_w, scene_h); + /* A new HDR10 swapchain, or a new image description on it: hand the game's metadata over. */ + if (g_swap_is_hdr && hf && hf->color && hf->color->identity != g_swap_md_identity) { + g_swap_md_identity = hf->color->identity; + send_hdr_metadata(hf->color); + } + + /* The compositor pass - scene -> effects -> frame generation -> mapping/blit -> swapchain - + * composes the scene off-screen when either stage needs the whole frame: the screen-effect + * chain (effects_chain.c) or frame generation (framegen_bridge.c). With both off the draws are + * blitted straight through the mapping into the swapchain image, as they always were; only the + * blit filter follows the scaling mode. */ + const int fx = !g_plain_frame && vkp_effects_active(); + const int fg = !g_plain_frame && vkp_framegen_active(); + /* HDR frames with frame generation through an HDR10 swapchain: the scene, the effects and the + * engine's frames in FP16 (FG_HDR_FMT) where the engine can take that format - more than 8 bits of + * PQ through interpolation - else the 8-bit scene, as before. */ + const int deep = hf && n > 0 && fg && g_swap_is_hdr && !hf->tonemap && vkp_framegen_format_ok(FG_HDR_FMT) && + ensure_img(&g_fgscene, scene_w, scene_h, FG_HDR_FMT, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + "HDR frame generation (scene)") == 0; + { + static int said = -1; + if (fg && hf && g_swap_is_hdr && deep != said) { + said = deep; + char sw[24]; + vk_format_short(g_swap_fmt, sw, sizeof(sw)); + if (deep) + banner_log("color", "frame generation runs on the HDR picture in FP16 (RGBA16F): more than 8 bits of PQ " + "through interpolation, into the HDR10 swapchain (%s)", sw); + else + banner_log("color", "frame generation runs on the HDR picture in 8 bits (the engine cannot take FP16 here), " + "into the HDR10 swapchain (%s): banding possible in smooth gradients", sw); + } + } + /* An HDR scene always takes the pass: its draws are composed into one encoding first. */ + const int pass = deep || ((fx || fg || (hf && n > 0)) && ensure_scene_image(scene_w, scene_h) == 0); + VkImage scene_img = deep ? g_fgscene.img : g_scene.img; + const VkFormat scene_fmt = deep ? FG_HDR_FMT : SCENE_FMT; + const VkFilter blit_filter = vkp_effects_blit_filter(); + + VkCommandBuffer cmd = g_cmds[0]; + g_vk.ResetCommandBuffer(cmd, 0); + VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; + g_vk.BeginCommandBuffer(cmd, &bi); + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + /* Source images: take dmabufs from the client's queue family, move shm images to + * GENERAL once (host writes stay visible across frames: memory is coherent and each + * frame is a new submission). One barrier per distinct image. The destination joins them: + * the swapchain image on the direct path, the scene image on the compositor pass (the + * per-present blits transition the swapchain images themselves there). */ + VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars)); + int nb = 0; + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = pass ? scene_img : g_images[img], .subresourceRange = range, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + for (int i = 0; i < n; i++) { + struct vkp_image *im = draws[i].img; + int seen = 0; + for (int j = 0; j < i; j++) if (draws[j].img == im) { seen = 1; break; } + if (seen || !im) continue; + if (im->dmabuf) { + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, + .image = im->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + } else if (!im->in_general) { + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = im->image, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_HOST_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + im->in_general = 1; + } + } + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | + (pass ? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT : 0), + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, (uint32_t)nb, bars); + free(bars); + + /* Clear the composition target to black (the letterbox on the direct path, the desktop's + * background on the pass) before the draws land on it. A draw that covers the whole scene + * overwrites every pixel of its rectangle (blits never blend), so then only what lies outside it + * needs black: the letterbox bars on the direct path, nothing at all on the pass (the scene image + * is exactly the scene). Anything else - no such draw, the HDR composition - clears the whole + * target as before. */ + VkImage target = pass ? scene_img : g_images[img]; + int covered = 0; + VkImageBlit cover_blit; + if (!(hf && pass)) { + for (int i = n - 1; i >= 0 && !covered; i--) { + const struct vkp_draw *d = &draws[i]; + if (!d->img || d->dx > 0 || d->dy > 0 || d->dx + d->dw < scene_w || d->dy + d->dh < scene_h) continue; + covered = pass ? draw_to_scene_blit(d, scene_w, scene_h, &cover_blit) : draw_to_blit(d, &cover_blit); + } + } + const int cleared = covered && (pass || record_bars_clear(cmd, target, &cover_blit)); + if (!cleared) { + VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; + g_vk.CmdClearColorImage(cmd, target, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); + } + { + VkMemoryBarrier mb = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 1, &mb, 0, NULL, 0, NULL); + } + + /* 1. Scene: the draws in order, 1:1 into the scene image (pass) or mapped onto the output. An HDR + * scene is composed into ONE encoding instead (hdr_compose.h): PQ BT.2020 for an HDR10 + * swapchain, tone-mapped sRGB for an ordinary one; the scene image comes back in + * TRANSFER_DST_OPTIMAL like the blits leave it. If that pass is unavailable, the blits below. */ + int drawn = 0; + int hdr_how = 0; + if (hf && pass && n > 0 && + compose_hdr(cmd, draws, n, hf, scene_w, scene_h, scene_img, scene_fmt, + g_swap_is_hdr ? HDRC_OUT_PQ : HDRC_OUT_SDR) == 0) { + hdr_how = g_swap_is_hdr ? 1 : 2; + drawn = n; + } + for (int i = 0; i < n && !hdr_how; i++) { + VkImageBlit blit; + if (!draws[i].img) continue; + if (pass ? !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit) : !draw_to_blit(&draws[i], &blit)) continue; + g_vk.CmdBlitImage(cmd, draws[i].img->image, + draws[i].img->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + target, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, + pass ? VK_FILTER_LINEAR : blit_filter); + drawn++; + } + + int ngen = 0; + VkImage gens[VKP_FG_MAX_GENERATIONS] = {VK_NULL_HANDLE}; + VkImage result = scene_img; + int rw = scene_w, rh = scene_h; + if (!pass) { + VkImageMemoryBarrier b_present = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = g_images[img], + .subresourceRange = range, .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &b_present); + } else { + /* 2. Effects (the hook): scaling to the scene's mapped size, then the effects, in the X11 + * order. The result stands for the whole scene (rw x rh) and comes back in + * TRANSFER_SRC_OPTIMAL; with nothing on the scene stays as composited. */ + VkImageLayout result_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + if (fx) { + int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); + /* This path's scene is 8-bit. Set only where the chain really runs: a plain frame (the black + * base under an HDR picture) must not flip the chain's format back every frame. */ + vkp_effects_set_formats(scene_fmt, scene_fmt); + result = vkp_effects_run(cmd, scene_img, scene_w, scene_h, mapped_w, mapped_h, &rw, &rh); + result_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + } + /* Hand-off: from here the frame lives in GENERAL - the frame-generation engines copy and + * sample it there, and every screen blit reads it there. Whatever wrote it last (the + * composite blits or the chain's last pass) is made visible to both. */ + VkImageMemoryBarrier b_general = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = result_layout, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = result, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, 0, NULL, 0, NULL, 1, &b_general); + + /* 3. Frame generation (the hook): the result is frame N; the engine interpolates between + * N-1 and N and hands back the frames that belong in between. Shown first, N last. */ + if (fg) { + ngen = vkp_framegen_run(cmd, result, VK_NULL_HANDLE, rw, rh, scene_fmt, gens); + if (ngen < 0) ngen = 0; + if (ngen > VKP_FG_MAX_GENERATIONS) ngen = VKP_FG_MAX_GENERATIONS; + } + + /* 4. Mapping/blit: the first present carries generated frame 0, or the result itself. */ + record_screen_blit(cmd, ngen ? gens[0] : result, rw, rh, scene_w, scene_h, img, blit_filter); + } + g_vk.EndCommandBuffer(cmd); + + /* One submit + present per slot: generated frames first, the real frame last. The frame + * fence rides on the last submit (a fence signal is ordered after everything submitted + * earlier on the queue, so it still covers all of this frame's work). With FIFO the + * presentation engine shows them on consecutive vblanks: that IS the pacing, no sleeps. */ + const int presents = 1 + ngen; + int fence_submitted = 0, presented_gen = 0; + VkResult pr = VK_SUCCESS; + g_vk.ResetFences(g_dev, 1, &g_fence); + for (int k = 0; k < presents; k++) { + if (k > 0) { + VkResult ark; + if (acquire_image(k, 0, &img, &ark) != 0) { + banner_log("framegen", "present %d/%d: no swapchain image; the frame ends early", k + 1, presents); + pr = VK_ERROR_OUT_OF_DATE_KHR; + break; + } + if (ark == VK_SUBOPTIMAL_KHR) ar = ark; + VkCommandBuffer ck = g_cmds[k]; + g_vk.ResetCommandBuffer(ck, 0); + g_vk.BeginCommandBuffer(ck, &bi); + record_screen_blit(ck, k < ngen ? gens[k] : result, rw, rh, scene_w, scene_h, img, blit_filter); + g_vk.EndCommandBuffer(ck); + } + const int last = (k + 1 == presents); + VkPipelineStageFlags wait = VK_PIPELINE_STAGE_TRANSFER_BIT; + VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .waitSemaphoreCount = 1, + .pWaitSemaphores = &g_acqs[k], .pWaitDstStageMask = &wait, .commandBufferCount = 1, + .pCommandBuffers = &g_cmds[k], .signalSemaphoreCount = 1, .pSignalSemaphores = &g_rnds[k]}; + VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, last ? g_fence : VK_NULL_HANDLE); + if (qr != VK_SUCCESS) { + if (qr == VK_ERROR_DEVICE_LOST) device_lost("submit"); + else LOGE("present: submit %d/%d failed (%d)", k + 1, presents, (int)qr); + /* The acquired image is never presented; the swapchain would be stuck with it. */ + if (g_dev_state != -2) destroy_swapchain(); + return -1; + } + fence_submitted = last; + VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1, + .pWaitSemaphores = &g_rnds[k], .swapchainCount = 1, + .pSwapchains = &g_swapchain, .pImageIndices = &img}; + const int64_t t_pres = perf_now(); + pr = g_vk.QueuePresentKHR(g_queue, &pi); + perf_add(&g_perf.present_ns, &g_perf.present_max_ns, &g_perf.presents, perf_now() - t_pres); + if (k < ngen) presented_gen++; + if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR || pr == VK_ERROR_DEVICE_LOST) break; + } + if (!fence_submitted) { + /* Ended early: an empty submit carrying the fence is ordered after everything queued + * above, so the wait below still means "this frame's work is done". */ + VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO}; + g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + } + VkResult fr = timed_wait(g_fence, UINT64_MAX); + if (fg) vkp_framegen_presented(presented_gen); + if (fr == VK_ERROR_DEVICE_LOST || pr == VK_ERROR_DEVICE_LOST) { device_lost("present"); return -1; } + if (pr == VK_ERROR_OUT_OF_DATE_KHR || pr == VK_ERROR_SURFACE_LOST_KHR) { + /* The surface changed or went away under this frame: rebuild before the next one. */ + banner_log("gpu", "screen surface %s on present: rebuilding the swapchain", vk_result_name(pr)); + destroy_swapchain(); + return -1; + } else if (pr == VK_SUBOPTIMAL_KHR || ar == VK_SUBOPTIMAL_KHR) { + /* Expected and harmless here: the swapchain uses IDENTITY preTransform on purpose (see + * swap_init), so a rotated panel reports SUBOPTIMAL on every frame. Rebuilding would change + * nothing (and a rebuild per frame would be far worse), so present as is; say so once. */ + static int said; + if (!said) { said = 1; banner_log("gpu", "surface reports SUBOPTIMAL (panel rotation); presenting as is"); } + } else if (pr != VK_SUCCESS) { + banner_log("error", "present: vkQueuePresentKHR failed (%s %d)", vk_result_name(pr), (int)pr); + destroy_swapchain(); + return -1; + } + + /* What the base surface shows from now on: black only after a plain frame with nothing drawn + * (vkp_base_black keeps presenting nothing while that holds); anything else it presented is + * content, and the next layer frame must put a black frame back under the layers first. */ + g_base_black = (g_plain_frame && n == 0 && !hf) ? 1 : 0; + + /* Signal the app once, on the first real client frame reaching the screen, so the + * launch/preloader overlay can dismiss (wayland has no XServer window-content hook). */ + if (drawn && !g_first_frame_done) { + g_first_frame_done = 1; + banner_on_first_frame(); + } + if (how) *how = hdr_how; + return 0; +} + +int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n) { + return render_impl(scene_w, scene_h, draws, n, NULL, NULL); +} + +int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *how) { + return render_impl(scene_w, scene_h, draws, n, hf, how); +} + +/* ---------------------------------------------------------------- layer mode helpers */ + +/* Degrees the display rotates our layers by: 0, 90, 180 or 270; -1 before the swapchain exists. + * Read from the surface, so it follows the panel's install orientation and the session's own + * orientation together, on any device. */ +int vkp_surface_rotation_degrees(void) { + if (!g_surface_transform_known) return -1; + switch (g_surface_transform) { + case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR: return 90; + case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR: return 180; + case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR: return 270; + default: return 0; /* IDENTITY, and the mirrored forms we never see here */ + } +} + +ANativeWindow *vkp_window(void) { return g_window; } + +void vkp_signal_first_frame(void) { + if (g_first_frame_done) return; + g_first_frame_done = 1; + banner_on_first_frame(); +} + +int vkp_update_map(int scene_w, int scene_h) { + if (g_dev_state == -2 || dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1; + check_surface_changed(); /* layer mode may present nothing on the base surface for a long time */ + if (!g_swapchain && swap_init() != 0) return -1; + update_map(scene_w, scene_h); + return g_map.valid ? 0 : -1; +} + +int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]) { + struct vkp_image tmp = {.w = img_w, .h = img_h}; /* only its size is looked at */ + struct vkp_draw d = {&tmp, 0, 0, (float)img_w, (float)img_h, 0, 0, scene_w, scene_h}; + return vkp_map_draw(&d, out); +} + +int vkp_map_draw(const struct vkp_draw *d, int out[8]) { + VkImageBlit blit; + if (!d || !d->img || !g_map.valid || !draw_to_blit(d, &blit)) return 0; + out[0] = blit.srcOffsets[0].x; out[1] = blit.srcOffsets[0].y; + out[2] = blit.srcOffsets[1].x; out[3] = blit.srcOffsets[1].y; + out[4] = blit.dstOffsets[0].x; out[5] = blit.dstOffsets[0].y; + out[6] = blit.dstOffsets[1].x; out[7] = blit.dstOffsets[1].y; + return 1; +} + +/* Copy src (a client frame) into dst (a layer pool buffer) 1:1 and wait for it. Both images are + * owned by the "foreign" queue family (the game's driver / the display) between our uses, so each + * use acquires them and the destination is released back for the display to read. */ +int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd) { + if (!src || !dst || !dst->blit_dst || g_dev_state == -2 || dev_init() != 0) { + if (wait_fd >= 0) close(wait_fd); + return -1; + } + const int gpu_wait = take_wait_fd(wait_fd); /* the display's release of dst, before the copy writes it */ + if (gpu_wait < 0) return -1; + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + VkCommandBuffer g_cmd = g_cmds[0]; + g_vk.ResetCommandBuffer(g_cmd, 0); + VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; + g_vk.BeginCommandBuffer(g_cmd, &bi); + VkImageMemoryBarrier acq[2] = { + {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcQueueFamilyIndex = src->dmabuf ? VK_QUEUE_FAMILY_FOREIGN_EXT : VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = src->dmabuf ? g_qfam : VK_QUEUE_FAMILY_IGNORED, + .image = src->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}, + {.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, + .image = dst->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}}; + if (!src->dmabuf) { /* shm image: host-written, GENERAL */ + acq[0].oldLayout = src->in_general ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_PREINITIALIZED; + acq[0].newLayout = VK_IMAGE_LAYOUT_GENERAL; + acq[0].srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + src->in_general = 1; + } + g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 2, acq); + int bw = src->w < dst->w ? src->w : dst->w, bh = src->h < dst->h ? src->h : dst->h; + VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{0, 0, 0}, {bw, bh, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{0, 0, 0}, {bw, bh, 1}}}; + g_vk.CmdBlitImage(g_cmd, src->image, + src->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + dst->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); + VkImageMemoryBarrier rel = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(g_cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &rel); + g_vk.EndCommandBuffer(g_cmd); + + VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; + VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &g_cmd, + .waitSemaphoreCount = gpu_wait ? 1u : 0u, .pWaitSemaphores = gpu_wait ? &g_wait_sem : NULL, + .pWaitDstStageMask = gpu_wait ? &wait_stage : NULL}; + g_vk.ResetFences(g_dev, 1, &g_fence); + VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + if (qr != VK_SUCCESS) { + if (qr == VK_ERROR_DEVICE_LOST) device_lost("layer blit"); + else LOGE("layer: blit submit failed (%d)", (int)qr); + return -1; + } + VkResult fr = timed_wait(g_fence, 1000000000ULL); + if (fr == VK_ERROR_DEVICE_LOST) { device_lost("layer blit"); return -1; } + if (fr != VK_SUCCESS) { LOGE("layer: blit fence wait -> %s", vk_result_name(fr)); return -1; } + return 0; +} + +/* ---------------------------------------------------------------- the compositor pass, off-screen + * + * Layer mode with screen effects on: the game's frame still has to go through the compositor pass + * (scene image -> effects chain), but the RESULT does not have to end up in the app's swapchain - + * it is copied into a gralloc buffer and put on the game's own Android layer, so hardware + * composition stays alive while a Look is applied and the scene -> output mapping is done by the + * display (setGeometry) instead of a second full-screen GPU blit. + * + * The chain runs in its OWN submit, with no swapchain image acquired. That is deliberate and was + * measured: folding it into the submit that owns the acquired image (one command buffer, one + * present, which looks cheaper on paper) puts the whole 13-pass chain behind the acquire + * semaphore, i.e. behind a vblank - 72 fps instead of 111 fps on the Pocket FIT with Retro CRT at + * 1920x1080. The base surface's black frame is presented by the caller AFTER the layer + * transaction, so the layer never waits for a vblank either. + * + * Three steps because the chain's result size is only known once the chain has run, and the layer + * buffer is allocated from it: + * vkp_pass_begin() -> records composite + effects into the frame's command buffer + * vkp_pass_copy_to()-> appends the copy into the layer buffer, submits, waits + * vkp_pass_abort() -> drops it unsubmitted (no free layer buffer this frame) + * Frame generation is NOT run here: its extra frames need a present each, on consecutive vblanks, + * which one buffer per layer transaction cannot pace (see WAYLAND_RUNTIME.md). */ + +static struct { + int active; + VkImage result; /* in TRANSFER_SRC_OPTIMAL */ + int rw, rh; +} g_pass; + +static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh); + +int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh) { + return pass_begin_impl(scene_w, scene_h, draws, n, NULL, rw, rh); +} + +int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh) { + if (!hf) return -1; + return pass_begin_impl(scene_w, scene_h, draws, n, hf, rw, rh); +} + +/* The off-screen pass for a layer: the SDR one (hf == NULL: composite into the 8-bit scene image, the + * effects in 8-bit - unchanged) or the HDR one (the draws composed into one 10-bit PQ BT.2020 picture, + * the effects run on it in 10-bit). */ +static int pass_begin_impl(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh) { + if (g_pass.active) vkp_pass_abort(); + if (g_dev_state == -2 || dev_init() != 0 || !g_window || scene_w <= 0 || scene_h <= 0) return -1; + if (!g_swapchain && swap_init() != 0) return -1; /* the mapping is in output pixels */ + update_map(scene_w, scene_h); + if (!g_map.valid) return -1; + if (hf) { + if (ensure_img(&g_hdrscene, scene_w, scene_h, HDR_FMT, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, + "HDR composition (picture)") != 0) + return -1; + } else if (ensure_scene_image(scene_w, scene_h) != 0) return -1; + + VkCommandBuffer cmd = g_cmds[0]; + g_vk.ResetCommandBuffer(cmd, 0); + VkCommandBufferBeginInfo bi = {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, + .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT}; + g_vk.BeginCommandBuffer(cmd, &bi); + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + /* Same acquisition as vkp_render's compositor pass: the sources come from the client's queue + * family (dmabuf) or from a host write (shm), the scene image is the transfer destination. */ + VkImageMemoryBarrier *bars = calloc((size_t)n + 1, sizeof(*bars)); + if (!bars) { g_vk.EndCommandBuffer(cmd); return -1; } + int nb = 0; + VkImage scene_img = hf ? g_hdrscene.img : g_scene.img; + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = scene_img, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + for (int i = 0; i < n; i++) { + struct vkp_image *im = draws[i].img; + int seen = 0; + for (int j = 0; j < i; j++) if (draws[j].img == im) { seen = 1; break; } + if (seen || !im) continue; + if (im->dmabuf) { + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .dstQueueFamilyIndex = g_qfam, + .image = im->image, .subresourceRange = range, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + } else if (!im->in_general) { + bars[nb++] = (VkImageMemoryBarrier){ + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_PREINITIALIZED, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = im->image, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_HOST_WRITE_BIT, .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT}; + im->in_general = 1; + } + } + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, (uint32_t)nb, bars); + free(bars); + + if (hf) { + /* HDR: every draw into the mixed image, then ONE encoding into the 10-bit picture: PQ BT.2020, or + * tone-mapped sRGB while the drawer's HDR output switch is off. */ + if (compose_hdr(cmd, draws, n, hf, scene_w, scene_h, g_hdrscene.img, HDR_FMT, + hf->tonemap ? HDRC_OUT_SDR : HDRC_OUT_PQ) != 0) { + g_vk.EndCommandBuffer(cmd); /* never submitted; reset before its next use */ + return -1; + } + if (vkp_effects_active()) vkp_effects_set_formats(HDR_FMT, HDR_FMT); + } else { + VkClearColorValue black = {.float32 = {0.0f, 0.0f, 0.0f, 1.0f}}; + g_vk.CmdClearColorImage(cmd, g_scene.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); + VkMemoryBarrier mb = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 1, &mb, 0, NULL, 0, NULL); + for (int i = 0; i < n; i++) { + VkImageBlit blit; + if (!draws[i].img || !draw_to_scene_blit(&draws[i], scene_w, scene_h, &blit)) continue; + g_vk.CmdBlitImage(cmd, draws[i].img->image, + draws[i].img->dmabuf ? VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, + g_scene.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_LINEAR); + } + if (vkp_effects_active()) vkp_effects_set_formats(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM); + } + + int mapped_w = (int)(scene_w * g_map.kx + 0.5f), mapped_h = (int)(scene_h * g_map.ky + 0.5f); + g_pass.rw = scene_w; g_pass.rh = scene_h; + g_pass.result = vkp_effects_run(cmd, scene_img, scene_w, scene_h, mapped_w, mapped_h, + &g_pass.rw, &g_pass.rh); + g_pass.active = 1; + if (rw) *rw = g_pass.rw; + if (rh) *rh = g_pass.rh; + return 0; +} + +int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd) { + if (!g_pass.active) { if (wait_fd >= 0) close(wait_fd); return -1; } + g_pass.active = 0; + VkCommandBuffer cmd = g_cmds[0]; + if (!dst || !dst->blit_dst || g_dev_state == -2) { + if (wait_fd >= 0) close(wait_fd); + g_vk.EndCommandBuffer(cmd); + return -1; + } + const int gpu_wait = take_wait_fd(wait_fd); /* the display's release of dst, before the copy writes it */ + if (gpu_wait < 0) { g_vk.EndCommandBuffer(cmd); return -1; } /* never submitted; reset before its next use */ + VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; + + VkImageMemoryBarrier acq = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, + .dstQueueFamilyIndex = g_qfam, .image = dst->image, .subresourceRange = range, + .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, 0, NULL, 0, NULL, 1, &acq); + /* The result stands for the whole scene, and so does the layer buffer (the DPU maps it onto + * the output), so this is 1:1 whenever the buffer was allocated at the size begin() reported; + * a stale-sized buffer is resampled rather than shown wrong. */ + VkImageBlit blit = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .srcOffsets = {{0, 0, 0}, {g_pass.rw, g_pass.rh, 1}}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, + .dstOffsets = {{0, 0, 0}, {dst->w, dst->h, 1}}}; + g_vk.CmdBlitImage(cmd, g_pass.result, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst->image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, + (g_pass.rw == dst->w && g_pass.rh == dst->h) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR); + VkImageMemoryBarrier rel = { + .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + .newLayout = VK_IMAGE_LAYOUT_GENERAL, .srcQueueFamilyIndex = g_qfam, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT, .image = dst->image, .subresourceRange = range, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT}; + g_vk.CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, 0, NULL, 0, NULL, 1, &rel); + g_vk.EndCommandBuffer(cmd); + + VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_TRANSFER_BIT; + VkSubmitInfo si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .commandBufferCount = 1, .pCommandBuffers = &cmd, + .waitSemaphoreCount = gpu_wait ? 1u : 0u, .pWaitSemaphores = gpu_wait ? &g_wait_sem : NULL, + .pWaitDstStageMask = gpu_wait ? &wait_stage : NULL}; + g_vk.ResetFences(g_dev, 1, &g_fence); + VkResult qr = g_vk.QueueSubmit(g_queue, 1, &si, g_fence); + if (qr != VK_SUCCESS) { + if (qr == VK_ERROR_DEVICE_LOST) device_lost("layer pass"); + else LOGE("layer: effects pass submit failed (%d)", (int)qr); + return -1; + } + VkResult fr = timed_wait(g_fence, 1000000000ULL); + if (fr == VK_ERROR_DEVICE_LOST) { device_lost("layer pass"); return -1; } + if (fr != VK_SUCCESS) { LOGE("layer: effects pass fence wait -> %s", vk_result_name(fr)); return -1; } + return 0; +} + +void vkp_pass_abort(void) { + if (!g_pass.active) return; + g_pass.active = 0; + g_vk.EndCommandBuffer(g_cmds[0]); /* never submitted; the buffer is reset before its next use */ +} diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h new file mode 100644 index 0000000000..89fbc617f8 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -0,0 +1,185 @@ +#ifndef VK_PRESENT_H +#define VK_PRESENT_H +#include <stdint.h> +#include <android/native_window.h> +/* + * Android-surface render backend for the embedded Wayland compositor. + * Owns a Turnip VkDevice + a swapchain on the SurfaceView's ANativeWindow. Each + * client buffer becomes an image (a dmabuf from winewayland's Vulkan WSI is + * imported zero-copy; a wl_shm buffer is copied into a host-visible image), and + * every frame blits the whole scene — desktop, windows, subsurfaces — in order. + */ + +// Set the Turnip driver to load (adrenotools). Call before the first frame. +// NULL args -> the backend falls back to the system libvulkan (dmabuf import will +// likely fail — Adreno lacks drm_format_modifier). driver_path ends with '/'. +void vk_present_set_driver(const char *driver_path, const char *library_name, + const char *native_lib_dir); + +// Set/replace the output window (from Surface via ANativeWindow_fromSurface; the backend +// owns the reference from then on). NULL = the surface is gone. Callable from any thread +// and never blocks: the request is applied by the compositor thread (vkp_render / +// vkp_apply_window_request), which tears the old swapchain down and releases the old window. +void vk_present_set_window(ANativeWindow *window); +/* Compositor thread: apply a pending window change now. Returns 1 if the window changed. */ +int vkp_apply_window_request(void); + +/* How the scene is mapped onto the output (the app's Container.FULLSCREEN_* / ALIGN_* values, + * mirrored 1:1 from ViewTransformation.java so touch input, which is mapped by the app with + * that class, lands on the same pixels). Callable from any thread, applies on the next frame. */ +enum vkp_scale_mode { VKP_MODE_OFF = 0, VKP_MODE_FIT = 1, VKP_MODE_STRETCH = 2, VKP_MODE_FILL = 3, + VKP_MODE_INTEGER = 4 }; +enum vkp_align { VKP_ALIGN_CENTER = 0, VKP_ALIGN_TOP = 1, VKP_ALIGN_BOTTOM = 2 }; +void vk_present_set_scale_mode(int mode, int alignment); +/* Output pixel (0..output size) -> scene pixel through the current mapping (compositor thread). + * Returns 0 before the first frame has established a mapping (sx/sy untouched). */ +int vkp_output_to_scene(double ox, double oy, double *sx, double *sy); +/* Output size in pixels (0x0 before the first swapchain). */ +void vkp_output_size(int *w, int *h); + +struct vkp_image; + +/* DRM format modifiers this backend knows the memory layout of (both single-plane on Adreno): + * LINEAR, and QCOM_COMPRESSED = UBWC (drm_fourcc.h: fourcc_mod_code(QCOM = 0x05, 1)). */ +#define VKP_MOD_LINEAR 0x0000000000000000ULL +#define VKP_MOD_QCOM_COMPRESSED 0x0500000000000001ULL +#define VKP_MOD_INVALID 0x00ffffffffffffffULL +/* "linear", "qcom_compressed", or "modifier 0x…" for anything else (static buffer). */ +const char *vkp_modifier_name(uint64_t modifier); +/* The modifiers a dma-buf of this DRM fourcc can be imported with as a blit source, asked of the + * renderer's own driver (VkDrmFormatModifierPropertiesListEXT, each confirmed for a dma-buf-backed + * TRANSFER_SRC image with vkGetPhysicalDeviceImageFormatProperties2). Only LINEAR and + * QCOM_COMPRESSED are ever returned (the ones this file can describe a plane layout for); other + * modifiers the driver reports are logged once. Returns the count, 0 when the device is not up + * (LINEAR is then the only safe assumption). Compositor thread. */ +int vkp_dmabuf_modifiers(uint32_t drm_format, uint64_t *out, int max); + +// Import a dmabuf (single plane). NULL on failure. The image aliases the buffer, so +// later client frames rendered into the same buffer show up without re-importing. +struct vkp_image *vkp_image_from_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, + int w, int h, uint32_t stride, uint32_t offset); +// Same, choosing the role: as_blit_dst = 0 imports a client frame (blit source), 1 imports a +// buffer this backend blits INTO (layer mode's AHardwareBuffer pool, see sc_layer.h). +struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, + int w, int h, uint32_t stride, uint32_t offset, + int as_blit_dst); +int vkp_image_is_dmabuf(const struct vkp_image *img); + +// Create a host-visible image and copy BGRA/XRGB8888 pixels into it. NULL on failure. +struct vkp_image *vkp_image_create_shm(int w, int h); +void vkp_image_upload_shm(struct vkp_image *img, const void *data, int stride); + +int vkp_image_width(const struct vkp_image *img); +int vkp_image_height(const struct vkp_image *img); +void vkp_image_destroy(struct vkp_image *img); + +// One scene draw: the src rectangle of an image (image pixels) scaled into the dst +// rectangle (scene pixels). The scene is mapped onto the output by the scale mode. +struct vkp_draw { + struct vkp_image *img; + float sx, sy, sw, sh; + int dx, dy, dw, dh; +}; + +// The GPU the renderer runs on ("Adreno (TM) 750"), empty before the device is up. +const char *vkp_gpu_name(void); + +// 0 if the renderer can create images (device up), -1 otherwise. +int vkp_ready(void); +/* Whether an output window is attached (or requested); without one vkp_render() draws nothing. */ +int vkp_has_window(void); +/* 1 once the Vulkan device was lost: nothing is presented any more (the session must restart). */ +int vkp_device_lost(void); + +// Clear to black, blit the draws in order (first = bottom) and present. +// Returns 0 on success, -1 if nothing could be presented (no window yet, etc.). +int vkp_render(int scene_w, int scene_h, const struct vkp_draw *draws, int n); +/* A black frame with no compositor pass (no effects, no frame generation), whatever is armed: the + * base surface under an HDR game that keeps its display layer (compositor.c). */ +int vkp_render_plain(int scene_w, int scene_h); +/* Layer mode's base surface: make sure it shows a plain black frame under the display layers. A frame + * is presented only when the base is not already black on the current swapchain (entering layer mode, + * after a copy-path / frame-generation frame, after a swapchain rebuild); otherwise nothing is drawn + * or presented at all. 0 = the base is black, -1 = no output. Compositor thread. */ +int vkp_base_black(int scene_w, int scene_h); + +/* ---- perf counters (the 10 s `perf` line, compositor.c) ---- + * Everything the compositor thread spends in the driver, since the last vkp_perf_take(). Times in ns. */ +struct vkp_perf { + unsigned acquires, presents, waits; + int64_t acquire_ns, acquire_max_ns; /* vkAcquireNextImageKHR */ + int64_t present_ns, present_max_ns; /* vkQueuePresentKHR */ + int64_t wait_ns, wait_max_ns; /* vkWaitForFences on the compositor's own work */ + unsigned base_presents; /* black frames presented under the display layers */ + unsigned base_kept; /* layer frames that kept the black frame already there */ + unsigned gpu_release_waits; /* layer-buffer release fences waited for on the GPU */ +}; +void vkp_perf_take(struct vkp_perf *out); +/* 1 when a release fence (sync_file) can be handed to the GPU as a wait (VK_KHR_external_semaphore_fd): + * the layer pool then reuses a buffer the display is still reading without blocking on the CPU. */ +int vkp_can_wait_sync_fd(void); + +/* ---- HDR composition (hdr_compose.h) ---- + * An HDR game that cannot be alone on its display layer: the scene is composed into ONE encoding. */ +struct banner_color; +struct vkp_hdr_frame { + const unsigned char *is_hdr; /* per draw: 1 = its image holds PQ BT.2020 (the surface's description) */ + float peak_nits; /* the HDR content's peak, for a tone-map (max CLL / mastering max; 0 = 1000) */ + int tonemap; /* 1 = the drawer's HDR output switch is off: tone-map to SDR, never PQ */ + const struct banner_color *color; /* the topmost HDR draw's description: an HDR10 swapchain's metadata */ +}; +/* vkp_render for a scene with HDR draws (frame generation): composed into PQ and presented through an + * HDR10 swapchain where the surface offers one (and hf->tonemap is 0), else tone-mapped into the ordinary + * one. *how = 1 HDR10, 2 tone-mapped, 0 the HDR pass was unavailable (shown the old way). Same return as + * vkp_render. */ +int vkp_render_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *how); +/* vkp_pass_begin for a scene with HDR draws: composed into a 10-bit picture - PQ BT.2020, or sRGB + * tone-mapped when hf->tonemap - the effects run on it in 10-bit, the result (rw x rh, A2B10G10R10) is + * left for vkp_pass_copy_to() into a layer buffer (a blit: 10-bit or 8-bit). -1 = not possible (nothing + * recorded). */ +int vkp_pass_begin_hdr(int scene_w, int scene_h, const struct vkp_draw *draws, int n, + const struct vkp_hdr_frame *hf, int *rw, int *rh); + +/* ---- layer mode helpers (sc_layer.c; compositor thread) ---- */ +/* Whole-image copy of src into dst (a blit-destination dmabuf image), waited for on the CPU. + * wait_fd: a sync_file the copy must wait for before writing dst (the display's release fence of that + * buffer), -1 = none. Always consumed (handed to the GPU, or waited for and closed). */ +int vkp_blit_image(struct vkp_image *src, struct vkp_image *dst, int wait_fd); +/* Refresh the scene -> output mapping for this scene size without presenting (creates the + * swapchain if needed, since the mapping is in output pixels). 0 = mapping valid. */ +int vkp_update_map(int scene_w, int scene_h); +/* Map a draw through the current mapping: out = {src x0,y0,x1,y1 (image px), dst x0,y0,x1,y1 + * (output px)}, clipped like the blit path. 0 = nothing of it is visible. */ +int vkp_map_draw(const struct vkp_draw *d, int out[8]); +/* The same for a bare w x h buffer shown over the whole scene (no vkp_image: zero-copy layers). */ +int vkp_map_rect(int img_w, int img_h, int scene_w, int scene_h, int out[8]); +/* The output window frames go to (NULL = none); compositor thread. */ +/* Degrees the display rotates every layer we present by (0/90/180/270), -1 before the swapchain + * exists. From VkSurfaceCapabilitiesKHR::currentTransform, i.e. what the presentation engine says + * it does — never a device allowlist. The layer path uses it to decide whether a SECOND display + * layer is affordable on this display (sc_layer_present_overlay). */ +int vkp_surface_rotation_degrees(void); + +ANativeWindow *vkp_window(void); +/* Fire the one-shot first-frame notification (layer mode presents outside vkp_render). */ +void vkp_signal_first_frame(void); + +/* ---- the compositor pass into a layer buffer (sc_layer.c; compositor thread) ---- + * Screen effects on the game's own Android layer: compose `draws` into the scene image and run the + * effects chain WITHOUT presenting, then copy the result into a gralloc layer buffer. Three steps + * because the chain's result size (a scaling mode resizes to the scene's mapped output size) is + * only known once the chain has run, and the layer buffer is allocated from it. + * begin: 0 = a pass is in progress, its result is *rw x *rh; -1 = not possible (draw the old way). + * Exactly one of copy_to (blit into dst, submit, wait; 0 = done) / abort (drop it unsubmitted) + * must follow a successful begin. The chain deliberately runs with NO swapchain image acquired - + * see the comment in vk_present.c. Frame generation is not run here (see WAYLAND_RUNTIME.md). */ +int vkp_pass_begin(int scene_w, int scene_h, const struct vkp_draw *draws, int n, int *rw, int *rh); +/* wait_fd: as for vkp_blit_image (consumed in every case). */ +int vkp_pass_copy_to(struct vkp_image *dst, int wait_fd); +void vkp_pass_abort(void); + +// Session log (compositor.c): one line to Download/Wayland-logs and logcat. +void banner_log(const char *tag, const char *fmt, ...) __attribute__((format(printf, 2, 3))); + +#endif diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c new file mode 100644 index 0000000000..fca8eac5d9 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -0,0 +1,632 @@ +/* + * JNI entry for the embedded Wayland compositor (experimental parallel runtime). + * Starts the compositor on a dedicated thread (it blocks in the wl event loop). + * The render-to-Surface backend + input are added in the M4 phase; this brings up + * the server so a Wayland client (eventually winewayland.drv) can connect. + */ +#include <jni.h> +#include <errno.h> +#include <stdint.h> +#include <pthread.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/resource.h> +#include <android/log.h> +#include <android/native_window_jni.h> +#include "vk_present.h" +#include "banner_ext.h" +#include "ahb_swapchain.h" +#include "sc_layer.h" +#include "effects_chain.h" +#include "banner_color.h" + +extern int banner_wayland_run(void); +extern void banner_wayland_send_pointer(int action, int x, int y); +extern void banner_wayland_send_key(int evdev, int state); +extern void banner_wayland_send_scene_input(int type, int a, int b); +extern void banner_wayland_vsync(int64_t frame_time_ns); +extern volatile int g_fps_limit; +extern volatile int g_hide_shell; +extern volatile int g_zero_copy; +extern volatile unsigned g_zero_copy_last; +extern volatile int g_ubwc; +extern volatile int g_no_render_node; +extern volatile int g_output_refresh_mhz; +extern volatile int g_output_w, g_output_h; + +#define TAG "BannerWayland" + +static JavaVM *g_jvm; +static jclass g_compositor_cls; /* global ref */ +static jmethodID g_on_first_frame; /* static void onFirstFramePresented() */ +static jmethodID g_on_game_surface; /* static void onGameSurface(String, String) */ +static jmethodID g_on_game_frame; /* static void onGameFrame() */ +static jmethodID g_on_game_program; /* static void onGameProgram(int, String) */ +static jmethodID g_on_pointer_lock; /* static void onPointerLock(boolean, int, int) */ +static jmethodID g_on_clipboard; /* static void onClipboardText(byte[]) */ +static jmethodID g_on_text_input; /* static void onTextInput(boolean, String, int, int, int, int) */ + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + (void)reserved; + g_jvm = vm; + JNIEnv *env; + if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_6) == JNI_OK) { + jclass c = (*env)->FindClass(env, "com/the412banner/steamdeck/wayland/WaylandCompositor"); + if (c) { + g_compositor_cls = (*env)->NewGlobalRef(env, c); + g_on_first_frame = (*env)->GetStaticMethodID(env, g_compositor_cls, + "onFirstFramePresented", "()V"); + g_on_game_surface = (*env)->GetStaticMethodID(env, g_compositor_cls, "onGameSurface", + "(Ljava/lang/String;Ljava/lang/String;)V"); + g_on_game_frame = (*env)->GetStaticMethodID(env, g_compositor_cls, "onGameFrame", "()V"); + g_on_game_program = (*env)->GetStaticMethodID(env, g_compositor_cls, "onGameProgram", + "(ILjava/lang/String;)V"); + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); g_on_game_program = NULL; } + g_on_pointer_lock = (*env)->GetStaticMethodID(env, g_compositor_cls, "onPointerLock", "(ZII)V"); + g_on_clipboard = (*env)->GetStaticMethodID(env, g_compositor_cls, "onClipboardText", "([B)V"); + g_on_text_input = (*env)->GetStaticMethodID(env, g_compositor_cls, "onTextInput", + "(ZLjava/lang/String;IIII)V"); + } + } + return JNI_VERSION_1_6; +} + +/* Called from vk_present.c on the compositor thread when the first client frame is + * presented. Attaches to the JVM (this thread is a bare pthread) and calls back into + * Java so the launch overlay can dismiss. Fires exactly once. */ +void banner_on_first_frame(void) { + if (!g_jvm || !g_compositor_cls || !g_on_first_frame) return; + JNIEnv *env = NULL; + int attached = 0; + if ((*g_jvm)->GetEnv(g_jvm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) { + if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL) != JNI_OK) return; + attached = 1; + } + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_first_frame); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); + if (attached) (*g_jvm)->DetachCurrentThread(g_jvm); + __android_log_print(ANDROID_LOG_INFO, TAG, "first client frame presented -> notified app"); +} + +/* The compositor thread stays attached once it first calls into Java: the HUD gets an upcall + * for every game frame. */ +static __thread JNIEnv *t_env; +static __thread int t_attached; + +static JNIEnv *thread_env(void) { + if (t_env) return t_env; + if (!g_jvm) return NULL; + JNIEnv *env = NULL; + if ((*g_jvm)->GetEnv(g_jvm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) { + if ((*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL) != JNI_OK) return NULL; + t_attached = 1; + } + return t_env = env; +} + +/* A window started presenting GPU frames (window = its description), or NULL when it closed. */ +void banner_on_game_surface(const char *window, const char *gpu) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_game_surface || !(env = thread_env())) return; + jstring jw = window ? (*env)->NewStringUTF(env, window) : NULL; + jstring jg = gpu ? (*env)->NewStringUTF(env, gpu) : NULL; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_game_surface, jw, jg); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); + if (jw) (*env)->DeleteLocalRef(env, jw); + if (jg) (*env)->DeleteLocalRef(env, jg); +} + +/* The program behind the game window that just started presenting: its Linux pid and executable name + * ("" = unknown). The app arms its launch-time CPU affinity on it. Compositor thread. */ +void banner_on_game_program(int pid, const char *program) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_game_program || !(env = thread_env())) return; + jstring jp = (*env)->NewStringUTF(env, program ? program : ""); + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_game_program, (jint)pid, jp); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); + if (jp) (*env)->DeleteLocalRef(env, jp); +} + +/* One GPU frame from that window. */ +void banner_on_game_frame(void) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_game_frame || !(env = thread_env())) return; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_game_frame); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); +} + +/* A program locked the pointer (locked = 1; the app's input path switches to deltas) or the lock + * ended (locked = 0; x,y = where the pointer is now, in scene coordinates, for the app to re-sync + * its own pointer to). Compositor thread. */ +void banner_on_pointer_lock(int locked, int x, int y) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_pointer_lock || !(env = thread_env())) return; + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_pointer_lock, (jboolean)(locked != 0), (jint)x, (jint)y); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); +} + +/* A program copied text (UTF-8, not NUL-terminated for the app's sake — a byte[] so emoji and + * NULs survive JNI). Compositor thread. */ +void banner_on_clipboard_text(const char *utf8, int len) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_clipboard || !(env = thread_env())) return; + jbyteArray arr = (*env)->NewByteArray(env, len); + if (!arr) { (*env)->ExceptionClear(env); return; } + (*env)->SetByteArrayRegion(env, arr, 0, len, (const jbyte *)utf8); + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_clipboard, arr); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); + (*env)->DeleteLocalRef(env, arr); +} + +/* A program started (enabled) or stopped accepting IME text; x,y,w,h = its caret rectangle in + * scene pixels (all 0 = unknown). Compositor thread. */ +void banner_on_text_input(int enabled, const char *program, int x, int y, int w, int h) { + JNIEnv *env; + if (!g_compositor_cls || !g_on_text_input || !(env = thread_env())) return; + jstring jp = (*env)->NewStringUTF(env, program ? program : ""); + (*env)->CallStaticVoidMethod(env, g_compositor_cls, g_on_text_input, (jboolean)(enabled != 0), jp, + (jint)x, (jint)y, (jint)w, (jint)h); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); + if (jp) (*env)->DeleteLocalRef(env, jp); +} + +/* android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY: the level the hwui RenderThread runs at. */ +#define COMPOSITOR_NICE (-8) + +static void *comp_thread(void *arg) { + (void)arg; + __android_log_print(ANDROID_LOG_INFO, TAG, "compositor thread starting"); + /* Every buffer release, frame callback and layer transaction of the session goes through this one + * thread. It is named, so `ps -T`, the logs and the drawer's Thread Priority Boost (PerfPriority + * matches thread names) can find it, and it runs at display priority instead of whatever the + * thread that started it had. Never lowered: a thread that already runs hotter keeps its value. */ + pthread_setname_np(pthread_self(), "wl-compositor"); + const id_t tid = (id_t)gettid(); + errno = 0; + const int before = getpriority(PRIO_PROCESS, tid); + int refused = 0; + if (before > COMPOSITOR_NICE && setpriority(PRIO_PROCESS, tid, COMPOSITOR_NICE) != 0) refused = errno ? errno : -1; + const int after = getpriority(PRIO_PROCESS, tid); + if (refused) + banner_log("perf", "compositor thread %d \"wl-compositor\": stays at nice %d, a higher priority was refused (%s)", + (int)tid, after, refused > 0 ? strerror(refused) : "?"); + else + banner_log("perf", "compositor thread %d \"wl-compositor\": nice %d -> %d", (int)tid, before, after); + banner_wayland_run(); + __android_log_print(ANDROID_LOG_INFO, TAG, "compositor thread exited"); + if (t_attached) (*g_jvm)->DetachCurrentThread(g_jvm); + t_env = NULL; t_attached = 0; + return NULL; +} + +static void set_runtime_dir(JNIEnv *env, jstring xdgRuntimeDir) { + if (!xdgRuntimeDir) return; + const char *dir = (*env)->GetStringUTFChars(env, xdgRuntimeDir, NULL); + if (dir) { + setenv("XDG_RUNTIME_DIR", dir, 1); + (*env)->ReleaseStringUTFChars(env, xdgRuntimeDir, dir); + } +} + +static void start_thread(void) { + pthread_t t; + if (pthread_create(&t, NULL, comp_thread, NULL) == 0) + pthread_detach(t); + else + __android_log_print(ANDROID_LOG_ERROR, TAG, "pthread_create failed"); +} + +/* Headless start (no output window) — used for bring-up tests. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeStart(JNIEnv *env, jclass clazz, + jstring xdgRuntimeDir) { + set_runtime_dir(env, xdgRuntimeDir); + start_thread(); +} + +static char *dup_jstr(JNIEnv *env, jstring s) { + if (!s) return NULL; + const char *c = (*env)->GetStringUTFChars(env, s, NULL); + char *out = c ? strdup(c) : NULL; + if (c) (*env)->ReleaseStringUTFChars(env, s, c); + return out; +} + +/* Start with a real output Surface + the container's Turnip driver (adrenotools). + * Frames committed by clients are composited to this Surface via Turnip. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeStartWithSurface( + JNIEnv *env, jclass clazz, jobject surface, jstring xdgRuntimeDir, + jstring driverPath, jstring libraryName, jstring nativeLibDir) { + set_runtime_dir(env, xdgRuntimeDir); + char *dp = dup_jstr(env, driverPath); + char *ln = dup_jstr(env, libraryName); + char *nl = dup_jstr(env, nativeLibDir); + vk_present_set_driver(dp, ln, nl); + free(dp); free(ln); free(nl); + if (surface) { + ANativeWindow *win = ANativeWindow_fromSurface(env, surface); + vk_present_set_window(win); /* backend acquires; released on nativeSetSurface(null) */ + __android_log_print(ANDROID_LOG_INFO, TAG, "output window bound (%p)", (void *)win); + } + start_thread(); +} + +/* Inject a pointer event from the Android SurfaceView touch listener (UI thread). + * action: 0=down 1=move 2=up; x/y in output space (0..1919, 0..1079). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSendPointer( + JNIEnv *env, jclass clazz, jint action, jint x, jint y) { + banner_wayland_send_pointer(action, x, y); +} + +/* Inject a key event. evdev = Linux input keycode (KEY_A=30…); state 1=down 0=up. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSendKey( + JNIEnv *env, jclass clazz, jint evdev, jint state) { + banner_wayland_send_key(evdev, state); +} + +/* App X-server input in scene (virtual desktop) coordinates; see banner_wayland_send_scene_input. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSendSceneInput( + JNIEnv *env, jclass clazz, jint type, jint a, jint b) { + banner_wayland_send_scene_input(type, a, b); +} + +/* One screen refresh (Choreographer frame callback, UI thread): the compositor draws once. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeVsync(JNIEnv *env, jclass clazz, jlong frameTimeNanos) { + banner_wayland_vsync((int64_t)frameTimeNanos); +} + +/* Shortcut launches: don't draw explorer's windows (desktop, taskbar), like X11's unviewable classes. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHideShell(JNIEnv *env, jclass clazz, jboolean hide) { + g_hide_shell = hide ? 1 : 0; +} + +/* Zero-copy layer mode (BANNER_WAYLAND_ZERO_COPY=1 at launch, the drawer's switch live): one fullscreen + * window on its own Android layer instead of the swapchain blit (sc_layer.c / ahb_swapchain.c). Any + * thread, any time: before the compositor starts it is the launch default; afterwards the compositor + * thread flips the state, tells the bound games to rebuild their swapchains for it and redraws. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetZeroCopy(JNIEnv *env, jclass clazz, jboolean on) { + int live = banner_get_display() != NULL; + if (!live) g_zero_copy = on ? 1 : 0; /* read by ahb_swapchain_init before the queue drains */ + banner_host_zero_copy(on ? 1 : 0, live); + __android_log_print(ANDROID_LOG_INFO, TAG, "zero-copy layer mode %s%s", on ? "on" : "off", live ? " (live)" : ""); +} + +/* Milliseconds since the compositor last put a game frame on the layer without a copy; -1 = never + * this session. The drawer's status line ("switching..." until the frames arrive / stop). */ +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeZeroCopyLastFrameAgeMs(JNIEnv *env, jclass clazz) { + return (jint)ahb_swapchain_last_frame_age_ms(); +} + +/* Zero-copy frames in the last completed 10 s stats window (on_stats_timer), for the drawer's live line. */ +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeZeroCopyFrames(JNIEnv *env, jclass clazz) { + return (jint)g_zero_copy_last; +} + +/* Compressed (UBWC) game buffers: advertise DRM_FORMAT_MOD_QCOM_COMPRESSED on zwp_linux_dmabuf_v1 when + * the renderer's driver imports it (default on; BANNER_WAYLAND_UBWC=0 = off). Set before the compositor + * starts. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetUbwc(JNIEnv *env, jclass clazz, jboolean on) { + g_ubwc = on ? 1 : 0; + __android_log_print(ANDROID_LOG_INFO, TAG, "compressed (UBWC) game buffers %s", on ? "on" : "off"); +} + +/* Debug: name no DRM device in the dma-buf feedback (BANNER_WAYLAND_NO_RENDER_NODE=1), the way a + * phone that exposes no /dev/dri node to apps does. Set before the compositor starts. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetNoRenderNode(JNIEnv *env, jclass clazz, jboolean on) { + g_no_render_node = on ? 1 : 0; + if (on) __android_log_print(ANDROID_LOG_INFO, TAG, "debug: advertising no DRM device (main device 0:0)"); +} + +/* VRR / refresh-rate matching: the rate the app is voting for the panel, mirrored onto the game's + * own SurfaceControl layer. Under zero-copy the game's frames bypass the app's surface entirely, so + * without this SurfaceFlinger never sees the game's cadence. 0 = clear the vote. Any thread, any + * time; the compositor applies it with its next layer transaction and logs the change. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetLayerFrameRate(JNIEnv *env, jclass clazz, jfloat hz) { + (void)env; (void)clazz; + sc_layer_set_frame_rate((float)hz); +} + +/* The panel's refresh rate (Hz) for the advertised wl_output mode. Set before the compositor starts. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetOutputRefreshRate(JNIEnv *env, jclass clazz, jfloat hz) { + g_output_refresh_mhz = hz > 1.0f ? (int)(hz * 1000.0f + 0.5f) : 0; +} + +/* The container's screen size for the advertised wl_output mode. Set before the compositor starts. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetOutputSize(JNIEnv *env, jclass clazz, jint w, jint h) { + g_output_w = w > 0 ? w : 0; + g_output_h = h > 0 ? h : 0; +} + +/* Fullscreen mode + screen alignment (Container.FULLSCREEN_* / ALIGN_* values): how the scene is + * fitted onto the output. Any thread, any time; the next frame uses it. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetScaleMode(JNIEnv *env, jclass clazz, jint mode, jint alignment) { + vk_present_set_scale_mode(mode, alignment); + __android_log_print(ANDROID_LOG_INFO, TAG, "scale mode %d alignment %d", mode, alignment); +} + +/* ---- screen effects (effects_chain.c): the X11 Vulkan renderer's post chain in the compositor. + * Any thread, any time; the compositor thread applies them on its next frame and logs one + * `effects` line per change. Values are 1:1 with VulkanRenderer's setters. */ + +/* Scaling mode: 0=None 1=Linear 2=Nearest 3=SGSR 4=FSR 5=FSR Fit 6=Sharpen 7=NIS 8=SGSR HQ. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetUpscaler(JNIEnv *env, jclass clazz, jint mode) { + vkp_effects_set_scaling(mode); +} + +/* The upscaler's sharpness slider 0..100 (RCAS lobe / SGSR edge / NIS sharpness). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetUpscaleSharpness(JNIEnv *env, jclass clazz, jint sharpness) { + vkp_effects_set_upscale_sharpness(sharpness); +} + +/* AMD CAS sharpen toggle + level 0..100 (0 = pass off). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetCas(JNIEnv *env, jclass clazz, jboolean enabled, jint sharpness) { + vkp_effects_set_cas(enabled ? 1 : 0, sharpness); +} + +/* Fake-HDR toggle. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdr(JNIEnv *env, jclass clazz, jboolean enabled) { + vkp_effects_set_hdr(enabled ? 1 : 0); +} + +/* Terminal debanding toggle + strength 0..200 (100 = 1 LSB). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetDeband(JNIEnv *env, jclass clazz, jboolean enabled, jint strength) { + vkp_effects_set_deband(enabled ? 1 : 0, strength); +} + +/* Colour grade (slider units: brightness/contrast -100..100, gamma 0.5..3, saturation 0..200 %) and the + * FXAA / Toon / CRT / NTSC toggles — VulkanRenderer.setScreenEffects. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetScreenEffects(JNIEnv *env, jclass clazz, jfloat brightness, + jfloat contrast, jfloat gamma, jfloat saturation, jboolean fxaa, jboolean toon, jboolean crt, jboolean ntsc) { + vkp_effects_set_screen(brightness, contrast, gamma, saturation, fxaa ? 1 : 0, toon ? 1 : 0, crt ? 1 : 0, ntsc ? 1 : 0); +} + +/* One "display" line in the session log, written from Java: facts that live in the Android + * framework (the panel's HDR capability) rather than in the compositor. banner_log() mirrors to + * logcat and appends to the session file when one is open, so this is safe at any point. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeLogDisplay(JNIEnv *env, jclass clazz, jstring message) { + char *s = dup_jstr(env, message); + if (s) banner_log("display", "%s", s); + free(s); +} + +/* The same under the "perf" area: facts the app knows about the session's performance setup (the CPU + * cores the game is pinned to, say). Same safety as nativeLogDisplay. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeLogPerf(JNIEnv *env, jclass clazz, jstring message) { + char *s = dup_jstr(env, message); + if (s) banner_log("perf", "%s", s); + free(s); +} + +/* ---- HDR10 output, round 1 (banner_color.h / wl_color_mgmt.c) ---- */ + +/* The opt-in: mode 0 off, 1 BANNER_WAYLAND_HDR=1, 2 =force (testing). Before the compositor starts. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdrRequest(JNIEnv *env, jclass clazz, jint mode, + jstring source, jboolean dxvkHdr, jboolean zeroCopyForced) { + char *s = dup_jstr(env, source); + banner_color_set_request((int)mode, s, dxvkHdr ? 1 : 0, zeroCopyForced ? 1 : 0); + free(s); +} + +/* The game's display as android.view.Display reports it (before the start; again on every change). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdrDisplay(JNIEnv *env, jclass clazz, jint id, jstring name, + jstring formats, jboolean hdr10, jfloat maxLum, jfloat maxAvg, jfloat minLum, jboolean ratioAvailable, + jfloat ratio, jint api) { + char *n = dup_jstr(env, name), *f = dup_jstr(env, formats); + banner_color_set_display((int)id, n, f, hdr10 ? 1 : 0, (float)maxLum, (float)maxAvg, (float)minLum, + ratioAvailable ? 1 : 0, (float)ratio, (int)api); + free(n); free(f); +} + +/* One Display.getHdrSdrRatio() reading (listener = from the display's ratio listener). Any thread. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrSdrRatioSample(JNIEnv *env, jclass clazz, jfloat ratio, + jboolean listener) { + banner_color_ratio_sample((float)ratio, listener ? 1 : 0); +} + +/* ms since an HDR frame last reached a display layer, -1 = never this session. Any thread. */ +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrLastFrameAgeMs(JNIEnv *env, jclass clazz) { + return (jint)banner_color_last_frame_age_ms(); +} + +/* -1 = not decided yet, 0 = closed, 1 = open. Any thread. */ +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrGateState(JNIEnv *env, jclass clazz) { + return (jint)banner_color_gate_state(); +} + +/* The session is ending: the "HDR on screen: ..." summary line. Any thread, once. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrSessionEnd(JNIEnv *env, jclass clazz) { + banner_color_session_end(); +} + +/* HDR frames really on screen right now (the HUD badge). Any thread. */ +JNIEXPORT jboolean JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrOnScreen(JNIEnv *env, jclass clazz) { + return banner_color_hdr_on_screen() ? JNI_TRUE : JNI_FALSE; +} + +/* One "color" line in the session log from Java. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeLogColor(JNIEnv *env, jclass clazz, jstring message) { + char *s = dup_jstr(env, message); + if (s) banner_log("color", "%s", s); + free(s); +} + +/* One line in the session log under an area Java names ("gpu", "nvapi"): launch facts the app decides. + * The area is the log's 9-character column; an empty one reads "app". */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeLog(JNIEnv *env, jclass clazz, jstring area, jstring message) { + char *a = dup_jstr(env, area), *s = dup_jstr(env, message); + if (s) banner_log(a && a[0] ? a : "app", "%s", s); + free(a); + free(s); +} + +/* SDR content's level inside an HDR picture, in nits (default 203). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdrSdrWhite(JNIEnv *env, jclass clazz, jfloat nits) { + banner_color_set_sdr_white((float)nits); +} + +/* The drawer's live HDR output switch: on = HDR frames as HDR, off = the same frames tone-mapped to SDR. + * Applied on the compositor thread (logged there, with a redraw). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdrOutput(JNIEnv *env, jclass clazz, jboolean on) { + if (banner_get_display()) banner_host_hdr_output(on ? 1 : 0); + else banner_color_set_output(on ? 1 : 0); /* no compositor thread yet: nothing is drawing either */ +} + +JNIEXPORT jboolean JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrOutput(JNIEnv *env, jclass clazz) { + return banner_color_output() ? JNI_TRUE : JNI_FALSE; +} + +/* Device evidence for the HDR lines: thermal status + headroom, brightness + mode. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrEnvSample(JNIEnv *env, jclass clazz, jint thermal, + jfloat headroom, jint brightness, jint mode) { + banner_color_env_sample((int)thermal, (float)headroom != (float)headroom ? -1.0f : (float)headroom, + (int)brightness, (int)mode); +} + +/* Display.getHighestHdrSdrRatio() (Android 16+), <= 0 = not reported. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetHdrHighestRatio(JNIEnv *env, jclass clazz, jfloat ratio) { + banner_color_set_highest_ratio((float)ratio == (float)ratio ? (float)ratio : -1.0f); +} + +/* The HDR headroom the screen surface should ask for (HDR10 swapchain frames in the last 1.5 s), 0 = none. */ +JNIEXPORT jfloat JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrScreenHeadroom(JNIEnv *env, jclass clazz) { + return (jfloat)banner_color_screen_headroom(NULL, 0); +} + +JNIEXPORT jstring JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrScreenHeadroomWhy(JNIEnv *env, jclass clazz) { + char why[200]; + banner_color_screen_headroom(why, sizeof(why)); + return (*env)->NewStringUTF(env, why); +} + +/* The app's screen-surface request, for the no-headroom lines: > 0 asked, 0 cleared, -1 not possible. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrNoteHeadroomRequest(JNIEnv *env, jclass clazz, jfloat ratio) { + banner_color_note_headroom_request((float)ratio); +} + +/* 0 none, 1 HDR frames on screen with headroom, 2 HDR frames on screen without headroom for 5 s+. */ +JNIEXPORT jint JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrState(JNIEnv *env, jclass clazz) { + return (jint)banner_color_hdr_state(); +} + +/* An HDR game's frames were shown tone-mapped to SDR in the last 1.5 s (the drawer's status line). */ +JNIEXPORT jboolean JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeHdrToneMappedOnScreen(JNIEnv *env, jclass clazz) { + return banner_color_tonemapped_on_screen() ? JNI_TRUE : JNI_FALSE; +} + +/* The Look the controls currently match (null = Custom) — only named in the session log. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetLookName(JNIEnv *env, jclass clazz, jstring name) { + char *s = dup_jstr(env, name); + vkp_effects_set_look(s); + free(s); +} + +/* The in-game FPS limiter: frames per second, 0 = unlimited. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetFpsLimit(JNIEnv *env, jclass clazz, jint fps) { + g_fps_limit = fps > 0 ? fps : 0; + __android_log_print(ANDROID_LOG_INFO, TAG, "fps limit %d", fps); +} + +/* Swap/clear the output window (e.g. SurfaceView recreated/destroyed). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetSurface( + JNIEnv *env, jclass clazz, jobject surface) { + if (surface) { + vk_present_set_window(ANativeWindow_fromSurface(env, surface)); + } else { + vk_present_set_window(NULL); + } +} + +/* ---- clipboard + text input (any thread; queued to the compositor thread) ---- + * Text crosses as UTF-8 byte arrays: JNI's modified UTF-8 would mangle emoji. */ + +static char *dup_bytes(JNIEnv *env, jbyteArray arr, int *len) { + *len = 0; + if (!arr) return NULL; + jsize n = (*env)->GetArrayLength(env, arr); + char *buf = malloc((size_t)n + 1); + if (!buf) return NULL; + if (n) (*env)->GetByteArrayRegion(env, arr, 0, n, (jbyte *)buf); + buf[n] = 0; + *len = (int)n; + return buf; +} + +/* Android's clipboard text becomes the guest's selection (empty/null = clear). */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeSetClipboardText(JNIEnv *env, jclass clazz, jbyteArray utf8) { + int len; + char *buf = dup_bytes(env, utf8, &len); + banner_host_clipboard_text(buf ? buf : "", len); + free(buf); +} + +/* Soft-keyboard text committed to the program accepting text input. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeTextInputCommit(JNIEnv *env, jclass clazz, jbyteArray utf8) { + int len; + char *buf = dup_bytes(env, utf8, &len); + if (buf && len) banner_host_text_commit(buf, len); + free(buf); +} + +/* Composing (pre-edit) text; cursorBegin/cursorEnd are character indexes into it, -1 = end. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeTextInputPreedit(JNIEnv *env, jclass clazz, jbyteArray utf8, + jint cursorBegin, jint cursorEnd) { + int len; + char *buf = dup_bytes(env, utf8, &len); + banner_host_text_preedit(buf ? buf : "", len, cursorBegin, cursorEnd); + free(buf); +} + +/* The IME deleted characters around the caret. */ +JNIEXPORT void JNICALL +Java_com_the412banner_steamdeck_wayland_WaylandCompositor_nativeTextInputDelete(JNIEnv *env, jclass clazz, jint before, jint after) { + banner_host_text_delete(before, after); +} diff --git a/app/src/main/cpp/waylandcomp/src/wl_clipboard.c b/app/src/main/cpp/waylandcomp/src/wl_clipboard.c new file mode 100644 index 0000000000..9a5d083581 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/wl_clipboard.c @@ -0,0 +1,524 @@ +/* + * Clipboard: wl_data_device_manager (core, v3) and zwlr_data_control_manager_v1 (v1), selection + * only — drag and drop is refused. Both protocols share one selection: + * + * owner CLIENT a program's wl_data_source / zwlr_data_control_source_v1 (its mime list) + * owner HOST text the app pushed from Android's clipboard (offered under the text mimes) + * owner NONE nothing + * + * Every selection change is announced to every data-control device (they see the selection + * regardless of focus, as the protocol says) and to the wl_data_devices of the client holding + * keyboard focus; a client also gets the current selection when its keyboard focus arrives. + * + * winewayland prefers zwlr_data_control (it then runs the clipboard from the desktop process + * without needing keyboard focus) and tags its own offers with application/x.winewayland.tag + * so it can ignore them when they come back; we pass mime lists through untouched. + * + * Guest → Android: when a program sets a selection with a text mime, the compositor asks for it + * once over a pipe on the event loop (non-blocking, 1 MiB cap, 3 s timeout) and hands the text + * to the app (banner_on_clipboard_text → ClipboardManager). Android → guest: the app's text + * becomes the HOST selection; receive requests are answered with a non-blocking writer. + */ +#define _GNU_SOURCE 1 +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include "banner_ext.h" +#include "wlr-data-control-unstable-v1-server-protocol.h" + +#define CLIP_MAX_BYTES (1024 * 1024) +#define CLIP_READ_TIMEOUT_MS 3000 +#define CLIP_WRITE_TIMEOUT_MS 5000 +#define MAX_MIMES 64 + +static struct wl_display *g_disp; + +enum owner { OWNER_NONE, OWNER_CLIENT, OWNER_HOST }; +static enum owner g_owner; +static uint32_t g_gen; /* bumps on every selection change */ + +struct source { /* a client's data source (either protocol) */ + struct wl_resource *res; + int is_control; + char *mimes[MAX_MIMES]; + int nmimes; +}; +static struct source *g_src; /* current CLIENT selection */ + +static char *g_host_text; /* current HOST selection */ +static size_t g_host_len; +static const char *const k_text_mimes[] = { + "text/plain;charset=utf-8", "text/plain", "UTF8_STRING", "TEXT", "STRING", NULL +}; + +struct device { + struct wl_resource *res; + int is_control; + struct wl_list link; +}; +static struct wl_list g_devices; +static struct wl_client *g_kb_client; /* keyboard focus holder */ + +struct offer { + struct wl_resource *res; + int is_control; + uint32_t gen; /* the selection this offer describes */ +}; + +static char *g_last_guest_text; /* echo guard: the last text handed to Android */ +static size_t g_last_guest_len; + +/* ------------------------------------------------------------------ helpers */ + +static int is_text_mime(const char *m) { + for (int i = 0; k_text_mimes[i]; i++) if (!strcmp(m, k_text_mimes[i])) return 1; + return 0; +} + +static const char *source_text_mime(const struct source *s) { + for (int i = 0; k_text_mimes[i]; i++) + for (int j = 0; j < s->nmimes; j++) + if (!strcmp(s->mimes[j], k_text_mimes[i])) return s->mimes[j]; + return NULL; +} + +static void source_send_send(struct source *s, const char *mime, int fd) { + if (s->is_control) zwlr_data_control_source_v1_send_send(s->res, mime, fd); + else wl_data_source_send_send(s->res, mime, fd); +} + +static void source_send_cancelled(struct source *s) { + if (s->is_control) zwlr_data_control_source_v1_send_cancelled(s->res); + else wl_data_source_send_cancelled(s->res); +} + +/* ------------------------------------------------------------------ host → client writer */ + +struct writer { + int fd; + char *data; + size_t len, off; + struct wl_event_source *src, *timer; +}; + +static void writer_free(struct writer *w) { + if (w->src) wl_event_source_remove(w->src); + if (w->timer) wl_event_source_remove(w->timer); + close(w->fd); + free(w->data); + free(w); +} + +static int writer_pump(struct writer *w) { + while (w->off < w->len) { + ssize_t n = write(w->fd, w->data + w->off, w->len - w->off); + if (n > 0) { w->off += (size_t)n; continue; } + if (n < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return 0; /* wait */ + if (n < 0 && errno == EINTR) continue; + break; /* gone */ + } + return 1; +} + +static int on_writer_writable(int fd, uint32_t mask, void *data) { + struct writer *w = data; + if (mask & (WL_EVENT_ERROR | WL_EVENT_HANGUP) || writer_pump(w)) writer_free(w); + return 0; +} + +static int on_writer_timeout(void *data) { + struct writer *w = data; + banner_log("clipboard", "a program never read the clipboard text it asked for; giving up"); + writer_free(w); + return 0; +} + +static void writer_start(int fd, const char *data, size_t len) { + struct writer *w = calloc(1, sizeof(*w)); + if (!w) { close(fd); return; } + w->fd = fd; + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + if (len && !(w->data = malloc(len))) { close(fd); free(w); return; } + if (len) memcpy(w->data, data, len); + w->len = len; + if (writer_pump(w)) { writer_free(w); return; } + struct wl_event_loop *loop = wl_display_get_event_loop(g_disp); + w->src = wl_event_loop_add_fd(loop, fd, WL_EVENT_WRITABLE, on_writer_writable, w); + w->timer = wl_event_loop_add_timer(loop, on_writer_timeout, w); + if (w->timer) wl_event_source_timer_update(w->timer, CLIP_WRITE_TIMEOUT_MS); +} + +/* ------------------------------------------------------------------ client → host reader */ + +struct reader { + int fd; + char *buf; + size_t len; + const char *mime; /* points into the source's list */ + struct wl_event_source *src, *timer; +}; +static struct reader *g_reader; + +static void reader_free(struct reader *r) { + if (r->src) wl_event_source_remove(r->src); + if (r->timer) wl_event_source_remove(r->timer); + close(r->fd); + free(r->buf); + free(r); + if (g_reader == r) g_reader = NULL; +} + +static void reader_finish(struct reader *r) { + if (r->len > 0) { + char *copy = malloc(r->len + 1); + if (copy) { + memcpy(copy, r->buf, r->len); + copy[r->len] = 0; + free(g_last_guest_text); + g_last_guest_text = copy; + g_last_guest_len = r->len; + banner_log("clipboard", "guest copied %zu bytes (%s)", r->len, r->mime); + banner_on_clipboard_text(copy, (int)r->len); + } + } else { + banner_log("clipboard", "guest copied an empty text; Android clipboard left alone"); + } + reader_free(r); +} + +static int on_reader_readable(int fd, uint32_t mask, void *data) { + struct reader *r = data; + for (;;) { + if (r->len >= CLIP_MAX_BYTES) { + banner_log("clipboard", "guest text exceeds %d bytes; dropped", CLIP_MAX_BYTES); + reader_free(r); + return 0; + } + size_t room = CLIP_MAX_BYTES - r->len, chunk = room < 65536 ? room : 65536; + char *nb = realloc(r->buf, r->len + chunk); + if (!nb) { reader_free(r); return 0; } + r->buf = nb; + ssize_t n = read(fd, r->buf + r->len, chunk); + if (n > 0) { r->len += (size_t)n; continue; } + if (n == 0) { reader_finish(r); return 0; } /* EOF */ + if (errno == EAGAIN || errno == EWOULDBLOCK) { + if (mask & WL_EVENT_HANGUP) { reader_finish(r); return 0; } + return 0; + } + if (errno == EINTR) continue; + reader_free(r); + return 0; + } +} + +static int on_reader_timeout(void *data) { + struct reader *r = data; + banner_log("clipboard", "timed out reading the guest's clipboard text (%zu bytes so far)", r->len); + reader_free(r); + return 0; +} + +/* Ask the current client source for its text, once. */ +static void read_client_text(void) { + const char *mime; + int p[2]; + if (g_reader) reader_free(g_reader); + if (!g_src || !(mime = source_text_mime(g_src))) return; + if (pipe2(p, O_CLOEXEC) != 0) return; + fcntl(p[0], F_SETFL, fcntl(p[0], F_GETFL) | O_NONBLOCK); /* our end only; the client writes blocking */ + struct reader *r = calloc(1, sizeof(*r)); + if (!r) { close(p[0]); close(p[1]); return; } + r->fd = p[0]; + r->mime = mime; + struct wl_event_loop *loop = wl_display_get_event_loop(g_disp); + r->src = wl_event_loop_add_fd(loop, p[0], WL_EVENT_READABLE, on_reader_readable, r); + r->timer = wl_event_loop_add_timer(loop, on_reader_timeout, r); + if (r->timer) wl_event_source_timer_update(r->timer, CLIP_READ_TIMEOUT_MS); + g_reader = r; + source_send_send(g_src, mime, p[1]); + close(p[1]); + wl_display_flush_clients(g_disp); +} + +/* ------------------------------------------------------------------ offers */ + +static void offer_res_destroy(struct wl_resource *r) { free(wl_resource_get_user_data(r)); } + +static void offer_receive(struct wl_client *c, struct wl_resource *r, const char *mime, int32_t fd) { + struct offer *o = wl_resource_get_user_data(r); + if (!o || o->gen != g_gen) { close(fd); return; } /* stale offer */ + if (g_owner == OWNER_HOST) { + if (is_text_mime(mime)) { + banner_log("clipboard", "Android clipboard → guest (%zu bytes) for %s", g_host_len, banner_client_name(c)); + writer_start(fd, g_host_text, g_host_len); + } else { + close(fd); + } + } else if (g_owner == OWNER_CLIENT && g_src) { + source_send_send(g_src, mime, fd); /* libwayland dups the fd */ + close(fd); + wl_display_flush_clients(g_disp); + } else { + close(fd); + } +} +static void offer_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void offer_accept(struct wl_client *c, struct wl_resource *r, uint32_t serial, const char *mime) {} +static void offer_finish(struct wl_client *c, struct wl_resource *r) {} +static void offer_set_actions(struct wl_client *c, struct wl_resource *r, uint32_t a, uint32_t p) {} + +static const struct wl_data_offer_interface data_offer_impl = { + .accept = offer_accept, .receive = offer_receive, .destroy = offer_destroy, + .finish = offer_finish, .set_actions = offer_set_actions, +}; +static const struct zwlr_data_control_offer_v1_interface control_offer_impl = { + .receive = offer_receive, .destroy = offer_destroy, +}; + +/* Tell one device what the selection is now (a fresh offer, or nothing). */ +static void device_send_selection(struct device *d) { + struct wl_client *c = wl_resource_get_client(d->res); + if (g_owner == OWNER_NONE) { + if (d->is_control) zwlr_data_control_device_v1_send_selection(d->res, NULL); + else wl_data_device_send_selection(d->res, NULL); + return; + } + struct offer *o = calloc(1, sizeof(*o)); + if (!o) return; + o->is_control = d->is_control; + o->gen = g_gen; + if (d->is_control) { + o->res = wl_resource_create(c, &zwlr_data_control_offer_v1_interface, 1, 0); + if (!o->res) { free(o); return; } + wl_resource_set_implementation(o->res, &control_offer_impl, o, offer_res_destroy); + zwlr_data_control_device_v1_send_data_offer(d->res, o->res); + } else { + o->res = wl_resource_create(c, &wl_data_offer_interface, wl_resource_get_version(d->res), 0); + if (!o->res) { free(o); return; } + wl_resource_set_implementation(o->res, &data_offer_impl, o, offer_res_destroy); + wl_data_device_send_data_offer(d->res, o->res); + } + if (g_owner == OWNER_CLIENT && g_src) { + for (int i = 0; i < g_src->nmimes; i++) { + if (d->is_control) zwlr_data_control_offer_v1_send_offer(o->res, g_src->mimes[i]); + else wl_data_offer_send_offer(o->res, g_src->mimes[i]); + } + } else { + for (int i = 0; k_text_mimes[i]; i++) { + if (d->is_control) zwlr_data_control_offer_v1_send_offer(o->res, k_text_mimes[i]); + else wl_data_offer_send_offer(o->res, k_text_mimes[i]); + } + } + if (d->is_control) zwlr_data_control_device_v1_send_selection(d->res, o->res); + else wl_data_device_send_selection(d->res, o->res); +} + +/* The selection changed: every data-control device hears it; wl_data_devices only if their + * client holds keyboard focus. */ +static void broadcast_selection(void) { + struct device *d; + g_gen++; + wl_list_for_each(d, &g_devices, link) { + if (d->is_control || (g_kb_client && wl_resource_get_client(d->res) == g_kb_client)) + device_send_selection(d); + } + wl_display_flush_clients(g_disp); +} + +void banner_clipboard_keyboard_focus(struct wl_client *client) { + struct device *d; + if (client == g_kb_client) return; + g_kb_client = client; + if (!client) return; + wl_list_for_each(d, &g_devices, link) + if (!d->is_control && wl_resource_get_client(d->res) == client) device_send_selection(d); +} + +/* ------------------------------------------------------------------ sources */ + +static void source_res_destroy(struct wl_resource *r) { + struct source *s = wl_resource_get_user_data(r); + if (!s) return; + if (g_src == s) { + g_src = NULL; + g_owner = OWNER_NONE; + if (g_reader) reader_free(g_reader); + banner_log("clipboard", "%s withdrew its clipboard contents", banner_client_name(wl_resource_get_client(r))); + broadcast_selection(); + } + for (int i = 0; i < s->nmimes; i++) free(s->mimes[i]); + free(s); +} + +static void source_offer(struct wl_client *c, struct wl_resource *r, const char *mime) { + struct source *s = wl_resource_get_user_data(r); + if (!s || s->nmimes >= MAX_MIMES) return; + if (!(s->mimes[s->nmimes] = strdup(mime))) return; + s->nmimes++; +} +static void source_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void source_set_actions(struct wl_client *c, struct wl_resource *r, uint32_t actions) {} + +static const struct wl_data_source_interface data_source_impl = { + .offer = source_offer, .destroy = source_destroy, .set_actions = source_set_actions, +}; +static const struct zwlr_data_control_source_v1_interface control_source_impl = { + .offer = source_offer, .destroy = source_destroy, +}; + +static void create_source(struct wl_client *c, uint32_t id, int is_control, uint32_t ver) { + struct source *s = calloc(1, sizeof(*s)); + if (!s) { wl_client_post_no_memory(c); return; } + s->is_control = is_control; + s->res = wl_resource_create(c, is_control ? &zwlr_data_control_source_v1_interface + : &wl_data_source_interface, ver, id); + if (!s->res) { free(s); wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(s->res, is_control ? (const void *)&control_source_impl + : (const void *)&data_source_impl, + s, source_res_destroy); +} + +/* A device set (or cleared) the selection. */ +static void set_selection(struct wl_client *c, struct wl_resource *source_res) { + struct source *s = source_res ? wl_resource_get_user_data(source_res) : NULL; + if (s && s == g_src) return; + if (g_src && g_src != s) source_send_cancelled(g_src); + if (g_reader) reader_free(g_reader); + free(g_host_text); g_host_text = NULL; g_host_len = 0; + g_src = s; + g_owner = s ? OWNER_CLIENT : OWNER_NONE; + if (s) { + char list[200] = ""; + for (int i = 0; i < s->nmimes && strlen(list) < 150; i++) { + if (!strncmp(s->mimes[i], "application/x.winewayland", 25)) continue; + if (*list) strncat(list, ", ", sizeof(list) - strlen(list) - 1); + strncat(list, s->mimes[i], sizeof(list) - strlen(list) - 1); + } + banner_log("clipboard", "selection set by %s (%s)", banner_client_name(c), *list ? list : "no mime types"); + } else { + banner_log("clipboard", "%s cleared the clipboard", banner_client_name(c)); + } + broadcast_selection(); + read_client_text(); +} + +/* ------------------------------------------------------------------ devices */ + +static void device_res_destroy(struct wl_resource *r) { + struct device *d = wl_resource_get_user_data(r); + if (!d) return; + wl_list_remove(&d->link); + free(d); +} + +static void device_start_drag(struct wl_client *c, struct wl_resource *r, struct wl_resource *source, + struct wl_resource *origin, struct wl_resource *icon, uint32_t serial) { + banner_log("clipboard", "%s started a drag and drop; not supported, cancelled", banner_client_name(c)); + if (source) { + struct source *s = wl_resource_get_user_data(source); + if (s && s != g_src) source_send_cancelled(s); + } +} +static void device_set_selection(struct wl_client *c, struct wl_resource *r, struct wl_resource *source, uint32_t serial) { + set_selection(c, source); +} +static void device_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void control_device_set_selection(struct wl_client *c, struct wl_resource *r, struct wl_resource *source) { + set_selection(c, source); +} +static void control_device_set_primary(struct wl_client *c, struct wl_resource *r, struct wl_resource *source) { + /* No primary selection on Android; a source given here just gets cancelled. */ + if (source) { + struct source *s = wl_resource_get_user_data(source); + if (s && s != g_src) source_send_cancelled(s); + } +} + +static const struct wl_data_device_interface data_device_impl = { + .start_drag = device_start_drag, .set_selection = device_set_selection, .release = device_release, +}; +static const struct zwlr_data_control_device_v1_interface control_device_impl = { + .set_selection = control_device_set_selection, .destroy = device_release, + .set_primary_selection = control_device_set_primary, +}; + +static void create_device(struct wl_client *c, uint32_t id, int is_control, uint32_t ver) { + struct device *d = calloc(1, sizeof(*d)); + if (!d) { wl_client_post_no_memory(c); return; } + d->is_control = is_control; + d->res = wl_resource_create(c, is_control ? &zwlr_data_control_device_v1_interface + : &wl_data_device_interface, ver, id); + if (!d->res) { free(d); wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(d->res, is_control ? (const void *)&control_device_impl + : (const void *)&data_device_impl, + d, device_res_destroy); + wl_list_insert(&g_devices, &d->link); + /* Data-control devices see the selection at once; wl_data_devices when focus arrives. */ + if (is_control || (g_kb_client && c == g_kb_client)) device_send_selection(d); +} + +/* ------------------------------------------------------------------ managers */ + +static void dm_create_source(struct wl_client *c, struct wl_resource *r, uint32_t id) { + create_source(c, id, 0, wl_resource_get_version(r)); +} +static void dm_get_device(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *seat) { + create_device(c, id, 0, wl_resource_get_version(r)); +} +static void dm_release(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct wl_data_device_manager_interface dm_impl = { + .create_data_source = dm_create_source, .get_data_device = dm_get_device, .release = dm_release, +}; +static void bind_data_device_manager(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &wl_data_device_manager_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &dm_impl, NULL, NULL); +} + +static void cm_create_source(struct wl_client *c, struct wl_resource *r, uint32_t id) { + create_source(c, id, 1, 1); +} +static void cm_get_device(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *seat) { + create_device(c, id, 1, wl_resource_get_version(r)); +} +static void cm_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static const struct zwlr_data_control_manager_v1_interface cm_impl = { + .create_data_source = cm_create_source, .get_data_device = cm_get_device, .destroy = cm_destroy, +}; +static void bind_data_control_manager(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &zwlr_data_control_manager_v1_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &cm_impl, NULL, NULL); +} + +/* ------------------------------------------------------------------ host side */ + +/* Android's clipboard text (compositor thread, via the host queue). Takes the buffer. */ +void clipboard_host_text(char *utf8, size_t len) { + if (len && g_last_guest_text && len == g_last_guest_len && !memcmp(utf8, g_last_guest_text, len)) { + free(utf8); /* our own copy coming back: not a change */ + return; + } + if (len && g_owner == OWNER_HOST && g_host_len == len && !memcmp(utf8, g_host_text, len)) { + free(utf8); + return; + } + if (g_src) { source_send_cancelled(g_src); g_src = NULL; } + if (g_reader) reader_free(g_reader); + free(g_host_text); + g_host_text = len ? utf8 : NULL; + if (!len) free(utf8); + g_host_len = len; + g_owner = len ? OWNER_HOST : OWNER_NONE; + banner_log("clipboard", len ? "Android clipboard → guest (%zu bytes)" : "Android clipboard cleared (%zu bytes)", len); + broadcast_selection(); +} + +void clipboard_init(struct wl_display *display) { + g_disp = display; + wl_list_init(&g_devices); + wl_global_create(display, &wl_data_device_manager_interface, 3, NULL, bind_data_device_manager); + wl_global_create(display, &zwlr_data_control_manager_v1_interface, 1, NULL, bind_data_control_manager); +} diff --git a/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c b/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c new file mode 100644 index 0000000000..bcf67ee989 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/wl_color_mgmt.c @@ -0,0 +1,1301 @@ +/* + * wp_color_manager_v1 (wayland-protocols staging color-management-v1, version 1) — the subset Mesa's + * Wayland WSI binds — plus the HDR gate, the per-surface image descriptions and the session log's + * HDR evidence. See banner_color.h for the design and HDR_RECON.md for why it is shaped this way. + * + * Strictness policy. A protocol error disconnects the client, and the client here is a GAME, so + * errors are only raised where the protocol leaves no choice and a conforming client can never hit + * them: a request gated on a feature we did not advertise, a property set twice, an incomplete + * parameter set, a description that is not ready, an intent we did not advertise. Everything a + * conforming client CAN produce on a bad day is accepted and logged instead: out-of-range HDR + * metadata is dropped (Android gets none rather than nonsense), a second colour-management object + * for the same surface replaces the first, a request on an inert object is ignored. + */ +#define _GNU_SOURCE +#include "banner_color.h" +#include "banner_ext.h" +#include "ahb_swapchain.h" +#include "sc_layer.h" +#include "color-management-v1-server-protocol.h" +#include <pthread.h> +#include <stdarg.h> +#include <stdatomic.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +extern volatile int g_zero_copy; + +#define TAG "color" + +/* AHARDWAREBUFFER_FORMAT_* (android/hardware_buffer.h), for the log only. */ +const char *banner_ahb_format_name(uint32_t f) { + static char other[32]; + switch (f) { + case 1: return "RGBA8888 (8-bit)"; + case 2: return "RGBX8888 (8-bit)"; + case 3: return "RGB888 (8-bit)"; + case 4: return "RGB565"; + case 0x16: return "RGBA16F (16-bit float)"; + case 0x2b: return "RGBA1010102 (10-bit)"; + default: snprintf(other, sizeof(other), "format %#x", f); return other; + } +} + +static int64_t now_ns(void) { + struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); + return (int64_t)ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + +static const char *primaries_name(uint32_t p) { + switch (p) { + case WP_COLOR_MANAGER_V1_PRIMARIES_SRGB: return "BT.709/sRGB"; + case WP_COLOR_MANAGER_V1_PRIMARIES_BT2020: return "BT.2020"; + case WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3: return "Display P3"; + case WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3: return "DCI-P3"; + case WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB: return "Adobe RGB"; + default: return "other primaries"; + } +} + +static const char *tf_name(uint32_t tf) { + switch (tf) { + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ: return "ST 2084 (PQ)"; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG: return "HLG"; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB: return "sRGB"; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR: return "extended linear"; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22: return "gamma 2.2"; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_BT1886: return "BT.1886"; + default: return "other transfer function"; + } +} + +static const char *dataspace_name(int32_t ds) { + switch (ds) { + case BANNER_ADATASPACE_BT2020_PQ: return "BT2020_PQ"; + case BANNER_ADATASPACE_BT2020_HLG: return "BT2020_HLG"; + case BANNER_ADATASPACE_UNKNOWN: return "UNKNOWN (sRGB)"; + default: return "other"; + } +} + +/* ---------------------------------------------------------------- request (app) + gate */ + +static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; /* g_req, g_hdr (app threads + compositor) */ + +static struct { + int mode; /* 0 off, 1 on, 2 forced */ + char source[64]; + int dxvk_hdr, zero_copy_forced; + int display_known; + int display_id, hdr10, ratio_available, api; + char display_name[96], formats[96]; + float max_lum, max_avg, min_lum, ratio; + float highest_ratio; /* Display.getHighestHdrSdrRatio() (Android 16+), < 0 = not reported */ +} g_req = {.highest_ratio = -1.0f}; + +static _Atomic int g_gate = -1; /* -1 undecided, 0 closed, 1 open */ +static char g_gate_why[320]; /* the closed gate's reason (for the summary) */ +static _Atomic int g_output_on = 1; /* the drawer's HDR output switch (per session, starts on) */ + +void banner_color_set_request(int mode, const char *source, int dxvk_hdr, int zero_copy_forced) { + pthread_mutex_lock(&g_mu); + g_req.mode = mode < 0 ? 0 : mode > 2 ? 2 : mode; + snprintf(g_req.source, sizeof(g_req.source), "%s", source ? source : "environment"); + g_req.dxvk_hdr = dxvk_hdr ? 1 : 0; + g_req.zero_copy_forced = zero_copy_forced ? 1 : 0; + pthread_mutex_unlock(&g_mu); + atomic_store(&g_output_on, 1); /* the drawer's switch is per session and starts on */ +} + +void banner_color_set_display(int id, const char *name, const char *formats, int hdr10, float max_lum, + float max_avg, float min_lum, int ratio_available, float ratio, int api) { + pthread_mutex_lock(&g_mu); + int was_known = g_req.display_known, was_hdr10 = g_req.hdr10, was_id = g_req.display_id; + g_req.display_known = 1; + g_req.display_id = id; + snprintf(g_req.display_name, sizeof(g_req.display_name), "%s", name ? name : "?"); + snprintf(g_req.formats, sizeof(g_req.formats), "%s", formats ? formats : "unknown"); + g_req.hdr10 = hdr10 ? 1 : 0; + g_req.max_lum = max_lum; g_req.max_avg = max_avg; g_req.min_lum = min_lum; + g_req.ratio_available = ratio_available ? 1 : 0; + g_req.ratio = ratio; + g_req.api = api; + pthread_mutex_unlock(&g_mu); + /* The gate is decided once, when the compositor starts: a display that changes under a running + * session is recorded, and what it means is said out loud. */ + if (was_known && atomic_load(&g_gate) >= 0 && (was_hdr10 != (hdr10 ? 1 : 0) || was_id != id)) { + if (atomic_load(&g_gate) == 1 && !hdr10) + banner_log(TAG, "the game is now on \"%s\" (display %d), which reports no HDR10: HDR frames stay tagged " + "BT2020_PQ and SurfaceFlinger tone-maps them for this display (the offer to games is fixed " + "for the session)", name ? name : "?", id); + else if (atomic_load(&g_gate) == 0 && hdr10) + banner_log(TAG, "the game is now on \"%s\" (display %d), which reports HDR10 - HDR stays off for this " + "session (the gate is decided when the compositor starts); relaunch to use it", name ? name : "?", id); + } +} + +int banner_color_gate_state(void) { return atomic_load(&g_gate); } +int banner_color_hdr_open(void) { return atomic_load(&g_gate) == 1; } + +/* ---------------------------------------------------------------- HDR evidence (summary) */ + +static struct { + unsigned descs; /* HDR image descriptions made ready */ + unsigned applied; /* commits that made one current on a surface */ + char applied_who[160]; /* the last surface that got one */ + uint64_t layer_frames, layer_10bit, layer_copy8, copy_frames; /* layer_frames = every frame shown AS HDR */ + uint64_t composed, swapchain, tonemapped; + uint64_t tm_off; /* of `tonemapped`: while the drawer's HDR output switch was off */ + unsigned output_offs; /* times the switch was turned off */ + unsigned win_layer, win_copy, win_copy8, win_zc, win_composed, win_swapchain, win_tonemapped; + char copy_reason[160]; + char layer_fmt[48]; + int ratio_n, win_ratio_n, ratio_live_n; + float ratio_min, ratio_max, ratio_last, win_ratio_min, win_ratio_max, ratio_logged; + float ratio_live_max; /* highest reading taken WHILE HDR frames were on screen (the verdict's) */ + int64_t ratio_logged_ns, ratio_periodic_ns; + /* Live headroom. The display may grant HDR frames no headroom at all while they are on screen - seen + * on the Fold while the screen was being RECORDED (Android turns HDR headroom off for a recording, + * which is SDR), and plausibly with the brightness slider at maximum (SDR white already at the panel's + * limit) - so "the ratio rose once" is not enough for a reader at minute 3: time with HDR frames on + * screen, the part of it with the ratio above 1, and the current no-headroom streak. */ + int64_t prev_sample_ns; int prev_live; float prev_ratio; + int64_t live_ns, headroom_ns; + int64_t nohead_since_ns; /* HDR frames on screen and ratio <= 1.01 since then (0 = not now) */ + int nohead_said; /* the streak's "no headroom" line is written */ + char verdict[512]; +} g_hdr; +static _Atomic int64_t g_last_frame_ns; +static _Atomic int64_t g_last_tm_ns; /* the last HDR frame shown tone-mapped to SDR */ + +/* What the device says beside the headroom (the app, non-root APIs; banner_color_env_*). The Fold showed + * three ways to lose HDR headroom with HDR frames on screen - a screen recording, heat under load, and + * (plausibly) the brightness slider at maximum - so every no-headroom line carries this. Under g_mu. */ +static struct { + int known; + int thermal; /* PowerManager THERMAL_STATUS_* (0 none .. 6 shutdown), -1 unknown */ + float headroom; /* PowerManager.getThermalHeadroom(10), < 0 = not available */ + int brightness; /* Settings.System.SCREEN_BRIGHTNESS (0..255), -1 unknown */ + int bmode; /* SCREEN_BRIGHTNESS_MODE: 1 automatic, 0 manual, -1 unknown */ + float requested; /* the last HDR headroom asked for (layer or screen surface): > 0 the ratio, + * 0 none asked, -1 the API is missing on this Android (< 15) */ +} g_env = {0, -1, -1.0f, -1, -1, 0.0f}; + +static const char *thermal_name(int t) { + switch (t) { + case 0: return "NONE"; case 1: return "LIGHT"; case 2: return "MODERATE"; case 3: return "SEVERE"; + case 4: return "CRITICAL"; case 5: return "EMERGENCY"; case 6: return "SHUTDOWN"; default: return "?"; + } +} + +/* "thermal MODERATE (headroom 0.83), brightness 180/255 manual". Caller holds g_mu. */ +static void env_text_locked(char *out, size_t n) { + char t[48], b[40]; + if (g_env.thermal < 0) snprintf(t, sizeof(t), "thermal ?"); + else if (g_env.headroom >= 0.0f) snprintf(t, sizeof(t), "thermal %s (headroom %.2f)", thermal_name(g_env.thermal), + g_env.headroom); + else snprintf(t, sizeof(t), "thermal %s", thermal_name(g_env.thermal)); + if (g_env.brightness < 0) snprintf(b, sizeof(b), "brightness ?"); + else snprintf(b, sizeof(b), "brightness %d/255%s", g_env.brightness, + g_env.bmode == 1 ? " auto" : g_env.bmode == 0 ? " manual" : ""); + snprintf(out, n, "%s, %s", t, b); +} + +/* What the evidence says about headroom lost with HDR frames on screen. A screenshot or a screen recording + * is not detected in this build (that needs extra permissions), so it is named as a possibility when + * nothing the app can measure explains the loss. Caller holds g_mu. */ +static void nohead_causes_locked(char *out, size_t n, int brief) { + const char *parts[2]; + char hot[48]; + int np = 0; + if (g_env.thermal >= 2) { + snprintf(hot, sizeof(hot), "the device is hot (thermal %s)", thermal_name(g_env.thermal)); + parts[np++] = hot; + } + /* Maximum brightness only counts when it is MANUAL: the Fold kept 3.00 of headroom at 255 auto. */ + if (g_env.brightness >= 250 && g_env.bmode == 0) parts[np++] = "brightness at maximum (manual)"; + if (np == 1) snprintf(out, n, "likely %s", parts[0]); + else if (np == 2) snprintf(out, n, "likely %s and %s", parts[0], parts[1]); + else if (g_env.known) { + char req[48], hi[48]; + if (g_env.requested > 0.0f) snprintf(req, sizeof(req), "%.1fx", g_env.requested); + else snprintf(req, sizeof(req), "%s", g_env.requested < 0.0f ? "not possible below Android 15" : "none"); + if (g_req.highest_ratio > 0.0f) snprintf(hi, sizeof(hi), "%.2f", g_req.highest_ratio); + else snprintf(hi, sizeof(hi), "not reported"); + if (brief) + snprintf(out, n, "no visible cause (a screenshot or recording? no HDR boost for apps?) - asked %s, highest " + "ratio %s", req, hi); + else + snprintf(out, n, "no cause the app can see (not hot, brightness below maximum): a screenshot or screen " + "recording, or this phone does not boost HDR from apps (the requested headroom was %s, the " + "display's highest ratio is %s)", req, hi); + } else + snprintf(out, n, "a screenshot or screen recording, heat, or manual brightness at maximum"); +} + +/* ---- the explicit HDR headroom request (API 35; sc_layer.c for the game layer, the app for the screen + * surface): content peak / SDR white, capped at the display's highest ratio when it reports one. */ +static _Atomic int g_screen_hr_x1000; /* the screen surface's wanted headroom x1000 (HDR10 swapchain) */ +static _Atomic int64_t g_screen_hr_ns; /* the last HDR10-swapchain frame */ +static char g_screen_hr_why[200]; /* under g_mu */ + +static float peak_of(const struct banner_color *c, float disp_max, const char **src) { + if (c->max_cll > 0.0f) { *src = "max CLL"; return c->max_cll; } + if (c->has_st2086 && c->max_lum > 0.0f) { *src = "mastering max"; return c->max_lum; } + if (disp_max > 0.0f) { *src = "the display's peak"; return disp_max; } + *src = "assumed"; return 1000.0f; +} + +float banner_color_desired_headroom(const struct banner_color *c, char *why, size_t n) { + if (!c || !c->dataspace) { if (why && n) why[0] = 0; return 0.0f; } + pthread_mutex_lock(&g_mu); + const float disp_max = g_req.max_lum, highest = g_req.highest_ratio; + pthread_mutex_unlock(&g_mu); + const char *src; + const float peak = peak_of(c, disp_max, &src), white = banner_color_sdr_white(); + if (highest > 0.0f && highest <= 1.01f) { + if (why && n) snprintf(why, n, "the display reports its highest HDR/SDR ratio as %.2f: no app can get a " + "boost here, so nothing is asked", highest); + return 0.0f; + } + float r = peak / (white > 0.0f ? white : 203.0f); + const int capped = highest > 1.0f && r > highest; + if (capped) r = highest; + if (r < 1.0f) r = 1.0f; + if (why && n) { + if (capped) snprintf(why, n, "content peak %.0f nits (%s) / SDR %.0f, capped at the display's highest ratio %.2f", + peak, src, white, highest); + else snprintf(why, n, "content peak %.0f nits (%s) / SDR %.0f%s", peak, src, white, + highest > 0.0f ? "" : "; the display reports no highest ratio"); + } + return r; +} + +void banner_color_note_headroom_request(float ratio) { + pthread_mutex_lock(&g_mu); + g_env.requested = ratio; + pthread_mutex_unlock(&g_mu); +} + +void banner_color_set_highest_ratio(float ratio) { + pthread_mutex_lock(&g_mu); + const float was = g_req.highest_ratio; + g_req.highest_ratio = ratio > 0.0f ? ratio : -1.0f; + pthread_mutex_unlock(&g_mu); + if (ratio > 0.0f && (was < 0.0f || was != ratio) && atomic_load(&g_gate) == 1) + banner_log(TAG, "the display's highest HDR/SDR ratio is %.2f%s", ratio, + ratio <= 1.01f ? " - it reports no HDR boost at all: no app can raise HDR highlights above SDR white here" + : " (the most HDR headroom it can give)"); +} + +float banner_color_screen_headroom(char *why, size_t n) { + const int64_t t = atomic_load(&g_screen_hr_ns); + if (!t || now_ns() - t > 1500000000LL) { if (why && n) why[0] = 0; return 0.0f; } + if (why && n) { + pthread_mutex_lock(&g_mu); + snprintf(why, n, "%s", g_screen_hr_why); + pthread_mutex_unlock(&g_mu); + } + return atomic_load(&g_screen_hr_x1000) / 1000.0f; +} + +int banner_color_last_frame_age_ms(void) { + int64_t t = atomic_load(&g_last_frame_ns); + if (!t) return -1; + int64_t age = (now_ns() - t) / 1000000LL; + return age > 0x7fffffff ? 0x7fffffff : (int)age; +} + +/* The one-line answer a tester quotes. Caller holds g_mu. */ +static void verdict_locked(char *out, size_t size) { + int gate = atomic_load(&g_gate); + if (gate < 0) { snprintf(out, size, "not decided yet (the compositor has not started)"); return; } + if (gate == 0) { snprintf(out, size, "no, because %s", g_gate_why); return; } + if (g_hdr.layer_frames) { + const char *who = g_hdr.applied_who[0] ? g_hdr.applied_who : "the game"; + /* Only the paths that carried frames, so the ratio, the share and the device evidence still fit + * the log line. */ + char paths[200] = ""; + size_t pp = 0; + const uint64_t zc_other = g_hdr.layer_frames - g_hdr.layer_10bit - g_hdr.layer_copy8 - g_hdr.composed - + g_hdr.swapchain; + const struct { uint64_t n; const char *what; } path[] = { + {g_hdr.layer_10bit, "10-bit zero-copy"}, {zc_other, "zero-copy"}, {g_hdr.layer_copy8, "8-bit layer copy"}, + {g_hdr.composed, "composed"}, {g_hdr.swapchain, "HDR10 swapchain"}}; + for (unsigned i = 0; i < sizeof(path) / sizeof(path[0]); i++) + if (path[i].n && path[i].n <= g_hdr.layer_frames && pp < sizeof(paths) - 40) + pp += (size_t)snprintf(paths + pp, sizeof(paths) - pp, "%s%llu %s", pp ? ", " : "", + (unsigned long long)path[i].n, path[i].what); + if (g_hdr.tonemapped && pp < sizeof(paths) - 60) + pp += (size_t)snprintf(paths + pp, sizeof(paths) - pp, "; %llu more tone-mapped (%llu with HDR output off)", + (unsigned long long)g_hdr.tonemapped, (unsigned long long)g_hdr.tm_off); + char frames[340]; + snprintf(frames, sizeof(frames), "%llu frames of %s shown as BT2020_PQ (%s)", + (unsigned long long)g_hdr.layer_frames, who, paths); + char env[128] = "", causes[256] = ""; + if (g_env.known) env_text_locked(env, sizeof(env)); + /* Brief: the verdict has to fit one log line with everything else in it. */ + if (g_hdr.nohead_said) nohead_causes_locked(causes, sizeof(causes), 1); + /* Only readings taken while HDR frames were on screen count: the ratio says what the display did + * with THEM, not with whatever else was up at another moment. And the share of that time with any + * headroom, plus where it stands now: a ratio that rose once and then fell to 1.00 for minutes is + * not the same answer. */ + char share[384] = ""; + const long long live_s = (long long)(g_hdr.live_ns / 1000000000LL); + if (g_hdr.live_ns >= 1000000000LL) + snprintf(share, sizeof(share), "; headroom above 1.00 for %d%% of the HDR time (%lld of %lld s), now %.2f%s%s" + "%s%s%s", + (int)(100.0 * (double)g_hdr.headroom_ns / (double)g_hdr.live_ns + 0.5), + (long long)(g_hdr.headroom_ns / 1000000000LL), live_s, g_hdr.ratio_last, + g_hdr.nohead_said ? " - no headroom now: " : "", g_hdr.nohead_said ? causes : "", + env[0] ? " [" : "", env, env[0] ? "]" : ""); + /* The display's own ceiling (Android 16+) and what was asked for, where known. */ + char ceil[80] = "", req[48] = ""; + if (g_req.highest_ratio > 0.0f) snprintf(ceil, sizeof(ceil), ", highest possible %.2f", g_req.highest_ratio); + if (g_env.requested > 0.0f) snprintf(req, sizeof(req), ", %.1fx requested", g_env.requested); + else if (g_env.requested < 0.0f) snprintf(req, sizeof(req), ", no request possible below Android 15"); + if (g_hdr.ratio_live_n && g_hdr.ratio_live_max > 1.01f) + snprintf(out, size, "yes - %s; the display's HDR/SDR ratio rose to %.2f while they were on screen " + "(1.00 = SDR only%s%s)%s", frames, g_hdr.ratio_live_max, g_hdr.nohead_said ? "" : ceil, + g_hdr.nohead_said ? "" : req, share); + else if (g_hdr.ratio_live_n) + snprintf(out, size, "tagged but NOT confirmed - %s, but the display's HDR/SDR ratio stayed at %.2f while they " + "were on screen (%s%s%s): Android gave them no HDR headroom - %s%s%s%s", frames, + g_hdr.ratio_live_max, g_req.highest_ratio > 0.0f ? "" : "highest ratio not reported", + ceil[0] ? ceil + 2 : "", g_hdr.nohead_said ? "" : req, g_hdr.nohead_said ? causes : "a screenshot or " + "screen recording? heat? brightness at maximum (manual)? HDR off for this display?", + env[0] ? " [" : "", env, env[0] ? "]" : ""); + else if (g_hdr.ratio_n) + snprintf(out, size, "tagged, not measured - %s, but no HDR/SDR ratio reading was taken while they were on " + "screen (highest reading otherwise %.2f)", frames, g_hdr.ratio_max); + else + snprintf(out, size, "yes by the tag only - %s (this display reports no HDR/SDR ratio to confirm it)", frames); + return; + } + if (g_hdr.applied || g_hdr.descs) { + if (g_hdr.tonemapped && g_hdr.tm_off == g_hdr.tonemapped) + snprintf(out, size, "no - HDR output was switched off in the drawer whenever %s showed HDR: its %llu HDR " + "frames were shown tone-mapped to SDR - correct colours, no HDR brightness (switch it on to see HDR)", + g_hdr.applied_who[0] ? g_hdr.applied_who : "the game", (unsigned long long)g_hdr.tonemapped); + else if (g_hdr.tonemapped) + snprintf(out, size, "no - %s's HDR frames were shown tone-mapped to SDR (%llu frames: %llu with frame " + "generation through a screen surface that offers no HDR10 swapchain, %llu with HDR output switched " + "off in the drawer) - correct colours, no HDR brightness", + g_hdr.applied_who[0] ? g_hdr.applied_who : "the game", (unsigned long long)g_hdr.tonemapped, + (unsigned long long)(g_hdr.tonemapped - g_hdr.tm_off), (unsigned long long)g_hdr.tm_off); + else if (g_hdr.copy_frames) + snprintf(out, size, "no, because %s asked for HDR but all %llu of its HDR frames went through the " + "compositor's 8-bit SDR copy (%s) and were shown without tone mapping", + g_hdr.applied_who[0] ? g_hdr.applied_who : "the game", (unsigned long long)g_hdr.copy_frames, + g_hdr.copy_reason[0] ? g_hdr.copy_reason : "no display layer"); + else + snprintf(out, size, "no, because %s made an HDR image description but no frame of it was ever shown " + "(the swapchain may have failed after that - see the DXVK log)", + g_hdr.applied_who[0] ? g_hdr.applied_who : "a program"); + return; + } + snprintf(out, size, "no, because no program asked for HDR: the colour manager was offered but nothing set an HDR " + "image description (is DXVK_HDR=1 set, and is HDR switched on in the game's own display options?)"); +} + +/* Log the verdict when it changed (force = log it even if not). */ +static void log_verdict(int force) { + char v[512]; + pthread_mutex_lock(&g_mu); + verdict_locked(v, sizeof(v)); + int changed = strcmp(v, g_hdr.verdict) != 0; + if (changed) snprintf(g_hdr.verdict, sizeof(g_hdr.verdict), "%s", v); + pthread_mutex_unlock(&g_mu); + if (changed || force) banner_log(TAG, "HDR on screen: %s", v); +} + +void banner_color_frame_shown(const struct banner_color *c, int path, uint32_t ahb_format) { + if (!c || !c->dataspace) return; + int first8 = 0; + pthread_mutex_lock(&g_mu); + switch (path) { + case BANNER_HDR_ZERO_COPY: + if (ahb_format == 0x2b) g_hdr.layer_10bit++; + g_hdr.win_zc++; + snprintf(g_hdr.layer_fmt, sizeof(g_hdr.layer_fmt), "%s", banner_ahb_format_name(ahb_format)); + break; + case BANNER_HDR_LAYER_COPY: + if (!g_hdr.layer_copy8) first8 = 1; + g_hdr.layer_copy8++; g_hdr.win_copy8++; + snprintf(g_hdr.layer_fmt, sizeof(g_hdr.layer_fmt), "RGBA8888 layer copy"); + break; + case BANNER_HDR_COMPOSED: + g_hdr.composed++; g_hdr.win_composed++; + snprintf(g_hdr.layer_fmt, sizeof(g_hdr.layer_fmt), "composed %s", banner_ahb_format_name(ahb_format)); + break; + case BANNER_HDR_SWAPCHAIN: + g_hdr.swapchain++; g_hdr.win_swapchain++; + snprintf(g_hdr.layer_fmt, sizeof(g_hdr.layer_fmt), "HDR10 swapchain"); + atomic_store(&g_screen_hr_ns, now_ns()); + break; + default: /* BANNER_HDR_TONEMAPPED: shown, but not as HDR */ + g_hdr.tonemapped++; g_hdr.win_tonemapped++; + if (!atomic_load(&g_output_on)) g_hdr.tm_off++; + pthread_mutex_unlock(&g_mu); + atomic_store(&g_last_tm_ns, now_ns()); + return; + } + g_hdr.layer_frames++; + g_hdr.win_layer++; + pthread_mutex_unlock(&g_mu); + atomic_store(&g_last_frame_ns, now_ns()); + if (path == BANNER_HDR_SWAPCHAIN) { + /* The screen surface's headroom request (the app applies it): worked out again when the + * description changes, else once a second. */ + static uint32_t ident; + static int64_t calc_ns; + const int64_t t = now_ns(); + if (c->identity != ident || t - calc_ns > 1000000000LL) { + char why[200]; + const float r = banner_color_desired_headroom(c, why, sizeof(why)); + ident = c->identity; calc_ns = t; + pthread_mutex_lock(&g_mu); + snprintf(g_screen_hr_why, sizeof(g_screen_hr_why), "%s", why); + pthread_mutex_unlock(&g_mu); + atomic_store(&g_screen_hr_x1000, (int)(r * 1000.0f + 0.5f)); + } + } + if (first8) + banner_log(TAG, "HDR frames are reaching the display layer through the compositor's 8-bit layer copy (the game's " + "buffer is not a gralloc buffer this frame): colours stay correct (the frame keeps its BT2020_PQ tag), " + "precision drops to 8 bits (banding possible)"); +} + +void banner_color_frame_copied(const char *who, const char *reason) { + int first = 0; + pthread_mutex_lock(&g_mu); + g_hdr.copy_frames++; + g_hdr.win_copy++; + if (reason && strcmp(reason, g_hdr.copy_reason)) { + snprintf(g_hdr.copy_reason, sizeof(g_hdr.copy_reason), "%s", reason); + first = 1; + } + pthread_mutex_unlock(&g_mu); + if (first) + banner_log(TAG, "HDR frames of %s go through the compositor's 8-bit SDR copy now, because %s: shown WITHOUT " + "tone mapping (washed out) until that changes", who ? who : "a window", reason ? reason : "?"); +} + +void banner_color_ratio_sample(float ratio, int listener) { + if (atomic_load(&g_gate) != 1) return; + int64_t t = now_ns(); + int age = banner_color_last_frame_age_ms(); + int live = age >= 0 && age < 1500; + int log_it = 0, periodic = 0, nohead_now = 0, head_back = 0; + float was; + char env[128] = "", causes[256] = ""; + pthread_mutex_lock(&g_mu); + was = g_hdr.ratio_logged; + if (ratio > 0.0f) { + /* Time with HDR frames on screen, credited to the reading that stood over it. */ + if (g_hdr.prev_sample_ns && g_hdr.prev_live) { + int64_t dt = t - g_hdr.prev_sample_ns; + if (dt > 0 && dt < 3000000000LL) { + g_hdr.live_ns += dt; + if (g_hdr.prev_ratio > 1.01f) g_hdr.headroom_ns += dt; + } + } + g_hdr.prev_sample_ns = t; g_hdr.prev_live = live; g_hdr.prev_ratio = ratio; + if (live && ratio <= 1.01f) { + if (!g_hdr.nohead_since_ns) g_hdr.nohead_since_ns = t; + if (!g_hdr.nohead_said && t - g_hdr.nohead_since_ns >= 5000000000LL) g_hdr.nohead_said = nohead_now = 1; + } else { + if (live && g_hdr.nohead_said) head_back = 1; + g_hdr.nohead_since_ns = 0; g_hdr.nohead_said = 0; + } + if (!g_hdr.ratio_n || ratio < g_hdr.ratio_min) g_hdr.ratio_min = ratio; + if (!g_hdr.ratio_n || ratio > g_hdr.ratio_max) g_hdr.ratio_max = ratio; + if (!g_hdr.win_ratio_n || ratio < g_hdr.win_ratio_min) g_hdr.win_ratio_min = ratio; + if (!g_hdr.win_ratio_n || ratio > g_hdr.win_ratio_max) g_hdr.win_ratio_max = ratio; + g_hdr.ratio_n++; g_hdr.win_ratio_n++; + g_hdr.ratio_last = ratio; + if (live) { + if (!g_hdr.ratio_live_n || ratio > g_hdr.ratio_live_max) g_hdr.ratio_live_max = ratio; + g_hdr.ratio_live_n++; + } + /* A change is logged at once (at most 4 lines a second); while HDR frames are on screen the + * steady value is restated every 5 s, so a tester's log shows it holding, not just moving. */ + float moved = ratio - g_hdr.ratio_logged; + if (moved < 0.0f) moved = -moved; + if ((g_hdr.ratio_n == 1 || moved >= 0.02f) && t - g_hdr.ratio_logged_ns > 250000000LL) + log_it = 1; + else if (live && t - g_hdr.ratio_periodic_ns > 5000000000LL) + log_it = periodic = 1; + if (log_it) { g_hdr.ratio_logged = ratio; g_hdr.ratio_logged_ns = t; g_hdr.ratio_periodic_ns = t; } + if (nohead_now || (periodic && live && ratio <= 1.01f)) { + env_text_locked(env, sizeof(env)); + nohead_causes_locked(causes, sizeof(causes), 0); + } + } + pthread_mutex_unlock(&g_mu); + if (nohead_now) + banner_log(TAG, "no HDR headroom for 5 s while HDR frames are on screen (display HDR/SDR ratio %.2f): %s - Android " + "drops HDR headroom while the screen is recorded and when the device is hot, and some phones never " + "boost HDR for apps; HDR highlights look no brighter until that ends [%s]", ratio, causes, env); + if (head_back) + banner_log(TAG, "HDR headroom is back: display HDR/SDR ratio %.2f with HDR frames on screen", ratio); + if (!log_it) return; + char when[64]; + if (age < 0) snprintf(when, sizeof(when), "none yet this session"); + else snprintf(when, sizeof(when), "%s, last one %d ms ago", live ? "yes" : "no", age); + if (periodic) + banner_log(TAG, "display HDR/SDR ratio %.2f (steady; HDR frames on screen: %s)%s%s%s%s%s", ratio, when, + live && ratio <= 1.01f ? " - no HDR headroom: " : "", live && ratio <= 1.01f ? causes : "", + env[0] ? " [" : "", env, env[0] ? "]" : ""); + else if (was > 0.0f) + banner_log(TAG, "display HDR/SDR ratio %.2f (was %.2f; HDR frames on screen: %s) [%s]", ratio, was, when, + listener ? "display listener" : "sampler"); + else + banner_log(TAG, "display HDR/SDR ratio %.2f (first reading; HDR frames on screen: %s) [%s]", ratio, when, + listener ? "display listener" : "sampler"); +} + +void banner_color_stats_tick(void) { + if (atomic_load(&g_gate) != 1) return; + char line[512]; + int any; + pthread_mutex_lock(&g_mu); + any = g_hdr.win_layer || g_hdr.win_copy || g_hdr.win_tonemapped; /* the ratio alone is logged when it moves */ + if (any) { + char ratio[256] = "no HDR/SDR ratio reading", env[128] = "", causes[256] = ""; + if (g_env.known) env_text_locked(env, sizeof(env)); + if (g_hdr.nohead_said) nohead_causes_locked(causes, sizeof(causes), 1); + if (g_hdr.win_ratio_n) + snprintf(ratio, sizeof(ratio), "display HDR/SDR ratio %.2f-%.2f (now %.2f)%s%s", g_hdr.win_ratio_min, + g_hdr.win_ratio_max, g_hdr.ratio_last, g_hdr.nohead_said ? " - NO headroom: " : "", + g_hdr.nohead_said ? causes : ""); + snprintf(line, sizeof(line), "HDR last 10 s: %u frames shown as BT2020_PQ (zero-copy %u, 8-bit layer copy %u, " + "composed picture %u, HDR10 swapchain %u; last buffer %s) | %u tone-mapped to SDR | %u washed-out " + "copies | %s%s%s", + g_hdr.win_layer, g_hdr.win_zc, g_hdr.win_copy8, g_hdr.win_composed, g_hdr.win_swapchain, + g_hdr.layer_fmt[0] ? g_hdr.layer_fmt : "-", g_hdr.win_tonemapped, g_hdr.win_copy, ratio, + env[0] ? " | " : "", env); + } + g_hdr.win_layer = g_hdr.win_copy = g_hdr.win_copy8 = 0; + g_hdr.win_zc = g_hdr.win_composed = g_hdr.win_swapchain = g_hdr.win_tonemapped = 0; + g_hdr.win_ratio_n = 0; + pthread_mutex_unlock(&g_mu); + if (any) banner_log(TAG, "%s", line); + log_verdict(0); +} + +int banner_color_hdr_state(void) { + if (atomic_load(&g_gate) != 1) return 0; + int age = banner_color_last_frame_age_ms(); + if (age < 0 || age >= 1500) return 0; + pthread_mutex_lock(&g_mu); + int confirmed = !g_hdr.ratio_n || g_hdr.ratio_last > 1.01f; /* no ratio on this display: the tag is all there is */ + int nohead = g_hdr.nohead_said; + pthread_mutex_unlock(&g_mu); + return confirmed ? 1 : nohead ? 2 : 0; +} + +int banner_color_hdr_on_screen(void) { return banner_color_hdr_state() == 1; } + +static _Atomic int g_sdr_white_x100 = 20300; +void banner_color_set_sdr_white(float nits) { + if (!(nits >= 10.0f && nits <= 2000.0f)) return; + atomic_store(&g_sdr_white_x100, (int)(nits * 100.0f + 0.5f)); + banner_log(TAG, "SDR content inside an HDR picture is placed at %.0f nits (BANNER_WAYLAND_HDR_SDR_NITS)", nits); +} +float banner_color_sdr_white(void) { return atomic_load(&g_sdr_white_x100) / 100.0f; } + +int banner_color_requested(void) { + pthread_mutex_lock(&g_mu); + int m = g_req.mode; + pthread_mutex_unlock(&g_mu); + return m != 0; +} + +int banner_color_output(void) { return atomic_load(&g_output_on); } + +void banner_color_env_sample(int thermal, float headroom, int brightness, int bmode) { + if (atomic_load(&g_gate) != 1) return; /* evidence for the HDR lines only */ + char msg[2][200]; + int nmsg = 0; + pthread_mutex_lock(&g_mu); + const int first = !g_env.known; + if (!first && thermal != g_env.thermal) { + char hr[32] = ""; + if (headroom >= 0.0f) snprintf(hr, sizeof(hr), ", headroom %.2f", headroom); + snprintf(msg[nmsg++], sizeof(msg[0]), "thermal status now %s (was %s%s)%s", thermal_name(thermal), + thermal_name(g_env.thermal), hr, thermal >= 2 ? " - Android lowers HDR headroom when the device is hot" : ""); + } + if (!first && (brightness != g_env.brightness || bmode != g_env.bmode)) + snprintf(msg[nmsg++], sizeof(msg[0]), "screen brightness now %d/255 %s (was %d/255 %s)", brightness, + bmode == 1 ? "auto" : bmode == 0 ? "manual" : "?", g_env.brightness, + g_env.bmode == 1 ? "auto" : g_env.bmode == 0 ? "manual" : "?"); + g_env.thermal = thermal; + g_env.headroom = headroom; + g_env.brightness = brightness; + g_env.bmode = bmode; + g_env.known = 1; + if (first) { + char e[128]; + env_text_locked(e, sizeof(e)); + snprintf(msg[nmsg++], sizeof(msg[0]), "device evidence beside the HDR/SDR headroom: %s (thermal status and " + "brightness changes are logged as they happen)", e); + } + pthread_mutex_unlock(&g_mu); + for (int i = 0; i < nmsg; i++) banner_log(TAG, "%s", msg[i]); +} + +int banner_color_tonemapped_on_screen(void) { + if (atomic_load(&g_gate) != 1) return 0; + int64_t t = atomic_load(&g_last_tm_ns); + return t && now_ns() - t < 1500000000LL; +} + +void banner_color_set_output(int on) { + on = on ? 1 : 0; + if (atomic_load(&g_gate) != 1) { + /* The drawer only shows the switch in sessions whose gate is open; say so if it ever gets here. */ + banner_log(TAG, "HDR output switch (%s) ignored: HDR is not open in this session", on ? "on" : "off"); + return; + } + if (atomic_exchange(&g_output_on, on) == on) return; + char who[160]; + int age = banner_color_last_frame_age_ms(), tm = banner_color_tonemapped_on_screen(); + pthread_mutex_lock(&g_mu); + if (!on) g_hdr.output_offs++; + snprintf(who, sizeof(who), "%s", g_hdr.applied_who[0] ? g_hdr.applied_who : "no HDR program yet"); + pthread_mutex_unlock(&g_mu); + if (on) + banner_log(TAG, "HDR output switched ON in the drawer: HDR frames go to the display as HDR again from the next " + "frame (%s; %s)", who, tm ? "they were being tone-mapped to SDR until now" : "none were on screen just now"); + else + banner_log(TAG, "HDR output switched OFF in the drawer: HDR frames are tone-mapped to SDR from the next frame " + "(%s; %s). The game is not told - it keeps rendering HDR; its own HDR setting and DXVK_HDR are " + "untouched", who, age >= 0 && age < 1500 ? "HDR frames were on screen" : "no HDR frames on screen just now"); + banner_request_redraw(); /* a paused game commits nothing: show the change now */ +} + +static _Atomic int g_session_ended; + +void banner_color_session_end(void) { + if (atomic_exchange(&g_session_ended, 1)) return; + if (atomic_load(&g_gate) < 0) return; + pthread_mutex_lock(&g_mu); + int asked = g_req.mode != 0; + pthread_mutex_unlock(&g_mu); + if (asked) log_verdict(1); /* nobody asked for HDR: no summary to write */ +} + +/* ---------------------------------------------------------------- image descriptions */ + +struct cm_desc { + int refs; /* protocol objects + surfaces (pending / current) */ + struct banner_color c; + /* Set on the output / preferred descriptions the compositor serves (never on one a game built + * from parameters): get_information is answered rather than refused, with these as the target. */ + int informative; + float ref_lum; /* nits: PQ reference white */ + float disp_min_lum, disp_max_lum; /* nits: the display's own volume, from the app */ +}; + +static uint32_t g_next_identity = 1; + +static struct cm_desc *desc_ref(struct cm_desc *d) { if (d) d->refs++; return d; } +static void desc_unref(struct cm_desc *d) { if (d && --d->refs <= 0) free(d); } + +/* The parametric creator's collected properties. 0 / has_* = 0 means unset. */ +struct cm_params { + uint32_t tf, primaries; + int has_mprim; int32_t mprim[8]; + int has_mlum; uint32_t mlum_min, mlum_max; /* min is cd/m² * 10000, max is cd/m² */ + int has_cll; uint32_t cll; + int has_fall; uint32_t fall; +}; + +static void image_description_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void image_description_get_information(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct cm_desc *d = wl_resource_get_user_data(r); + if (!d || !d->informative) { + /* Built by the game from parameters: the protocol says it knows what it asked for. */ + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_V1_ERROR_NO_INFORMATION, + "get_information is not allowed on this image description"); + return; + } + struct wl_resource *info = wl_resource_create(c, &wp_image_description_info_v1_interface, + wl_resource_get_version(r), id); + if (!info) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(info, NULL, NULL, NULL); /* events only */ + const struct banner_color *col = &d->c; + int32_t xy[8] = { (int32_t)(col->red[0] * 1e6f + 0.5f), (int32_t)(col->red[1] * 1e6f + 0.5f), + (int32_t)(col->green[0] * 1e6f + 0.5f), (int32_t)(col->green[1] * 1e6f + 0.5f), + (int32_t)(col->blue[0] * 1e6f + 0.5f), (int32_t)(col->blue[1] * 1e6f + 0.5f), + (int32_t)(col->white[0] * 1e6f + 0.5f), (int32_t)(col->white[1] * 1e6f + 0.5f) }; + wp_image_description_info_v1_send_primaries(info, xy[0], xy[1], xy[2], xy[3], xy[4], xy[5], xy[6], xy[7]); + wp_image_description_info_v1_send_primaries_named(info, col->primaries); + wp_image_description_info_v1_send_tf_named(info, col->tf); + /* min is cd/m² * 10000, max and reference are cd/m² */ + wp_image_description_info_v1_send_luminances(info, (uint32_t)(col->min_lum * 10000.0f + 0.5f), + (uint32_t)(col->max_lum + 0.5f), (uint32_t)(d->ref_lum + 0.5f)); + wp_image_description_info_v1_send_target_primaries(info, xy[0], xy[1], xy[2], xy[3], xy[4], xy[5], xy[6], xy[7]); + wp_image_description_info_v1_send_target_luminance(info, (uint32_t)(d->disp_min_lum * 10000.0f + 0.5f), + (uint32_t)(d->disp_max_lum + 0.5f)); + /* done is a destructor event: the client's proxy is gone once it arrives, so the resource goes too. */ + wp_image_description_info_v1_send_done(info); + wl_resource_destroy(info); +} +static const struct wp_image_description_v1_interface image_description_impl = { + .destroy = image_description_destroy_req, + .get_information = image_description_get_information, +}; +static void image_description_resource_destroy(struct wl_resource *r) { + desc_unref(wl_resource_get_user_data(r)); +} + +/* What the display layer shows while the gate is open - BT.2020 + PQ over the display's own + * volume - served as the output's image description and as every surface's preferred one. It is + * ready at once and open to get_information, and that is not optional: gamescope asks for the + * preferred description and for its information in the same breath, before any roundtrip + * (WaylandBackend.cpp, UpdateWPPreferredColorManagement). Answering 'failed' and then refusing + * get_information with a protocol error severs its connection mid-roundtrip - the Fold 8 on r5: + * "Broken pipe", signal 6 - while a device with the gate closed never offers colour management + * and never gets here. gamescope reads only the luminances from the answer (reference white vs + * the display's peak) to decide whether it exposes HDR to what it hosts. */ +static void make_output_description(struct wl_client *c, struct wl_resource *parent, uint32_t id, const char *what) { + struct cm_desc *d = calloc(1, sizeof(*d)); + if (!d) { wl_client_post_no_memory(c); return; } + struct banner_color *col = &d->c; + col->identity = g_next_identity++; + if (!g_next_identity) g_next_identity = 1; + col->primaries = WP_COLOR_MANAGER_V1_PRIMARIES_BT2020; + col->tf = WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ; + col->dataspace = BANNER_ADATASPACE_BT2020_PQ; + col->has_st2086 = 1; + col->red[0] = 0.708f; col->red[1] = 0.292f; col->green[0] = 0.170f; col->green[1] = 0.797f; + col->blue[0] = 0.131f; col->blue[1] = 0.046f; col->white[0] = 0.3127f; col->white[1] = 0.3290f; + col->min_lum = 0.005f; col->max_lum = 10000.0f; /* the PQ volume */ + d->informative = 1; + d->ref_lum = 203.0f; /* PQ reference white */ + pthread_mutex_lock(&g_mu); + d->disp_min_lum = g_req.min_lum > 0.0f ? g_req.min_lum : 0.0f; + d->disp_max_lum = g_req.max_lum > 0.0f ? g_req.max_lum : 1000.0f; + pthread_mutex_unlock(&g_mu); + snprintf(col->text, sizeof(col->text), "BT.2020, ST 2084 PQ; target %.0f nits (the display)", d->disp_max_lum); + + struct wl_resource *r = wl_resource_create(c, &wp_image_description_v1_interface, wl_resource_get_version(parent), id); + if (!r) { free(d); wl_client_post_no_memory(c); return; } + d->refs = 1; + wl_resource_set_implementation(r, &image_description_impl, d, image_description_resource_destroy); + wp_image_description_v1_send_ready(r, col->identity); + banner_log(TAG, "%s asked for %s: answered the display's HDR10 volume (%s), ready and open to get_information", + banner_client_name(c), what, col->text); +} + +static void params_create(struct wl_client *client, struct wl_resource *r, uint32_t id) { + struct cm_params *p = wl_resource_get_user_data(r); + if (!p->tf || !p->primaries) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET, + "transfer function and primaries must both be set"); + return; + } + struct cm_desc *d = calloc(1, sizeof(*d)); + if (!d) { wl_client_post_no_memory(client); return; } + struct banner_color *c = &d->c; + c->identity = g_next_identity++; + if (!g_next_identity) g_next_identity = 1; + c->primaries = p->primaries; + c->tf = p->tf; + if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ) + c->dataspace = BANNER_ADATASPACE_BT2020_PQ; + else if (p->primaries == WP_COLOR_MANAGER_V1_PRIMARIES_BT2020 && p->tf == WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG) + c->dataspace = BANNER_ADATASPACE_BT2020_HLG; + + /* HDR metadata, kept only when it makes sense. The PQ defaults stand in for what was not given + * (0.005 - 10000 cd/m², the target volume = the primary one); CTA-861.3 treats 0 as unknown. */ + char dropped[160] = ""; + float mlum_min = 0.005f, mlum_max = 10000.0f; + if (p->has_mlum) { + float mn = p->mlum_min / 10000.0f, mx = (float)p->mlum_max; + if (mx > mn && mx > 0.0f) { mlum_min = mn; mlum_max = mx; } + else snprintf(dropped + strlen(dropped), sizeof(dropped) - strlen(dropped), " mastering luminance %.4f-%.0f (max <= min),", mn, mx); + } + if (p->has_mprim || p->has_mlum) { + c->has_st2086 = 1; + if (p->has_mprim) { + c->red[0] = p->mprim[0] / 1e6f; c->red[1] = p->mprim[1] / 1e6f; + c->green[0] = p->mprim[2] / 1e6f; c->green[1] = p->mprim[3] / 1e6f; + c->blue[0] = p->mprim[4] / 1e6f; c->blue[1] = p->mprim[5] / 1e6f; + c->white[0] = p->mprim[6] / 1e6f; c->white[1] = p->mprim[7] / 1e6f; + } else { /* the container's own primaries (BT.2020, D65) */ + c->red[0] = 0.708f; c->red[1] = 0.292f; c->green[0] = 0.170f; c->green[1] = 0.797f; + c->blue[0] = 0.131f; c->blue[1] = 0.046f; c->white[0] = 0.3127f; c->white[1] = 0.3290f; + } + c->min_lum = mlum_min; + c->max_lum = mlum_max; + } + float cll = p->has_cll ? (float)p->cll : 0.0f, fall = p->has_fall ? (float)p->fall : 0.0f; + if (cll > 0.0f && (cll <= mlum_min || cll > mlum_max)) { + snprintf(dropped + strlen(dropped), sizeof(dropped) - strlen(dropped), " max CLL %.0f (outside %.4f-%.0f),", cll, mlum_min, mlum_max); + cll = 0.0f; + } + if (fall > 0.0f && (fall <= mlum_min || fall > mlum_max || (cll > 0.0f && fall > cll))) { + snprintf(dropped + strlen(dropped), sizeof(dropped) - strlen(dropped), " max FALL %.0f (outside the range or above max CLL),", fall); + fall = 0.0f; + } + if (cll > 0.0f || fall > 0.0f) { c->has_cta861 = 1; c->max_cll = cll; c->max_fall = fall; } + + int n = snprintf(c->text, sizeof(c->text), "%s, %s", primaries_name(c->primaries), tf_name(c->tf)); + if (c->has_st2086 && n < (int)sizeof(c->text)) + n += snprintf(c->text + n, sizeof(c->text) - (size_t)n, + "; mastering R %.4f,%.4f G %.4f,%.4f B %.4f,%.4f W %.4f,%.4f, %.4f-%.0f nits%s", + c->red[0], c->red[1], c->green[0], c->green[1], c->blue[0], c->blue[1], c->white[0], c->white[1], + c->min_lum, c->max_lum, p->has_mprim ? "" : " (container primaries)"); + if (n < (int)sizeof(c->text)) + n += snprintf(c->text + n, sizeof(c->text) - (size_t)n, "; max CLL %s%.0f, max FALL %s%.0f", + c->max_cll > 0.0f ? "" : "unknown ", c->max_cll, c->max_fall > 0.0f ? "" : "unknown ", c->max_fall); + if (!c->has_st2086 && !c->has_cta861 && n < (int)sizeof(c->text)) + snprintf(c->text + n, sizeof(c->text) - (size_t)n, " (no HDR metadata: the game has not called vkSetHdrMetadataEXT)"); + + struct wl_resource *out = wl_resource_create(client, &wp_image_description_v1_interface, + wl_resource_get_version(r), id); + if (!out) { free(d); wl_client_post_no_memory(client); return; } + d->refs = 1; + wl_resource_set_implementation(out, &image_description_impl, d, image_description_resource_destroy); + /* Sent from inside the request: Mesa blocks its swapchain on this event (it dispatches its queue + * until ready/failed arrives), and the event loop flushes it before it sleeps again. */ + wp_image_description_v1_send_ready(out, c->identity); + if (c->dataspace) { + pthread_mutex_lock(&g_mu); + g_hdr.descs++; + pthread_mutex_unlock(&g_mu); + } + banner_log(TAG, "image description #%u from %s: %s -> ready (on a display layer: dataspace %s)", c->identity, + banner_client_name(client), c->text, dataspace_name(c->dataspace)); + if (dropped[0]) { + size_t l = strlen(dropped); + if (l && dropped[l - 1] == ',') dropped[l - 1] = 0; + banner_log(TAG, "image description #%u: dropped HDR metadata that breaks the protocol's rules:%s " + "(Android gets the rest)", c->identity, dropped); + } + wl_resource_destroy(r); /* create is the creator's destructor */ +} + +#define PARAMS_ONCE(field, what) \ + do { \ + if (field) { \ + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, \ + what " already set"); \ + return; \ + } \ + } while (0) + +static void params_set_tf_named(struct wl_client *c, struct wl_resource *r, uint32_t tf) { + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->tf, "transfer function"); + if (tf != WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF, + "transfer function %u was not advertised", tf); + return; + } + p->tf = tf; +} +static void params_set_tf_power(struct wl_client *c, struct wl_resource *r, uint32_t eexp) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE, + "set_tf_power is not supported"); +} +static void params_set_primaries_named(struct wl_client *c, struct wl_resource *r, uint32_t primaries) { + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->primaries, "primaries"); + if (primaries != WP_COLOR_MANAGER_V1_PRIMARIES_BT2020) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED, + "primaries %u were not advertised", primaries); + return; + } + p->primaries = primaries; +} +static void params_set_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry, int32_t gx, + int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE, + "set_primaries is not supported"); +} +static void params_set_luminances(struct wl_client *c, struct wl_resource *r, uint32_t mn, uint32_t mx, uint32_t ref) { + wl_resource_post_error(r, WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_UNSUPPORTED_FEATURE, + "set_luminances is not supported"); +} +static void params_set_mastering_display_primaries(struct wl_client *c, struct wl_resource *r, int32_t rx, int32_t ry, + int32_t gx, int32_t gy, int32_t bx, int32_t by, int32_t wx, int32_t wy) { + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->has_mprim, "mastering display primaries"); + p->has_mprim = 1; + p->mprim[0] = rx; p->mprim[1] = ry; p->mprim[2] = gx; p->mprim[3] = gy; + p->mprim[4] = bx; p->mprim[5] = by; p->mprim[6] = wx; p->mprim[7] = wy; +} +static void params_set_mastering_luminance(struct wl_client *c, struct wl_resource *r, uint32_t mn, uint32_t mx) { + struct cm_params *p = wl_resource_get_user_data(r); + PARAMS_ONCE(p->has_mlum, "mastering luminance"); + p->has_mlum = 1; p->mlum_min = mn; p->mlum_max = mx; +} +static void params_set_max_cll(struct wl_client *c, struct wl_resource *r, uint32_t v) { + struct cm_params *p = wl_resource_get_user_data(r); + p->has_cll = v != 0; p->cll = v; +} +static void params_set_max_fall(struct wl_client *c, struct wl_resource *r, uint32_t v) { + struct cm_params *p = wl_resource_get_user_data(r); + p->has_fall = v != 0; p->fall = v; +} +static const struct wp_image_description_creator_params_v1_interface params_impl = { + .create = params_create, + .set_tf_named = params_set_tf_named, + .set_tf_power = params_set_tf_power, + .set_primaries_named = params_set_primaries_named, + .set_primaries = params_set_primaries, + .set_luminances = params_set_luminances, + .set_mastering_display_primaries = params_set_mastering_display_primaries, + .set_mastering_luminance = params_set_mastering_luminance, + .set_max_cll = params_set_max_cll, + .set_max_fall = params_set_max_fall, +}; +static void params_resource_destroy(struct wl_resource *r) { free(wl_resource_get_user_data(r)); } + +/* ---------------------------------------------------------------- per-surface state */ + +/* One per wl_surface that ever had a colour-management object. Lives until the wl_surface goes (a + * swapchain rebuild destroys the object and makes a new one for the same surface). */ +struct cm_surf { + struct wl_resource *surface; /* the wl_surface */ + struct wl_listener surface_destroy; + struct wl_resource *owner; /* the live wp_color_management_surface_v1, NULL = none */ + struct cm_desc *pending, *current; + int pending_dirty; +}; + +static void cm_surface_destroyed(struct wl_listener *l, void *data); + +static struct cm_surf *surf_of(struct wl_resource *surface) { + if (!surface) return NULL; + struct wl_listener *l = wl_resource_get_destroy_listener(surface, cm_surface_destroyed); + if (!l) return NULL; + struct cm_surf *cs = wl_container_of(l, cs, surface_destroy); + return cs; +} + +static void describe_surface(struct wl_resource *surface, char *out, size_t size) { + struct surface *s = surface ? wl_resource_get_user_data(surface) : NULL; + if (s) banner_surface_describe(s, out, size); + else snprintf(out, size, "a closed window"); +} + +static void cm_surface_destroyed(struct wl_listener *l, void *data) { + struct cm_surf *cs = wl_container_of(l, cs, surface_destroy); + wl_list_remove(&cs->surface_destroy.link); + if (cs->owner) wl_resource_set_user_data(cs->owner, NULL); /* inert from now on */ + desc_unref(cs->pending); + desc_unref(cs->current); + free(cs); +} + +static void cm_surface_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } + +static void cm_surface_set_image_description(struct wl_client *c, struct wl_resource *r, + struct wl_resource *desc_res, uint32_t intent) { + struct cm_surf *cs = wl_resource_get_user_data(r); + struct cm_desc *d = desc_res ? wl_resource_get_user_data(desc_res) : NULL; + if (!cs) { + banner_log(TAG, "%s set an image description on a colour-management object whose surface is gone: ignored", + banner_client_name(c)); + return; + } + if (!d) { + wl_resource_post_error(r, WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_IMAGE_DESCRIPTION, + "the image description is not ready"); + return; + } + if (intent != WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL) { + wl_resource_post_error(r, WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_RENDER_INTENT, + "rendering intent %u was not advertised", intent); + return; + } + desc_unref(cs->pending); + cs->pending = desc_ref(d); + cs->pending_dirty = 1; +} + +static void cm_surface_unset_image_description(struct wl_client *c, struct wl_resource *r) { + struct cm_surf *cs = wl_resource_get_user_data(r); + if (!cs) return; + desc_unref(cs->pending); + cs->pending = NULL; + cs->pending_dirty = 1; +} + +static const struct wp_color_management_surface_v1_interface cm_surface_impl = { + .destroy = cm_surface_destroy_req, + .set_image_description = cm_surface_set_image_description, + .unset_image_description = cm_surface_unset_image_description, +}; + +/* Destroying the object does what unset_image_description does (double-buffered, like it). */ +static void cm_surface_resource_destroy(struct wl_resource *r) { + struct cm_surf *cs = wl_resource_get_user_data(r); + if (!cs || cs->owner != r) return; + cs->owner = NULL; + desc_unref(cs->pending); + cs->pending = NULL; + cs->pending_dirty = 1; +} + +void banner_color_commit(struct wl_resource *surface) { + if (atomic_load(&g_gate) != 1) return; + struct cm_surf *cs = surf_of(surface); + if (!cs || !cs->pending_dirty) return; + cs->pending_dirty = 0; + if (cs->pending == cs->current) return; + struct cm_desc *old = cs->current; + cs->current = desc_ref(cs->pending); + char who[160]; + describe_surface(surface, who, sizeof(who)); + if (cs->current) { + banner_log(TAG, "%s: image description #%u now applies to its frames (%s; perceptual intent)", who, + cs->current->c.identity, cs->current->c.text); + if (cs->current->c.dataspace) { + pthread_mutex_lock(&g_mu); + g_hdr.applied++; + snprintf(g_hdr.applied_who, sizeof(g_hdr.applied_who), "%s", who); + pthread_mutex_unlock(&g_mu); + if (!g_zero_copy) + banner_log(TAG, "%s: zero-copy presentation is OFF, so its HDR frames are composed into the HDR picture " + "(one extra pass per frame) - switch Zero-copy presentation on for the direct path", who); + } + } else if (old) { + banner_log(TAG, "%s: image description #%u removed - its frames are sRGB again", who, old->c.identity); + } + desc_unref(old); +} + +const struct banner_color *banner_color_of(struct wl_resource *surface) { + if (atomic_load(&g_gate) != 1) return NULL; + struct cm_surf *cs = surf_of(surface); + return cs && cs->current ? &cs->current->c : NULL; +} + +/* ---------------------------------------------------------------- output + feedback */ + +static void cm_output_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void cm_output_get_image_description(struct wl_client *c, struct wl_resource *r, uint32_t id) { + make_output_description(c, r, id, "the output's image description"); +} +static const struct wp_color_management_output_v1_interface cm_output_impl = { + .destroy = cm_output_destroy_req, + .get_image_description = cm_output_get_image_description, +}; + +static void cm_feedback_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void cm_feedback_get_preferred(struct wl_client *c, struct wl_resource *r, uint32_t id) { + make_output_description(c, r, id, "a surface's preferred image description"); +} +static const struct wp_color_management_surface_feedback_v1_interface cm_feedback_impl = { + .destroy = cm_feedback_destroy_req, + .get_preferred = cm_feedback_get_preferred, + .get_preferred_parametric = cm_feedback_get_preferred, +}; + +/* ---------------------------------------------------------------- wp_color_manager_v1 */ + +static void cm_destroy_req(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } + +static void cm_get_output(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *output) { + struct wl_resource *o = wl_resource_create(c, &wp_color_management_output_v1_interface, wl_resource_get_version(r), id); + if (!o) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(o, &cm_output_impl, NULL, NULL); +} + +static void cm_get_surface(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *surface) { + struct wl_resource *o = wl_resource_create(c, &wp_color_management_surface_v1_interface, wl_resource_get_version(r), id); + if (!o) { wl_client_post_no_memory(c); return; } + struct cm_surf *cs = surf_of(surface); + if (!cs) { + cs = calloc(1, sizeof(*cs)); + if (!cs) { wl_resource_destroy(o); wl_client_post_no_memory(c); return; } + cs->surface = surface; + cs->surface_destroy.notify = cm_surface_destroyed; + wl_resource_add_destroy_listener(surface, &cs->surface_destroy); + } + char who[160]; + describe_surface(surface, who, sizeof(who)); + if (cs->owner) { + /* The protocol says surface_exists; a game would be disconnected for it. The newer object wins. */ + banner_log(TAG, "%s: a second colour-management object for the same surface - the newer one takes over " + "(protocol error surface_exists not raised)", who); + wl_resource_set_user_data(cs->owner, NULL); + } + cs->owner = o; + wl_resource_set_implementation(o, &cm_surface_impl, cs, cm_surface_resource_destroy); + banner_log(TAG, "%s: colour-management surface created by %s (its Vulkan swapchain asks for a colour space " + "other than sRGB)", who, banner_client_name(c)); +} + +static void cm_get_surface_feedback(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *surface) { + struct wl_resource *o = wl_resource_create(c, &wp_color_management_surface_feedback_v1_interface, + wl_resource_get_version(r), id); + if (!o) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(o, &cm_feedback_impl, NULL, NULL); +} + +static void cm_create_icc_creator(struct wl_client *c, struct wl_resource *r, uint32_t id) { + wl_resource_post_error(r, WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "ICC image descriptions are not supported"); +} + +static void cm_create_parametric_creator(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct cm_params *p = calloc(1, sizeof(*p)); + if (!p) { wl_client_post_no_memory(c); return; } + struct wl_resource *o = wl_resource_create(c, &wp_image_description_creator_params_v1_interface, + wl_resource_get_version(r), id); + if (!o) { free(p); wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(o, ¶ms_impl, p, params_resource_destroy); +} + +static void cm_create_windows_scrgb(struct wl_client *c, struct wl_resource *r, uint32_t id) { + wl_resource_post_error(r, WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "windows_scrgb is not supported"); +} + +static const struct wp_color_manager_v1_interface cm_impl = { + .destroy = cm_destroy_req, + .get_output = cm_get_output, + .get_surface = cm_get_surface, + .get_surface_feedback = cm_get_surface_feedback, + .create_icc_creator = cm_create_icc_creator, + .create_parametric_creator = cm_create_parametric_creator, + .create_windows_scrgb = cm_create_windows_scrgb, +}; + +static void bind_cm(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + static struct wl_client *last_named; + struct wl_resource *r = wl_resource_create(c, &wp_color_manager_v1_interface, ver > 1 ? 1 : (int)ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &cm_impl, NULL, NULL); + /* All at bind, then done: Mesa reads them in the registry roundtrip that follows the bind and + * lists VK_COLOR_SPACE_HDR10_ST2084_EXT from exactly this pair (bt2020 + st2084_pq). Only what + * the display layer can honour is offered. */ + wp_color_manager_v1_send_supported_intent(r, WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC); + wp_color_manager_v1_send_supported_feature(r, WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES); + wp_color_manager_v1_send_supported_primaries_named(r, WP_COLOR_MANAGER_V1_PRIMARIES_BT2020); + wp_color_manager_v1_send_supported_tf_named(r, WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ); + wp_color_manager_v1_send_done(r); + /* One line per program: Mesa binds again for every surface-format query. */ + if (last_named != c) { + last_named = c; + banner_log(TAG, "%s bound wp_color_manager_v1 version %u (offered: perceptual intent; parametric descriptions " + "with mastering metadata; BT.2020 primaries; ST 2084 PQ) - its Vulkan driver can now list " + "VK_COLOR_SPACE_HDR10_ST2084_EXT", banner_client_name(c), ver > 1 ? 1u : ver); + } +} + +void banner_color_client_gone(struct wl_client *client) { + if (atomic_load(&g_gate) != 1 || atomic_load(&g_session_ended)) return; + /* A program that presented HDR has left: say where the session stands now, while it is fresh. */ + const char *name = banner_client_name(client); + int mine; + pthread_mutex_lock(&g_mu); + mine = g_hdr.applied_who[0] && name && strstr(g_hdr.applied_who, name) != NULL; + pthread_mutex_unlock(&g_mu); + if (mine) log_verdict(1); +} + +/* ---------------------------------------------------------------- the gate */ + +void banner_color_init(struct wl_display *display) { + char why[320] = ""; + int mode, dxvk_hdr, zc_forced, known, hdr10, id, ratio_avail, api; + char name[96], formats[96], source[64]; + float max_lum, max_avg, min_lum, ratio; + pthread_mutex_lock(&g_mu); + mode = g_req.mode; dxvk_hdr = g_req.dxvk_hdr; zc_forced = g_req.zero_copy_forced; + known = g_req.display_known; hdr10 = g_req.hdr10; id = g_req.display_id; + ratio_avail = g_req.ratio_available; api = g_req.api; + snprintf(name, sizeof(name), "%s", g_req.display_name); + snprintf(formats, sizeof(formats), "%s", g_req.formats); + snprintf(source, sizeof(source), "%s", g_req.source); + max_lum = g_req.max_lum; max_avg = g_req.max_avg; min_lum = g_req.min_lum; ratio = g_req.ratio; + pthread_mutex_unlock(&g_mu); + + char disp[256]; + if (known) + snprintf(disp, sizeof(disp), "\"%s\" (display %d, Android API %d) reports HDR types %s, peak %.0f nits, HDR/SDR " + "ratio %s", name, id, api, formats, max_lum, ratio_avail ? "available" : "not available"); + else + snprintf(disp, sizeof(disp), "the app could not read the display's HDR capability"); + + /* What asked for HDR, in the words the user knows it by: the editors' setting, or the env override. */ + char asked[128]; + if (mode == 2) snprintf(asked, sizeof(asked), "BANNER_WAYLAND_HDR=force (%s)", source); + else if (strstr(source, "env")) snprintf(asked, sizeof(asked), "BANNER_WAYLAND_HDR=1 (%s)", source); + else snprintf(asked, sizeof(asked), "HDR output is on (%s)", source); + + int layer_ok = sc_layer_can_tag_hdr(); + int ahb_ok = ahb_swapchain_advertised(); + char off_why[128]; + if (strstr(source, "env")) snprintf(off_why, sizeof(off_why), "BANNER_WAYLAND_HDR=0 in the %s overrides the setting", source); + else snprintf(off_why, sizeof(off_why), "the HDR output setting is off"); + if (mode == 0) + snprintf(why, sizeof(why), "HDR output is off (%s)", off_why); + else if (mode == 1 && !known) + snprintf(why, sizeof(why), "%s but %s", asked, disp); + else if (mode == 1 && !hdr10) + snprintf(why, sizeof(why), "%s but this display cannot show HDR10: %s", asked, disp); + else if (!layer_ok) + snprintf(why, sizeof(why), "this Android has no display layers with dataspace control " + "(ASurfaceControl + ASurfaceTransaction_setBufferDataSpace, Android 10+)"); + else if (!ahb_ok) + snprintf(why, sizeof(why), "zero-copy presentation is unavailable here (banner_ahb_v1 not advertised), and an " + "HDR frame is only honest on the game's own display layer"); + + if (why[0]) { + snprintf(g_gate_why, sizeof(g_gate_why), "%s", why); + atomic_store(&g_gate, 0); + if (mode) { + banner_log(TAG, "HDR gate CLOSED: %s. Nothing is advertised (no wp_color_manager_v1, no 10-bit dma-buf " + "formats): games see an SDR display, exactly as without the switch", why); + if (dxvk_hdr) + banner_log(TAG, "DXVK_HDR=1 is set: DXGI will still claim an HDR display that no swapchain can get here " + "(games that check fall back to SDR; some show washed-out colours) - remove it on this display"); + log_verdict(1); + } else if (dxvk_hdr || (known && hdr10)) { + /* Off, and silent unless it is worth a line: a display that could show HDR10, or a DXVK + * switch that promises games an HDR display they cannot get. */ + banner_log(TAG, "HDR output off for this session (%s)%s%s", off_why, + (known && hdr10) ? " - this display lists HDR10, so switching HDR output on for this game would " + "offer it to games" : "", + dxvk_hdr ? " - but DXVK_HDR=1 is set, so DXGI claims an HDR display the game cannot get a " + "swapchain for" : ""); + } + return; + } + + if (!wl_global_create(display, &wp_color_manager_v1_interface, 1, NULL, bind_cm)) { + snprintf(g_gate_why, sizeof(g_gate_why), "creating the wp_color_manager_v1 global failed"); + atomic_store(&g_gate, 0); + banner_log("error", "color: wp_color_manager_v1 global creation failed - HDR gate closed"); + log_verdict(1); + return; + } + atomic_store(&g_gate, 1); + char syms[160]; + sc_layer_hdr_symbols(syms, sizeof(syms)); + banner_log(TAG, "HDR gate %s: %s and %s. Offering games HDR10: wp_color_manager_v1 version 1 (BT.2020 primaries " + "+ ST 2084 PQ, parametric descriptions with mastering metadata) and 10-bit AB30/XB30 dma-buf formats; HDR " + "frames go on the game's own display layer as BT2020_PQ (%s)", + mode == 2 ? "FORCED OPEN (testing)" : "OPEN", asked, disp, syms); + if (mode == 2 && !hdr10) + banner_log(TAG, "BANNER_WAYLAND_HDR=force on a display without HDR10 - testing only: SurfaceFlinger will tone-map " + "the game layer for this panel (expect GPU/CLIENT composition for it), nothing looks HDR"); + if (zc_forced) + banner_log(TAG, "zero-copy presentation turned on for this session: the HDR game's own 10-bit frames go straight " + "to its display layer (the best path; anything that needs the compositor gets the composed HDR picture)"); + if (!dxvk_hdr) + banner_log(TAG, "DXVK_HDR=1 is not in the game's environment: DXVK games will not see an HDR display in DXGI " + "(dxgi.enableHDR in a dxvk.conf does the same) - add DXVK_HDR=1 to the container's or shortcut's " + "environment variables"); + (void)max_avg; (void)min_lum; +} diff --git a/app/src/main/cpp/waylandcomp/src/wl_text_input.c b/app/src/main/cpp/waylandcomp/src/wl_text_input.c new file mode 100644 index 0000000000..eeb05cedfa --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/wl_text_input.c @@ -0,0 +1,276 @@ +/* + * Text input: zwp_text_input_manager_v3 (advertised at version 1), the host input method + * bridge winewayland.drv uses for IME text (our soft keyboard). + * + * Focus model. winewayland enables its text input as soon as our `enter` names a surface and + * routes every IME update to that surface's window — inside that window's process (the update + * list is per process). Keyboard focus in this compositor sits on the desktop surface (the + * desktop owner's process), so text input can't follow it; it follows banner_ime_target(): + * the program window last clicked, else the topmost program window. Clicking into notepad + * moves the text-input focus to notepad's process, which is where the edit control lives. + * + * Protocol state. Requests between commits are pending; `commit` bumps the serial and applies + * them (enable resets the state as the protocol says). We answer with `done(serial)` only when + * we sent events (preedit/commit strings), never for every commit. + * + * Host side. banner_on_text_input(enabled, program, cursor rect in scene pixels) tells the app + * when a program starts/stops accepting IME text or moves its caret (Wine reports the rect only + * when an edit control positions its IME composition window, via ImmSetCompositionWindow). + * Typed text arrives through text_input_host_*: preedit_string / commit_string + done. + * delete_surrounding_text is NOT used: winewayland's handler for it is empty, so deletions + * become Backspace/Delete key presses on the wl_keyboard path instead. + */ +#define _GNU_SOURCE 1 +#include <stdlib.h> +#include <string.h> +#include "banner_ext.h" +#include "text-input-unstable-v3-server-protocol.h" + +#ifndef KEY_BACKSPACE +#define KEY_BACKSPACE 14 +#endif +#ifndef KEY_DELETE +#define KEY_DELETE 111 +#endif + +static struct wl_display *g_disp; + +struct text_input { + struct wl_resource *res; + struct wl_client *client; + struct wl_list link; + struct wl_resource *entered; /* surface we sent enter for, or NULL */ + uint32_t serial; /* commits received */ + /* pending, applied on commit */ + int p_enable, p_disable, p_rect_set, p_content_set; + int p_rect[4]; + uint32_t p_hint, p_purpose; + /* current */ + int enabled; + int rect[4]; + uint32_t hint, purpose; + int has_preedit; /* we sent a non-empty preedit last */ +}; +static struct wl_list g_inputs; +static struct wl_resource *g_target; /* surface text input is focused on */ + +/* What the app was last told. */ +static int g_told_enabled, g_told_rect[4]; +static struct text_input *g_told_ti; + +static const char *ti_program(struct text_input *ti) { return banner_client_name(ti->client); } + +/* The enabled text input focused on the current target, if any. */ +static struct text_input *active_input(void) { + struct text_input *ti; + if (!g_target) return NULL; + wl_list_for_each(ti, &g_inputs, link) + if (ti->entered == g_target && ti->enabled) return ti; + return NULL; +} + +static void tell_app(void) { + struct text_input *ti = active_input(); + int enabled = ti != NULL, rect[4] = {0, 0, 0, 0}; + if (ti) { + int ox = 0, oy = 0; + banner_surface_scene_origin(ti->entered, &ox, &oy); + rect[0] = ti->rect[0] + ox; rect[1] = ti->rect[1] + oy; + rect[2] = ti->rect[2]; rect[3] = ti->rect[3]; + } + if (enabled == g_told_enabled && ti == g_told_ti && !memcmp(rect, g_told_rect, sizeof(rect))) return; + if (enabled && (!g_told_enabled || ti != g_told_ti)) + banner_log("text-input", "text input enabled by %s (cursor rect %d,%d %dx%d)", ti_program(ti), + rect[0], rect[1], rect[2], rect[3]); + else if (enabled) + banner_log("text-input", "cursor rect from %s: %d,%d %dx%d", ti_program(ti), rect[0], rect[1], rect[2], rect[3]); + else + banner_log("text-input", "text input disabled%s%s", g_told_ti ? " by " : "", g_told_ti ? ti_program(g_told_ti) : ""); + g_told_enabled = enabled; + g_told_ti = ti; + memcpy(g_told_rect, rect, sizeof(rect)); + banner_on_text_input(enabled, enabled ? ti_program(ti) : "", rect[0], rect[1], rect[2], rect[3]); +} + +/* ------------------------------------------------------------------ focus */ + +static void send_leave(struct text_input *ti) { + if (!ti->entered) return; + zwp_text_input_v3_send_leave(ti->res, ti->entered); + ti->entered = NULL; + ti->enabled = 0; /* the protocol disables on leave */ + ti->has_preedit = 0; +} + +void banner_text_input_refocus(void) { + struct wl_resource *t = banner_ime_target(); + struct text_input *ti; + if (t == g_target) return; + wl_list_for_each(ti, &g_inputs, link) + if (ti->entered && ti->entered != t) send_leave(ti); + g_target = t; + if (t) { + struct wl_client *c = wl_resource_get_client(t); + wl_list_for_each(ti, &g_inputs, link) { + if (ti->client != c || ti->entered == t) continue; + ti->entered = t; + zwp_text_input_v3_send_enter(ti->res, t); + } + } + tell_app(); + wl_display_flush_clients(g_disp); +} + +void banner_text_input_surface_gone(struct wl_resource *surface) { + struct text_input *ti; + wl_list_for_each(ti, &g_inputs, link) + if (ti->entered == surface) { ti->entered = NULL; ti->enabled = 0; ti->has_preedit = 0; } + if (g_target == surface) g_target = NULL; + if (g_told_ti && g_told_ti->entered == NULL && g_told_enabled) tell_app(); +} + +/* ------------------------------------------------------------------ requests */ + +static void ti_res_destroy(struct wl_resource *r) { + struct text_input *ti = wl_resource_get_user_data(r); + if (!ti) return; + wl_list_remove(&ti->link); + if (g_told_ti == ti) { g_told_ti = NULL; g_told_enabled = 0; memset(g_told_rect, 0, sizeof(g_told_rect)); + banner_on_text_input(0, "", 0, 0, 0, 0); } + free(ti); +} + +static void ti_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void ti_enable(struct wl_client *c, struct wl_resource *r) { + struct text_input *ti = wl_resource_get_user_data(r); + if (ti) { ti->p_enable = 1; ti->p_disable = 0; } +} +static void ti_disable(struct wl_client *c, struct wl_resource *r) { + struct text_input *ti = wl_resource_get_user_data(r); + if (ti) { ti->p_disable = 1; ti->p_enable = 0; } +} +static void ti_set_surrounding_text(struct wl_client *c, struct wl_resource *r, const char *text, int32_t cursor, int32_t anchor) {} +static void ti_set_text_change_cause(struct wl_client *c, struct wl_resource *r, uint32_t cause) {} +static void ti_set_content_type(struct wl_client *c, struct wl_resource *r, uint32_t hint, uint32_t purpose) { + struct text_input *ti = wl_resource_get_user_data(r); + if (ti) { ti->p_hint = hint; ti->p_purpose = purpose; ti->p_content_set = 1; } +} +static void ti_set_cursor_rectangle(struct wl_client *c, struct wl_resource *r, int32_t x, int32_t y, int32_t w, int32_t h) { + struct text_input *ti = wl_resource_get_user_data(r); + if (!ti) return; + ti->p_rect[0] = x; ti->p_rect[1] = y; ti->p_rect[2] = w; ti->p_rect[3] = h; + ti->p_rect_set = 1; +} +static void ti_commit(struct wl_client *c, struct wl_resource *r) { + struct text_input *ti = wl_resource_get_user_data(r); + if (!ti) return; + ti->serial++; + if (ti->p_enable) { + ti->enabled = ti->entered != NULL; /* enable only counts while focused */ + memset(ti->rect, 0, sizeof(ti->rect)); + ti->hint = 0; ti->purpose = 0; + ti->has_preedit = 0; + } + if (ti->p_disable) { ti->enabled = 0; ti->has_preedit = 0; } + if (ti->p_rect_set) memcpy(ti->rect, ti->p_rect, sizeof(ti->rect)); + if (ti->p_content_set) { ti->hint = ti->p_hint; ti->purpose = ti->p_purpose; } + ti->p_enable = ti->p_disable = ti->p_rect_set = ti->p_content_set = 0; + tell_app(); +} +static void ti_set_available_actions(struct wl_client *c, struct wl_resource *r, struct wl_array *a) {} +static void ti_show_input_panel(struct wl_client *c, struct wl_resource *r) {} +static void ti_hide_input_panel(struct wl_client *c, struct wl_resource *r) {} + +static const struct zwp_text_input_v3_interface ti_impl = { + .destroy = ti_destroy, .enable = ti_enable, .disable = ti_disable, + .set_surrounding_text = ti_set_surrounding_text, .set_text_change_cause = ti_set_text_change_cause, + .set_content_type = ti_set_content_type, .set_cursor_rectangle = ti_set_cursor_rectangle, + .commit = ti_commit, .set_available_actions = ti_set_available_actions, + .show_input_panel = ti_show_input_panel, .hide_input_panel = ti_hide_input_panel, +}; + +static void tim_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void tim_get_text_input(struct wl_client *c, struct wl_resource *r, uint32_t id, struct wl_resource *seat) { + struct text_input *ti = calloc(1, sizeof(*ti)); + if (!ti) { wl_client_post_no_memory(c); return; } + ti->res = wl_resource_create(c, &zwp_text_input_v3_interface, wl_resource_get_version(r), id); + if (!ti->res) { free(ti); wl_client_post_no_memory(c); return; } + ti->client = c; + wl_resource_set_implementation(ti->res, &ti_impl, ti, ti_res_destroy); + wl_list_insert(&g_inputs, &ti->link); + if (g_target && wl_resource_get_client(g_target) == c) { + ti->entered = g_target; + zwp_text_input_v3_send_enter(ti->res, g_target); + } +} +static const struct zwp_text_input_manager_v3_interface tim_impl = { + .destroy = tim_destroy, .get_text_input = tim_get_text_input, +}; +static void bind_text_input_manager(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &zwp_text_input_manager_v3_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &tim_impl, NULL, NULL); +} + +/* ------------------------------------------------------------------ host side (compositor thread) */ + +static size_t utf8_chars(const char *s, size_t len) { + size_t n = 0; + for (size_t i = 0; i < len; i++) if (((unsigned char)s[i] & 0xC0) != 0x80) n++; + return n; +} + +/* Byte offset of UTF-8 character index `chars` (negative = end). */ +static int32_t utf8_offset(const char *s, size_t len, int chars) { + if (chars < 0) return (int32_t)len; + size_t i = 0; + while (i < len && chars > 0) { + i++; + while (i < len && ((unsigned char)s[i] & 0xC0) == 0x80) i++; + chars--; + } + return (int32_t)i; +} + +void text_input_host_commit(const char *utf8, size_t len) { + struct text_input *ti = active_input(); + if (!ti) { + banner_log("text-input", "typed text (%zu chars) dropped: no program accepts text input", utf8_chars(utf8, len)); + return; + } + if (ti->has_preedit) { zwp_text_input_v3_send_preedit_string(ti->res, "", 0, 0); ti->has_preedit = 0; } + zwp_text_input_v3_send_commit_string(ti->res, utf8); + zwp_text_input_v3_send_done(ti->res, ti->serial); + banner_log("text-input", "committed %zu chars to %s", utf8_chars(utf8, len), ti_program(ti)); +} + +void text_input_host_preedit(const char *utf8, size_t len, int cursor_begin, int cursor_end) { + struct text_input *ti = active_input(); + if (!ti) return; + if (!len && !ti->has_preedit) return; + zwp_text_input_v3_send_preedit_string(ti->res, len ? utf8 : "", + utf8_offset(utf8, len, cursor_begin), utf8_offset(utf8, len, cursor_end)); + zwp_text_input_v3_send_done(ti->res, ti->serial); + ti->has_preedit = len > 0; +} + +void text_input_host_delete(int before, int after) { + if (before <= 0 && after <= 0) return; + if (before > 64) before = 64; + if (after > 64) after = 64; + struct text_input *ti = active_input(); + if (ti && ti->has_preedit) { /* deleting inside a composition: clear it first */ + zwp_text_input_v3_send_preedit_string(ti->res, "", 0, 0); + zwp_text_input_v3_send_done(ti->res, ti->serial); + ti->has_preedit = 0; + } + for (int i = 0; i < before; i++) { banner_inject_key(KEY_BACKSPACE, 1); banner_inject_key(KEY_BACKSPACE, 0); } + for (int i = 0; i < after; i++) { banner_inject_key(KEY_DELETE, 1); banner_inject_key(KEY_DELETE, 0); } + banner_log("text-input", "deleted %d before / %d after the caret (as key presses)", before, after); +} + +void text_input_init(struct wl_display *display) { + g_disp = display; + wl_list_init(&g_inputs); + wl_global_create(display, &zwp_text_input_manager_v3_interface, 1, NULL, bind_text_input_manager); +} diff --git a/app/src/main/cpp/waylandcomp/src/wl_toplevel_icon.c b/app/src/main/cpp/waylandcomp/src/wl_toplevel_icon.c new file mode 100644 index 0000000000..17a9f59e08 --- /dev/null +++ b/app/src/main/cpp/waylandcomp/src/wl_toplevel_icon.c @@ -0,0 +1,36 @@ +/* + * xdg_toplevel_icon_manager_v1 (version 1): window icons are accepted and dropped. The scene + * has no title bars to draw them in; winewayland only stops complaining that the global is + * missing. We send no icon_size (any size is fine) and `done` at bind, as the protocol asks. + */ +#include <stdlib.h> +#include "banner_ext.h" +#include "xdg-toplevel-icon-v1-server-protocol.h" + +static void icon_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void icon_set_name(struct wl_client *c, struct wl_resource *r, const char *name) {} +static void icon_add_buffer(struct wl_client *c, struct wl_resource *r, struct wl_resource *buffer, int32_t scale) {} +static const struct xdg_toplevel_icon_v1_interface icon_impl = { + .destroy = icon_destroy, .set_name = icon_set_name, .add_buffer = icon_add_buffer, +}; + +static void mgr_destroy(struct wl_client *c, struct wl_resource *r) { wl_resource_destroy(r); } +static void mgr_create_icon(struct wl_client *c, struct wl_resource *r, uint32_t id) { + struct wl_resource *icon = wl_resource_create(c, &xdg_toplevel_icon_v1_interface, wl_resource_get_version(r), id); + if (!icon) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(icon, &icon_impl, NULL, NULL); +} +static void mgr_set_icon(struct wl_client *c, struct wl_resource *r, struct wl_resource *toplevel, struct wl_resource *icon) {} +static const struct xdg_toplevel_icon_manager_v1_interface mgr_impl = { + .destroy = mgr_destroy, .create_icon = mgr_create_icon, .set_icon = mgr_set_icon, +}; +static void bind_icon_manager(struct wl_client *c, void *data, uint32_t ver, uint32_t id) { + struct wl_resource *r = wl_resource_create(c, &xdg_toplevel_icon_manager_v1_interface, ver, id); + if (!r) { wl_client_post_no_memory(c); return; } + wl_resource_set_implementation(r, &mgr_impl, NULL, NULL); + xdg_toplevel_icon_manager_v1_send_done(r); +} + +void toplevel_icon_init(struct wl_display *display) { + wl_global_create(display, &xdg_toplevel_icon_manager_v1_interface, 1, NULL, bind_icon_manager); +} diff --git a/app/src/main/java/com/the412banner/steamdeck/MainActivity.kt b/app/src/main/java/com/the412banner/steamdeck/MainActivity.kt new file mode 100644 index 0000000000..0e56ee8fce --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/MainActivity.kt @@ -0,0 +1,154 @@ +package com.the412banner.steamdeck + +import android.Manifest +import android.app.Activity +import android.app.AlertDialog +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.view.View +import android.widget.Button +import android.widget.ProgressBar +import android.widget.TextView +import com.the412banner.steamdeck.core.FileUtils +import com.the412banner.steamdeck.runtime.LinuxRuntime +import com.the412banner.steamdeck.runtime.LinuxRuntimeInstaller + +/** + * The whole app outside a session: is the runtime installed, is there a newer one, and one button + * that starts Steam. Everything a Steam client can do — the library, the store, downloads, + * settings — is the client's own job once {@link SessionActivity} has it on screen. + */ +class MainActivity : Activity() { + private lateinit var status: TextView + private lateinit var detail: TextView + private lateinit var progress: ProgressBar + private lateinit var playButton: Button + private lateinit var runtimeButton: Button + + private val ui = Handler(Looper.getMainLooper()) + @Volatile private var busy = false + @Volatile private var available: LinuxRuntimeInstaller.Release? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + status = findViewById(R.id.status) + detail = findViewById(R.id.detail) + progress = findViewById(R.id.progress) + playButton = findViewById(R.id.play) + runtimeButton = findViewById(R.id.runtime) + + playButton.setOnClickListener { startActivity(Intent(this, SessionActivity::class.java)) } + runtimeButton.setOnClickListener { onRuntimeButton() } + + // The session's logs land in Downloads so a failed run can be handed over as a folder + // rather than dug out of app-private storage. targetSdk 28 means the old permission still + // grants exactly that. + if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 1) + } + } + + override fun onResume() { + super.onResume() + render() + if (!busy) Thread({ checkCatalog() }, "catalog").start() + } + + private fun onRuntimeButton() { + if (busy) return + val installed = LinuxRuntimeInstaller.installedVersion(this) + if (installed != null && available?.version == installed) { + // Nothing to install: offer the one destructive thing this screen can do. + AlertDialog.Builder(this) + .setTitle(R.string.remove_runtime) + .setMessage(R.string.remove_runtime_message) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.remove) { _, _ -> + Thread({ + LinuxRuntimeInstaller.uninstall(this) + ui.post { render() } + }, "uninstall").start() + } + .show() + return + } + val release = available + if (release == null) { + Thread({ checkCatalog() }, "catalog").start() + return + } + install(release) + } + + private fun install(release: LinuxRuntimeInstaller.Release) { + busy = true + render() + Thread({ + val ok = LinuxRuntimeInstaller.install(this, release) { stage, percent -> + ui.post { + progress.isIndeterminate = percent < 0 + if (percent >= 0) progress.progress = percent + detail.text = if (percent >= 0) "$stage $percent%" else stage + } + } + busy = false + ui.post { + if (!ok) detail.text = getString(R.string.install_failed) + render() + } + }, "install").start() + } + + private fun checkCatalog() { + val release = LinuxRuntimeInstaller.fetchRelease() + if (release != null) available = release + Log.i(TAG, "catalog: " + (release?.version ?: "unreachable")) + ui.post { render() } + } + + private fun render() { + val installed = LinuxRuntimeInstaller.installedVersion(this) + val ready = LinuxRuntime.isInstalled(this) + progress.visibility = if (busy) View.VISIBLE else View.GONE + playButton.isEnabled = ready && !busy + runtimeButton.isEnabled = !busy + + val offered = available + when { + busy -> { + status.setText(R.string.working) + runtimeButton.setText(R.string.working) + } + !ready -> { + status.setText(R.string.runtime_missing) + runtimeButton.setText(R.string.install_runtime) + detail.text = if (offered != null) { + getString(R.string.runtime_download_size, + offered.version, FileUtils.sizeToString(offered.size)) + } else { + getString(R.string.catalog_unreachable) + } + } + offered != null && offered.version != installed -> { + status.setText(R.string.ready) + runtimeButton.setText(R.string.update_runtime) + detail.text = getString(R.string.runtime_update, installed ?: "?", offered.version) + } + else -> { + status.setText(R.string.ready) + runtimeButton.setText(R.string.remove_runtime) + detail.text = getString(R.string.runtime_installed, installed ?: "?") + } + } + } + + companion object { + private const val TAG = "MainActivity" + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/SessionActivity.kt b/app/src/main/java/com/the412banner/steamdeck/SessionActivity.kt new file mode 100644 index 0000000000..83eb9626bb --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/SessionActivity.kt @@ -0,0 +1,450 @@ +package com.the412banner.steamdeck + +import android.app.Activity +import android.os.Build +import android.os.Bundle +import android.os.Environment +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.view.Choreographer +import android.view.KeyEvent +import android.view.MotionEvent +import android.view.SurfaceHolder +import android.view.SurfaceView +import android.view.View +import android.view.WindowManager +import android.widget.TextView +import android.widget.FrameLayout +import com.the412banner.steamdeck.audio.PulseAudioComponent +import com.the412banner.steamdeck.core.EnvVars +import com.the412banner.steamdeck.core.EnvironmentComponent +import com.the412banner.steamdeck.core.FileUtils +import com.the412banner.steamdeck.core.ProcessHelper +import com.the412banner.steamdeck.gpu.TurnipDriver +import com.the412banner.steamdeck.input.FakeInputWriter +import com.the412banner.steamdeck.input.PadBridge +import com.the412banner.steamdeck.runtime.LinuxNetworkLinkComponent +import com.the412banner.steamdeck.runtime.LinuxRuntime +import com.the412banner.steamdeck.wayland.WaylandCompositor +import java.io.File +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +/** + * The session: our Wayland compositor on this activity's Surface, and gamescope plus Valve's + * native arm64 Steam client running under proot inside the Linux runtime, presenting into it. + * + * Nothing here is Wine. proot and the session script are the whole of the guest side, and the + * activity's own job is three things: keep a Surface under the compositor, feed it input, and + * hold the session's host-side components (audio, the network link, the proot process) for as + * long as the client is up. + * + * Ported from Bannerlator's XServerDisplayActivity.setupLinuxSession, which in turn follows + * WinNative's gamescope runtime (GPL-3.0). + */ +class SessionActivity : Activity(), SurfaceHolder.Callback { + private lateinit var surfaceView: SurfaceView + private lateinit var statusView: TextView + private val components = ArrayList<EnvironmentComponent>() + private var padBridge: PadBridge? = null + private var compositorStarted = false + private var sessionStarted = false + private var finishing = false + private var sessionPid = -1 + private var vsyncRunning = false + private lateinit var sessionLog: File + + private val vsyncCallback = object : Choreographer.FrameCallback { + override fun doFrame(frameTimeNanos: Long) { + WaylandCompositor.nativeVsync(frameTimeNanos) + if (vsyncRunning) Choreographer.getInstance().postFrameCallback(this) + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + goFullscreen() + + if (!LinuxRuntime.isInstalled(this)) { + Log.e(TAG, "the Linux runtime is not installed") + finish() + return + } + + val root = FrameLayout(this) + surfaceView = SurfaceView(this) + surfaceView.holder.addCallback(this) + root.addView(surfaceView) + // Until the client's first frame arrives there is nothing on screen for a minute or more + // on a first run, so the session's own milestones are shown instead of a black panel. + statusView = TextView(this).apply { + setPadding(48, 48, 48, 48) + setTextColor(0xFFDDDDDD.toInt()) + textSize = 14f + text = getString(R.string.session_starting) + } + root.addView(statusView) + setContentView(root) + + WaylandCompositor.setFirstFrameListener { + runOnUiThread { statusView.visibility = View.GONE } + } + } + + // ── Compositor ────────────────────────────────────────────────────────────────────────── + + override fun surfaceCreated(holder: SurfaceHolder) { + if (compositorStarted) { + WaylandCompositor.nativeSetSurface(holder.surface) + return + } + compositorStarted = true + + val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() } + // The compositor hands this keymap to wl_keyboard clients, which is how the guest reads + // the evdev codes we inject. + FileUtils.copyAsset(this, "wayland/keymap.xkb", File(runtimeDir, "keymap.xkb")) + + // Turnip, not the system Adreno driver: importing the dma-bufs gamescope commits needs + // VK_EXT_image_drm_format_modifier, which the system driver does not implement. + val turnip = TurnipDriver(this) + val driverId = turnip.install() + val driverPath = driverId?.let { turnip.driverPath(it) } + val libraryName = driverId?.let { turnip.libraryName(it) } + + val size = outputSize() + WaylandCompositor.nativeSetOutputSize(size.first, size.second) + WaylandCompositor.nativeSetOutputRefreshRate(refreshHz()) + WaylandCompositor.nativeStartWithSurface( + holder.surface, runtimeDir.path, driverPath, libraryName, + applicationInfo.nativeLibraryDir, + ) + vsyncRunning = true + Choreographer.getInstance().postFrameCallback(vsyncCallback) + + Thread({ startSession(runtimeDir, size) }, "session-start").start() + } + + override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {} + + override fun surfaceDestroyed(holder: SurfaceHolder) { + WaylandCompositor.nativeSetSurface(null) + } + + /** + * The size the session renders at. gamescope is told this and scales its output onto whatever + * the panel is, so a 1440p phone can run the client at 1080p without the client knowing. + */ + private fun outputSize(): Pair<Int, Int> { + val metrics = resources.displayMetrics + var width = maxOf(metrics.widthPixels, metrics.heightPixels) + var height = minOf(metrics.widthPixels, metrics.heightPixels) + // The client's CEF is the heaviest thing in the session; above 1080p it costs frames for + // nothing anyone can see on a phone panel. + if (height > 1080) { + width = width * 1080 / height + height = 1080 + } + // Odd sizes upset the scaler; both dimensions even is what every mode here would be. + return Pair(width and 1.inv(), height and 1.inv()) + } + + private fun refreshHz(): Float { + val display = if (Build.VERSION.SDK_INT >= 30) display else windowManager.defaultDisplay + val hz = display?.refreshRate ?: 60f + return if (hz > 1f) hz else 60f + } + + // ── Session ───────────────────────────────────────────────────────────────────────────── + + private fun startSession(runtimeDir: File, size: Pair<Int, Int>) { + try { + LinuxRuntime.writeAccounts(this) + } catch (e: Exception) { + Log.e(TAG, "could not write the guest's passwd/group", e) + endSession(-1) + return + } + + val root = LinuxRuntime.rootDir(this) + val sessionRoot = LinuxRuntime.sessionRoot(this).apply { mkdirs() } + stageSessionFiles(root) + + val logDir = LinuxRuntime.debugLogDir().apply { mkdirs() } + val stamp = SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US).format(Date()) + sessionLog = File(logDir, "session-$stamp.log") + + val guest = ArrayList<String>() + guest.add("/usr/bin/env") + guest.add("-i") + guest.add("HOME=/root") + guest.add("USER=root") + guest.add("PATH=/usr/local/bin:/usr/bin:/bin") + guest.add("TERM=xterm-256color") + guest.add("LANG=C.UTF-8") + guest.add("XDG_RUNTIME_DIR=" + runtimeDir.path) + guest.add("XDG_SESSION_TYPE=wayland") + guest.add("WAYLAND_DISPLAY=wayland-0") + guest.add("GAMESCOPE_FORCE_GENERAL_QUEUE=1") + // Steam's CEF needs GL and the rootfs ships no native GL driver: route it through Zink. + guest.add("MESA_LOADER_DRIVER_OVERRIDE=zink") + guest.add("GALLIUM_DRIVER=zink") + guest.add("LIBGL_KOPPER_DRI2=true") + LinuxRuntime.vulkanIcd(this)?.let { guest.add("VK_ICD_FILENAMES=" + it.path) } + + val pulse = PulseAudioComponent(this) + pulse.setContext(this) + guest.add("PULSE_SERVER=unix:" + pulse.socket().absolutePath) + components.add(pulse) + + guest.add("BL_WIDTH=" + size.first) + guest.add("BL_HEIGHT=" + size.second) + guest.add("BL_FPS=0") + // What gamescope advertises as the refresh rate, and what a game reads as the display's. + // Left unset it says 60, and a 120 Hz panel then offers only 60 Hz in game settings. + guest.add("BL_REFRESH=" + Math.round(refreshHz())) + guest.add("BL_LOG=" + sessionLog.path) + guest.add("BL_DEBUG_DIR=" + File(logDir, "session-$stamp").path) + + // Controllers. WinHandler is a Wine thing and there is none here, so the pad is published + // into the rings by PadBridge instead; the reader is the same interposer either way. + val fakeInputDir = File(sessionRoot, "dev/input").apply { mkdirs() } + val controllersOn = !File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists() + if (controllersOn) { + FakeInputWriter.prepareRingSlots(fakeInputDir, 4) + guest.add("FAKE_EVDEV_DIR=" + fakeInputDir.path) + val rings = FakeInputWriter.getRingEnv(fakeInputDir) + if (!rings.isNullOrEmpty()) guest.add("FAKE_EVDEV_MEMFD_PATHS=$rings") + // SDL and Steam key their mapping database on bus+vendor+product: only a known + // identity gets the standard layout without the user configuring the pad by hand. + guest.add("FAKE_EVDEV_IDENTITY=xbox360") + guest.add("FAKE_EVDEV_VIBRATION=1") + guest.add("FAKE_EVDEV_STEAM_VIRTUAL=1") + // No udev runs in the runtime: SDL and hidapi scan /dev/input themselves, and the + // netlink monitor they open anyway is answered by the session shim's stand-in. + guest.add("SDL_JOYSTICK_DISABLE_UDEV=1") + guest.add("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV=1") + guest.add("SDL_JOYSTICK_HIDAPI=0") + if (File(Environment.getExternalStorageDirectory(), PAD_LOG_SWITCH).exists()) { + guest.add("FAKE_EVDEV_LOG=1") + } + padBridge = PadBridge(fakeInputDir).also { it.start() } + } + guest.add(LinuxRuntime.SESSION_SCRIPT) + guest.add(LinuxRuntime.MODE_STEAM) + + // Android has no /dev/shm; the cache stands in for it and, unlike the real thing, keeps + // whatever a session leaves behind. The client abandons tens of megabytes of streams a run. + FileUtils.clear(File(cacheDir, "shm")) + + val binds = ArrayList<String>() + // Apps may not list /dev/input, so the fake nodes are bound in as the whole directory. + if (controllersOn) binds.add(fakeInputDir.path + ":/dev/input") + + val command = LinuxRuntime.command( + this, sessionRoot, runtimeDir, Environment.getExternalStorageDirectory(), binds, guest, + ) + + val hostEnv = EnvVars() + hostEnv.put("PROOT_LOADER", LinuxRuntime.prootLoader(this).path) + hostEnv.put("PROOT_TMP_DIR", cacheDir.path) + // proot links against a libtalloc beside it, and Android's linker does not search an + // executable's own directory: unnamed, the process dies before it starts and says so only + // in `logcat -b crash`. + val prootLibs = LinuxRuntime.prootLibraryPath(this) + if (prootLibs.isNotEmpty()) hostEnv.put("LD_LIBRARY_PATH", prootLibs) + + val networkLink = LinuxNetworkLinkComponent(this, LinuxRuntime.rootDir(this)) + networkLink.setContext(this) + networkLink.publish() + components.add(networkLink) + components.forEach { it.start() } + + watchSessionLog() + val line = command.joinToString(" ") { it.replace(" ", "\\ ") } + sessionPid = ProcessHelper.exec(line, hostEnv.toStringArray(), root, { status -> + Log.i(TAG, "session ended: $status") + endSession(status) + }, null) + sessionStarted = true + Log.i(TAG, "session pid $sessionPid, log ${sessionLog.path}") + } + + /** + * The libraries and scripts the session runs, refreshed from the apk at every launch. + * + * The runtime image carries its own copies, but a runtime installed months ago carries the + * copies of that day and a device has no way to replace them from outside the app. Staging + * them here is how a fix inside the session shim, the controller reader or one of the scripts + * reaches an already-installed runtime without a ~790 MB re-download. Each lands through a + * rename, so a session that still has one mapped keeps the file it opened. + */ + private fun stageSessionFiles(root: File) { + val files = arrayOf( + "libblsession.so" to "usr/local/lib/libblsession.so", + "libfakeinput.so" to "usr/local/lib/libfakeinput.so", + "usr/local/bin/bannerlator-session" to "usr/local/bin/bannerlator-session", + "usr/local/bin/bannerlator-steam-compat" to "usr/local/bin/bannerlator-steam-compat", + "usr/local/bin/bannerlator-steam-install" to "usr/local/bin/bannerlator-steam-install", + "usr/local/bin/bannerlator-steam-library" to "usr/local/bin/bannerlator-steam-library", + "usr/local/bin/bannerlator-seed-redists" to "usr/local/bin/bannerlator-seed-redists", + ) + for ((asset, relative) in files) { + val target = File(root, relative) + val staged = File(target.parentFile, target.name + ".staged") + var installed = false + try { + target.parentFile?.mkdirs() + assets.open("linuxfs/$asset").use { input -> + staged.outputStream().use { output -> FileUtils.copy(input, output) } + } + installed = staged.setExecutable(true, false) && staged.renameTo(target) + } catch (e: Exception) { + Log.w(TAG, "could not stage $relative", e) + } finally { + if (!installed) staged.delete() + } + if (!installed) Log.e(TAG, "$relative NOT staged") + } + // What every process in the session preloads. LD_PRELOAD in the environment would not + // survive: the Steam client rebuilds it for each process it starts and appends its own + // overlay entry without a separator, which silently drops whatever was there. + val preload = StringBuilder("/usr/local/lib/libblsession.so\n") + if (!File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()) { + preload.append("/usr/local/lib/libfakeinput.so\n") + } + val etc = File(root, "etc").apply { mkdirs() } + val staged = File(etc, "ld.so.preload.staged") + if (!FileUtils.writeString(staged, preload.toString()) || !staged.renameTo(File(etc, "ld.so.preload"))) { + staged.delete() + Log.e(TAG, "could not write ld.so.preload") + } + } + + /** Mirrors the session script's "== STEP" milestones onto the screen while it starts. */ + private fun watchSessionLog() { + val handler = Handler(Looper.getMainLooper()) + Thread({ + var shown = "" + while (!finishing) { + try { + Thread.sleep(500) + val text = FileUtils.readString(sessionLog) ?: continue + val step = text.lineSequence().lastOrNull { it.startsWith("== STEP") } ?: continue + val message = step.substringAfter("== STEP ").substringAfter(' ') + if (message != shown) { + shown = message + handler.post { if (statusView.visibility == View.VISIBLE) statusView.text = message } + } + } catch (e: InterruptedException) { + return@Thread + } catch (ignored: Exception) { + } + } + }, "session-log").start() + } + + private fun endSession(status: Int) { + if (finishing) return + finishing = true + runOnUiThread { + if (status != 0) { + statusView.visibility = View.VISIBLE + statusView.text = getString(R.string.session_ended, status, sessionLogName()) + } + // A moment on screen, so a failure is readable rather than a flash of black. + Handler(Looper.getMainLooper()).postDelayed({ finish() }, if (status == 0) 0 else 4000) + } + } + + private fun sessionLogName(): String = + if (::sessionLog.isInitialized) "${LinuxRuntime.DEBUG_LOG_DIR}/${sessionLog.name}" else "-" + + // ── Input ─────────────────────────────────────────────────────────────────────────────── + + override fun dispatchKeyEvent(event: KeyEvent): Boolean { + if (padBridge?.onKeyEvent(event) == true) return true + return super.dispatchKeyEvent(event) + } + + override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean { + if (padBridge?.onMotionEvent(event) == true) return true + return super.dispatchGenericMotionEvent(event) + } + + /** + * Touch as a mouse: where you touch is where the pointer goes, and a tap is a left click. + * The compositor's pointer space is a fixed 1920x1080 whatever the output size, so the view's + * coordinates are scaled into it. + */ + override fun onTouchEvent(event: MotionEvent): Boolean { + val width = surfaceView.width.takeIf { it > 0 } ?: return false + val height = surfaceView.height.takeIf { it > 0 } ?: return false + val action = when (event.actionMasked) { + MotionEvent.ACTION_DOWN -> 0 + MotionEvent.ACTION_MOVE -> 1 + MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> 2 + else -> return false + } + val x = (event.x / width * 1920f).toInt().coerceIn(0, 1919) + val y = (event.y / height * 1080f).toInt().coerceIn(0, 1079) + WaylandCompositor.nativeSendPointer(action, x, y) + return true + } + + // ── Lifecycle ─────────────────────────────────────────────────────────────────────────── + + override fun onWindowFocusChanged(hasFocus: Boolean) { + super.onWindowFocusChanged(hasFocus) + if (hasFocus) goFullscreen() + } + + private fun goFullscreen() { + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + or View.SYSTEM_UI_FLAG_FULLSCREEN + or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + or View.SYSTEM_UI_FLAG_LAYOUT_STABLE + or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) + if (Build.VERSION.SDK_INT >= 28) { + window.attributes = window.attributes.apply { + layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } + } + } + + override fun onDestroy() { + finishing = true + vsyncRunning = false + padBridge?.stop() + // proot runs with --kill-on-exit, so killing it takes the whole guest tree with it. + if (sessionPid != -1) { + android.os.Process.killProcess(sessionPid) + sessionPid = -1 + } + components.reversed().forEach { + try { + it.stop() + } catch (e: Exception) { + Log.w(TAG, "stopping ${it.javaClass.simpleName}", e) + } + } + components.clear() + FakeInputWriter.releaseAllRingSlots() + WaylandCompositor.setFirstFrameListener(null) + super.onDestroy() + } + + companion object { + private const val TAG = "SessionActivity" + /** Turns the whole controller feature off, for a true baseline on a device we cannot reach. */ + private const val NO_PAD_SWITCH = "Download/steamdeck-no-pad" + /** Traces every interposer call into the session log. */ + private const val PAD_LOG_SWITCH = "Download/steamdeck-pad-log" + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/audio/PulseAudioComponent.java b/app/src/main/java/com/the412banner/steamdeck/audio/PulseAudioComponent.java new file mode 100644 index 0000000000..622938a627 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/audio/PulseAudioComponent.java @@ -0,0 +1,111 @@ +package com.the412banner.steamdeck.audio; + +import android.content.Context; +import android.os.Process; +import android.util.Log; + +import com.the412banner.steamdeck.core.FileUtils; +import com.the412banner.steamdeck.core.EnvironmentComponent; +import com.the412banner.steamdeck.core.ProcessHelper; +import com.the412banner.steamdeck.core.TarZst; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; + +/** + * PulseAudio 13.0 running in the app process, with Android's AAudio as its sink, so the guest's + * libpulse clients (Steam and everything it launches) have a server to talk to. The socket lives + * in the app's files directory and is bound into the session at its own path, so PULSE_SERVER + * needs no translating. + * + * <p>Ported down from Bannerlator's component: no sink suspend/resume and no route-change + * recreate — those need the pasink native client, and a session here is a foreground activity + * that does not background the way a game container does. + */ +public class PulseAudioComponent extends EnvironmentComponent { + private static final String TAG = "PulseAudio"; + /** Where the guest reaches the daemon; the session exports PULSE_SERVER=unix:<this>. */ + public static final String SOCKET_NAME = "PS0"; + + private final File workingDir; + private int pid = -1; + + public PulseAudioComponent(Context context) { + this.workingDir = new File(context.getFilesDir(), "pulseaudio"); + } + + public File socket() { + return new File(workingDir, SOCKET_NAME); + } + + @Override + public void start() { + stop(); + if (!workingDir.isDirectory()) { + //noinspection ResultOfMethodCallIgnored + workingDir.mkdirs(); + FileUtils.chmod(workingDir, 0771); + } + // The loadable modules (module-aaudio-sink and the native protocol) ride in the apk; the + // daemon and its libraries come from the native library directory, the one place an app + // may execute a file from. + if (!new File(workingDir, "modules/arm64/module-aaudio-sink.so").isFile()) { + TarZst.extractAsset(context, "pulseaudio.tzst", workingDir); + } + copyFromLibraryDir(); + + //noinspection ResultOfMethodCallIgnored + socket().delete(); + FileUtils.writeString(new File(workingDir, "default.pa"), String.join("\n", + "load-module module-native-protocol-unix auth-anonymous=1 auth-cookie-enabled=0 socket=\"" + + socket().getAbsolutePath() + "\"", + // volume=1.0 is not optional: with no volume argument module-aaudio-sink defaults + // the sink to 0% and the session plays silence. + "load-module module-aaudio-sink performance_mode=1 adaptive=1 volume=1.0", + "set-default-sink AAudioSink")); + + File modules = new File(workingDir, "modules/arm64"); + ArrayList<String> env = new ArrayList<>(); + env.add("LD_LIBRARY_PATH=/system/lib64:" + modules + ":" + workingDir.getAbsolutePath()); + env.add("HOME=" + workingDir); + env.add("TMPDIR=" + workingDir); + + String command = workingDir.getAbsolutePath() + "/libpulseaudio.so" + + " --system=false --disable-shm=true --fail=false" + + " -n --file=default.pa --daemonize=false --use-pid-file=false --exit-idle-time=-1"; + pid = ProcessHelper.exec(command, env.toArray(new String[0]), workingDir, null, + line -> Log.i(TAG, line)); + } + + @Override + public void stop() { + if (pid != -1) { + Process.killProcess(pid); + pid = -1; + } + } + + private void copyFromLibraryDir() { + String[] libs = {"libltdl.so", "libpulseaudio.so", "libpulse.so", + "libpulsecommon-13.0.so", "libpulsecore-13.0.so"}; + ClassLoader loader = PulseAudioComponent.class.getClassLoader(); + for (String lib : libs) { + URL resource = loader != null ? loader.getResource("lib/arm64-v8a/" + lib) : null; + if (resource == null) { + Log.w(TAG, lib + " missing from the apk"); + continue; + } + File destination = new File(workingDir, lib); + try (InputStream in = resource.openStream()) { + Files.copy(in, destination.toPath(), StandardCopyOption.REPLACE_EXISTING); + FileUtils.chmod(destination, 0771); + } catch (Exception e) { + Log.w(TAG, "copy " + lib, e); + } + } + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/Callback.java b/app/src/main/java/com/the412banner/steamdeck/core/Callback.java new file mode 100644 index 0000000000..d9c07730a9 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/Callback.java @@ -0,0 +1,6 @@ +package com.the412banner.steamdeck.core; + +/** One-argument callback, kept so the ported runtime classes read as they did in Bannerlator. */ +public interface Callback<T> { + void call(T value); +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/Downloader.java b/app/src/main/java/com/the412banner/steamdeck/core/Downloader.java new file mode 100644 index 0000000000..048f4a5ff2 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/Downloader.java @@ -0,0 +1,112 @@ +package com.the412banner.steamdeck.core; + +import android.util.Log; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +/** + * The two fetches this app makes: the runtime catalog (a few hundred bytes of JSON) and the + * runtime tarball itself (~790 MB). Plain HttpURLConnection — nothing here needs a client library, + * and one fewer dependency is one fewer thing that can fail a release build. + */ +public final class Downloader { + private static final String TAG = "Downloader"; + private static final int TIMEOUT_MS = 30_000; + + private Downloader() {} + + public static String downloadString(String url) { + HttpURLConnection connection = null; + try { + connection = open(url); + if (connection.getResponseCode() / 100 != 2) { + Log.w(TAG, url + " -> HTTP " + connection.getResponseCode()); + return null; + } + try (InputStream in = connection.getInputStream(); + ByteArrayOutputStream out = new ByteArrayOutputStream()) { + FileUtils.copy(in, out); + return new String(out.toByteArray(), StandardCharsets.UTF_8); + } + } catch (Exception e) { + Log.w(TAG, "GET " + url, e); + return null; + } finally { + if (connection != null) connection.disconnect(); + } + } + + /** + * Downloads to {@code destination}, reporting a 0..1 fraction (or -1 when the server sends no + * length). {@code resume} continues a partial file with a Range request, which is what makes a + * 790 MB download survive a dropped connection instead of starting over. + */ + public static boolean downloadFile(String url, File destination, boolean resume, + Callback<Float> progress) { + HttpURLConnection connection = null; + long have = resume && destination.isFile() ? destination.length() : 0; + try { + connection = open(url); + if (have > 0) connection.setRequestProperty("Range", "bytes=" + have + "-"); + int code = connection.getResponseCode(); + boolean appending = code == HttpURLConnection.HTTP_PARTIAL; + if (code / 100 != 2) { + // The server ignored or refused the range: start the file again. + if (have > 0) { + connection.disconnect(); + //noinspection ResultOfMethodCallIgnored + destination.delete(); + return downloadFile(url, destination, false, progress); + } + Log.w(TAG, url + " -> HTTP " + code); + return false; + } + if (!appending) have = 0; + long length = connection.getContentLengthLong(); + long total = length < 0 ? -1 : length + have; + File parent = destination.getParentFile(); + if (parent != null && !parent.isDirectory()) //noinspection ResultOfMethodCallIgnored + parent.mkdirs(); + long written = have; + try (InputStream in = new BufferedInputStream(connection.getInputStream(), 1 << 16); + OutputStream out = new FileOutputStream(destination, appending)) { + byte[] buffer = new byte[1 << 16]; + long lastReport = 0; + for (int read = in.read(buffer); read > 0; read = in.read(buffer)) { + out.write(buffer, 0, read); + written += read; + // A callback per 64 KB would be tens of thousands of UI hops; once per MB is + // enough to move a progress bar smoothly. + if (progress != null && written - lastReport > (1 << 20)) { + lastReport = written; + progress.call(total > 0 ? written / (float) total : -1f); + } + } + } + if (progress != null) progress.call(1f); + return total <= 0 || written >= total; + } catch (Exception e) { + Log.w(TAG, "download " + url, e); + return false; + } finally { + if (connection != null) connection.disconnect(); + } + } + + private static HttpURLConnection open(String url) throws java.io.IOException { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setConnectTimeout(TIMEOUT_MS); + connection.setReadTimeout(TIMEOUT_MS); + connection.setInstanceFollowRedirects(true); + connection.setRequestProperty("User-Agent", "SteamDeck-Android"); + return connection; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/EnvVars.java b/app/src/main/java/com/the412banner/steamdeck/core/EnvVars.java new file mode 100644 index 0000000000..bb3a419a4c --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/EnvVars.java @@ -0,0 +1,31 @@ +package com.the412banner.steamdeck.core; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** An ordered NAME=VALUE set, in the shape {@code ProcessBuilder} and proot want it. */ +public class EnvVars { + private final Map<String, String> vars = new LinkedHashMap<>(); + + public EnvVars put(String name, String value) { + vars.put(name, value); + return this; + } + + public void putAll(EnvVars other) { + if (other != null) vars.putAll(other.vars); + } + + public String get(String name) { return vars.get(name); } + + public boolean has(String name) { return vars.containsKey(name); } + + public boolean isEmpty() { return vars.isEmpty(); } + + public String[] toStringArray() { + String[] out = new String[vars.size()]; + int i = 0; + for (Map.Entry<String, String> e : vars.entrySet()) out[i++] = e.getKey() + "=" + e.getValue(); + return out; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/EnvironmentComponent.java b/app/src/main/java/com/the412banner/steamdeck/core/EnvironmentComponent.java new file mode 100644 index 0000000000..2b3f31d542 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/EnvironmentComponent.java @@ -0,0 +1,17 @@ +package com.the412banner.steamdeck.core; + +import android.content.Context; + +/** + * One piece of a running session — the audio daemon, the network-link file, the session process + * itself. The session starts them in order and stops them in reverse. + */ +public abstract class EnvironmentComponent { + protected Context context; + + public void setContext(Context context) { this.context = context; } + + public abstract void start(); + + public abstract void stop(); +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/FileUtils.java b/app/src/main/java/com/the412banner/steamdeck/core/FileUtils.java new file mode 100644 index 0000000000..3c8839ecee --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/FileUtils.java @@ -0,0 +1,109 @@ +package com.the412banner.steamdeck.core; + +import android.content.Context; +import android.system.ErrnoException; +import android.system.Os; +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +public final class FileUtils { + private static final String TAG = "FileUtils"; + + private FileUtils() {} + + /** Recursive delete that does not follow symlinks — a rootfs is full of them. */ + public static void delete(File file) { + if (file == null || !file.exists() && !isSymlink(file)) return; + if (file.isDirectory() && !isSymlink(file)) { + File[] children = file.listFiles(); + if (children != null) for (File child : children) delete(child); + } + //noinspection ResultOfMethodCallIgnored + file.delete(); + } + + private static boolean isSymlink(File file) { + try { + return Files.isSymbolicLink(file.toPath()); + } catch (Exception e) { + return false; + } + } + + /** Empties a directory without removing it. */ + public static void clear(File dir) { + if (dir == null || !dir.isDirectory()) return; + File[] children = dir.listFiles(); + if (children != null) for (File child : children) delete(child); + } + + public static boolean writeString(File file, String content) { + try { + File parent = file.getParentFile(); + if (parent != null && !parent.isDirectory()) //noinspection ResultOfMethodCallIgnored + parent.mkdirs(); + Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8)); + return true; + } catch (IOException e) { + Log.w(TAG, "write " + file, e); + return false; + } + } + + public static String readString(File file) { + try { + return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); + } catch (IOException e) { + return null; + } + } + + public static void symlink(String target, String linkPath) { + try { + Os.symlink(target, linkPath); + } catch (ErrnoException e) { + Log.w(TAG, "symlink " + linkPath + " -> " + target + ": " + e.getMessage()); + } + } + + public static void chmod(File file, int mode) { + try { + Os.chmod(file.getAbsolutePath(), mode); + } catch (ErrnoException e) { + Log.w(TAG, "chmod " + file + ": " + e.getMessage()); + } + } + + /** Copies an asset out of the apk, creating the parent directory. */ + public static boolean copyAsset(Context context, String assetPath, File destination) { + File parent = destination.getParentFile(); + if (parent != null && !parent.isDirectory()) //noinspection ResultOfMethodCallIgnored + parent.mkdirs(); + try (InputStream in = context.getAssets().open(assetPath); + OutputStream out = new FileOutputStream(destination)) { + copy(in, out); + return true; + } catch (IOException e) { + Log.w(TAG, "copy asset " + assetPath, e); + return false; + } + } + + public static void copy(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1 << 16]; + for (int read = in.read(buffer); read > 0; read = in.read(buffer)) out.write(buffer, 0, read); + } + + public static String sizeToString(long bytes) { + if (bytes >= 1L << 30) return String.format(java.util.Locale.US, "%.1f GB", bytes / (float) (1L << 30)); + if (bytes >= 1L << 20) return String.format(java.util.Locale.US, "%.0f MB", bytes / (float) (1L << 20)); + return bytes + " B"; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/ProcessHelper.java b/app/src/main/java/com/the412banner/steamdeck/core/ProcessHelper.java new file mode 100644 index 0000000000..98d9f8c6df --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/ProcessHelper.java @@ -0,0 +1,113 @@ +package com.the412banner.steamdeck.core; + +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * Starts the session's host processes — proot and the audio daemon — and reports the exit status. + * The pid is read out of the hidden field on {@code java.lang.Process} because stopping a session + * means killing that exact process: proot runs with {@code --kill-on-exit}, so the whole guest + * tree goes with it. + */ +public final class ProcessHelper { + private static final String TAG = "ProcessHelper"; + + private ProcessHelper() {} + + public static int exec(String command, String[] envp, File workingDir) { + return exec(command, envp, workingDir, null, null); + } + + /** + * @param lineCallback receives stdout and stderr line by line, or null to discard both. The + * Linux session sends everything to its own log file, so nothing is passed + * here for it; the audio daemon is the one that benefits. + */ + public static int exec(String command, String[] envp, File workingDir, + Callback<Integer> terminationCallback, Callback<String> lineCallback) { + int pid = -1; + try { + ProcessBuilder builder = new ProcessBuilder(splitCommand(command)); + if (workingDir != null) builder.directory(workingDir); + if (envp != null) { + builder.environment().clear(); + for (String entry : envp) { + int eq = entry.indexOf('='); + if (eq > 0) builder.environment().put(entry.substring(0, eq), entry.substring(eq + 1)); + } + } + builder.redirectErrorStream(true); + if (lineCallback == null) builder.redirectOutput(new File("/dev/null")); + Process process = builder.start(); + + Field pidField = process.getClass().getDeclaredField("pid"); + pidField.setAccessible(true); + pid = pidField.getInt(process); + pidField.setAccessible(false); + Log.i(TAG, "started pid " + pid + ": " + command); + + if (lineCallback != null) drain(process.getInputStream(), lineCallback); + if (terminationCallback != null) { + Thread waiter = new Thread(() -> { + int status = -1; + try { + status = process.waitFor(); + } catch (InterruptedException ignored) { + } finally { + terminationCallback.call(status); + } + }, "proc-wait-" + pid); + waiter.setPriority(Thread.NORM_PRIORITY - 1); + waiter.start(); + } + } catch (Exception e) { + Log.e(TAG, "exec " + command, e); + } + return pid; + } + + private static void drain(InputStream stream, Callback<String> lineCallback) { + Thread thread = new Thread(() -> { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) { + for (String line = reader.readLine(); line != null; line = reader.readLine()) { + lineCallback.call(line); + } + } catch (Exception ignored) { + } + }, "proc-out"); + thread.setPriority(Thread.NORM_PRIORITY - 1); + thread.start(); + } + + /** Splits on spaces, honouring backslash-escaped spaces — paths under /data are full of them. */ + public static String[] splitCommand(String command) { + List<String> parts = new ArrayList<>(); + StringBuilder current = new StringBuilder(); + boolean escaped = false; + for (int i = 0; i < command.length(); i++) { + char c = command.charAt(i); + if (escaped) { + current.append(c); + escaped = false; + } else if (c == '\\') { + escaped = true; + } else if (c == ' ') { + if (current.length() > 0) { + parts.add(current.toString()); + current.setLength(0); + } + } else { + current.append(c); + } + } + if (current.length() > 0) parts.add(current.toString()); + return parts.toArray(new String[0]); + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/core/TarZst.java b/app/src/main/java/com/the412banner/steamdeck/core/TarZst.java new file mode 100644 index 0000000000..0681b7f68b --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/core/TarZst.java @@ -0,0 +1,72 @@ +package com.the412banner.steamdeck.core; + +import android.content.Context; +import android.util.Log; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * The small zstd tarballs that ship inside the apk (the Turnip driver, the PulseAudio modules). + * The runtime rootfs is not one of these — it needs hard links and symlinks preserved, which + * {@link com.the412banner.steamdeck.runtime.LinuxRuntimeInstaller} handles itself. + */ +public final class TarZst { + private static final String TAG = "TarZst"; + + private TarZst() {} + + public static boolean extractAsset(Context context, String assetPath, File destination) { + try (InputStream in = context.getAssets().open(assetPath)) { + return extract(in, destination); + } catch (Exception e) { + Log.e(TAG, "extract " + assetPath, e); + return false; + } + } + + public static boolean extract(InputStream source, File destination) { + //noinspection ResultOfMethodCallIgnored + destination.mkdirs(); + try (InputStream in = new ZstdCompressorInputStream(new BufferedInputStream(source, 1 << 16)); + TarArchiveInputStream tar = new TarArchiveInputStream(in)) { + String base = destination.getCanonicalPath() + File.separator; + TarArchiveEntry entry; + while ((entry = tar.getNextTarEntry()) != null) { + File file = new File(destination, entry.getName()); + if (!file.getCanonicalPath().startsWith(base)) continue; + if (entry.isDirectory()) { + //noinspection ResultOfMethodCallIgnored + file.mkdirs(); + continue; + } + File parent = file.getParentFile(); + if (parent != null && !parent.isDirectory()) //noinspection ResultOfMethodCallIgnored + parent.mkdirs(); + if (entry.isSymbolicLink()) { + //noinspection ResultOfMethodCallIgnored + file.delete(); + FileUtils.symlink(entry.getLinkName(), file.getAbsolutePath()); + continue; + } + if (!entry.isFile()) continue; + try (OutputStream out = new FileOutputStream(file)) { + FileUtils.copy(tar, out); + } + if ((entry.getMode() & 0111) != 0) //noinspection ResultOfMethodCallIgnored + file.setExecutable(true, false); + } + return true; + } catch (Exception e) { + Log.e(TAG, "extract into " + destination, e); + return false; + } + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/gpu/TurnipDriver.java b/app/src/main/java/com/the412banner/steamdeck/gpu/TurnipDriver.java new file mode 100644 index 0000000000..abc0523f0e --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/gpu/TurnipDriver.java @@ -0,0 +1,118 @@ +package com.the412banner.steamdeck.gpu; + +import android.content.Context; +import android.os.Environment; +import android.util.Log; + +import com.the412banner.steamdeck.core.FileUtils; +import com.the412banner.steamdeck.core.TarZst; + +import org.json.JSONObject; + +import java.io.File; + +/** + * The Vulkan driver the in-app compositor runs on. It has to be Turnip: the system Adreno driver + * does not implement VK_EXT_image_drm_format_modifier, so importing the dma-bufs gamescope hands + * over fails and the session renders nothing. Two builds ship in the apk, one per Adreno + * generation, and the GPU decides which is unpacked. + * + * <p>The guest's own Turnip is a different copy entirely — a glibc build inside the rootfs, found + * through its ICD manifest. This one is the bionic build the app process loads through adrenotools. + */ +public final class TurnipDriver { + private static final String TAG = "TurnipDriver"; + /** Adreno 7xx (8 Gen 2/3, e.g. the Pocket FIT's A750). */ + private static final String DRIVER_A7XX = "turnip25.1.0"; + /** Adreno 8xx (8 Elite, e.g. a Fold 8's A830). */ + private static final String DRIVER_A8XX = "turnip-sdk36"; + /** Overrides the pick, for a device we cannot reach: a7xx, a8xx or system. */ + private static final String OVERRIDE_FILE = "Download/steamdeck-driver"; + + private final Context context; + private final File contentDir; + + public TurnipDriver(Context context) { + this.context = context; + this.contentDir = new File(context.getFilesDir(), "graphics_driver"); + } + + /** Absolute directory holding the driver, with a trailing slash — adrenotools wants both. */ + public String driverPath(String driverId) { + return new File(contentDir, driverId).getAbsolutePath() + "/"; + } + + public String libraryName(String driverId) { + File meta = new File(new File(contentDir, driverId), "meta.json"); + String content = FileUtils.readString(meta); + if (content == null) return null; + try { + return new JSONObject(content).optString("libraryName", null); + } catch (Exception e) { + Log.w(TAG, "meta.json for " + driverId, e); + return null; + } + } + + /** + * Unpacks the driver this device needs and returns its id, or null to fall back to the system + * Vulkan loader (which means a black session on Adreno, but is better than refusing to start + * on a GPU neither build covers). + */ + public String install() { + String id = choose(); + if (id == null) return null; + File dir = new File(contentDir, id); + if (!new File(dir, "meta.json").isFile()) { + FileUtils.delete(dir); + if (!TarZst.extractAsset(context, "graphics_driver/adrenotools-" + id + ".tzst", dir)) { + Log.e(TAG, "could not unpack " + id); + FileUtils.delete(dir); + return null; + } + } + String library = libraryName(id); + if (library == null || !new File(dir, library).isFile()) { + Log.e(TAG, id + " unpacked without " + library); + return null; + } + Log.i(TAG, "graphics driver " + id + " (" + library + ")"); + return id; + } + + private String choose() { + File override = new File(Environment.getExternalStorageDirectory(), OVERRIDE_FILE); + String forced = override.isFile() ? FileUtils.readString(override) : null; + if (forced != null) { + forced = forced.trim().toLowerCase(java.util.Locale.US); + Log.i(TAG, "driver forced by " + override + ": " + forced); + if (forced.startsWith("system")) return null; + if (forced.startsWith("a8")) return DRIVER_A8XX; + if (forced.startsWith("a7")) return DRIVER_A7XX; + } + String model = gpuModel(); + Log.i(TAG, "gpu model: " + (model == null ? "unknown" : model)); + if (model != null) { + // "Adreno750", "adreno_830" — the generation is the first digit of the three. + java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\\d)\\d\\d").matcher(model); + if (m.find()) { + char generation = m.group(1).charAt(0); + if (generation >= '8') return DRIVER_A8XX; + if (generation == '7') return DRIVER_A7XX; + } + } + // Nothing to go on: Android 16 shipped with the 8 Elite, so treat a new device as 8xx. + return android.os.Build.VERSION.SDK_INT >= 36 ? DRIVER_A8XX : DRIVER_A7XX; + } + + /** KGSL names the GPU here, and this file is world-readable where /dev/kgsl-3d0 is not. */ + private static String gpuModel() { + for (String path : new String[]{ + "/sys/class/kgsl/kgsl-3d0/gpu_model", + "/sys/class/kgsl/kgsl-3d0/gpu_chipid"}) { + String value = FileUtils.readString(new File(path)); + if (value != null && !value.trim().isEmpty()) return value.trim(); + } + return null; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/input/FakeInputWriter.java b/app/src/main/java/com/the412banner/steamdeck/input/FakeInputWriter.java new file mode 100644 index 0000000000..3fe692f845 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/input/FakeInputWriter.java @@ -0,0 +1,689 @@ +package com.the412banner.steamdeck.input; + +import android.util.Log; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.FileChannel; + +/** + * Fake evdev transport for the emulated Xbox 360 pads. + * + * <p>Replaces the old append-file transport (which desynced after ~15 min when an + * unlooped {@code channel.write} left a partial event in the file and the + * IOException was swallowed) with a fixed-size mmap RING BUFFER shared with the + * native reader in {@code fakeinput.cpp}. Delta events are published into the + * ring under a monotonic {@code write_seq}; an authoritative absolute-state + * snapshot is published alongside under a seqlock so the native reader can replay + * a full keyframe to heal any desync (open, ring overflow) without duplicate + * input. Ring layout (magic/version/offsets) is a paired ABI with the native + * {@code FakeInputRingHeader} — keep the two in lockstep. + */ +public class FakeInputWriter { + private static final String TAG = "FakeInputWriter"; + + // Event types + public static final short EV_SYN = 0x00; + public static final short EV_KEY = 0x01; + public static final short EV_ABS = 0x03; + public static final short EV_MSC = 0x04; + + // Event codes + public static final short MSC_SCAN = 0x04; + public static final short SYN_REPORT = 0x00; + + // Xbox 360 controller button codes + public static final short BTN_A = 0x130; + public static final short BTN_B = 0x131; + public static final short BTN_X = 0x133; + public static final short BTN_Y = 0x134; + public static final short BTN_TL = 0x136; + public static final short BTN_TR = 0x137; + public static final short BTN_SELECT = 0x13A; + public static final short BTN_START = 0x13B; + public static final short BTN_THUMBL = 0x13D; + public static final short BTN_MODE = 0x13C; + public static final short BTN_THUMBR = 0x13E; + + // Absolute axis codes + public static final short ABS_X = 0x00; + public static final short ABS_Y = 0x01; + public static final short ABS_RX = 0x03; + public static final short ABS_RY = 0x04; + public static final short ABS_GAS = 0x09; + public static final short ABS_BRAKE = 0x0A; + public static final short ABS_HAT0X = 0x10; + public static final short ABS_HAT0Y = 0x11; + + // Button mapping (bit i of the snapshot buttons word) + private static final short[] BUTTON_MAP = { + BTN_A, BTN_B, BTN_X, BTN_Y, BTN_TL, BTN_TR, + BTN_SELECT, BTN_START, BTN_THUMBL, BTN_THUMBR, + BTN_MODE + }; + /** Bit 10 of the snapshot word. The first ten are GamepadState's own bit order; the Steam + * button is not, because GamepadState keeps 10 and 11 for the triggers. */ + private static final int SNAPSHOT_IDX_MODE = 10; + + private static final int EVENT_SIZE = 24; + static final int MAX_EVENTS_PER_UPDATE = 32; + private static final int BUFFER_SIZE = EVENT_SIZE * MAX_EVENTS_PER_UPDATE; + private static final int MAX_FAKE_INPUT_SLOTS = 4; + + // Ring layout — MUST match FakeInputRingHeader in fakeinput.cpp. + private static final int RING_CAPACITY_EVENTS = 4096; + private static final int RING_HEADER_SIZE = 64; + private static final int RING_SIZE = RING_HEADER_SIZE + (RING_CAPACITY_EVENTS * EVENT_SIZE); + private static final int RING_MAGIC = 0x46494252; // FIBR + private static final int RING_VERSION = 2; + private static final int RING_MAGIC_OFFSET = 0; + private static final int RING_VERSION_OFFSET = 4; + private static final int RING_EVENT_SIZE_OFFSET = 8; + private static final int RING_CAPACITY_OFFSET = 12; + private static final int RING_WRITE_SEQ_OFFSET = 16; + private static final int RING_GENERATION_OFFSET = 24; + // Authoritative absolute-state snapshot the native reader replays as a full + // keyframe to heal any delta-stream desync. Written under a seqlock + // (RING_SNAPSHOT_SEQ_OFFSET: odd = write in progress). + private static final int RING_SNAPSHOT_SEQ_OFFSET = 32; + private static final int RING_SNAPSHOT_BUTTONS_OFFSET = 40; + private static final int RING_SNAPSHOT_AXES_OFFSET = 44; // short[8] + private static final String RING_DIR_NAME = "fakeinput-rings"; + + private static final Object RING_LOCK = new Object(); + private static final RingSlot[] RING_SLOTS = new RingSlot[MAX_FAKE_INPUT_SLOTS]; + + static { + System.loadLibrary("sdnative"); + } + + private static native void nativeStoreFence(); + + private final File eventFile; + private final int slot; + private final ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER_SIZE); + + private boolean isOpen = false; + private volatile boolean destroyed = false; + + private final boolean[] prevButtonStates = new boolean[12]; + private int prevThumbLX, prevThumbLY, prevThumbRX, prevThumbRY; + private int prevTriggerL, prevTriggerR; + private int prevHatX, prevHatY; + private boolean hasChanges = false; + // If a publish fails after prev* state has already advanced, the next frame + // must re-emit the whole state once; otherwise an unchanged control would stay + // silent and the ring snapshot would never catch up. + private boolean pendingFullResend = false; + private boolean forceResend = false; + + public FakeInputWriter(String fakeInputPath, int slot) { + this.slot = slot; + this.eventFile = new File(fakeInputPath, "event" + slot); + this.buffer.order(ByteOrder.LITTLE_ENDIAN); + } + + private static final class RingSlot { + ByteBuffer data; + File ringFile; + FileChannel ringChannel; + RandomAccessFile ringRaf; + String exportPath; + long generation; + boolean active; + boolean everActivated; + } + + // ---- Static ring management (shared by all writers + the env exporter) ---- + + public static void prepareRingSlots(File fakeInputDir, int slotCount) { + int boundedSlotCount = Math.max(0, Math.min(slotCount, MAX_FAKE_INPUT_SLOTS)); + synchronized (RING_LOCK) { + for (int slot = 0; slot < boundedSlotCount; slot++) { + ensureRingSlotLocked(slot, fakeInputDir); + } + } + } + + /** + * Prepares every slot ring and returns the {@code slot=path;...} spec the native + * reader consumes via FAKE_EVDEV_MEMFD_PATHS. + */ + public static String getRingEnv(File fakeInputDir) { + synchronized (RING_LOCK) { + prepareRingSlotsLocked(fakeInputDir, MAX_FAKE_INPUT_SLOTS); + return buildRingEnvLocked(); + } + } + + public static void releaseAllRingSlots() { + synchronized (RING_LOCK) { + for (int slot = 0; slot < RING_SLOTS.length; slot++) { + releaseRingSlotLocked(slot); + } + } + } + + private static String buildRingEnvLocked() { + StringBuilder builder = new StringBuilder(); + for (int slot = 0; slot < RING_SLOTS.length; slot++) { + RingSlot ringSlot = RING_SLOTS[slot]; + if (ringSlot == null || ringSlot.data == null || ringSlot.exportPath == null) { + continue; + } + if (builder.length() > 0) { + builder.append(';'); + } + builder.append(slot).append('=').append(ringSlot.exportPath); + } + return builder.toString(); + } + + private static File getRingDir(File fakeInputDir) { + if (fakeInputDir == null) { + return null; + } + File inputDir = fakeInputDir.getAbsoluteFile(); + File parent = inputDir.getParentFile(); + return new File(parent != null ? parent : inputDir, RING_DIR_NAME); + } + + private static File getRingFile(File fakeInputDir, int slot) { + File ringDir = getRingDir(fakeInputDir); + return ringDir != null ? new File(ringDir, "ring" + slot) : null; + } + + private static String getCanonicalOrAbsolutePath(File file) { + try { + return file.getCanonicalPath(); + } catch (IOException e) { + return file.getAbsolutePath(); + } + } + + private static void initializeRingHeader(ByteBuffer data) { + data.order(ByteOrder.LITTLE_ENDIAN); + data.putInt(RING_MAGIC_OFFSET, RING_MAGIC); + data.putInt(RING_VERSION_OFFSET, RING_VERSION); + data.putInt(RING_EVENT_SIZE_OFFSET, EVENT_SIZE); + data.putInt(RING_CAPACITY_OFFSET, RING_CAPACITY_EVENTS); + data.putLong(RING_WRITE_SEQ_OFFSET, 0L); + data.putLong(RING_GENERATION_OFFSET, 0L); + data.putLong(RING_SNAPSHOT_SEQ_OFFSET, 0L); + data.putInt(RING_SNAPSHOT_BUTTONS_OFFSET, 0); + for (int i = 0; i < 8; i++) { + data.putShort(RING_SNAPSHOT_AXES_OFFSET + (i * 2), (short) 0); + } + } + + private static void releaseRingSlotLocked(int slot) { + RingSlot ringSlot = RING_SLOTS[slot]; + if (ringSlot == null) { + return; + } + ringSlot.data = null; + if (ringSlot.ringChannel != null) { + try { + ringSlot.ringChannel.close(); + } catch (IOException ignored) { + } + ringSlot.ringChannel = null; + } + if (ringSlot.ringRaf != null) { + try { + ringSlot.ringRaf.close(); + } catch (IOException ignored) { + } + ringSlot.ringRaf = null; + } + if (ringSlot.ringFile != null && ringSlot.ringFile.exists()) { + ringSlot.ringFile.delete(); + } + RING_SLOTS[slot] = null; + } + + private static void prepareRingSlotsLocked(File fakeInputDir, int slotCount) { + int boundedSlotCount = Math.max(0, Math.min(slotCount, MAX_FAKE_INPUT_SLOTS)); + for (int slot = 0; slot < boundedSlotCount; slot++) { + ensureRingSlotLocked(slot, fakeInputDir); + } + } + + private static RingSlot ensureRingSlotLocked(int slot, File fakeInputDir) { + if (slot < 0 || slot >= MAX_FAKE_INPUT_SLOTS || fakeInputDir == null) { + return null; + } + + File desiredRingFile = getRingFile(fakeInputDir, slot); + if (desiredRingFile == null) { + return null; + } + desiredRingFile = desiredRingFile.getAbsoluteFile(); + RingSlot existing = RING_SLOTS[slot]; + if (existing != null && existing.data != null) { + if (existing.ringFile != null && existing.ringFile.equals(desiredRingFile)) { + return existing; + } + releaseRingSlotLocked(slot); + } + + RingSlot fileRingSlot = createFileRingSlotLocked(slot, desiredRingFile); + if (fileRingSlot != null) { + RING_SLOTS[slot] = fileRingSlot; + return fileRingSlot; + } + return null; + } + + private static RingSlot createFileRingSlotLocked(int slot, File ringFile) { + File ringDir = ringFile.getParentFile(); + if (ringDir == null || (!ringDir.exists() && !ringDir.mkdirs())) { + Log.e(TAG, "Failed to create fake input ring directory for slot " + slot); + return null; + } + + RandomAccessFile raf = null; + FileChannel channel = null; + try { + raf = new RandomAccessFile(ringFile, "rw"); + raf.setLength(RING_SIZE); + channel = raf.getChannel(); + ByteBuffer data = channel.map(FileChannel.MapMode.READ_WRITE, 0, RING_SIZE); + initializeRingHeader(data); + + RingSlot ringSlot = new RingSlot(); + ringSlot.data = data; + ringSlot.ringFile = ringFile.getAbsoluteFile(); + ringSlot.ringRaf = raf; + ringSlot.ringChannel = channel; + ringSlot.exportPath = getCanonicalOrAbsolutePath(ringFile); + Log.i(TAG, "Created fake input file ring for slot " + slot + ": " + ringSlot.exportPath); + return ringSlot; + } catch (IOException e) { + Log.e(TAG, "Failed to create fake input file ring for slot " + slot + ": " + e.getMessage()); + if (channel != null) { + try { + channel.close(); + } catch (IOException ignored) { + } + } + if (raf != null) { + try { + raf.close(); + } catch (IOException ignored) { + } + } + return null; + } + } + + private RingSlot ensureRingSlot() { + synchronized (RING_LOCK) { + return ensureRingSlotLocked(this.slot, this.eventFile.getParentFile()); + } + } + + private boolean activateRingSlot() { + RingSlot ringSlot = ensureRingSlot(); + if (ringSlot == null || ringSlot.data == null) { + return false; + } + synchronized (ringSlot) { + if (!ringSlot.active) { + if (ringSlot.everActivated) { + ringSlot.generation++; + } else { + ringSlot.everActivated = true; + } + ringSlot.data.putLong(RING_WRITE_SEQ_OFFSET, 0L); + clearSnapshotLocked(ringSlot.data); + ringSlot.data.putLong(RING_GENERATION_OFFSET, ringSlot.generation); + ringSlot.active = true; + Log.d(TAG, "Activated fake input ring for slot " + this.slot + + " generation=" + ringSlot.generation); + } + } + return true; + } + + private void deactivateRingSlot() { + RingSlot ringSlot; + synchronized (RING_LOCK) { + ringSlot = this.slot >= 0 && this.slot < RING_SLOTS.length ? RING_SLOTS[this.slot] : null; + } + if (ringSlot == null) { + return; + } + synchronized (ringSlot) { + if (ringSlot.active && ringSlot.data != null) { + ringSlot.generation++; + ringSlot.data.putLong(RING_WRITE_SEQ_OFFSET, 0L); + clearSnapshotLocked(ringSlot.data); + ringSlot.data.putLong(RING_GENERATION_OFFSET, ringSlot.generation); + Log.i(TAG, "Deactivated fake input ring for slot " + this.slot + + " generation=" + ringSlot.generation); + } + ringSlot.active = false; + } + } + + private boolean flushBufferToRing() { + RingSlot ringSlot = ensureRingSlot(); + if (ringSlot == null || ringSlot.data == null) { + return false; + } + + // Raw byte copy: endianness is irrelevant since we never interpret + // multi-byte fields out of the source here. + ByteBuffer source = this.buffer.duplicate(); + synchronized (ringSlot) { + ByteBuffer ring = ringSlot.data; + long writeSeq = ring.getLong(RING_WRITE_SEQ_OFFSET); + int sourceLimit = source.limit(); + while (source.remaining() >= EVENT_SIZE) { + int eventIndex = (int) (writeSeq % RING_CAPACITY_EVENTS); + int targetOffset = RING_HEADER_SIZE + (eventIndex * EVENT_SIZE); + // Bulk-copy one event (EVENT_SIZE bytes) instead of byte-by-byte. + // Bound the source to a single event, position the ring at the slot, + // then let put(ByteBuffer) move the whole block. Mutating the ring's + // Java position is harmless: the native reader uses a raw pointer, not + // this position. API-26 safe (no JDK 13+ absolute bulk put). + source.limit(source.position() + EVENT_SIZE); + ring.position(targetOffset); + ring.put(source); + source.limit(sourceLimit); + writeSeq++; + } + // Publish the resulting absolute state. prev* now hold the post-update + // values, i.e. exactly the state the events just written transition to. + writeSnapshotLocked(ring); + nativeStoreFence(); + ring.putLong(RING_WRITE_SEQ_OFFSET, writeSeq); + } + return true; + } + + // Publishes the full absolute controller state for the native reader to replay + // as a keyframe. seqlock: bump to odd, write fields, bump to even, with + // store-store fences so the reader's acquire loads see consistent payloads. + private void writeSnapshotLocked(ByteBuffer ring) { + int buttons = 0; + for (int i = 0; i < BUTTON_MAP.length; i++) { + if (this.prevButtonStates[i]) { + buttons |= (1 << i); + } + } + long seq = ring.getLong(RING_SNAPSHOT_SEQ_OFFSET); + ring.putLong(RING_SNAPSHOT_SEQ_OFFSET, seq + 1); // odd: write in progress + nativeStoreFence(); + ring.putInt(RING_SNAPSHOT_BUTTONS_OFFSET, buttons); + // Axis order must match the native kSnapshotAxisCodes: + // X, Y, RX, RY, GAS(=triggerR), BRAKE(=triggerL), HAT0X, HAT0Y. + ring.putShort(RING_SNAPSHOT_AXES_OFFSET, clampShort(this.prevThumbLX)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 2, clampShort(this.prevThumbLY)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 4, clampShort(this.prevThumbRX)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 6, clampShort(this.prevThumbRY)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 8, clampShort(this.prevTriggerR)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 10, clampShort(this.prevTriggerL)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 12, clampShort(this.prevHatX)); + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + 14, clampShort(this.prevHatY)); + nativeStoreFence(); + ring.putLong(RING_SNAPSHOT_SEQ_OFFSET, seq + 2); // even: write complete + } + + private static short clampShort(int value) { + if (value > Short.MAX_VALUE) { + return Short.MAX_VALUE; + } + if (value < Short.MIN_VALUE) { + return Short.MIN_VALUE; + } + return (short) value; + } + + private static void clearSnapshotLocked(ByteBuffer ring) { + long seq = ring.getLong(RING_SNAPSHOT_SEQ_OFFSET); + ring.putLong(RING_SNAPSHOT_SEQ_OFFSET, seq + 1); + nativeStoreFence(); + ring.putInt(RING_SNAPSHOT_BUTTONS_OFFSET, 0); + for (int i = 0; i < 8; i++) { + ring.putShort(RING_SNAPSHOT_AXES_OFFSET + (i * 2), (short) 0); + } + nativeStoreFence(); + ring.putLong(RING_SNAPSHOT_SEQ_OFFSET, seq + 2); + } + + private boolean flushBuffer() { + return flushBufferToRing(); + } + + public synchronized boolean open() { + if (destroyed) + return false; + if (isOpen) + return true; + + try { + eventFile.getParentFile().mkdirs(); + if (!eventFile.exists()) { + eventFile.createNewFile(); + } + if (!activateRingSlot()) { + if (eventFile.exists()) { + eventFile.delete(); + } + Log.e(TAG, "Failed to open fake input mmap ring: " + eventFile.getAbsolutePath()); + return false; + } + isOpen = true; + Log.i(TAG, "Opened fake input: " + eventFile.getAbsolutePath()); + return true; + } catch (IOException e) { + Log.e(TAG, "Failed to open: " + e.getMessage()); + return false; + } + } + + public synchronized void close() { + isOpen = false; + } + + /** + * Reset all input state to neutral (all buttons released, axes zeroed). + * This keeps the ring active so games that cache the file descriptor can still + * reconnect. + */ + public synchronized void reset() { + if (!isOpen && !open()) + return; + + buffer.clear(); + hasChanges = false; + + // Release all buttons + for (int i = 0; i < BUTTON_MAP.length; i++) { + if (prevButtonStates[i]) { + prevButtonStates[i] = false; + writeEvent(EV_MSC, MSC_SCAN, BUTTON_MAP[i]); + writeEvent(EV_KEY, BUTTON_MAP[i], 0); + } + } + + // Zero all axes + if (prevThumbLX != 0) { + prevThumbLX = 0; + writeEvent(EV_ABS, ABS_X, 0); + } + if (prevThumbLY != 0) { + prevThumbLY = 0; + writeEvent(EV_ABS, ABS_Y, 0); + } + if (prevThumbRX != 0) { + prevThumbRX = 0; + writeEvent(EV_ABS, ABS_RX, 0); + } + if (prevThumbRY != 0) { + prevThumbRY = 0; + writeEvent(EV_ABS, ABS_RY, 0); + } + if (prevTriggerL != 0) { + prevTriggerL = 0; + writeEvent(EV_ABS, ABS_BRAKE, 0); + } + if (prevTriggerR != 0) { + prevTriggerR = 0; + writeEvent(EV_ABS, ABS_GAS, 0); + } + if (prevHatX != 0) { + prevHatX = 0; + writeEvent(EV_ABS, ABS_HAT0X, 0); + } + if (prevHatY != 0) { + prevHatY = 0; + writeEvent(EV_ABS, ABS_HAT0Y, 0); + } + + if (hasChanges) { + writeEvent(EV_SYN, SYN_REPORT, 0); + buffer.flip(); + if (!flushBuffer()) + Log.e(TAG, "Reset write error: fake input mmap ring unavailable"); + } + Log.i(TAG, "Reset fake input to neutral state: " + eventFile.getAbsolutePath()); + } + + public synchronized void softRelease() { + reset(); + close(); + Log.i(TAG, "Soft released fake input: " + eventFile.getAbsolutePath()); + } + + /** + * Full destroy - reset, tear the ring generation down, and delete the discovery node. + */ + public synchronized void destroy() { + destroyed = true; + reset(); + close(); + deactivateRingSlot(); + if (eventFile != null && eventFile.exists()) { + boolean deleted = eventFile.delete(); + Log.i(TAG, "Deleted fake input discovery node: " + eventFile.getAbsolutePath() + " (" + deleted + ")"); + } + } + + private void writeEvent(short type, short code, int value) { + long timeMs = System.currentTimeMillis(); + buffer.putLong(timeMs / 1000); + buffer.putLong((timeMs % 1000) * 1000); + buffer.putShort(type); + buffer.putShort(code); + buffer.putInt(value); + hasChanges = true; + } + + private void writeButton(int idx, boolean pressed) { + if (idx < 0 || idx >= BUTTON_MAP.length) + return; + if (!forceResend && prevButtonStates[idx] == pressed) + return; + prevButtonStates[idx] = pressed; + writeEvent(EV_MSC, MSC_SCAN, BUTTON_MAP[idx]); + writeEvent(EV_KEY, BUTTON_MAP[idx], pressed ? 1 : 0); + } + + public synchronized void writeGamepadState(GamepadState state) { + if (!isOpen && !open()) + return; + + // Keep the ring delta-first for latency. Full event frames are only used as + // a one-shot repair after a failed publish; normal open/overflow recovery is + // handled by the native snapshot keyframe. + forceResend = pendingFullResend; + pendingFullResend = false; + if (forceResend) { + Log.d(TAG, "Re-emitting full gamepad state after failed publish for slot " + slot); + } + + buffer.clear(); + hasChanges = false; + + // Buttons + for (int i = 0; i < 10; i++) { + writeButton(i, state.isPressed((byte) i)); + } + // The Steam button. In a Linux session this is what opens the client's own in-game menu, + // and the client looks for it where an Xbox pad keeps it: evdev BTN_MODE, which SDL then + // reports as button 8 - exactly the "guide:b8" in the mapping Steam writes for this pad. + writeButton(SNAPSHOT_IDX_MODE, + state.isPressed(GamepadState.IDX_BUTTON_MODE)); + + // Sticks + int lx = (int) (state.thumbLX * 32767); + int ly = (int) (state.thumbLY * 32767); + int rx = (int) (state.thumbRX * 32767); + int ry = (int) (state.thumbRY * 32767); + + // The fake evdev ring is event-queue semantics, so unchanged axes normally + // stay silent; forceResend overrides that to emit a complete keyframe. + if (forceResend || lx != prevThumbLX) { + prevThumbLX = lx; + writeEvent(EV_ABS, ABS_X, lx); + } + if (forceResend || ly != prevThumbLY) { + prevThumbLY = ly; + writeEvent(EV_ABS, ABS_Y, ly); + } + if (forceResend || rx != prevThumbRX) { + prevThumbRX = rx; + writeEvent(EV_ABS, ABS_RX, rx); + } + if (forceResend || ry != prevThumbRY) { + prevThumbRY = ry; + writeEvent(EV_ABS, ABS_RY, ry); + } + + // L2 and R2 (Triggers) + int tl = (int) (state.triggerL * 255); + int tr = (int) (state.triggerR * 255); + if (forceResend || tl != prevTriggerL) { + prevTriggerL = tl; + writeEvent(EV_ABS, ABS_BRAKE, tl); + } + if (forceResend || tr != prevTriggerR) { + prevTriggerR = tr; + writeEvent(EV_ABS, ABS_GAS, tr); + } + + // D-pad + int hatX = state.dpad[3] ? -1 : (state.dpad[1] ? 1 : 0); + int hatY = state.dpad[0] ? -1 : (state.dpad[2] ? 1 : 0); + if (forceResend || hatX != prevHatX) { + prevHatX = hatX; + writeEvent(EV_ABS, ABS_HAT0X, hatX); + } + if (forceResend || hatY != prevHatY) { + prevHatY = hatY; + writeEvent(EV_ABS, ABS_HAT0Y, hatY); + } + + // Detect change else no need to write + if (hasChanges) { + writeEvent(EV_SYN, SYN_REPORT, 0); + buffer.flip(); + if (!flushBuffer()) { + Log.e(TAG, "Gamepad write error: fake input mmap ring unavailable"); + // Couldn't publish; re-assert the whole state on the next frame. + pendingFullResend = true; + } + } + forceResend = false; + } + + public boolean isOpen() { + return isOpen; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/input/GamepadState.java b/app/src/main/java/com/the412banner/steamdeck/input/GamepadState.java new file mode 100644 index 0000000000..0400df0338 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/input/GamepadState.java @@ -0,0 +1,58 @@ +package com.the412banner.steamdeck.input; + +public class GamepadState { + /** Bit index of the Steam/Guide button; 0-9 are the face/shoulder/stick buttons. */ + public static final byte IDX_BUTTON_MODE = 12; + + public float thumbLX = 0; + public float thumbLY = 0; + public float thumbRX = 0; + public float thumbRY = 0; + public float triggerL = 0; + public float triggerR = 0; + public final boolean[] dpad = new boolean[4]; + public short buttons = 0; + + public void setPressed(int buttonIdx, boolean pressed) { + int flag = 1<<buttonIdx; + if (pressed) { + buttons |= flag; + } + else buttons &= ~flag; + } + + public boolean isPressed(int buttonIdx) { + return (buttons & (1<<buttonIdx)) != 0; + } + + public byte getDPadX() { + return (byte)(dpad[1] ? 1 : (dpad[3] ? -1 : 0)); + } + + public byte getDPadY() { + return (byte)(dpad[0] ? -1 : (dpad[2] ? 1 : 0)); + } + + public void copy(GamepadState other) { + thumbLX = other.thumbLX; + thumbLY = other.thumbLY; + thumbRX = other.thumbRX; + thumbRY = other.thumbRY; + triggerL = other.triggerL; + triggerR = other.triggerR; + buttons = other.buttons; + System.arraycopy(other.dpad, 0, dpad, 0, dpad.length); + } + + public void reset() { + thumbLX = 0; + thumbLY = 0; + thumbRX = 0; + thumbRY = 0; + triggerL = 0; + triggerR = 0; + buttons = 0; + java.util.Arrays.fill(dpad, false); + } + +} diff --git a/app/src/main/java/com/the412banner/steamdeck/input/PadBridge.java b/app/src/main/java/com/the412banner/steamdeck/input/PadBridge.java new file mode 100644 index 0000000000..8b990ae63a --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/input/PadBridge.java @@ -0,0 +1,131 @@ +package com.the412banner.steamdeck.input; + +import android.util.Log; +import android.view.InputDevice; +import android.view.KeyEvent; +import android.view.MotionEvent; + +import java.io.File; + +/** + * A physical controller, republished as a synthetic evdev device the Steam client can see. + * + * <p>Android hands a gamepad to the foreground activity as key and motion events; the Steam client + * inside the runtime never sees that. What it does scan is {@code /dev/input}, which the session's + * interposer (libfakeinput.so) serves out of the shared-memory rings written here. So the path is: + * Android event → {@link GamepadState} → {@link FakeInputWriter} ring → interposer → evdev node → + * SDL → Big Picture. + * + * <p>The identity the interposer reports is an Xbox 360 pad, which is what makes SDL apply a known + * mapping without the user configuring anything. + */ +public final class PadBridge { + private static final String TAG = "PadBridge"; + /** Slot 0 is the one the session exports; extra slots would each show as another pad. */ + private static final int SLOT = 0; + private static final float DEAD_ZONE = 0.12f; + + private final FakeInputWriter writer; + private final GamepadState state = new GamepadState(); + private boolean open; + + public PadBridge(File fakeInputDir) { + writer = new FakeInputWriter(fakeInputDir.getAbsolutePath(), SLOT); + } + + /** Opens the ring; safe to call more than once. */ + public synchronized boolean start() { + if (!open) { + open = writer.open(); + Log.i(TAG, "ring slot " + SLOT + (open ? " open" : " NOT open")); + } + return open; + } + + public synchronized void stop() { + if (open) { + state.reset(); + writer.writeGamepadState(state); + writer.close(); + open = false; + } + } + + /** True when the device this event came from is a gamepad or joystick, not the touchscreen. */ + public static boolean isFromController(InputDevice device) { + if (device == null) return false; + int sources = device.getSources(); + return (sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD + || (sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK; + } + + /** @return true when the event was a pad button and has been consumed. */ + public synchronized boolean onKeyEvent(KeyEvent event) { + if (!isFromController(event.getDevice())) return false; + boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; + switch (event.getKeyCode()) { + case KeyEvent.KEYCODE_BUTTON_A: state.setPressed(0, pressed); break; + case KeyEvent.KEYCODE_BUTTON_B: state.setPressed(1, pressed); break; + case KeyEvent.KEYCODE_BUTTON_X: state.setPressed(2, pressed); break; + case KeyEvent.KEYCODE_BUTTON_Y: state.setPressed(3, pressed); break; + case KeyEvent.KEYCODE_BUTTON_L1: state.setPressed(4, pressed); break; + case KeyEvent.KEYCODE_BUTTON_R1: state.setPressed(5, pressed); break; + case KeyEvent.KEYCODE_BUTTON_SELECT: + case KeyEvent.KEYCODE_BACK: state.setPressed(6, pressed); break; + case KeyEvent.KEYCODE_BUTTON_START: + case KeyEvent.KEYCODE_MENU: state.setPressed(7, pressed); break; + case KeyEvent.KEYCODE_BUTTON_THUMBL: state.setPressed(8, pressed); break; + case KeyEvent.KEYCODE_BUTTON_THUMBR: state.setPressed(9, pressed); break; + // The client's own in-game menu is opened by this one; the interposer publishes it as + // BTN_MODE, which SDL reports as the "guide" button. + case KeyEvent.KEYCODE_BUTTON_MODE: + case KeyEvent.KEYCODE_HOME: state.setPressed(GamepadState.IDX_BUTTON_MODE, pressed); break; + case KeyEvent.KEYCODE_BUTTON_L2: state.triggerL = pressed ? 1f : 0f; break; + case KeyEvent.KEYCODE_BUTTON_R2: state.triggerR = pressed ? 1f : 0f; break; + case KeyEvent.KEYCODE_DPAD_UP: state.dpad[0] = pressed; break; + case KeyEvent.KEYCODE_DPAD_RIGHT: state.dpad[1] = pressed; break; + case KeyEvent.KEYCODE_DPAD_DOWN: state.dpad[2] = pressed; break; + case KeyEvent.KEYCODE_DPAD_LEFT: state.dpad[3] = pressed; break; + default: return false; + } + publish(); + return true; + } + + /** @return true when the event was a pad's sticks/triggers and has been consumed. */ + public synchronized boolean onMotionEvent(MotionEvent event) { + if (!isFromController(event.getDevice())) return false; + if (event.getAction() != MotionEvent.ACTION_MOVE) return false; + state.thumbLX = axis(event, MotionEvent.AXIS_X); + // Android's Y axis grows downwards and evdev's ABS_Y does too, so no flip here: what the + // pad reports as "down" is what the client is told. + state.thumbLY = axis(event, MotionEvent.AXIS_Y); + state.thumbRX = axis(event, MotionEvent.AXIS_Z); + state.thumbRY = axis(event, MotionEvent.AXIS_RZ); + float lt = event.getAxisValue(MotionEvent.AXIS_LTRIGGER); + float rt = event.getAxisValue(MotionEvent.AXIS_RTRIGGER); + // Some pads only report the triggers on BRAKE/GAS. + if (lt == 0f) lt = event.getAxisValue(MotionEvent.AXIS_BRAKE); + if (rt == 0f) rt = event.getAxisValue(MotionEvent.AXIS_GAS); + state.triggerL = lt; + state.triggerR = rt; + float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); + float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); + state.dpad[0] = hatY < -0.5f; + state.dpad[1] = hatX > 0.5f; + state.dpad[2] = hatY > 0.5f; + state.dpad[3] = hatX < -0.5f; + publish(); + return true; + } + + private void publish() { + if (!open && !start()) return; + writer.writeGamepadState(state); + } + + private static float axis(MotionEvent event, int axis) { + float value = event.getAxisValue(axis); + return Math.abs(value) < DEAD_ZONE ? 0f : value; + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxNetworkLinkComponent.kt b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxNetworkLinkComponent.kt new file mode 100644 index 0000000000..236f10d705 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxNetworkLinkComponent.kt @@ -0,0 +1,117 @@ +package com.the412banner.steamdeck.runtime + +import android.content.Context +import android.net.ConnectivityManager +import android.net.LinkProperties +import android.net.Network +import android.os.Build +import android.provider.Settings +import android.util.Log +import com.the412banner.steamdeck.core.EnvironmentComponent +import java.io.File +import java.io.IOException +import java.net.Inet4Address +import java.net.Inet6Address + +/** + * The device's network link, published for the Linux runtime's processes. + * + * Android denies an app the rtnetlink dump behind getifaddrs() and if_nameindex(), the hardware + * address ioctl and every table under /proc/net. Wine builds its adapter, address, route and + * neighbour tables from those, so a game under the runtime saw no adapter, no address, no gateway + * and no MAC - and one that checks its adapters before going online waited for good. The link the + * app can see through ConnectivityManager is written here, kept current while the session runs, + * and the session shim answers whatever the kernel refuses from it (tools/linuxfs/preload/netif.c). + * + * Shape follows WinNative's LinuxNetworkLinkComponent (maxjivi05, f76a5c4a), GPL-3.0. + */ +class LinuxNetworkLinkComponent( + context: Context, + private val rootDir: File, +) : EnvironmentComponent() { + private val appContext = context.applicationContext + private val connectivity = + appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + private val lock = Any() + private var callback: ConnectivityManager.NetworkCallback? = null + + /** Called before the session starts, so its first process already sees the link. */ + fun publish() = write(connectivity.activeNetwork?.let(connectivity::getLinkProperties)) + + override fun start() { + val registered = object : ConnectivityManager.NetworkCallback() { + override fun onLinkPropertiesChanged(network: Network, properties: LinkProperties) = write(properties) + override fun onLost(network: Network) = write(null) + } + synchronized(lock) { callback = registered } + connectivity.registerDefaultNetworkCallback(registered) + } + + override fun stop() { + val registered = synchronized(lock) { callback.also { callback = null } } ?: return + try { + connectivity.unregisterNetworkCallback(registered) + } catch (e: IllegalArgumentException) { + Log.w(TAG, "Network callback was already gone", e) + } + } + + private fun write(properties: LinkProperties?) { + val file = File(rootDir, LINK_FILE) + synchronized(lock) { + try { + file.parentFile?.mkdirs() + val staged = File(file.path + ".staged") + staged.writeText(describe(properties)) + if (!staged.renameTo(file)) throw IOException("Could not replace $file") + } catch (e: IOException) { + Log.w(TAG, "Could not publish the network link", e) + } + } + } + + private fun describe(properties: LinkProperties?): String { + val addresses = properties?.linkAddresses.orEmpty() + .filter { it.address is Inet4Address || it.address is Inet6Address } + val name = properties?.interfaceName?.takeIf { addresses.isNotEmpty() } ?: OFFLINE_NAME + val mtu = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) properties?.mtu ?: 0 else 0 + return buildString { + append("if $name $LINK_INDEX ${if (mtu > 0) mtu else DEFAULT_MTU}\n") + append("mac ${seededMac()}\n") + if (addresses.isEmpty()) { + append("addr $OFFLINE_ADDRESS\n") + return@buildString + } + for (address in addresses) { + append("addr ${address.address.hostAddress?.substringBefore('%')} ${address.prefixLength}\n") + } + for (family in listOf(Inet4Address::class.java, Inet6Address::class.java)) { + val gateway = properties?.routes.orEmpty() + .firstOrNull { it.isDefaultRoute && family.isInstance(it.gateway) && !it.gateway!!.isAnyLocalAddress } + ?.gateway ?: continue + append("gw ${gateway.hostAddress?.substringBefore('%')}\n") + } + } + } + + /** + * A stable, locally administered address for this device. Android hides the real one, and a + * title should see the same hardware identity every session. + */ + private fun seededMac(): String { + val id = Settings.Secure.getString(appContext.contentResolver, Settings.Secure.ANDROID_ID) ?: "bannerlator" + val bytes = java.security.MessageDigest.getInstance("SHA-1").digest(id.toByteArray()) + val b0 = (bytes[0].toInt() and 0xfc) or 0x02 + return listOf(b0, bytes[1].toInt(), bytes[2].toInt(), bytes[3].toInt(), bytes[4].toInt(), bytes[5].toInt()) + .joinToString(":") { "%02x".format(it and 0xff) } + } + + companion object { + private const val TAG = "LinuxNetworkLink" + private const val LINK_FILE = "etc/bannerlator-net" + private const val LINK_INDEX = 2 + private const val DEFAULT_MTU = 1500 + private const val OFFLINE_NAME = "eth0" + private const val OFFLINE_ADDRESS = "10.0.0.2 24" + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntime.java b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntime.java new file mode 100644 index 0000000000..7e285a6b4c --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntime.java @@ -0,0 +1,242 @@ +package com.the412banner.steamdeck.runtime; + +import android.content.Context; +import android.os.Process; +import android.system.ErrnoException; +import android.system.Os; +import android.system.StructStat; + + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +/** + * The glibc arm64 rootfs at {@code files/linuxfs} and the proot invocation that runs a program in + * it as this app's own uid. It is a second runtime beside the Wine imagefs, not a container: no + * Wine, no box64, no FEX. proot is packaged as {@code libproot.so} so the installer places it, with + * its loader, in the native library directory — the only place an app on targetSdk 28 may execute + * a file from. + * + * <p>Ported from WinNative's gamescope runtime (GPL-3.0). + */ +public final class LinuxRuntime { + public static final String DIR = "linuxfs"; + public static final String SESSION_SCRIPT = "/usr/local/bin/bannerlator-session"; + public static final String MODE_DESKTOP = "desktop"; + public static final String MODE_STEAM = "steam"; + public static final String MODE_RUN = "run"; + /** Shortcut extra naming which of the modes above a Linux entry launches. */ + public static final String EXTRA_LINUX_MODE = "linux_mode"; + private static final String KGSL_DEVICE = "/dev/kgsl-3d0"; + /** Where every Linux session's debug log lands: public, so a user can just hand the folder over. */ + public static final String DEBUG_LOG_DIR = "SteamDeck"; + + public static File debugLogDir() { + return new File(android.os.Environment.getExternalStoragePublicDirectory( + android.os.Environment.DIRECTORY_DOWNLOADS), DEBUG_LOG_DIR); + } + + private LinuxRuntime() {} + + public static File rootDir(Context context) { + return new File(context.getFilesDir(), DIR); + } + + /** + * The session's own small tree beside the rootfs: the fake evdev nodes and their rings. In + * Bannerlator these lived in the Wine imagefs; here there is no Wine, so the session owns them. + * Bound into the guest at its own host path, so nothing needs translating. + */ + public static File sessionRoot(Context context) { + return new File(context.getFilesDir(), "session"); + } + + /** Where the runtime carries the host-side proot; see tools/linuxfs/prebuilt/proot/README.md. */ + private static final String HOST_DIR = "opt/android-host"; + + /** + * proot, preferred from the installed runtime and falling back to the copy in the apk. + * + * <p>It is an Android binary rather than part of the rootfs — it is what creates the rootfs — + * but it travels in the runtime tarball so that reinstalling the app cannot replace the one + * binary everything else depends on, and so a device with no working packaged proot can still + * run the runtime. + */ + public static File prootBinary(Context context) { + File shipped = new File(rootDir(context), HOST_DIR + "/proot"); + if (shipped.isFile()) return shipped; + return new File(context.getApplicationInfo().nativeLibraryDir, "libproot.so"); + } + + public static File prootLoader(Context context) { + File shipped = new File(rootDir(context), HOST_DIR + "/loader"); + if (shipped.isFile()) return shipped; + return new File(context.getApplicationInfo().nativeLibraryDir, "libproot-loader.so"); + } + + /** proot links against libtalloc, which sits beside it; empty when the apk copy is in use. */ + public static String prootLibraryPath(Context context) { + File dir = new File(rootDir(context), HOST_DIR); + return new File(dir, "proot").isFile() ? dir.getPath() : ""; + } + + /** The rootfs is present with gamescope and the session script the launcher hands control to. */ + public static boolean isInstalled(Context context) { + File root = rootDir(context); + return new File(root, "usr/bin/gamescope").isFile() + && new File(root, SESSION_SCRIPT.substring(1)).isFile() + && prootBinary(context).isFile() + && prootLoader(context).isFile(); + } + + /** The Vulkan ICD manifest the rootfs ships for the device GPU, or null when it has none. */ + public static File vulkanIcd(Context context) { + File icdDir = new File(rootDir(context), "usr/share/vulkan/icd.d"); + File[] manifests = icdDir.listFiles((dir, name) -> name.endsWith(".json")); + if (manifests == null) return null; + for (File manifest : manifests) { + if (manifest.getName().contains("freedreno")) return manifest; + } + return manifests.length > 0 ? manifests[0] : null; + } + + /** + * The proot command line running {@code guestCommand} inside the rootfs. Host paths the session + * needs — the app's files directory for the compositor and audio sockets, external storage for + * the user's games — are bound at their own paths, so nothing on either side needs translating + * and proot never touches the fds a dma-buf travels in. Android has no /dev/shm; a directory + * under the cache stands in, which glibc's shm_open and Chromium's shared memory accept. + */ + public static List<String> command(Context context, File sessionRoot, File runtimeDir, + File externalStorage, List<String> guestCommand) { + return command(context, sessionRoot, runtimeDir, externalStorage, null, guestCommand); + } + + /** As above, plus {@code host:guest} bind specs — the installed games handed to Steam. */ + public static List<String> command(Context context, File sessionRoot, File runtimeDir, + File externalStorage, List<String> extraBinds, + List<String> guestCommand) { + File root = rootDir(context); + List<String> cmd = new ArrayList<>(); + cmd.add(prootBinary(context).getPath()); + cmd.add("--kill-on-exit"); + // Android's app seccomp policy traps the whole set*id family. Xwayland's Popen() calls + // setgid()/setuid() before it execs xkbcomp and _exit(127)s when they fail, so without + // this the keymap never compiles and Xwayland dies. -i makes proot answer those calls + // itself while still reporting our real ids, so nothing inside sees a different user. + int uid = Process.myUid(); + cmd.add("-i"); + cmd.add(uid + ":" + uid); + cmd.add("-r"); + cmd.add(root.getPath()); + cmd.add("-w"); + cmd.add("/root"); + bind(cmd, "/dev"); + bind(cmd, "/proc"); + bind(cmd, "/sys"); + bind(cmd, "/dev/urandom:/dev/random"); + bind(cmd, "/proc/self/fd:/dev/fd"); + bind(cmd, "/proc/self/fd/0:/dev/stdin"); + bind(cmd, "/proc/self/fd/1:/dev/stdout"); + bind(cmd, "/proc/self/fd/2:/dev/stderr"); + bind(cmd, new File(root, "etc/bannerlator/empty").getPath() + ":/sys/fs/selinux"); + bind(cmd, context.getFilesDir().getPath()); + bind(cmd, context.getCacheDir().getPath()); + bind(cmd, runtimeDir.getPath()); + if (sessionRoot != null) bind(cmd, sessionRoot.getPath()); + if (externalStorage != null && externalStorage.isDirectory()) { + bind(cmd, externalStorage.getPath()); + } + File shm = new File(context.getCacheDir(), "shm"); + shm.mkdirs(); + bind(cmd, shm.getPath() + ":/dev/shm"); + + // Android denies apps these; glibc, Steam and libcap read them at startup. + File fakeProc = new File(root, "etc/bannerlator/proc"); + String[][] procFiles = { + {"stat", "/proc/stat"}, + {"version", "/proc/version"}, + {"loadavg", "/proc/loadavg"}, + {"uptime", "/proc/uptime"}, + {"vmstat", "/proc/vmstat"}, + {"cap_last_cap", "/proc/sys/kernel/cap_last_cap"}, + {"overflowuid", "/proc/sys/kernel/overflowuid"}, + {"overflowgid", "/proc/sys/kernel/overflowgid"}, + }; + for (String[] entry : procFiles) { + File fake = new File(fakeProc, entry[0]); + if (fake.isFile() && !new File(entry[1]).canRead()) { + bind(cmd, fake.getPath() + ":" + entry[1]); + } + } + bindGpuNode(context, cmd); + if (extraBinds != null) { + for (String spec : extraBinds) bind(cmd, spec); + } + cmd.addAll(guestCommand); + return cmd; + } + + /** + * An app process may not open {@code /dev/dri} — the nodes exist but are labelled + * {@code graphics_device}, which stock policy grants surfaceflinger and not us — yet libdrm and + * everything built on it identify a GPU by its render node, and gamescope refuses to offer + * linux-dmabuf without one. The KGSL device Turnip actually drives ({@code gpu_device}, which we + * may open) stands in: it appears as a render node with the sysfs entries libdrm reads, and our + * Turnip build reports the same device numbers for it. + */ + private static void bindGpuNode(Context context, List<String> cmd) { + StructStat st; + try { + st = Os.stat(KGSL_DEVICE); + } catch (ErrnoException e) { + return; + } + long dev = st.st_rdev; + long major = ((dev >> 8) & 0xfff) | ((dev >> 32) & ~0xfffL); + long minor = (dev & 0xff) | ((dev >> 12) & ~0xffL); + String node = "renderD" + minor; + File base = new File(context.getCacheDir(), "drm"); + File dri = new File(base, "dri"); + File device = new File(base, "sys/" + major + ":" + minor + "/device"); + File drm = new File(device, "drm/" + node); + try { + if ((!dri.isDirectory() && !dri.mkdirs()) || (!drm.isDirectory() && !drm.mkdirs())) { + return; + } + new File(dri, node).createNewFile(); + Files.write(new File(drm, "dev").toPath(), + (major + ":" + minor + "\n").getBytes(StandardCharsets.UTF_8)); + Files.write(new File(device, "uevent").toPath(), + "DRIVER=kgsl-3d0\nMODALIAS=platform:kgsl-3d0\n".getBytes(StandardCharsets.UTF_8)); + File subsystem = new File(device, "subsystem"); + if (!Files.isSymbolicLink(subsystem.toPath())) { + Os.symlink("/sys/bus/platform", subsystem.getPath()); + } + } catch (IOException | ErrnoException e) { + return; + } + bind(cmd, new File(base, "sys").getPath() + ":/sys/dev/char"); + bind(cmd, dri.getPath() + ":/dev/dri"); + bind(cmd, KGSL_DEVICE + ":/dev/dri/" + node); + } + + private static void bind(List<String> cmd, String spec) { + cmd.add("-b"); + cmd.add(spec); + } + + /** X access control and Steam look the session user up by uid: the app uid is root inside. */ + public static void writeAccounts(Context context) throws IOException { + File root = rootDir(context); + int uid = Process.myUid(); + Files.write(new File(root, "etc/passwd").toPath(), + ("root:x:" + uid + ":" + uid + ":root:/root:/bin/bash\n").getBytes(StandardCharsets.UTF_8)); + Files.write(new File(root, "etc/group").toPath(), + ("root:x:" + uid + ":\n").getBytes(StandardCharsets.UTF_8)); + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntimeInstaller.java b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntimeInstaller.java new file mode 100644 index 0000000000..0e9f36b239 --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/runtime/LinuxRuntimeInstaller.java @@ -0,0 +1,258 @@ +package com.the412banner.steamdeck.runtime; + +import android.content.Context; +import android.util.Log; + + +import com.the412banner.steamdeck.core.FileUtils; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream; + +import org.json.JSONObject; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.security.MessageDigest; + +/** + * Downloads and unpacks the Linux runtime rootfs into {@code files/linuxfs}. It is opt-in: nothing + * fetches it until the user asks for it, and a gamescope session refuses to start without it. + * + * <p>The catalog row names the build, its URL and its sha256, so an interrupted or corrupted + * download is caught before anything is written into the app's files directory. + */ +public final class LinuxRuntimeInstaller { + private static final String TAG = "LinuxRuntimeInstaller"; + + /** Catalog row, beside the other component catalogs in winlator-contents. */ + public static final String CATALOG_URL = + "https://raw.githubusercontent.com/The412Banner/winlator-contents/main/linuxfs.json"; + + private static final String VERSION_FILE = ".version"; + + public interface ProgressListener { + /** {@code percent} is -1 while the size is unknown. */ + void onProgress(String stage, int percent); + } + + public static final class Release { + public final String version; + public final String url; + public final String sha256; + public final long size; + + Release(String version, String url, String sha256, long size) { + this.version = version; + this.url = url; + this.sha256 = sha256; + this.size = size; + } + } + + private LinuxRuntimeInstaller() {} + + /** The build currently unpacked, or null when the runtime is not installed. */ + public static String installedVersion(Context context) { + File marker = new File(LinuxRuntime.rootDir(context), VERSION_FILE); + if (!marker.isFile() || !LinuxRuntime.isInstalled(context)) return null; + String v = FileUtils.readString(marker); + return v == null ? null : v.trim(); + } + + /** The catalog's current build, or null when it cannot be reached or read. */ + public static Release fetchRelease() { + String body = Downloader.downloadString(CATALOG_URL); + if (body == null || body.isEmpty()) return null; + try { + JSONObject json = new JSONObject(body); + String version = json.optString("version", ""); + String url = json.optString("url", ""); + String sha256 = json.optString("sha256", ""); + if (version.isEmpty() || url.isEmpty() || sha256.isEmpty()) return null; + return new Release(version, url, sha256, json.optLong("size", 0L)); + } catch (Exception e) { + Log.w(TAG, "catalog: " + e); + return null; + } + } + + /** + * The guest's home directory, carried across an update rather than replaced with the tarball's + * empty one. Steam installs itself here - the client, the signed-in account and every + * downloaded game - so replacing the rootfs wholesale used to delete all three and leave the + * user re-downloading Steam and signing in again, with their library gone. + */ + private static final String USER_DATA = "root"; + + /** + * Downloads {@code release} and replaces whatever is installed with it. Returns false and + * leaves the existing runtime alone if the download or the checksum fails; the new rootfs is + * only moved into place once it has been unpacked whole. + * + * <p>{@link #USER_DATA} survives the swap: the system is replaced, what the user put in it is + * not. An update therefore keeps Steam, the login and the installed games. + */ + public static boolean install(Context context, Release release, ProgressListener listener) { + File archive = new File(context.getCacheDir(), "linuxfs.tar.zst"); + try { + if (listener != null) listener.onProgress("Downloading", 0); + // Downloader reports a 0..1 fraction, or -1 while the total size is unknown. + boolean ok = Downloader.downloadFile(release.url, archive, true, (fraction) -> { + if (listener != null) { + listener.onProgress("Downloading", + fraction < 0 ? -1 : Math.round(fraction * 100f)); + } + }); + if (!ok) { + Log.w(TAG, "download failed"); + return false; + } + + if (listener != null) listener.onProgress("Verifying", -1); + String actual = sha256(archive); + if (!release.sha256.equalsIgnoreCase(actual)) { + Log.w(TAG, "checksum mismatch: wanted " + release.sha256 + ", got " + actual); + return false; + } + + // Unpack beside the live rootfs and swap, so a failure here cannot leave a half + // runtime that isInstalled() would happily launch. + File root = LinuxRuntime.rootDir(context); + File staging = new File(root.getParentFile(), LinuxRuntime.DIR + ".new"); + FileUtils.delete(staging); + if (!staging.mkdirs()) return false; + if (listener != null) listener.onProgress("Extracting", -1); + if (!extract(archive, staging, listener)) { + FileUtils.delete(staging); + return false; + } + FileUtils.writeString(new File(staging, VERSION_FILE), release.version); + + File old = new File(root.getParentFile(), LinuxRuntime.DIR + ".old"); + FileUtils.delete(old); + if (root.isDirectory() && !root.renameTo(old)) { + FileUtils.delete(staging); + return false; + } + + // Carry the user's home over before the new rootfs takes the name. A rename inside the + // same filesystem, so a 30 GB library costs nothing and cannot half-copy; the tarball's + // own empty /root is dropped first so the rename has somewhere to land. If this fails + // the update is abandoned and the previous runtime is put back untouched - shipping a + // working system with the user's games gone is the worse outcome. + File keptFrom = new File(old, USER_DATA); + if (keptFrom.isDirectory()) { + File keptTo = new File(staging, USER_DATA); + FileUtils.delete(keptTo); + if (!keptFrom.renameTo(keptTo)) { + Log.w(TAG, "could not carry " + USER_DATA + " across the update; rolling back"); + FileUtils.delete(staging); + old.renameTo(root); + return false; + } + } + + if (!staging.renameTo(root)) { + if (old.isDirectory()) old.renameTo(root); + return false; + } + FileUtils.delete(old); + return LinuxRuntime.isInstalled(context); + } catch (Exception e) { + Log.e(TAG, "install", e); + return false; + } finally { + archive.delete(); + } + } + + public static void uninstall(Context context) { + FileUtils.delete(LinuxRuntime.rootDir(context)); + } + + /** + * A whole-rootfs tar, which is not the shape the shared extractor handles: a distribution + * rootfs is full of hard links (one binary under several names), and an entry written as an + * empty file instead of its link target is a rootfs that boots to nothing. Symlinks, hard + * links and the executable bit are all carried over here. + */ + private static boolean extract(File archive, File destination, ProgressListener listener) { + long entries = 0; + try (InputStream in = new ZstdCompressorInputStream( + new BufferedInputStream(new FileInputStream(archive), 1 << 16)); + TarArchiveInputStream tar = new TarArchiveInputStream(in)) { + TarArchiveEntry entry; + String base = destination.getCanonicalPath() + File.separator; + while ((entry = tar.getNextTarEntry()) != null) { + File file = new File(destination, entry.getName()); + // Refuse anything that would land outside the runtime directory. + if (!(file.getCanonicalPath() + (entry.isDirectory() ? File.separator : "")).startsWith(base) + && !file.getCanonicalPath().equals(destination.getCanonicalPath())) { + Log.w(TAG, "skipping entry outside the rootfs: " + entry.getName()); + continue; + } + if (entry.isDirectory()) { + file.mkdirs(); + continue; + } + File parent = file.getParentFile(); + if (parent != null && !parent.isDirectory()) parent.mkdirs(); + + if (entry.isSymbolicLink()) { + file.delete(); + FileUtils.symlink(entry.getLinkName(), file.getAbsolutePath()); + } else if (entry.isLink()) { + // A hard link to an earlier entry. Link where the filesystem allows it and + // fall back to a copy, which costs space but always works. + File target = new File(destination, entry.getLinkName()); + file.delete(); + try { + Files.createLink(file.toPath(), target.toPath()); + } catch (IOException | UnsupportedOperationException e) { + if (target.isFile()) { + Files.copy(target.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + } + } else if (entry.isFile()) { + try (OutputStream out = new FileOutputStream(file)) { + byte[] buffer = new byte[1 << 16]; + int read; + while ((read = tar.read(buffer)) != -1) out.write(buffer, 0, read); + } + if ((entry.getMode() & 0111) != 0) file.setExecutable(true, false); + } else { + continue; // device nodes and fifos: the runtime binds the real ones + } + if (++entries % 2000 == 0 && listener != null) { + listener.onProgress("Extracting", -1); + } + } + return true; + } catch (Exception e) { + Log.e(TAG, "extract", e); + return false; + } + } + + private static String sha256(File file) throws Exception { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + try (InputStream in = new BufferedInputStream(new FileInputStream(file), 1 << 16)) { + byte[] buffer = new byte[1 << 16]; + int read; + while ((read = in.read(buffer)) != -1) digest.update(buffer, 0, read); + } + StringBuilder sb = new StringBuilder(); + for (byte b : digest.digest()) sb.append(String.format("%02x", b)); + return sb.toString(); + } +} diff --git a/app/src/main/java/com/the412banner/steamdeck/wayland/WaylandCompositor.java b/app/src/main/java/com/the412banner/steamdeck/wayland/WaylandCompositor.java new file mode 100644 index 0000000000..efb776fb4b --- /dev/null +++ b/app/src/main/java/com/the412banner/steamdeck/wayland/WaylandCompositor.java @@ -0,0 +1,422 @@ +package com.the412banner.steamdeck.wayland; + +import android.view.Surface; + +/** + * Embedded Wayland compositor (experimental parallel display runtime). + * + * Brings up a libwayland-server compositor in-process so games launched through + * Wine's winewayland.drv can present into it (companion to the winewayland Proton + * build). Committed frames (dmabufs from winewayland's Vulkan WSI) are composited + * onto the given Surface via the native Vulkan present backend. Not on the default + * X11 path. + */ +public final class WaylandCompositor { + static { + System.loadLibrary("bannerwayland"); + } + + private WaylandCompositor() {} + + private static volatile Runnable firstFrameListener; + + /** Register a callback fired once, when the compositor presents the first client + * frame to the output Surface. Used to dismiss the launch overlay in wayland mode + * (there is no XServer window-content hook). Runs on the compositor thread — the + * listener must marshal to the UI thread itself. */ + public static void setFirstFrameListener(Runnable r) { firstFrameListener = r; } + + /** Invoked from native (banner_on_first_frame) on the first present. */ + @SuppressWarnings("unused") + static void onFirstFramePresented() { + Runnable r = firstFrameListener; + if (r != null) r.run(); + } + + /** The in-game performance HUD's feed in wayland mode (X11 binds the HUD to the window + * carrying _MESA_DRV and counts X presents; there is no X server here). */ + public interface GameListener { + /** A window started presenting GPU frames ({@code window} describes it; {@code gpuName} is the + * compositor's GPU), or {@code window == null} when that window closed. Compositor thread. */ + void onGameSurface(String window, String gpuName); + /** One GPU frame from that window. Compositor thread — keep it cheap. */ + void onGameFrame(); + /** The program behind that window, right after {@link #onGameSurface}: its Linux pid (the + * Wayland client's credentials) and executable name ({@code ""} when unknown). The app arms its + * launch-time CPU affinity on it — on X11 that comes from window events, which a Wayland session + * has none of. Compositor thread — marshal to the UI thread. */ + default void onGameProgram(int pid, String program) {} + } + + private static volatile GameListener gameListener; + + public static void setGameListener(GameListener l) { gameListener = l; } + + /** Invoked from native (banner_on_game_surface). */ + @SuppressWarnings("unused") + static void onGameSurface(String window, String gpuName) { + GameListener l = gameListener; + if (l != null) l.onGameSurface(window, gpuName); + } + + /** Invoked from native (banner_on_game_frame) for every frame of the HUD's window. */ + @SuppressWarnings("unused") + static void onGameFrame() { + GameListener l = gameListener; + if (l != null) l.onGameFrame(); + } + + /** Invoked from native (banner_on_game_program) once per game window that starts presenting. */ + @SuppressWarnings("unused") + static void onGameProgram(int pid, String program) { + GameListener l = gameListener; + if (l != null) l.onGameProgram(pid, program != null ? program : ""); + } + + /** Pointer lock (zwp_pointer_constraints_v1) state, for the app's input path. */ + public interface PointerLockListener { + /** A program locked the pointer ({@code locked}): the app must feed the compositor deltas + * (scene input type 6) instead of absolute positions. When the lock ends, {@code x,y} is + * where the pointer now is (scene = virtual-desktop coordinates) for the app to re-sync + * its own pointer to. Compositor thread. */ + void onPointerLock(boolean locked, int x, int y); + } + + private static volatile PointerLockListener pointerLockListener; + + public static void setPointerLockListener(PointerLockListener l) { pointerLockListener = l; } + + /** Invoked from native (banner_on_pointer_lock). */ + @SuppressWarnings("unused") + static void onPointerLock(boolean locked, int x, int y) { + PointerLockListener l = pointerLockListener; + if (l != null) l.onPointerLock(locked, x, y); + } + + /** Clipboard text a program in the guest copied (wl_data_device / zwlr_data_control). */ + public interface ClipboardListener { + /** {@code text} is what the guest put on its clipboard. Compositor thread. */ + void onGuestClipboardText(String text); + } + + private static volatile ClipboardListener clipboardListener; + + public static void setClipboardListener(ClipboardListener l) { clipboardListener = l; } + + /** Invoked from native (banner_on_clipboard_text) with UTF-8 bytes. */ + @SuppressWarnings("unused") + static void onClipboardText(byte[] utf8) { + ClipboardListener l = clipboardListener; + if (l != null && utf8 != null) l.onGuestClipboardText(new String(utf8, java.nio.charset.StandardCharsets.UTF_8)); + } + + /** Text input (zwp_text_input_v3) state: a program accepts IME text, or stopped. */ + public interface TextInputListener { + /** {@code enabled}: {@code program} (its exe name) accepts IME text; {@code x,y,w,h} is its caret + * rectangle in scene (virtual desktop) pixels, all 0 until the program positions one. Compositor + * thread. */ + void onTextInput(boolean enabled, String program, int x, int y, int w, int h); + } + + private static volatile TextInputListener textInputListener; + + public static void setTextInputListener(TextInputListener l) { textInputListener = l; } + + /** Invoked from native (banner_on_text_input). */ + @SuppressWarnings("unused") + static void onTextInput(boolean enabled, String program, int x, int y, int w, int h) { + TextInputListener l = textInputListener; + if (l != null) l.onTextInput(enabled, program, x, y, w, h); + } + + private static byte[] utf8(String s) { + return s == null ? new byte[0] : s.getBytes(java.nio.charset.StandardCharsets.UTF_8); + } + + /** Android's clipboard text becomes the guest's selection ({@code null}/empty clears it). Any thread. */ + public static void setClipboardText(String text) { nativeSetClipboardText(utf8(text)); } + + /** Commit soft-keyboard text to the program accepting text input. Any thread. */ + public static void textInputCommit(String text) { if (text != null && !text.isEmpty()) nativeTextInputCommit(utf8(text)); } + + /** Composing (pre-edit) text with the caret at character index {@code cursor} (-1 = end); empty clears. */ + public static void textInputPreedit(String text, int cursor) { nativeTextInputPreedit(utf8(text), cursor, cursor); } + + /** The IME deleted {@code before} characters before and {@code after} after the caret. */ + public static void textInputDelete(int before, int after) { nativeTextInputDelete(before, after); } + + private static native void nativeSetClipboardText(byte[] utf8); + private static native void nativeTextInputCommit(byte[] utf8); + private static native void nativeTextInputPreedit(byte[] utf8, int cursorBegin, int cursorEnd); + private static native void nativeTextInputDelete(int before, int after); + + /** Start the compositor headless (no output window) — bring-up tests only. */ + public static native void nativeStart(String xdgRuntimeDir); + + /** Start the compositor rendering to {@code surface}. XDG_RUNTIME_DIR = an + * app-writable dir for the wayland socket (e.g. context.getFilesDir()). + * driverPath/libraryName/nativeLibDir select the Turnip driver via adrenotools + * (all null -> system libvulkan, which can't do dmabuf import). */ + public static native void nativeStartWithSurface(Surface surface, String xdgRuntimeDir, + String driverPath, String libraryName, + String nativeLibDir); + + /** Replace/clear the output window when the SurfaceView is (re)created/destroyed. */ + public static native void nativeSetSurface(Surface surface); + + /** Inject a pointer event into the compositor (from the SurfaceView touch listener). + * action: 0=down, 1=move, 2=up. x/y in compositor output space (0..1919, 0..1079). */ + public static native void nativeSendPointer(int action, int x, int y); + + /** Inject a key event. evdev = Linux input keycode (KEY_A=30…); state: 1=down, 0=up. */ + public static native void nativeSendKey(int evdev, int state); + + /** One screen refresh (Choreographer frame callback). The compositor draws the newest state + * once per tick, so games run unthrottled and the screen shows their latest frame. */ + public static native void nativeVsync(long frameTimeNanos); + + /** Shortcut launches: don't draw explorer's windows (desktop, taskbar, Start menu), matching the + * X11 renderer's unviewable "explorer.exe". Set before the compositor starts. */ + public static native void nativeSetHideShell(boolean hide); + + /** The panel's refresh rate in Hz, advertised on the Wayland output so Wine's display modes + * carry the real rate (games that insist on their saved 144 Hz mode find it, as on X11). + * Set before the compositor starts. */ + public static native void nativeSetOutputRefreshRate(float hz); + + /** Show a single fullscreen window on its own Android layer (SurfaceControl) instead of blitting + * it into the compositor's swapchain. BANNER_WAYLAND_ZERO_COPY=1 in the container's environment + * variables is the launch default; see waylandcomp/ZERO_COPY_SPIKE.md. + * + * Live and thread-safe: before the compositor starts this is the initial state, and afterwards + * the call is marshalled onto the compositor thread, which flips the state, tells every bound + * game over banner_ahb_v1.mode to rebuild its swapchain for it, and redraws. The switch is one + * frame's worth of latency; the picture never goes black, because the old swapchain's buffers + * keep being shown until the game has replaced them. */ + public static native void nativeSetZeroCopy(boolean on); + + /** Zero-copy frames the compositor presented in its LAST completed 10 s stats window (the + * "| N zero-copy frames" figure of its session-log stats line); 0 while zero-copy is off or + * before the first window closes. Read-only, any thread — the in-game drawer polls it. */ + public static native int nativeZeroCopyFrames(); + + /** Milliseconds since the compositor last put a game frame on the display layer without a copy; + * -1 if it never has this session. Unlike nativeZeroCopyFrames this updates on every such frame + * rather than once per 10 s window, so the drawer can tell "switching..." from "running" within + * a frame or two of the live toggle. Read-only, any thread. */ + public static native int nativeZeroCopyLastFrameAgeMs(); + + /** Compressed (UBWC) game buffers: the compositor advertises DRM_FORMAT_MOD_QCOM_COMPRESSED next to + * LINEAR on zwp_linux_dmabuf_v1 for every format its driver can import that way, so the game's + * Turnip allocates compressed swapchain images instead of resolving every frame to a linear copy. + * Default on; BANNER_WAYLAND_UBWC=0 in the container's environment variables turns it off (A/B). + * Set before the compositor starts. */ + public static native void nativeSetUbwc(boolean on); + + /** Debug: advertise no DRM device (main device 0:0) in the dma-buf feedback, as a phone that + * exposes no /dev/dri node to apps does. BANNER_WAYLAND_NO_RENDER_NODE=1 in the container's or + * shortcut's environment variables. Set before the compositor starts. */ + public static native void nativeSetNoRenderNode(boolean on); + + /** VRR / refresh-rate matching: mirror the panel refresh-rate vote the activity puts on the + * compositor's SurfaceView onto the game's own SurfaceControl layer. Under zero-copy the game's + * frames go straight onto that layer and never reach the app's surface, so the surface vote alone + * does not tell SurfaceFlinger the game's cadence. Same rate and compatibility as + * {@code Surface.setFrameRate}; {@code 0} clears the vote. Callable any time from any thread; the + * compositor applies it on its next layer transaction and writes one `layer` line per change to + * the session log. A no-op on Android versions without {@code ASurfaceTransaction_setFrameRate}. */ + public static native void nativeSetLayerFrameRate(float hz); + + /** Write one line into the compositor's session log (Download/Wayland-logs) under the "display" + * area, from Java. Used for facts the platform knows and the native side does not — the panel's + * HDR capability, which lives behind android.view.Display. Safe before the compositor thread is + * up (the line then only reaches logcat) and safe after it has gone. */ + public static native void nativeLogDisplay(String message); + + /** The same under the "perf" area (e.g. the CPU cores Prefer Big Cores picked). Same safety. */ + public static native void nativeLogPerf(String message); + + /** The container's screen size, advertised as the Wayland output's mode so Wine's display-mode + * list stops at the desktop size, as the X server's does on X11. Set before the compositor starts. */ + public static native void nativeSetOutputSize(int width, int height); + + // ── HDR10 output, round 1 (waylandcomp/src/banner_color.h, wl_color_mgmt.c) ───────────────── + // Opt-in: BANNER_WAYLAND_HDR=1 in the container's or shortcut's env vars. The compositor offers + // games HDR10 (wp_color_manager_v1 + 10-bit buffers, frames tagged BT2020_PQ on the game's own + // display layer) only when the game's display lists HDR10 as well; otherwise nothing changes and + // the session log says why. Not the drawer's "HDR" effect, which is an SDR bloom/contrast filter. + + /** HDR_MODE_OFF / HDR_MODE_ON (BANNER_WAYLAND_HDR=1) / HDR_MODE_FORCE (=force: skip the display + * check, for testing the negotiation on an SDR panel). */ + public static final int HDR_MODE_OFF = 0, HDR_MODE_ON = 1, HDR_MODE_FORCE = 2; + + /** The opt-in: mode, where it came from ("container env" / "shortcut env"), whether DXVK_HDR=1 is + * in the game's environment, and whether the app turned zero-copy on for this session because HDR + * needs it. Set before the compositor starts. */ + public static native void nativeSetHdrRequest(int mode, String source, boolean dxvkHdr, boolean zeroCopyForced); + + /** The game's display as {@code android.view.Display} reports it. Before the compositor starts (it + * feeds the gate) and again whenever it changes (logged; the gate is decided once per session). */ + public static native void nativeSetHdrDisplay(int displayId, String name, String formats, boolean hdr10, + float maxLuminance, float maxAverageLuminance, float minLuminance, + boolean hdrSdrRatioAvailable, float hdrSdrRatio, int apiLevel); + + /** One {@code Display.getHdrSdrRatio()} reading ({@code < 0} = not available); {@code listener} = it + * came from the display's ratio listener rather than the periodic sampler. Any thread. */ + public static native void nativeHdrSdrRatioSample(float ratio, boolean listener); + + /** Milliseconds since an HDR frame last reached a display layer; -1 = none this session. Any thread. */ + public static native int nativeHdrLastFrameAgeMs(); + + /** -1 = the compositor has not decided the HDR gate yet, 0 = closed, 1 = open. Any thread. */ + public static native int nativeHdrGateState(); + + /** The session is ending: the compositor writes its "HDR on screen: …" summary line. Once. */ + public static native void nativeHdrSessionEnd(); + + /** True while HDR frames are really on screen: frames tagged BT2020_PQ reached the display in the + * last 1.5 s and, where the display reports an HDR/SDR ratio, it is above 1 (the HUD's badge). */ + public static native boolean nativeHdrOnScreen(); + + /** One "color" line in the session log, from Java (the HDR environment, the DXVK warning). */ + public static native void nativeLogColor(String message); + + /** One line in the session log under {@code area} (the log's 9-character column: "gpu", "nvapi"), + * from Java: launch facts the app decides (the GPU name spoof, the Unreal Engine HDR mode). Like + * {@link #nativeLogDisplay}, safe before the session file exists (the line is written when it + * opens) and after it has gone. */ + public static native void nativeLog(String area, String message); + + /** Nits at which SDR content is placed when the compositor composes an HDR picture (a window over + * an HDR game, the desktop around a windowed one). Default 203 (BT.2408). Before the start. */ + public static native void nativeSetHdrSdrWhite(float nits); + + /** The in-game drawer's HDR output switch (only meaningful while the HDR gate is open; per session, + * starts on). On = the game's HDR frames go to the display as HDR; off = the same frames are shown + * tone-mapped to SDR. Live, any thread (queued to the compositor, which logs the flip); the game is + * told nothing - DXVK_HDR and the colour-manager offer were decided at launch. */ + public static native void nativeSetHdrOutput(boolean on); + + /** The HDR output switch's current state (any thread). */ + public static native boolean nativeHdrOutput(); + + /** True while an HDR game's frames are being shown tone-mapped to SDR (the last one under 1.5 s ago). */ + public static native boolean nativeHdrToneMappedOnScreen(); + + /** 0 = no HDR frames on screen (or not confirmed yet), 1 = HDR frames on screen with HDR headroom, + * 2 = HDR frames on screen but the display has given them no headroom (HDR/SDR ratio 1.00) for 5 s + * or more - the brightness slider at maximum, or a screen recording (Android turns HDR headroom off + * while the screen is recorded). The HUD badge and the drawer's HDR row. */ + public static native int nativeHdrState(); + + /** Device evidence beside the HDR/SDR headroom, HDR sessions only (any thread): PowerManager thermal + * status (0..6, -1 unknown) and getThermalHeadroom(10) (NaN / negative = not available), and + * Settings.System SCREEN_BRIGHTNESS (0..255, -1 unknown) + SCREEN_BRIGHTNESS_MODE (1 auto, 0 manual, + * -1 unknown). The compositor logs changes of status and brightness and puts the values on every + * no-headroom line, the 10 s HDR line and the verdict. */ + public static native void nativeHdrEnvSample(int thermalStatus, float thermalHeadroom, int brightness, + int brightnessMode); + + /** Display.getHighestHdrSdrRatio() (Android 16+), <= 0 = not reported: the display's own ceiling, capped + * into the headroom request and logged in the verdict. Any thread. */ + public static native void nativeSetHdrHighestRatio(float ratio); + + /** The HDR headroom the SCREEN surface should ask for while HDR frames go through the HDR10 swapchain + * (frame generation), 0 = none; the app applies it (SurfaceView.setDesiredHdrHeadroom, API 35). */ + public static native float nativeHdrScreenHeadroom(); + + /** Why that value ("content peak 1207 nits (max CLL) / SDR 203 ..."), for the log line. */ + public static native String nativeHdrScreenHeadroomWhy(); + + /** What the app asked for on the screen surface: > 0 the ratio, 0 cleared, -1 not possible (< Android 15). */ + public static native void nativeHdrNoteHeadroomRequest(float ratio); + + /** Fullscreen mode ({@code Container.FULLSCREEN_OFF/FIT/STRETCH/FILL/INTEGER}) and screen alignment + * ({@code Container.ALIGN_CENTER/TOP/BOTTOM}): how the compositor fits the desktop onto the screen, + * with the same arithmetic as {@code ViewTransformation} (which maps touch input), so the picture and + * the pointer agree. OFF and FIT both letterbox. Callable any time; the next frame uses it. */ + public static native void nativeSetScaleMode(int fullscreenMode, int screenAlignment); + + // ---- Screen effects: the X11 Vulkan renderer's post chain, run by the compositor between the + // composited scene and the output blit (waylandcomp/src/effects_chain.c). Same modes, ranges and + // pass order as VulkanRenderer's setters, so a saved preset looks the same on both backends. + // Callable any time from any thread; the compositor applies them on its next frame and writes + // one `effects` line to the session log per change. While any effect is on, a zero-copy + // (layer-mode) game is presented through the compositor pass instead. + + /** Scaling mode: 0=None 1=Linear 2=Nearest 3=SGSR 4=FSR 5=FSR Fit 6=Sharpen 7=NIS 8=SGSR HQ. + * Resizes the scene to its mapped output size (there is no render scale on Wayland). */ + public static native void nativeSetUpscaler(int mode); + + /** The upscaler's own sharpness slider 0..100 (RCAS lobe scale, SGSR edge 0.5..4.5, NIS). */ + public static native void nativeSetUpscaleSharpness(int sharpness); + + /** AMD CAS sharpen toggle + level 0..100 (0 = the pass is off). */ + public static native void nativeSetCas(boolean enabled, int sharpness); + + /** Fake-HDR toggle. */ + public static native void nativeSetHdr(boolean enabled); + + /** Terminal debanding toggle + strength 0..200 (100 = 1 LSB). */ + public static native void nativeSetDeband(boolean enabled, int strength); + + /** Colour grade in the drawer's slider units (brightness/contrast -100..100, gamma 0.5..3.0, + * saturation 0..200 percent; 0/0/1/100 = neutral, pass off) plus the FXAA / Toon / CRT / NTSC + * toggles — the same signature as {@code VulkanRenderer.setScreenEffects}. */ + public static native void nativeSetScreenEffects(float brightness, float contrast, float gamma, float saturation, + boolean fxaa, boolean toon, boolean crt, boolean ntsc); + + /** The Look the controls currently match ({@code null} = Custom); only named in the log line. */ + public static native void nativeSetLookName(String name); + + /** The in-game FPS limiter: frames per second, 0 = unlimited. Paces when replaced buffers go + * back to the game, like the X11 IdleNotify pacer, so the game itself slows to the cap. */ + public static native void nativeSetFpsLimit(int fps); + + /** Inject the app's X-server input in scene (virtual desktop) pixels. type 2 = move to a,b; + * 3 = evdev button a (BTN_LEFT=0x110…) pressed (b=1) or released (b=0); 4 = a wheel steps, + * negative = up. */ + public static native void nativeSendSceneInput(int type, int a, int b); + + // ── Frame generation (waylandcomp/src/framegen_bridge.c) ───────────────────────────────── + // LSFG Native and Win-FG Native run inside the compositor's Turnip device, the same engines + // the X11 VulkanRenderer hosts. Every setter only stores a value; the compositor thread applies + // it on its next frame, so they are safe from any thread and before the compositor starts. + // bionic-fg (the guest-side win-fg layer) is X11-only and has no Wayland counterpart. + public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_WINFG = 1; + + /** Which native engine generates: {@link #FG_ENGINE_LSFG} or {@link #FG_ENGINE_WINFG}. */ + public static native void nativeSetFrameGenEngine(int kind); + + /** Arm (multiplier 2..4: one real frame plus multiplier-1 interpolated ones per game frame) or + * disarm. Generated frames are presented ahead of the real frame on consecutive vblanks. */ + public static native void nativeSetFrameGenArmed(boolean armed, int multiplier); + + /** LSFG Native: the SPIR-V cache built from the user's Lossless.dll ({@code LsfgNative.cacheFile}). */ + public static native void nativeSetLsfgCachePath(String path); + + /** Flow scale (0.25-1.0) and the panel's real refresh rate (the pacer never generates above it). */ + public static native void nativeSetFrameGenTuning(float flowScale, float refreshHz); + + /** Win-FG Native only: interpolation model (3/4) and performance preset (0..2). */ + public static native void nativeSetWinFgTuning(int model, int perfPreset); + + /** Same codes as {@code VulkanRenderer.getFrameGenProblem()}: -1 not known yet (the compositor's + * device is not up), 0 fine, 1 the driver lacks what the selected engine needs + * ({@link #nativeFrameGenCapsReason()} says what), 2 the engine failed to start. */ + public static native int nativeFrameGenProblem(); + public static native String nativeFrameGenCapsReason(); + + /** Same shape as {@code VulkanRenderer.getFrameGenStats()}: {generations trusted, generations + * planned, real fps, presented fps (generated frames included), thermal (-1 = none), + * GPU ms per generated frame (-1 = unknown)}. */ + public static native float[] nativeFrameGenStats(); + + /** Relative pointer motion by dx,dy scene pixels (the Relative Mouse / captured-mouse path): + * while a program holds a pointer lock this is what it receives as relative_motion; otherwise + * the compositor moves its pointer by the delta. */ + public static void sendPointerDelta(int dx, int dy) { + if (dx == 0 && dy == 0) return; + nativeSendSceneInput(6, dx * 256, dy * 256); + } +} diff --git a/app/src/main/jniLibs/arm64-v8a/libltdl.so b/app/src/main/jniLibs/arm64-v8a/libltdl.so new file mode 100644 index 0000000000..100b64c2a8 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libltdl.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libpulse.so b/app/src/main/jniLibs/arm64-v8a/libpulse.so new file mode 100644 index 0000000000..5791e2a290 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libpulse.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libpulseaudio.so b/app/src/main/jniLibs/arm64-v8a/libpulseaudio.so new file mode 100644 index 0000000000..f13a308c58 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libpulseaudio.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libpulsecommon-13.0.so b/app/src/main/jniLibs/arm64-v8a/libpulsecommon-13.0.so new file mode 100644 index 0000000000..798caa1715 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libpulsecommon-13.0.so differ diff --git a/app/src/main/jniLibs/arm64-v8a/libpulsecore-13.0.so b/app/src/main/jniLibs/arm64-v8a/libpulsecore-13.0.so new file mode 100644 index 0000000000..dd5fa7f709 Binary files /dev/null and b/app/src/main/jniLibs/arm64-v8a/libpulsecore-13.0.so differ diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000000..950161c7eb --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,7 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="108dp" android:height="108dp" + android:viewportWidth="108" android:viewportHeight="108"> + <!-- A gamepad silhouette: the app is a handheld launcher and nothing else. --> + <path android:fillColor="#FFFFFFFF" + android:pathData="M34,42h40c8.8,0 16,7.2 16,16v4c0,5.5 -4.5,10 -10,10c-3.6,0 -6.9,-1.9 -8.7,-5l-2.6,-4.5h-29.4l-2.6,4.5c-1.8,3.1 -5.1,5 -8.7,5c-5.5,0 -10,-4.5 -10,-10v-4C18,49.2 25.2,42 34,42zM40,50v6h-6v4h6v6h4v-6h6v-4h-6v-6zM68,52a3,3 0 1,0 0.1,0zM76,60a3,3 0 1,0 0.1,0z" /> +</vector> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..a285a544fd --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:gravity="center" + android:padding="32dp" + android:background="#FF101418"> + + <TextView + android:id="@+id/title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/app_name" + android:textColor="#FFFFFFFF" + android:textSize="28sp" + android:layout_marginBottom="4dp" /> + + <TextView + android:id="@+id/subtitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/subtitle" + android:textColor="#FF8899A6" + android:textSize="13sp" + android:layout_marginBottom="28dp" /> + + <TextView + android:id="@+id/status" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textColor="#FFDDDDDD" + android:textSize="16sp" /> + + <TextView + android:id="@+id/detail" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center" + android:textColor="#FF8899A6" + android:textSize="13sp" + android:layout_marginTop="6dp" /> + + <ProgressBar + android:id="@+id/progress" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:max="100" + android:visibility="gone" /> + + <Button + android:id="@+id/play" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="28dp" + android:text="@string/play" /> + + <Button + android:id="@+id/runtime" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:text="@string/install_runtime" /> +</LinearLayout> diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000000..a8a8fa5518 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@color/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon> diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000000..a8a8fa5518 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@color/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon> diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml new file mode 100644 index 0000000000..126b5f3665 --- /dev/null +++ b/app/src/main/res/values/ic_launcher_background.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="ic_launcher_background">#FF1B2838</color> +</resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000000..b2b0638c36 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string name="app_name">SteamDeck</string> + <string name="subtitle">Valve\'s native ARM64 Steam client, under gamescope</string> + <string name="play">Play</string> + <string name="ready">Ready</string> + <string name="working">Working…</string> + <string name="runtime_missing">Linux runtime not installed</string> + <string name="install_runtime">Install Linux runtime</string> + <string name="update_runtime">Update Linux runtime</string> + <string name="remove_runtime">Remove Linux runtime</string> + <string name="remove">Remove</string> + <string name="remove_runtime_message">This deletes the runtime, the Steam client inside it, and every game installed there.</string> + <string name="runtime_installed">Runtime %1$s installed</string> + <string name="runtime_update">Runtime %1$s installed · %2$s available</string> + <string name="runtime_download_size">%1$s · %2$s download, one time</string> + <string name="catalog_unreachable">Could not reach the runtime catalog</string> + <string name="install_failed">Install failed — nothing was changed</string> + <string name="session_starting">Starting the session…</string> + <string name="session_ended">The session ended (%1$d). Log: Download/%2$s</string> +</resources> diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000000..bf4532ceac --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="AppTheme" parent="@android:style/Theme.Material.NoActionBar"> + <item name="android:colorBackground">#FF101418</item> + </style> + <!-- A session owns the whole panel: no bars, no title, and black behind the compositor. --> + <style name="SessionTheme" parent="@android:style/Theme.Material.NoActionBar.Fullscreen"> + <item name="android:windowBackground">@android:color/black</item> + </style> +</resources> diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000000..e1c6134739 --- /dev/null +++ b/build.gradle @@ -0,0 +1,11 @@ +buildscript { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } + dependencies { + classpath 'com.android.tools.build:gradle:8.8.0' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21' + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000000..2cbf5f77cb --- /dev/null +++ b/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 +android.useAndroidX=true +android.nonTransitiveRClass=true +# The NDK the compositor is built with. CI passes the one the runner has installed +# (-PndkVersion=…); this is the fallback for a local build. +ndkVersion=27.0.12077973 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e708b1c023 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..5f07093805 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 07 19:24:10 CST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..4f906e0c81 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# 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 +# +# https://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. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..ac1b06f938 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000000..13cc2289c2 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,17 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "SteamDeck" +include ':app' diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists b/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists new file mode 100755 index 0000000000..9d2d60fa72 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-seed-redists @@ -0,0 +1,58 @@ +#!/bin/bash +# Marks Steam's shared redistributables as already run in every Proton prefix. +# +# A game whose depot lists _CommonRedist makes the client run the real installer inside the +# prefix on first launch. Those are x86 bundles, so they run under FEX, and the 2019 one leaves +# a task behind every time: its main thread exits while a helper stays blocked reading a pipe it +# also holds the write end of, so the process never reaps and the client keeps waiting on it. +# +# The client skips a "Run Process" block whose HasRunKey is already set, which is the same escape +# WineUtils.seedVcRedistRegistryIfDllsPresent() takes for the app's own containers. The names and +# versions come out of the install scripts rather than a list kept here, because Valve revises +# them; a prefix already carrying the same set is left alone. +set -u +steam_root=${1:?steam root} + +redist="$steam_root/steamapps/common/Steamworks Shared/_CommonRedist" +[ -d "$redist" ] || exit 0 + +# Every process an install script would run becomes the registry value the client writes once it +# has run it. Names sit one level inside "Run Process", the key they share a level further in. +block=$(find "$redist" -name installscript.vdf -print0 2>/dev/null | sort -z | xargs -0 -r awk -v now="$(date +%s)" ' + function emit(key, name, path) { + path = key + sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path) + if (path == key) + return + printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, name + # The client writes these from 32-bit steam.exe, so its own copy lands under Wow6432Node; + # both spellings are seeded because the reader picks by its own word size. + sub(/^Software\\\\/, "Software\\\\\\\\Wow6432Node\\\\\\\\", path) + printf "\n[%s] %d\n\"%s\"=dword:00000001\n", path, now, name + } + FNR == 1 { depth = 0; name = ""; key = "" } + /^[[:space:]]*\{/ { depth++; next } + /^[[:space:]]*\}/ { + if (depth == 3 && name != "" && key != "") + emit(key, name) + depth-- + next + } + { + n = split($0, part, "\"") + if (n >= 5 && tolower(part[2]) == "hasrunkey") { key = part[4]; next } + if (n >= 3 && depth == 2) { name = part[2]; key = "" } + } +') +[ -n "$block" ] || exit 0 +stamp=$(printf '%s' "$block" | cksum) + +for reg in "$steam_root"/steamapps/compatdata/*/pfx/system.reg \ + /mnt/bannerlator-sd/steamapps/compatdata/*/pfx/system.reg; do + [ -f "$reg" ] || continue + seeded=$(dirname "$reg")/.bannerlator-redists + [ "$(cat "$seeded" 2>/dev/null)" = "$stamp" ] && continue + printf '%s\n' "$block" >>"$reg" || continue + printf '%s\n' "$stamp" >"$seeded" + echo "== seeded redist markers into $reg" +done diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session new file mode 100755 index 0000000000..73b9275d8f --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -0,0 +1,186 @@ +#!/bin/bash +# The Linux runtime's session. Bannerlator execs this under proot with the output size and mode; +# the first pass starts gamescope, which execs this script again inside it for the program: +# bannerlator-session desktop the file manager +# bannerlator-session run <path> a Linux program (AppImage, script or ELF) +# bannerlator-session steam [steam-url] the native Steam client +# BL_WIDTH / BL_HEIGHT size the output, BL_FPS limits it, BL_LOG collects everything said here. +set -u +export HOME=${HOME:-/root} +mode=${1:-desktop} +shift || true +# One line per milestone, greppable as "== STEP", so a first run reads as a narrative rather than +# something to be reconstructed from Steam's own chatter. The app shows these while it waits. +step() { echo "== STEP $(date -u +%H:%M:%S) $*"; } +if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then + mkdir -p "$(dirname "$BL_LOG")" 2>/dev/null + # The client alone writes megabytes an hour; one earlier log is kept, not every session's. + if [ "$(stat -c %s "$BL_LOG" 2>/dev/null || echo 0)" -gt 8388608 ]; then + mv -f "$BL_LOG" "$BL_LOG.1" + fi + exec >>"$BL_LOG" 2>&1 + echo "== bannerlator-session $(date) mode=$mode $*" + echo "== uid=$(id -u) size=${BL_WIDTH:-?}x${BL_HEIGHT:-?} fps=${BL_FPS:-0} icd=${VK_ICD_FILENAMES:-none}" + echo "== gamescope: $(gamescope --version 2>&1 | head -1)" + echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)" +fi + +# Until the runtime is stable, Steam's own logs are copied beside the session log at exit so a +# failed launch can be handed over as one folder. +collect_steam_logs() { + [ -n "${BL_DEBUG_DIR:-}" ] || return 0 + local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam + mkdir -p "$BL_DEBUG_DIR" 2>/dev/null || return 0 + [ -d "$steam_root/logs" ] && cp -r "$steam_root/logs" "$BL_DEBUG_DIR/steam-logs" 2>/dev/null + [ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/" 2>/dev/null + [ -f "$steam_root/steam.pid" ] && cp "$steam_root/steam.pid" "$BL_DEBUG_DIR/" 2>/dev/null + echo "== steam logs copied to $BL_DEBUG_DIR" +} +export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} +export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config} +export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache} +mkdir -p "$XDG_DATA_HOME" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" + +if [ -z "${BL_INSIDE:-}" ]; then + # The compositor may still be starting, and a socket left by an earlier session is not + # a compositor: probe until a connection succeeds. + for _ in $(seq 1 100); do + wayland-info >/dev/null 2>&1 && break + sleep 0.1 + done + width=${BL_WIDTH:-1280} + height=${BL_HEIGHT:-720} + args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height") + # -r is what gamescope advertises as the refresh rate, and what a game reads as the display's. + # Left unset it defaults to 60, so a 120 Hz panel offers only 60 Hz in game settings. The FPS + # limiter wins when it is on (it is a deliberate cap); otherwise use the panel's own rate. + if [ "${BL_FPS:-0}" -gt 0 ]; then + args+=(-r "$BL_FPS") + elif [ "${BL_REFRESH:-0}" -gt 0 ]; then + args+=(-r "$BL_REFRESH") + fi + [ "$mode" = steam ] && args+=(-e) + export BL_INSIDE=1 + exec gamescope "${args[@]}" -- "$0" "$mode" "$@" +fi + +# gamescope manages X windows: toolkits go through Xwayland, not gamescope's own Wayland socket. +export GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb SDL_VIDEODRIVER=x11 +# gamescope's reaper waits for every process left under it before the compositor comes down. A +# process a game left behind - a Wine service blocked on a server that is already gone - is +# reparented there when the client exits, and the screen stays black on it for good. Nothing of +# the session outlives the program it was started for. +reap_orphans() { + local round p stat pid left + for round in 1 2 3 4 5; do + left= + for p in /proc/[0-9]*; do + pid=${p#/proc/} + [ "$pid" = "$$" ] && continue + stat=$(cat "$p/stat" 2>/dev/null) || continue + stat=${stat##*) } + set -- $stat + [ "${2:-}" = "$PPID" ] && left="$left $pid" + done + [ -n "$left" ] || return 0 + echo "== leaving behind:$left" + kill -9 $left 2>/dev/null + sleep 0.2 + done +} + +case $mode in + desktop) + exec pcmanfm + ;; + run) + target=${1:?program path} + shift + case ${target,,} in + *.appimage) + export APPIMAGE_EXTRACT_AND_RUN=1 + chmod +x "$target" 2>/dev/null + exec "$target" "$@" + ;; + *.sh) + exec bash "$target" "$@" + ;; + *) + chmod +x "$target" 2>/dev/null + cd "$(dirname "$target")" && exec "$target" "$@" + ;; + esac + ;; + steam) + step "checking the Steam client (first run downloads it, ~1-2 min with nothing on screen)" + bannerlator-steam-install || exit $? + step "Steam client ready" + steam_root=$XDG_DATA_HOME/Steam + # Register the card library (bound at /mnt/bannerlator-sd) with the client - internal storage is + # its main library already - and the ARM64 Proton that lets it launch the Windows ones. + step "registering the app's game library with Steam" + bannerlator-steam-library "$steam_root" || true + step "setting up the ARM64 Proton compatibility tool" + bannerlator-steam-compat "$steam_root" || true + # Steam runs a game's shared redistributables inside its prefix on first launch; marking + # them as already run keeps those x86 installers from starting under emulation at all. + bannerlator-seed-redists "$steam_root" || true + # The compatibility tool runs Valve's arm64 Proton, which the client fetches like any depot. + # Asked for on the command line the first time, so a Windows title has it before it is needed. + if [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then + step "asking the client to fetch the ARM64 Proton" + set -- "$@" steam://install/4427310 + fi + # The tool is registered before the client starts and finds the depot at launch time, so + # nothing here waits for a download. What can still change under a running client is which + # titles are installed: a title installed this session gets the client's own per-app Proton + # choice, which it cannot start. Refresh the per-app entries every so often; the registrar is + # idempotent, so a repeat costs nothing. + ( + for _ in $(seq 1 240); do + sleep 15 + bannerlator-steam-compat "$steam_root" >/dev/null 2>&1 || true + done + ) & + # Debug aid while the runtime is being brought up: an app id dropped in ~/.bl-autolaunch is + # handed to the client as a rungameid URL, so a launch can be reproduced without touching the + # screen. Removed once the runtime is stable. + if [ -s "$HOME/.bl-autolaunch" ]; then + _bl_app=$(cat "$HOME/.bl-autolaunch") + # A bare app id runs the game; a full steam:// URL is passed through, which is how a + # validate or an install is driven without touching the screen. + case $_bl_app in + steam://*) _bl_url=$_bl_app ;; + *) _bl_url=steam://rungameid/$_bl_app ;; + esac + echo "== autolaunch $_bl_url" + set -- "$@" "$_bl_url" + fi + export STEAM_RUNTIME=1 + export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} + export SDL_VIDEO_X11_DGAMOUSE=0 + # Native-Linux x86 games go through Valve's FEX compat tool, which runs FEX with FEX_PORTABLE=1 + # - that makes FEX look for its config next to the binary, while the tool writes one into the + # app's compatdata instead. FEX therefore starts with no rootfs, every x86_64 library lookup + # falls through to the host, and the guest shell dies on libreadline before the game is reached. + # FEX_ROOTFS names it outright and is read whatever the config situation. + [ -d /usr/share/guestos/fex-mesa ] && export FEX_ROOTFS=/usr/share/guestos/fex-mesa + # The client exits 42 when it has updated itself and wants a fresh start (steam.sh does this). + while :; do + step "starting the Steam client" + "$steam_root/steamrtarm64/steam" -gamepadui -clientbeta publicbeta \ + -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 \ + -cef-use-gl=angle -cef-use-angle=vulkan "$@" + rc=$? + echo "== steam exited rc=$rc" + collect_steam_logs + [ "$rc" -eq 42 ] || break + done + reap_orphans + exit "$rc" + ;; + *) + echo "bannerlator-session: unknown mode '$mode'" >&2 + exit 64 + ;; +esac diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat new file mode 100755 index 0000000000..73a5feda45 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-compat @@ -0,0 +1,285 @@ +#!/usr/bin/python3 +# Makes the ARM64 Proton the client already downloaded usable here, and sets it as the default tool +# for Windows titles (CompatToolMapping "0" in config.vdf) when the user has not chosen one. Run +# before the client starts; it rewrites config.vdf on exit. +# +# bannerlator-steam-compat <steam root> +# +# Valve ships a native aarch64 Proton (arm64ec Wine with FEX as the x86 layer) as an ordinary depot, +# which is exactly what this runtime wants. Its toolmanifest declares require_tool_appid 4185400 - +# Steam Linux Runtime 4 for arm64 - so Steam stacks pressure-vessel underneath it, and +# pressure-vessel needs unprivileged user namespaces, which an Android app does not get. Steam then +# drops the launch on the floor: no window, no log, straight back to the library. +# +# So the depot is re-registered here as a compatibility tool of our own: every entry symlinked so +# nothing is copied and Steam still updates the real depot, but with a toolmanifest that leaves out +# require_tool_appid. Proton takes its base directory from dirname(sys.argv[0]) without resolving +# it, so it reads files/ through those symlinks and runs directly on this rootfs. +import os +import re +import shutil +import sys + +TOOL = "bannerlator-proton-arm64" +# Valve's own ARM64 Proton, by the name the client registers it under. Used only to bootstrap a +# fresh install: naming it is what makes the client offer it and fetch the depot. +SEED_TOOL = "proton-experimental-arm64" +# The ARM64 Proton depot the client downloads for itself, as a compatibility-tool appid. +# The session asks the client to install it on the command line the first time (steam://install), +# so a new client has it before a Windows title is first launched. It is deliberately NOT named as +# this tool's dependency: a dependency is composed with its own dependencies, and this depot +# requires 4185400, the arm64 Steam Linux Runtime, whose container needs user namespaces Android +# does not give - the launch would be wrapped in it and die before this tool ever ran. +PROTON_ARM64_APPID = "4427310" +LAUNCHER = "bannerlator-proton" +# The extra Steam library the app mounts the installed games into (see bannerlator-steam-library). +# installed_apps() scans it too; it lives only in the sibling script, so define it here as well. +LIBRARY = "/mnt/bannerlator" # the card library is LIBRARY + "-sd"; internal storage is steam_root itself +# The client lists its own "Proton Experimental (ARM64)" and "Proton 11.0 (ARM64)" in the same +# Compatibility dropdown, and those are the two that cannot start a game here. Ours has to be +# unmistakable at a glance, or a user picks a neighbour and gets a launch that fails silently. +# Newest first: whichever the client has downloaded is used. +SOURCES = ("Proton Experimental (ARM64)", "Proton 11.0 (ARM64)") +# Written by us; everything else in the depot is symlinked through. +OWN_FILES = ("toolmanifest.vdf", "compatibilitytool.vdf", "bannerlator-proton") +# The client assigns a Proton to a Windows title by itself, as a per-app CompatToolMapping entry at +# priority 250 - which outranks the "0" default, so setting that default alone changes nothing. Every +# Proton it can pick is one this runtime cannot start: the ARM64 ones want pressure-vessel (see +# above) and the x86_64 ones want pressure-vessel and FEX on top. Ours is the only one that runs +# here, so every Proton mapping is repointed at it. Tools that are not Proton are left alone. +COMPAT_TOOL_VDF = """"compatibilitytools" +{ + "compat_tools" + { + "%s" + { + "install_path" "." + "display_name" "Bannerlator Proton (ARM64)" + "from_oslist" "windows" + "to_oslist" "linux" + } + } +} +""" +TOOL_MANIFEST_VDF = """"manifest" +{ + "version" "2" + "commandline" "/%s %%verb%%" + "use_sessions" "1" + "compatmanager_layer_name" "proton" +} +""" % LAUNCHER + +# Resolves the depot at launch time, so the tool can be registered before the depot exists and +# survives the client updating or replacing it. Proton takes its base directory from +# dirname(sys.argv[0]) without resolving it, so it is run from the depot itself. +LAUNCHER_SH = """#!/bin/bash +# Bannerlator Proton (ARM64): runs the ARM64 Proton the Steam client downloaded, without the +# Steam Linux Runtime container its own manifest asks for (no user namespaces on Android). +verb=$1; shift +steam_root=${STEAM_COMPAT_CLIENT_INSTALL_PATH:-${XDG_DATA_HOME:-$HOME/.local/share}/Steam} +# The client preloads its overlay library into every game. In a gamescope session the overlay is +# the client's own window, so the library draws nothing - but it stands in front of open() and +# read() on /dev/input, lets Wine open the session's pad and answers every read of it with nothing: +# a controller that never reports, and Wine's HID thread spinning a core on it. Dropped here; +# anything else in LD_PRELOAD is kept. +kept= +IFS=': ' +for lib in ${LD_PRELOAD:-}; do + case $lib in */gameoverlayrenderer.so) ;; *) kept=${kept:+$kept:}$lib ;; esac +done +unset IFS +if [ -n "$kept" ]; then export LD_PRELOAD="$kept"; else unset LD_PRELOAD; fi +for name in %s; do + depot="$steam_root/steamapps/common/$name" + if [ -d "$depot/files/bin-arm64" ] && [ -x "$depot/proton" ]; then + exec "$depot/proton" "$verb" "$@" + fi +done +echo "bannerlator-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2 +exit 1 +""" % " ".join('"%s"' % n for n in SOURCES) + +TOKEN = re.compile(r'\s*(?:"((?:[^"\\]|\\.)*)"|([{}])|//[^\n]*)') + + +def tokenize(text): + tokens = [] + pos = 0 + while pos < len(text): + m = TOKEN.match(text, pos) + if not m or m.end() == pos: + break + pos = m.end() + if m.group(2): + tokens.append(m.group(2)) + elif m.group(1) is not None: + tokens.append('"' + m.group(1) + '"') + return tokens + + +def find_block(tokens, path): + """Index of the '{' opening the block at path, or None.""" + depth, want, i = 0, 0, 0 + while i < len(tokens): + t = tokens[i] + if t == "{": + depth += 1 + elif t == "}": + depth -= 1 + if depth < want: + return None + elif depth == want and i + 1 < len(tokens) and tokens[i + 1] == "{": + if t.lower() == '"%s"' % path[want].lower(): + if want == len(path) - 1: + return i + 1 + want += 1 + i += 1 + return None + + +def block_end(tokens, start): + depth = 0 + for i in range(start, len(tokens)): + if tokens[i] == "{": + depth += 1 + elif tokens[i] == "}": + depth -= 1 + if depth == 0: + return i + return len(tokens) + + +def serialize(tokens): + out, depth, i = [], 0, 0 + while i < len(tokens): + t = tokens[i] + if t == "}": + depth -= 1 + out.append("\t" * depth + "}") + i += 1 + elif i + 1 < len(tokens) and tokens[i + 1] == "{": + out.append("\t" * depth + t) + out.append("\t" * depth + "{") + depth += 1 + i += 2 + else: + out.append("\t" * depth + t + "\t\t" + tokens[i + 1]) + i += 2 + return "\n".join(out) + "\n" + + +# Steam's own tools and runtimes live in steamapps beside the games; they are not titles and must +# not be mapped to a compatibility tool. +NOT_GAMES = frozenset(( + "228980", # Steamworks Common Redistributables + "1070560", # Steam Linux Runtime 1.0 (scout) + "1391110", # Steam Linux Runtime 2.0 (soldier) + "1493710", # Proton Experimental + "3127680", # FEX + "4183110", # Steam Linux Runtime 4.0 + "4185400", # Steam Linux Runtime 4.0 - Arm64 + "4427310", # Proton Experimental (ARM64) + "4628740", # Proton 11.0 (ARM64) +)) + + +def installed_apps(steam_root): + """App ids of the titles the client has installed, tools and runtimes excluded.""" + apps = set() + for library in (steam_root, LIBRARY + "-sd"): + steamapps = os.path.join(library, "steamapps") + try: + names = os.listdir(steamapps) + except OSError: + continue + for name in names: + m = re.fullmatch(r"appmanifest_(\d+)\.acf", name) + if m and m.group(1) not in NOT_GAMES: + apps.add(m.group(1)) + return sorted(apps, key=int) + + +def register_default(config_path, apps=(), name=None): + """Writes the mapping. `name` defaults to our own tool; the first-run seed passes Valve's.""" + tool = name or TOOL + with open(config_path, encoding="utf-8", errors="replace") as f: + tokens = tokenize(f.read()) + steam = find_block(tokens, ["InstallConfigStore", "Software", "Valve", "Steam"]) + if steam is None: + return + mapping = find_block(tokens[steam + 1:], ["CompatToolMapping"]) + entry = ['"0"', "{", '"name"', '"%s"' % tool, '"config"', '""', '"priority"', '"75"', "}"] + if mapping is None: + end = block_end(tokens, steam) + tokens[end:end] = ['"CompatToolMapping"', "{"] + entry + ["}"] + else: + mapping += steam + 1 + # Repoint every per-app entry the client aimed at a Proton it cannot actually start. + for i in range(mapping, block_end(tokens, mapping)): + named = tokens[i + 1].strip('"').lower() + if tokens[i] == '"name"' and named.startswith("proton") and named != tool: + tokens[i + 1] = '"%s"' % tool + if find_block(tokens[mapping + 1:], ["0"]) is None: + tokens[mapping + 1:mapping + 1] = entry + # The "0" default only decides how a title is installed, so it settles new downloads and + # leaves anything already installed as a Linux build running as one. An entry per installed + # app is what the client's own Compatibility checkbox writes, and is what makes it switch. + for app in apps: + if find_block(tokens[mapping + 1:], [app]) is not None: + continue + tokens[mapping + 1:mapping + 1] = [ + '"%s"' % app, "{", '"name"', '"%s"' % tool, '"config"', '""', '"priority"', '"250"', "}"] + tmp = config_path + ".bannerlator" + with open(tmp, "w", encoding="utf-8") as f: + f.write(serialize(tokens)) + os.replace(tmp, config_path) + + +def find_source(steam_root): + """The ARM64 Proton depot the client has downloaded, or None.""" + common = os.path.join(steam_root, "steamapps", "common") + for name in SOURCES: + depot = os.path.join(common, name) + # bin-arm64 is what makes it the native build rather than the x86_64 one. + if os.path.isdir(os.path.join(depot, "files", "bin-arm64")): + return depot + return None + + +def build_tool(tool_dir): + """Our own manifests and the launcher. The depot is found at launch time, not here.""" + if os.path.islink(tool_dir): + os.unlink(tool_dir) + elif os.path.isdir(tool_dir): + # Earlier versions mirrored the depot in here as symlinks; start clean. + shutil.rmtree(tool_dir) + os.makedirs(tool_dir) + with open(os.path.join(tool_dir, "toolmanifest.vdf"), "w", encoding="utf-8") as f: + f.write(TOOL_MANIFEST_VDF) + with open(os.path.join(tool_dir, "compatibilitytool.vdf"), "w", encoding="utf-8") as f: + f.write(COMPAT_TOOL_VDF % TOOL) + launcher = os.path.join(tool_dir, LAUNCHER) + with open(launcher, "w", encoding="utf-8") as f: + f.write(LAUNCHER_SH) + os.chmod(launcher, 0o755) + + +def main(): + steam_root = sys.argv[1] + tools = os.path.join(steam_root, "compatibilitytools.d") + os.makedirs(tools, exist_ok=True) + build_tool(os.path.join(tools, TOOL)) + depot = find_source(steam_root) + print("bannerlator-steam-compat: registered %s (%s)" % ( + TOOL, "depot %s present" % os.path.basename(depot) if depot else + "no ARM64 Proton depot yet; the session asks the client to fetch it")) + config = os.path.join(steam_root, "config", "config.vdf") + if os.path.isfile(config): + apps = installed_apps(steam_root) + register_default(config, apps) + print("bannerlator-steam-compat: default and %d installed title(s) set to %s" % (len(apps), TOOL)) + + +if __name__ == "__main__": + main() diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-install b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-install new file mode 100755 index 0000000000..de6570426a --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-install @@ -0,0 +1,61 @@ +#!/bin/bash +# Fetches the native arm64 Steam client from Valve's client-update CDN into ~/.local/share/Steam. +# The client is not redistributable, so the runtime ships this script instead of the client. +set -eu +cdn=https://client-update.fastly.steamstatic.com +manifest=steam_client_publicbeta_linuxarm64 +steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam +stamp=$steam_root/package/bannerlator-installed +[ -x "$steam_root/steamrtarm64/steam" ] && [ -f "$stamp" ] && exit 0 + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +curl -fsSL "$cdn/$manifest" -o "$work/manifest" +version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest") +# Every component block: its name, then the plain zip's file name and sha256. +awk -F'"' ' + /^\t"/ && NF >= 3 && $4 == "" { block = $2 } + $2 == "file" { file[block] = $4 } + $2 == "sha2" { sha[block] = $4 } + END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b] } +' "$work/manifest" | sort > "$work/parts" +[ -s "$work/parts" ] || { echo "bannerlator-steam-install: no client components in $manifest" >&2; exit 1; } +total=$(grep -c . "$work/parts" 2>/dev/null || echo 0) + +mkdir -p "$steam_root/package" +while read -r block file sum; do + i=$((${i:-0} + 1)) + echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)" + curl -fsSL "$cdn/$file" -o "$work/$file" + echo "$sum $work/$file" | sha256sum -c --quiet + unzip -qo "$work/$file" -d "$steam_root" + rm -f "$work/$file" +done < "$work/parts" +# Some entries are zipped with Windows separators; unzip keeps the backslash in the file name. +find "$steam_root" -depth -name '*\\*' | while read -r odd; do + fixed=${odd//\\//} + mkdir -p "$(dirname "$fixed")" + if [ -d "$odd" ]; then + cp -a "$odd/." "$fixed/" && rm -rf "$odd" + else + mv -f "$odd" "$fixed" + fi +done +echo publicbeta > "$steam_root/package/beta" +echo "$version" > "$stamp" +ln -sfn "$steam_root/steamrtarm64" "$steam_root/steamrtarm32" +chmod +x "$steam_root/steamrtarm64/steam" 2>/dev/null || true +# What Valve's steam.sh sets up before it runs the client (it has no arm64 branch itself). +mkdir -p "$HOME/.steam" +ln -sfn "$steam_root" "$HOME/.steam/root" +ln -sfn "$steam_root" "$HOME/.steam/steam" +ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/bin64" +ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdk64" +# The arm64 client runs every game through $HOME/.steam/sdkarm64/steam-launch-wrapper. Valve's +# steam.sh has no arm64 branch to create it, and without it a launch dies in /bin/sh before Proton +# is ever invoked - "No such file or directory", no Proton log, and the only other clue is an +# unrelated-looking installscript assertion. Same target as sdk64; the client picks the name by +# architecture. +ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64" +ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64" +ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32" diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-library b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-library new file mode 100755 index 0000000000..de553f43d6 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-library @@ -0,0 +1,104 @@ +#!/usr/bin/python3 +# Registers the card the app installs to (bound at /mnt/bannerlator-sd) as a library folder of the +# native Steam client, so they show as installed there instead of being downloaded a second time. +# +# bannerlator-steam-library <steam root> +# +# Ported from WinNative's gamescope runtime (GPL-3.0). +import os +import re +import sys + +# The client's own library is internal storage (its steamapps/common is bound to the app's root); +# the card is the one extra library folder. +LIBRARIES = (("/mnt/bannerlator-sd", "Bannerlator (card)"),) + + +def register(steam_root, library, label): + """Adds one library folder to the client's list; the client then offers it as an install + location as well as reading the games already in it. Registered even when empty: a new user + should be able to install straight into it.""" + steamapps = os.path.join(library, "steamapps") + if not os.path.isdir(steamapps): + return 0 + apps = sorted( + int(m.group(1)) + for m in (re.fullmatch(r"appmanifest_(\d+)\.acf", n) for n in os.listdir(steamapps)) + if m + ) + marker = os.path.join(library, "libraryfolder.vdf") + if not os.path.isfile(marker): + with open(marker, "w", encoding="utf-8") as f: + f.write('"libraryfolder"\n{\n\t"contentid"\t\t"%d"\n\t"label"\t\t"%s"\n}\n' + % (int.from_bytes(os.urandom(8), "little"), label)) + steamapps_dir = os.path.join(steam_root, "steamapps") + path = os.path.join(steamapps_dir, "libraryfolders.vdf") + text = "" + if os.path.isfile(path): + with open(path, encoding="utf-8", errors="replace") as f: + text = f.read() + if re.search(r'"path"\s+"%s"' % re.escape(library), text): + return len(apps) + indexes = [int(i) for i in re.findall(r'^\t"(\d+)"\s*$', text, re.M)] + if not text.strip(): + text = ('"libraryfolders"\n{\n\t"0"\n\t{\n\t\t"path"\t\t"%s"\n\t\t"label"\t\t""\n\t}\n}\n' + % steam_root) + indexes = [0] + entry = ['\t"%d"' % (max(indexes) + 1), "\t{", '\t\t"path"\t\t"%s"' % library, + '\t\t"label"\t\t"%s"' % label, '\t\t"apps"', "\t\t{"] + entry += ['\t\t\t"%d"\t\t"0"' % app for app in apps] + entry += ["\t\t}", "\t}"] + closing = text.rstrip().rfind("}") + if closing < 0: + return len(apps) + text = text[:closing] + "\n".join(entry) + "\n" + text[closing:] + os.makedirs(steamapps_dir, exist_ok=True) + with open(path, "w", encoding="utf-8") as f: + f.write(text) + print("bannerlator-steam-library: registered %s with %d game(s)" % (library, len(apps))) + return len(apps) + + +RETIRED = ("/mnt/bannerlator",) + + +def forget(steam_root, library): + """Removes a library folder earlier builds registered and this one no longer binds, so the + client does not keep offering a location that is not there.""" + path = os.path.join(steam_root, "steamapps", "libraryfolders.vdf") + if not os.path.isfile(path): + return + with open(path, encoding="utf-8", errors="replace") as f: + lines = f.read().split("\n") + out, block, depth = [], None, 0 + for line in lines: + if depth == 1 and re.fullmatch(r'\t"\d+"', line): + block = [line] + continue + if block is not None: + block.append(line) + depth += line.count("{") - line.count("}") + if depth == 1: + if not re.search(r'"path"\s+"%s"' % re.escape(library), "\n".join(block)): + out.extend(block) + block = None + continue + depth += line.count("{") - line.count("}") + out.append(line) + text = "\n".join(out) + if text != "\n".join(lines): + with open(path, "w", encoding="utf-8") as f: + f.write(text) + print("bannerlator-steam-library: forgot %s" % library) + + +def main(): + steam_root = sys.argv[1] + for library in RETIRED: + forget(steam_root, library) + for library, label in LIBRARIES: + register(steam_root, library, label) + + +if __name__ == "__main__": + main() diff --git a/tools/linuxfs/preload/drm.c b/tools/linuxfs/preload/drm.c new file mode 100644 index 0000000000..f2d3ae1926 --- /dev/null +++ b/tools/linuxfs/preload/drm.c @@ -0,0 +1,113 @@ +/* + * GEM handle emulation for the KGSL device presented as a DRM render node. + * + * Compositors and Mesa validate or convert dma-bufs with PRIME ioctls on the render node; KGSL + * has no GEM. Handles only serve as tokens to these callers, so a table of duplicated dma-buf + * descriptors stands in for the kernel's, and every other device is left to libdrm. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <stdint.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <unistd.h> + +#define MAX_HANDLES 4096 + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static int handle_fds[MAX_HANDLES]; +static dev_t kgsl_dev; +static int kgsl_state; /* 0 unknown, 1 known, -1 absent */ + +static int is_kgsl(int fd) { + struct stat st; + pthread_mutex_lock(&lock); + if (kgsl_state == 0) { + kgsl_state = stat("/dev/kgsl-3d0", &st) == 0 ? 1 : -1; + kgsl_dev = st.st_rdev; + } + pthread_mutex_unlock(&lock); + return kgsl_state > 0 && fstat(fd, &st) == 0 && S_ISCHR(st.st_mode) && st.st_rdev == kgsl_dev; +} + +static void *real(const char *name) { + void *fn = dlsym(RTLD_NEXT, name); + if (!fn) { + errno = ENOSYS; + } + return fn; +} + +int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) { + if (!is_kgsl(fd)) { + int (*fn)(int, int, uint32_t *) = (int (*)(int, int, uint32_t *)) real("drmPrimeFDToHandle"); + return fn ? fn(fd, prime_fd, handle) : -ENOSYS; + } + int dup_fd = fcntl(prime_fd, F_DUPFD_CLOEXEC, 0); + if (dup_fd < 0) { + return -errno; + } + int ret = -ENOMEM; + pthread_mutex_lock(&lock); + for (uint32_t i = 1; i < MAX_HANDLES; i++) { + if (handle_fds[i] == 0) { + handle_fds[i] = dup_fd; + *handle = i; + ret = 0; + break; + } + } + pthread_mutex_unlock(&lock); + if (ret) { + close(dup_fd); + } + return ret; +} + +int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) { + if (!is_kgsl(fd)) { + int (*fn)(int, uint32_t, uint32_t, int *) = (int (*)(int, uint32_t, uint32_t, int *)) real("drmPrimeHandleToFD"); + return fn ? fn(fd, handle, flags, prime_fd) : -ENOSYS; + } + int ret = -EINVAL; + pthread_mutex_lock(&lock); + if (handle > 0 && handle < MAX_HANDLES && handle_fds[handle] > 0) { + *prime_fd = fcntl(handle_fds[handle], F_DUPFD_CLOEXEC, 0); + ret = *prime_fd < 0 ? -errno : 0; + } + pthread_mutex_unlock(&lock); + return ret; +} + +int drmCloseBufferHandle(int fd, uint32_t handle) { + if (!is_kgsl(fd)) { + int (*fn)(int, uint32_t) = (int (*)(int, uint32_t)) real("drmCloseBufferHandle"); + return fn ? fn(fd, handle) : -ENOSYS; + } + int ret = -EINVAL; + pthread_mutex_lock(&lock); + if (handle > 0 && handle < MAX_HANDLES && handle_fds[handle] > 0) { + close(handle_fds[handle]); + handle_fds[handle] = 0; + ret = 0; + } + pthread_mutex_unlock(&lock); + return ret; +} + +/* + * fork() carries over only the calling thread, so a lock another thread was holding at that + * instant stays held in the child by a thread that is not there to release it. Taking it before + * the fork makes the copy consistent; the parent then unlocks it and the child, whose one thread + * never locked it, gets a fresh one. (WinNative 79aa7f68.) + */ +static void drm_lock_before_fork(void) { pthread_mutex_lock(&lock); } +static void drm_unlock_after_fork(void) { pthread_mutex_unlock(&lock); } +static void drm_reset_after_fork(void) { pthread_mutex_init(&lock, NULL); } + +__attribute__((constructor)) static void install_drm_fork_handlers(void) { + pthread_atfork(drm_lock_before_fork, drm_unlock_after_fork, drm_reset_after_fork); +} diff --git a/tools/linuxfs/preload/inputudev.c b/tools/linuxfs/preload/inputudev.c new file mode 100644 index 0000000000..b3dffd1f31 --- /dev/null +++ b/tools/linuxfs/preload/inputudev.c @@ -0,0 +1,293 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names + * changed to this project's. The reasoning below is the original author's. + * + * The session's controllers, described to libudev's callers. + * + * The pads are evdev nodes the app backs with its own input rings, bound over /dev/input. Wine's + * HID bus finds them there, but it identifies a node by resolving /sys/class/input/<name> and + * asking libudev about the result: on Android that resolves to whatever real input device the + * host numbered the same, whose device node libudev cannot read, so every pad is discarded before + * its identity is ever looked at. The fallback is Wine's SDL bus, and SDL enumerates through udev + * too, over a netlink socket the app sandbox refuses. A game was left with no controller at all + * while the Steam client, which reads the nodes itself, had one. + * + * So the pads are described here instead: the resolved path is answered for the session's own + * nodes, and libudev's accessors answer for that path from what the app already knows. They carry + * the identity of the pad Steam Input would present if it could - it has no /dev/uinput here to + * make one - which is the one identity Wine's own bus keeps rather than handing on to SDL. + * + * Only Wine's device host is answered, and only for the session's own nodes: the Steam client + * enumerates the same nodes for itself and would take a pad wearing Steam Input's identity for one + * of its own and ignore it. Every other caller, path and device object goes straight through. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <limits.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/sysmacros.h> +#include <sys/types.h> + +/* The app opens one ring per configured controller; four is what its launcher offers. */ +#define PAD_MAX 4 +#define EVENT_MINOR_BASE 64 + +/* BUS_VIRTUAL, and the identity Steam Input gives the gamepad it presents to a game. */ +#define PAD_UEVENT_FORMAT \ + "PRODUCT=6/28de/11ff/110\n" \ + "NAME=\"Generic HID Gamepad %d\"\n" \ + "PHYS=\"usb-fakeinput/input%d\"\n" + +struct pad { + char syspath[64]; + char devnode[32]; + char sysname[16]; + char uevent[128]; + dev_t devnum; +}; + +static struct pad pads[PAD_MAX]; +static int pad_count; + +/* + * The slots the app published rings for, named in FAKE_EVDEV_MEMFD_PATHS as "<slot>=<path>" + * separated by semicolons. Without it the process has no pads of the session's and every call + * here is a passthrough. + */ +static void discover_pads(void) { + const char *spec = getenv("FAKE_EVDEV_MEMFD_PATHS"); + const char *entry; + + if (spec == NULL) return; + for (entry = spec; *entry != '\0';) { + char *end; + long slot = strtol(entry, &end, 10); + + if (end != entry && *end == '=' && slot >= 0 && slot < PAD_MAX) { + struct pad *pad = &pads[slot]; + + if (pad->devnode[0] == '\0') { + snprintf(pad->sysname, sizeof(pad->sysname), "event%ld", slot); + snprintf(pad->syspath, sizeof(pad->syspath), "/sys/devices/virtual/input/bannerlator%ld", + slot); + snprintf(pad->devnode, sizeof(pad->devnode), "/dev/input/event%ld", slot); + snprintf(pad->uevent, sizeof(pad->uevent), PAD_UEVENT_FORMAT, (int)slot, (int)slot); + pad->devnum = makedev(13, EVENT_MINOR_BASE + (unsigned int)slot); + if (slot >= pad_count) pad_count = (int)slot + 1; + } + } + entry = strchr(entry, ';'); + if (entry == NULL) break; + entry++; + } +} + +static void ensure_pads(void) { + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, discover_pads); +} + +/* The pad a synthetic syspath names, or NULL when the path is not one of ours. */ +static struct pad *pad_for_syspath(const char *syspath) { + int i; + + if (syspath == NULL) return NULL; + ensure_pads(); + for (i = 0; i < pad_count; i++) { + if (pads[i].devnode[0] != '\0' && strcmp(pads[i].syspath, syspath) == 0) return &pads[i]; + } + return NULL; +} + +/* A device object is ours exactly when it is one of the pads. */ +static struct pad *pad_for_device(void *device) { + int i; + + if (device == NULL) return NULL; + ensure_pads(); + for (i = 0; i < pad_count; i++) { + if (&pads[i] == device) return pads[i].devnode[0] != '\0' ? &pads[i] : NULL; + } + return NULL; +} + +/* The pad /sys/class/input/<name> stands for, or NULL when the path names something else. */ +static struct pad *pad_for_syslink(const char *path) { + static const char prefix[] = "/sys/class/input/"; + const char *name; + int i; + + if (path == NULL || strncmp(path, prefix, sizeof(prefix) - 1) != 0) return NULL; + name = path + sizeof(prefix) - 1; + ensure_pads(); + for (i = 0; i < pad_count; i++) { + if (pads[i].devnode[0] != '\0' && strcmp(pads[i].sysname, name) == 0) return &pads[i]; + } + return NULL; +} + +static void *next_symbol(const char *name) { return dlsym(RTLD_NEXT, name); } + +/* Wine reaches libudev from its HID bus driver, which is the only caller these pads are for. */ +static int caller_is_winebus(void *caller) { + Dl_info info; + + if (dladdr(caller, &info) == 0 || info.dli_fname == NULL) return 0; + return strstr(info.dli_fname, "winebus.so") != NULL; +} + +char *realpath(const char *path, char *resolved) { + static char *(*real_realpath)(const char *, char *); + void *caller = __builtin_return_address(0); + struct pad *pad = caller_is_winebus(caller) ? pad_for_syslink(path) : NULL; + + if (pad != NULL) { + if (resolved == NULL) return strdup(pad->syspath); + /* PATH_MAX is what the caller promises when it passes a buffer. */ + memcpy(resolved, pad->syspath, strlen(pad->syspath) + 1); + return resolved; + } + if (real_realpath == NULL) real_realpath = next_symbol("realpath"); + if (real_realpath == NULL) return NULL; + return real_realpath(path, resolved); +} + +void *udev_device_new_from_syspath(void *udev, const char *syspath) { + static void *(*real_new)(void *, const char *); + void *caller = __builtin_return_address(0); + struct pad *pad = caller_is_winebus(caller) ? pad_for_syspath(syspath) : NULL; + + if (pad != NULL) return pad; + if (real_new == NULL) real_new = next_symbol("udev_device_new_from_syspath"); + if (real_new == NULL) return NULL; + return real_new(udev, syspath); +} + +void *udev_device_ref(void *device) { + static void *(*real_ref)(void *); + + if (pad_for_device(device) != NULL) return device; + if (real_ref == NULL) real_ref = next_symbol("udev_device_ref"); + if (real_ref == NULL) return NULL; + return real_ref(device); +} + +void *udev_device_unref(void *device) { + static void *(*real_unref)(void *); + + if (pad_for_device(device) != NULL) return NULL; + if (real_unref == NULL) real_unref = next_symbol("udev_device_unref"); + if (real_unref == NULL) return NULL; + return real_unref(device); +} + +const char *udev_device_get_devnode(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return pad->devnode; + if (real_get == NULL) real_get = next_symbol("udev_device_get_devnode"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +const char *udev_device_get_syspath(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return pad->syspath; + if (real_get == NULL) real_get = next_symbol("udev_device_get_syspath"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +const char *udev_device_get_sysname(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return pad->sysname; + if (real_get == NULL) real_get = next_symbol("udev_device_get_sysname"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +const char *udev_device_get_subsystem(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return "input"; + if (real_get == NULL) real_get = next_symbol("udev_device_get_subsystem"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +const char *udev_device_get_devtype(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return NULL; + if (real_get == NULL) real_get = next_symbol("udev_device_get_devtype"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +const char *udev_device_get_action(void *device) { + static const char *(*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return NULL; + if (real_get == NULL) real_get = next_symbol("udev_device_get_action"); + if (real_get == NULL) return NULL; + return real_get(device); +} + +dev_t udev_device_get_devnum(void *device) { + static dev_t (*real_get)(void *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return pad->devnum; + if (real_get == NULL) real_get = next_symbol("udev_device_get_devnum"); + if (real_get == NULL) return makedev(0, 0); + return real_get(device); +} + +/* + * A pad has no bus behind it, so it stands in for its own input device and has no other parent. + * The reference is a borrowed one either way. + */ +void *udev_device_get_parent_with_subsystem_devtype(void *device, const char *subsystem, + const char *devtype) { + static void *(*real_get)(void *, const char *, const char *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) { + if (subsystem != NULL && strcmp(subsystem, "input") == 0 && devtype == NULL) return pad; + return NULL; + } + if (real_get == NULL) real_get = next_symbol("udev_device_get_parent_with_subsystem_devtype"); + if (real_get == NULL) return NULL; + return real_get(device, subsystem, devtype); +} + +const char *udev_device_get_sysattr_value(void *device, const char *attr) { + static const char *(*real_get)(void *, const char *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return attr != NULL && strcmp(attr, "uevent") == 0 ? pad->uevent : NULL; + if (real_get == NULL) real_get = next_symbol("udev_device_get_sysattr_value"); + if (real_get == NULL) return NULL; + return real_get(device, attr); +} + +const char *udev_device_get_property_value(void *device, const char *key) { + static const char *(*real_get)(void *, const char *); + struct pad *pad = pad_for_device(device); + + if (pad != NULL) return key != NULL && strcmp(key, "ID_INPUT_JOYSTICK") == 0 ? "1" : NULL; + if (real_get == NULL) real_get = next_symbol("udev_device_get_property_value"); + if (real_get == NULL) return NULL; + return real_get(device, key); +} diff --git a/tools/linuxfs/preload/lock.c b/tools/linuxfs/preload/lock.c new file mode 100644 index 0000000000..a11d024e26 --- /dev/null +++ b/tools/linuxfs/preload/lock.c @@ -0,0 +1,109 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names + * changed to this project's. The reasoning below is the original author's. + * + * File locking for the game library on external storage. + * + * The user's games are bound in from /storage/emulated, which Android serves over FUSE, and that + * filesystem implements no locking at all: flock() and fcntl()'s lock commands answer ENOSYS for + * every file under it. The Steam client takes a shared lock on each content file as it validates + * or updates a title and treats the refusal as a failure, so a download walks its progress back + * and forth instead of finishing; a game reading its own data hits the same wall. + * + * Where the kernel can lock, it does: the real call runs first and its answer stands, so files on + * the app's own f2fs storage keep genuine cross-process exclusion. Only the filesystem that cannot + * lock at all is answered here, and granting is the honest reading of it - a filesystem with no + * lock state has nothing to contend over, and the one other party that could contend is inside + * this same session. Reporting failure instead buys no safety and costs the download. + * + * F_GETLK is the exception: it asks who holds a lock, and on a filesystem holding none the true + * answer is "nobody", so it is reported unlocked rather than granted. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <stdarg.h> +#include <stddef.h> +#include <sys/file.h> +#include <unistd.h> + +/* The filesystem refuses the whole operation, rather than declining this particular lock. */ +static int unsupported(int error) { + return error == ENOSYS || error == ENOTSUP || error == EOPNOTSUPP; +} + +int flock(int fd, int operation) { + static int (*real_flock)(int, int); + int result; + + if (real_flock == NULL) real_flock = dlsym(RTLD_NEXT, "flock"); + if (real_flock == NULL) return 0; + result = real_flock(fd, operation); + if (result < 0 && unsupported(errno)) return 0; + return result; +} + +/* + * fcntl()'s third argument is an int, a pointer, or absent depending on the command; only the + * lock commands are of interest here and all of those take a struct flock *. Anything else is + * passed straight through as a void * - wide enough for both an int and a pointer on every ABI + * the runtime is built for. + */ +static int is_lock_command(int cmd) { + switch (cmd) { + case F_SETLK: + case F_SETLKW: +#ifdef F_OFD_SETLK + case F_OFD_SETLK: +#endif +#ifdef F_OFD_SETLKW + case F_OFD_SETLKW: +#endif + return 1; + default: + return 0; + } +} + +static int is_lock_query(int cmd) { + switch (cmd) { + case F_GETLK: +#ifdef F_OFD_GETLK + case F_OFD_GETLK: +#endif + return 1; + default: + return 0; + } +} + +int fcntl(int fd, int cmd, ...) { + static int (*real_fcntl)(int, int, ...); + va_list ap; + void *arg; + int result; + + va_start(ap, cmd); + arg = va_arg(ap, void *); + va_end(ap); + + if (real_fcntl == NULL) real_fcntl = dlsym(RTLD_NEXT, "fcntl"); + if (real_fcntl == NULL) { + errno = ENOSYS; + return -1; + } + result = real_fcntl(fd, cmd, arg); + if (result >= 0 || !unsupported(errno)) return result; + if (is_lock_command(cmd)) return 0; + if (is_lock_query(cmd) && arg != NULL) { + ((struct flock *)arg)->l_type = F_UNLCK; + return 0; + } + return result; +} + +#if defined(__GLIBC__) && defined(F_SETLK64) +/* glibc's large-file build redirects both names; the runtime is 64-bit, so they are the same call. */ +int fcntl64(int fd, int cmd, ...) __attribute__((alias("fcntl"))); +#endif diff --git a/tools/linuxfs/preload/net.c b/tools/linuxfs/preload/net.c new file mode 100644 index 0000000000..babe95bdda --- /dev/null +++ b/tools/linuxfs/preload/net.c @@ -0,0 +1,247 @@ +/* + * Loopback socket ownership for Steam's IPC peer check. + * + * Steam validates a websocket peer by running lsof to find which process owns a 127.0.0.1 port. + * The Android sandbox denies both /proc/net/tcp and sock_diag, so no tool can answer. Every Steam + * process is preloaded with this library, so each records the ports it binds and connects, and the + * lsof Steam spawns is answered from that shared registry instead of being run. + */ +#define _GNU_SOURCE +#include <arpa/inet.h> +#include <spawn.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <linux/netlink.h> +#include <netinet/in.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <errno.h> +#include <unistd.h> + +static const char *net_dir(void) { + static char dir[256]; + if (!dir[0]) { + const char *base = getenv("BL_SYSV_DIR"); + snprintf(dir, sizeof(dir), "%s/net", base && *base ? base : "/dev/shm/wnsysv"); + char parent[256]; + snprintf(parent, sizeof(parent), "%s", dir); + char *slash = strrchr(parent, '/'); + if (slash) { + *slash = '\0'; + mkdir(parent, 0777); + } + mkdir(dir, 0777); + } + return dir; +} + +/* Record that this process owns a loopback socket on its local port; peer is the far end's port, + * 0 for a listening socket. */ +static void record_port(int fd, unsigned peer) { + struct sockaddr_storage ss; + socklen_t len = sizeof(ss); + if (getsockname(fd, (struct sockaddr *)&ss, &len) != 0) { + return; + } + unsigned port; + if (ss.ss_family == AF_INET) { + struct sockaddr_in *in = (struct sockaddr_in *)&ss; + if (in->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) { + return; + } + port = ntohs(in->sin_port); + } else if (ss.ss_family == AF_INET6) { + port = ntohs(((struct sockaddr_in6 *)&ss)->sin6_port); + } else { + return; + } + if (port == 0) { + return; + } + char path[300]; + snprintf(path, sizeof(path), "%s/p%u", net_dir(), port); + char line[64]; + int n = snprintf(line, sizeof(line), "%d %d %d %u\n", (int)getpid(), (int)getppid(), (int)getuid(), peer); + int out = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (out >= 0) { + if (write(out, line, n) != n) { /* best effort */ } + close(out); + } +} + +static unsigned addr_port(const struct sockaddr *addr, socklen_t len) { + if (addr && addr->sa_family == AF_INET && len >= sizeof(struct sockaddr_in)) { + return ntohs(((const struct sockaddr_in *)addr)->sin_port); + } + if (addr && addr->sa_family == AF_INET6 && len >= sizeof(struct sockaddr_in6)) { + return ntohs(((const struct sockaddr_in6 *)addr)->sin6_port); + } + return 0; +} + +static unsigned peer_port(int fd) { + struct sockaddr_storage ps; + socklen_t plen = sizeof(ps); + if (getpeername(fd, (struct sockaddr *)&ps, &plen) != 0) { + return 0; + } + return addr_port((struct sockaddr *)&ps, plen); +} + +typedef int (*bind_fn)(int, const struct sockaddr *, socklen_t); +typedef int (*listen_fn)(int, int); +typedef int (*connect_fn)(int, const struct sockaddr *, socklen_t); +typedef int (*accept4_fn)(int, struct sockaddr *, socklen_t *, int); + +/* udevmon.c: a stand-in for the netlink socket the sandbox refuses, bound here without the kernel. */ +__attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd); + +int bind(int fd, const struct sockaddr *addr, socklen_t len) { + static bind_fn real; + if (!real) real = (bind_fn)dlsym(RTLD_NEXT, "bind"); + if (bl_udevmon_stand_in(fd)) { + if (addr == NULL || len < sizeof(struct sockaddr_nl) || addr->sa_family != AF_NETLINK) { + errno = EINVAL; + return -1; + } + return 0; + } + int ret = real(fd, addr, len); + if (ret == 0) record_port(fd, 0); + return ret; +} + +int listen(int fd, int backlog) { + static listen_fn real; + if (!real) real = (listen_fn)dlsym(RTLD_NEXT, "listen"); + int ret = real(fd, backlog); + if (ret == 0) record_port(fd, 0); + return ret; +} + +int connect(int fd, const struct sockaddr *addr, socklen_t len) { + static connect_fn real; + if (!real) real = (connect_fn)dlsym(RTLD_NEXT, "connect"); + int ret = real(fd, addr, len); + if (ret == 0 || errno == EINPROGRESS) { + /* The caller goes on to test for EINPROGRESS, which the bookkeeping must not disturb. */ + int saved = errno; + record_port(fd, addr_port(addr, len)); + errno = saved; + } + return ret; +} + +int accept4(int fd, struct sockaddr *addr, socklen_t *len, int flags) { + static accept4_fn real; + if (!real) real = (accept4_fn)dlsym(RTLD_NEXT, "accept4"); + int ret = real(fd, addr, len, flags); + if (ret >= 0) record_port(ret, peer_port(ret)); + return ret; +} + +int accept(int fd, struct sockaddr *addr, socklen_t *len) { + return accept4(fd, addr, len, 0); +} + +/* lsof would read the denied /proc/net/tcp; answer its -i TCP@host:port query from the registry + * instead of executing it. Recognised only when invoked as lsof with that query. */ +static int maybe_answer_lsof(const char *path, char *const argv[]) { + const char *base = strrchr(path, '/'); + base = base ? base + 1 : path; + if (strcmp(base, "lsof") != 0) { + return 0; + } + const char *port_str = NULL; + for (int i = 0; argv[i]; i++) { + const char *at = strstr(argv[i], "TCP@"); + if (at) { + const char *colon = strrchr(at, ':'); + if (colon) port_str = colon + 1; + } + } + if (!port_str) { + return 0; + } + char path_buf[300]; + snprintf(path_buf, sizeof(path_buf), "%s/p%u", net_dir(), (unsigned)atoi(port_str)); + int in = open(path_buf, O_RDONLY); + if (in < 0) { + _exit(1); /* lsof exit code for "nothing found" */ + } + char buf[64]; + int n = read(in, buf, sizeof(buf) - 1); + close(in); + if (n <= 0) { + _exit(1); + } + buf[n] = '\0'; + int pid = 0, ppid = 0, uid = 0; + unsigned peer = 0; + sscanf(buf, "%d %d %d %u", &pid, &ppid, &uid, &peer); + /* Steam splits the address on "->" and wants exactly two halves, taking the port it asked + * about from the left one; only a listening socket has no far end. */ + char out[160]; + int m = peer ? snprintf(out, sizeof(out), "p%d\nR%d\nu%d\nn127.0.0.1:%u->127.0.0.1:%u\n", + pid, ppid, uid, (unsigned)atoi(port_str), peer) + : snprintf(out, sizeof(out), "p%d\nR%d\nu%d\nn127.0.0.1:%u\n", + pid, ppid, uid, (unsigned)atoi(port_str)); + if (write(1, out, m) != m) { /* best effort */ } + _exit(0); +} + +int execve(const char *path, char *const argv[], char *const envp[]) { + static int (*real)(const char *, char *const[], char *const[]); + if (!real) real = (int (*)(const char *, char *const[], char *const[]))dlsym(RTLD_NEXT, "execve"); + maybe_answer_lsof(path, argv); + return real(path, argv, envp); +} + +/* popen(3) and posix_spawn(3) reach lsof without going through the execve symbol above. The + * check is cheap, so a spawned lsof is answered here too by handling it in a short-lived child. */ +static int answer_lsof_via_spawn(const char *path, char *const argv[], pid_t *pid) { + pid_t child = fork(); + if (child < 0) { + return errno; + } + if (child == 0) { + maybe_answer_lsof(path, argv); + _exit(127); + } + if (pid) { + *pid = child; + } + return 0; +} + +int execvp(const char *file, char *const argv[]) { + static int (*real)(const char *, char *const[]); + if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execvp"); + maybe_answer_lsof(file, argv); + return real(file, argv); +} + +int execv(const char *path, char *const argv[]) { + static int (*real)(const char *, char *const[]); + if (!real) real = (int (*)(const char *, char *const[]))dlsym(RTLD_NEXT, "execv"); + maybe_answer_lsof(path, argv); + return real(path, argv); +} + +int posix_spawn(pid_t *pid, const char *path, const posix_spawn_file_actions_t *fa, + const posix_spawnattr_t *attr, char *const argv[], char *const envp[]) { + const char *base = strrchr(path, '/'); + base = base ? base + 1 : path; + if (strcmp(base, "lsof") == 0 && !fa) { + return answer_lsof_via_spawn(path, argv, pid); + } + static int (*real)(pid_t *, const char *, const posix_spawn_file_actions_t *, + const posix_spawnattr_t *, char *const[], char *const[]); + if (!real) real = (int (*)(pid_t *, const char *, const posix_spawn_file_actions_t *, + const posix_spawnattr_t *, char *const[], char *const[]))dlsym(RTLD_NEXT, "posix_spawn"); + return real(pid, path, fa, attr, argv, envp); +} diff --git a/tools/linuxfs/preload/netif.c b/tools/linuxfs/preload/netif.c new file mode 100644 index 0000000000..4b79c3f3f9 --- /dev/null +++ b/tools/linuxfs/preload/netif.c @@ -0,0 +1,506 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names + * changed to this project's. The reasoning below is the original author's. + * + * Network interfaces for a sandbox that hides them. + * + * Android denies an app the rtnetlink dump behind getifaddrs() and if_nameindex(), the hardware + * address ioctl, and every table under /proc/net. Wine builds its adapter, address, route and + * neighbour tables from exactly those, so a game saw a machine with no adapter, no address, no + * gateway and no MAC, and one that checks its adapters before going online waited for good. + * The app knows the real link from ConnectivityManager and writes it to /etc/bannerlator-net; + * whatever the kernel refuses is answered from that file. Anything the kernel does answer wins. + */ +#define _GNU_SOURCE 1 +#include <arpa/inet.h> +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <ifaddrs.h> +#include <net/if.h> +#include <net/if_arp.h> +#include <netpacket/packet.h> +#include <netinet/in.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/socket.h> +#include <unistd.h> + +#define LINK_FILE "/etc/bannerlator-net" +#define LO_NAME "lo" +#define LO_INDEX 1 +#define LO_MTU 65536 +#define MAX_ADDRS 16 + +struct link_addr { + int family; + unsigned char bytes[16]; + unsigned prefix; +}; + +struct link { + char name[IFNAMSIZ]; + unsigned index; + int mtu; + unsigned char mac[6]; + struct link_addr addrs[MAX_ADDRS]; + int addr_count; + struct link_addr gateways[2]; + int gateway_count; +}; + +static int parse_addr(const char *text, struct link_addr *out) { + memset(out, 0, sizeof(*out)); + if (inet_pton(AF_INET, text, out->bytes) == 1) out->family = AF_INET; + else if (inet_pton(AF_INET6, text, out->bytes) == 1) out->family = AF_INET6; + else return 0; + return 1; +} + +/* Read on every call: the app rewrites the file when the device changes network. */ +static int load_link(struct link *link) { + typedef FILE *(*fopen_fn)(const char *, const char *); + fopen_fn real_fopen = (fopen_fn) dlsym(RTLD_NEXT, "fopen"); + FILE *f = real_fopen ? real_fopen(LINK_FILE, "re") : NULL; + if (f == NULL) return 0; + + memset(link, 0, sizeof(*link)); + char line[160], text[64]; + unsigned m[6], prefix; + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "if %15s %u %d", link->name, &link->index, &link->mtu) == 3) continue; + if (sscanf(line, "mac %2x:%2x:%2x:%2x:%2x:%2x", m, m + 1, m + 2, m + 3, m + 4, m + 5) == 6) { + for (int i = 0; i < 6; i++) link->mac[i] = (unsigned char) m[i]; + } else if (sscanf(line, "addr %63s %u", text, &prefix) == 2) { + struct link_addr addr; + if (link->addr_count < MAX_ADDRS && parse_addr(text, &addr) + && prefix <= (addr.family == AF_INET ? 32u : 128u)) { + addr.prefix = prefix; + link->addrs[link->addr_count++] = addr; + } + } else if (sscanf(line, "gw %63s", text) == 1) { + struct link_addr addr; + if (link->gateway_count < 2 && parse_addr(text, &addr)) { + link->gateways[link->gateway_count++] = addr; + } + } + } + fclose(f); + return link->name[0] != '\0' && link->index > LO_INDEX && link->addr_count > 0; +} + +static void prefix_mask(int family, unsigned prefix, unsigned char *out) { + int len = family == AF_INET ? 4 : 16; + for (int i = 0; i < len; i++, prefix -= prefix < 8 ? prefix : 8) { + out[i] = prefix >= 8 ? 0xff : (unsigned char) (0xff00 >> prefix); + } +} + +static int is_link_local(const struct link_addr *addr) { + return addr->family == AF_INET6 && addr->bytes[0] == 0xfe && (addr->bytes[1] & 0xc0) == 0x80; +} + +/* One allocation per list. ifa_data of the head points at the head itself, which glibc never + * does, so freeifaddrs() can tell the two kinds of list apart without keeping any state. */ +struct entry { + struct ifaddrs ifa; + struct sockaddr_storage addr, mask, extra; + char name[IFNAMSIZ]; +}; + +static struct entry *fill_entry(struct entry *e, const char *name, unsigned flags) { + snprintf(e->name, sizeof(e->name), "%s", name); + e->ifa.ifa_name = e->name; + e->ifa.ifa_flags = flags; + e->ifa.ifa_addr = (struct sockaddr *) &e->addr; + e[-1].ifa.ifa_next = &e->ifa; + return e; +} + +static void fill_packet(struct entry *e, unsigned index, const unsigned char *mac) { + struct sockaddr_ll *ll = (struct sockaddr_ll *) &e->addr; + ll->sll_family = AF_PACKET; + ll->sll_ifindex = (int) index; + ll->sll_hatype = mac ? ARPHRD_ETHER : ARPHRD_LOOPBACK; + ll->sll_halen = 6; + if (mac) memcpy(ll->sll_addr, mac, 6); +} + +static void fill_inet(struct entry *e, const struct link_addr *addr, unsigned index) { + unsigned char mask[16]; + prefix_mask(addr->family, addr->prefix, mask); + e->ifa.ifa_netmask = (struct sockaddr *) &e->mask; + if (addr->family == AF_INET) { + struct sockaddr_in *sin = (struct sockaddr_in *) &e->addr; + struct sockaddr_in *smask = (struct sockaddr_in *) &e->mask; + sin->sin_family = smask->sin_family = AF_INET; + memcpy(&sin->sin_addr, addr->bytes, 4); + memcpy(&smask->sin_addr, mask, 4); + if (e->ifa.ifa_flags & IFF_BROADCAST) { + struct sockaddr_in *bcast = (struct sockaddr_in *) &e->extra; + bcast->sin_family = AF_INET; + bcast->sin_addr.s_addr = sin->sin_addr.s_addr | ~smask->sin_addr.s_addr; + e->ifa.ifa_broadaddr = (struct sockaddr *) bcast; + } + } else { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &e->addr; + struct sockaddr_in6 *smask = (struct sockaddr_in6 *) &e->mask; + sin6->sin6_family = smask->sin6_family = AF_INET6; + memcpy(&sin6->sin6_addr, addr->bytes, 16); + memcpy(&smask->sin6_addr, mask, 16); + if (is_link_local(addr)) sin6->sin6_scope_id = index; + } +} + +static const struct link_addr LO_V4 = { AF_INET, { 127, 0, 0, 1 }, 8 }; +static const struct link_addr LO_V6 = { AF_INET6, { [15] = 1 }, 128 }; + +static int real_list_usable(const struct ifaddrs *list) { + for (const struct ifaddrs *e = list; e; e = e->ifa_next) { + if (e->ifa_addr && e->ifa_addr->sa_family == AF_INET && !(e->ifa_flags & IFF_LOOPBACK)) { + return 1; + } + } + return 0; +} + +int getifaddrs(struct ifaddrs **out) { + typedef int (*getifaddrs_fn)(struct ifaddrs **); + typedef void (*freeifaddrs_fn)(struct ifaddrs *); + getifaddrs_fn real = (getifaddrs_fn) dlsym(RTLD_NEXT, "getifaddrs"); + struct ifaddrs *list = NULL; + int rc = real(&list); + int saved = errno; + if (rc == 0 && real_list_usable(list)) { + *out = list; + return 0; + } + + struct link link; + if (!load_link(&link)) { + if (rc == 0) *out = list; + errno = saved; + return rc; + } + if (rc == 0 && list) ((freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs"))(list); + + /* A leading slot keeps fill_entry()'s back link in bounds; the list starts after it. */ + struct entry *block = calloc((size_t) link.addr_count + 5, sizeof(*block)); + if (block == NULL) { + errno = ENOMEM; + return -1; + } + unsigned lo_flags = IFF_UP | IFF_RUNNING | IFF_LOOPBACK; + unsigned up_flags = IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST; + struct entry *e = block; + fill_packet(fill_entry(++e, LO_NAME, lo_flags), LO_INDEX, NULL); + fill_inet(fill_entry(++e, LO_NAME, lo_flags), &LO_V4, LO_INDEX); + fill_inet(fill_entry(++e, LO_NAME, lo_flags), &LO_V6, LO_INDEX); + fill_packet(fill_entry(++e, link.name, up_flags), link.index, link.mac); + for (int i = 0; i < link.addr_count; i++) { + fill_inet(fill_entry(++e, link.name, up_flags), &link.addrs[i], link.index); + } + block[1].ifa.ifa_data = &block[1].ifa; + *out = &block[1].ifa; + return 0; +} + +void freeifaddrs(struct ifaddrs *list) { + typedef void (*freeifaddrs_fn)(struct ifaddrs *); + if (list == NULL) return; + if (list->ifa_data == list) { + free((struct entry *) list - 1); + return; + } + ((freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs"))(list); +} + +/* Names live in the same allocation as the array, right behind it; glibc strdup()s each one. */ +struct name_block { + struct if_nameindex index[3]; + char names[2][IFNAMSIZ]; +}; + +struct if_nameindex *if_nameindex(void) { + typedef struct if_nameindex *(*if_nameindex_fn)(void); + struct if_nameindex *list = ((if_nameindex_fn) dlsym(RTLD_NEXT, "if_nameindex"))(); + int saved = errno; + if (list && list[0].if_index != 0) return list; + + struct link link; + struct name_block *block; + if (!load_link(&link) || (block = calloc(1, sizeof(*block))) == NULL) { + errno = saved; + return list; + } + if (list) if_freenameindex(list); + snprintf(block->names[0], IFNAMSIZ, "%s", LO_NAME); + snprintf(block->names[1], IFNAMSIZ, "%s", link.name); + block->index[0] = (struct if_nameindex) { LO_INDEX, block->names[0] }; + block->index[1] = (struct if_nameindex) { link.index, block->names[1] }; + return block->index; +} + +void if_freenameindex(struct if_nameindex *list) { + typedef void (*if_freenameindex_fn)(struct if_nameindex *); + if (list == NULL) return; + if (list[0].if_name == ((struct name_block *) list)->names[0]) { + free(list); + return; + } + ((if_freenameindex_fn) dlsym(RTLD_NEXT, "if_freenameindex"))(list); +} + +unsigned int if_nametoindex(const char *name) { + typedef unsigned int (*if_nametoindex_fn)(const char *); + unsigned int index = ((if_nametoindex_fn) dlsym(RTLD_NEXT, "if_nametoindex"))(name); + if (index != 0 || name == NULL) return index; + int saved = errno; + struct link link; + if (strcmp(name, LO_NAME) == 0) return LO_INDEX; + if (load_link(&link) && strcmp(name, link.name) == 0) return link.index; + errno = saved; + return 0; +} + +char *if_indextoname(unsigned int index, char name[IF_NAMESIZE]) { + typedef char *(*if_indextoname_fn)(unsigned int, char *); + char *found = ((if_indextoname_fn) dlsym(RTLD_NEXT, "if_indextoname"))(index, name); + if (found || name == NULL) return found; + int saved = errno; + struct link link; + if (index == LO_INDEX) return strcpy(name, LO_NAME); + if (load_link(&link) && index == link.index) return strcpy(name, link.name); + errno = saved; + return NULL; +} + +static int mac_unusable(const struct ifreq *ifr) { + const unsigned char *a = (const unsigned char *) ifr->ifr_hwaddr.sa_data; + if (ifr->ifr_hwaddr.sa_family != ARPHRD_ETHER) return 1; + /* Android hands out 02:00:00:00:00:00 where it hides the real address. */ + int rest = a[1] | a[2] | a[3] | a[4] | a[5]; + return (a[0] & 0x03) || (rest == 0 && (a[0] == 0 || a[0] == 0x02)); +} + +static const struct link_addr *first_v4(const struct link *link) { + for (int i = 0; i < link->addr_count; i++) { + if (link->addrs[i].family == AF_INET) return &link->addrs[i]; + } + return NULL; +} + +static int answer_ifreq(unsigned long request, struct ifreq *ifr, int real_rc) { + char name[IFNAMSIZ + 1] = { 0 }; + memcpy(name, ifr->ifr_name, IFNAMSIZ); + int loopback = strcmp(name, LO_NAME) == 0; + struct link link; + if (!load_link(&link) || (!loopback && strcmp(name, link.name) != 0)) return 0; + + if (request == SIOCGIFHWADDR) { + if (real_rc == 0 && (loopback || !mac_unusable(ifr))) return 0; + memset(&ifr->ifr_hwaddr, 0, sizeof(ifr->ifr_hwaddr)); + ifr->ifr_hwaddr.sa_family = loopback ? ARPHRD_LOOPBACK : ARPHRD_ETHER; + if (!loopback) memcpy(ifr->ifr_hwaddr.sa_data, link.mac, 6); + return 1; + } + if (real_rc == 0) return 0; + + const struct link_addr *v4 = loopback ? &LO_V4 : first_v4(&link); + struct sockaddr_in *sin = (struct sockaddr_in *) &ifr->ifr_addr; + unsigned char mask[16]; + switch (request) { + case SIOCGIFFLAGS: + ifr->ifr_flags = loopback ? IFF_UP | IFF_RUNNING | IFF_LOOPBACK + : IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST; + return 1; + case SIOCGIFMTU: + ifr->ifr_mtu = loopback ? LO_MTU : link.mtu; + return 1; + case SIOCGIFINDEX: + ifr->ifr_ifindex = loopback ? LO_INDEX : (int) link.index; + return 1; + case SIOCGIFADDR: + case SIOCGIFNETMASK: + case SIOCGIFBRDADDR: + if (v4 == NULL) return 0; + prefix_mask(AF_INET, v4->prefix, mask); + memset(sin, 0, sizeof(*sin)); + sin->sin_family = AF_INET; + for (int i = 0; i < 4; i++) { + unsigned char *out = (unsigned char *) &sin->sin_addr + i; + *out = request == SIOCGIFNETMASK ? mask[i] + : request == SIOCGIFADDR ? v4->bytes[i] + : (unsigned char) (v4->bytes[i] | ~mask[i]); + } + return 1; + default: + return 0; + } +} + +static int is_link_query(unsigned long request) { + return request == SIOCGIFHWADDR || request == SIOCGIFFLAGS || request == SIOCGIFMTU + || request == SIOCGIFINDEX || request == SIOCGIFADDR || request == SIOCGIFNETMASK + || request == SIOCGIFBRDADDR; +} + +/* Every DRM and evdev call comes through here, so the lookup is done once. Two threads racing + * to store it store the same pointer. */ +int ioctl(int fd, unsigned long request, ...) { + typedef int (*ioctl_fn)(int, unsigned long, void *); + static ioctl_fn real; + va_list ap; + va_start(ap, request); + void *arg = va_arg(ap, void *); + va_end(ap); + + if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl"); + int rc = real(fd, request, arg); + if (arg == NULL || !is_link_query(request)) return rc; + int saved = errno; + if (answer_ifreq(request, (struct ifreq *) arg, rc)) return 0; + errno = saved; + return rc; +} + +static void print_v6(FILE *out, const unsigned char *bytes) { + for (int i = 0; i < 16; i++) fprintf(out, "%02x", bytes[i]); +} + +static unsigned v6_scope(const struct link_addr *addr) { + if (memcmp(addr, &LO_V6, sizeof(*addr)) == 0) return 0x10; + return is_link_local(addr) ? 0x20 : 0x00; +} + +static void write_table(FILE *out, const char *table, const struct link *link) { + static const unsigned char zero[16]; + unsigned char mask[16]; + if (strcmp(table, "route") == 0) { + fprintf(out, "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT\n"); + for (int i = 0; i < link->gateway_count; i++) { + if (link->gateways[i].family != AF_INET) continue; + unsigned gw; + memcpy(&gw, link->gateways[i].bytes, 4); + fprintf(out, "%s\t00000000\t%08X\t0003\t0\t0\t0\t00000000\t0\t0\t0\n", link->name, gw); + } + for (int i = 0; i < link->addr_count; i++) { + if (link->addrs[i].family != AF_INET) continue; + unsigned addr, net; + prefix_mask(AF_INET, link->addrs[i].prefix, mask); + memcpy(&addr, link->addrs[i].bytes, 4); + memcpy(&net, mask, 4); + fprintf(out, "%s\t%08X\t00000000\t0001\t0\t0\t0\t%08X\t0\t0\t0\n", + link->name, addr & net, net); + } + } else if (strcmp(table, "ipv6_route") == 0) { + for (int i = 0; i < link->gateway_count; i++) { + if (link->gateways[i].family != AF_INET6) continue; + print_v6(out, zero); + fprintf(out, " 00 "); + print_v6(out, zero); + fprintf(out, " 00 "); + print_v6(out, link->gateways[i].bytes); + fprintf(out, " 00000400 00000001 00000000 00000003 %8s\n", link->name); + } + for (int i = 0; i < link->addr_count; i++) { + if (link->addrs[i].family != AF_INET6) continue; + unsigned char net[16]; + prefix_mask(AF_INET6, link->addrs[i].prefix, mask); + for (int b = 0; b < 16; b++) net[b] = link->addrs[i].bytes[b] & mask[b]; + print_v6(out, net); + fprintf(out, " %02x ", link->addrs[i].prefix); + print_v6(out, zero); + fprintf(out, " 00 "); + print_v6(out, zero); + fprintf(out, " 00000100 00000001 00000000 00000001 %8s\n", link->name); + } + } else if (strcmp(table, "if_inet6") == 0) { + print_v6(out, LO_V6.bytes); + fprintf(out, " %02x %02x %02x 80 %8s\n", LO_INDEX, LO_V6.prefix, v6_scope(&LO_V6), LO_NAME); + for (int i = 0; i < link->addr_count; i++) { + if (link->addrs[i].family != AF_INET6) continue; + print_v6(out, link->addrs[i].bytes); + fprintf(out, " %02x %02x %02x 80 %8s\n", link->index, link->addrs[i].prefix, + v6_scope(&link->addrs[i]), link->name); + } + } else if (strcmp(table, "dev") == 0) { + fprintf(out, "Inter-| Receive | Transmit\n" + " face |bytes packets errs drop fifo frame compressed multicast|" + "bytes packets errs drop fifo colls carrier compressed\n"); + fprintf(out, "%6s: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", LO_NAME); + fprintf(out, "%6s: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", link->name); + } else if (strcmp(table, "arp") == 0) { + fprintf(out, "IP address HW type Flags HW address Mask Device\n"); + } else { + fprintf(out, "1\n"); + } +} + +static const char *denied_table(const char *path) { + static const char *const tables[] = { "route", "ipv6_route", "if_inet6", "dev", "arp" }; + if (strncmp(path, "/proc/net/", 10) == 0) { + for (size_t i = 0; i < sizeof(tables) / sizeof(tables[0]); i++) { + if (strcmp(path + 10, tables[i]) == 0) return tables[i]; + } + return NULL; + } + size_t len = strlen(path); + if (strncmp(path, "/sys/class/net/", 15) == 0 && len > 8 && strcmp(path + len - 8, "/carrier") == 0) { + return "carrier"; + } + return NULL; +} + +/* A memfd rather than fmemopen(): the stream owns its contents, so fclose() frees everything. */ +static FILE *synthesize(const char *table) { + struct link link; + if (!load_link(&link)) return NULL; + int fd = memfd_create("bannerlator-net", MFD_CLOEXEC); + if (fd < 0) return NULL; + FILE *out = fdopen(fd, "w+"); + if (out == NULL) { + close(fd); + return NULL; + } + write_table(out, table, &link); + if (fflush(out) != 0) { + fclose(out); + return NULL; + } + rewind(out); + return out; +} + +/* tracer.c */ +int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden"))); + +static FILE *open_stream(const char *symbol, const char *path, const char *mode) { + typedef FILE *(*fopen_fn)(const char *, const char *); + int status = mode && mode[0] == 'r' && !strchr(mode, '+') + ? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC) : -1; + if (status >= 0) { + FILE *copy = fdopen(status, "r"); + if (copy == NULL) close(status); + return copy; + } + FILE *f = ((fopen_fn) dlsym(RTLD_NEXT, symbol))(path, mode); + if (f || path == NULL || mode == NULL || mode[0] != 'r') return f; + int saved = errno; + const char *table = denied_table(path); + if (table && (f = synthesize(table)) != NULL) return f; + errno = saved; + return NULL; +} + +FILE *fopen(const char *path, const char *mode) { + return open_stream("fopen", path, mode); +} + +FILE *fopen64(const char *path, const char *mode) { + return open_stream("fopen64", path, mode); +} diff --git a/tools/linuxfs/preload/opens.c b/tools/linuxfs/preload/opens.c new file mode 100644 index 0000000000..52d52ec4c3 --- /dev/null +++ b/tools/linuxfs/preload/opens.c @@ -0,0 +1,99 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names + * changed to this project's. The reasoning below is the original author's. + * + * The adjustments a session's opens need. + * + * O_NOATIME on the game library: the user's games are bound in from shared storage, which Android + * serves over FUSE with every file owned by its media provider rather than by the app. O_NOATIME + * is reserved for a file's owner, so the kernel refuses such an open outright with EPERM. The + * Steam client opens every content file it reads that way, and treats the refusal as the file + * being unreadable or missing: a validation reports corrupt or missing files and an update is + * cancelled. The flag only asks the filesystem to skip an access-time update; the open is retried + * without it. Every other refusal is passed through untouched, and a file the process may open + * with the flag still is. + * + * The kernel's trace marker: tracefs is world-writable here, so the client's tier0 opens + * /sys/kernel/tracing/trace_marker at startup - three times over, once per module that profiles - + * and writes a "[%s] tgid=%d begin_ctx=%lld" line for every scope it enters. Nothing in the + * session reads those markers, and they are one more thing that can land in the wrong file when + * a descriptor number changes hands (tracer.c has the cause). They have been found appended to an + * app manifest, which the client then cannot parse, to a download's state file, and to content + * chunks, which it quarantines as corrupt. Refused the descriptor, tier0 writes nothing at all and + * has nothing to lose. + * + * A process status is served without the container's tracer in it; see tracer.c. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <stdarg.h> +#include <stddef.h> +#include <string.h> +#include <sys/types.h> + +int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden"))); + +static int retry_without_noatime(int fd, int flags) { + return fd < 0 && errno == EPERM && (flags & O_NOATIME); +} + +/* Both spellings tier0 tries, the debugfs one first. */ +static int is_trace_marker(const char *path) { + return path != NULL + && (strcmp(path, "/sys/kernel/tracing/trace_marker") == 0 + || strcmp(path, "/sys/kernel/debug/tracing/trace_marker") == 0); +} + +int open(const char *path, int flags, ...) { + static int (*real_open)(const char *, int, ...); + va_list ap; + mode_t mode; + int fd; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + if (is_trace_marker(path)) { + errno = EACCES; + return -1; + } + if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd; + if (real_open == NULL) real_open = dlsym(RTLD_NEXT, "open"); + if (real_open == NULL) { + errno = ENOSYS; + return -1; + } + fd = real_open(path, flags, mode); + if (retry_without_noatime(fd, flags)) fd = real_open(path, flags & ~O_NOATIME, mode); + return fd; +} + +int openat(int dirfd, const char *path, int flags, ...) { + static int (*real_openat)(int, const char *, int, ...); + va_list ap; + mode_t mode; + int fd; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + if (is_trace_marker(path)) { + errno = EACCES; + return -1; + } + if ((fd = bl_status_without_tracer(path, flags)) >= 0) return fd; + if (real_openat == NULL) real_openat = dlsym(RTLD_NEXT, "openat"); + if (real_openat == NULL) { + errno = ENOSYS; + return -1; + } + fd = real_openat(dirfd, path, flags, mode); + if (retry_without_noatime(fd, flags)) fd = real_openat(dirfd, path, flags & ~O_NOATIME, mode); + return fd; +} + +/* The runtime is 64-bit, so the large-file names are the same calls. */ +int open64(const char *path, int flags, ...) __attribute__((alias("open"))); +int openat64(int dirfd, const char *path, int flags, ...) __attribute__((alias("openat"))); diff --git a/tools/linuxfs/preload/robust.c b/tools/linuxfs/preload/robust.c new file mode 100644 index 0000000000..0f0b581ca9 --- /dev/null +++ b/tools/linuxfs/preload/robust.c @@ -0,0 +1,79 @@ +/* + * get_robust_list(2) for the session's own threads. + * + * Android's app policy refuses the call, and Steam's cross-process mutex insists on seeing the + * head glibc registered. The kernel's list protocol gives it away: a robust mutex this thread + * holds is linked directly behind the registered head, so locking a private one and following + * the link back finds the head without depending on libc's layout. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <linux/futex.h> +#include <pthread.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdint.h> +#include <sys/syscall.h> +#include <sys/uio.h> +#include <unistd.h> + +static long (*real_syscall)(long, ...); + +static struct robust_list_head *thread_robust_head(void) { + pthread_mutexattr_t attr; + pthread_mutex_t mutex; + struct robust_list_head *head = NULL; + pthread_mutexattr_init(&attr); + pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST); + pthread_mutex_init(&mutex, &attr); + pthread_mutexattr_destroy(&attr); + if (pthread_mutex_lock(&mutex) != 0) { + return NULL; + } + /* The mutex holds tids and lock words beside the link, so a word is only followed + * through a read that fails instead of faulting on a non-pointer. */ + uintptr_t lo = (uintptr_t)&mutex, hi = lo + sizeof(mutex); + for (uintptr_t p = lo; p + sizeof(void *) <= hi && !head; p += sizeof(void *)) { + struct robust_list_head *candidate = *(struct robust_list_head **)p; + struct robust_list_head copy; + struct iovec local = {©, sizeof(copy)}, remote = {candidate, sizeof(copy)}; + if ((uintptr_t)candidate & (sizeof(void *) - 1)) { + continue; + } + if (process_vm_readv(getpid(), &local, 1, &remote, 1, 0) != (ssize_t)sizeof(copy)) { + continue; + } + uintptr_t entry = (uintptr_t)copy.list.next; + if (entry >= lo && entry < hi && copy.futex_offset < 0 && copy.futex_offset > -256) { + head = candidate; + } + } + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); + return head; +} + +long syscall(long number, ...) { + va_list ap; + long args[6]; + va_start(ap, number); + for (int i = 0; i < 6; i++) { + args[i] = va_arg(ap, long); + } + va_end(ap); + if (number == SYS_get_robust_list && (args[0] == 0 || args[0] == gettid())) { + struct robust_list_head *head = thread_robust_head(); + if (!head) { + errno = ENOSYS; + return -1; + } + *(struct robust_list_head **)args[1] = head; + *(size_t *)args[2] = sizeof(*head); + return 0; + } + if (!real_syscall) { + real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall"); + } + return real_syscall(number, args[0], args[1], args[2], args[3], args[4], args[5]); +} diff --git a/tools/linuxfs/preload/sysv.c b/tools/linuxfs/preload/sysv.c new file mode 100644 index 0000000000..6b9a21dc8a --- /dev/null +++ b/tools/linuxfs/preload/sysv.c @@ -0,0 +1,411 @@ +/* System V semaphores and shared memory for programs in the Linux runtime. + * + * Android kernels are built without System V IPC, so semget/shmget fail with ENOSYS. Steam's tier0 + * creates its client-instance semaphore with semget and gives up when that fails. This library is + * LD_PRELOADed into the session and keeps each object in a file under /dev/shm (a bound directory + * the whole session shares): a semaphore set is an array of counters waited on with futexes, a + * segment is a plain file that shmat maps. Objects are found by the inode of their file, which is + * what the id is. semop applies its operations one by one (no all-or-nothing across a set) and + * SEM_UNDO is accepted but not performed - enough for the client, which uses single-counter sets. + * Message queues stay unsupported. */ +#define _GNU_SOURCE +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <linux/futex.h> +#include <pthread.h> +#include <stdarg.h> +#include <stdatomic.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/ipc.h> +#include <sys/mman.h> +#include <sys/sem.h> +#include <sys/shm.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <time.h> +#include <unistd.h> + +#define DIR_DEFAULT "/dev/shm/wnsysv" +#define SEM_MAGIC 0x574e5345u /* "WNSE" */ +#define MAX_OBJECTS 64 + +struct sem_header { + uint32_t magic; + uint32_t nsems; + uint32_t key; + uint32_t mode; + int32_t creator_pid; + int32_t pad[11]; +}; +/* The counters follow the header, one 32-bit word each (a futex word). */ + +struct sem_map { int id; struct sem_header *hdr; size_t len; }; +struct shm_map { void *addr; size_t len; int id; }; + +static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; +static struct sem_map g_sems[MAX_OBJECTS]; +static struct shm_map g_shms[MAX_OBJECTS]; +static char g_dir[PATH_MAX - NAME_MAX - 2]; + +static const char *object_dir(void) { + if (!g_dir[0]) { + const char *d = getenv("BL_SYSV_DIR"); + snprintf(g_dir, sizeof(g_dir), "%s", d && *d ? d : DIR_DEFAULT); + mkdir(g_dir, 0700); + } + return g_dir; +} + +static int object_id(int fd) { + struct stat st; + if (fstat(fd, &st) != 0) return -1; + return (int)(st.st_ino & 0x7fffffff); +} + +/* Open the object file of kind ("sem"/"shm") for key, creating it as flags ask. */ +static int open_object(const char *kind, key_t key, int flags, int *created) { + char path[PATH_MAX]; + int oflags = O_RDWR | O_CLOEXEC; + *created = 0; + if (key == IPC_PRIVATE) { + static atomic_uint serial; + snprintf(path, sizeof(path), "%s/%s.p%d.%u", object_dir(), kind, (int)getpid(), + atomic_fetch_add(&serial, 1)); + oflags |= O_CREAT | O_EXCL; + } else { + snprintf(path, sizeof(path), "%s/%s.k%08x", object_dir(), kind, (unsigned)key); + if (flags & IPC_CREAT) oflags |= O_CREAT; + if ((flags & (IPC_CREAT | IPC_EXCL)) == (IPC_CREAT | IPC_EXCL)) oflags |= O_EXCL; + } + int fd = open(path, oflags, (flags & 0777) ? (flags & 0777) : 0600); + if (fd < 0) return -1; + struct stat st; + if (fstat(fd, &st) == 0 && st.st_size == 0) *created = 1; + return fd; +} + +/* The object file for an id, found by inode. */ +static int open_by_id(const char *kind, int id) { + DIR *d = opendir(object_dir()); + if (!d) return -1; + struct dirent *e; + int fd = -1; + size_t klen = strlen(kind); + while ((e = readdir(d))) { + if (strncmp(e->d_name, kind, klen) || e->d_name[klen] != '.') continue; + if ((int)(e->d_ino & 0x7fffffff) != id) continue; + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s", g_dir, e->d_name); + fd = open(path, O_RDWR | O_CLOEXEC); + break; + } + closedir(d); + if (fd < 0) errno = EINVAL; + return fd; +} + +static int unlink_by_id(const char *kind, int id) { + DIR *d = opendir(object_dir()); + if (!d) return -1; + struct dirent *e; + int rc = -1; + size_t klen = strlen(kind); + while ((e = readdir(d))) { + if (strncmp(e->d_name, kind, klen) || e->d_name[klen] != '.') continue; + if ((int)(e->d_ino & 0x7fffffff) != id) continue; + char path[PATH_MAX]; + snprintf(path, sizeof(path), "%s/%s", g_dir, e->d_name); + rc = unlink(path); + break; + } + closedir(d); + if (rc < 0) errno = EINVAL; + return rc; +} + +static long futex(void *addr, int op, int val, const struct timespec *timeout) { + return syscall(SYS_futex, addr, op, val, timeout, NULL, 0); +} + +/* ------------------------------------------------------------------ semaphores */ + +static struct sem_map *sem_lookup(int id) { + for (int i = 0; i < MAX_OBJECTS; i++) + if (g_sems[i].hdr && g_sems[i].id == id) return &g_sems[i]; + int fd = open_by_id("sem", id); + if (fd < 0) return NULL; + struct stat st; + if (fstat(fd, &st) != 0 || st.st_size < (off_t)sizeof(struct sem_header)) { close(fd); errno = EINVAL; return NULL; } + void *m = mmap(NULL, (size_t)st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + close(fd); + if (m == MAP_FAILED) return NULL; + struct sem_header *h = m; + if (h->magic != SEM_MAGIC) { munmap(m, (size_t)st.st_size); errno = EINVAL; return NULL; } + for (int i = 0; i < MAX_OBJECTS; i++) { + if (g_sems[i].hdr) continue; + g_sems[i].id = id; g_sems[i].hdr = h; g_sems[i].len = (size_t)st.st_size; + return &g_sems[i]; + } + munmap(m, (size_t)st.st_size); + errno = ENOSPC; + return NULL; +} + +static void sem_forget(int id) { + for (int i = 0; i < MAX_OBJECTS; i++) + if (g_sems[i].hdr && g_sems[i].id == id) { munmap(g_sems[i].hdr, g_sems[i].len); g_sems[i].hdr = NULL; } +} + +static _Atomic int32_t *sem_words(struct sem_header *h) { return (_Atomic int32_t *)(h + 1); } + +int semget(key_t key, int nsems, int semflg) { + if (nsems < 0 || nsems > 250) { errno = EINVAL; return -1; } + int created; + int fd = open_object("sem", key, semflg, &created); + if (fd < 0) return -1; + if (created) { + if (nsems == 0) { close(fd); errno = EINVAL; return -1; } + size_t len = sizeof(struct sem_header) + (size_t)nsems * sizeof(int32_t); + if (ftruncate(fd, (off_t)len) != 0) { close(fd); return -1; } + struct sem_header h = {.magic = SEM_MAGIC, .nsems = (uint32_t)nsems, .key = (uint32_t)key, + .mode = (uint32_t)(semflg & 0777), .creator_pid = (int32_t)getpid()}; + if (pwrite(fd, &h, sizeof(h), 0) != (ssize_t)sizeof(h)) { close(fd); return -1; } + } else { + struct sem_header h; + if (pread(fd, &h, sizeof(h), 0) != (ssize_t)sizeof(h) || h.magic != SEM_MAGIC) { close(fd); errno = EINVAL; return -1; } + if (nsems > 0 && (uint32_t)nsems > h.nsems) { close(fd); errno = EINVAL; return -1; } + } + int id = object_id(fd); + close(fd); + return id; +} + +static int sem_wait_op(_Atomic int32_t *word, short op, short flg, const struct timespec *timeout) { + for (;;) { + int32_t v = atomic_load(word); + if (op == 0) { + if (v == 0) return 0; + } else if (v >= -op) { + if (atomic_compare_exchange_weak(word, &v, v + op)) return 0; + continue; + } + if (flg & IPC_NOWAIT) { errno = EAGAIN; return -1; } + long r = futex(word, FUTEX_WAIT, v, timeout); + if (r != 0 && errno == ETIMEDOUT) return -1; + if (r != 0 && errno == EINTR) { errno = EINTR; return -1; } + } +} + +int semtimedop(int semid, struct sembuf *sops, size_t nsops, const struct timespec *timeout) { + pthread_mutex_lock(&g_lock); + struct sem_map *m = sem_lookup(semid); + pthread_mutex_unlock(&g_lock); + if (!m) return -1; + struct sem_header *h = m->hdr; + _Atomic int32_t *words = sem_words(h); + for (size_t i = 0; i < nsops; i++) { + if (sops[i].sem_num >= h->nsems) { errno = EFBIG; return -1; } + _Atomic int32_t *w = &words[sops[i].sem_num]; + if (sops[i].sem_op > 0) { + atomic_fetch_add(w, sops[i].sem_op); + futex(w, FUTEX_WAKE, INT_MAX, NULL); + } else if (sem_wait_op(w, sops[i].sem_op, sops[i].sem_flg, timeout) != 0) { + return -1; + } + if (sops[i].sem_op < 0) futex(w, FUTEX_WAKE, INT_MAX, NULL); /* zero-waiters see the change */ + } + return 0; +} + +int semop(int semid, struct sembuf *sops, size_t nsops) { return semtimedop(semid, sops, nsops, NULL); } + +int semctl(int semid, int semnum, int cmd, ...) { + union { int val; struct semid_ds *buf; unsigned short *array; } arg = {0}; + if (cmd == SETVAL || cmd == IPC_STAT || cmd == IPC_SET || cmd == GETALL || cmd == SETALL) { + va_list ap; + va_start(ap, cmd); + arg.buf = va_arg(ap, struct semid_ds *); + va_end(ap); + } + if (cmd == IPC_RMID) { + pthread_mutex_lock(&g_lock); + sem_forget(semid); + int rc = unlink_by_id("sem", semid); + pthread_mutex_unlock(&g_lock); + return rc; + } + pthread_mutex_lock(&g_lock); + struct sem_map *m = sem_lookup(semid); + pthread_mutex_unlock(&g_lock); + if (!m) return -1; + struct sem_header *h = m->hdr; + _Atomic int32_t *words = sem_words(h); + switch (cmd) { + case GETVAL: + if (semnum < 0 || (uint32_t)semnum >= h->nsems) { errno = EINVAL; return -1; } + return atomic_load(&words[semnum]); + case SETVAL: + if (semnum < 0 || (uint32_t)semnum >= h->nsems) { errno = EINVAL; return -1; } + atomic_store(&words[semnum], (int32_t)(intptr_t)arg.buf); + futex(&words[semnum], FUTEX_WAKE, INT_MAX, NULL); + return 0; + case GETALL: + for (uint32_t i = 0; i < h->nsems; i++) arg.array[i] = (unsigned short)atomic_load(&words[i]); + return 0; + case SETALL: + for (uint32_t i = 0; i < h->nsems; i++) { + atomic_store(&words[i], arg.array[i]); + futex(&words[i], FUTEX_WAKE, INT_MAX, NULL); + } + return 0; + case GETPID: return h->creator_pid; + case GETNCNT: case GETZCNT: return 0; + case IPC_STAT: + memset(arg.buf, 0, sizeof(*arg.buf)); + arg.buf->sem_perm.__key = (key_t)h->key; + arg.buf->sem_perm.uid = arg.buf->sem_perm.cuid = getuid(); + arg.buf->sem_perm.gid = arg.buf->sem_perm.cgid = getgid(); + arg.buf->sem_perm.mode = (unsigned short)h->mode; + arg.buf->sem_nsems = h->nsems; + return 0; + case IPC_SET: return 0; + default: errno = EINVAL; return -1; + } +} + +/* ------------------------------------------------------------------ shared memory */ + +/* Linux keeps a removed segment attachable until the last detach, which X clients rely on: they + * remove the segment right after asking the server to attach it. A removed segment is renamed out + * of key lookup instead, and removed for good once it has been out of use for a while. */ +static int remove_shm(int id) { + DIR *d = opendir(object_dir()); + if (!d) return -1; + struct dirent *e; + int rc = -1; + while ((e = readdir(d))) { + if (strncmp(e->d_name, "shm.", 4) || !strncmp(e->d_name, "shm.d.", 6)) continue; + if ((int)(e->d_ino & 0x7fffffff) != id) continue; + char from[PATH_MAX], to[PATH_MAX]; + snprintf(from, sizeof(from), "%s/%s", g_dir, e->d_name); + snprintf(to, sizeof(to), "%s/shm.d.%s", g_dir, e->d_name + 4); + rc = rename(from, to); + break; + } + closedir(d); + if (rc < 0) errno = EINVAL; + return rc; +} + +static void expire_removed_shm(void) { + DIR *d = opendir(object_dir()); + if (!d) return; + struct dirent *e; + time_t now = time(NULL); + while ((e = readdir(d))) { + if (strncmp(e->d_name, "shm.d.", 6)) continue; + char path[PATH_MAX]; + struct stat st; + snprintf(path, sizeof(path), "%s/%s", g_dir, e->d_name); + if (stat(path, &st) == 0 && now - st.st_mtime > 30) unlink(path); + } + closedir(d); +} + +int shmget(key_t key, size_t size, int shmflg) { + int created; + expire_removed_shm(); + int fd = open_object("shm", key, shmflg, &created); + if (fd < 0) return -1; + if (created) { + if (size == 0) { close(fd); errno = EINVAL; return -1; } + if (ftruncate(fd, (off_t)size) != 0) { close(fd); return -1; } + } else { + struct stat st; + if (fstat(fd, &st) != 0 || (size_t)st.st_size < size) { close(fd); errno = EINVAL; return -1; } + } + int id = object_id(fd); + close(fd); + return id; +} + +void *shmat(int shmid, const void *shmaddr, int shmflg) { + int fd = open_by_id("shm", shmid); + if (fd < 0) return (void *)-1; + struct stat st; + if (fstat(fd, &st) != 0) { close(fd); return (void *)-1; } + int prot = PROT_READ | ((shmflg & SHM_RDONLY) ? 0 : PROT_WRITE); + void *m = mmap((void *)shmaddr, (size_t)st.st_size, prot, MAP_SHARED, fd, 0); + close(fd); + if (m == MAP_FAILED) return (void *)-1; + pthread_mutex_lock(&g_lock); + for (int i = 0; i < MAX_OBJECTS; i++) { + if (g_shms[i].addr) continue; + g_shms[i].addr = m; g_shms[i].len = (size_t)st.st_size; g_shms[i].id = shmid; + break; + } + pthread_mutex_unlock(&g_lock); + return m; +} + +int shmdt(const void *shmaddr) { + pthread_mutex_lock(&g_lock); + for (int i = 0; i < MAX_OBJECTS; i++) { + if (g_shms[i].addr != shmaddr) continue; + munmap(g_shms[i].addr, g_shms[i].len); + g_shms[i].addr = NULL; + pthread_mutex_unlock(&g_lock); + return 0; + } + pthread_mutex_unlock(&g_lock); + errno = EINVAL; + return -1; +} + +int shmctl(int shmid, int cmd, struct shmid_ds *buf) { + switch (cmd) { + case IPC_RMID: { + pthread_mutex_lock(&g_lock); + int rc = remove_shm(shmid); + pthread_mutex_unlock(&g_lock); + return rc; + } + case IPC_STAT: { + int fd = open_by_id("shm", shmid); + if (fd < 0) return -1; + struct stat st; + int rc = fstat(fd, &st); + close(fd); + if (rc != 0) return -1; + memset(buf, 0, sizeof(*buf)); + buf->shm_perm.uid = buf->shm_perm.cuid = getuid(); + buf->shm_perm.gid = buf->shm_perm.cgid = getgid(); + buf->shm_perm.mode = 0600; + buf->shm_segsz = (size_t)st.st_size; + buf->shm_nattch = 1; + buf->shm_cpid = (pid_t)getpid(); + return 0; + } + case IPC_SET: case SHM_LOCK: case SHM_UNLOCK: return 0; + default: errno = EINVAL; return -1; + } +} + +/* + * fork() carries over only the calling thread, so a lock another thread was holding at that + * instant stays held in the child by a thread that is not there to release it. Taking it before + * the fork makes the copy consistent; the parent then unlocks it and the child, whose one thread + * never locked it, gets a fresh one. (WinNative 79aa7f68.) + */ +static void sysv_lock_before_fork(void) { pthread_mutex_lock(&g_lock); } +static void sysv_unlock_after_fork(void) { pthread_mutex_unlock(&g_lock); } +static void sysv_reset_after_fork(void) { pthread_mutex_init(&g_lock, NULL); } + +__attribute__((constructor)) static void install_sysv_fork_handlers(void) { + pthread_atfork(sysv_lock_before_fork, sysv_unlock_after_fork, sysv_reset_after_fork); +} diff --git a/tools/linuxfs/preload/tracer.c b/tools/linuxfs/preload/tracer.c new file mode 100644 index 0000000000..afcd37ee19 --- /dev/null +++ b/tools/linuxfs/preload/tracer.c @@ -0,0 +1,103 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with names + * changed to this project's. The reasoning below is the original author's. + * + * A process status without the container's tracer in it. + * + * proot runs the session under ptrace, so every process here reads a TracerPid in its + * /proc/<pid>/status. The Steam client takes that to mean a debugger is attached, and its arm64 + * build breaks into the supposed debugger with a bare "svc #0" after every failed assertion. That + * is no breakpoint: the registers still hold the call Plat_IsInDebugSession() just made, close(), + * with its own result, 1, as the argument - so each assertion closes descriptor 1. The number then + * goes to whatever the client opens next, and its standard output is written into that: app + * manifests and content chunks, its own connections, and the socket a game's Steam API talks + * over, which is how a game that stayed silent while loading found its pipe dead. + * + * The tracer is part of the container, not something a program should react to, so the status + * files are served with TracerPid 0. + */ +#define _GNU_SOURCE +#include <ctype.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/syscall.h> +#include <unistd.h> + +#define STATUS_MAX 16384 +#define TRACER_FIELD "\nTracerPid:\t" + +static const char *skip_digits(const char *s) { + const char *end = s; + while (isdigit((unsigned char)*end)) end++; + return end == s ? NULL : end; +} + +/* /proc/{self,thread-self,<pid>}[/task/<tid>]/status */ +static int is_status_path(const char *path) { + const char *rest; + if (path == NULL || strncmp(path, "/proc/", 6) != 0) return 0; + path += 6; + if (strncmp(path, "self/", 5) == 0) rest = path + 4; + else if (strncmp(path, "thread-self/", 12) == 0) rest = path + 11; + else if ((rest = skip_digits(path)) == NULL) return 0; + if (strncmp(rest, "/task/", 6) == 0 && (rest = skip_digits(rest + 6)) == NULL) return 0; + return strcmp(rest, "/status") == 0; +} + +/* Chromium stands its hang watchdogs down when it sees a tracer, and the client's web helper does + * not come up within their patience here: it is left reading the truth. */ +static int is_web_helper(void) { + return strcmp(program_invocation_short_name, "steamwebhelper") == 0; +} + +static int write_all(int fd, const char *data, size_t len) { + while (len > 0) { + ssize_t n = write(fd, data, len); + if (n < 0 && errno == EINTR) continue; + if (n <= 0) return -1; + data += n; + len -= (size_t)n; + } + return 0; +} + +/* The descriptor to hand back for a read-only open of a status file, or -1 with errno untouched + * when the path is something else or the copy cannot be made, and the real open should run. */ +__attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *path, int flags) { + char text[STATUS_MAX]; + size_t len = 0; + int saved = errno; + int out = -1; + + if ((flags & O_ACCMODE) != O_RDONLY || !is_status_path(path) || is_web_helper()) return -1; + int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC); + if (in < 0) goto done; + for (;;) { + ssize_t n = read(in, text + len, sizeof(text) - 1 - len); + if (n < 0 && errno == EINTR) continue; + if (n <= 0) break; + len += (size_t)n; + } + close(in); + text[len] = '\0'; + + char *field = strstr(text, TRACER_FIELD); + if (field == NULL) goto done; + char *value = field + strlen(TRACER_FIELD); + char *line_end = strchr(value, '\n'); + if (line_end == NULL) goto done; + + out = memfd_create("status", (flags & O_CLOEXEC) ? MFD_CLOEXEC : 0); + if (out < 0) goto done; + if (write_all(out, text, (size_t)(value - text)) != 0 || write_all(out, "0", 1) != 0 + || write_all(out, line_end, len - (size_t)(line_end - text)) != 0 + || lseek(out, 0, SEEK_SET) != 0) { + close(out); + out = -1; + } +done: + errno = saved; + return out; +} diff --git a/tools/linuxfs/preload/udevmon.c b/tools/linuxfs/preload/udevmon.c new file mode 100644 index 0000000000..39e568b3be --- /dev/null +++ b/tools/linuxfs/preload/udevmon.c @@ -0,0 +1,191 @@ +/* + * Ported from WinNative (maxjivi05, feature/wayland-gamescope, 2026-09-18/19), GPL-3.0, with the + * symbol prefix changed to match this library. The reasoning below is the original author's. + * + * udev's netlink monitor, stood in for where the sandbox refuses the socket it is built on. + * + * The app sandbox denies a NETLINK_KOBJECT_UEVENT socket outright. libudev cannot create a + * monitor without one, and SDL's HID layer cannot start without a monitor: every SDL_hid_init() + * fails, the Steam client's controller code retries it hundreds of times a second, its main loop + * stalls, and the client asserts out from under the running game. Refusing SDL the library + * altogether (the earlier answer here) is what produced that failure. + * + * So the socket is answered instead: one end of a datagram socketpair stands in for the netlink + * socket, its peer held open so it never reads as hung up, and the few calls libudev makes on + * the socket that only a netlink one could answer are answered here. Nothing is ever written to + * it, so the monitor is live and silent, which is the most the kernel would deliver in a + * container anyway. The real socket is tried first, so this stays out of the way wherever a + * monitor could genuinely be created. + * + * Wine is left without one. Its HID bus reads the session's pads itself only when its SDL bus + * cannot start, and that is the path inputudev.c describes them on. Given a monitor the SDL bus + * comes up and takes the pads over from it. + */ +#define _GNU_SOURCE +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <linux/netlink.h> +#include <pthread.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <unistd.h> + +struct stand_in { + int fd; /* the descriptor handed out, -1 when the slot is free */ + int peer; /* the other end, kept open */ + ino_t inode; /* identifies the socket after fd is closed and its number reused */ +}; + +static struct stand_in stand_ins[16]; +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + +static void lock_before_fork(void) { pthread_mutex_lock(&lock); } +static void unlock_after_fork(void) { pthread_mutex_unlock(&lock); } +static void reset_after_fork(void) { pthread_mutex_init(&lock, NULL); } + +__attribute__((constructor)) static void init_udevmon(void) { + for (size_t i = 0; i < sizeof(stand_ins) / sizeof(stand_ins[0]); i++) + stand_ins[i].fd = -1; + pthread_atfork(lock_before_fork, unlock_after_fork, reset_after_fork); +} + +static ino_t socket_inode(int fd) { + struct stat st; + return fstat(fd, &st) == 0 ? st.st_ino : 0; +} + +/* Whether fd is one of the stand-in sockets. A slot whose descriptor was closed and reused by + * something else is retired on sight, so a later socket with the same number is not mistaken. */ +static int is_stand_in(int fd) { + int found = 0; + if (fd < 0) + return 0; + pthread_mutex_lock(&lock); + for (size_t i = 0; i < sizeof(stand_ins) / sizeof(stand_ins[0]); i++) { + if (stand_ins[i].fd != fd) + continue; + if (stand_ins[i].inode == socket_inode(fd)) { + found = 1; + } else { + close(stand_ins[i].peer); + stand_ins[i].fd = -1; + } + break; + } + pthread_mutex_unlock(&lock); + return found; +} + +static int is_wine_process(void) { + static int known; + if (known == 0) { + char exe[PATH_MAX]; + ssize_t n = readlink("/proc/self/exe", exe, sizeof(exe) - 1); + const char *name = exe; + if (n > 0) { + exe[n] = '\0'; + name = strrchr(exe, '/'); + name = name != NULL ? name + 1 : exe; + } + known = n > 0 && strncmp(name, "wine", 4) == 0 ? 1 : -1; + } + return known == 1; +} + +static int make_stand_in(int type) { + int sv[2]; + int saved = errno; + int flags = SOCK_DGRAM | (type & (SOCK_CLOEXEC | SOCK_NONBLOCK)); + if (socketpair(AF_UNIX, flags, 0, sv) != 0) { + errno = saved; + return -1; + } + /* The peer is ours alone: it must not follow the socket into a child. */ + fcntl(sv[1], F_SETFD, FD_CLOEXEC); + pthread_mutex_lock(&lock); + for (size_t i = 0; i < sizeof(stand_ins) / sizeof(stand_ins[0]); i++) { + if (stand_ins[i].fd == -1) { + stand_ins[i].fd = sv[0]; + stand_ins[i].peer = sv[1]; + stand_ins[i].inode = socket_inode(sv[0]); + pthread_mutex_unlock(&lock); + return sv[0]; + } + } + pthread_mutex_unlock(&lock); + close(sv[0]); + close(sv[1]); + errno = saved; + return -1; +} + +int socket(int domain, int type, int protocol) { + static int (*real_socket)(int, int, int); + int fd; + + if (real_socket == NULL) real_socket = dlsym(RTLD_NEXT, "socket"); + if (real_socket == NULL) { + errno = ENOSYS; + return -1; + } + fd = real_socket(domain, type, protocol); + if (fd >= 0 || domain != AF_NETLINK || protocol != NETLINK_KOBJECT_UEVENT) + return fd; + int refused = errno; + if (is_wine_process()) { + errno = refused; + return -1; + } + return make_stand_in(type); +} + +/* For net.c's bind(): whether fd is a stand-in, which accepts any netlink address as bound. */ +__attribute__((visibility("hidden"))) int bl_udevmon_stand_in(int fd) { + return is_stand_in(fd); +} + +int getsockname(int fd, struct sockaddr *addr, socklen_t *len) { + static int (*real_getsockname)(int, struct sockaddr *, socklen_t *); + struct sockaddr_nl nl; + + if (is_stand_in(fd)) { + if (addr == NULL || len == NULL) { + errno = EFAULT; + return -1; + } + memset(&nl, 0, sizeof(nl)); + nl.nl_family = AF_NETLINK; + nl.nl_pid = (unsigned)getpid(); + memcpy(addr, &nl, *len < sizeof(nl) ? *len : sizeof(nl)); + *len = sizeof(nl); + return 0; + } + if (real_getsockname == NULL) real_getsockname = dlsym(RTLD_NEXT, "getsockname"); + if (real_getsockname == NULL) { + errno = ENOSYS; + return -1; + } + return real_getsockname(fd, addr, len); +} + +int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) { + static int (*real_setsockopt)(int, int, int, const void *, socklen_t); + + if (is_stand_in(fd)) { + /* Group membership and packet filters only mean something on a socket that receives; this + * one never does, so they are accepted as set. The rest is genuine on a unix socket. */ + if (level == SOL_NETLINK) + return 0; + if (level == SOL_SOCKET && (optname == SO_ATTACH_FILTER || optname == SO_DETACH_FILTER)) + return 0; + } + if (real_setsockopt == NULL) real_setsockopt = dlsym(RTLD_NEXT, "setsockopt"); + if (real_setsockopt == NULL) { + errno = ENOSYS; + return -1; + } + return real_setsockopt(fd, level, optname, optval, optlen); +}