Android Graphics模塊中的各種State和重要類普法

Android Graphics模塊中的各種State和重要類普法



引言

尼瑪,這Android Graphics圖形棧蛋疼啊,更新太快了。機會是每年一個版本,前進的膠布不能停啊,繼續干。這邊博客,我們的核心是理一理Android Graphics中各種State狀態類。

這里分析的Android版本是Android 13 aosp!



一. Layer中State

先不解釋,先直接上代碼,后分析:

//frameworks/native/services/surfaceflinger/Layer.h//struct android::Layer::Statestruct State {Geometry active_legacy;Geometry requested_legacy;int32_t z;ui::LayerStack layerStack;uint32_t flags;uint8_t reserved[2];int32_t sequence; // changes when visible regions can changebool modified;// Crop is expressed in layer space coordinate.Rect crop;Rect requestedCrop;// the transparentRegion hint is a bit special, it's latched only// when we receive a buffer -- this is because it's "content"// dependent.Region activeTransparentRegion_legacy;Region requestedTransparentRegion_legacy;LayerMetadata metadata;// If non-null, a Surface this Surface's Z-order is interpreted relative to.wp<Layer> zOrderRelativeOf;bool isRelativeOf{false};// A list of surfaces whose Z-order is interpreted relative to ours.SortedVector<wp<Layer>> zOrderRelatives;half4 color;float cornerRadius;int backgroundBlurRadius;gui::WindowInfo inputInfo;wp<Layer> touchableRegionCrop;// dataspace is only used by BufferStateLayer and EffectLayerui::Dataspace dataspace;// The fields below this point are only used by BufferStateLayeruint64_t frameNumber;uint32_t width;uint32_t height;ui::Transform transform;uint32_t bufferTransform;bool transformToDisplayInverse;Region transparentRegionHint;std::shared_ptr<renderengine::ExternalTexture> buffer;client_cache_t clientCacheId;sp<Fence> acquireFence;std::shared_ptr<FenceTime> acquireFenceTime;HdrMetadata hdrMetadata;Region surfaceDamageRegion;int32_t api;sp<NativeHandle> sidebandStream;mat4 colorTransform;bool hasColorTransform;// pointer to background color layer that, if set, appears below the buffer state layer// and the buffer state layer's children.  Z order will be set to// INT_MINsp<Layer> bgColorLayer;// The deque of callback handles for this frame. The back of the deque contains the most// recent callback handle.std::deque<sp<CallbackHandle>> callbackHandles;bool colorSpaceAgnostic;nsecs_t desiredPresentTime = 0;bool isAutoTimestamp = true;// Length of the cast shadow. If the radius is > 0, a shadow of length shadowRadius will// be rendered around the layer.float shadowRadius;// Layer regions that are made of custom materials, like frosted glassstd::vector<BlurRegion> blurRegions;// Priority of the layer assigned by Window Manager.int32_t frameRateSelectionPriority;FrameRate frameRate;// The combined frame rate of parents / children of this layerFrameRate frameRateForLayerTree;// Set by window manager indicating the layer and all its children are// in a different orientation than the display. The hint suggests that// the graphic producers should receive a transform hint as if the// display was in this orientation. When the display changes to match// the layer orientation, the graphic producer may not need to allocate// a buffer of a different size. ui::Transform::ROT_INVALID means the// a fixed transform hint is not set.ui::Transform::RotationFlags fixedTransformHint;// The vsync info that was used to start the transactionFrameTimelineInfo frameTimelineInfo;// When the transaction was postednsecs_t postTime;sp<ITransactionCompletedListener> releaseBufferListener;// SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one// such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.// If multiple buffers are queued, the prior ones will be dropped, along with the// SurfaceFrame that's tracking them.std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX;// A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction// that contains the token. Only one SurfaceFrame exisits for transactions that share the// same token, unless they are presented in different vsyncs.std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>>bufferlessSurfaceFramesTX;// An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to// trigger a warning if the number of SurfaceFrames crosses the threshold.static constexpr uint32_t kStateSurfaceFramesThreshold = 25;// Stretch effect to apply to this layerStretchEffect stretchEffect;// Whether or not this layer is a trusted overlay for inputbool isTrustedOverlay;Rect bufferCrop;Rect destinationFrame;sp<IBinder> releaseBufferEndpoint;gui::DropInputMode dropInputMode;bool autoRefresh = false;bool dimmingEnabled = true;};// These are only accessed by the main thread or the tracing thread.State mDrawingState;

