tu: Implement fallback linear staging blit for CopyImage
[mesa.git] / src / gallium / state_trackers / omx / tizonia / h264eoutport.c
1 /**************************************************************************
2 *
3 * Copyright 2013 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <assert.h>
29 #include <string.h>
30 #include <limits.h>
31
32 #include <tizplatform.h>
33
34 #include "vl/vl_winsys.h"
35
36 #include "h264eoutport.h"
37 #include "h264eoutport_decls.h"
38 #include "vid_enc_common.h"
39
40 /*
41 * h264eoutport class
42 */
43
44 static void * h264e_outport_ctor(void * ap_obj, va_list * app)
45 {
46 return super_ctor(typeOf(ap_obj, "h264eoutport"), ap_obj, app);
47 }
48
49 static void * h264e_outport_dtor(void * ap_obj)
50 {
51 return super_dtor(typeOf(ap_obj, "h264eoutport"), ap_obj);
52 }
53
54 /*
55 * from tiz_api
56 */
57
58 static OMX_ERRORTYPE h264e_outport_AllocateBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl,
59 OMX_BUFFERHEADERTYPE ** buf, OMX_U32 idx,
60 OMX_PTR private, OMX_U32 size)
61 {
62 OMX_ERRORTYPE r;
63
64 r = super_UseBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl,
65 buf, idx, private, size, NULL);
66 if (r)
67 return r;
68
69 (*buf)->pBuffer = NULL;
70 (*buf)->pOutputPortPrivate = CALLOC(1, sizeof(struct output_buf_private));
71 if (!(*buf)->pOutputPortPrivate) {
72 super_FreeBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl, idx, *buf);
73 return OMX_ErrorInsufficientResources;
74 }
75
76 return OMX_ErrorNone;
77 }
78
79 static OMX_ERRORTYPE h264e_outport_FreeBuffer(const void * ap_obj, OMX_HANDLETYPE ap_hdl,
80 OMX_U32 idx, OMX_BUFFERHEADERTYPE *buf)
81 {
82 vid_enc_PrivateType *priv = tiz_get_prc(ap_hdl);
83 struct output_buf_private *outp = buf->pOutputPortPrivate;
84
85 if (outp) {
86 if (outp->transfer)
87 pipe_transfer_unmap(priv->t_pipe, outp->transfer);
88 pipe_resource_reference(&outp->bitstream, NULL);
89 FREE(outp);
90 buf->pOutputPortPrivate = NULL;
91 }
92 buf->pBuffer = NULL;
93
94 return super_FreeBuffer(typeOf(ap_obj, "h264eoutport"), ap_obj, ap_hdl, idx, buf);
95 }
96
97 /*
98 * h264e_outport_class
99 */
100
101 static void * h264e_outport_class_ctor(void * ap_obj, va_list * app)
102 {
103 /* NOTE: Class methods might be added in the future. None for now. */
104 return super_ctor(typeOf(ap_obj, "h264eoutport_class"), ap_obj, app);
105 }
106
107 /*
108 * initialization
109 */
110
111 void * h264e_outport_class_init(void * ap_tos, void * ap_hdl)
112 {
113 void * tizavcport = tiz_get_type(ap_hdl, "tizavcport");
114 void * h264eoutport_class
115 = factory_new (classOf(tizavcport), "h264eoutport_class",
116 classOf(tizavcport), sizeof(h264e_outport_class_t),
117 ap_tos, ap_hdl, ctor, h264e_outport_class_ctor, 0);
118 return h264eoutport_class;
119 }
120
121 void * h264e_outport_init(void * ap_tos, void * ap_hdl)
122 {
123 void * tizavcport = tiz_get_type(ap_hdl, "tizavcport");
124 void * h264eoutport_class = tiz_get_type(ap_hdl, "h264eoutport_class");
125 void * h264eoutport = factory_new
126 /* TIZ_CLASS_COMMENT: class type, class name, parent, size */
127 (h264eoutport_class, "h264eoutport", tizavcport,
128 sizeof(h264e_outport_t),
129 /* TIZ_CLASS_COMMENT: class constructor */
130 ap_tos, ap_hdl,
131 /* TIZ_CLASS_COMMENT: class constructor */
132 ctor, h264e_outport_ctor,
133 /* TIZ_CLASS_COMMENT: class destructor */
134 dtor, h264e_outport_dtor,
135 /* TIZ_CLASS_COMMENT: */
136 tiz_api_AllocateBuffer, h264e_outport_AllocateBuffer,
137 /* TIZ_CLASS_COMMENT: */
138 tiz_api_FreeBuffer, h264e_outport_FreeBuffer,
139 /* TIZ_CLASS_COMMENT: stop value*/
140 0);
141
142 return h264eoutport;
143 }