diff options
| author | 2019-10-27 04:44:29 +0000 | |
|---|---|---|
| committer | 2019-10-27 04:44:29 +0000 | |
| commit | 1aed8b369dd977fba69134fc03bf3762c26c560c (patch) | |
| tree | 5840f75cb9669f1da1c4aae8ab1cf2dedd016fb8 /libs/gui | |
| parent | 19c8513c7b7d75ddd78d1b4c6948e4dadc1e50f7 (diff) | |
| parent | 0205f87a0121f1e6057055752365a01b390c60ec (diff) | |
Merge "Merge Coral/Flame into AOSP master"
Diffstat (limited to 'libs/gui')
| -rw-r--r-- | libs/gui/Android.bp | 1 | ||||
| -rw-r--r-- | libs/gui/BufferQueueProducer.cpp | 9 | ||||
| -rw-r--r-- | libs/gui/DebugEGLImageTracker.cpp | 98 | ||||
| -rw-r--r-- | libs/gui/DisplayEventReceiver.cpp | 5 | ||||
| -rw-r--r-- | libs/gui/GLConsumer.cpp | 6 | ||||
| -rw-r--r-- | libs/gui/ISurfaceComposer.cpp | 12 | ||||
| -rw-r--r-- | libs/gui/Surface.cpp | 12 | ||||
| -rw-r--r-- | libs/gui/include/gui/DebugEGLImageTracker.h | 44 | ||||
| -rw-r--r-- | libs/gui/include/gui/DisplayEventReceiver.h | 5 | ||||
| -rw-r--r-- | libs/gui/include/gui/ISurfaceComposer.h | 5 | ||||
| -rw-r--r-- | libs/gui/include/gui/Surface.h | 3 | ||||
| -rw-r--r-- | libs/gui/tests/Surface_test.cpp | 4 |
12 files changed, 192 insertions, 12 deletions
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 59cb8e0a2b..a615fbf812 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -34,6 +34,7 @@ cc_library_shared { "BufferItemConsumer.cpp", "ConsumerBase.cpp", "CpuConsumer.cpp", + "DebugEGLImageTracker.cpp", "DisplayEventReceiver.cpp", "GLConsumer.cpp", "GuiConfig.cpp", diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 9c311a314f..92ab41019e 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -936,6 +936,15 @@ status_t BufferQueueProducer::queueBuffer(int slot, } } + // Make sure to merge the damage rect from the frame we're about + // to drop into the new frame's damage rect. + if (last.mSurfaceDamage.bounds() == Rect::INVALID_RECT || + item.mSurfaceDamage.bounds() == Rect::INVALID_RECT) { + item.mSurfaceDamage = Region::INVALID_REGION; + } else { + item.mSurfaceDamage |= last.mSurfaceDamage; + } + // Overwrite the droppable buffer with the incoming one mCore->mQueue.editItemAt(mCore->mQueue.size() - 1) = item; frameReplacedListener = mCore->mConsumerListener; diff --git a/libs/gui/DebugEGLImageTracker.cpp b/libs/gui/DebugEGLImageTracker.cpp new file mode 100644 index 0000000000..ab6f36444a --- /dev/null +++ b/libs/gui/DebugEGLImageTracker.cpp @@ -0,0 +1,98 @@ +/* + * Copyright 2019 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 <android-base/stringprintf.h> +#include <cutils/properties.h> +#include <gui/DebugEGLImageTracker.h> + +#include <cinttypes> +#include <unordered_map> + +using android::base::StringAppendF; + +std::mutex DebugEGLImageTracker::mInstanceLock; +std::atomic<DebugEGLImageTracker *> DebugEGLImageTracker::mInstance; + +class DebugEGLImageTrackerNoOp : public DebugEGLImageTracker { +public: + DebugEGLImageTrackerNoOp() = default; + ~DebugEGLImageTrackerNoOp() override = default; + void create(const char * /*from*/) override {} + void destroy(const char * /*from*/) override {} + + void dump(std::string & /*result*/) override {} +}; + +class DebugEGLImageTrackerImpl : public DebugEGLImageTracker { +public: + DebugEGLImageTrackerImpl() = default; + ~DebugEGLImageTrackerImpl() override = default; + void create(const char * /*from*/) override; + void destroy(const char * /*from*/) override; + + void dump(std::string & /*result*/) override; + +private: + std::mutex mLock; + std::unordered_map<std::string, int64_t> mCreateTracker; + std::unordered_map<std::string, int64_t> mDestroyTracker; + + int64_t mTotalCreated = 0; + int64_t mTotalDestroyed = 0; +}; + +DebugEGLImageTracker *DebugEGLImageTracker::getInstance() { + std::lock_guard lock(mInstanceLock); + if (mInstance == nullptr) { + char value[PROPERTY_VALUE_MAX]; + property_get("debug.sf.enable_egl_image_tracker", value, "0"); + const bool enabled = static_cast<bool>(atoi(value)); + + if (enabled) { + mInstance = new DebugEGLImageTrackerImpl(); + } else { + mInstance = new DebugEGLImageTrackerNoOp(); + } + } + + return mInstance; +} + +void DebugEGLImageTrackerImpl::create(const char *from) { + std::lock_guard lock(mLock); + mCreateTracker[from]++; + mTotalCreated++; +} + +void DebugEGLImageTrackerImpl::destroy(const char *from) { + std::lock_guard lock(mLock); + mDestroyTracker[from]++; + mTotalDestroyed++; +} + +void DebugEGLImageTrackerImpl::dump(std::string &result) { + std::lock_guard lock(mLock); + StringAppendF(&result, "Live EGL Image objects: %" PRIi64 "\n", + mTotalCreated - mTotalDestroyed); + StringAppendF(&result, "Total EGL Image created: %" PRIi64 "\n", mTotalCreated); + for (const auto &[from, count] : mCreateTracker) { + StringAppendF(&result, "\t%s: %" PRIi64 "\n", from.c_str(), count); + } + StringAppendF(&result, "Total EGL Image destroyed: %" PRIi64 "\n", mTotalDestroyed); + for (const auto &[from, count] : mDestroyTracker) { + StringAppendF(&result, "\t%s: %" PRIi64 "\n", from.c_str(), count); + } +} diff --git a/libs/gui/DisplayEventReceiver.cpp b/libs/gui/DisplayEventReceiver.cpp index f5cf1c4d5a..b8faa2df4c 100644 --- a/libs/gui/DisplayEventReceiver.cpp +++ b/libs/gui/DisplayEventReceiver.cpp @@ -32,10 +32,11 @@ namespace android { // --------------------------------------------------------------------------- -DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) { +DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource, + ISurfaceComposer::ConfigChanged configChanged) { sp<ISurfaceComposer> sf(ComposerService::getComposerService()); if (sf != nullptr) { - mEventConnection = sf->createDisplayEventConnection(vsyncSource); + mEventConnection = sf->createDisplayEventConnection(vsyncSource, configChanged); if (mEventConnection != nullptr) { mDataChannel = std::make_unique<gui::BitTube>(); mEventConnection->stealReceiveChannel(mDataChannel.get()); diff --git a/libs/gui/GLConsumer.cpp b/libs/gui/GLConsumer.cpp index 8d66154bdd..8199c98582 100644 --- a/libs/gui/GLConsumer.cpp +++ b/libs/gui/GLConsumer.cpp @@ -34,6 +34,7 @@ #include <math/mat4.h> #include <gui/BufferItem.h> +#include <gui/DebugEGLImageTracker.h> #include <gui/GLConsumer.h> #include <gui/ISurfaceComposer.h> #include <gui/SurfaceComposerClient.h> @@ -944,6 +945,7 @@ GLConsumer::EglImage::~EglImage() { if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) { ALOGE("~EglImage: eglDestroyImageKHR failed"); } + DEBUG_EGL_IMAGE_TRACKER_DESTROY(); eglTerminate(mEglDisplay); } } @@ -957,6 +959,7 @@ status_t GLConsumer::EglImage::createIfNeeded(EGLDisplay eglDisplay, if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) { ALOGE("createIfNeeded: eglDestroyImageKHR failed"); } + DEBUG_EGL_IMAGE_TRACKER_DESTROY(); eglTerminate(mEglDisplay); mEglImage = EGL_NO_IMAGE_KHR; mEglDisplay = EGL_NO_DISPLAY; @@ -1006,7 +1009,10 @@ EGLImageKHR GLConsumer::EglImage::createImage(EGLDisplay dpy, EGLint error = eglGetError(); ALOGE("error creating EGLImage: %#x", error); eglTerminate(dpy); + } else { + DEBUG_EGL_IMAGE_TRACKER_CREATE(); } + return image; } diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 9590df7c8f..12deaf0bd6 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -278,8 +278,8 @@ public: return NO_ERROR; } - virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource) - { + virtual sp<IDisplayEventConnection> createDisplayEventConnection(VsyncSource vsyncSource, + ConfigChanged configChanged) { Parcel data, reply; sp<IDisplayEventConnection> result; int err = data.writeInterfaceToken( @@ -288,6 +288,7 @@ public: return result; } data.writeInt32(static_cast<int32_t>(vsyncSource)); + data.writeInt32(static_cast<int32_t>(configChanged)); err = remote()->transact( BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION, data, &reply); @@ -1155,8 +1156,11 @@ status_t BnSurfaceComposer::onTransact( } case CREATE_DISPLAY_EVENT_CONNECTION: { CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp<IDisplayEventConnection> connection(createDisplayEventConnection( - static_cast<ISurfaceComposer::VsyncSource>(data.readInt32()))); + auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32()); + auto configChanged = static_cast<ISurfaceComposer::ConfigChanged>(data.readInt32()); + + sp<IDisplayEventConnection> connection( + createDisplayEventConnection(vsyncSource, configChanged)); reply->writeStrongBinder(IInterface::asBinder(connection)); return NO_ERROR; } diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index e6eb327c6f..9fe5de82d1 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1920,7 +1920,8 @@ status_t Surface::getAndFlushRemovedBuffers(std::vector<sp<GraphicBuffer>>* out) return OK; } -status_t Surface::attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer) { +status_t Surface::attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer, + Dataspace dataspace) { if (buffer == nullptr) { return BAD_VALUE; } @@ -1929,6 +1930,11 @@ status_t Surface::attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffe if (err != OK) { return err; } + ui::Dataspace tmpDataspace = surface->getBuffersDataSpace(); + err = surface->setBuffersDataSpace(dataspace); + if (err != OK) { + return err; + } err = surface->attachBuffer(buffer->getNativeBuffer()); if (err != OK) { return err; @@ -1937,6 +1943,10 @@ status_t Surface::attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffe if (err != OK) { return err; } + err = surface->setBuffersDataSpace(tmpDataspace); + if (err != OK) { + return err; + } err = surface->disconnect(NATIVE_WINDOW_API_CPU); return err; } diff --git a/libs/gui/include/gui/DebugEGLImageTracker.h b/libs/gui/include/gui/DebugEGLImageTracker.h new file mode 100644 index 0000000000..5d369c9a35 --- /dev/null +++ b/libs/gui/include/gui/DebugEGLImageTracker.h @@ -0,0 +1,44 @@ +/* + * Copyright 2019 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 <atomic> +#include <mutex> +#include <string> + +class DebugEGLImageTracker { +public: + static DebugEGLImageTracker *getInstance(); + + virtual void create(const char *from) = 0; + virtual void destroy(const char *from) = 0; + + virtual void dump(std::string &result) = 0; + +protected: + DebugEGLImageTracker() = default; + virtual ~DebugEGLImageTracker() = default; + DebugEGLImageTracker(const DebugEGLImageTracker &) = delete; + + static std::mutex mInstanceLock; + static std::atomic<DebugEGLImageTracker *> mInstance; +}; + +#define DEBUG_EGL_IMAGE_TRACKER_CREATE() \ + (DebugEGLImageTracker::getInstance()->create(__PRETTY_FUNCTION__)) +#define DEBUG_EGL_IMAGE_TRACKER_DESTROY() \ + (DebugEGLImageTracker::getInstance()->destroy(__PRETTY_FUNCTION__))
\ No newline at end of file diff --git a/libs/gui/include/gui/DisplayEventReceiver.h b/libs/gui/include/gui/DisplayEventReceiver.h index 22de751498..a558cf9e18 100644 --- a/libs/gui/include/gui/DisplayEventReceiver.h +++ b/libs/gui/include/gui/DisplayEventReceiver.h @@ -88,10 +88,13 @@ public: * DisplayEventReceiver creates and registers an event connection with * SurfaceFlinger. VSync events are disabled by default. Call setVSyncRate * or requestNextVsync to receive them. + * To receive Config Changed events specify this in the constructor. * Other events start being delivered immediately. */ explicit DisplayEventReceiver( - ISurfaceComposer::VsyncSource vsyncSource = ISurfaceComposer::eVsyncSourceApp); + ISurfaceComposer::VsyncSource vsyncSource = ISurfaceComposer::eVsyncSourceApp, + ISurfaceComposer::ConfigChanged configChanged = + ISurfaceComposer::eConfigChangedSuppress); /* * ~DisplayEventReceiver severs the connection with SurfaceFlinger, new events diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index e2f77365b3..c84910b6ec 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -90,6 +90,8 @@ public: eVsyncSourceSurfaceFlinger = 1 }; + enum ConfigChanged { eConfigChangedSuppress = 0, eConfigChangedDispatch = 1 }; + /* * Create a connection with SurfaceFlinger. */ @@ -97,7 +99,8 @@ public: /* return an IDisplayEventConnection */ virtual sp<IDisplayEventConnection> createDisplayEventConnection( - VsyncSource vsyncSource = eVsyncSourceApp) = 0; + VsyncSource vsyncSource = eVsyncSourceApp, + ConfigChanged configChanged = eConfigChangedSuppress) = 0; /* create a virtual display * requires ACCESS_SURFACE_FLINGER permission. diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 0c471bb701..5c6a1ee383 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -292,7 +292,8 @@ public: ui::Dataspace getBuffersDataSpace(); - static status_t attachAndQueueBuffer(Surface* surface, sp<GraphicBuffer> buffer); + static status_t attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer, + ui::Dataspace dataspace); protected: enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 960cf1846e..d3708586f5 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -548,8 +548,8 @@ public: } sp<ISurfaceComposerClient> createConnection() override { return nullptr; } - sp<IDisplayEventConnection> createDisplayEventConnection(ISurfaceComposer::VsyncSource) - override { + sp<IDisplayEventConnection> createDisplayEventConnection( + ISurfaceComposer::VsyncSource, ISurfaceComposer::ConfigChanged) override { return nullptr; } sp<IBinder> createDisplay(const String8& /*displayName*/, |