1 /*
2 * cl_multi_image_handler.cpp - CL multi-image handler
3 *
4 * Copyright (c) 2016 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
21 #include "cl_multi_image_handler.h"
22 #if ENABLE_PROFILING
23 #include "cl_device.h"
24 #endif
25
26 namespace XCam {
27
CLMultiImageHandler(const SmartPtr<CLContext> & context,const char * name)28 CLMultiImageHandler::CLMultiImageHandler (const SmartPtr<CLContext> &context, const char *name)
29 : CLImageHandler (context, name)
30 {
31 }
32
~CLMultiImageHandler()33 CLMultiImageHandler::~CLMultiImageHandler ()
34 {
35 _handler_list.clear ();
36 }
37
38 bool
add_image_handler(SmartPtr<CLImageHandler> & handler)39 CLMultiImageHandler::add_image_handler (SmartPtr<CLImageHandler> &handler)
40 {
41 _handler_list.push_back (handler);
42 return append_kernels (handler);
43 }
44
45 XCamReturn
execute_kernels()46 CLMultiImageHandler::execute_kernels ()
47 {
48 XCamReturn ret = XCAM_RETURN_NO_ERROR;
49
50 for (KernelList::iterator i_kernel = _kernels.begin ();
51 i_kernel != _kernels.end (); ++i_kernel) {
52 SmartPtr<CLImageKernel> &kernel = *i_kernel;
53 XCAM_FAIL_RETURN (WARNING, kernel.ptr(), ret, "kernel empty");
54
55 if (!kernel->is_enabled ())
56 continue;
57
58 ret = execute_kernel (kernel);
59
60 XCAM_FAIL_RETURN (
61 WARNING,
62 (ret == XCAM_RETURN_NO_ERROR || ret == XCAM_RETURN_BYPASS), ret,
63 "cl_multi_image_handler(%s) execute kernel(%s) failed",
64 XCAM_STR (_name), kernel->get_kernel_name ());
65
66 if (ret != XCAM_RETURN_NO_ERROR)
67 break;
68
69 for (HandlerList::iterator i_handler = _handler_list.begin ();
70 i_handler != _handler_list.end (); ++i_handler) {
71 SmartPtr<CLImageHandler> &sub_handler = *i_handler;
72 XCAM_ASSERT (sub_handler.ptr ());
73
74 SmartPtr<CLImageKernel> &sub_handler_last_kernel = *(sub_handler->_kernels.rbegin());
75 XCAM_ASSERT (sub_handler_last_kernel.ptr ());
76 if (sub_handler_last_kernel.ptr () == kernel.ptr ()) {
77 sub_handler->reset_buf_cache (NULL, NULL);
78 sub_handler_execute_done (sub_handler);
79 break;
80 }
81 }
82 }
83
84 return ret;
85 }
86
87 XCamReturn
ensure_handler_parameters(const SmartPtr<CLImageHandler> & handler,SmartPtr<VideoBuffer> & input,SmartPtr<VideoBuffer> & output)88 CLMultiImageHandler::ensure_handler_parameters (
89 const SmartPtr<CLImageHandler> &handler, SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output)
90 {
91 XCAM_ASSERT (handler.ptr ());
92 return handler->ensure_parameters (input, output);
93 }
94
95 XCamReturn
prepare_parameters(SmartPtr<VideoBuffer> & input,SmartPtr<VideoBuffer> & output)96 CLMultiImageHandler::prepare_parameters (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output)
97 {
98 for (HandlerList::iterator i_handler = _handler_list.begin ();
99 i_handler != _handler_list.end (); ++i_handler) {
100 SmartPtr<CLImageHandler> &handler = *i_handler;
101 XCAM_ASSERT (handler.ptr ());
102 XCamReturn ret = ensure_handler_parameters (handler, input, output);
103
104 XCAM_FAIL_RETURN (
105 WARNING,
106 ret == XCAM_RETURN_NO_ERROR,
107 ret,
108 "CLMultiImageHandler(%s) prepare parameters failed on handler(%s)",
109 XCAM_STR (get_name ()), XCAM_STR (handler->get_name ()));
110 }
111 return XCAM_RETURN_NO_ERROR;
112 }
113
114 XCamReturn
execute_done(SmartPtr<VideoBuffer> & output)115 CLMultiImageHandler::execute_done (SmartPtr<VideoBuffer> &output)
116 {
117 for (HandlerList::iterator i_handler = _handler_list.begin ();
118 i_handler != _handler_list.end (); ++i_handler) {
119 SmartPtr<CLImageHandler> &handler = *i_handler;
120 XCAM_ASSERT (handler.ptr ());
121
122 XCamReturn ret = handler->execute_done (output);
123 if (ret == XCAM_RETURN_BYPASS)
124 return ret;
125
126 XCAM_FAIL_RETURN (
127 WARNING,
128 ret == XCAM_RETURN_NO_ERROR,
129 ret,
130 "CLMultiImageHandler(%s) execute buffer done failed on handler(%s)",
131 XCAM_STR (get_name ()), XCAM_STR (handler->get_name ()));
132 }
133 return XCAM_RETURN_NO_ERROR;
134 }
135
136 XCamReturn
sub_handler_execute_done(SmartPtr<CLImageHandler> & handler)137 CLMultiImageHandler::sub_handler_execute_done (SmartPtr<CLImageHandler> &handler)
138 {
139 XCAM_UNUSED (handler);
140 return XCAM_RETURN_NO_ERROR;
141 }
142
143 }
144
145