Loading services/surfaceflinger/DisplayDevice.cpp +20 −7 Original line number Diff line number Diff line Loading @@ -225,6 +225,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) mNativeWindow(args.nativeWindow), mGraphicBuffer(nullptr), mDisplaySurface(args.displaySurface), mSurface{std::move(args.renderSurface)}, mDisplayInstallOrientation(args.displayInstallOrientation), mPageFlipCount(0), mIsVirtual(args.isVirtual), Loading @@ -246,6 +247,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) ALOGE_IF(!mNativeWindow, "No native window was set for display"); ALOGE_IF(!mDisplaySurface, "No display surface was set for display"); ALOGE_IF(!mSurface, "No render surface was set for display"); std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes(); for (Hdr hdrType : types) { Loading Loading @@ -437,6 +439,12 @@ void DisplayDevice::onPresentDisplayCompleted() { mDisplaySurface->onFrameCommitted(); } bool DisplayDevice::makeCurrent() const { bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface); setViewportAndProjection(); return success; } void DisplayDevice::setViewportAndProjection() const { size_t w = mDisplayWidth; size_t h = mDisplayHeight; Loading Loading @@ -599,8 +607,12 @@ status_t DisplayDevice::orientationToTransfrom( void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { dirtyRegion.set(getBounds()); mSurface->setNativeWindow(nullptr); mDisplaySurface->resizeBuffers(newWidth, newHeight); ANativeWindow* const window = mNativeWindow.get(); mSurface->setNativeWindow(window); mDisplayWidth = newWidth; mDisplayHeight = newHeight; } Loading Loading @@ -716,11 +728,12 @@ void DisplayDevice::dump(String8& result) const { ANativeWindow* const window = mNativeWindow.get(); result.appendFormat("+ %s\n", getDebugName().c_str()); result.appendFormat(" layerStack=%u, (%4dx%4d), ANativeWindow=%p " "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, " "powerMode=%d, activeConfig=%d, numLayers=%zu\n", "(%d:%d:%d:%d), orient=%2d (type=%08x), " "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n", mLayerStack, mDisplayWidth, mDisplayHeight, window, ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, mSurface->queryRedSize(), mSurface->queryGreenSize(), mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation, tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size()); result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", Loading @@ -731,9 +744,9 @@ void DisplayDevice::dump(String8& result) const { auto const surface = static_cast<Surface*>(window); ui::Dataspace dataspace = surface->getBuffersDataSpace(); result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); String8 surfaceDump; mDisplaySurface->dumpAsString(surfaceDump); Loading services/surfaceflinger/DisplayDevice.h +6 −2 Original line number Diff line number Diff line Loading @@ -24,13 +24,12 @@ #include <string> #include <unordered_map> #include <android/native_window.h> #include <binder/IBinder.h> #include <gui/LayerState.h> #include <hardware/hwcomposer_defs.h> #include <math/mat4.h> #include <renderengine/RenderEngine.h> #include <system/window.h> #include <renderengine/Surface.h> #include <ui/GraphicTypes.h> #include <ui/HdrCapabilities.h> #include <ui/Region.h> Loading @@ -43,6 +42,8 @@ #include "DisplayHardware/DisplayIdentification.h" #include "RenderArea.h" struct ANativeWindow; namespace android { class DisplaySurface; Loading Loading @@ -162,6 +163,7 @@ public: void setDisplayName(const std::string& displayName); const std::string& getDisplayName() const { return mDisplayName; } bool makeCurrent() const; // Acquires a new buffer for GPU composition. void readyNewBuffer(); // Marks the current buffer has finished, so that it can be presented and Loading Loading @@ -218,6 +220,7 @@ private: // that drawing to the buffer is now complete. base::unique_fd mBufferReady; std::unique_ptr<renderengine::Surface> mSurface; int mDisplayWidth; int mDisplayHeight; const int mDisplayInstallOrientation; Loading Loading @@ -337,6 +340,7 @@ struct DisplayDeviceCreationArgs { bool isSecure{false}; sp<ANativeWindow> nativeWindow; sp<DisplaySurface> displaySurface; std::unique_ptr<renderengine::Surface> renderSurface; int displayInstallOrientation{DisplayState::eOrientationDefault}; bool hasWideColorGamut{false}; HdrCapabilities hdrCapabilities; Loading services/surfaceflinger/SurfaceFlinger.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -2337,6 +2337,14 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( auto nativeWindow = nativeWindowSurface->getNativeWindow(); creationArgs.nativeWindow = nativeWindow; /* * Create our display's surface */ std::unique_ptr<renderengine::Surface> renderSurface = getRenderEngine().createSurface(); renderSurface->setCritical(isInternalDisplay); renderSurface->setAsync(state.isVirtual()); creationArgs.renderSurface = std::move(renderSurface); // Make sure that composition can never be stalled by a virtual display // consumer that isn't processing buffers fast enough. We have to do this // here, in case the display is composed entirely by HWC. Loading services/surfaceflinger/tests/unittests/CompositionTest.cpp +3 −4 Original line number Diff line number Diff line Loading @@ -94,10 +94,6 @@ public: EXPECT_CALL(*mPrimaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0)); EXPECT_CALL(*mPrimaryDispSync, getPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0))); mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); setupComposer(0); Loading Loading @@ -144,6 +140,7 @@ public: sp<DisplayDevice> mDisplay; sp<DisplayDevice> mExternalDisplay; sp<mock::DisplaySurface> mDisplaySurface = new mock::DisplaySurface(); renderengine::mock::Surface* mRenderSurface = new renderengine::mock::Surface(); mock::NativeWindow* mNativeWindow = new mock::NativeWindow(); sp<GraphicBuffer> mBuffer = new GraphicBuffer(); Loading Loading @@ -249,6 +246,8 @@ struct BaseDisplayVariant { test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */, true /* isPrimary */) .setDisplaySurface(test->mDisplaySurface) .setRenderSurface(std::unique_ptr<renderengine::Surface>( test->mRenderSurface)) .setNativeWindow(test->mNativeWindow) .setSecure(Derived::IS_SECURE) .setPowerMode(Derived::INIT_POWER_MODE) Loading services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,7 @@ public: sp<mock::GraphicBufferConsumer> mConsumer; sp<mock::GraphicBufferProducer> mProducer; surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; renderengine::mock::Surface* mRenderSurface = nullptr; }; DisplayTransactionTest::DisplayTransactionTest() { Loading Loading @@ -341,10 +342,22 @@ struct DisplayVariant { EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) .WillOnce(Return(test->mNativeWindow)); // For simplicity, we only expect to create a single render surface for // each test. ASSERT_TRUE(test->mRenderSurface == nullptr); test->mRenderSurface = new renderengine::mock::Surface(); EXPECT_CALL(*test->mRenderEngine, createSurface()) .WillOnce(Return(ByMove( std::unique_ptr<renderengine::Surface>(test->mRenderSurface)))); EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); // Creating a DisplayDevice requires getting default dimensions from the // native window. EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1); EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1); } static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { Loading Loading @@ -1931,10 +1944,12 @@ TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); auto displaySurface = new mock::DisplaySurface(); auto renderSurface = new renderengine::mock::Surface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); display.setDisplaySurface(displaySurface); display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); // Setup injection expections EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); Loading Loading @@ -1973,10 +1988,12 @@ TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); auto displaySurface = new mock::DisplaySurface(); auto renderSurface = new renderengine::mock::Surface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); display.setDisplaySurface(displaySurface); display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); // Setup injection expections EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); Loading Loading
services/surfaceflinger/DisplayDevice.cpp +20 −7 Original line number Diff line number Diff line Loading @@ -225,6 +225,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) mNativeWindow(args.nativeWindow), mGraphicBuffer(nullptr), mDisplaySurface(args.displaySurface), mSurface{std::move(args.renderSurface)}, mDisplayInstallOrientation(args.displayInstallOrientation), mPageFlipCount(0), mIsVirtual(args.isVirtual), Loading @@ -246,6 +247,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) ALOGE_IF(!mNativeWindow, "No native window was set for display"); ALOGE_IF(!mDisplaySurface, "No display surface was set for display"); ALOGE_IF(!mSurface, "No render surface was set for display"); std::vector<Hdr> types = args.hdrCapabilities.getSupportedHdrTypes(); for (Hdr hdrType : types) { Loading Loading @@ -437,6 +439,12 @@ void DisplayDevice::onPresentDisplayCompleted() { mDisplaySurface->onFrameCommitted(); } bool DisplayDevice::makeCurrent() const { bool success = mFlinger->getRenderEngine().setCurrentSurface(*mSurface); setViewportAndProjection(); return success; } void DisplayDevice::setViewportAndProjection() const { size_t w = mDisplayWidth; size_t h = mDisplayHeight; Loading Loading @@ -599,8 +607,12 @@ status_t DisplayDevice::orientationToTransfrom( void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { dirtyRegion.set(getBounds()); mSurface->setNativeWindow(nullptr); mDisplaySurface->resizeBuffers(newWidth, newHeight); ANativeWindow* const window = mNativeWindow.get(); mSurface->setNativeWindow(window); mDisplayWidth = newWidth; mDisplayHeight = newHeight; } Loading Loading @@ -716,11 +728,12 @@ void DisplayDevice::dump(String8& result) const { ANativeWindow* const window = mNativeWindow.get(); result.appendFormat("+ %s\n", getDebugName().c_str()); result.appendFormat(" layerStack=%u, (%4dx%4d), ANativeWindow=%p " "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, " "powerMode=%d, activeConfig=%d, numLayers=%zu\n", "(%d:%d:%d:%d), orient=%2d (type=%08x), " "flips=%u, isSecure=%d, powerMode=%d, activeConfig=%d, numLayers=%zu\n", mLayerStack, mDisplayWidth, mDisplayHeight, window, ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, mSurface->queryRedSize(), mSurface->queryGreenSize(), mSurface->queryBlueSize(), mSurface->queryAlphaSize(), mOrientation, tr.getType(), getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size()); result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", Loading @@ -731,9 +744,9 @@ void DisplayDevice::dump(String8& result) const { auto const surface = static_cast<Surface*>(window); ui::Dataspace dataspace = surface->getBuffersDataSpace(); result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), dataspaceDetails(static_cast<android_dataspace>(dataspace)).c_str(), dataspace); String8 surfaceDump; mDisplaySurface->dumpAsString(surfaceDump); Loading
services/surfaceflinger/DisplayDevice.h +6 −2 Original line number Diff line number Diff line Loading @@ -24,13 +24,12 @@ #include <string> #include <unordered_map> #include <android/native_window.h> #include <binder/IBinder.h> #include <gui/LayerState.h> #include <hardware/hwcomposer_defs.h> #include <math/mat4.h> #include <renderengine/RenderEngine.h> #include <system/window.h> #include <renderengine/Surface.h> #include <ui/GraphicTypes.h> #include <ui/HdrCapabilities.h> #include <ui/Region.h> Loading @@ -43,6 +42,8 @@ #include "DisplayHardware/DisplayIdentification.h" #include "RenderArea.h" struct ANativeWindow; namespace android { class DisplaySurface; Loading Loading @@ -162,6 +163,7 @@ public: void setDisplayName(const std::string& displayName); const std::string& getDisplayName() const { return mDisplayName; } bool makeCurrent() const; // Acquires a new buffer for GPU composition. void readyNewBuffer(); // Marks the current buffer has finished, so that it can be presented and Loading Loading @@ -218,6 +220,7 @@ private: // that drawing to the buffer is now complete. base::unique_fd mBufferReady; std::unique_ptr<renderengine::Surface> mSurface; int mDisplayWidth; int mDisplayHeight; const int mDisplayInstallOrientation; Loading Loading @@ -337,6 +340,7 @@ struct DisplayDeviceCreationArgs { bool isSecure{false}; sp<ANativeWindow> nativeWindow; sp<DisplaySurface> displaySurface; std::unique_ptr<renderengine::Surface> renderSurface; int displayInstallOrientation{DisplayState::eOrientationDefault}; bool hasWideColorGamut{false}; HdrCapabilities hdrCapabilities; Loading
services/surfaceflinger/SurfaceFlinger.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -2337,6 +2337,14 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal( auto nativeWindow = nativeWindowSurface->getNativeWindow(); creationArgs.nativeWindow = nativeWindow; /* * Create our display's surface */ std::unique_ptr<renderengine::Surface> renderSurface = getRenderEngine().createSurface(); renderSurface->setCritical(isInternalDisplay); renderSurface->setAsync(state.isVirtual()); creationArgs.renderSurface = std::move(renderSurface); // Make sure that composition can never be stalled by a virtual display // consumer that isn't processing buffers fast enough. We have to do this // here, in case the display is composed entirely by HWC. Loading
services/surfaceflinger/tests/unittests/CompositionTest.cpp +3 −4 Original line number Diff line number Diff line Loading @@ -94,10 +94,6 @@ public: EXPECT_CALL(*mPrimaryDispSync, computeNextRefresh(0)).WillRepeatedly(Return(0)); EXPECT_CALL(*mPrimaryDispSync, getPeriod()) .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0))); mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); setupComposer(0); Loading Loading @@ -144,6 +140,7 @@ public: sp<DisplayDevice> mDisplay; sp<DisplayDevice> mExternalDisplay; sp<mock::DisplaySurface> mDisplaySurface = new mock::DisplaySurface(); renderengine::mock::Surface* mRenderSurface = new renderengine::mock::Surface(); mock::NativeWindow* mNativeWindow = new mock::NativeWindow(); sp<GraphicBuffer> mBuffer = new GraphicBuffer(); Loading Loading @@ -249,6 +246,8 @@ struct BaseDisplayVariant { test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, DEFAULT_DISPLAY_ID, false /* isVirtual */, true /* isPrimary */) .setDisplaySurface(test->mDisplaySurface) .setRenderSurface(std::unique_ptr<renderengine::Surface>( test->mRenderSurface)) .setNativeWindow(test->mNativeWindow) .setSecure(Derived::IS_SECURE) .setPowerMode(Derived::INIT_POWER_MODE) Loading
services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -135,6 +135,7 @@ public: sp<mock::GraphicBufferConsumer> mConsumer; sp<mock::GraphicBufferProducer> mProducer; surfaceflinger::mock::NativeWindowSurface* mNativeWindowSurface = nullptr; renderengine::mock::Surface* mRenderSurface = nullptr; }; DisplayTransactionTest::DisplayTransactionTest() { Loading Loading @@ -341,10 +342,22 @@ struct DisplayVariant { EXPECT_CALL(*test->mNativeWindowSurface, getNativeWindow()) .WillOnce(Return(test->mNativeWindow)); // For simplicity, we only expect to create a single render surface for // each test. ASSERT_TRUE(test->mRenderSurface == nullptr); test->mRenderSurface = new renderengine::mock::Surface(); EXPECT_CALL(*test->mRenderEngine, createSurface()) .WillOnce(Return(ByMove( std::unique_ptr<renderengine::Surface>(test->mRenderSurface)))); EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(WIDTH), Return(0))); EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) .WillRepeatedly(DoAll(SetArgPointee<1>(HEIGHT), Return(0))); // Creating a DisplayDevice requires getting default dimensions from the // native window. EXPECT_CALL(*test->mRenderSurface, setAsync(static_cast<bool>(ASYNC))).Times(1); EXPECT_CALL(*test->mRenderSurface, setCritical(static_cast<bool>(CRITICAL))).Times(1); } static void setupFramebufferConsumerBufferQueueCallExpectations(DisplayTransactionTest* test) { Loading Loading @@ -1931,10 +1944,12 @@ TEST_F(HandleTransactionLockedTest, processesDisplayWidthChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); auto displaySurface = new mock::DisplaySurface(); auto renderSurface = new renderengine::mock::Surface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); display.setDisplaySurface(displaySurface); display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); // Setup injection expections EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); Loading Loading @@ -1973,10 +1988,12 @@ TEST_F(HandleTransactionLockedTest, processesDisplayHeightChanges) { // A display is set up auto nativeWindow = new mock::NativeWindow(); auto displaySurface = new mock::DisplaySurface(); auto renderSurface = new renderengine::mock::Surface(); sp<GraphicBuffer> buf = new GraphicBuffer(); auto display = Case::Display::makeFakeExistingDisplayInjector(this); display.setNativeWindow(nativeWindow); display.setDisplaySurface(displaySurface); display.setRenderSurface(std::unique_ptr<renderengine::Surface>(renderSurface)); // Setup injection expections EXPECT_CALL(*nativeWindow, query(NATIVE_WINDOW_WIDTH, _)) .WillOnce(DoAll(SetArgPointee<1>(oldWidth), Return(0))); Loading