這里的Layer.State主要存儲了該Layer相關的數據,例如長寬,各種矩陣,陰影等。

這里有點疑問,沒有看到mCurrentState這個!




二. BufferLayer中對應的BufferInfo

這個BufferInfo比較重要,主要用于將Layer的信息傳遞給后續的OutputLayer。

//frameworks/native/services/surfaceflinger/BufferLayer.h
class BufferLayer : public Layer {...protected:struct BufferInfo {nsecs_t mDesiredPresentTime;std::shared_ptr<FenceTime> mFenceTime;sp<Fence> mFence;uint32_t mTransform{0};ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN};Rect mCrop;uint32_t mScaleMode{NATIVE_WINDOW_SCALING_MODE_FREEZE};Region mSurfaceDamage;HdrMetadata mHdrMetadata;int mApi;PixelFormat mPixelFormat{PIXEL_FORMAT_NONE};bool mTransformToDisplayInverse{false};std::shared_ptr<renderengine::ExternalTexture> mBuffer;uint64_t mFrameNumber;int mBufferSlot{BufferQueue::INVALID_BUFFER_SLOT};bool mFrameLatencyNeeded{false};};BufferInfo mBufferInfo;   ...}



三. OutputLayer對應的CompositionState

這里需要注意CompositionState對應的域空間,不要和Layer里面的搞混淆了!

//frameworks/native/services/surfaceflinger/CompositionEngine/include/compositionengine/OutputLayer.h
class OutputLayer {using CompositionState = compositionengine::impl::OutputLayerCompositionState;
}///frameworks/native/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
namespace compositionengine::impl {//namespace android::compositionengine::impl// Note that fields that affect HW composer state may need to be mirrored into
// android::compositionengine::impl::planner::LayerState
struct OutputLayerCompositionState {// The portion of the layer that is not obscured by opaque layers on topRegion visibleRegion;// The portion of the layer that is not obscured and is also opaqueRegion visibleNonTransparentRegion;// The portion of the layer that is obscured by opaque layers on topRegion coveredRegion;// The visibleRegion transformed to output spaceRegion outputSpaceVisibleRegion;// Region cast by the layer's shadowRegion shadowRegion;// If true, client composition will be used on this outputbool forceClientComposition{false};// If true, when doing client composition, the target may need to be clearedbool clearClientTarget{false};// The display frame for this layer on this outputRect displayFrame;// The source crop for this layer on this outputFloatRect sourceCrop;// The buffer transform to use for this layer o on this output.Hwc2::Transform bufferTransform{static_cast<Hwc2::Transform>(0)};// The dataspace for this layerui::Dataspace dataspace{ui::Dataspace::UNKNOWN};// A hint to the HWC that this region is transparent and may be skipped in// order to save power.Region outputSpaceBlockingRegionHint;// Overrides the buffer, acquire fence, and display frame stored in LayerFECompositionStatestruct {std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;sp<Fence> acquireFence = nullptr;Rect displayFrame = {};ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};ProjectionSpace displaySpace;Region damageRegion = Region::INVALID_REGION;Region visibleRegion;// The OutputLayer pointed to by this field will be rearranged to draw// behind the OutputLayer represented by this CompositionState and will// be visible through it. Unowned - the OutputLayer's lifetime will// outlast this.)compositionengine::OutputLayer* peekThroughLayer = nullptr;// True when this layer's blur has been cached with a previous layer, so that this layer// does not need to request blurring.// TODO(b/188816867): support blur regions too, which are less likely to be common if a// device supports cross-window blurs. Blur region support should be doable, but we would// need to make sure that layer caching works well with the blur region transform passed// into RenderEnginebool disableBackgroundBlur = false;} overrideInfo;/** HWC state*/struct Hwc {explicit Hwc(std::shared_ptr<HWC2::Layer> hwcLayer) : hwcLayer(hwcLayer) {}// The HWC Layer backing this layerstd::shared_ptr<HWC2::Layer> hwcLayer;// The most recently set HWC composition type for this layeraidl::android::hardware::graphics::composer3::Composition hwcCompositionType{aidl::android::hardware::graphics::composer3::Composition::INVALID};// The buffer cache for this layer. This is used to lower the// cost of sending reused buffers to the HWC.HwcBufferCache hwcBufferCache;// Set to true when overridden info has been sent to HW composerbool stateOverridden = false;// True when this layer was skipped as part of SF-side layer caching.bool layerSkipped = false;};// The HWC state is optional, and is only set up if there is any potential// HWC acceleration possible.std::optional<Hwc> hwc;// Debuggingvoid dump(std::string& result) const;// Timestamp for when the layer is queued for client compositionnsecs_t clientCompositionTimestamp{0};static constexpr float kDefaultWhitePointNits = 200.f;float whitePointNits = kDefaultWhitePointNits;// Dimming ratio of the layer from [0, 1]static constexpr float kDefaultDimmingRatio = 1.f;float dimmingRatio = kDefaultDimmingRatio;
};} // namespace compositionengine::impl



