blob: 8cf30c8f9020307d8557a4a99c772ca824a4c712 [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"
Wind Yuan87926782015-02-15 15:53:15 +080025#include "cl_demo_handler.h"
ShincyTu5710f972015-03-23 23:20:44 +080026#include "cl_blc_handler.h"
27
Wind Yuan5ddbfd22015-02-10 18:04:09 +080028
29namespace XCam {
30
Wind Yuand50fde62015-03-25 17:43:49 +080031CLImageProcessor::CLImageProcessor (const char* name)
32 : ImageProcessor (name ? name : "CLImageProcessor")
Wind Yuan5ddbfd22015-02-10 18:04:09 +080033{
34 _context = CLDevice::instance ()->get_context ();
35 XCAM_ASSERT (_context.ptr());
36 XCAM_LOG_DEBUG ("CLImageProcessor constructed");
37}
38
39CLImageProcessor::~CLImageProcessor ()
40{
41 XCAM_LOG_DEBUG ("CLImageProcessor destructed");
42}
43
44bool
Wind Yuanffe35592015-02-11 16:05:12 +080045CLImageProcessor::add_handler (SmartPtr<CLImageHandler> &handler)
46{
47 XCAM_ASSERT (handler.ptr ());
48 _handlers.push_back (handler);
49 return true;
50}
51
Wind Yuand50fde62015-03-25 17:43:49 +080052SmartPtr<CLContext>
53CLImageProcessor::get_cl_context ()
54{
55 return _context;
56}
Wind Yuanffe35592015-02-11 16:05:12 +080057
58bool
Wind Yuan5ddbfd22015-02-10 18:04:09 +080059CLImageProcessor::can_process_result (SmartPtr<X3aResult> &result)
60{
61 XCAM_UNUSED (result);
62 return false;
63}
64
65XCamReturn
66CLImageProcessor::apply_3a_results (X3aResultList &results)
67{
68 XCAM_UNUSED (results);
69 return XCAM_RETURN_NO_ERROR;
70}
71
72XCamReturn
73CLImageProcessor::apply_3a_result (SmartPtr<X3aResult> &result)
74{
75 XCAM_UNUSED (result);
76 return XCAM_RETURN_NO_ERROR;
77}
78
79XCamReturn
80CLImageProcessor::process_buffer (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output)
81{
82 SmartPtr<DrmBoBuffer> drm_bo_in, drm_bo_out;
83 XCamReturn ret = XCAM_RETURN_NO_ERROR;
84 SmartPtr<DrmDisplay> display = DrmDisplay::instance ();
85
86 drm_bo_in = display->convert_to_drm_bo_buf (display, input);
87 XCAM_FAIL_RETURN (
88 WARNING,
89 drm_bo_in.ptr (),
90 XCAM_RETURN_ERROR_MEM,
91 "CL image processor can't handle this buffer, maybe type error");
92
93 if (_handlers.empty()) {
94 ret = create_handlers ();
95 }
96
97 for (ImageHandlerList::iterator i_handler = _handlers.begin ();
98 i_handler != _handlers.end (); ++i_handler)
99 {
100 ret = (*i_handler)->execute (drm_bo_in, drm_bo_out);
101 XCAM_FAIL_RETURN (
102 WARNING,
103 ret == XCAM_RETURN_NO_ERROR,
104 ret,
105 "CL image handler(%s) execute buffer failed", (*i_handler)->get_name());
106 drm_bo_in = drm_bo_out;
107 }
108
109 output = drm_bo_out;
110 return XCAM_RETURN_NO_ERROR;
111}
112
113XCamReturn
114CLImageProcessor::create_handlers ()
115{
Wind Yuanffe35592015-02-11 16:05:12 +0800116 SmartPtr<CLImageHandler> demo_handler;
Wind Yuan87926782015-02-15 15:53:15 +0800117 demo_handler = create_cl_demo_image_handler (_context);
118 XCAM_FAIL_RETURN (
119 WARNING,
120 demo_handler.ptr (),
121 XCAM_RETURN_ERROR_CL,
122 "CLImageProcessor create demo handler failed");
Wind Yuanffe35592015-02-11 16:05:12 +0800123 add_handler (demo_handler);
Wind Yuan5ddbfd22015-02-10 18:04:09 +0800124
Wind Yuan87926782015-02-15 15:53:15 +0800125 return XCAM_RETURN_NO_ERROR;
Wind Yuan5ddbfd22015-02-10 18:04:09 +0800126}
127
128};