UNDERSTANDING ANDROID GRAPHICS INTERNALS – GRAPHICS BASICS(II)

After the preceding post on ANativeWindow and ANativeWindowBuffer, we have the fodder to discuss GraphicBuffer and Surface.

After the preceding posts on ANativeWindow and ANativeWindowBuffer, we have the fodder to discuss GraphicBuffer and Surface.

  • GraphicBuffer class

GraphicBuffer is an implementation of ANativeWindowBuffer, part of the definition from frameworks/native/include/ui/GraphicBuffer.h is quoted below.

class GraphicBuffer : public ANativeObjectBase

< ANativeWindowBuffer, GraphicBuffer, RefBase >,

public Flattenable

{

public:

...

status status_t initCheck() const;

uint32_t getWidth() const { return width; }

uint32_t getHeight() const { return height; }

uint32_t getStride() const { return stride; }

uint32_t getUsage() const { return usage; }

PixelFormat getPixelFormat() const { return format; }

Rect getBounds() const { return Rect(width, height); }

status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage);

status_t lock(uint32_t usage, void** vaddr);

status_t lock(uint32_t usage, const Rect& rect, void** vaddr);

// For HAL_PIXEL_FORMAT_YCbCr_420_888

status_t lockYCbCr(uint32_t usage, android_ycbcr *ycbcr);

status_t lockYCbCr(uint32_t usage, const Rect& rect, android_ycbcr *ycbcr);

status_t unlock();

ANativeWindowBuffer* getNativeBuffer() const;

void setIndex(int index); int getIndex() const;

private:

inline const GraphicBufferMapper& getBufferMapper() const { return mBufferMapper; }

inline GraphicBufferMapper& getBufferMapper() {

return mBufferMapper; }

uint8_t mOwner;

private:

friend class Surface;

friend class BpSurface;

friend class BnSurface;

friend class LightRefBase<GraphicBuffer>;

status_t initSize(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage);

void free_handle();

GraphicBufferMapper& mBufferMapper;

ssize_t mInitCheck;

int mIndex;

// If we're wrapping another buffer then this reference will make sure it

// doesn't get freed.

sp<ANativeWindowBuffer> mWrappedBuffer;

...

};

At this point ,we shall not have doubt with respect to GraphicBuffer’s multiple inheritance from Flattenable, ANativeObjectBase and RefBase, and the geometric/color space parameters.

The lock/unlock function are used in mapping/unmapping virtual memory address. The GraphicBufferMapper is the work horse for the functionality.

  • Surface class

Surface class is well-documented in comments in frameworks/native/include/gui/Surface.h.

/*An implementation of ANativeWindow that feeds graphics buffers into a BufferQueue. This is typically used by programs that want to render frames through some means (maybe OpenGL, a software renderer, or a hardware decoder) and have the frames they create forwarded to SurfaceFlinger for compositing. For example, a video decoder could render a frame and call eglSwapBuffers(), which invokes ANativeWindow callbacks defined by Surface. Surface then forwards the buffers through Binder IPC to the BufferQueue’s producer interface, providing the new frame to a consumer such as GLConsumer. */

