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

Commit 22098366 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Break out NativeWindowSurface

I should perhaps have done this originally.
Separating it out like this  is better for the upcoming factory change.

Test: atest libsurfaceflinger_unittest
Bug: None

Change-Id: Ia0d87c55cab9b315886eba6320b5e345632e4231
parent 42ab75e0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ filegroup {
        "LayerStats.cpp",
        "LayerVector.cpp",
        "MonitoredProducer.cpp",
        "NativeWindowSurface.cpp",
        "RenderArea.cpp",
        "Scheduler/DispSync.cpp",
        "Scheduler/DispSyncSource.cpp",
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "NativeWindowSurface.h"

#include <gui/IGraphicBufferProducer.h>
#include <gui/Surface.h>

namespace android::surfaceflinger {

NativeWindowSurface::~NativeWindowSurface() = default;

namespace impl {

std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
        const sp<IGraphicBufferProducer>& producer) {
    class NativeWindowSurface final : public surfaceflinger::NativeWindowSurface {
    public:
        explicit NativeWindowSurface(const sp<IGraphicBufferProducer>& producer)
              : mSurface(new Surface(producer, /* controlledByApp */ false)) {}

        ~NativeWindowSurface() override = default;

        sp<ANativeWindow> getNativeWindow() const override { return mSurface; }

        void preallocateBuffers() override { mSurface->allocateBuffers(); }

    private:
        sp<Surface> mSurface;
    };

    return std::make_unique<NativeWindowSurface>(producer);
}

} // namespace impl
} // namespace android::surfaceflinger
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <memory>

#include <utils/StrongPointer.h>

struct ANativeWindow;

namespace android {

class IGraphicBufferProducer;

namespace surfaceflinger {

// A thin interface to abstract creating instances of Surface (gui/Surface.h) to
// use as a NativeWindow.
class NativeWindowSurface {
public:
    virtual ~NativeWindowSurface();

    // Gets the NativeWindow to use for the surface.
    virtual sp<ANativeWindow> getNativeWindow() const = 0;

    // Indicates that the surface should allocate its buffers now.
    virtual void preallocateBuffers() = 0;
};

namespace impl {

std::unique_ptr<NativeWindowSurface> createNativeWindowSurface(const sp<IGraphicBufferProducer>&);

} // namespace impl
} // namespace surfaceflinger
} // namespace android
+2 −27
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@
#include "Layer.h"
#include "LayerVector.h"
#include "MonitoredProducer.h"
#include "NativeWindowSurface.h"
#include "SurfaceFlinger.h"

#include "DisplayHardware/ComposerHal.h"
@@ -222,32 +223,6 @@ std::string decodeDisplayColorSetting(DisplayColorSetting displayColorSetting) {
    }
}

NativeWindowSurface::~NativeWindowSurface() = default;

namespace impl {

class NativeWindowSurface final : public android::NativeWindowSurface {
public:
    static std::unique_ptr<android::NativeWindowSurface> create(
            const sp<IGraphicBufferProducer>& producer) {
        return std::make_unique<NativeWindowSurface>(producer);
    }

    explicit NativeWindowSurface(const sp<IGraphicBufferProducer>& producer)
          : surface(new Surface(producer, false)) {}

    ~NativeWindowSurface() override = default;

private:
    sp<ANativeWindow> getNativeWindow() const override { return surface; }

    void preallocateBuffers() override { surface->allocateBuffers(); }

    sp<Surface> surface;
};

} // namespace impl

SurfaceFlingerBE::SurfaceFlingerBE()
      : mHwcServiceName(getHwcServiceName()),
        mRenderEngine(nullptr),
@@ -284,7 +259,7 @@ SurfaceFlinger::SurfaceFlinger(SurfaceFlinger::SkipInitializationTag)
        mVrFlingerRequestsDisplay(false),
        mMainThreadId(std::this_thread::get_id()),
        mCreateBufferQueue(&BufferQueue::createBufferQueue),
        mCreateNativeWindowSurface(&impl::NativeWindowSurface::create) {}
        mCreateNativeWindowSurface(&surfaceflinger::impl::createNativeWindowSurface) {}

SurfaceFlinger::SurfaceFlinger() : SurfaceFlinger(SkipInitialization) {
    ALOGI("SurfaceFlinger is starting");
+6 −13
Original line number Diff line number Diff line
@@ -117,6 +117,10 @@ namespace dvr {
class VrFlinger;
} // namespace dvr

namespace surfaceflinger {
class NativeWindowSurface;
} // namespace surfaceflinger

// ---------------------------------------------------------------------------

enum {
@@ -133,18 +137,6 @@ enum class DisplayColorSetting : int32_t {
    ENHANCED = 2,
};

// A thin interface to abstract creating instances of Surface (gui/Surface.h) to
// use as a NativeWindow.
class NativeWindowSurface {
public:
    virtual ~NativeWindowSurface();

    // Gets the NativeWindow to use for the surface.
    virtual sp<ANativeWindow> getNativeWindow() const = 0;

    // Indicates that the surface should allocate its buffers now.
    virtual void preallocateBuffers() = 0;
};

class SurfaceFlingerBE
{
@@ -939,7 +931,8 @@ private:
    CreateBufferQueueFunction mCreateBufferQueue;

    using CreateNativeWindowSurfaceFunction =
            std::function<std::unique_ptr<NativeWindowSurface>(const sp<IGraphicBufferProducer>&)>;
            std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>(
                    const sp<IGraphicBufferProducer>&)>;
    CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface;

    SurfaceFlingerBE mBE;
Loading