• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * swapped_buffer.cpp - swapped buffer
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 
21 #include <xcam_std.h>
22 #include "swapped_buffer.h"
23 
24 namespace XCam {
25 
SwappedBuffer(const VideoBufferInfo & info,const SmartPtr<BufferData> & data)26 SwappedBuffer::SwappedBuffer (
27     const VideoBufferInfo &info, const SmartPtr<BufferData> &data)
28     : BufferProxy (info, data)
29     , _swap_flags (SwappedBuffer::SwapNone)
30 {
31     xcam_mem_clear (_swap_offsets);
32 }
33 
~SwappedBuffer()34 SwappedBuffer::~SwappedBuffer ()
35 {
36 }
37 
38 void
set_swap_info(uint32_t flags,uint32_t * offsets)39 SwappedBuffer::set_swap_info (uint32_t flags, uint32_t* offsets)
40 {
41     _swap_flags = flags;
42     XCAM_ASSERT (offsets);
43     memcpy(_swap_offsets, offsets, sizeof (_swap_offsets));
44 }
45 
swap_new_buffer_info(const VideoBufferInfo & in,uint32_t flags,VideoBufferInfo & out)46 bool SwappedBuffer::swap_new_buffer_info(
47     const VideoBufferInfo &in, uint32_t flags, VideoBufferInfo &out)
48 {
49     out = in;
50     if (flags & (uint32_t)(SwapY)) {
51         if (in.offsets[0] == _swap_offsets[SwapYOffset0]) {
52             out.offsets[0] = _swap_offsets[SwapYOffset1];
53         } else {
54             XCAM_ASSERT (in.offsets[0] == _swap_offsets[SwapYOffset1]);
55             out.offsets[0] = _swap_offsets[SwapYOffset0];
56         }
57     }
58     if (flags & (uint32_t)(SwapUV)) {
59         if (in.offsets[1] == _swap_offsets[SwapUVOffset0]) {
60             out.offsets[1] = _swap_offsets[SwapUVOffset1];
61         } else {
62             XCAM_ASSERT (in.offsets[1] == _swap_offsets[SwapUVOffset1]);
63             out.offsets[1] = _swap_offsets[SwapUVOffset0];
64         }
65     }
66     return true;
67 }
68 
69 SmartPtr<SwappedBuffer>
create_new_swap_buffer(const VideoBufferInfo & info,SmartPtr<BufferData> & data)70 SwappedBuffer::create_new_swap_buffer (
71     const VideoBufferInfo &info, SmartPtr<BufferData> &data)
72 {
73     XCAM_ASSERT (false);
74     SmartPtr<SwappedBuffer> out = new SwappedBuffer (info, data);
75     return out;
76 }
77 
78 SmartPtr<SwappedBuffer>
swap_clone(SmartPtr<SwappedBuffer> self,uint32_t flags)79 SwappedBuffer::swap_clone (SmartPtr<SwappedBuffer> self, uint32_t flags)
80 {
81     XCAM_ASSERT (self.ptr () && self.ptr () == (SwappedBuffer*)(this));
82     XCAM_FAIL_RETURN(
83         WARNING,
84         flags && (flags & _swap_flags) == flags,
85         NULL,
86         "SwappedBuffer swap_clone failed since flags doesn't match");
87 
88     const VideoBufferInfo &cur_info = this->get_video_info ();
89     VideoBufferInfo out_info;
90     XCAM_FAIL_RETURN(
91         WARNING,
92         swap_new_buffer_info (cur_info, flags, out_info),
93         NULL,
94         "SwappedBuffer swap_clone failed on out buffer info");
95 
96     SmartPtr<BufferData> data = get_buffer_data ();
97     XCAM_FAIL_RETURN(
98         WARNING,
99         data.ptr (),
100         NULL,
101         "SwappedBuffer swap_clone failed to get buffer data");
102 
103     SmartPtr<SwappedBuffer> out = create_new_swap_buffer (out_info, data);
104     XCAM_FAIL_RETURN(
105         WARNING,
106         out.ptr (),
107         NULL,
108         "SwappedBuffer swap_clone failed to create new swap buffer");
109     out->_swap_flags = _swap_flags;
110     memcpy (out->_swap_offsets, _swap_offsets, sizeof (_swap_offsets));
111     out->set_parent (self);
112     return out;
113 }
114 
115 };
116