四 Output和Display

這里要怎么理解Output和Display呢,可以簡單概括就是:

  • Output: 封裝所有與合成輸出層相關的狀態
//frameworks/native/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h
namespace android {
namespace compositionengine {
class Output {
public:using OutputCompositionState = compositionengine::impl::OutputCompositionState;// Gets the raw composition state data for the output// TODO(lpique): Make this protected once it is only internally called.virtual const OutputCompositionState& getState() const = 0;// Allows mutable access to the raw composition state data for the output.// This is meant to be used by the various functions that are part of the// composition process.// TODO(lpique): Make this protected once it is only internally called.virtual OutputCompositionState& editState() = 0;auto getOutputLayersOrderedByZ() const { return OutputLayersEnumerator(*this); }    // Prepare the output, updating the OutputLayers used in the outputvirtual void prepare(const CompositionRefreshArgs&, LayerFESet&) = 0;// Presents the output, finalizing all composition detailsvirtual void present(const CompositionRefreshArgs&) = 0;// Latches the front-end layer state for each output layervirtual void updateLayerStateFromFE(const CompositionRefreshArgs&) const = 0;    
}
}// namespace compositionengine
}// namespace android

Output還有一個對應域空間android::compositionengine::impl的,它們之間的關聯,暫時還沒有搞清楚

  • Display: 表示所有輸出層最終對應的顯示設備,可以有硬件合成器支持的顯示設備,也可以對應虛擬顯示設備
namespace android::compositionengine {
class Display : public virtual Output {
}
} // namespace android::compositionengine



五. LayerFE

按照谷歌注釋的翻譯意思是,定義合成引擎用于向前端層發出請求的接口!這個我的理解它主要是Layer的一個前端,主要用來處理Layer合成相關的,!表示一個"前端"Layer,跟Layer相對應,用于處理Layer在合成階段的工作