class Surface : public ANativeObjectBase<ANativeWindow, Surface, RefBase> {

public:

/* creates a Surface from the given IGraphicBufferProducer (which concrete * implementation is a BufferQueue). Surface is mainly state-less while it’s disconnected, it can be viewed as a glorified IGraphicBufferProducer holder. It’s therefore safe to create other Surfaces from the same IGraphicBufferProducer. However, once a Surface is connected, it’ll prevent other Surfaces referring to the same IGraphicBufferProducer to become connected and therefore prevent them to be used as actual producers of buffers. */

Surface(const sp<IGraphicBufferProducer>& bufferProducer);

/* getIGraphicBufferProducer() returns the GraphicBufferProducer this Surface was created with. Usually it’s an error to use the IGraphicBufferProducer while the Surface is connected. */

sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;

/* convenience function to check that the given surface is non NULL as well as its IGraphicBufferProducer */

static bool isValid(const sp<Surface>& surface) { return surface != NULL && surface->getIGraphicBufferProducer() != NULL; }

private:

/* mSurfaceTexture is the interface to the surface texture server. All operations on the surface texture client ultimately translate into interactions with the server using this interface. TODO: rename to mBufferProducer */

sp<IGraphicBufferProducer> mGraphicBufferProducer;

/* mSlots stores the buffers that have been allocated for each buffer slot. It is initialized to null pointers, and gets filled in with the result of IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a slot that has not yet been used. The buffer allocated to a slot will also be replaced if the requested buffer usage or geometry differs from that of the buffer allocated to a slot. */

BufferSlot mSlots[NUM_BUFFER_SLOTS];

/*mReqWidth is the buffer width that will be requested at the next dequeue operation. It is initialized to 1.

uint32_t mReqWidth;

/*mReqHeight is the buffer height that will be requested at the next dequeue operation. It is initialized to 1.

uint32_t mReqHeight;

/* mReqFormat is the buffer pixel format that will be requested at the next deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.

uint32_t mReqFormat;

/* mReqUsage is the set of buffer usage flags that will be requested at the next deuque operation. It is initialized to 0. uint32_t mReqUsage;

/* mTimestamp is the timestamp that will be used for the next buffer queue operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that a timestamp is auto-generated when queueBuffer is called. */

int64_t mTimestamp;

/* mCrop is the crop rectangle that will be used for the next buffer that gets queued. It is set by calling setCrop. Rect mCrop; mScalingMode is the scaling mode that will be used for the next buffers that get queued. It is set by calling setScalingMode. */

int mScalingMode;

//mTransform is the transform identifier that will be used for the next buffer that gets queued. It is set by calling setTransform. uint32_t mTransform; mDefaultWidth is default width of the buffers, regardless of the native_window_set_buffers_dimensions call. uint32_t mDefaultWidth; mDefaultHeight is default height of the buffers, regardless of the native_window_set_buffers_dimensions call. */

uint32_t mDefaultHeight;

/* mUserWidth, if non-zero, is an application-specified override of mDefaultWidth. This is lower priority than the width set by native_window_set_buffers_dimensions. */ uint32_t mUserWidth;

/* mUserHeight, if non-zero, is an application-specified override of mDefaultHeight. This is lower priority than the height set by native_window_set_buffers_dimensions. */

uint32_t mUserHeight;

/*mTransformHint is the transform probably applied to buffers of this window. this is only a hint, actual transform may differ. */

uint32_t mTransformHint;

/* mConsumerRunningBehind whether the consumer is running more than one buffer behind the producer. */

mutable bool mConsumerRunningBehind;

/* mMutex is the mutex used to prevent concurrent access to the member variables of Surface objects. It must be locked whenever the member variables are accessed.

mutable Mutex mMutex;

// must be used from the lock/unlock thread sp<GraphicBuffer> mLockedBuffer;

sp<GraphicBuffer> mPostedBuffer; bool mConnectedToCpu;

// must be accessed from lock/unlock thread only

Region mDirtyRegion;

};

 

It is worth to stress that the buffer operations in Surface is carried out by IGraphiciBufferProducer instance mGraphicBufferProducer, which is assigned in Surface Constructor.

Last note before concluding this post, Surface uses a set of static hook methods to specify the callback function pointes in ANativceWindow.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Understanding Linux Network Internals”(了解Linux网络内部)是一本介绍Linux操作系统网络内部机制的书籍。该书深入介绍了Linux操作系统中网络协议栈的实现原理,以及网络设备驱动程序、套接字接口和网络管理等方面的知识。 该书以理论和实践相结合的方式,系统地介绍了Linux网络协议栈的设计、功能和实现。它从网络硬件驱动程序开始,逐步探讨了数据在不同网络层之间的传输过程,包括数据包的封装、解封装、路由选择和转发等关键步骤。 此外,该书还介绍了Linux内核中关键的网络数据结构、算法和协议。读者可以学习到如何使用套接字编程接口创建网络应用程序,并深入了解每个网络层的功能和工作原理,从而更好地理解Linux操作系统中网络的运行机制。 对于计算机网络相关的开发人员和系统管理员而言,深入了解Linux网络内部机制是非常重要的。通过掌握Linux网络协议栈的实现原理,操作系统和网络应用程序的开发者可以更好地进行网络性能调优、故障排查和安全加固等工作。同时,系统管理员可以更好地监控和管理网络资源,提高网络的可靠性和性能。 总的来说,阅读“Understanding Linux Network Internals”这本书可以帮助读者深入了解Linux操作系统中网络的工作原理和机制,进而提升计算机网络相关领域的技术能力。这对于开发人员和系统管理员来说都是非常有价值的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值