summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lloyd Pique <lpique@google.com> 2018-09-13 11:46:49 -0700
committer Lloyd Pique <lpique@google.com> 2018-09-26 12:59:49 -0700
commit22098366c9cee59b5aeb3b1ca85692152c0a484e (patch)
tree34844be70c85ba1b77ce06c2f69948b34de8e03a
parent42ab75e0b89351f2346dd174b63f0445ceaf3ee3 (diff)
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
-rw-r--r--services/surfaceflinger/Android.bp1
-rw-r--r--services/surfaceflinger/NativeWindowSurface.cpp49
-rw-r--r--services/surfaceflinger/NativeWindowSurface.h50
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp29
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h19
-rw-r--r--services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp9
-rw-r--r--services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.cpp10
-rw-r--r--services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.h12
8 files changed, 122 insertions, 57 deletions
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index 4f12d3e7b5..339f83b5f0 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -138,6 +138,7 @@ filegroup {
"LayerStats.cpp",
"LayerVector.cpp",
"MonitoredProducer.cpp",
+ "NativeWindowSurface.cpp",
"RenderArea.cpp",
"Scheduler/DispSync.cpp",
"Scheduler/DispSyncSource.cpp",
diff --git a/services/surfaceflinger/NativeWindowSurface.cpp b/services/surfaceflinger/NativeWindowSurface.cpp
new file mode 100644
index 0000000000..3fff9283ee
--- /dev/null
+++ b/services/surfaceflinger/NativeWindowSurface.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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
diff --git a/services/surfaceflinger/NativeWindowSurface.h b/services/surfaceflinger/NativeWindowSurface.h
new file mode 100644
index 0000000000..f34a45abed
--- /dev/null
+++ b/services/surfaceflinger/NativeWindowSurface.h
@@ -0,0 +1,50 @@
+/*
+ * 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
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 8dc22e971e..1e8958fa67 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -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");
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index a300857749..3154666b43 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -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;
diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
index cc460439a6..b474e42260 100644
--- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
@@ -125,7 +125,7 @@ public:
// These mocks are created only when expected to be created via a factory.
sp<mock::GraphicBufferConsumer> mConsumer;
sp<mock::GraphicBufferProducer> mProducer;
- mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
+ surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr;
sp<mock::NativeWindow> mNativeWindow;
renderengine::mock::Surface* mRenderSurface = nullptr;
};
@@ -195,11 +195,12 @@ void DisplayTransactionTest::injectFakeNativeWindowSurfaceFactory() {
// This setup is only expected once per test.
ASSERT_TRUE(mNativeWindowSurface == nullptr);
- mNativeWindowSurface = new mock::NativeWindowSurface();
+ mNativeWindowSurface = new surfaceflinger::mock::NativeWindowSurface();
mNativeWindow = new mock::NativeWindow();
- mFlinger.setCreateNativeWindowSurface(
- [this](auto) { return std::unique_ptr<NativeWindowSurface>(mNativeWindowSurface); });
+ mFlinger.setCreateNativeWindowSurface([this](auto) {
+ return std::unique_ptr<surfaceflinger::NativeWindowSurface>(mNativeWindowSurface);
+ });
}
bool DisplayTransactionTest::hasHwcDisplay(hwc2_display_t displayId) {
diff --git a/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.cpp b/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.cpp
index 25ff39bbd1..9cc6d38397 100644
--- a/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.cpp
+++ b/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.cpp
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
- *
+ * 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
@@ -16,12 +16,10 @@
#include "mock/MockNativeWindowSurface.h"
-namespace android {
-namespace mock {
+namespace android::surfaceflinger::mock {
// Explicit default instantiation is recommended.
NativeWindowSurface::NativeWindowSurface() = default;
NativeWindowSurface::~NativeWindowSurface() = default;
-} // namespace mock
-} // namespace android
+} // namespace android::surfaceflinger::mock
diff --git a/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.h b/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.h
index 88d1a9fc51..7bc1151d61 100644
--- a/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.h
+++ b/services/surfaceflinger/tests/unittests/mock/MockNativeWindowSurface.h
@@ -20,19 +20,17 @@
#include <system/window.h> // for ANativeWindow
-#include "SurfaceFlinger.h" // for base NativeWindowSurface
+#include "NativeWindowSurface.h"
-namespace android {
-namespace mock {
+namespace android::surfaceflinger::mock {
-class NativeWindowSurface : public android::NativeWindowSurface {
+class NativeWindowSurface : public surfaceflinger::NativeWindowSurface {
public:
NativeWindowSurface();
- ~NativeWindowSurface();
+ ~NativeWindowSurface() override;
MOCK_CONST_METHOD0(getNativeWindow, sp<ANativeWindow>());
MOCK_METHOD0(preallocateBuffers, void());
};
-} // namespace mock
-} // namespace android
+} // namespace android::surfaceflinger::mock