cl: add cl image bo buffer and pool
* CLImageBoBuffer derived from DrmBoBuffer
* CLImageBoData created from cl image and export bo
to DrmBoData
diff --git a/xcore/Makefile.am b/xcore/Makefile.am
index 18e6c98..661eeb7 100644
--- a/xcore/Makefile.am
+++ b/xcore/Makefile.am
@@ -98,6 +98,7 @@
cl_device.cpp \
cl_kernel.cpp \
cl_memory.cpp \
+ cl_image_bo_buffer.cpp \
cl_image_handler.cpp \
cl_image_processor.cpp \
cl_3a_image_processor.cpp \
diff --git a/xcore/buffer_pool.cpp b/xcore/buffer_pool.cpp
index d7640fc..1e36c6d 100644
--- a/xcore/buffer_pool.cpp
+++ b/xcore/buffer_pool.cpp
@@ -90,12 +90,11 @@
{
uint32_t i = 0;
- XCAM_ASSERT (_buf_list.is_empty ());
XCAM_ASSERT (max_count);
SmartLock lock (_mutex);
- for (; i < max_count; ++i) {
+ for (i = _allocated_num; i < max_count; ++i) {
SmartPtr<BufferData> new_data = allocate_data (_buffer_info);
if (!new_data.ptr ())
break;
@@ -112,12 +111,25 @@
XCAM_LOG_WARNING ("BufferPool expect to reserve %d data but only reserved %d", max_count, i);
}
_max_count = i;
- _allocated_num = i;
+ _allocated_num = _max_count;
_started = true;
return true;
}
+bool
+BufferPool::add_data_unsafe (SmartPtr<BufferData> data)
+{
+ if (!data.ptr ())
+ return false;
+
+ _buf_list.push (data);
+ ++_allocated_num;
+
+ XCAM_ASSERT (_allocated_num <= _max_count || !_max_count);
+ return true;
+}
+
SmartPtr<BufferProxy>
BufferPool::get_buffer (const SmartPtr<BufferPool> &self)
{
diff --git a/xcore/buffer_pool.h b/xcore/buffer_pool.h
index 37045ad..c96b6d1 100644
--- a/xcore/buffer_pool.h
+++ b/xcore/buffer_pool.h
@@ -97,6 +97,8 @@
virtual SmartPtr<BufferData> allocate_data (const VideoBufferInfo &buffer_info) = 0;
virtual SmartPtr<BufferProxy> create_buffer_from_data (SmartPtr<BufferData> &data);
+ bool add_data_unsafe (SmartPtr<BufferData> data);
+
private:
void release (SmartPtr<BufferData> &data);
XCAM_DEAD_COPY (BufferPool);
diff --git a/xcore/cl_bo_buffer.cpp b/xcore/cl_image_bo_buffer.cpp
similarity index 91%
rename from xcore/cl_bo_buffer.cpp
rename to xcore/cl_image_bo_buffer.cpp
index 02f359c..f2aedd0 100644
--- a/xcore/cl_bo_buffer.cpp
+++ b/xcore/cl_image_bo_buffer.cpp
@@ -1,5 +1,5 @@
/*
- * cl_bo_buffer.cpp - cl bo buffer
+ * cl_image_bo_buffer.cpp - cl image bo buffer
*
* Copyright (c) 2015 Intel Corporation
*
@@ -18,16 +18,14 @@
* Author: Wind Yuan <feng.yuan@intel.com>
*/
-#ifndef XCAM_CL_BO_BUFFER_H
-#define XCAM_CL_BO_BUFFER_H
-
-#include "cl_bo_buffer.h"
+#include "cl_image_bo_buffer.h"
#include "cl_memory.h"
namespace XCam {
CLImageBoData::CLImageBoData (SmartPtr<DrmDisplay> &display, SmartPtr<CLImage> &image, drm_intel_bo *bo)
: DrmBoData (display, bo)
+ , _image (image)
{
XCAM_ASSERT (image->get_mem_id ());
}
@@ -56,6 +54,8 @@
int32_t mem_fd = -1;
SmartPtr<DrmDisplay> display = get_drm_display ();
drm_intel_bo *bo = NULL;
+ CLImageDesc desc;
+ SmartPtr<CLImageBoData> data;
SmartPtr<CLImage> image = new CLImage2D (_context, info, CL_MEM_READ_WRITE);
XCAM_FAIL_RETURN (
WARNING,
@@ -63,6 +63,7 @@
NULL,
"CLBoBufferPool create image failed");
+ desc = image->get_image_desc ();
mem_fd = image->export_fd ();
XCAM_FAIL_RETURN (
WARNING,
@@ -70,14 +71,14 @@
NULL,
"CLBoBufferPool export image fd failed");
- bo = display->create_drm_bo_from_fd ();
+ bo = display->create_drm_bo_from_fd (mem_fd, desc.size);
XCAM_FAIL_RETURN (
WARNING,
bo,
NULL,
"CLBoBufferPool bind fd to bo failed");
- SmartPtr<CLImageBoData> data = new CLImageBoData (display, image, bo);
+ data = new CLImageBoData (display, image, bo);
XCAM_FAIL_RETURN (
WARNING,
data.ptr (),
diff --git a/xcore/cl_bo_buffer.h b/xcore/cl_image_bo_buffer.h
similarity index 89%
rename from xcore/cl_bo_buffer.h
rename to xcore/cl_image_bo_buffer.h
index 1c647fb..97a41e0 100644
--- a/xcore/cl_bo_buffer.h
+++ b/xcore/cl_image_bo_buffer.h
@@ -1,5 +1,5 @@
/*
- * cl_bo_buffer.h - cl bo buffer
+ * cl_image_bo_buffer.h - cl image bo buffer
*
* Copyright (c) 2015 Intel Corporation
*
@@ -18,18 +18,20 @@
* Author: Wind Yuan <feng.yuan@intel.com>
*/
-#ifndef XCAM_CL_BO_BUFFER_H
-#define XCAM_CL_BO_BUFFER_H
+#ifndef XCAM_CL_IMAGE_BO_BUFFER_H
+#define XCAM_CL_IMAGE_BO_BUFFER_H
#include "xcam_utils.h"
#include "drm_bo_buffer.h"
+#include "cl_memory.h"
+#include "cl_context.h"
namespace XCam {
class CLImageBoData
: public DrmBoData
{
- friend class DrmBoBufferPool;
+ friend class CLBoBufferPool;
public:
private:
@@ -77,4 +79,4 @@
};
-#endif // XCAM_CL_BO_BUFFER_H
+#endif // XCAM_CL_IMAGE_BO_BUFFER_H
diff --git a/xcore/drm_bo_buffer.h b/xcore/drm_bo_buffer.h
index 315443e..54a8bbc 100644
--- a/xcore/drm_bo_buffer.h
+++ b/xcore/drm_bo_buffer.h
@@ -46,8 +46,10 @@
virtual uint8_t *map ();
virtual bool unmap ();
-private:
+protected:
explicit DrmBoData (SmartPtr<DrmDisplay> &display, drm_intel_bo *bo);
+
+private:
XCAM_DEAD_COPY (DrmBoData);
private:
SmartPtr<DrmDisplay> _display;
@@ -64,7 +66,7 @@
virtual ~DrmBoBuffer () {}
drm_intel_bo *get_bo ();
-private:
+protected:
DrmBoBuffer (const VideoBufferInfo &info, const SmartPtr<DrmBoData> &data);
XCAM_DEAD_COPY (DrmBoBuffer);
};
@@ -83,6 +85,10 @@
virtual SmartPtr<BufferData> allocate_data (const VideoBufferInfo &buffer_info);
virtual SmartPtr<BufferProxy> create_buffer_from_data (SmartPtr<BufferData> &data);
+ SmartPtr<DrmDisplay> &get_drm_display () {
+ return _display;
+ }
+
private:
XCAM_DEAD_COPY (DrmBoBufferPool);
@@ -90,7 +96,6 @@
SmartPtr<DrmDisplay> _display;
};
-
};
#endif //XCAM_DRM_BO_BUFFER_H
diff --git a/xcore/drm_display.cpp b/xcore/drm_display.cpp
index 003797e..aebb0f8 100644
--- a/xcore/drm_display.cpp
+++ b/xcore/drm_display.cpp
@@ -414,4 +414,16 @@
return new_bo;
}
+drm_intel_bo *
+DrmDisplay::create_drm_bo_from_fd (int32_t fd, uint32_t size)
+{
+ drm_intel_bo *bo = NULL;
+ XCAM_ASSERT (_buf_manager);
+ bo = drm_intel_bo_gem_create_from_prime (_buf_manager, fd, size);
+
+ XCAM_ASSERT (bo);
+ return bo;
+}
+
+
};
diff --git a/xcore/drm_display.h b/xcore/drm_display.h
index 2ba5774..138418a 100644
--- a/xcore/drm_display.h
+++ b/xcore/drm_display.h
@@ -52,6 +52,7 @@
class DrmDisplay {
friend class DrmBoBufferPool;
+ friend class CLBoBufferPool;
struct FB {
uint32_t fb_handle;
@@ -100,6 +101,7 @@
DrmDisplay (const char* module = NULL);
SmartPtr<DrmBoData> create_drm_bo (SmartPtr<DrmDisplay> &self, const VideoBufferInfo& info);
+ drm_intel_bo *create_drm_bo_from_fd (int32_t fd, uint32_t size);
XCamReturn get_crtc(drmModeRes *res);
XCamReturn get_connector(drmModeRes *res);
diff --git a/xcore/smartptr.h b/xcore/smartptr.h
index baf119f..7ad44b8 100644
--- a/xcore/smartptr.h
+++ b/xcore/smartptr.h
@@ -144,7 +144,7 @@
private:
Obj *_ptr;
- RefCount *_ref;
+ mutable RefCount *_ref;
};
}; // end namespace
diff --git a/xcore/v4l2_buffer_proxy.cpp b/xcore/v4l2_buffer_proxy.cpp
index b5ccb33..d006ab1 100644
--- a/xcore/v4l2_buffer_proxy.cpp
+++ b/xcore/v4l2_buffer_proxy.cpp
@@ -127,9 +127,9 @@
}
const struct v4l2_buffer &
-V4l2BufferProxy::get_v4l2_buf () const
+V4l2BufferProxy::get_v4l2_buf ()
{
- SmartPtr<BufferData> data = get_buffer_data ();
+ SmartPtr<BufferData> &data = get_buffer_data ();
SmartPtr<V4l2Buffer> v4l2_data = data.dynamic_cast_ptr<V4l2Buffer> ();
XCAM_ASSERT (v4l2_data.ptr ());
return v4l2_data->get_buf ();
diff --git a/xcore/v4l2_buffer_proxy.h b/xcore/v4l2_buffer_proxy.h
index 1ccc76a..67a9a4e 100644
--- a/xcore/v4l2_buffer_proxy.h
+++ b/xcore/v4l2_buffer_proxy.h
@@ -109,7 +109,7 @@
}
private:
- const struct v4l2_buffer & get_v4l2_buf () const;
+ const struct v4l2_buffer & get_v4l2_buf ();
void v4l2_format_to_video_info (
const struct v4l2_format &format, VideoBufferInfo &info);