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

Commit 2bb603a9 authored by Jim Shargo's avatar Jim Shargo
Browse files

Add a method to libgui flags to handle ANativeWindow properly for media

Bug: n/a
Flag: com.android.graphics.libgui.flags.wb_media_migration
Test: builds
Change-Id: I871198d76de58d54bcd18c04c8643fa8965cbe9b
parent bbf0e156
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>
#include <gui/view/Surface.h>
#include <system/window.h>

namespace android {
namespace flagtools {
@@ -78,6 +79,20 @@ sp<SurfaceType> convertParcelableSurfaceTypeToSurface(const ParcelableSurfaceTyp
}
} // namespace flagtools
namespace mediaflagtools {

sp<MediaSurfaceType> nativeWindowToSurfaceType(ANativeWindow* anw) {
    if (anw == nullptr) {
        return nullptr;
    }

    sp<Surface> surface = Surface::from(anw);
#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    return surface;
#else
    return surface->getIGraphicBufferProducer();
#endif
}

sp<MediaSurfaceType> igbpToSurfaceType(const sp<IGraphicBufferProducer>& igbp) {
    if (igbp == nullptr) {
        return nullptr;
+4 −0
Original line number Diff line number Diff line
@@ -189,6 +189,10 @@ Surface::~Surface() {
#endif // !defined(NO_BINDER)
}

sp<Surface> Surface::from(ANativeWindow* anw) {
    return sp<Surface>::fromExisting(static_cast<Surface*>(anw));
}

#ifndef NO_BINDER
sp<ISurfaceComposer> Surface::composerService() const {
    return ComposerService::getComposerService();
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <com_android_graphics_libgui_flags.h>
#include <utils/StrongPointer.h>

struct ANativeWindow;

namespace android {

class IGraphicBufferProducer;
@@ -59,6 +61,7 @@ typedef android::sp<android::IGraphicBufferProducer> MediaParcelableSurfaceType;
#endif

namespace mediaflagtools {
sp<MediaSurfaceType> nativeWindowToSurfaceType(ANativeWindow* anw);
sp<MediaSurfaceType> igbpToSurfaceType(const sp<IGraphicBufferProducer>& igbp);
sp<IGraphicBufferProducer> surfaceTypeToIGBP(const sp<MediaSurfaceType>& mst);
sp<SurfaceType> mediaSurfaceToCameraSurfaceType(const sp<MediaSurfaceType>& mst,
+5 −0
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@ public:
    explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false,
                     const sp<IBinder>& surfaceControlHandle = nullptr);

    /*
     * Get the underlying Surface from the given ANativeWindow.
     */
    static sp<Surface> from(ANativeWindow* anw);

    /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
     * Surface was created with. Usually it's an error to use the
     * IGraphicBufferProducer while the Surface is connected.