blob: 453943976cd27478815bea755fa5181784a04556 [file] [log] [blame]
Wind Yuan5ddbfd22015-02-10 18:04:09 +08001/*
2 * cl_image_processor.cpp - CL image processor
3 *
4 * Copyright (c) 2015 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20#include "cl_image_processor.h"
21#include "cl_context.h"
22#include "cl_device.h"
23#include "cl_image_handler.h"
24#include "drm_display.h"
25
26namespace XCam {
27
28CLImageProcessor::CLImageProcessor ()
29 : ImageProcessor ("CLImageProcessor")
30{
31 _context = CLDevice::instance ()->get_context ();
32 XCAM_ASSERT (_context.ptr());
33 XCAM_LOG_DEBUG ("CLImageProcessor constructed");
34}
35
36CLImageProcessor::~CLImageProcessor ()
37{
38 XCAM_LOG_DEBUG ("CLImageProcessor destructed");
39}
40
41bool
Wind Yuanffe35592015-02-11 16:05:12 +080042CLImageProcessor::add_handler (SmartPtr<CLImageHandler> &handler)
43{
44 XCAM_ASSERT (handler.ptr ());
45 _handlers.push_back (handler);
46 return true;
47}
48
49
50bool
Wind Yuan5ddbfd22015-02-10 18:04:09 +080051CLImageProcessor::can_process_result (SmartPtr<X3aResult> &result)
52{
53 XCAM_UNUSED (result);
54 return false;
55}
56
57XCamReturn
58CLImageProcessor::apply_3a_results (X3aResultList &results)
59{
60 XCAM_UNUSED (results);
61 return XCAM_RETURN_NO_ERROR;
62}
63
64XCamReturn
65CLImageProcessor::apply_3a_result (SmartPtr<X3aResult> &result)
66{
67 XCAM_UNUSED (result);
68 return XCAM_RETURN_NO_ERROR;
69}
70
71XCamReturn
72CLImageProcessor::process_buffer (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output)
73{
74 SmartPtr<DrmBoBuffer> drm_bo_in, drm_bo_out;
75 XCamReturn ret = XCAM_RETURN_NO_ERROR;
76 SmartPtr<DrmDisplay> display = DrmDisplay::instance ();
77
78 drm_bo_in = display->convert_to_drm_bo_buf (display, input);
79 XCAM_FAIL_RETURN (
80 WARNING,
81 drm_bo_in.ptr (),
82 XCAM_RETURN_ERROR_MEM,
83 "CL image processor can't handle this buffer, maybe type error");
84
85 if (_handlers.empty()) {
86 ret = create_handlers ();
87 }
88
89 for (ImageHandlerList::iterator i_handler = _handlers.begin ();
90 i_handler != _handlers.end (); ++i_handler)
91 {
92 ret = (*i_handler)->execute (drm_bo_in, drm_bo_out);
93 XCAM_FAIL_RETURN (
94 WARNING,
95 ret == XCAM_RETURN_NO_ERROR,
96 ret,
97 "CL image handler(%s) execute buffer failed", (*i_handler)->get_name());
98 drm_bo_in = drm_bo_out;
99 }
100
101 output = drm_bo_out;
102 return XCAM_RETURN_NO_ERROR;
103}
104
105XCamReturn
106CLImageProcessor::create_handlers ()
107{
Wind Yuanffe35592015-02-11 16:05:12 +0800108 SmartPtr<CLImageHandler> demo_handler;
109 SmartPtr<CLImageKernel> demo_kernel;
110 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan5ddbfd22015-02-10 18:04:09 +0800111
Wind Yuanffe35592015-02-11 16:05:12 +0800112 demo_kernel = new CLImageKernel (_context, "kernel_demo");
113 {
114 XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_demo)
115 #include "kernel_demo.cl"
116 XCAM_CL_KERNEL_FUNC_END;
117 ret = demo_kernel->load_from_source (kernel_demo_body, strlen (kernel_demo_body));
118 XCAM_FAIL_RETURN (
119 WARNING,
120 ret == XCAM_RETURN_NO_ERROR,
121 ret,
122 "CL image handler(%s) load source failed", demo_kernel->get_kernel_name());
123 }
124 XCAM_ASSERT (demo_kernel->is_valid ());
125 demo_handler = new CLImageHandler ("cl_handler_demo");
126 demo_handler->add_kernel (demo_kernel);
127 add_handler (demo_handler);
Wind Yuan5ddbfd22015-02-10 18:04:09 +0800128
129 return XCAM_RETURN_ERROR_CL;
130}
131
132};