diff options
Diffstat (limited to 'libs/gui/include')
31 files changed, 494 insertions, 1439 deletions
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h index ea9b1c68af..2320771a38 100644 --- a/libs/gui/include/gui/BLASTBufferQueue.h +++ b/libs/gui/include/gui/BLASTBufferQueue.h @@ -28,11 +28,9 @@ #include <system/window.h> #include <thread> -#include <queue> namespace android { -class BLASTBufferQueue; class BufferItemConsumer; class BLASTBufferItemConsumer : public BufferItemConsumer { @@ -41,73 +39,51 @@ public: int bufferCount, bool controlledByApp) : BufferItemConsumer(consumer, consumerUsage, bufferCount, controlledByApp), mCurrentlyConnected(false), - mPreviouslyConnected(false), - mBLASTBufferQueue(nullptr) {} + mPreviouslyConnected(false) {} void onDisconnect() override; void addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, - FrameEventHistoryDelta* outDelta) override REQUIRES(mMutex); + FrameEventHistoryDelta* outDelta) override + REQUIRES(mFrameEventHistoryMutex); void updateFrameTimestamps(uint64_t frameNumber, nsecs_t refreshStartTime, const sp<Fence>& gpuCompositionDoneFence, const sp<Fence>& presentFence, const sp<Fence>& prevReleaseFence, CompositorTiming compositorTiming, nsecs_t latchTime, - nsecs_t dequeueReadyTime) REQUIRES(mMutex); + nsecs_t dequeueReadyTime) REQUIRES(mFrameEventHistoryMutex); void getConnectionEvents(uint64_t frameNumber, bool* needsDisconnect); - void setBlastBufferQueue(BLASTBufferQueue* blastbufferqueue) REQUIRES(mMutex); - -protected: - void onSidebandStreamChanged() override REQUIRES(mMutex); private: uint64_t mCurrentFrameNumber = 0; - Mutex mMutex; - ConsumerFrameEventHistory mFrameEventHistory GUARDED_BY(mMutex); - std::queue<uint64_t> mDisconnectEvents GUARDED_BY(mMutex); - bool mCurrentlyConnected GUARDED_BY(mMutex); - bool mPreviouslyConnected GUARDED_BY(mMutex); - BLASTBufferQueue* mBLASTBufferQueue GUARDED_BY(mMutex); + Mutex mFrameEventHistoryMutex; + ConsumerFrameEventHistory mFrameEventHistory GUARDED_BY(mFrameEventHistoryMutex); + std::queue<uint64_t> mDisconnectEvents GUARDED_BY(mFrameEventHistoryMutex); + bool mCurrentlyConnected GUARDED_BY(mFrameEventHistoryMutex); + bool mPreviouslyConnected GUARDED_BY(mFrameEventHistoryMutex); }; class BLASTBufferQueue : public ConsumerBase::FrameAvailableListener, public BufferItemConsumer::BufferFreedListener { public: - BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width, - int height, int32_t format); + BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height, + bool enableTripleBuffering = true); sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { return mProducer; } - sp<Surface> getSurface(bool includeSurfaceControlHandle); void onBufferFreed(const wp<GraphicBuffer>&/* graphicBuffer*/) override { /* TODO */ } - void onFrameReplaced(const BufferItem& item) override; + void onFrameReplaced(const BufferItem& item) override {onFrameAvailable(item);} void onFrameAvailable(const BufferItem& item) override; - void onFrameDequeued(const uint64_t) override; - void onFrameCancelled(const uint64_t) override; void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence, const std::vector<SurfaceControlStats>& stats); - void releaseBufferCallback(const ReleaseCallbackId& id, const sp<Fence>& releaseFence, - uint32_t transformHint, uint32_t currentMaxAcquiredBufferCount); void setNextTransaction(SurfaceComposerClient::Transaction *t); - void mergeWithNextTransaction(SurfaceComposerClient::Transaction* t, uint64_t frameNumber); - void setTransactionCompleteCallback(uint64_t frameNumber, - std::function<void(int64_t)>&& transactionCompleteCallback); - - void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height, int32_t format, - SurfaceComposerClient::Transaction* outTransaction = nullptr); - void flushShadowQueue() {} - - status_t setFrameRate(float frameRate, int8_t compatibility, bool shouldBeSeamless); - status_t setFrameTimelineInfo(const FrameTimelineInfo& info); - - void setSidebandStream(const sp<NativeHandle>& stream); - uint32_t getLastTransformHint() const; + void update(const sp<SurfaceControl>& surface, int width, int height); - virtual ~BLASTBufferQueue(); + virtual ~BLASTBufferQueue() = default; private: friend class BLASTBufferQueueHelper; @@ -115,22 +91,10 @@ private: // can't be copied BLASTBufferQueue& operator = (const BLASTBufferQueue& rhs); BLASTBufferQueue(const BLASTBufferQueue& rhs); - void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, - sp<IGraphicBufferConsumer>* outConsumer); void processNextBufferLocked(bool useNextTransaction) REQUIRES(mMutex); - Rect computeCrop(const BufferItem& item) REQUIRES(mMutex); - // Return true if we need to reject the buffer based on the scaling mode and the buffer size. - bool rejectBuffer(const BufferItem& item) REQUIRES(mMutex); - bool maxBuffersAcquired(bool includeExtraAcquire) const REQUIRES(mMutex); - static PixelFormat convertBufferFormat(PixelFormat& format); - - std::string mName; - // Represents the queued buffer count from buffer queue, - // pre-BLAST. This is mNumFrameAvailable (buffers that queued to blast) + - // mNumAcquired (buffers that queued to SF) mPendingRelease.size() (buffers that are held by - // blast). This counter is read by android studio profiler. - std::string mQueuedBufferTrace; + Rect computeCrop(const BufferItem& item); + sp<SurfaceControl> mSurfaceControl; std::mutex mMutex; @@ -138,61 +102,21 @@ private: // BufferQueue internally allows 1 more than // the max to be acquired - int32_t mMaxAcquiredBuffers = 1; + static const int MAX_ACQUIRED_BUFFERS = 1; int32_t mNumFrameAvailable GUARDED_BY(mMutex); int32_t mNumAcquired GUARDED_BY(mMutex); - // Keep a reference to the submitted buffers so we can release when surfaceflinger drops the - // buffer or the buffer has been presented and a new buffer is ready to be presented. - std::unordered_map<ReleaseCallbackId, BufferItem, ReleaseBufferCallbackIdHash> mSubmitted - GUARDED_BY(mMutex); - - // Keep a queue of the released buffers instead of immediately releasing - // the buffers back to the buffer queue. This would be controlled by SF - // setting the max acquired buffer count. - struct ReleasedBuffer { - ReleaseCallbackId callbackId; + struct PendingReleaseItem { + BufferItem item; sp<Fence> releaseFence; }; - std::deque<ReleasedBuffer> mPendingRelease GUARDED_BY(mMutex); - - ui::Size mSize GUARDED_BY(mMutex); - ui::Size mRequestedSize GUARDED_BY(mMutex); - int32_t mFormat GUARDED_BY(mMutex); - - struct BufferInfo { - bool hasBuffer = false; - uint32_t width; - uint32_t height; - uint32_t transform; - // This is used to check if we should update the blast layer size immediately or wait until - // we get the next buffer. This will support scenarios where the layer can change sizes - // and the buffer will scale to fit the new size. - uint32_t scalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; - Rect crop; - - void update(bool hasBuffer, uint32_t width, uint32_t height, uint32_t transform, - uint32_t scalingMode, const Rect& crop) { - this->hasBuffer = hasBuffer; - this->width = width; - this->height = height; - this->transform = transform; - this->scalingMode = scalingMode; - if (!crop.isEmpty()) { - this->crop = crop; - } else { - this->crop = Rect(width, height); - } - } - }; - // Last acquired buffer's info. This is used to calculate the correct scale when size change is - // requested. We need to use the old buffer's info to determine what scale we need to apply to - // ensure the correct size. - BufferInfo mLastBufferInfo GUARDED_BY(mMutex); - void setMatrix(SurfaceComposerClient::Transaction* t, const BufferInfo& bufferInfo) - REQUIRES(mMutex); + std::queue<const BufferItem> mSubmitted GUARDED_BY(mMutex); + PendingReleaseItem mPendingReleaseItem GUARDED_BY(mMutex); + + int mWidth GUARDED_BY(mMutex); + int mHeight GUARDED_BY(mMutex); uint32_t mTransformHint GUARDED_BY(mMutex); @@ -201,37 +125,6 @@ private: sp<BLASTBufferItemConsumer> mBufferItemConsumer; SurfaceComposerClient::Transaction* mNextTransaction GUARDED_BY(mMutex); - std::vector<std::tuple<uint64_t /* framenumber */, SurfaceComposerClient::Transaction>> - mPendingTransactions GUARDED_BY(mMutex); - - // Last requested auto refresh state set by the producer. The state indicates that the consumer - // should acquire the next frame as soon as it can and not wait for a frame to become available. - // This is only relevant for shared buffer mode. - bool mAutoRefresh GUARDED_BY(mMutex) = false; - - std::queue<FrameTimelineInfo> mNextFrameTimelineInfoQueue GUARDED_BY(mMutex); - - // Tracks the last acquired frame number - uint64_t mLastAcquiredFrameNumber GUARDED_BY(mMutex) = 0; - - std::function<void(int64_t)> mTransactionCompleteCallback GUARDED_BY(mMutex) = nullptr; - uint64_t mTransactionCompleteFrameNumber GUARDED_BY(mMutex){0}; - - // Queues up transactions using this token in SurfaceFlinger. This prevents queued up - // transactions from other parts of the client from blocking this transaction. - const sp<IBinder> mApplyToken GUARDED_BY(mMutex) = new BBinder(); - - // Guards access to mDequeueTimestamps since we cannot hold to mMutex in onFrameDequeued or - // we will deadlock. - std::mutex mTimestampMutex; - // Tracks buffer dequeue times by the client. This info is sent to SurfaceFlinger which uses - // it for debugging purposes. - std::unordered_map<uint64_t /* bufferId */, nsecs_t> mDequeueTimestamps - GUARDED_BY(mTimestampMutex); - - // Keep track of SurfaceControls that have submitted a transaction and BBQ is waiting on a - // callback for them. - std::queue<sp<SurfaceControl>> mSurfaceControlsWithPendingCallback GUARDED_BY(mMutex); }; } // namespace android diff --git a/libs/gui/include/gui/BufferQueueConsumer.h b/libs/gui/include/gui/BufferQueueConsumer.h index 6aa801ab86..7db69eca9d 100644 --- a/libs/gui/include/gui/BufferQueueConsumer.h +++ b/libs/gui/include/gui/BufferQueueConsumer.h @@ -174,10 +174,6 @@ public: // Value used to determine if present time is valid. constexpr static int MAX_REASONABLE_NSEC = 1'000'000'000ULL; // 1 second - // This allows the consumer to acquire an additional buffer if that buffer is not droppable and - // will eventually be released or acquired by the consumer. - void setAllowExtraAcquire(bool /* allow */); - private: sp<BufferQueueCore> mCore; diff --git a/libs/gui/include/gui/BufferQueueCore.h b/libs/gui/include/gui/BufferQueueCore.h index 8d0828d88e..557c28b1b7 100644 --- a/libs/gui/include/gui/BufferQueueCore.h +++ b/libs/gui/include/gui/BufferQueueCore.h @@ -354,9 +354,6 @@ private: // mTransformHintInUse is to cache the mTransformHint used by the producer. uint32_t mTransformHintInUse; - // This allows the consumer to acquire an additional buffer if that buffer is not droppable and - // will eventually be released or acquired by the consumer. - bool mAllowExtraAcquire = false; }; // class BufferQueueCore } // namespace android diff --git a/libs/gui/include/gui/BufferQueueProducer.h b/libs/gui/include/gui/BufferQueueProducer.h index 0ad3075a4d..a7f7d1defa 100644 --- a/libs/gui/include/gui/BufferQueueProducer.h +++ b/libs/gui/include/gui/BufferQueueProducer.h @@ -186,10 +186,6 @@ public: virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, float outTransformMatrix[16]) override; - // See IGraphicBufferProducer::getLastQueuedBuffer - virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, - Rect* outRect, uint32_t* outTransform) override; - // See IGraphicBufferProducer::getFrameTimestamps virtual void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override; diff --git a/libs/gui/include/gui/DisplayEventDispatcher.h b/libs/gui/include/gui/DisplayEventDispatcher.h index 4ade240dcf..f210c34196 100644 --- a/libs/gui/include/gui/DisplayEventDispatcher.h +++ b/libs/gui/include/gui/DisplayEventDispatcher.h @@ -19,33 +19,19 @@ #include <utils/Looper.h> namespace android { -using FrameRateOverride = DisplayEventReceiver::Event::FrameRateOverride; - -struct VsyncEventData { - // The Vsync Id corresponsing to this vsync event. This will be used to - // populate ISurfaceComposer::setFrameTimelineVsync and - // SurfaceComposerClient::setFrameTimelineVsync - int64_t id = FrameTimelineInfo::INVALID_VSYNC_ID; - - // The deadline in CLOCK_MONOTONIC that the app needs to complete its - // frame by (both on the CPU and the GPU) - int64_t deadlineTimestamp = std::numeric_limits<int64_t>::max(); - - // The current frame interval in ns when this frame was scheduled. - int64_t frameInterval = 0; -}; class DisplayEventDispatcher : public LooperCallback { public: explicit DisplayEventDispatcher( const sp<Looper>& looper, ISurfaceComposer::VsyncSource vsyncSource = ISurfaceComposer::eVsyncSourceApp, - ISurfaceComposer::EventRegistrationFlags eventRegistration = {}); + ISurfaceComposer::ConfigChanged configChanged = + ISurfaceComposer::eConfigChangedSuppress); status_t initialize(); void dispose(); status_t scheduleVsync(); - void injectEvent(const DisplayEventReceiver::Event& event); + void requestLatestConfig(); int getFd() const; virtual int handleEvent(int receiveFd, int events, void* data); @@ -57,22 +43,13 @@ private: DisplayEventReceiver mReceiver; bool mWaitingForVsync; - std::vector<FrameRateOverride> mFrameRateOverrides; - - virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count, - VsyncEventData vsyncEventData) = 0; + virtual void dispatchVsync(nsecs_t timestamp, PhysicalDisplayId displayId, uint32_t count) = 0; virtual void dispatchHotplug(nsecs_t timestamp, PhysicalDisplayId displayId, bool connected) = 0; - virtual void dispatchModeChanged(nsecs_t timestamp, PhysicalDisplayId displayId, int32_t modeId, - nsecs_t vsyncPeriod) = 0; - // AChoreographer-specific hook for processing null-events so that looper - // can be properly poked. - virtual void dispatchNullEvent(nsecs_t timestamp, PhysicalDisplayId displayId) = 0; - - virtual void dispatchFrameRateOverrides(nsecs_t timestamp, PhysicalDisplayId displayId, - std::vector<FrameRateOverride> overrides) = 0; + virtual void dispatchConfigChanged(nsecs_t timestamp, PhysicalDisplayId displayId, + int32_t configId, nsecs_t vsyncPeriod) = 0; bool processPendingEvents(nsecs_t* outTimestamp, PhysicalDisplayId* outDisplayId, - uint32_t* outCount, VsyncEventData* outVsyncEventData); + uint32_t* outCount); }; } // namespace android diff --git a/libs/gui/include/gui/DisplayEventReceiver.h b/libs/gui/include/gui/DisplayEventReceiver.h index 0dffbde88a..8d49184caf 100644 --- a/libs/gui/include/gui/DisplayEventReceiver.h +++ b/libs/gui/include/gui/DisplayEventReceiver.h @@ -52,53 +52,36 @@ public: enum { DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'), DISPLAY_EVENT_HOTPLUG = fourcc('p', 'l', 'u', 'g'), - DISPLAY_EVENT_MODE_CHANGE = fourcc('m', 'o', 'd', 'e'), - DISPLAY_EVENT_NULL = fourcc('n', 'u', 'l', 'l'), - DISPLAY_EVENT_FRAME_RATE_OVERRIDE = fourcc('r', 'a', 't', 'e'), - DISPLAY_EVENT_FRAME_RATE_OVERRIDE_FLUSH = fourcc('f', 'l', 's', 'h'), + DISPLAY_EVENT_CONFIG_CHANGED = fourcc('c', 'o', 'n', 'f'), }; struct Event { - // We add __attribute__((aligned(8))) for nsecs_t fields because - // we need to make sure all fields are aligned the same with x86 - // and x64 (long long has different default alignment): - // - // https://en.wikipedia.org/wiki/Data_structure_alignment struct Header { uint32_t type; - PhysicalDisplayId displayId __attribute__((aligned(8))); + PhysicalDisplayId displayId; nsecs_t timestamp __attribute__((aligned(8))); }; struct VSync { uint32_t count; - nsecs_t expectedVSyncTimestamp __attribute__((aligned(8))); - nsecs_t deadlineTimestamp __attribute__((aligned(8))); - nsecs_t frameInterval __attribute__((aligned(8))); - int64_t vsyncId; + nsecs_t expectedVSyncTimestamp; }; struct Hotplug { bool connected; }; - struct ModeChange { - int32_t modeId; - nsecs_t vsyncPeriod __attribute__((aligned(8))); - }; - - struct FrameRateOverride { - uid_t uid __attribute__((aligned(8))); - float frameRateHz __attribute__((aligned(8))); + struct Config { + int32_t configId; + nsecs_t vsyncPeriod; }; Header header; union { VSync vsync; Hotplug hotplug; - ModeChange modeChange; - FrameRateOverride frameRateOverride; + Config config; }; }; @@ -107,12 +90,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 ModeChanged and/or FrameRateOverrides events specify this in - * the constructor. Other events start being delivered immediately. + * To receive Config Changed events specify this in the constructor. + * Other events start being delivered immediately. */ explicit DisplayEventReceiver( ISurfaceComposer::VsyncSource vsyncSource = ISurfaceComposer::eVsyncSourceApp, - ISurfaceComposer::EventRegistrationFlags eventRegistration = {}); + ISurfaceComposer::ConfigChanged configChanged = + ISurfaceComposer::eConfigChangedSuppress); /* * ~DisplayEventReceiver severs the connection with SurfaceFlinger, new events @@ -146,7 +130,6 @@ public: * sendEvents write events to the queue and returns how many events were * written. */ - ssize_t sendEvents(Event const* events, size_t count); static ssize_t sendEvents(gui::BitTube* dataChannel, Event const* events, size_t count); /* @@ -163,6 +146,12 @@ public: */ status_t requestNextVsync(); + /* + * requestLatestConfig() force-requests the current config for the primary + * display. + */ + status_t requestLatestConfig(); + private: sp<IDisplayEventConnection> mEventConnection; std::unique_ptr<gui::BitTube> mDataChannel; diff --git a/libs/gui/include/gui/FrameTimelineInfo.h b/libs/gui/include/gui/FrameTimelineInfo.h deleted file mode 100644 index a23c20248c..0000000000 --- a/libs/gui/include/gui/FrameTimelineInfo.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2021 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 <stdint.h> - -#include <binder/Parcel.h> - -namespace android { - -struct FrameTimelineInfo { - // Needs to be in sync with android.graphics.FrameInfo.INVALID_VSYNC_ID in java - static constexpr int64_t INVALID_VSYNC_ID = -1; - - // The vsync id that was used to start the transaction - int64_t vsyncId = INVALID_VSYNC_ID; - - // The id of the input event that caused this buffer - // Default is android::os::IInputConstants::INVALID_INPUT_EVENT_ID = 0 - // We copy the value of the input event ID instead of including the header, because libgui - // header libraries containing FrameTimelineInfo must be available to vendors, but libinput is - // not directly vendor available. - int32_t inputEventId = 0; - - status_t write(Parcel& output) const; - status_t read(const Parcel& input); - - void merge(const FrameTimelineInfo& other); - void clear(); -}; - -} // namespace android diff --git a/libs/gui/include/gui/FrameTimestamps.h b/libs/gui/include/gui/FrameTimestamps.h index dd3de58844..0750080e1c 100644 --- a/libs/gui/include/gui/FrameTimestamps.h +++ b/libs/gui/include/gui/FrameTimestamps.h @@ -131,7 +131,6 @@ public: // Public for testing. static nsecs_t snapToNextTick( nsecs_t timestamp, nsecs_t tickPhase, nsecs_t tickInterval); - nsecs_t getReportedCompositeDeadline() const { return mCompositorTiming.deadline; }; nsecs_t getNextCompositeDeadline(const nsecs_t now) const; nsecs_t getCompositeInterval() const { return mCompositorTiming.interval; } diff --git a/libs/gui/include/gui/GLConsumer.h b/libs/gui/include/gui/GLConsumer.h index 2f538ffb86..ddd868d7d1 100644 --- a/libs/gui/include/gui/GLConsumer.h +++ b/libs/gui/include/gui/GLConsumer.h @@ -499,7 +499,7 @@ private: // protects static initialization static Mutex sStaticInitLock; - // mReleasedTexImageBuffer is a buffer placeholder used when in single buffer + // mReleasedTexImageBuffer is a dummy buffer used when in single buffer // mode and releaseTexImage() has been called static sp<GraphicBuffer> sReleasedTexImageBuffer; sp<EglImage> mReleasedTexImage; diff --git a/libs/gui/include/gui/TransactionTracing.h b/libs/gui/include/gui/GuiConfig.h index 9efba47a18..7aa54321fd 100644 --- a/libs/gui/include/gui/TransactionTracing.h +++ b/libs/gui/include/gui/GuiConfig.h @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Android Open Source Project + * Copyright (C) 2012 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. @@ -14,28 +14,16 @@ * limitations under the License. */ -#pragma once +#ifndef ANDROID_GUI_CONFIG_H +#define ANDROID_GUI_CONFIG_H -#include <android/gui/BnTransactionTraceListener.h> -#include <utils/Mutex.h> +#include <string> namespace android { -class TransactionTraceListener : public gui::BnTransactionTraceListener { - static std::mutex sMutex; - static sp<TransactionTraceListener> sInstance; +// Append the libgui configuration details to configStr. +void appendGuiConfigString(std::string& configStr); - TransactionTraceListener(); +}; // namespace android -public: - static sp<TransactionTraceListener> getInstance(); - - binder::Status onToggled(bool enabled) override; - - bool isTracingEnabled(); - -private: - bool mTracingEnabled = false; -}; - -} // namespace android +#endif /*ANDROID_GUI_CONFIG_H*/ diff --git a/libs/gui/include/gui/IDisplayEventConnection.h b/libs/gui/include/gui/IDisplayEventConnection.h index cff22a368a..674aafd81c 100644 --- a/libs/gui/include/gui/IDisplayEventConnection.h +++ b/libs/gui/include/gui/IDisplayEventConnection.h @@ -51,6 +51,11 @@ public: * requestNextVsync() schedules the next vsync event. It has no effect if the vsync rate is > 0. */ virtual void requestNextVsync() = 0; // Asynchronous + + /* + * requestLatestConfig() requests the config for the primary display. + */ + virtual void requestLatestConfig() = 0; // Asynchronous }; class BnDisplayEventConnection : public SafeBnInterface<IDisplayEventConnection> { diff --git a/libs/gui/include/gui/IGraphicBufferProducer.h b/libs/gui/include/gui/IGraphicBufferProducer.h index 98df83453d..d7f34920c4 100644 --- a/libs/gui/include/gui/IGraphicBufferProducer.h +++ b/libs/gui/include/gui/IGraphicBufferProducer.h @@ -38,9 +38,6 @@ #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h> #include <android/hardware/graphics/bufferqueue/2.0/IGraphicBufferProducer.h> -#include <optional> -#include <vector> - namespace android { // ---------------------------------------------------------------------------- @@ -292,9 +289,8 @@ public: const sp<GraphicBuffer>& buffer) = 0; struct QueueBufferInput : public Flattenable<QueueBufferInput> { - explicit inline QueueBufferInput(const Parcel& parcel) { - parcel.read(*this); - } + friend class Flattenable<QueueBufferInput>; + explicit inline QueueBufferInput(const Parcel& parcel); // timestamp - a monotonically increasing value in nanoseconds // isAutoTimestamp - if the timestamp was synthesized at queue time @@ -308,29 +304,21 @@ public: // camera mode). // getFrameTimestamps - whether or not the latest frame timestamps // should be retrieved from the consumer. - // slot - the slot index to queue. This is used only by queueBuffers(). - // queueBuffer() ignores this value and uses the argument `slot` - // instead. inline QueueBufferInput(int64_t _timestamp, bool _isAutoTimestamp, android_dataspace _dataSpace, const Rect& _crop, int _scalingMode, uint32_t _transform, const sp<Fence>& _fence, - uint32_t _sticky = 0, bool _getFrameTimestamps = false, - int _slot = -1) + uint32_t _sticky = 0, bool _getFrameTimestamps = false) : timestamp(_timestamp), isAutoTimestamp(_isAutoTimestamp), dataSpace(_dataSpace), crop(_crop), scalingMode(_scalingMode), - transform(_transform), stickyTransform(_sticky), - fence(_fence), surfaceDamage(), - getFrameTimestamps(_getFrameTimestamps), slot(_slot) { } - - QueueBufferInput() = default; + transform(_transform), stickyTransform(_sticky), fence(_fence), + surfaceDamage(), getFrameTimestamps(_getFrameTimestamps) { } inline void deflate(int64_t* outTimestamp, bool* outIsAutoTimestamp, android_dataspace* outDataSpace, Rect* outCrop, int* outScalingMode, uint32_t* outTransform, sp<Fence>* outFence, uint32_t* outStickyTransform = nullptr, - bool* outGetFrameTimestamps = nullptr, - int* outSlot = nullptr) const { + bool* outGetFrameTimestamps = nullptr) const { *outTimestamp = timestamp; *outIsAutoTimestamp = bool(isAutoTimestamp); *outDataSpace = dataSpace; @@ -344,9 +332,6 @@ public: if (outGetFrameTimestamps) { *outGetFrameTimestamps = getFrameTimestamps; } - if (outSlot) { - *outSlot = slot; - } } // Flattenable protocol @@ -372,7 +357,6 @@ public: sp<Fence> fence; Region surfaceDamage; bool getFrameTimestamps{false}; - int slot{-1}; HdrMetadata hdrMetadata; }; @@ -401,7 +385,6 @@ public: FrameEventHistoryDelta frameTimestamps; bool bufferReplaced{false}; int maxBufferCount{0}; - status_t result{NO_ERROR}; }; // queueBuffer indicates that the client has finished filling in the @@ -421,10 +404,6 @@ public: // Upon success, the output will be filled with meaningful values // (refer to the documentation below). // - // Note: QueueBufferInput::slot was added to QueueBufferInput to be used by - // queueBuffers(), the batched version of queueBuffer(). The non-batched - // method (queueBuffer()) uses `slot` and ignores `input.slot`. - // // Return of a value other than NO_ERROR means an error has occurred: // * NO_INIT - the buffer queue has been abandoned or the producer is not // connected. @@ -479,7 +458,7 @@ public: // the producer wants to be notified when the consumer releases a buffer // back to the BufferQueue. It is also used to detect the death of the // producer. If only the latter functionality is desired, there is a - // StubProducerListener class in IProducerListener.h that can be used. + // DummyProducerListener class in IProducerListener.h that can be used. // // The api should be one of the NATIVE_WINDOW_API_* values in <window.h> // @@ -640,22 +619,6 @@ public: virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence, float outTransformMatrix[16]) = 0; - // Returns the last queued buffer along with a fence which must signal - // before the contents of the buffer are read. If there are no buffers in - // the queue, outBuffer will be populated with nullptr and outFence will be - // populated with Fence::NO_FENCE - // - // outRect & outTransform are not modified if outBuffer is null. - // - // Returns NO_ERROR or the status of the Binder transaction - virtual status_t getLastQueuedBuffer([[maybe_unused]] sp<GraphicBuffer>* outBuffer, - [[maybe_unused]] sp<Fence>* outFence, - [[maybe_unused]] Rect* outRect, - [[maybe_unused]] uint32_t* outTransform) { - // Too many things implement IGraphicBufferProducer... - return UNKNOWN_TRANSACTION; - } - // Gets the frame events that haven't already been retrieved. virtual void getFrameTimestamps(FrameEventHistoryDelta* /*outDelta*/) {} @@ -676,147 +639,6 @@ public: // the width and height used for dequeueBuffer will be additionally swapped. virtual status_t setAutoPrerotation(bool autoPrerotation); - struct RequestBufferOutput : public Flattenable<RequestBufferOutput> { - RequestBufferOutput() = default; - - // Flattenable protocol - static constexpr size_t minFlattenedSize(); - size_t getFlattenedSize() const; - size_t getFdCount() const; - status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; - status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); - - status_t result; - sp<GraphicBuffer> buffer; - }; - - // Batched version of requestBuffer(). - // This method behaves like a sequence of requestBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t requestBuffers( - const std::vector<int32_t>& slots, - std::vector<RequestBufferOutput>* outputs); - - struct DequeueBufferInput : public LightFlattenable<DequeueBufferInput> { - DequeueBufferInput() = default; - - // LightFlattenable protocol - inline bool isFixedSize() const { return true; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); - - uint32_t width; - uint32_t height; - PixelFormat format; - uint64_t usage; - bool getTimestamps; - }; - - struct DequeueBufferOutput : public Flattenable<DequeueBufferOutput> { - DequeueBufferOutput() = default; - - // Flattenable protocol - static constexpr size_t minFlattenedSize(); - size_t getFlattenedSize() const; - size_t getFdCount() const; - status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; - status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); - - status_t result; - int slot = -1; - sp<Fence> fence = Fence::NO_FENCE; - uint64_t bufferAge; - std::optional<FrameEventHistoryDelta> timestamps; - }; - - // Batched version of dequeueBuffer(). - // This method behaves like a sequence of dequeueBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t dequeueBuffers( - const std::vector<DequeueBufferInput>& inputs, - std::vector<DequeueBufferOutput>* outputs); - - // Batched version of detachBuffer(). - // This method behaves like a sequence of detachBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t detachBuffers(const std::vector<int32_t>& slots, - std::vector<status_t>* results); - - - struct AttachBufferOutput : public LightFlattenable<AttachBufferOutput> { - AttachBufferOutput() = default; - - // LightFlattenable protocol - inline bool isFixedSize() const { return true; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); - - status_t result; - int slot; - }; - // Batched version of attachBuffer(). - // This method behaves like a sequence of attachBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t attachBuffers( - const std::vector<sp<GraphicBuffer>>& buffers, - std::vector<AttachBufferOutput>* outputs); - - // Batched version of queueBuffer(). - // This method behaves like a sequence of queueBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - // - // Note: QueueBufferInput::slot was added to QueueBufferInput to include the - // `slot` input argument of the non-batched method queueBuffer(). - virtual status_t queueBuffers(const std::vector<QueueBufferInput>& inputs, - std::vector<QueueBufferOutput>* outputs); - - struct CancelBufferInput : public Flattenable<CancelBufferInput> { - CancelBufferInput() = default; - - // Flattenable protocol - static constexpr size_t minFlattenedSize(); - size_t getFlattenedSize() const; - size_t getFdCount() const; - status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; - status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); - - int slot; - sp<Fence> fence; - }; - // Batched version of cancelBuffer(). - // This method behaves like a sequence of cancelBuffer() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t cancelBuffers( - const std::vector<CancelBufferInput>& inputs, - std::vector<status_t>* results); - - struct QueryOutput : public LightFlattenable<QueryOutput> { - QueryOutput() = default; - - // LightFlattenable protocol - inline bool isFixedSize() const { return true; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); - - status_t result; - int64_t value; - }; - // Batched version of query(). - // This method behaves like a sequence of query() calls. - // The return value of the batched method will only be about the - // transaction. For a local call, the return value will always be NO_ERROR. - virtual status_t query(const std::vector<int32_t> inputs, - std::vector<QueryOutput>* outputs); - #ifndef NO_BINDER // Static method exports any IGraphicBufferProducer object to a parcel. It // handles null producer as well. diff --git a/libs/gui/include/gui/IProducerListener.h b/libs/gui/include/gui/IProducerListener.h index f7ffbb99ea..0b1f4b5838 100644 --- a/libs/gui/include/gui/IProducerListener.h +++ b/libs/gui/include/gui/IProducerListener.h @@ -80,9 +80,10 @@ class IProducerListener : public ProducerListener { class BnProducerListener : public IProducerListener { }; #endif -class StubProducerListener : public BnProducerListener { +class DummyProducerListener : public BnProducerListener +{ public: - virtual ~StubProducerListener(); + virtual ~DummyProducerListener(); virtual void onBufferReleased() {} virtual bool needsReleaseNotify() { return false; } }; diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 2a3f6a43d9..8d3160a815 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -16,29 +16,25 @@ #pragma once -#include <android/gui/DisplayBrightness.h> -#include <android/gui/IFpsListener.h> -#include <android/gui/IHdrLayerInfoListener.h> -#include <android/gui/IScreenCaptureListener.h> -#include <android/gui/ITransactionTraceListener.h> -#include <android/gui/ITunnelModeEnabledListener.h> +#include <stdint.h> +#include <sys/types.h> + #include <binder/IBinder.h> #include <binder/IInterface.h> -#include <gui/FrameTimelineInfo.h> + #include <gui/ITransactionCompletedListener.h> -#include <input/Flags.h> + #include <math/vec4.h> -#include <stdint.h> -#include <sys/types.h> + #include <ui/ConfigStoreTypes.h> -#include <ui/DisplayId.h> -#include <ui/DisplayMode.h> #include <ui/DisplayedFrameStats.h> #include <ui/FrameStats.h> #include <ui/GraphicBuffer.h> #include <ui/GraphicTypes.h> +#include <ui/PhysicalDisplayId.h> #include <ui/PixelFormat.h> #include <ui/Rotation.h> + #include <utils/Errors.h> #include <utils/RefBase.h> #include <utils/Timers.h> @@ -52,11 +48,11 @@ namespace android { struct client_cache_t; struct ComposerState; -struct DisplayCaptureArgs; +struct DisplayConfig; +struct DisplayInfo; struct DisplayStatInfo; struct DisplayState; struct InputWindowCommands; -struct LayerCaptureArgs; class LayerDebugInfo; class HdrCapabilities; class IDisplayEventConnection; @@ -66,14 +62,9 @@ class IRegionSamplingListener; class Rect; enum class FrameEvent; -using gui::IScreenCaptureListener; - namespace ui { -struct DisplayMode; struct DisplayState; -struct DynamicDisplayInfo; -struct StaticDisplayInfo; } // namespace ui @@ -92,15 +83,18 @@ public: eSynchronous = 0x01, eAnimation = 0x02, + // DEPRECATED - use eExplicitEarlyWakeup[Start|End] + eEarlyWakeup = 0x04, + // Explicit indication that this transaction and others to follow will likely result in a // lot of layers being composed, and thus, SurfaceFlinger should wake-up earlier to avoid // missing frame deadlines. In this case SurfaceFlinger will wake up at // (sf vsync offset - debug.sf.early_phase_offset_ns). SurfaceFlinger will continue to be - // in the early configuration until it receives eEarlyWakeupEnd. These flags are + // in the early configuration until it receives eExplicitEarlyWakeupEnd. These flags are // expected to be used by WindowManager only and are guarded by // android.permission.ACCESS_SURFACE_FLINGER - eEarlyWakeupStart = 0x08, - eEarlyWakeupEnd = 0x10, + eExplicitEarlyWakeupStart = 0x08, + eExplicitEarlyWakeupEnd = 0x10, }; enum VsyncSource { @@ -108,12 +102,7 @@ public: eVsyncSourceSurfaceFlinger = 1 }; - enum class EventRegistration { - modeChanged = 1 << 0, - frameRateOverride = 1 << 1, - }; - - using EventRegistrationFlags = Flags<EventRegistration>; + enum ConfigChanged { eConfigChangedSuppress = 0, eConfigChangedDispatch = 1 }; /* * Create a connection with SurfaceFlinger. @@ -123,7 +112,7 @@ public: /* return an IDisplayEventConnection */ virtual sp<IDisplayEventConnection> createDisplayEventConnection( VsyncSource vsyncSource = eVsyncSourceApp, - EventRegistrationFlags eventRegistration = {}) = 0; + ConfigChanged configChanged = eConfigChangedSuppress) = 0; /* create a virtual display * requires ACCESS_SURFACE_FLINGER permission. @@ -158,12 +147,13 @@ public: } /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ - virtual status_t setTransactionState( - const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& state, - const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, - const InputWindowCommands& inputWindowCommands, int64_t desiredPresentTime, - bool isAutoTimestamp, const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, - const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId) = 0; + virtual void setTransactionState(const Vector<ComposerState>& state, + const Vector<DisplayState>& displays, uint32_t flags, + const sp<IBinder>& applyToken, + const InputWindowCommands& inputWindowCommands, + int64_t desiredPresentTime, + const client_cache_t& uncacheBuffer, bool hasListenerCallbacks, + const std::vector<ListenerCallbacks>& listenerCallbacks) = 0; /* signal that we're done booting. * Requires ACCESS_SURFACE_FLINGER permission @@ -199,32 +189,56 @@ public: virtual status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState*) = 0; /** - * Gets immutable information about given physical display. + * Get immutable information about given physical display. + */ + virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*) = 0; + + /** + * Get configurations supported by given physical display. */ - virtual status_t getStaticDisplayInfo(const sp<IBinder>& display, ui::StaticDisplayInfo*) = 0; + virtual status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*) = 0; /** - * Gets dynamic information about given physical display. + * Get the index into configurations returned by getDisplayConfigs, + * corresponding to the active configuration. */ - virtual status_t getDynamicDisplayInfo(const sp<IBinder>& display, ui::DynamicDisplayInfo*) = 0; + virtual int getActiveConfig(const sp<IBinder>& display) = 0; + virtual status_t getDisplayColorModes(const sp<IBinder>& display, + Vector<ui::ColorMode>* outColorModes) = 0; virtual status_t getDisplayNativePrimaries(const sp<IBinder>& display, ui::DisplayPrimaries& primaries) = 0; + virtual ui::ColorMode getActiveColorMode(const sp<IBinder>& display) = 0; virtual status_t setActiveColorMode(const sp<IBinder>& display, ui::ColorMode colorMode) = 0; /** + * Returns true if the connected display reports support for HDMI 2.1 Auto + * Low Latency Mode. + * For more information, see the HDMI 2.1 specification. + */ + virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display, + bool* outSupport) const = 0; + + /** * Switches Auto Low Latency Mode on/off on the connected display, if it is - * available. This should only be called if the display supports Auto Low - * Latency Mode as reported in #getDynamicDisplayInfo. + * available. This should only be called if #getAutoLowLatencyMode returns + * true. * For more information, see the HDMI 2.1 specification. */ virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) = 0; /** + * Returns true if the connected display reports support for Game Content Type. + * For more information, see the HDMI 1.4 specification. + */ + virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, + bool* outSupport) const = 0; + + /** * This will start sending infoframes to the connected display with - * ContentType=Game (if on=true). This should only be called if the display - * Game Content Type as reported in #getDynamicDisplayInfo. + * ContentType=Game (if on=true). This will switch the disply to Game mode. + * This should only be called if #getGameContentTypeSupport returns true. * For more information, see the HDMI 1.4 specification. */ virtual void setGameContentType(const sp<IBinder>& display, bool on) = 0; @@ -232,17 +246,65 @@ public: /** * Capture the specified screen. This requires READ_FRAME_BUFFER * permission. This function will fail if there is a secure window on - * screen and DisplayCaptureArgs.captureSecureLayers is false. + * screen. * * This function can capture a subregion (the source crop) of the screen. * The subregion can be optionally rotated. It will also be scaled to * match the size of the output buffer. + * + * reqDataspace and reqPixelFormat specify the data space and pixel format + * of the buffer. The caller should pick the data space and pixel format + * that it can consume. + * + * sourceCrop is the crop on the logical display. + * + * reqWidth and reqHeight specifies the size of the buffer. When either + * of them is 0, they are set to the size of the logical display viewport. + * + * When useIdentityTransform is true, layer transformations are disabled. + * + * rotation specifies the rotation of the source crop (and the pixels in + * it) around its center. + */ + virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer, + bool& outCapturedSecureLayers, ui::Dataspace reqDataspace, + ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform, + ui::Rotation rotation = ui::ROTATION_0, + bool captureSecureLayers = false) = 0; + /** + * Capture the specified screen. This requires READ_FRAME_BUFFER + * permission. This function will fail if there is a secure window on + * screen. + * + * This function can capture a subregion (the source crop) of the screen + * into an sRGB buffer with RGBA_8888 pixel format. + * The subregion can be optionally rotated. It will also be scaled to + * match the size of the output buffer. + * + * At the moment, sourceCrop is ignored and is always set to the visible + * region (projected display viewport) of the screen. + * + * reqWidth and reqHeight specifies the size of the buffer. When either + * of them is 0, they are set to the size of the logical display viewport. + * + * When useIdentityTransform is true, layer transformations are disabled. + * + * rotation specifies the rotation of the source crop (and the pixels in + * it) around its center. */ - virtual status_t captureDisplay(const DisplayCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) = 0; + virtual status_t captureScreen(const sp<IBinder>& display, sp<GraphicBuffer>* outBuffer, + const Rect& sourceCrop, uint32_t reqWidth, uint32_t reqHeight, + bool useIdentityTransform, + ui::Rotation rotation = ui::ROTATION_0) { + bool outIgnored; + return captureScreen(display, outBuffer, outIgnored, ui::Dataspace::V0_SRGB, + ui::PixelFormat::RGBA_8888, sourceCrop, reqWidth, reqHeight, + useIdentityTransform, rotation); + } - virtual status_t captureDisplay(uint64_t displayOrLayerStack, - const sp<IScreenCaptureListener>& captureListener) = 0; + virtual status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace, + sp<GraphicBuffer>* outBuffer) = 0; template <class AA> struct SpHash { @@ -251,11 +313,27 @@ public: /** * Capture a subtree of the layer hierarchy, potentially ignoring the root node. - * This requires READ_FRAME_BUFFER permission. This function will fail if there - * is a secure window on screen + * + * reqDataspace and reqPixelFormat specify the data space and pixel format + * of the buffer. The caller should pick the data space and pixel format + * that it can consume. */ - virtual status_t captureLayers(const LayerCaptureArgs& args, - const sp<IScreenCaptureListener>& captureListener) = 0; + virtual status_t captureLayers( + const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer, + ui::Dataspace reqDataspace, ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + const std::unordered_set<sp<IBinder>, SpHash<IBinder>>& excludeHandles, + float frameScale = 1.0, bool childrenOnly = false) = 0; + + /** + * Capture a subtree of the layer hierarchy into an sRGB buffer with RGBA_8888 pixel format, + * potentially ignoring the root node. + */ + status_t captureLayers(const sp<IBinder>& layerHandleBinder, sp<GraphicBuffer>* outBuffer, + const Rect& sourceCrop, float frameScale = 1.0, + bool childrenOnly = false) { + return captureLayers(layerHandleBinder, outBuffer, ui::Dataspace::V0_SRGB, + ui::PixelFormat::RGBA_8888, sourceCrop, {}, frameScale, childrenOnly); + } /* Clears the frame statistics for animations. * @@ -269,18 +347,12 @@ public: */ virtual status_t getAnimationFrameStats(FrameStats* outStats) const = 0; - /* Overrides the supported HDR modes for the given display device. + /* Gets the supported HDR capabilities of the given display. * * Requires the ACCESS_SURFACE_FLINGER permission. */ - virtual status_t overrideHdrTypes(const sp<IBinder>& display, - const std::vector<ui::Hdr>& hdrTypes) = 0; - - /* Pulls surfaceflinger atoms global stats and layer stats to pipe to statsd. - * - * Requires the calling uid be from system server. - */ - virtual status_t onPullAtom(const int32_t atomId, std::string* outData, bool* success) = 0; + virtual status_t getHdrCapabilities(const sp<IBinder>& display, + HdrCapabilities* outCapabilities) const = 0; virtual status_t enableVSyncInjections(bool enable) = 0; @@ -362,66 +434,36 @@ public: */ virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) = 0; - /* Registers a listener that streams fps updates from SurfaceFlinger. - * - * The listener will stream fps updates for the layer tree rooted at the layer denoted by the - * task ID, i.e., the layer must have the task ID as part of its layer metadata with key - * METADATA_TASK_ID. If there is no such layer, then no fps is expected to be reported. - * - * Multiple listeners may be supported. - * - * Requires the READ_FRAME_BUFFER permission. - */ - virtual status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) = 0; - /* - * Removes a listener that was streaming fps updates from SurfaceFlinger. - */ - virtual status_t removeFpsListener(const sp<gui::IFpsListener>& listener) = 0; - - /* Registers a listener to receive tunnel mode enabled updates from SurfaceFlinger. - * - * Requires ACCESS_SURFACE_FLINGER permission. - */ - virtual status_t addTunnelModeEnabledListener( - const sp<gui::ITunnelModeEnabledListener>& listener) = 0; - - /* - * Removes a listener that was receiving tunnel mode enabled updates from SurfaceFlinger. - * - * Requires ACCESS_SURFACE_FLINGER permission. - */ - virtual status_t removeTunnelModeEnabledListener( - const sp<gui::ITunnelModeEnabledListener>& listener) = 0; - /* Sets the refresh rate boundaries for the display. * * The primary refresh rate range represents display manager's general guidance on the display - * modes we'll consider when switching refresh rates. Unless we get an explicit signal from an + * configs we'll consider when switching refresh rates. Unless we get an explicit signal from an * app, we should stay within this range. * - * The app request refresh rate range allows us to consider more display modes when switching + * The app request refresh rate range allows us to consider more display configs when switching * refresh rates. Although we should generally stay within the primary range, specific * considerations, such as layer frame rate settings specified via the setFrameRate() api, may * cause us to go outside the primary range. We never go outside the app request range. The app * request range will be greater than or equal to the primary refresh rate range, never smaller. * - * defaultMode is used to narrow the list of display modes SurfaceFlinger will consider - * switching between. Only modes with a mode group and resolution matching defaultMode - * will be considered for switching. The defaultMode corresponds to an ID of mode in the list - * of supported modes returned from getDynamicDisplayInfo(). - */ - virtual status_t setDesiredDisplayModeSpecs( - const sp<IBinder>& displayToken, ui::DisplayModeId defaultMode, - bool allowGroupSwitching, float primaryRefreshRateMin, float primaryRefreshRateMax, - float appRequestRefreshRateMin, float appRequestRefreshRateMax) = 0; - - virtual status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, - ui::DisplayModeId* outDefaultMode, - bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax) = 0; + * defaultConfig is used to narrow the list of display configs SurfaceFlinger will consider + * switching between. Only configs with a config group and resolution matching defaultConfig + * will be considered for switching. The defaultConfig index corresponds to the list of configs + * returned from getDisplayConfigs(). + */ + virtual status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, + int32_t defaultConfig, + float primaryRefreshRateMin, + float primaryRefreshRateMax, + float appRequestRefreshRateMin, + float appRequestRefreshRateMax) = 0; + + virtual status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, + int32_t* outDefaultConfig, + float* outPrimaryRefreshRateMin, + float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, + float* outAppRequestRefreshRateMax) = 0; /* * Gets whether brightness operations are supported on a display. * @@ -443,44 +485,25 @@ public: * displayToken * The token of the display whose brightness is set. * brightness - * The DisplayBrightness info to set on the desired display. + * A number between 0.0f (minimum brightness) and 1.0 (maximum brightness), or -1.0f to + * turn the backlight off. * * Returns NO_ERROR upon success. Otherwise, * NAME_NOT_FOUND if the display is invalid, or * BAD_VALUE if the brightness is invalid, or * INVALID_OPERATION if brightness operations are not supported. */ - virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, - const gui::DisplayBrightness& brightness) = 0; - - /* - * Adds a listener that receives HDR layer information. This is used in combination - * with setDisplayBrightness to adjust the display brightness depending on factors such - * as whether or not HDR is in use. - * - * Returns NO_ERROR upon success or NAME_NOT_FOUND if the display is invalid. - */ - virtual status_t addHdrLayerInfoListener(const sp<IBinder>& displayToken, - const sp<gui::IHdrLayerInfoListener>& listener) = 0; - /* - * Removes a listener that was added with addHdrLayerInfoListener. - * - * Returns NO_ERROR upon success, NAME_NOT_FOUND if the display is invalid, and BAD_VALUE if - * the listener wasn't registered. - * - */ - virtual status_t removeHdrLayerInfoListener(const sp<IBinder>& displayToken, - const sp<gui::IHdrLayerInfoListener>& listener) = 0; + virtual status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness) = 0; /* - * Sends a power boost to the composer. This function is asynchronous. + * Sends a power hint to the composer. This function is asynchronous. * - * boostId - * boost id according to android::hardware::power::Boost + * hintId + * hint id according to android::hardware::power::V1_0::PowerHint * * Returns NO_ERROR upon success. */ - virtual status_t notifyPowerBoost(int32_t boostId) = 0; + virtual status_t notifyPowerHint(int32_t hintId) = 0; /* * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows @@ -508,7 +531,7 @@ public: * Sets the intended frame rate for a surface. See ANativeWindow_setFrameRate() for more info. */ virtual status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate, - int8_t compatibility, int8_t changeFrameRateStrategy) = 0; + int8_t compatibility) = 0; /* * Acquire a frame rate flexibility token from SurfaceFlinger. While this token is acquired, @@ -517,41 +540,6 @@ public: * for tests. Release the token by releasing the returned IBinder reference. */ virtual status_t acquireFrameRateFlexibilityToken(sp<IBinder>* outToken) = 0; - - /* - * Sets the frame timeline vsync info received from choreographer that corresponds to next - * buffer submitted on that surface. - */ - virtual status_t setFrameTimelineInfo(const sp<IGraphicBufferProducer>& surface, - const FrameTimelineInfo& frameTimelineInfo) = 0; - - /* - * Adds a TransactionTraceListener to listen for transaction tracing state updates. - */ - virtual status_t addTransactionTraceListener( - const sp<gui::ITransactionTraceListener>& listener) = 0; - - /** - * Gets priority of the RenderEngine in SurfaceFlinger. - */ - virtual int getGPUContextPriority() = 0; - - /** - * Gets the number of buffers SurfaceFlinger would need acquire. This number - * would be propagated to the client via MIN_UNDEQUEUED_BUFFERS so that the - * client could allocate enough buffers to match SF expectations of the - * pipeline depth. SurfaceFlinger will make sure that it will give the app at - * least the time configured as the 'appDuration' before trying to latch - * the buffer. - * - * The total buffers needed for a given configuration is basically the - * numbers of vsyncs a single buffer is used across the stack. For the default - * configuration a buffer is held ~1 vsync by the app, ~1 vsync by SurfaceFlinger - * and 1 vsync by the display. The extra buffers are calculated as the - * number of additional buffers on top of the 2 buffers already present - * in MIN_UNDEQUEUED_BUFFERS. - */ - virtual status_t getMaxAcquiredBufferCount(int* buffers) const = 0; }; // ---------------------------------------------------------------------------- @@ -563,7 +551,7 @@ public: // Java by ActivityManagerService. BOOT_FINISHED = IBinder::FIRST_CALL_TRANSACTION, CREATE_CONNECTION, - GET_STATIC_DISPLAY_INFO, + GET_DISPLAY_INFO, CREATE_DISPLAY_EVENT_CONNECTION, CREATE_DISPLAY, DESTROY_DISPLAY, @@ -571,18 +559,18 @@ public: SET_TRANSACTION_STATE, AUTHENTICATE_SURFACE, GET_SUPPORTED_FRAME_TIMESTAMPS, - GET_DISPLAY_MODES, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. - GET_ACTIVE_DISPLAY_MODE, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. + GET_DISPLAY_CONFIGS, + GET_ACTIVE_CONFIG, GET_DISPLAY_STATE, - CAPTURE_DISPLAY, + CAPTURE_SCREEN, CAPTURE_LAYERS, CLEAR_ANIMATION_FRAME_STATS, GET_ANIMATION_FRAME_STATS, SET_POWER_MODE, GET_DISPLAY_STATS, - GET_HDR_CAPABILITIES, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. - GET_DISPLAY_COLOR_MODES, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. - GET_ACTIVE_COLOR_MODE, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. + GET_HDR_CAPABILITIES, + GET_DISPLAY_COLOR_MODES, + GET_ACTIVE_COLOR_MODE, SET_ACTIVE_COLOR_MODE, ENABLE_VSYNC_INJECTIONS, INJECT_VSYNC, @@ -598,32 +586,19 @@ public: GET_PHYSICAL_DISPLAY_IDS, ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, - SET_DESIRED_DISPLAY_MODE_SPECS, - GET_DESIRED_DISPLAY_MODE_SPECS, + SET_DESIRED_DISPLAY_CONFIG_SPECS, + GET_DESIRED_DISPLAY_CONFIG_SPECS, GET_DISPLAY_BRIGHTNESS_SUPPORT, SET_DISPLAY_BRIGHTNESS, - CAPTURE_DISPLAY_BY_ID, - NOTIFY_POWER_BOOST, + CAPTURE_SCREEN_BY_ID, + NOTIFY_POWER_HINT, SET_GLOBAL_SHADOW_SETTINGS, - GET_AUTO_LOW_LATENCY_MODE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. + GET_AUTO_LOW_LATENCY_MODE_SUPPORT, SET_AUTO_LOW_LATENCY_MODE, - GET_GAME_CONTENT_TYPE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. + GET_GAME_CONTENT_TYPE_SUPPORT, SET_GAME_CONTENT_TYPE, SET_FRAME_RATE, ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, - SET_FRAME_TIMELINE_INFO, - ADD_TRANSACTION_TRACE_LISTENER, - GET_GPU_CONTEXT_PRIORITY, - GET_MAX_ACQUIRED_BUFFER_COUNT, - GET_DYNAMIC_DISPLAY_INFO, - ADD_FPS_LISTENER, - REMOVE_FPS_LISTENER, - OVERRIDE_HDR_TYPES, - ADD_HDR_LAYER_INFO_LISTENER, - REMOVE_HDR_LAYER_INFO_LISTENER, - ON_PULL_ATOM, - ADD_TUNNEL_MODE_ENABLED_LISTENER, - REMOVE_TUNNEL_MODE_ENABLED_LISTENER, // Always append new enum to the end. }; diff --git a/libs/gui/include/gui/ISurfaceComposerClient.h b/libs/gui/include/gui/ISurfaceComposerClient.h index 9e9e191480..3afbabf1dc 100644 --- a/libs/gui/include/gui/ISurfaceComposerClient.h +++ b/libs/gui/include/gui/ISurfaceComposerClient.h @@ -36,7 +36,6 @@ public: enum { // (keep in sync with SurfaceControl.java) eHidden = 0x00000004, eDestroyBackbuffer = 0x00000020, - eSkipScreenshot = 0x00000040, eSecure = 0x00000080, eNonPremultiplied = 0x00000100, eOpaque = 0x00000400, @@ -52,15 +51,13 @@ public: eFXSurfaceMask = 0x000F0000, }; - // TODO(b/172002646): Clean up the Surface Creation Arguments /* * Requires ACCESS_SURFACE_FLINGER permission */ virtual status_t createSurface(const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, const sp<IBinder>& parent, LayerMetadata metadata, sp<IBinder>* handle, - sp<IGraphicBufferProducer>* gbp, int32_t* outLayerId, - uint32_t* outTransformHint) = 0; + sp<IGraphicBufferProducer>* gbp, uint32_t* outTransformHint) = 0; /* * Requires ACCESS_SURFACE_FLINGER permission @@ -69,7 +66,7 @@ public: PixelFormat format, uint32_t flags, const sp<IGraphicBufferProducer>& parent, LayerMetadata metadata, sp<IBinder>* handle, - sp<IGraphicBufferProducer>* gbp, int32_t* outLayerId, + sp<IGraphicBufferProducer>* gbp, uint32_t* outTransformHint) = 0; /* @@ -82,8 +79,7 @@ public: */ virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const = 0; - virtual status_t mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle, - int32_t* outLayerId) = 0; + virtual status_t mirrorSurface(const sp<IBinder>& mirrorFromHandle, sp<IBinder>* outHandle) = 0; }; class BnSurfaceComposerClient : public SafeBnInterface<ISurfaceComposerClient> { diff --git a/libs/gui/include/gui/ITransactionCompletedListener.h b/libs/gui/include/gui/ITransactionCompletedListener.h index 937095c543..c58634b8a2 100644 --- a/libs/gui/include/gui/ITransactionCompletedListener.h +++ b/libs/gui/include/gui/ITransactionCompletedListener.h @@ -16,8 +16,6 @@ #pragma once -#include "JankInfo.h" - #include <binder/IInterface.h> #include <binder/Parcel.h> #include <binder/Parcelable.h> @@ -36,52 +34,7 @@ namespace android { class ITransactionCompletedListener; class ListenerCallbacks; -class CallbackId : public Parcelable { -public: - int64_t id; - enum class Type : int32_t { ON_COMPLETE, ON_COMMIT } type; - - CallbackId() {} - CallbackId(int64_t id, Type type) : id(id), type(type) {} - status_t writeToParcel(Parcel* output) const override; - status_t readFromParcel(const Parcel* input) override; - - bool operator==(const CallbackId& rhs) const { return id == rhs.id && type == rhs.type; } -}; - -struct CallbackIdHash { - std::size_t operator()(const CallbackId& key) const { return std::hash<int64_t>()(key.id); } -}; - -class ReleaseCallbackId : public Parcelable { -public: - static const ReleaseCallbackId INVALID_ID; - - uint64_t bufferId; - uint64_t framenumber; - ReleaseCallbackId() {} - ReleaseCallbackId(uint64_t bufferId, uint64_t framenumber) - : bufferId(bufferId), framenumber(framenumber) {} - status_t writeToParcel(Parcel* output) const override; - status_t readFromParcel(const Parcel* input) override; - - bool operator==(const ReleaseCallbackId& rhs) const { - return bufferId == rhs.bufferId && framenumber == rhs.framenumber; - } - bool operator!=(const ReleaseCallbackId& rhs) const { return !operator==(rhs); } - std::string to_string() const { - if (*this == INVALID_ID) return "INVALID_ID"; - - return "bufferId:" + std::to_string(bufferId) + - " framenumber:" + std::to_string(framenumber); - } -}; - -struct ReleaseBufferCallbackIdHash { - std::size_t operator()(const ReleaseCallbackId& key) const { - return std::hash<uint64_t>()(key.bufferId); - } -}; +using CallbackId = int64_t; class FrameEventHistoryStats : public Parcelable { public: @@ -104,26 +57,6 @@ public: nsecs_t dequeueReadyTime; }; -/** - * Jank information representing SurfaceFlinger's jank classification about frames for a specific - * surface. - */ -class JankData : public Parcelable { -public: - status_t writeToParcel(Parcel* output) const override; - status_t readFromParcel(const Parcel* input) override; - - JankData(); - JankData(int64_t frameVsyncId, int32_t jankType) - : frameVsyncId(frameVsyncId), jankType(jankType) {} - - // Identifier for the frame submitted with Transaction.setFrameTimelineVsyncId - int64_t frameVsyncId; - - // Bitmask of janks that occurred - int32_t jankType; -}; - class SurfaceStats : public Parcelable { public: status_t writeToParcel(Parcel* output) const override; @@ -131,26 +64,18 @@ public: SurfaceStats() = default; SurfaceStats(const sp<IBinder>& sc, nsecs_t time, const sp<Fence>& prevReleaseFence, - uint32_t hint, uint32_t currentMaxAcquiredBuffersCount, - FrameEventHistoryStats frameEventStats, std::vector<JankData> jankData, - ReleaseCallbackId previousReleaseCallbackId) + uint32_t hint, FrameEventHistoryStats frameEventStats) : surfaceControl(sc), acquireTime(time), previousReleaseFence(prevReleaseFence), transformHint(hint), - currentMaxAcquiredBufferCount(currentMaxAcquiredBuffersCount), - eventStats(frameEventStats), - jankData(std::move(jankData)), - previousReleaseCallbackId(previousReleaseCallbackId) {} + eventStats(frameEventStats) {} sp<IBinder> surfaceControl; nsecs_t acquireTime = -1; sp<Fence> previousReleaseFence; uint32_t transformHint = 0; - uint32_t currentMaxAcquiredBufferCount = 0; FrameEventHistoryStats eventStats; - std::vector<JankData> jankData; - ReleaseCallbackId previousReleaseCallbackId; }; class TransactionStats : public Parcelable { @@ -160,7 +85,7 @@ public: TransactionStats() = default; TransactionStats(const std::vector<CallbackId>& ids) : callbackIds(ids) {} - TransactionStats(const std::unordered_set<CallbackId, CallbackIdHash>& ids) + TransactionStats(const std::unordered_set<CallbackId>& ids) : callbackIds(ids.begin(), ids.end()) {} TransactionStats(const std::vector<CallbackId>& ids, nsecs_t latch, const sp<Fence>& present, const std::vector<SurfaceStats>& surfaces) @@ -177,9 +102,8 @@ public: status_t writeToParcel(Parcel* output) const override; status_t readFromParcel(const Parcel* input) override; - static ListenerStats createEmpty( - const sp<IBinder>& listener, - const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds); + static ListenerStats createEmpty(const sp<IBinder>& listener, + const std::unordered_set<CallbackId>& callbackIds); sp<IBinder> listener; std::vector<TransactionStats> transactionStats; @@ -190,10 +114,6 @@ public: DECLARE_META_INTERFACE(TransactionCompletedListener) virtual void onTransactionCompleted(ListenerStats stats) = 0; - - virtual void onReleaseBuffer(ReleaseCallbackId callbackId, sp<Fence> releaseFence, - uint32_t transformHint, - uint32_t currentMaxAcquiredBufferCount) = 0; }; class BnTransactionCompletedListener : public SafeBnInterface<ITransactionCompletedListener> { @@ -207,8 +127,7 @@ public: class ListenerCallbacks { public: - ListenerCallbacks(const sp<IBinder>& listener, - const std::unordered_set<CallbackId, CallbackIdHash>& callbacks) + ListenerCallbacks(const sp<IBinder>& listener, const std::unordered_set<CallbackId>& callbacks) : transactionCompletedListener(listener), callbackIds(callbacks.begin(), callbacks.end()) {} @@ -222,12 +141,9 @@ public: if (callbackIds.empty()) { return rhs.callbackIds.empty(); } - return callbackIds.front().id == rhs.callbackIds.front().id; + return callbackIds.front() == rhs.callbackIds.front(); } - // Returns a new ListenerCallbacks filtered by type - ListenerCallbacks filter(CallbackId::Type type) const; - sp<IBinder> transactionCompletedListener; std::vector<CallbackId> callbackIds; }; @@ -246,7 +162,7 @@ struct CallbackIdsHash { // same members. It is sufficient to just check the first CallbackId in the vectors. If // they match, they are the same. If they do not match, they are not the same. std::size_t operator()(const std::vector<CallbackId>& callbackIds) const { - return std::hash<int64_t>{}((callbackIds.empty()) ? 0 : callbackIds.front().id); + return std::hash<CallbackId>{}((callbackIds.empty()) ? 0 : callbackIds.front()); } }; diff --git a/libs/gui/include/gui/JankInfo.h b/libs/gui/include/gui/JankInfo.h deleted file mode 100644 index ce9716f1fe..0000000000 --- a/libs/gui/include/gui/JankInfo.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020 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 - -namespace android { - -// Jank information tracked by SurfaceFlinger(SF) for perfetto tracing and telemetry. -enum JankType { - // No Jank - None = 0x0, - // Jank that occurs in the layers below SurfaceFlinger - DisplayHAL = 0x1, - // SF took too long on the CPU - SurfaceFlingerCpuDeadlineMissed = 0x2, - // SF took too long on the GPU - SurfaceFlingerGpuDeadlineMissed = 0x4, - // Either App or GPU took too long on the frame - AppDeadlineMissed = 0x8, - // Vsync predictions have drifted beyond the threshold from the actual HWVsync - PredictionError = 0x10, - // Janks caused due to the time SF was scheduled to work on the frame - // Example: SF woke up too early and latched a buffer resulting in an early present - SurfaceFlingerScheduling = 0x20, - // A buffer is said to be stuffed if it was expected to be presented on a vsync but was - // presented later because the previous buffer was presented in its expected vsync. This - // usually happens if there is an unexpectedly long frame causing the rest of the buffers - // to enter a stuffed state. - BufferStuffing = 0x40, - // Jank due to unknown reasons. - Unknown = 0x80, - // SF is said to be stuffed if the previous frame ran longer than expected resulting in the case - // where the previous frame was presented in the current frame's expected vsync. This pushes the - // current frame to the next vsync. The behavior is similar to BufferStuffing. - SurfaceFlingerStuffing = 0x100, -}; - -} // namespace android diff --git a/libs/gui/include/gui/LayerDebugInfo.h b/libs/gui/include/gui/LayerDebugInfo.h index 8b7d32c0a5..66a7b4dc06 100644 --- a/libs/gui/include/gui/LayerDebugInfo.h +++ b/libs/gui/include/gui/LayerDebugInfo.h @@ -20,7 +20,6 @@ #include <ui/PixelFormat.h> #include <ui/Region.h> -#include <ui/StretchEffect.h> #include <string> #include <math/vec4.h> @@ -67,7 +66,6 @@ public: bool mRefreshPending = false; bool mIsOpaque = false; bool mContentDirty = false; - StretchEffect mStretchEffect = {}; }; std::string to_string(const LayerDebugInfo& info); diff --git a/libs/gui/include/gui/LayerMetadata.h b/libs/gui/include/gui/LayerMetadata.h index de14b3d785..d58e019799 100644 --- a/libs/gui/include/gui/LayerMetadata.h +++ b/libs/gui/include/gui/LayerMetadata.h @@ -27,10 +27,6 @@ enum { METADATA_WINDOW_TYPE = 2, METADATA_TASK_ID = 3, METADATA_MOUSE_CURSOR = 4, - METADATA_ACCESSIBILITY_ID = 5, - METADATA_OWNER_PID = 6, - METADATA_DEQUEUE_TIME = 7, - METADATA_GAME_MODE = 8 }; struct LayerMetadata : public Parcelable { @@ -53,8 +49,6 @@ struct LayerMetadata : public Parcelable { bool has(uint32_t key) const; int32_t getInt32(uint32_t key, int32_t fallback) const; void setInt32(uint32_t key, int32_t value); - std::optional<int64_t> getInt64(uint32_t key) const; - void setInt64(uint32_t key, int64_t value); std::string itemToString(uint32_t key, const char* separator) const; }; diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 3e57ff611e..a77e4b0462 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -17,7 +17,6 @@ #ifndef ANDROID_SF_LAYER_STATE_H #define ANDROID_SF_LAYER_STATE_H - #include <stdint.h> #include <sys/types.h> @@ -27,20 +26,15 @@ #include <math/mat4.h> #ifndef NO_INPUT -#include <android/FocusRequest.h> #include <input/InputWindow.h> #endif -#include <gui/ISurfaceComposer.h> #include <gui/LayerMetadata.h> -#include <gui/SurfaceControl.h> #include <math/vec3.h> -#include <ui/BlurRegion.h> #include <ui/GraphicTypes.h> #include <ui/Rect.h> #include <ui/Region.h> #include <ui/Rotation.h> -#include <ui/StretchEffect.h> #include <ui/Transform.h> #include <utils/Errors.h> @@ -63,14 +57,9 @@ struct client_cache_t { */ struct layer_state_t { enum { - eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java - eLayerOpaque = 0x02, // SURFACE_OPAQUE - eLayerSkipScreenshot = 0x40, // SKIP_SCREENSHOT - eLayerSecure = 0x80, // SECURE - // Queue up BufferStateLayer buffers instead of dropping the oldest buffer when this flag is - // set. This blocks the client until all the buffers have been presented. If the buffers - // have presentation timestamps, then we may drop buffers. - eEnableBackpressure = 0x100, // ENABLE_BACKPRESSURE + eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java + eLayerOpaque = 0x02, // SURFACE_OPAQUE + eLayerSecure = 0x80, // SECURE }; enum { @@ -82,10 +71,12 @@ struct layer_state_t { eTransparentRegionChanged = 0x00000020, eFlagsChanged = 0x00000040, eLayerStackChanged = 0x00000080, - eReleaseBufferListenerChanged = 0x00000400, + eCropChanged_legacy = 0x00000100, + eDeferTransaction_legacy = 0x00000200, + eOverrideScalingModeChanged = 0x00000400, eShadowRadiusChanged = 0x00000800, - eLayerCreated = 0x00001000, - eBufferCropChanged = 0x00002000, + eReparentChildren = 0x00001000, + eDetachChildren = 0x00002000, eRelativeLayerChanged = 0x00004000, eReparent = 0x00008000, eColorChanged = 0x00010000, @@ -104,7 +95,7 @@ struct layer_state_t { eHasListenerCallbacksChanged = 0x20000000, eInputInfoChanged = 0x40000000, eCornerRadiusChanged = 0x80000000, - eDestinationFrameChanged = 0x1'00000000, + eFrameChanged = 0x1'00000000, eCachedBufferChanged = 0x2'00000000, eBackgroundColorChanged = 0x4'00000000, eMetadataChanged = 0x8'00000000, @@ -114,31 +105,59 @@ struct layer_state_t { eBackgroundBlurRadiusChanged = 0x80'00000000, eProducerDisconnect = 0x100'00000000, eFixedTransformHintChanged = 0x200'00000000, - eFrameNumberChanged = 0x400'00000000, - eBlurRegionsChanged = 0x800'00000000, - eAutoRefreshChanged = 0x1000'00000000, - eStretchChanged = 0x2000'00000000, - eTrustedOverlayChanged = 0x4000'00000000, + eTrustedOverlayChanged = 0x400'00000000, }; - layer_state_t(); + layer_state_t() + : what(0), + x(0), + y(0), + z(0), + w(0), + h(0), + layerStack(0), + alpha(0), + flags(0), + mask(0), + reserved(0), + crop_legacy(Rect::INVALID_RECT), + cornerRadius(0.0f), + backgroundBlurRadius(0), + frameNumber_legacy(0), + overrideScalingMode(-1), + transform(0), + transformToDisplayInverse(false), + crop(Rect::INVALID_RECT), + frame(Rect::INVALID_RECT), + dataspace(ui::Dataspace::UNKNOWN), + surfaceDamageRegion(), + api(-1), + colorTransform(mat4()), + bgColorAlpha(0), + bgColorDataspace(ui::Dataspace::UNKNOWN), + colorSpaceAgnostic(false), + shadowRadius(0.0f), + frameRateSelectionPriority(-1), + frameRate(0.0f), + frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT), + fixedTransformHint(ui::Transform::ROT_INVALID), + isTrustedOverlay(false) { + matrix.dsdx = matrix.dtdy = 1.0f; + matrix.dsdy = matrix.dtdx = 0.0f; + hdrMetadata.validTypes = 0; + } void merge(const layer_state_t& other); status_t write(Parcel& output) const; status_t read(const Parcel& input); - bool hasBufferChanges() const; - bool hasValidBuffer() const; struct matrix22_t { float dsdx{0}; float dtdx{0}; float dtdy{0}; float dsdy{0}; - status_t write(Parcel& output) const; - status_t read(const Parcel& input); }; sp<IBinder> surface; - int32_t layerId; uint64_t what; float x; float y; @@ -147,17 +166,23 @@ struct layer_state_t { uint32_t h; uint32_t layerStack; float alpha; - uint32_t flags; - uint32_t mask; + uint8_t flags; + uint8_t mask; uint8_t reserved; matrix22_t matrix; + Rect crop_legacy; float cornerRadius; uint32_t backgroundBlurRadius; - sp<SurfaceControl> reparentSurfaceControl; + sp<IBinder> barrierHandle_legacy; + sp<IBinder> reparentHandle; + uint64_t frameNumber_legacy; + int32_t overrideScalingMode; + + sp<IGraphicBufferProducer> barrierGbp_legacy; - sp<SurfaceControl> relativeLayerSurfaceControl; + sp<IBinder> relativeLayerHandle; - sp<SurfaceControl> parentSurfaceControlForChild; + sp<IBinder> parentHandleForChild; half3 color; @@ -167,7 +192,7 @@ struct layer_state_t { uint32_t transform; bool transformToDisplayInverse; Rect crop; - Rect orientedDisplaySpaceRect; + Rect frame; sp<GraphicBuffer> buffer; sp<Fence> acquireFence; ui::Dataspace dataspace; @@ -176,10 +201,9 @@ struct layer_state_t { int32_t api; sp<NativeHandle> sidebandStream; mat4 colorTransform; - std::vector<BlurRegion> blurRegions; #ifndef NO_INPUT - sp<InputWindowHandle> inputHandle = new InputWindowHandle(); + InputWindowInfo inputInfo; #endif client_cache_t cachedBuffer; @@ -206,7 +230,6 @@ struct layer_state_t { // Layer frame rate and compatibility. See ANativeWindow_setFrameRate(). float frameRate; int8_t frameRateCompatibility; - int8_t changeFrameRateStrategy; // Set by window manager indicating the layer and all its children are // in a different orientation than the display. The hint suggests that @@ -217,35 +240,9 @@ struct layer_state_t { // otherwise the value will be a valid ui::Rotation. ui::Transform::RotationFlags fixedTransformHint; - // Used by BlastBufferQueue to forward the framenumber generated by the - // graphics producer. - uint64_t frameNumber; - - // Indicates that the consumer should acquire the next frame as soon as it - // can and not wait for a frame to become available. This is only relevant - // in shared buffer mode. - bool autoRefresh; - // An inherited state that indicates that this surface control and its children // should be trusted for input occlusion detection purposes bool isTrustedOverlay; - - // Stretch effect to be applied to this layer - StretchEffect stretchEffect; - - Rect bufferCrop; - Rect destinationFrame; - - // Listens to when the buffer is safe to be released. This is used for blast - // layers only. The callback includes a release fence as well as the graphic - // buffer id to identify the buffer. - sp<ITransactionCompletedListener> releaseBufferListener; - - // Keeps track of the release callback id associated with the listener. This - // is not sent to the server since the id can be reconstructed there. This - // is used to remove the old callback from the client process map if it is - // overwritten by another setBuffer call. - ReleaseCallbackId releaseCallbackId; }; struct ComposerState { @@ -272,18 +269,18 @@ struct DisplayState { // These states define how layers are projected onto the physical display. // - // Layers are first clipped to `layerStackSpaceRect'. They are then translated and - // scaled from `layerStackSpaceRect' to `orientedDisplaySpaceRect'. Finally, they are rotated - // according to `orientation', `width', and `height'. + // Layers are first clipped to `viewport'. They are then translated and + // scaled from `viewport' to `frame'. Finally, they are rotated according + // to `orientation', `width', and `height'. // - // For example, assume layerStackSpaceRect is Rect(0, 0, 200, 100), orientedDisplaySpaceRect is - // Rect(20, 10, 420, 210), and the size of the display is WxH. When orientation is 0, layers - // will be scaled by a factor of 2 and translated by (20, 10). When orientation is 1, layers - // will be additionally rotated by 90 degrees around the origin clockwise and translated by (W, - // 0). + // For example, assume viewport is Rect(0, 0, 200, 100), frame is Rect(20, + // 10, 420, 210), and the size of the display is WxH. When orientation is + // 0, layers will be scaled by a factor of 2 and translated by (20, 10). + // When orientation is 1, layers will be additionally rotated by 90 + // degrees around the origin clockwise and translated by (W, 0). ui::Rotation orientation = ui::ROTATION_0; - Rect layerStackSpaceRect; - Rect orientedDisplaySpaceRect; + Rect viewport; + Rect frame; uint32_t width, height; @@ -292,17 +289,12 @@ struct DisplayState { }; struct InputWindowCommands { -#ifndef NO_INPUT - std::vector<FocusRequest> focusRequests; -#endif bool syncInputWindows{false}; - // Merges the passed in commands and returns true if there were any changes. - bool merge(const InputWindowCommands& other); - bool empty() const; + void merge(const InputWindowCommands& other); void clear(); - status_t write(Parcel& output) const; - status_t read(const Parcel& input); + void write(Parcel& output) const; + void read(const Parcel& input); }; static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { @@ -315,65 +307,11 @@ static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) return compare_type(lhs.token, rhs.token); } -// Returns true if the frameRate is valid. -// -// @param frameRate the frame rate in Hz -// @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* -// @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_* -// @param functionName calling function or nullptr. Used for logging -// @param privileged whether caller has unscoped surfaceflinger access -bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, - const char* functionName, bool privileged = false); - -struct CaptureArgs { - const static int32_t UNSET_UID = -1; - virtual ~CaptureArgs() = default; - - ui::PixelFormat pixelFormat{ui::PixelFormat::RGBA_8888}; - Rect sourceCrop; - float frameScaleX{1}; - float frameScaleY{1}; - bool captureSecureLayers{false}; - int32_t uid{UNSET_UID}; - // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured - // result will be in the display's colorspace. - // The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be - // different from SRGB (byte per color), and failed when checking colors in tests. - // NOTE: In normal cases, we want the screen to be captured in display's colorspace. - ui::Dataspace dataspace = ui::Dataspace::UNKNOWN; - - // The receiver of the capture can handle protected buffer. A protected buffer has - // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour. - // Any read/write access from unprotected context will result in undefined behaviour. - // Protected contents are typically DRM contents. This has no direct implication to the - // secure property of the surface, which is specified by the application explicitly to avoid - // the contents being accessed/captured by screenshot or unsecure display. - bool allowProtected = false; - - bool grayscale = false; - - virtual status_t write(Parcel& output) const; - virtual status_t read(const Parcel& input); -}; - -struct DisplayCaptureArgs : CaptureArgs { - sp<IBinder> displayToken; - uint32_t width{0}; - uint32_t height{0}; - bool useIdentityTransform{false}; - - status_t write(Parcel& output) const override; - status_t read(const Parcel& input) override; -}; - -struct LayerCaptureArgs : CaptureArgs { - sp<IBinder> layerHandle; - std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeHandles; - bool childrenOnly{false}; - - status_t write(Parcel& output) const override; - status_t read(const Parcel& input) override; -}; +// Returns true if the frameRate and compatibility are valid values, false +// othwerise. If either of the params are invalid, an error log is printed, and +// functionName is added to the log to indicate which function call failed. +// functionName can be null. +bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* functionName); }; // namespace android diff --git a/libs/gui/include/gui/ScreenCaptureResults.h b/libs/gui/include/gui/ScreenCaptureResults.h deleted file mode 100644 index 99c35c1a3d..0000000000 --- a/libs/gui/include/gui/ScreenCaptureResults.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2021 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 <binder/Parcel.h> -#include <binder/Parcelable.h> -#include <ui/Fence.h> -#include <ui/GraphicBuffer.h> - -namespace android::gui { - -struct ScreenCaptureResults : public Parcelable { -public: - ScreenCaptureResults() = default; - virtual ~ScreenCaptureResults() = default; - status_t writeToParcel(android::Parcel* parcel) const override; - status_t readFromParcel(const android::Parcel* parcel) override; - - sp<GraphicBuffer> buffer; - sp<Fence> fence = Fence::NO_FENCE; - bool capturedSecureLayers{false}; - ui::Dataspace capturedDataspace{ui::Dataspace::V0_SRGB}; - status_t result = OK; -}; - -} // namespace android::gui diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index e5403512a9..49c83da319 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -18,7 +18,6 @@ #define ANDROID_GUI_SURFACE_H #include <gui/BufferQueueDefs.h> -#include <gui/FrameTimelineInfo.h> #include <gui/HdrMetadata.h> #include <gui/IGraphicBufferProducer.h> #include <gui/IProducerListener.h> @@ -31,7 +30,6 @@ #include <utils/RefBase.h> #include <shared_mutex> -#include <unordered_set> namespace android { @@ -69,6 +67,7 @@ class Surface : public ANativeObjectBase<ANativeWindow, Surface, RefBase> { public: + /* * creates a Surface from the given IGraphicBufferProducer (which concrete * implementation is a BufferQueue). @@ -83,15 +82,9 @@ public: * * the controlledByApp flag indicates that this Surface (producer) is * controlled by the application. This flag is used at connect time. - * - * Pass in the SurfaceControlHandle to store a weak reference to the layer - * that the Surface was created from. This handle can be used to create a - * child surface without using the IGBP to identify the layer. This is used - * for surfaces created by the BlastBufferQueue whose IGBP is created on the - * client and cannot be verified in SF. */ - explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false, - const sp<IBinder>& surfaceControlHandle = nullptr); + explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, + bool controlledByApp = false); /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this * Surface was created with. Usually it's an error to use the @@ -99,8 +92,6 @@ public: */ sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; - sp<IBinder> getSurfaceControlHandle() const; - /* convenience function to check that the given surface is non NULL as * well as its IGraphicBufferProducer */ static bool isValid(const sp<Surface>& surface) { @@ -128,7 +119,7 @@ public: * delay during dequeueBuffer. If there are already the maximum number of * buffers allocated, this function has no effect. */ - virtual void allocateBuffers(); + void allocateBuffers(); /* Sets the generation number on the IGraphicBufferProducer and updates the * generation number on any buffers attached to the Surface after this call. @@ -187,9 +178,7 @@ public: status_t getUniqueId(uint64_t* outId) const; status_t getConsumerUsage(uint64_t* outUsage) const; - virtual status_t setFrameRate(float frameRate, int8_t compatibility, - int8_t changeFrameRateStrategy); - virtual status_t setFrameTimelineInfo(const FrameTimelineInfo& info); + status_t setFrameRate(float frameRate, int8_t compatibility); protected: virtual ~Surface(); @@ -275,8 +264,7 @@ private: int dispatchAddQueueInterceptor(va_list args); int dispatchAddQueryInterceptor(va_list args); int dispatchGetLastQueuedBuffer(va_list args); - int dispatchGetLastQueuedBuffer2(va_list args); - int dispatchSetFrameTimelineInfo(va_list args); + bool transformToDisplayInverse(); protected: virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd); @@ -333,7 +321,6 @@ public: virtual int connect( int api, bool reportBufferRemoval, const sp<SurfaceListener>& sListener); - virtual void destroy(); // When client connects to Surface with reportBufferRemoval set to true, any buffers removed // from this Surface will be collected and returned here. Once this method returns, these @@ -347,23 +334,6 @@ public: static status_t attachAndQueueBufferWithDataspace(Surface* surface, sp<GraphicBuffer> buffer, ui::Dataspace dataspace); - // Batch version of dequeueBuffer, cancelBuffer and queueBuffer - // Note that these batched operations are not supported when shared buffer mode is being used. - struct BatchBuffer { - ANativeWindowBuffer* buffer = nullptr; - int fenceFd = -1; - }; - virtual int dequeueBuffers(std::vector<BatchBuffer>* buffers); - virtual int cancelBuffers(const std::vector<BatchBuffer>& buffers); - - struct BatchQueuedBuffer { - ANativeWindowBuffer* buffer = nullptr; - int fenceFd = -1; - nsecs_t timestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; - }; - virtual int queueBuffers( - const std::vector<BatchQueuedBuffer>& buffers); - protected: enum { NUM_BUFFER_SLOTS = BufferQueueDefs::NUM_BUFFER_SLOTS }; enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; @@ -393,14 +363,6 @@ protected: void freeAllBuffers(); int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; - void getDequeueBufferInputLocked(IGraphicBufferProducer::DequeueBufferInput* dequeueInput); - - void getQueueBufferInputLocked(android_native_buffer_t* buffer, int fenceFd, nsecs_t timestamp, - IGraphicBufferProducer::QueueBufferInput* out); - - void onBufferQueuedLocked(int slot, sp<Fence> fence, - const IGraphicBufferProducer::QueueBufferOutput& output); - struct BufferSlot { sp<GraphicBuffer> buffer; Region dirtyRegion; @@ -489,8 +451,6 @@ protected: // mTransformHint is the transform probably applied to buffers of this // window. this is only a hint, actual transform may differ. uint32_t mTransformHint; - virtual uint32_t getTransformHint() const { return mTransformHint; } - bool transformToDisplayInverse() const; // mProducerControlledByApp whether this buffer producer is controlled // by the application @@ -578,25 +538,13 @@ protected: bool mEnableFrameTimestamps = false; std::unique_ptr<ProducerFrameEventHistory> mFrameEventHistory; - // Reference to the SurfaceFlinger layer that was used to create this - // surface. This is only populated when the Surface is created from - // a BlastBufferQueue. - sp<IBinder> mSurfaceControlHandle; - bool mReportRemovedBuffers = false; std::vector<sp<GraphicBuffer>> mRemovedBuffers; int mMaxBufferCount; sp<IProducerListener> mListenerProxy; - - // Get and flush the buffers of given slots, if the buffer in the slot - // is currently dequeued then it won't be flushed and won't be returned - // in outBuffers. status_t getAndFlushBuffersFromSlots(const std::vector<int32_t>& slots, std::vector<sp<GraphicBuffer>>* outBuffers); - - // Buffers that are successfully dequeued/attached and handed to clients - std::unordered_set<int> mDequeuedSlots; }; } // namespace android diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index baa0567617..eebd9ca774 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -29,7 +29,6 @@ #include <utils/SortedVector.h> #include <utils/threads.h> -#include <ui/BlurRegion.h> #include <ui/ConfigStoreTypes.h> #include <ui/DisplayedFrameStats.h> #include <ui/FrameStats.h> @@ -50,7 +49,6 @@ class HdrCapabilities; class ISurfaceComposerClient; class IGraphicBufferProducer; class IRegionSamplingListener; -class ITunnelModeEnabledListener; class Region; struct SurfaceControlStats { @@ -81,14 +79,6 @@ using TransactionCompletedCallbackTakesContext = using TransactionCompletedCallback = std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/, const std::vector<SurfaceControlStats>& /*stats*/)>; -using ReleaseBufferCallback = - std::function<void(const ReleaseCallbackId&, const sp<Fence>& /*releaseFence*/, - uint32_t transformHint, uint32_t currentMaxAcquiredBufferCount)>; - -using SurfaceStatsCallback = - std::function<void(void* /*context*/, nsecs_t /*latchTime*/, - const sp<Fence>& /*presentFence*/, - const SurfaceStats& /*stats*/)>; // --------------------------------------------------------------------------- @@ -117,42 +107,57 @@ public: static status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState*); // Get immutable information about given physical display. - static status_t getStaticDisplayInfo(const sp<IBinder>& display, ui::StaticDisplayInfo*); + static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*); + + // Get configurations supported by given physical display. + static status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*); - // Get dynamic information about given physical display. - static status_t getDynamicDisplayInfo(const sp<IBinder>& display, ui::DynamicDisplayInfo*); + // Get the ID of the active DisplayConfig, as getDisplayConfigs index. + static int getActiveConfig(const sp<IBinder>& display); - // Shorthand for the active display mode from getDynamicDisplayInfo(). - // TODO(b/180391891): Update clients to use getDynamicDisplayInfo and remove this function. - static status_t getActiveDisplayMode(const sp<IBinder>& display, ui::DisplayMode*); + // Shorthand for getDisplayConfigs element at getActiveConfig index. + static status_t getActiveDisplayConfig(const sp<IBinder>& display, DisplayConfig*); // Sets the refresh rate boundaries for the display. - static status_t setDesiredDisplayModeSpecs( - const sp<IBinder>& displayToken, ui::DisplayModeId defaultMode, - bool allowGroupSwitching, float primaryRefreshRateMin, float primaryRefreshRateMax, - float appRequestRefreshRateMin, float appRequestRefreshRateMax); + static status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, + int32_t defaultConfig, float primaryRefreshRateMin, + float primaryRefreshRateMax, + float appRequestRefreshRateMin, + float appRequestRefreshRateMax); // Gets the refresh rate boundaries for the display. - static status_t getDesiredDisplayModeSpecs(const sp<IBinder>& displayToken, - ui::DisplayModeId* outDefaultMode, - bool* outAllowGroupSwitching, - float* outPrimaryRefreshRateMin, - float* outPrimaryRefreshRateMax, - float* outAppRequestRefreshRateMin, - float* outAppRequestRefreshRateMax); + static status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, + int32_t* outDefaultConfig, + float* outPrimaryRefreshRateMin, + float* outPrimaryRefreshRateMax, + float* outAppRequestRefreshRateMin, + float* outAppRequestRefreshRateMax); + + // Gets the list of supported color modes for the given display + static status_t getDisplayColorModes(const sp<IBinder>& display, + Vector<ui::ColorMode>* outColorModes); // Get the coordinates of the display's native color primaries static status_t getDisplayNativePrimaries(const sp<IBinder>& display, ui::DisplayPrimaries& outPrimaries); + // Gets the active color mode for the given display + static ui::ColorMode getActiveColorMode(const sp<IBinder>& display); + // Sets the active color mode for the given display static status_t setActiveColorMode(const sp<IBinder>& display, ui::ColorMode colorMode); + // Reports whether the connected display supports Auto Low Latency Mode + static bool getAutoLowLatencyModeSupport(const sp<IBinder>& display); + // Switches on/off Auto Low Latency Mode on the connected display. This should only be // called if the connected display supports Auto Low Latency Mode as reported by // #getAutoLowLatencyModeSupport static void setAutoLowLatencyMode(const sp<IBinder>& display, bool on); + // Reports whether the connected display supports Game content type + static bool getGameContentTypeSupport(const sp<IBinder>& display); + // Turns Game mode on/off on the connected display. This should only be called // if the display supports Game content type, as reported by #getGameContentTypeSupport static void setGameContentType(const sp<IBinder>& display, bool on); @@ -177,11 +182,6 @@ public: static bool getProtectedContentSupport(); /** - * Gets the context priority of surface flinger's render engine. - */ - static int getGPUContextPriority(); - - /** * Uncaches a buffer in ISurfaceComposer. It must be uncached via a transaction so that it is * in order with other transactions that use buffers. */ @@ -214,23 +214,17 @@ public: * BAD_VALUE if the brightness value is invalid, or * INVALID_OPERATION if brightness operaetions are not supported. */ - static status_t setDisplayBrightness(const sp<IBinder>& displayToken, - const gui::DisplayBrightness& brightness); - - static status_t addHdrLayerInfoListener(const sp<IBinder>& displayToken, - const sp<gui::IHdrLayerInfoListener>& listener); - static status_t removeHdrLayerInfoListener(const sp<IBinder>& displayToken, - const sp<gui::IHdrLayerInfoListener>& listener); + static status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness); /* - * Sends a power boost to the composer. This function is asynchronous. + * Sends a power hint to the composer. This function is asynchronous. * - * boostId - * boost id according to android::hardware::power::Boost + * hintId + * hint id according to android::hardware::power::V1_0::PowerHint * * Returns NO_ERROR upon success. */ - static status_t notifyPowerBoost(int32_t boostId); + static status_t notifyPowerHint(int32_t hintId); /* * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows @@ -259,13 +253,13 @@ public: static sp<SurfaceComposerClient> getDefault(); //! Create a surface - sp<SurfaceControl> createSurface(const String8& name, // name of the surface - uint32_t w, // width in pixel - uint32_t h, // height in pixel - PixelFormat format, // pixel-format desired - uint32_t flags = 0, // usage flags - const sp<IBinder>& parentHandle = nullptr, // parentHandle - LayerMetadata metadata = LayerMetadata(), // metadata + sp<SurfaceControl> createSurface(const String8& name, // name of the surface + uint32_t w, // width in pixel + uint32_t h, // height in pixel + PixelFormat format, // pixel-format desired + uint32_t flags = 0, // usage flags + SurfaceControl* parent = nullptr, // parent + LayerMetadata metadata = LayerMetadata(), // metadata uint32_t* outTransformHint = nullptr); status_t createSurfaceChecked(const String8& name, // name of the surface @@ -273,9 +267,9 @@ public: uint32_t h, // height in pixel PixelFormat format, // pixel-format desired sp<SurfaceControl>* outSurface, - uint32_t flags = 0, // usage flags - const sp<IBinder>& parentHandle = nullptr, // parentHandle - LayerMetadata metadata = LayerMetadata(), // metadata + uint32_t flags = 0, // usage flags + SurfaceControl* parent = nullptr, // parent + LayerMetadata metadata = LayerMetadata(), // metadata uint32_t* outTransformHint = nullptr); //! Create a surface @@ -338,30 +332,25 @@ public: struct CallbackInfo { // All the callbacks that have been requested for a TransactionCompletedListener in the // Transaction - std::unordered_set<CallbackId, CallbackIdHash> callbackIds; + std::unordered_set<CallbackId> callbackIds; // All the SurfaceControls that have been modified in this TransactionCompletedListener's // process that require a callback if there is one or more callbackIds set. std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls; }; class Transaction : public Parcelable { - private: - static std::atomic<uint32_t> idCounter; - int64_t generateId(); - protected: std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> mComposerStates; - SortedVector<DisplayState> mDisplayStates; + SortedVector<DisplayState > mDisplayStates; std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; - uint64_t mId; - uint32_t mForceSynchronous = 0; uint32_t mTransactionNestCount = 0; bool mAnimation = false; - bool mEarlyWakeupStart = false; - bool mEarlyWakeupEnd = false; + bool mEarlyWakeup = false; + bool mExplicitEarlyWakeupStart = false; + bool mExplicitEarlyWakeupEnd = false; // Indicates that the Transaction contains a buffer that should be cached bool mContainsBuffer = false; @@ -370,39 +359,28 @@ public: // to be presented. When it is not possible to present at exactly that time, it will be // presented after the time has passed. // - // If the client didn't pass a desired presentation time, mDesiredPresentTime will be - // populated to the time setBuffer was called, and mIsAutoTimestamp will be set to true. - // // Desired present times that are more than 1 second in the future may be ignored. // When a desired present time has already passed, the transaction will be presented as soon // as possible. // // Transactions from the same process are presented in the same order that they are applied. // The desired present time does not affect this ordering. - int64_t mDesiredPresentTime = 0; - bool mIsAutoTimestamp = true; - - // The vsync id provided by Choreographer.getVsyncId and the input event id - FrameTimelineInfo mFrameTimelineInfo; - - // If not null, transactions will be queued up using this token otherwise a common token - // per process will be used. - sp<IBinder> mApplyToken = nullptr; + int64_t mDesiredPresentTime = -1; InputWindowCommands mInputWindowCommands; int mStatus = NO_ERROR; - layer_state_t* getLayerState(const sp<SurfaceControl>& sc); + layer_state_t* getLayerState(const sp<IBinder>& surfaceHandle); + layer_state_t* getLayerState(const sp<SurfaceControl>& sc) { + return getLayerState(sc->getHandle()); + } DisplayState& getDisplayState(const sp<IBinder>& token); void cacheBuffers(); void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc); - void setReleaseBufferCallback(layer_state_t*, const ReleaseCallbackId&, - ReleaseBufferCallback); - void removeReleaseBufferCallback(layer_state_t*); public: - Transaction(); + Transaction() = default; virtual ~Transaction() = default; Transaction(Transaction const& other); @@ -440,7 +418,7 @@ public: // If the relative is removed, the Surface will have no layer and be // invisible, until the next time set(Relative)Layer is called. Transaction& setRelativeLayer(const sp<SurfaceControl>& sc, - const sp<SurfaceControl>& relativeTo, int32_t z); + const sp<IBinder>& relativeTo, int32_t z); Transaction& setFlags(const sp<SurfaceControl>& sc, uint32_t flags, uint32_t mask); Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc, @@ -449,17 +427,33 @@ public: float alpha); Transaction& setMatrix(const sp<SurfaceControl>& sc, float dsdx, float dtdx, float dtdy, float dsdy); - Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop); + Transaction& setCrop_legacy(const sp<SurfaceControl>& sc, const Rect& crop); Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius); Transaction& setBackgroundBlurRadius(const sp<SurfaceControl>& sc, int backgroundBlurRadius); - Transaction& setBlurRegions(const sp<SurfaceControl>& sc, - const std::vector<BlurRegion>& regions); Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack); Transaction& setMetadata(const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p); + // Defers applying any changes made in this transaction until the Layer + // identified by handle reaches the given frameNumber. If the Layer identified + // by handle is removed, then we will apply this transaction regardless of + // what frame number has been reached. + Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, + const sp<IBinder>& handle, uint64_t frameNumber); + // A variant of deferTransactionUntil_legacy which identifies the Layer we wait for by + // Surface instead of Handle. Useful for clients which may not have the + // SurfaceControl for some of their Surfaces. Otherwise behaves identically. + Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, + const sp<Surface>& barrierSurface, + uint64_t frameNumber); + // Reparents all children of this layer to the new parent handle. + Transaction& reparentChildren(const sp<SurfaceControl>& sc, + const sp<IBinder>& newParentHandle); /// Reparents the current layer to the new parent handle. The new parent must not be null. - Transaction& reparent(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent); + // This can be used instead of reparentChildren if the caller wants to + // only re-parent a specific child. + Transaction& reparent(const sp<SurfaceControl>& sc, + const sp<IBinder>& newParentHandle); Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color); @@ -470,9 +464,9 @@ public: Transaction& setTransform(const sp<SurfaceControl>& sc, uint32_t transform); Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc, bool transformToDisplayInverse); - Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer, - const ReleaseCallbackId& id = ReleaseCallbackId::INVALID_ID, - ReleaseBufferCallback callback = nullptr); + Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop); + Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame); + Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer); Transaction& setCachedBuffer(const sp<SurfaceControl>& sc, int32_t bufferId); Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence); Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace); @@ -488,23 +482,31 @@ public: // Sets information about the priority of the frame. Transaction& setFrameRateSelectionPriority(const sp<SurfaceControl>& sc, int32_t priority); - Transaction& addTransactionCallback(TransactionCompletedCallbackTakesContext callback, - void* callbackContext, CallbackId::Type callbackType); - Transaction& addTransactionCompletedCallback( TransactionCompletedCallbackTakesContext callback, void* callbackContext); - Transaction& addTransactionCommittedCallback( - TransactionCompletedCallbackTakesContext callback, void* callbackContext); - // ONLY FOR BLAST ADAPTER Transaction& notifyProducerDisconnect(const sp<SurfaceControl>& sc); - // Set the framenumber generated by the graphics producer to mimic BufferQueue behaviour. - Transaction& setFrameNumber(const sp<SurfaceControl>& sc, uint64_t frameNumber); + + // Detaches all child surfaces (and their children recursively) + // from their SurfaceControl. + // The child SurfaceControls will not throw exceptions or return errors, + // but transactions will have no effect. + // The child surfaces will continue to follow their parent surfaces, + // and remain eligible for rendering, but their relative state will be + // frozen. We use this in the WindowManager, in app shutdown/relaunch + // scenarios, where the app would otherwise clean up its child Surfaces. + // Sometimes the WindowManager needs to extend their lifetime slightly + // in order to perform an exit animation or prevent flicker. + Transaction& detachChildren(const sp<SurfaceControl>& sc); + // Set an override scaling mode as documented in <system/window.h> + // the override scaling mode will take precedence over any client + // specified scaling mode. -1 will clear the override scaling mode. + Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc, + int32_t overrideScalingMode); #ifndef NO_INPUT Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const InputWindowInfo& info); - Transaction& setFocusedWindow(const FocusRequest& request); Transaction& syncInputWindows(); #endif @@ -517,7 +519,7 @@ public: Transaction& setShadowRadius(const sp<SurfaceControl>& sc, float cornerRadius); Transaction& setFrameRate(const sp<SurfaceControl>& sc, float frameRate, - int8_t compatibility, int8_t changeFrameRateStrategy); + int8_t compatibility); // Set by window manager indicating the layer and all its children are // in a different orientation than the display. The hint suggests that @@ -527,43 +529,9 @@ public: // a buffer of a different size. Transaction& setFixedTransformHint(const sp<SurfaceControl>& sc, int32_t transformHint); - // Sets the frame timeline vsync id received from choreographer that corresponds - // to the transaction, and the input event id that identifies the input event that caused - // the current frame. - Transaction& setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInfo); - - // Indicates that the consumer should acquire the next frame as soon as it - // can and not wait for a frame to become available. This is only relevant - // in shared buffer mode. - Transaction& setAutoRefresh(const sp<SurfaceControl>& sc, bool autoRefresh); - // Sets that this surface control and its children are trusted overlays for input Transaction& setTrustedOverlay(const sp<SurfaceControl>& sc, bool isTrustedOverlay); - - // Queues up transactions using this token in SurfaceFlinger. By default, all transactions - // from a client are placed on the same queue. This can be used to prevent multiple - // transactions from blocking each other. - Transaction& setApplyToken(const sp<IBinder>& token); - - /** - * Provides the stretch effect configured on a container that the - * surface is rendered within. - * @param sc target surface the stretch should be applied to - * @param stretchEffect the corresponding stretch effect to be applied - * to the surface. This can be directly on the surface itself or - * configured from a parent of the surface in which case the - * StretchEffect provided has parameters mapping the position of - * the surface within the container that has the stretch configured - * on it - * @return The transaction being constructed - */ - Transaction& setStretchEffect(const sp<SurfaceControl>& sc, - const StretchEffect& stretchEffect); - - Transaction& setBufferCrop(const sp<SurfaceControl>& sc, const Rect& bufferCrop); - Transaction& setDestinationFrame(const sp<SurfaceControl>& sc, - const Rect& destinationFrame); - + status_t setDisplaySurface(const sp<IBinder>& token, const sp<IGraphicBufferProducer>& bufferProducer); @@ -583,8 +551,9 @@ public: const Rect& layerStackRect, const Rect& displayRect); void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); void setAnimationTransaction(); - void setEarlyWakeupStart(); - void setEarlyWakeupEnd(); + void setEarlyWakeup(); + void setExplicitEarlyWakeupStart(); + void setExplicitEarlyWakeupEnd(); }; status_t clearLayerFrameStats(const sp<IBinder>& token) const; @@ -592,10 +561,8 @@ public: static status_t clearAnimationFrameStats(); static status_t getAnimationFrameStats(FrameStats* outStats); - static status_t overrideHdrTypes(const sp<IBinder>& display, - const std::vector<ui::Hdr>& hdrTypes); - - static status_t onPullAtom(const int32_t atomId, std::string* outData, bool* success); + static status_t getHdrCapabilities(const sp<IBinder>& display, + HdrCapabilities* outCapabilities); static void setDisplayProjection(const sp<IBinder>& token, ui::Rotation orientation, const Rect& layerStackRect, const Rect& displayRect); @@ -615,12 +582,6 @@ public: const sp<IBinder>& stopLayerHandle, const sp<IRegionSamplingListener>& listener); static status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener); - static status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener); - static status_t removeFpsListener(const sp<gui::IFpsListener>& listener); - static status_t addTunnelModeEnabledListener( - const sp<gui::ITunnelModeEnabledListener>& listener); - static status_t removeTunnelModeEnabledListener( - const sp<gui::ITunnelModeEnabledListener>& listener); private: virtual void onFirstRef(); @@ -634,61 +595,50 @@ private: class ScreenshotClient { public: - static status_t captureDisplay(const DisplayCaptureArgs& captureArgs, - const sp<IScreenCaptureListener>& captureListener); - static status_t captureDisplay(uint64_t displayOrLayerStack, - const sp<IScreenCaptureListener>& captureListener); - static status_t captureLayers(const LayerCaptureArgs& captureArgs, - const sp<IScreenCaptureListener>& captureListener); + // if cropping isn't required, callers may pass in a default Rect, e.g.: + // capture(display, producer, Rect(), reqWidth, ...); + static status_t capture(const sp<IBinder>& display, ui::Dataspace reqDataSpace, + ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform, + ui::Rotation rotation, bool captureSecureLayers, + sp<GraphicBuffer>* outBuffer, bool& outCapturedSecureLayers); + static status_t capture(const sp<IBinder>& display, ui::Dataspace reqDataSpace, + ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform, + ui::Rotation rotation, sp<GraphicBuffer>* outBuffer); + static status_t capture(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace, + sp<GraphicBuffer>* outBuffer); + static status_t captureLayers(const sp<IBinder>& layerHandle, ui::Dataspace reqDataSpace, + ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + float frameScale, sp<GraphicBuffer>* outBuffer); + static status_t captureChildLayers( + const sp<IBinder>& layerHandle, ui::Dataspace reqDataSpace, + ui::PixelFormat reqPixelFormat, const Rect& sourceCrop, + const std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& + excludeHandles, + float frameScale, sp<GraphicBuffer>* outBuffer); }; // --------------------------------------------------------------------------- -class JankDataListener : public VirtualLightRefBase { -public: - virtual ~JankDataListener() = 0; - virtual void onJankDataAvailable(const std::vector<JankData>& jankData) = 0; -}; - class TransactionCompletedListener : public BnTransactionCompletedListener { TransactionCompletedListener(); - int64_t getNextIdLocked() REQUIRES(mMutex); + CallbackId getNextIdLocked() REQUIRES(mMutex); std::mutex mMutex; - // This lock needs to be recursive so we can unregister a callback from within that callback. - std::recursive_mutex mSurfaceStatsListenerMutex; - bool mListening GUARDED_BY(mMutex) = false; - int64_t mCallbackIdCounter GUARDED_BY(mMutex) = 1; + CallbackId mCallbackIdCounter GUARDED_BY(mMutex) = 1; + struct CallbackTranslation { TransactionCompletedCallback callbackFunction; std::unordered_map<sp<IBinder>, sp<SurfaceControl>, SurfaceComposerClient::IBinderHash> surfaceControls; }; - struct SurfaceStatsCallbackEntry { - SurfaceStatsCallbackEntry(void* context, void* cookie, SurfaceStatsCallback callback) - : context(context), - cookie(cookie), - callback(callback) {} - - void* context; - void* cookie; - SurfaceStatsCallback callback; - }; - - std::unordered_map<CallbackId, CallbackTranslation, CallbackIdHash> mCallbacks - GUARDED_BY(mMutex); - std::multimap<sp<IBinder>, sp<JankDataListener>> mJankListeners GUARDED_BY(mMutex); - std::unordered_map<ReleaseCallbackId, ReleaseBufferCallback, ReleaseBufferCallbackIdHash> - mReleaseBufferCallbacks GUARDED_BY(mMutex); - - // This is protected by mSurfaceStatsListenerMutex, but GUARDED_BY isn't supported for - // std::recursive_mutex - std::multimap<sp<IBinder>, SurfaceStatsCallbackEntry> mSurfaceStatsListeners; + std::unordered_map<CallbackId, CallbackTranslation> mCallbacks GUARDED_BY(mMutex); public: static sp<TransactionCompletedListener> getInstance(); @@ -699,39 +649,13 @@ public: CallbackId addCallbackFunction( const TransactionCompletedCallback& callbackFunction, const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>& - surfaceControls, - CallbackId::Type callbackType); - - void addSurfaceControlToCallbacks( - const sp<SurfaceControl>& surfaceControl, - const std::unordered_set<CallbackId, CallbackIdHash>& callbackIds); - - /* - * Adds a jank listener to be informed about SurfaceFlinger's jank classification for a specific - * surface. Jank classifications arrive as part of the transaction callbacks about previous - * frames submitted to this Surface. - */ - void addJankListener(const sp<JankDataListener>& listener, sp<SurfaceControl> surfaceControl); + surfaceControls); - /** - * Removes a jank listener previously added to addJankCallback. - */ - void removeJankListener(const sp<JankDataListener>& listener); - - void addSurfaceStatsListener(void* context, void* cookie, sp<SurfaceControl> surfaceControl, - SurfaceStatsCallback listener); - void removeSurfaceStatsListener(void* context, void* cookie); + void addSurfaceControlToCallbacks(const sp<SurfaceControl>& surfaceControl, + const std::unordered_set<CallbackId>& callbackIds); - void setReleaseBufferCallback(const ReleaseCallbackId&, ReleaseBufferCallback); - void removeReleaseBufferCallback(const ReleaseCallbackId&); - - // BnTransactionCompletedListener overrides + // Overrides BnTransactionCompletedListener's onTransactionCompleted void onTransactionCompleted(ListenerStats stats) override; - void onReleaseBuffer(ReleaseCallbackId, sp<Fence> releaseFence, uint32_t transformHint, - uint32_t currentMaxAcquiredBufferCount) override; - -private: - ReleaseBufferCallback popReleaseBufferCallbackLocked(const ReleaseCallbackId&); }; } // namespace android diff --git a/libs/gui/include/gui/SurfaceControl.h b/libs/gui/include/gui/SurfaceControl.h index 9ee4636ae1..ac2bbccfd2 100644 --- a/libs/gui/include/gui/SurfaceControl.h +++ b/libs/gui/include/gui/SurfaceControl.h @@ -20,6 +20,7 @@ #include <stdint.h> #include <sys/types.h> +#include <utils/KeyedVector.h> #include <utils/RefBase.h> #include <utils/threads.h> @@ -37,19 +38,14 @@ namespace android { class IGraphicBufferProducer; class Surface; class SurfaceComposerClient; -class BLASTBufferQueue; // --------------------------------------------------------------------------- class SurfaceControl : public RefBase { public: - static status_t readFromParcel(const Parcel& parcel, sp<SurfaceControl>* outSurfaceControl); - status_t writeToParcel(Parcel& parcel); - - static status_t readNullableFromParcel(const Parcel& parcel, - sp<SurfaceControl>* outSurfaceControl); - static status_t writeNullableToParcel(Parcel& parcel, const sp<SurfaceControl>& surfaceControl); + static sp<SurfaceControl> readFromParcel(const Parcel* parcel); + void writeToParcel(Parcel* parcel); static bool isValid(const sp<SurfaceControl>& surface) { return (surface != nullptr) && surface->isValid(); @@ -71,13 +67,11 @@ public: static status_t writeSurfaceToParcel( const sp<SurfaceControl>& control, Parcel* parcel); - sp<Surface> getSurface(); - sp<Surface> createSurface(); + sp<Surface> getSurface() const; + sp<Surface> createSurface() const; sp<IBinder> getHandle() const; - sp<IBinder> getLayerStateHandle() const; - int32_t getLayerId() const; - sp<IGraphicBufferProducer> getIGraphicBufferProducer(); + sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; status_t clearLayerFrameStats() const; status_t getLayerFrameStats(FrameStats* outStats) const; @@ -87,16 +81,11 @@ public: uint32_t getTransformHint() const; void setTransformHint(uint32_t hint); - void updateDefaultBufferSize(uint32_t width, uint32_t height); explicit SurfaceControl(const sp<SurfaceControl>& other); SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle, - const sp<IGraphicBufferProducer>& gbp, int32_t layerId, - uint32_t width = 0, uint32_t height = 0, PixelFormat format = 0, - uint32_t transformHint = 0, uint32_t flags = 0); - - sp<SurfaceControl> getParentingLayer(); + const sp<IGraphicBufferProducer>& gbp, uint32_t transformHint = 0); private: // can't be copied @@ -108,7 +97,7 @@ private: ~SurfaceControl(); - sp<Surface> generateSurfaceLocked(); + sp<Surface> generateSurfaceLocked() const; status_t validate() const; sp<SurfaceComposerClient> mClient; @@ -116,14 +105,7 @@ private: sp<IGraphicBufferProducer> mGraphicBufferProducer; mutable Mutex mLock; mutable sp<Surface> mSurfaceData; - mutable sp<BLASTBufferQueue> mBbq; - mutable sp<SurfaceControl> mBbqChild; - int32_t mLayerId; uint32_t mTransformHint; - uint32_t mWidth; - uint32_t mHeight; - PixelFormat mFormat; - uint32_t mCreateFlags; }; }; // namespace android diff --git a/libs/gui/include/gui/SyncScreenCaptureListener.h b/libs/gui/include/gui/SyncScreenCaptureListener.h deleted file mode 100644 index 0784fbc058..0000000000 --- a/libs/gui/include/gui/SyncScreenCaptureListener.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020 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 <android/gui/BnScreenCaptureListener.h> -#include <gui/SurfaceComposerClient.h> -#include <future> - -namespace android { - -using gui::ScreenCaptureResults; - -struct SyncScreenCaptureListener : gui::BnScreenCaptureListener { -public: - binder::Status onScreenCaptureCompleted(const ScreenCaptureResults& captureResults) override { - resultsPromise.set_value(captureResults); - return binder::Status::ok(); - } - - ScreenCaptureResults waitForResults() { - std::future<ScreenCaptureResults> resultsFuture = resultsPromise.get_future(); - const auto screenCaptureResults = resultsFuture.get(); - screenCaptureResults.fence->waitForever(""); - return screenCaptureResults; - } - -private: - std::promise<ScreenCaptureResults> resultsPromise; -}; - -} // namespace android
\ No newline at end of file diff --git a/libs/gui/include/gui/TraceUtils.h b/libs/gui/include/gui/TraceUtils.h deleted file mode 100644 index b9ec14aaf0..0000000000 --- a/libs/gui/include/gui/TraceUtils.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2021 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 <cutils/trace.h> -#include <utils/Trace.h> - -#define ATRACE_FORMAT(fmt, ...) \ - TraceUtils::TraceEnder __traceEnder = \ - (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder()) - -#define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__) - -namespace android { - -class TraceUtils { -public: - class TraceEnder { - public: - ~TraceEnder() { ATRACE_END(); } - }; - - static void atraceFormatBegin(const char* fmt, ...) { - if (CC_LIKELY(!ATRACE_ENABLED())) return; - - const int BUFFER_SIZE = 256; - va_list ap; - char buf[BUFFER_SIZE]; - - va_start(ap, fmt); - vsnprintf(buf, BUFFER_SIZE, fmt, ap); - va_end(ap); - - ATRACE_BEGIN(buf); - } - -}; // class TraceUtils - -} /* namespace android */ diff --git a/libs/gui/include/gui/bufferqueue/1.0/WGraphicBufferProducer.h b/libs/gui/include/gui/bufferqueue/1.0/WGraphicBufferProducer.h index 004d87574a..99ab0857d3 100644 --- a/libs/gui/include/gui/bufferqueue/1.0/WGraphicBufferProducer.h +++ b/libs/gui/include/gui/bufferqueue/1.0/WGraphicBufferProducer.h @@ -51,14 +51,12 @@ typedef ::android::IGraphicBufferProducer BGraphicBufferProducer; typedef ::android::IProducerListener BProducerListener; #ifndef LOG -struct LOG_stub { +struct LOG_dummy { template <typename T> - LOG_stub& operator<<(const T&) { - return *this; - } + LOG_dummy& operator<< (const T&) { return *this; } }; -#define LOG(x) LOG_stub() +#define LOG(x) LOG_dummy() #endif // Instantiate only if HGraphicBufferProducer is base of BASE. diff --git a/libs/gui/include/gui/view/Surface.h b/libs/gui/include/gui/view/Surface.h index f7dcbc698d..cc64fd45dd 100644 --- a/libs/gui/include/gui/view/Surface.h +++ b/libs/gui/include/gui/view/Surface.h @@ -21,7 +21,6 @@ #include <utils/StrongPointer.h> #include <utils/String16.h> -#include <binder/IBinder.h> #include <binder/Parcelable.h> namespace android { @@ -44,7 +43,6 @@ class Surface : public Parcelable { String16 name; sp<IGraphicBufferProducer> graphicBufferProducer; - sp<IBinder> surfaceControlHandle; virtual status_t writeToParcel(Parcel* parcel) const override; virtual status_t readFromParcel(const Parcel* parcel) override; diff --git a/libs/gui/include/private/gui/BitTube.h b/libs/gui/include/private/gui/BitTube.h index 80485184bd..13c01623b7 100644 --- a/libs/gui/include/private/gui/BitTube.h +++ b/libs/gui/include/private/gui/BitTube.h @@ -58,9 +58,6 @@ public: // resets this BitTube's receive file descriptor to receiveFd void setReceiveFd(base::unique_fd&& receiveFd); - // resets this BitTube's send file descriptor to sendFd - void setSendFd(base::unique_fd&& sendFd); - // send objects (sized blobs). All objects are guaranteed to be written or the call fails. template <typename T> static ssize_t sendObjects(BitTube* tube, T const* events, size_t count) { @@ -88,7 +85,7 @@ private: // the message, excess data is silently discarded. ssize_t read(void* vaddr, size_t size); - mutable base::unique_fd mSendFd; + base::unique_fd mSendFd; mutable base::unique_fd mReceiveFd; static ssize_t sendObjects(BitTube* tube, void const* events, size_t count, size_t objSize); diff --git a/libs/gui/include/private/gui/ComposerService.h b/libs/gui/include/private/gui/ComposerService.h index fa1071a4e3..50bd742b6a 100644 --- a/libs/gui/include/private/gui/ComposerService.h +++ b/libs/gui/include/private/gui/ComposerService.h @@ -45,12 +45,13 @@ class ComposerService : public Singleton<ComposerService> Mutex mLock; ComposerService(); - bool connectLocked(); + void connectLocked(); void composerServiceDied(); friend class Singleton<ComposerService>; public: + // Get a connection to the Composer Service. This will block until - // a connection is established. Returns null if permission is denied. + // a connection is established. static sp<ISurfaceComposer> getComposerService(); }; diff --git a/libs/gui/include/private/gui/ParcelUtils.h b/libs/gui/include/private/gui/ParcelUtils.h deleted file mode 100644 index 1cdd07e36e..0000000000 --- a/libs/gui/include/private/gui/ParcelUtils.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2021 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 <cstring> - -#define SAFE_PARCEL(FUNC, ...) \ - { \ - status_t error = FUNC(__VA_ARGS__); \ - if (error) { \ - ALOGE("ERROR(%s, %d). Failed to call parcel %s(%s)", strerror(-error), error, #FUNC, \ - #__VA_ARGS__); \ - return error; \ - } \ - } - -#define SAFE_PARCEL_READ_SIZE(FUNC, COUNT, SIZE) \ - { \ - SAFE_PARCEL(FUNC, COUNT); \ - if (static_cast<unsigned int>(*COUNT) > SIZE) { \ - ALOGE("ERROR(BAD_VALUE). %s was greater than dataSize", #COUNT); \ - return BAD_VALUE; \ - } \ - }
\ No newline at end of file |