namespace android {
namespace compositionengine {// Defines the interface used by the CompositionEngine to make requests
// of the front-end layer
class LayerFE : public virtual RefBase {// Gets the raw front-end composition state data for the layervirtual const LayerFECompositionState* getCompositionState() const = 0;}} // namespace compositionengine
} // namespace android



六 LayerFECompositionState

表示Layer的frontEnd(LayerFECompositionState)

//frameworks/native/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
/** Used by LayerFE::getCompositionState* Note that fields that affect HW composer state may need to be mirrored into* android::compositionengine::impl::planner::LayerState*/
struct LayerFECompositionState {// If set to true, forces client composition on all output layers until// the next geometry change.bool forceClientComposition{false};// TODO(b/121291683): Reorganize and rename the contents of this structure/** Visibility state*/// The filter that determines which outputs include this layerui::LayerFilter outputFilter;// If false, this layer should not be considered visiblebool isVisible{true};// True if the layer is completely opaquebool isOpaque{true};// If true, invalidates the entire visible regionbool contentDirty{false};// The alpha value for this layerfloat alpha{1.f};// Background blur in pixelsint backgroundBlurRadius{0};// The transform from layer local coordinates to composition coordinatesui::Transform geomLayerTransform;// The inverse of the layer transformui::Transform geomInverseLayerTransform;// The hint from the layer producer as to what portion of the layer is// transparent.Region transparentRegionHint;// The blend mode for this layerhal::BlendMode blendMode{hal::BlendMode::INVALID};// The bounds of the layer in layer local coordinatesFloatRect geomLayerBounds;// length of the shadow in screen spacefloat shadowRadius{0.f};// List of regions that require blurstd::vector<BlurRegion> blurRegions;StretchEffect stretchEffect;/** Geometry state*/bool isSecure{false};bool geomUsesSourceCrop{false};bool geomBufferUsesDisplayInverseTransform{false};uint32_t geomBufferTransform{0};Rect geomBufferSize;Rect geomContentCrop;Rect geomCrop;GenericLayerMetadataMap metadata;/** Per-frame content*/// The type of composition for this layeraidl::android::hardware::graphics::composer3::Composition compositionType{aidl::android::hardware::graphics::composer3::Composition::INVALID};// The buffer and related statesp<GraphicBuffer> buffer;int bufferSlot{BufferQueue::INVALID_BUFFER_SLOT};sp<Fence> acquireFence = Fence::NO_FENCE;Region surfaceDamage;uint64_t frameNumber = 0;// The handle to use for a sideband stream for this layersp<NativeHandle> sidebandStream;// If true, this sideband layer has a frame updatebool sidebandStreamHasFrame{false};// The color for this layerhalf4 color;/** Per-frame presentation state*/// If true, this layer will use the dataspace chosen for the output and// ignore the dataspace value just belowbool isColorspaceAgnostic{false};// The dataspace for this layerui::Dataspace dataspace{ui::Dataspace::UNKNOWN};// The metadata for this layerHdrMetadata hdrMetadata;// The color transformmat4 colorTransform;bool colorTransformIsIdentity{true};// True if the layer has protected contentbool hasProtectedContent{false};/** Cursor state*/// The output-independent frame for the cursorRect cursorFrame;// framerate of the layer as measured by LayerHistoryfloat fps;// The dimming flagbool dimmingEnabled{true};virtual ~LayerFECompositionState();// Debuggingvirtual void dump(std::string& out) const;
};



1.Surface的創建【Android 12】

2.Android下Layer的創建

3.onMessageRefresh

參考里面對核心類的解釋!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/17668.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/17668.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/17668.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2024最新版本激活Typora,1.8.10.0版本可用

?實測可用日期為&#xff1a;2024-05-28 目前最新版本 1.8.10.0 也是可以實現激活的 注&#xff1a;免修改注冊表、不用修改時間&#xff0c;更不需要破解補丁 01、下載&安裝 Typora 文件 從官網下載最新版本的 Typora&#xff0c;并安裝 或者阿里云盤&#xff1a; htt…

Pytorch深度學習實踐筆記12(b站劉二大人)

&#x1f3ac;個人簡介&#xff1a;一個全棧工程師的升級之路&#xff01; &#x1f4cb;個人專欄&#xff1a;pytorch深度學習 &#x1f380;CSDN主頁 發狂的小花 &#x1f304;人生秘訣&#xff1a;學習的本質就是極致重復! 《PyTorch深度學習實踐》完結合集_嗶哩嗶哩_bilibi…

數據集008:吸煙、抽煙檢測數據集(含數據集下載鏈接)

數據集簡介 兩個數據集 一個是783張圖片對應的xml文件 一個是2482張圖片對應的xml文件 如下圖所示&#xff1a; 部分代碼&#xff1a; # 測試數據讀取 def test_data_loader(datadir, batch_size 10, test_image_size608, modetest):"""加載測試用的圖片…

大學生選擇算法向還是嵌入式向?

在開始前剛好我有一些資料&#xff0c;是我根據網友給的問題精心整理了一份「嵌入式的資料從專業入門到高級教程」&#xff0c; 點個關注在評論區回復“888”之后私信回復“888”&#xff0c;全部無償共享給大家&#xff01;&#xff01;&#xff01; 由于嵌入式的薪資待遇和…

品牌建設不迷路:系統化方法讓品牌成長更高效

很多創始人才創業過程中都會發現&#xff1a; 企業越大&#xff0c;遇到的系統性的底層品牌問題就會越多&#xff0c;品牌的系統化建設底層根基如果不穩&#xff0c;后續的增長也會搖搖欲墜。 所以在當今競爭激烈的市場環境中&#xff0c;品牌的成功不僅僅依靠一個響亮的名字…

Spring Boot注解(Annotation)

在Spring Boot中&#xff0c;注解&#xff08;Annotation&#xff09;是一種元數據形式&#xff0c;它可以在代碼中提供信息&#xff0c;這些信息可以在運行時或編譯時被處理。Spring Boot使用注解來實現依賴注入、事務管理、配置等功能。 以下是Spring Boot中注解的執行機制的…

【Linux】Linux的權限_1

文章目錄 三、權限1. shell外殼2. Linux的用戶3. Linux權限管理文件訪問者的分類文件類型和訪問權限 未完待續 三、權限 1. shell外殼 為什么要使用shell外殼 由于用戶不擅長直接與操作系統直接接觸和操作系統的易用程度、安全性考慮&#xff0c;用戶不能直接訪問操作系統。 什…

文件IO(一)

文件IO&#xff08;一&#xff09; 文件IO文件的分類在文件IO下&#xff0c;文件分類按存儲的內容分按照操作分 標準IO和文件IO的區別系統調用和庫函數的區別 文件IO 把程序暫存在內存的數據&#xff0c;存儲到本地外存上 文件的分類 在Linux系統下&#xff0c;文件共分為7類…

AI答題項目,無門檻答題一小時收益30+

朋友們&#xff0c;今天我想和大家探討一個令人興奮的副業機遇。你是否曾感覺到日常工作的枯燥乏味&#xff0c;而又渴望找到一種輕松的賺錢方式來增加你的收入&#xff1f;今天我將和你分享的這個項目正是你所期待的。 項目的核心是利用AI技術來回答網上付費用戶的問題&…

重生之我要精通JAVA--第六周筆記

File 路徑 相對路徑 路徑1&#xff1a;“a.txt” 路徑2&#xff1a;“abc\\a.txt” 絕對路徑 路徑1&#xff1a;“c:\\a.txt” 路徑2&#xff1a;“c:\\abc\\a.txt” File對象就表示一個路徑&#xff0c;可以是文件的路徑、也可以是文件夾的路徑這個路徑可以是存在的&…

linux線程,線程控制與線程相關概念

線程概念 線程這個詞或多或少大家都聽過&#xff0c;今天我們正式的來談一下線程&#xff1b; 在我一開始的概念中線程就是進程的一部分&#xff0c;一個進程中有很多個線程&#xff0c;這個想法基本是正確的&#xff0c;但細節部分呢我們需要細細講解一下&#xff1b; 什么…

“揭秘:為什么羊駝Ollama成為計算機運行大型語言模型的最佳拍檔?“

最近&#xff0c;AIM 評測了在計算機上本地運行大語言模型&#xff08;LLM&#xff09;的最佳工具&#xff0c;Ollama 脫穎而出&#xff0c;成為最高效的解決方案&#xff0c;提供了無與倫比的靈活性。Ollama 是 Jeffrey Morgan 開發的一款開源工具&#xff0c;它正在徹底改變愛…

我被恐嚇了,對方揚言要壓測我的網站

大家好我是聰&#xff0c;昨天真是水逆&#xff0c;在技術群里交流問題&#xff0c;竟然被人身攻擊了&#xff01;罵的話太難聽具體就不加討論了&#xff0c;人身攻擊我可以接受&#xff0c;我接受不了他竟然說要刷我接口&#xff01;&#xff01;&#xff01;&#xff01;這下…

啟用標準大頁后內存使用率下降了

未啟用前 [rootol819c ~]# free -htotal used free shared buff/cache available Mem: 9.3Gi 984Mi 379Mi 1.5Gi 8.0Gi 6.8Gi Swap: 15Gi 3.0Mi 15Gi [rootol819c ~]# free -htotal …

【NumPy】掌握NumPy的histogram函數:數據直方圖的生成與應用詳解

&#x1f9d1; 博主簡介&#xff1a;阿里巴巴嵌入式技術專家&#xff0c;深耕嵌入式人工智能領域&#xff0c;具備多年的嵌入式硬件產品研發管理經驗。 &#x1f4d2; 博客介紹&#xff1a;分享嵌入式開發領域的相關知識、經驗、思考和感悟&#xff0c;歡迎關注。提供嵌入式方向…

速度百倍提升,高性能 Python 編譯器 Codon 火了

引言 在當下的編程世界里&#xff0c;Python由于其易用性和強大的庫支持在數據科學、人工智能和網頁開發等多個領域占據著舉足輕重的地位。然而&#xff0c;Python的執行速度往往成為開發者的一大痛點。 針對 這一問題&#xff0c;Codon項目正試圖提供一個高效的解決方案。Codo…

java新特性(Stream API)

什么是 Stream API? Stream API 是 Java 8 引入的一個用于對集合數據進行函數式編程操作的強大的庫。它允許我們以一種更簡潔、易讀、高效的方式來處理集合數據,可以極大提高 Java 程序員的生產力,是目前為止對 Java 類庫最好的補充。 Stream API 的核心思想是將數據處理操作…

小識MFC,一套設計優雅與不優雅并存的類庫----小話MFC(2)

Q1&#xff1a; CPoint繼承于POINT&#xff0c;這樣有什么好處&#xff1f; A&#xff1a; 繼承的一個最基本的好處當然就是減少代碼量。CPoint和POINT內部數據一樣&#xff0c;只是一個提供了更多的方法來操作對象。 typedef struct tagPOINT {LONG x;LONG y; } POINT, *P…

【Flutter】動畫介紹隱式動畫

&#x1f525; 本文由 程序喵正在路上 原創&#xff0c;CSDN首發&#xff01; &#x1f496; 系列專欄&#xff1a;Flutter學習 &#x1f320; 首發時間&#xff1a;2024年5月28日 &#x1f98b; 歡迎關注&#x1f5b1;點贊&#x1f44d;收藏&#x1f31f;留言&#x1f43e; 目…

SpringMvc-restful設計風格

Restful 1、入門1.1 簡介1.2 實例 1、入門 1.1 簡介 RESTFul是什么 RESTFul是WEB服務接口的一種設計風格。 RESTFul定義了一組約束條件和規范&#xff0c;可以讓WEB服務接口更加簡潔、易于理解、易于擴展、安全可靠。 1.2 實例 web.xml <?xml version"1.0"…