diff --git a/export/surface/buffer_extra_data.h b/export/surface/buffer_extra_data.h new file mode 100644 index 0000000000000000000000000000000000000000..19001df1a56f05d6851fdc3ee399705fdfcaeb29 --- /dev/null +++ b/export/surface/buffer_extra_data.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H +#define INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H + +#include + +#include +#include "surface_type.h" + +namespace OHOS { +class MessageParcel; +class BufferExtraData : public RefBase { +public: + virtual GSError ReadFromParcel(MessageParcel &parcel) = 0; + virtual GSError WriteToParcel(MessageParcel &parcel) = 0; + virtual GSError ExtraGet(const std::string &key, int32_t &value) const = 0; + virtual GSError ExtraGet(const std::string &key, int64_t &value) const = 0; + virtual GSError ExtraGet(const std::string &key, double &value) const = 0; + virtual GSError ExtraGet(const std::string &key, std::string &value) const = 0; + virtual GSError ExtraSet(const std::string &key, int32_t value) = 0; + virtual GSError ExtraSet(const std::string &key, int64_t value) = 0; + virtual GSError ExtraSet(const std::string &key, double value) = 0; + virtual GSError ExtraSet(const std::string &key, const std::string& value) = 0; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_BUFFER_EXTRA_DATA_H diff --git a/export/surface/egl_data.h b/export/surface/egl_data.h new file mode 100644 index 0000000000000000000000000000000000000000..a5290e79f0528b94cbd0bd36f55caf6c93a737f9 --- /dev/null +++ b/export/surface/egl_data.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_EGL_DATA_H +#define INTERFACES_INNERKITS_SURFACE_EGL_DATA_H + +#include + +namespace OHOS { +class EglData : public RefBase { +public: + virtual ~EglData() = default; + + virtual uint32_t GetFrameBufferObj() const = 0; + virtual uint32_t GetTexture() const = 0; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_EGL_DATA_H diff --git a/export/surface/ibuffer_consumer_listener.h b/export/surface/ibuffer_consumer_listener.h new file mode 100644 index 0000000000000000000000000000000000000000..fd1e7dec608f03050cc493f978550794f6abc2bb --- /dev/null +++ b/export/surface/ibuffer_consumer_listener.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H +#define INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H + +#include +#include "surface_type.h" + +namespace OHOS { +class IBufferConsumerListener : public RefBase { +public: + virtual ~IBufferConsumerListener() = default; + virtual void OnBufferAvailable() = 0; + virtual void OnTunnelHandleChange() {}; + virtual void OnGoBackground() {}; + virtual void OnCleanCache() {}; +}; + +class IBufferConsumerListenerClazz { +public: + virtual ~IBufferConsumerListenerClazz() = default; + virtual void OnBufferAvailable() = 0; + virtual void OnTunnelHandleChange() {}; + virtual void OnGoBackground() {}; + virtual void OnCleanCache() {}; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_IBUFFER_CONSUMER_LISTENER_H diff --git a/export/surface/ibuffer_producer.h b/export/surface/ibuffer_producer.h new file mode 100644 index 0000000000000000000000000000000000000000..8da64a08d5922f7c3796289cfe6ad8a8da162b3f --- /dev/null +++ b/export/surface/ibuffer_producer.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H +#define INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H + +#include +#include + +#include "iremote_broker.h" + +#include "buffer_extra_data.h" +#include "native_surface.h" +#include "surface_buffer.h" +#include "surface_type.h" + +namespace OHOS { +class SyncFence; +class IBufferProducer : public IRemoteBroker { +public: + struct RequestBufferReturnValue { + uint32_t sequence; + sptr buffer; + sptr fence; + std::vector deletingBuffers; + }; + virtual GSError RequestBuffer(const BufferRequestConfig &config, sptr &bedata, + RequestBufferReturnValue &retval) = 0; + + virtual GSError CancelBuffer(uint32_t sequence, const sptr &bedata) = 0; + + virtual GSError FlushBuffer(uint32_t sequence, const sptr &bedata, + const sptr& fence, BufferFlushConfig &config) = 0; + + virtual GSError AttachBuffer(sptr& buffer) = 0; + virtual GSError DetachBuffer(sptr& buffer) = 0; + + virtual uint32_t GetQueueSize() = 0; + virtual GSError SetQueueSize(uint32_t queueSize) = 0; + + virtual GSError GetName(std::string &name) = 0; + virtual uint64_t GetUniqueId() = 0; + virtual GSError GetNameAndUniqueId(std::string& name, uint64_t& uniqueId) = 0; + + virtual int32_t GetDefaultWidth() = 0; + virtual int32_t GetDefaultHeight() = 0; + virtual uint32_t GetDefaultUsage() = 0; + + virtual GSError CleanCache() = 0; + virtual GSError GoBackground() = 0; + + virtual GSError RegisterReleaseListener(OnReleaseFunc func) = 0; + + virtual GSError SetTransform(GraphicTransformType transform) = 0; + + virtual GSError IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) = 0; + + virtual GSError Disconnect() = 0; + + virtual GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) = 0; + virtual GSError SetMetaData(uint32_t sequence, const std::vector &metaData) = 0; + virtual GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, + const std::vector &metaData) = 0; + virtual GSError SetTunnelHandle(const GraphicExtDataHandle *handle) = 0; + virtual GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, int64_t &time) = 0; + + virtual sptr GetNativeSurface() = 0; + + DECLARE_INTERFACE_DESCRIPTOR(u"surf.IBufferProducer"); + +protected: + enum { + BUFFER_PRODUCER_REQUEST_BUFFER = 0, + BUFFER_PRODUCER_CANCEL_BUFFER = 1, + BUFFER_PRODUCER_FLUSH_BUFFER = 2, + BUFFER_PRODUCER_GET_QUEUE_SIZE = 3, + BUFFER_PRODUCER_SET_QUEUE_SIZE = 4, + BUFFER_PRODUCER_GET_NAME = 5, + BUFFER_PRODUCER_GET_DEFAULT_WIDTH = 6, + BUFFER_PRODUCER_GET_DEFAULT_HEIGHT = 7, + BUFFER_PRODUCER_GET_DEFAULT_USAGE = 8, + BUFFER_PRODUCER_CLEAN_CACHE = 9, + BUFFER_PRODUCER_ATTACH_BUFFER = 10, + BUFFER_PRODUCER_DETACH_BUFFER = 11, + BUFFER_PRODUCER_REGISTER_RELEASE_LISTENER = 12, + BUFFER_PRODUCER_GET_UNIQUE_ID = 13, + BUFFER_PRODUCER_SET_TRANSFORM = 14, + BUFFER_PRODUCER_IS_SUPPORTED_ALLOC = 15, + BUFFER_PRODUCER_GET_NAMEANDUNIQUEDID = 16, + BUFFER_PRODUCER_DISCONNECT = 17, + BUFFER_PRODUCER_SET_SCALING_MODE = 18, + BUFFER_PRODUCER_SET_METADATA = 19, + BUFFER_PRODUCER_SET_METADATASET = 20, + BUFFER_PRODUCER_SET_TUNNEL_HANDLE = 21, + BUFFER_PRODUCER_GO_BACKGROUND = 22, + BUFFER_PRODUCER_GET_PRESENT_TIMESTAMP = 23, + }; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_IBUFFER_PRODUCER_H diff --git a/export/surface/native_buffer.h b/export/surface/native_buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..9d746579ee108fb7b271f1eddebb464721b50871 --- /dev/null +++ b/export/surface/native_buffer.h @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef NDK_INCLUDE_NATIVE_BUFFER_H_ +#define NDK_INCLUDE_NATIVE_BUFFER_H_ + +/** + * @addtogroup OH_NativeBuffer + * @{ + * + * @brief Provides the native buffer capability. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @since 9 + * @version 1.0 + */ + +/** + * @file native_buffer.h + * + * @brief Defines the functions for obtaining and using a native buffer. + * + * @since 9 + * @version 1.0 + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct OH_NativeBuffer; +typedef struct OH_NativeBuffer OH_NativeBuffer; + +/** + * @brief OH_NativeBuffer config. \n + * Used to allocating new OH_NativeBuffer andquery parameters if existing ones. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @since 9 + * @version 1.0 + */ +typedef struct { + int32_t width; ///< Width in pixels + int32_t height; ///< Height in pixels + int32_t format; ///< One of PixelFormat + int32_t usage; ///< Combination of buffer usage +} OH_NativeBuffer_Config; + +/** + * @brief Alloc a OH_NativeBuffer that matches the passed BufferRequestConfig. \n + * A new OH_NativeBuffer instance is created each time this function is called. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param config Indicates the pointer to a BufferRequestConfig instance. + * @return Returns the pointer to the OH_NativeBuffer instance created if the operation is successful, \n + * returns NULL otherwise. + * @since 9 + * @version 1.0 + */ +OH_NativeBuffer* OH_NativeBuffer_Alloc(const OH_NativeBuffer_Config* config); + +/** + * @brief Adds the reference count of a OH_NativeBuffer. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @return Returns an error code defined in GSError. + * @since 9 + * @version 1.0 + */ +int32_t OH_NativeBuffer_Reference(OH_NativeBuffer *buffer); + +/** + * @brief Decreases the reference count of a OH_NativeBuffer and, when the reference count reaches 0, \n + * destroys this OH_NativeBuffer. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @return Returns an error code defined in GSError. + * @since 9 + * @version 1.0 + */ +int32_t OH_NativeBuffer_Unreference(OH_NativeBuffer *buffer); + +/** + * @brief Return a config of the OH_NativeBuffer in the passed OHNativeBufferConfig struct. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @param config Indicates the pointer to the NativeBufferConfig of the buffer. + * @return Returns the pointer to the BufferRequestConfig instance if the operation is successful, \n + * returns NULL otherwise. + * @since 9 + * @version 1.0 + */ +void OH_NativeBuffer_GetConfig(OH_NativeBuffer *buffer, OH_NativeBuffer_Config* config); + +/** + * @brief Provide direct cpu access to the OH_NativeBuffer in the process's address space. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @param virAddr Indicates the address of the OH_NativeBuffer in virtual memory. + * @return Returns an error code defined in GSError. + * @since 9 + * @version 1.0 + */ + +int32_t OH_NativeBuffer_Map(OH_NativeBuffer *buffer, void **virAddr); + +/** + * @brief Remove direct cpu access ability of the OH_NativeBuffer in the process's address space. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @return Returns an error code defined in GSError. + * @since 9 + * @version 1.0 + */ +int32_t OH_NativeBuffer_Unmap(OH_NativeBuffer *buffer); + +/** + * @brief Get the systen wide unique sequence number of the OH_NativeBuffer. + * + * @syscap SystemCapability.Graphic.Graphic2D.OH_NativeBuffer + * @param buffer Indicates the pointer to a OH_NativeBuffer instance. + * @return Returns the sequence number, which is unique for each OH_NativeBuffer. + * @since 9 + * @version 1.0 + */ +uint32_t OH_NativeBuffer_GetSeqNum(OH_NativeBuffer *buffer); + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif \ No newline at end of file diff --git a/export/surface/native_surface.h b/export/surface/native_surface.h new file mode 100644 index 0000000000000000000000000000000000000000..4ee1d23c4b1711f48de4798dd250fd87cc7ace1a --- /dev/null +++ b/export/surface/native_surface.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_NATIVE_SURFACE_H +#define INTERFACES_INNERKITS_SURFACE_NATIVE_SURFACE_H + +#include +#include + +namespace OHOS { +class NativeSurface : public RefBase { + friend class SurfaceDelegate; + +public: + /* + * Constructor of native surface. + */ + NativeSurface(); + + /* + * Destructor of native surface. + */ + ~NativeSurface(); + + /* + * Get compat native window. + * + * @return native window. + */ + void* GetNativeWindow(); + + /* + * Get compat native window(for compatbility). + * + * @return native window. + */ + void* Get(); + +private: + /* + * Callback when the compat native window is created. + * + * @param nativeWindow the native window. + */ + void OnNativeWindowCreated(void* nativeWindow); + + /* + * Callback when the compat native window is destroyed. + */ + void OnNativeWindowDestroyed(); + + /* + * Release native window. + */ + void ReleaseNativeWindow(); + + void* nativeWindow_ = nullptr; + + std::condition_variable condVar_; + + std::mutex mutex_; +}; +} // namespace OHOS +#endif // INTERFACES_INNERKITS_SURFACE_NATIVE_SURFACE_H \ No newline at end of file diff --git a/export/surface/surface.h b/export/surface/surface.h new file mode 100644 index 0000000000000000000000000000000000000000..48408608c8461955e1168c3948f8e9385a167dbe --- /dev/null +++ b/export/surface/surface.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_H +#define INTERFACES_INNERKITS_SURFACE_SURFACE_H + +#include + +#include "ibuffer_consumer_listener.h" +#include "ibuffer_producer.h" +#include "surface_buffer.h" +#include "surface_type.h" +#include "surface_tunnel_handle.h" + +namespace OHOS { +class Surface : public RefBase { +public: + static sptr CreateSurfaceAsConsumer(std::string name = "noname", bool isShared = false); + static sptr CreateSurfaceAsProducer(sptr& producer); + + virtual ~Surface() = default; + + virtual bool IsConsumer() const = 0; + virtual sptr GetProducer() const = 0; + + virtual GSError RequestBuffer(sptr& buffer, + int32_t &fence, BufferRequestConfig &config) = 0; + + virtual GSError CancelBuffer(sptr& buffer) = 0; + + virtual GSError FlushBuffer(sptr& buffer, + int32_t fence, BufferFlushConfig &config) = 0; + + virtual GSError AcquireBuffer(sptr& buffer, int32_t &fence, + int64_t ×tamp, Rect &damage) = 0; + virtual GSError ReleaseBuffer(sptr& buffer, int32_t fence) = 0; + + virtual GSError RequestBuffer(sptr& buffer, + sptr& fence, BufferRequestConfig &config) = 0; + virtual GSError FlushBuffer(sptr& buffer, + const sptr& fence, BufferFlushConfig &config) = 0; + virtual GSError AcquireBuffer(sptr& buffer, sptr& fence, + int64_t ×tamp, Rect &damage) = 0; + virtual GSError ReleaseBuffer(sptr& buffer, const sptr& fence) = 0; + + virtual GSError AttachBuffer(sptr& buffer) = 0; + + virtual GSError DetachBuffer(sptr& buffer) = 0; + + virtual uint32_t GetQueueSize() = 0; + virtual GSError SetQueueSize(uint32_t queueSize) = 0; + + virtual GSError SetDefaultWidthAndHeight(int32_t width, int32_t height) = 0; + virtual int32_t GetDefaultWidth() = 0; + virtual int32_t GetDefaultHeight() = 0; + + virtual GSError SetDefaultUsage(uint32_t usage) = 0; + virtual uint32_t GetDefaultUsage() = 0; + + virtual GSError SetUserData(const std::string &key, const std::string &val) = 0; + virtual std::string GetUserData(const std::string &key) = 0; + + virtual const std::string& GetName() = 0; + virtual uint64_t GetUniqueId() const = 0; + + virtual GSError RegisterConsumerListener(sptr& listener) = 0; + virtual GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener) = 0; + virtual GSError RegisterReleaseListener(OnReleaseFunc func) = 0; + virtual GSError RegisterDeleteBufferListener(OnDeleteBufferFunc func) = 0; + virtual GSError UnregisterConsumerListener() = 0; + + // Call carefully. This interface will empty all caches of the current process + virtual GSError CleanCache() = 0; + virtual GSError GoBackground() = 0; + + virtual GSError SetTransform(GraphicTransformType transform) = 0; + virtual GraphicTransformType GetTransform() const = 0; + + virtual GSError IsSupportedAlloc(const std::vector &infos, + std::vector &supporteds) = 0; + virtual GSError Disconnect() = 0; + virtual GSError SetScalingMode(uint32_t sequence, ScalingMode scalingMode) = 0; + virtual GSError GetScalingMode(uint32_t sequence, ScalingMode &scalingMode) = 0; + virtual GSError SetMetaData(uint32_t sequence, const std::vector &metaData) = 0; + virtual GSError SetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey key, + const std::vector &metaData) = 0; + virtual GSError QueryMetaDataType(uint32_t sequence, HDRMetaDataType &type) const = 0; + virtual GSError GetMetaData(uint32_t sequence, std::vector &metaData) const = 0; + virtual GSError GetMetaDataSet(uint32_t sequence, GraphicHDRMetadataKey &key, + std::vector &metaData) const = 0; + virtual GSError SetTunnelHandle(const GraphicExtDataHandle *handle) = 0; + virtual sptr GetTunnelHandle() const = 0; + virtual GSError SetPresentTimestamp(uint32_t sequence, const GraphicPresentTimestamp ×tamp) = 0; + virtual GSError GetPresentTimestamp(uint32_t sequence, GraphicPresentTimestampType type, + int64_t &time) const = 0; + + virtual void Dump(std::string &result) const = 0; + + virtual int32_t GetDefaultFormat() = 0; + virtual GSError SetDefaultFormat(int32_t format) = 0; + virtual int32_t GetDefaultColorGamut() = 0; + virtual GSError SetDefaultColorGamut(int32_t colorGamut) = 0; + + virtual sptr GetNativeSurface() = 0; + +protected: + Surface() = default; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_H diff --git a/export/surface/surface_buffer.h b/export/surface/surface_buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..b876eadba584f14ec80893dc03c5a76fd7b38eac --- /dev/null +++ b/export/surface/surface_buffer.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H +#define INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H + +#include + +#include +#include + +#include "buffer_handle_utils.h" +#include "surface_type.h" +#include "egl_data.h" +#include "buffer_extra_data.h" +#include "native_buffer.h" + +struct BufferWrapper; + +namespace OHOS { +class MessageParcel; +class SurfaceBuffer : public RefBase { +public: + virtual BufferHandle *GetBufferHandle() const = 0; + virtual int32_t GetWidth() const = 0; + virtual int32_t GetHeight() const = 0; + virtual int32_t GetStride() const = 0; + virtual int32_t GetFormat() const = 0; + virtual uint64_t GetUsage() const = 0; + virtual uint64_t GetPhyAddr() const = 0; + virtual int32_t GetKey() const = 0; + virtual void *GetVirAddr() = 0; + virtual int32_t GetFileDescriptor() const = 0; + virtual uint32_t GetSize() const = 0; + + virtual const GraphicColorGamut& GetSurfaceBufferColorGamut() const = 0; + virtual const GraphicTransformType& GetSurfaceBufferTransform() const = 0; + virtual void SetSurfaceBufferColorGamut(const GraphicColorGamut& colorGamut) = 0; + virtual void SetSurfaceBufferTransform(const GraphicTransformType& transform) = 0; + + virtual int32_t GetSurfaceBufferWidth() const = 0; + virtual int32_t GetSurfaceBufferHeight() const = 0; + virtual void SetSurfaceBufferWidth(int32_t width) = 0; + virtual void SetSurfaceBufferHeight(int32_t width) = 0; + + virtual uint32_t GetSeqNum() const = 0; + + // opt EglData + virtual sptr GetEglData() const = 0; + virtual void SetEglData(const sptr& data) = 0; + + virtual void SetExtraData(const sptr &bedata) = 0; + virtual const sptr& GetExtraData() const = 0; + virtual GSError WriteToMessageParcel(MessageParcel &parcel) = 0; + virtual GSError ReadFromMessageParcel(MessageParcel &parcel) = 0; + virtual void SetBufferHandle(BufferHandle *handle) = 0; + + virtual BufferWrapper GetBufferWrapper() = 0; + virtual void SetBufferWrapper(BufferWrapper wrapper) = 0; + + // gralloc + virtual GSError Alloc(const BufferRequestConfig &config) = 0; + virtual GSError Map() = 0; + virtual GSError Unmap() = 0; + virtual GSError FlushCache() = 0; + virtual GSError InvalidateCache() = 0; + + static SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer* buffer) + { + return reinterpret_cast(buffer); + }; + + static const SurfaceBuffer* NativeBufferToSurfaceBuffer(OH_NativeBuffer const* buffer) + { + return reinterpret_cast(buffer); + }; + + virtual OH_NativeBuffer* SurfaceBufferToNativeBuffer() = 0; + +protected: + SurfaceBuffer(){} + SurfaceBuffer(const SurfaceBuffer&) = delete; + SurfaceBuffer& operator=(const SurfaceBuffer&) = delete; + virtual ~SurfaceBuffer(){} +}; + +using OnReleaseFunc = std::function &)>; +using OnDeleteBufferFunc = std::function; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_BUFFER_H diff --git a/export/surface/surface_delegate.h b/export/surface/surface_delegate.h new file mode 100644 index 0000000000000000000000000000000000000000..320ab233427ebb31114f6c8524b2c3b205408ca4 --- /dev/null +++ b/export/surface/surface_delegate.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_DELEGATE_H +#define INTERFACES_INNERKITS_SURFACE_SURFACE_DELEGATE_H + +#include + +#include "surface.h" + +struct NativeSurfaceCallback; + +namespace OHOS { + +enum class SurfaceDelegateError : int32_t { + SURFACE_DELEGATE_ERROR_DEFAULT = -1, + SURFACE_DELEGATE_OK = 0, + SURFACE_DELEGATE_DO_NOTHING = 1, + SURFACE_DELEGATE_ERROR_SAMGR = 100, + SURFACE_DELEGATE_ERROR_IPC_FAILED = 101, + SURFACE_DELEGATE_ERROR_NO_MEM = 110, + SURFACE_DELEGATE_ERROR_NULLPTR = 120, + SURFACE_DELEGATE_ERROR_INVALID_PARAM = 130, + SURFACE_DELEGATE_ERROR_DESTROYED_OBJECT = 140, + SURFACE_DELEGATE_ERROR_DEATH_RECIPIENT = 150, + SURFACE_DELEGATE_ERROR_INVALID_WINDOW = 160, + SURFACE_DELEGATE_ERROR_INVALID_OPERATION = 170, + SURFACE_DELEGATE_ERROR_INVALID_TYPE = 180, + SURFACE_DELEGATE_ERROR_INVALID_PERMISSION = 190, + SURFACE_DELEGATE_ERROR_UNKNOWN, +}; + +class SurfaceDelegate : public RefBase { +public: + /* + * Define callback for the surface lifecycle. + */ + class ISurfaceCallback : virtual public RefBase { + public: + /* + * Callback when the surface was created. + * + * @param surface the surface. + */ + virtual void OnSurfaceCreated(const sptr& surface) = 0; + + /* + * Callback when the surface was changed. + * + * @param surface the surface. + * @param width the surface width. + * @param height the surface height. + */ + virtual void OnSurfaceChanged(const sptr& surface, int32_t width, int32_t height) = 0; + + /* + * Callback when the surface was destroyed. + */ + virtual void OnSurfaceDestroyed() = 0; + }; + + /* + * Add the surface callback. + * + * @param callback the ISurfaceCallback. + */ + void AddSurfaceCallback(const sptr& callback); + + /* + * Remove the surface callback. + * + * @param callback the ISurfaceCallback. + */ + void RemoveSurfaceCallback(const sptr& callback); + + /* + * Constructor of SurfaceDelegate. + * + * @param windowId the window id the surface will be on. + */ + SurfaceDelegate(int windowId); + + /* + * Destructor of SurfaceDelegate. + */ + ~SurfaceDelegate() = default; + + /* + * Create the surface. + * + * @param isWindowSurface if the surface is a window type surface. + * @return the SurfaceDelegateError code. + */ + SurfaceDelegateError CreateSurface(bool isWindowSurface = false); + + /* + * Set the boundaries of the area where the surface is located. + * + * @param left the left of the boundaries. + * @param right the right of the boundaries. + * @param width the width of the boundaries. + * @param height the height of the boundaries. + * @return the SurfaceDelegateError code. + */ + SurfaceDelegateError SetBounds(int32_t left, int32_t right, int32_t width, int32_t height); + + /* + * Release the surface. + * + * @return the SurfaceDelegateError code. + */ + SurfaceDelegateError ReleaseSurface(); + + /* + * Set the surface size. + * + * @param width the surface width. + * @param height the surface height. + * @return the SurfaceDelegateError code. + */ + SurfaceDelegateError SetSurfaceSize(uint32_t width, uint32_t height); + + /* + * Get the surface. + * + * @return the surface. + */ + sptr GetSurface(); + + /* + * Get the native window. + * + * @return the void pointer of the native window. + */ + void* GetNativeWindow(); + +private: + NativeSurfaceCallback CreateNativeSurfaceCallback(); + + sptr GetNativeSurface(); + + void OnSurfaceCreated(uint32_t windowId, uint64_t surfaceId); + void OnSurfaceChanged(uint32_t windowId, uint64_t surfaceId, int32_t width, int32_t height); + void OnSurfaceDestroyed(uint32_t windowId, uint64_t surfaceId); + + void OnNativeSurfaceCreated(void* nativeWindow); + void OnNativeSurfaceDestroyed(); + + sptr surface_ = nullptr; + + std::vector> surfaceCallbacks_; + std::recursive_mutex mutex_; + + int windowId_ = 0; +}; +} // namespace OHOS +#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_DELEGATE_H \ No newline at end of file diff --git a/export/surface/surface_tunnel_handle.h b/export/surface/surface_tunnel_handle.h new file mode 100644 index 0000000000000000000000000000000000000000..e136d08aaa0f8898aceb4f9f678dccecedf14a75 --- /dev/null +++ b/export/surface/surface_tunnel_handle.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef FRAMEWORKS_SURFACE_INCLUDE_SURFACE_TUNNEL_HANDLE_H +#define FRAMEWORKS_SURFACE_INCLUDE_SURFACE_TUNNEL_HANDLE_H +#include +#include +#include +#include "surface_type.h" + +namespace OHOS { +GraphicExtDataHandle *AllocExtDataHandle(uint32_t reserveInts); +void FreeExtDataHandle(GraphicExtDataHandle *handle); +class SurfaceTunnelHandle : public RefBase { +public: + SurfaceTunnelHandle(); + virtual ~SurfaceTunnelHandle(); + GSError SetHandle(const GraphicExtDataHandle *handle); + GraphicExtDataHandle *GetHandle(); + bool Different(const sptr &handle); + +protected: + SurfaceTunnelHandle(const SurfaceTunnelHandle&) = delete; + SurfaceTunnelHandle& operator=(const SurfaceTunnelHandle&) = delete; + +private: + GraphicExtDataHandle *tunnelHandle_ = nullptr; + mutable std::mutex mutex_; +}; +} // namespace OHOS + +#endif // FRAMEWORKS_SURFACE_INCLUDE_SURFACE_TUNNEL_HANDLE_H diff --git a/export/surface/surface_type.h b/export/surface/surface_type.h new file mode 100644 index 0000000000000000000000000000000000000000..fb2df398a159d739149ca8c88d9734c8d3832b2b --- /dev/null +++ b/export/surface/surface_type.h @@ -0,0 +1,377 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H +#define INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H + +#include +#include +#include +#include +#include + +namespace OHOS { +#define SURFACE_MAX_USER_DATA_COUNT 1000 +#define SURFACE_MAX_QUEUE_SIZE 32 +#define SURFACE_DEFAULT_QUEUE_SIZE 3 +#define SURFACE_MAX_STRIDE_ALIGNMENT 32 +#define SURFACE_MIN_STRIDE_ALIGNMENT 4 +#define SURFACE_DEFAULT_STRIDE_ALIGNMENT 4 +#define SURFACE_MAX_SIZE 58982400 // 8K * 8K + +using GraphicDispErrCode = enum { + GRAPHIC_DISPLAY_SUCCESS = 0, /**< Success */ + GRAPHIC_DISPLAY_FAILURE = -1, /**< Failure */ + GRAPHIC_DISPLAY_FD_ERR = -2, /**< File handle (FD) error */ + GRAPHIC_DISPLAY_PARAM_ERR = -3, /**< Parameter error */ + GRAPHIC_DISPLAY_NULL_PTR = -4, /**< Null pointer */ + GRAPHIC_DISPLAY_NOT_SUPPORT = -5, /**< Unsupported feature */ + GRAPHIC_DISPLAY_NOMEM = -6, /**< Insufficient memory */ + GRAPHIC_DISPLAY_SYS_BUSY = -7, /**< System busy */ + GRAPHIC_DISPLAY_NOT_PERM = -8 /**< Forbidden operation */ +}; + +using GraphicCompositionType = enum { + GRAPHIC_COMPOSITION_CLIENT, /**< Client composition type. The composer should be the CPU or GPU. */ + GRAPHIC_COMPOSITION_DEVICE, /**< Device composition type. The composer should be the hardware. */ + GRAPHIC_COMPOSITION_CURSOR, /**< Cursor composition type, used for cursor. */ + GRAPHIC_COMPOSITION_VIDEO, /**< Video composition type, used for video. */ + GRAPHIC_COMPOSITION_DEVICE_CLEAR, /**< Device clear composition type, the device will clear the target region. */ + GRAPHIC_COMPOSITION_CLIENT_CLEAR, /**< Client clear composition type, the service will clear the target region. */ + GRAPHIC_COMPOSITION_TUNNEL, /**< Tunnel composition type, used for tunnel. */ + GRAPHIC_COMPOSITION_BUTT +}; + +using GraphicBlendType = enum { + GRAPHIC_BLEND_NONE = 0, /**< No blending */ + GRAPHIC_BLEND_CLEAR, /**< CLEAR blending */ + GRAPHIC_BLEND_SRC, /**< SRC blending */ + GRAPHIC_BLEND_SRCOVER, /**< SRC_OVER blending */ + GRAPHIC_BLEND_DSTOVER, /**< DST_OVER blending */ + GRAPHIC_BLEND_SRCIN, /**< SRC_IN blending */ + GRAPHIC_BLEND_DSTIN, /**< DST_IN blending */ + GRAPHIC_BLEND_SRCOUT, /**< SRC_OUT blending */ + GRAPHIC_BLEND_DSTOUT, /**< DST_OUT blending */ + GRAPHIC_BLEND_SRCATOP, /**< SRC_ATOP blending */ + GRAPHIC_BLEND_DSTATOP, /**< DST_ATOP blending */ + GRAPHIC_BLEND_ADD, /**< ADD blending */ + GRAPHIC_BLEND_XOR, /**< XOR blending */ + GRAPHIC_BLEND_DST, /**< DST blending */ + GRAPHIC_BLEND_AKS, /**< AKS blending */ + GRAPHIC_BLEND_AKD, /**< AKD blending */ + GRAPHIC_BLEND_BUTT /**< Null operation */ +}; + +using GraphicPixelFormat = enum { + GRAPHIC_PIXEL_FMT_CLUT8 = 0, /**< CLUT8 format */ + GRAPHIC_PIXEL_FMT_CLUT1, /**< CLUT1 format */ + GRAPHIC_PIXEL_FMT_CLUT4, /**< CLUT4 format */ + GRAPHIC_PIXEL_FMT_RGB_565, /**< RGB565 format */ + GRAPHIC_PIXEL_FMT_RGBA_5658, /**< RGBA5658 format */ + GRAPHIC_PIXEL_FMT_RGBX_4444, /**< RGBX4444 format */ + GRAPHIC_PIXEL_FMT_RGBA_4444, /**< RGBA4444 format */ + GRAPHIC_PIXEL_FMT_RGB_444, /**< RGB444 format */ + GRAPHIC_PIXEL_FMT_RGBX_5551, /**< RGBX5551 format */ + GRAPHIC_PIXEL_FMT_RGBA_5551, /**< RGBA5551 format */ + GRAPHIC_PIXEL_FMT_RGB_555, /**< RGB555 format */ + GRAPHIC_PIXEL_FMT_RGBX_8888, /**< RGBX8888 format */ + GRAPHIC_PIXEL_FMT_RGBA_8888, /**< RGBA8888 format */ + GRAPHIC_PIXEL_FMT_RGB_888, /**< RGB888 format */ + GRAPHIC_PIXEL_FMT_BGR_565, /**< BGR565 format */ + GRAPHIC_PIXEL_FMT_BGRX_4444, /**< BGRX4444 format */ + GRAPHIC_PIXEL_FMT_BGRA_4444, /**< BGRA4444 format */ + GRAPHIC_PIXEL_FMT_BGRX_5551, /**< BGRX5551 format */ + GRAPHIC_PIXEL_FMT_BGRA_5551, /**< BGRA5551 format */ + GRAPHIC_PIXEL_FMT_BGRX_8888, /**< BGRX8888 format */ + GRAPHIC_PIXEL_FMT_BGRA_8888, /**< BGRA8888 format */ + GRAPHIC_PIXEL_FMT_YUV_422_I, /**< YUV422 interleaved format */ + GRAPHIC_PIXEL_FMT_YCBCR_422_SP, /**< YCBCR422 semi-planar format */ + GRAPHIC_PIXEL_FMT_YCRCB_422_SP, /**< YCRCB422 semi-planar format */ + GRAPHIC_PIXEL_FMT_YCBCR_420_SP, /**< YCBCR420 semi-planar format */ + GRAPHIC_PIXEL_FMT_YCRCB_420_SP, /**< YCRCB420 semi-planar format */ + GRAPHIC_PIXEL_FMT_YCBCR_422_P, /**< YCBCR422 planar format */ + GRAPHIC_PIXEL_FMT_YCRCB_422_P, /**< YCRCB422 planar format */ + GRAPHIC_PIXEL_FMT_YCBCR_420_P, /**< YCBCR420 planar format */ + GRAPHIC_PIXEL_FMT_YCRCB_420_P, /**< YCRCB420 planar format */ + GRAPHIC_PIXEL_FMT_YUYV_422_PKG, /**< YUYV422 packed format */ + GRAPHIC_PIXEL_FMT_UYVY_422_PKG, /**< UYVY422 packed format */ + GRAPHIC_PIXEL_FMT_YVYU_422_PKG, /**< YVYU422 packed format */ + GRAPHIC_PIXEL_FMT_VYUY_422_PKG, /**< VYUY422 packed format */ + GRAPHIC_PIXEL_FMT_VENDER_MASK = 0X7FFF0000, /**< vendor mask format */ + GRAPHIC_PIXEL_FMT_BUTT = 0X7FFFFFFF /**< Invalid pixel format */ +}; + +using GraphicLayerType = enum { + GRAPHIC_LAYER_TYPE_GRAPHIC, /**< Graphic layer */ + GRAPHIC_LAYER_TYPE_OVERLAY, /**< Overlay layer */ + GRAPHIC_LAYER_TYPE_SDIEBAND, /**< Sideband layer */ + GRAPHIC_LAYER_TYPE_CURSOR, /**< Cursor Layer */ + GRAPHIC_LAYER_TYPE_BUTT /**< Empty layer */ +}; + +using GraphicLayerAlpha = struct { + bool enGlobalAlpha; /**< Global alpha enable bit */ + bool enPixelAlpha; /**< Pixel alpha enable bit */ + uint8_t alpha0; /**< Alpha0 value, ranging from 0 to 255 */ + uint8_t alpha1; /**< Alpha1 value, ranging from 0 to 255 */ + uint8_t gAlpha; /**< Global alpha value, ranging from 0 to 255 */ +}; + +using GraphicLayerInfo = struct { + int32_t width; /**< Layer width */ + int32_t height; /**< Layer height */ + GraphicLayerType type; /**< Layer type, which can be a graphic layer, overlay layer, or sideband layer */ + int32_t bpp; /**< Number of bits occupied by each pixel */ + GraphicPixelFormat pixFormat; /**< Pixel format of the layer */ +}; + +using Rect = struct { + int32_t x; + int32_t y; + int32_t w; + int32_t h; +}; + +using BufferAllocInfo = struct { + uint32_t width; /**< Width of the requested memory */ + uint32_t height; /**< Height of the requested memory */ + uint64_t usage; /**< Usage of the requested memory */ + GraphicPixelFormat format; /**< Format of the requested memory */ + uint32_t expectedSize; /**< Size assigned by memory requester */ +}; + + +using BufferVerifyAllocInfo = struct { + uint32_t width; /**< Width of the memory to allocate */ + uint32_t height; /**< Height of the memory to allocate */ + uint64_t usage; /**< Usage of the memory */ + GraphicPixelFormat format; /**< Format of the memory to allocate */ +}; + +using GraphicPresentTimestampType = enum { + GRAPHIC_DISPLAY_PTS_UNSUPPORTED = 0, /**< Unsupported */ + GRAPHIC_DISPLAY_PTS_DELAY = 1 << 0, /**< Delay */ + GRAPHIC_DISPLAY_PTS_TIMESTAMP = 1 << 1, /**< Timestamp */ +}; + +using GraphicPresentTimestamp = struct { + GraphicPresentTimestampType type; /**< Present timestamp type */ + int64_t time; /**< Present timestamp value */ +}; + +using ScalingMode = enum { + SCALING_MODE_FREEZE = 0, + SCALING_MODE_SCALE_TO_WINDOW, + SCALING_MODE_SCALE_CROP, + SCALING_MODE_NO_SCALE_CROP, +}; + +using HDRMetaDataType = enum { + HDR_NOT_USED = 0, + HDR_META_DATA, + HDR_META_DATA_SET, +}; + +using GraphicHDRMetadataKey = enum { + GRAPHIC_MATAKEY_RED_PRIMARY_X = 0, + GRAPHIC_MATAKEY_RED_PRIMARY_Y = 1, + GRAPHIC_MATAKEY_GREEN_PRIMARY_X = 2, + GRAPHIC_MATAKEY_GREEN_PRIMARY_Y = 3, + GRAPHIC_MATAKEY_BLUE_PRIMARY_X = 4, + GRAPHIC_MATAKEY_BLUE_PRIMARY_Y = 5, + GRAPHIC_MATAKEY_WHITE_PRIMARY_X = 6, + GRAPHIC_MATAKEY_WHITE_PRIMARY_Y = 7, + GRAPHIC_MATAKEY_MAX_LUMINANCE = 8, + GRAPHIC_MATAKEY_MIN_LUMINANCE = 9, + GRAPHIC_MATAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, + GRAPHIC_MATAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, + GRAPHIC_MATAKEY_HDR10_PLUS = 12, + GRAPHIC_MATAKEY_HDR_VIVID = 13, +}; + +using GraphicHDRMetaDataSet = struct GraphicHDRMetaDataSet { + GraphicHDRMetadataKey key = GraphicHDRMetadataKey::GRAPHIC_MATAKEY_RED_PRIMARY_X; + std::vector metaData; +}; + +typedef struct { + GraphicHDRMetadataKey key; + float value; +} GraphicHDRMetaData; + +using SurfaceBufferUsage = enum { + BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ + BUFFER_USAGE_CPU_WRITE = (1ULL << 1), /**< CPU write memory */ + BUFFER_USAGE_MEM_MMZ = (1ULL << 2), /**< Media memory zone (MMZ) */ + BUFFER_USAGE_MEM_DMA = (1ULL << 3), /**< Direct memory access (DMA) buffer */ + BUFFER_USAGE_MEM_SHARE = (1ULL << 4), /**< Shared memory buffer*/ + BUFFER_USAGE_MEM_MMZ_CACHE = (1ULL << 5), /**< MMZ with cache*/ + BUFFER_USAGE_MEM_FB = (1ULL << 6), /**< Framebuffer */ + BUFFER_USAGE_ASSIGN_SIZE = (1ULL << 7), /**< Memory assigned */ + BUFFER_USAGE_HW_RENDER = (1ULL << 8), /**< For GPU write case */ + BUFFER_USAGE_HW_TEXTURE = (1ULL << 9), /**< For GPU read case */ + BUFFER_USAGE_HW_COMPOSER = (1ULL << 10), /**< For hardware composer */ + BUFFER_USAGE_PROTECTED = (1ULL << 11), /**< For safe buffer case, such as DRM */ + BUFFER_USAGE_CAMERA_READ = (1ULL << 12), /**< For camera read case */ + BUFFER_USAGE_CAMERA_WRITE = (1ULL << 13), /**< For camera write case */ + BUFFER_USAGE_VIDEO_ENCODER = (1ULL << 14), /**< For encode case */ + BUFFER_USAGE_VIDEO_DECODER = (1ULL << 15), /**< For decode case */ + BUFFER_USAGE_VENDOR_PRI0 = (1ULL << 44), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI1 = (1ULL << 45), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI2 = (1ULL << 46), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI3 = (1ULL << 47), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI4 = (1ULL << 48), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI5 = (1ULL << 49), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI6 = (1ULL << 50), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI7 = (1ULL << 51), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI8 = (1ULL << 52), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI9 = (1ULL << 53), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI10 = (1ULL << 54), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI11 = (1ULL << 55), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI12 = (1ULL << 56), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI13 = (1ULL << 57), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI14 = (1ULL << 58), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI15 = (1ULL << 59), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI16 = (1ULL << 60), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI17 = (1ULL << 61), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI18 = (1ULL << 62), /**< Reserverd for vendor */ + BUFFER_USAGE_VENDOR_PRI19 = (1ULL << 63), /**< Reserverd for vendor */ +}; + +using GraphicColorGamut = enum { + GRAPHIC_COLOR_GAMUT_INVALID = -1, /**< Invalid */ + GRAPHIC_COLOR_GAMUT_NATIVE = 0, /**< Native or default */ + GRAPHIC_COLOR_GAMUT_STANDARD_BT601 = 1, /**< Standard BT601 */ + GRAPHIC_COLOR_GAMUT_STANDARD_BT709 = 2, /**< Standard BT709 */ + GRAPHIC_COLOR_GAMUT_DCI_P3 = 3, /**< DCI P3 */ + GRAPHIC_COLOR_GAMUT_SRGB = 4, /**< SRGB */ + GRAPHIC_COLOR_GAMUT_ADOBE_RGB = 5, /**< Adobe RGB */ + GRAPHIC_COLOR_GAMUT_DISPLAY_P3 = 6, /**< display P3 */ + GRAPHIC_COLOR_GAMUT_BT2020 = 7, /**< BT2020 */ + GRAPHIC_COLOR_GAMUT_BT2100_PQ = 8, /**< BT2100 PQ */ + GRAPHIC_COLOR_GAMUT_BT2100_HLG = 9, /**< BT2100 HLG */ + GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020 = 10, /**< Display BT2020 */ +}; + +using GraphicColorDataSpace = enum { + GRAPHIC_COLOR_DATA_SPACE_UNKNOWN = 0, + GRAPHIC_GAMUT_BT601 = 0x00000001, + GRAPHIC_GAMUT_BT709 = 0x00000002, + GRAPHIC_GAMUT_DCI_P3 = 0x00000003, + GRAPHIC_GAMUT_SRGB = 0x00000004, + GRAPHIC_GAMUT_ADOBE_RGB = 0x00000005, + GRAPHIC_GAMUT_DISPLAY_P3 = 0x00000006, + GRAPHIC_GAMUT_BT2020 = 0x00000007, + GRAPHIC_GAMUT_BT2100_PQ = 0x00000008, + GRAPHIC_GAMUT_BT2100_HLG = 0x00000009, + GRAPHIC_GAMUT_DISPLAY_BT2020 = 0x0000000a, + GRAPHIC_TRANSFORM_FUNC_UNSPECIFIED = 0x00000100, + GRAPHIC_TRANSFORM_FUNC_LINEAR = 0x00000200, + GRAPHIC_TRANSFORM_FUNC_SRGB = 0x00000300, + GRAPHIC_TRANSFORM_FUNC_SMPTE_170M = 0x00000400, + GRAPHIC_TRANSFORM_FUNC_GM2_2 = 0x00000500, + GRAPHIC_TRANSFORM_FUNC_GM2_6 = 0x00000600, + GRAPHIC_TRANSFORM_FUNC_GM2_8 = 0x00000700, + GRAPHIC_TRANSFORM_FUNC_ST2084 = 0x00000800, + GRAPHIC_TRANSFORM_FUNC_HLG = 0x00000900, + GRAPHIC_PRECISION_UNSPECIFIED = 0x00010000, + GRAPHIC_PRECISION_FULL = 0x00020000, + GRAPHIC_PRESION_LIMITED = 0x00030000, + GRAPHIC_PRESION_EXTENDED = 0x00040000, + GRAPHIC_BT601_SMPTE170M_FULL = GRAPHIC_GAMUT_BT601 | GRAPHIC_TRANSFORM_FUNC_SMPTE_170M | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT601_SMPTE170M_LIMITED = GRAPHIC_GAMUT_BT601 | GRAPHIC_TRANSFORM_FUNC_SMPTE_170M | GRAPHIC_PRESION_LIMITED, + GRAPHIC_BT709_LINEAR_FULL = GRAPHIC_GAMUT_BT709 | GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT709_LINEAR_EXTENDED = GRAPHIC_GAMUT_BT709 | GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRESION_EXTENDED, + GRAPHIC_BT709_SRGB_FULL = GRAPHIC_GAMUT_BT709 | GRAPHIC_TRANSFORM_FUNC_SRGB | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT709_SRGB_EXTENDED = GRAPHIC_GAMUT_BT709 | GRAPHIC_TRANSFORM_FUNC_SRGB | GRAPHIC_PRESION_EXTENDED, + GRAPHIC_BT709_SMPTE170M_LIMITED = GRAPHIC_GAMUT_BT709 | GRAPHIC_TRANSFORM_FUNC_SMPTE_170M | GRAPHIC_PRESION_LIMITED, + GRAPHIC_DCI_P3_LINEAR_FULL = GRAPHIC_GAMUT_DCI_P3 | GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRECISION_FULL, + GRAPHIC_DCI_P3_GAMMA26_FULL = GRAPHIC_GAMUT_DCI_P3 | GRAPHIC_TRANSFORM_FUNC_GM2_6 | GRAPHIC_PRECISION_FULL, + GRAPHIC_DISPLAY_P3_LINEAR_FULL = GRAPHIC_GAMUT_DISPLAY_P3 | GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRECISION_FULL, + GRAPHIC_DCI_P3_SRGB_FULL = GRAPHIC_GAMUT_DCI_P3 | GRAPHIC_TRANSFORM_FUNC_SRGB | GRAPHIC_PRECISION_FULL, + GRAPHIC_ADOBE_RGB_GAMMA22_FULL = GRAPHIC_GAMUT_ADOBE_RGB | GRAPHIC_TRANSFORM_FUNC_GM2_2 | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_LINEAR_FULL = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_LINEAR | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_SRGB_FULL = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_SRGB | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_SMPTE170M_FULL = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_SMPTE_170M | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_ST2084_FULL = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_ST2084 | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_HLG_FULL = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_HLG | GRAPHIC_PRECISION_FULL, + GRAPHIC_BT2020_ST2084_LIMITED = GRAPHIC_GAMUT_BT2020 | GRAPHIC_TRANSFORM_FUNC_ST2084 | GRAPHIC_PRESION_LIMITED, +}; + +using GraphicTransformType = enum { + GRAPHIC_ROTATE_NONE = 0, /**< No rotation */ + GRAPHIC_ROTATE_90, /**< Rotation by 90 degrees */ + GRAPHIC_ROTATE_180, /**< Rotation by 180 degrees */ + GRAPHIC_ROTATE_270, /**< Rotation by 270 degrees */ + GRAPHIC_FLIP_H, /**< Flip horizontally */ + GRAPHIC_FLIP_V, /**< Flip vertically */ + GRAPHIC_FLIP_H_ROT90, /**< Flip horizontally and rotate 90 degrees */ + GRAPHIC_FLIP_V_ROT90, /**< Flip vertically and rotate 90 degrees */ + GRAPHIC_FLIP_H_ROT180, /**< Flip horizontally and rotate 180 degrees */ + GRAPHIC_FLIP_V_ROT180, /**< Flip vertically and rotate 180 degrees */ + GRAPHIC_FLIP_H_ROT270, /**< Flip horizontally and rotate 270 degrees */ + GRAPHIC_FLIP_V_ROT270, /**< Flip vertically and rotate 270 degrees */ + GRAPHIC_ROTATE_BUTT /**< Invalid operation */ +}; + +using BufferRequestConfig = struct BufferRequestConfig { + int32_t width; + int32_t height; + int32_t strideAlignment; + int32_t format; // PixelFormat + uint64_t usage; + int32_t timeout; + GraphicColorGamut colorGamut = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; + GraphicTransformType transform = GraphicTransformType::GRAPHIC_ROTATE_NONE; + bool operator ==(const struct BufferRequestConfig &config) const + { + return width == config.width && + height == config.height && + strideAlignment == config.strideAlignment && + format == config.format && + usage == config.usage && + timeout == config.timeout && + colorGamut == config.colorGamut && + transform == config.transform; + } + bool operator != (const struct BufferRequestConfig &config) const + { + return !(*this == config); + } +}; + +using BufferFlushConfig = struct { + Rect damage; + int64_t timestamp; +}; + +using SceneType = enum { + SURFACE_SCENE_TYPE_EGL = 0, + SURFACE_SCENE_TYPE_MEDIA, + SURFACE_SCENE_TYPE_CAMERA, + SURFACE_SCENE_TYPE_CPU, +}; + +using GraphicExtDataHandle = struct { + /**< Handle fd, -1 if not supported */ + int32_t fd; + /**< the number of reserved integer value */ + uint32_t reserveInts; + /**< the reserved data */ + int32_t reserve[0]; +}; + +} // namespace OHOS +#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_TYPE_H diff --git a/export/surface/surface_utils.h b/export/surface/surface_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..f33a4c3ee1071ff19bc1dfb4741dbf7e26769d25 --- /dev/null +++ b/export/surface/surface_utils.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H +#define INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H + +#include +#include +#include "surface.h" + +namespace OHOS { +class SurfaceUtils { +public: + static SurfaceUtils* GetInstance(); + + // get surface by uniqueId. + sptr GetSurface(uint64_t uniqueId); + // maintenance map with uniqueId and surface. + SurfaceError Add(uint64_t uniqueId, const sptr &surface); + // remove surface by uniqueId. + SurfaceError Remove(uint64_t uniqueId); + +private: + SurfaceUtils() = default; + virtual ~SurfaceUtils(); + + std::unordered_map> surfaceCache_; + std::mutex mutex_; +}; +} // namespace OHOS + +#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H