blob: fc0cdaab0cdf21b9e43016f0b157f2f61fa57485 [file] [log] [blame]
wangfei11987462015-03-12 15:02:57 +08001/*
2 * cl_hdr_handler.cpp - CL hdr handler
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: wangfei <feix.w.wang@intel.com>
19 */
20#include "xcam_utils.h"
21#include "cl_hdr_handler.h"
22
23namespace XCam {
24
25CLHdrImageKernel::CLHdrImageKernel (SmartPtr<CLContext> &context)
26 : CLImageKernel (context, "kernel_hdr")
27{
28}
29
30XCamReturn
31CLHdrImageKernel::prepare_arguments (
32 SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output,
33 CLArgument args[], uint32_t &arg_count,
34 CLWorkSize &work_size)
35{
36 SmartPtr<CLContext> context = get_context ();
37 const VideoBufferInfo & video_info = input->get_video_info ();
38 cl_libva_image image_info;
39 uint32_t channel_bits = XCAM_ALIGN_UP (video_info.color_bits, 8);
40
41 xcam_mem_clear (&image_info);
42 image_info.fmt.image_channel_order = CL_R;
43 if (channel_bits == 8)
44 image_info.fmt.image_channel_data_type = CL_UNORM_INT8;
45 else if (channel_bits == 16)
46 image_info.fmt.image_channel_data_type = CL_UNORM_INT16;
47 image_info.offset = 0;
48 image_info.width = video_info.width;
49 image_info.height = (video_info.size / video_info.strides[0])/4*4;
50 image_info.row_pitch = video_info.strides[0];
51
52 _image_in = new CLVaImage (context, input, &image_info);
53 _image_out = new CLVaImage (context, output, &image_info);
54
55 XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ());
56 XCAM_FAIL_RETURN (
57 WARNING,
58 _image_in->is_valid () && _image_out->is_valid (),
59 XCAM_RETURN_ERROR_MEM,
60 "cl image kernel(%s) in/out memory not available", get_kernel_name ());
61
62 //set args;
63 args[0].arg_adress = &_image_in->get_mem_id ();
64 args[0].arg_size = sizeof (cl_mem);
65 args[1].arg_adress = &_image_out->get_mem_id ();
66 args[1].arg_size = sizeof (cl_mem);
67 arg_count = 2;
68
69 work_size.dim = XCAM_DEFAULT_IMAGE_DIM;
70 work_size.global[0] = image_info.row_pitch;
71 work_size.global[1] = image_info.height;
72 work_size.local[0] = 8;
73 work_size.local[1] = 4;
74
75 return XCAM_RETURN_NO_ERROR;
76}
77
78
79XCamReturn
80CLHdrImageKernel::post_execute ()
81{
82 return CLImageKernel::post_execute ();
83}
84
85SmartPtr<CLImageHandler>
86create_cl_hdr_image_handler (SmartPtr<CLContext> &context)
87{
88 SmartPtr<CLImageHandler> hdr_handler;
89 SmartPtr<CLImageKernel> hdr_kernel;
90 XCamReturn ret = XCAM_RETURN_NO_ERROR;
91
92 hdr_kernel = new CLHdrImageKernel (context);
93 {
94 XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_hdr)
95#include "kernel_hdr.cl"
96 XCAM_CL_KERNEL_FUNC_END;
97 ret = hdr_kernel->load_from_source (kernel_hdr_body, strlen (kernel_hdr_body));
98 XCAM_FAIL_RETURN (
99 WARNING,
100 ret == XCAM_RETURN_NO_ERROR,
101 NULL,
102 "CL image handler(%s) load source failed", hdr_kernel->get_kernel_name());
103 }
104 XCAM_ASSERT (hdr_kernel->is_valid ());
105 hdr_handler = new CLImageHandler ("cl_handler_hdr");
106 hdr_handler->add_kernel (hdr_kernel);
107
108 return hdr_handler;
109}
110
111};