• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/intel-driver


Commit MetaInfo

Revisionf75ddc58b16cb93e85e737792c431415288cafb1 (tree)
Time2015-09-06 15:13:27
AuthorZhao Yakui <yakui.zhao@inte...>
CommiterXiang, Haihao

Log Message

Add the support of wrapper the VA Buffer to the backend driver

The obj_context is passed when calling vaCreateBuffer, which can be
used to check whether it belongs to the wrapped context. If one VA buffer
belongs to wrapped buffer, the callback function of backend driver will
be called for the corresponding VA buffer.

Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Signed-off-by: Sean V Kelley <seanvk@posteo.de>

Change Summary

Incremental Difference

--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -2161,6 +2161,8 @@ i965_create_buffer_internal(VADriverContextP ctx,
21612161 struct buffer_store *buffer_store = NULL;
21622162 int bufferID;
21632163 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2164+ struct object_context *obj_context = CONTEXT(context);
2165+ int wrapper_flag = 0;
21642166
21652167 /* Validate type */
21662168 switch (type) {
@@ -2217,22 +2219,54 @@ i965_create_buffer_internal(VADriverContextP ctx,
22172219 assert(buffer_store);
22182220 buffer_store->ref_count = 1;
22192221
2222+ if (obj_context &&
2223+ (obj_context->wrapper_context != VA_INVALID_ID) &&
2224+ i965->wrapper_pdrvctx) {
2225+ VAGenericID wrapper_buffer;
2226+ VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2227+
2228+ CALL_VTABLE(pdrvctx, vaStatus,
2229+ vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2230+ data, &wrapper_buffer));
2231+ if (vaStatus == VA_STATUS_SUCCESS) {
2232+ obj_buffer->wrapper_buffer = wrapper_buffer;
2233+ } else {
2234+ free(buffer_store);
2235+ return vaStatus;
2236+ }
2237+ wrapper_flag = 1;
2238+ }
2239+
22202240 if (store_bo != NULL) {
22212241 buffer_store->bo = store_bo;
22222242 dri_bo_reference(buffer_store->bo);
2223-
2224- if (data)
2243+
2244+ /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2245+ if (data && !wrapper_flag)
22252246 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
22262247 } else if (type == VASliceDataBufferType ||
22272248 type == VAImageBufferType ||
22282249 type == VAEncCodedBufferType ||
22292250 type == VAProbabilityBufferType) {
2230- buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2231- "Buffer",
2232- size * num_elements, 64);
2251+
2252+ /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2253+ * So it is enough to allocate one 64 byte bo
2254+ */
2255+ if (wrapper_flag)
2256+ buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2257+ 64, 64);
2258+ else
2259+ buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2260+ "Buffer",
2261+ size * num_elements, 64);
22332262 assert(buffer_store->bo);
22342263
2235- if (type == VAEncCodedBufferType) {
2264+ /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2265+ * In fact it can be skipped. But it is still allocated and it is
2266+ * only to follow the normal flowchart of buffer_allocation/release.
2267+ */
2268+ if (!wrapper_flag) {
2269+ if (type == VAEncCodedBufferType) {
22362270 struct i965_coded_buffer_segment *coded_buffer_segment;
22372271
22382272 dri_bo_map(buffer_store->bo, 1);
@@ -2245,9 +2279,10 @@ i965_create_buffer_internal(VADriverContextP ctx,
22452279 coded_buffer_segment->mapped = 0;
22462280 coded_buffer_segment->codec = 0;
22472281 dri_bo_unmap(buffer_store->bo);
2248- } else if (data) {
2249- dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2250- }
2282+ } else if (data) {
2283+ dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2284+ }
2285+ }
22512286
22522287 } else {
22532288 int msize = size;
@@ -2256,10 +2291,14 @@ i965_create_buffer_internal(VADriverContextP ctx,
22562291 msize = ALIGN(size, 4);
22572292 }
22582293
2259- buffer_store->buffer = malloc(msize * num_elements);
2294+ /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2295+ if (wrapper_flag)
2296+ buffer_store->buffer = malloc(4);
2297+ else
2298+ buffer_store->buffer = malloc(msize * num_elements);
22602299 assert(buffer_store->buffer);
22612300
2262- if (data)
2301+ if (data && (!wrapper_flag))
22632302 memcpy(buffer_store->buffer, data, size * num_elements);
22642303 }
22652304
@@ -2295,6 +2334,19 @@ i965_BufferSetNumElements(VADriverContextP ctx,
22952334
22962335 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
22972336
2337+ /* When the wrapper_buffer exists, it will wrapper to the
2338+ * buffer allocated from backend driver.
2339+ */
2340+ if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2341+ i965->wrapper_pdrvctx) {
2342+ VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2343+
2344+ CALL_VTABLE(pdrvctx, vaStatus,
2345+ vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2346+ num_elements));
2347+ return vaStatus;
2348+ }
2349+
22982350 if ((num_elements < 0) ||
22992351 (num_elements > obj_buffer->max_num_elements)) {
23002352 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
@@ -2318,6 +2370,19 @@ i965_MapBuffer(VADriverContextP ctx,
23182370 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
23192371
23202372 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2373+
2374+ /* When the wrapper_buffer exists, it will wrapper to the
2375+ * buffer allocated from backend driver.
2376+ */
2377+ if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2378+ i965->wrapper_pdrvctx) {
2379+ VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2380+
2381+ CALL_VTABLE(pdrvctx, vaStatus,
2382+ vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2383+ return vaStatus;
2384+ }
2385+
23212386 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
23222387 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
23232388
@@ -2430,6 +2495,18 @@ i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
24302495 return VA_STATUS_ERROR_INVALID_BUFFER;
24312496
24322497 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2498+ /* When the wrapper_buffer exists, it will wrapper to the
2499+ * buffer allocated from backend driver.
2500+ */
2501+ if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2502+ i965->wrapper_pdrvctx) {
2503+ VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2504+
2505+ CALL_VTABLE(pdrvctx, vaStatus,
2506+ vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2507+ return vaStatus;
2508+ }
2509+
24332510 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
24342511 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
24352512
@@ -5448,6 +5525,16 @@ i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
54485525 if (obj_buffer->type != VAImageBufferType)
54495526 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
54505527
5528+ /*
5529+ * As the allocated buffer by calling vaCreateBuffer is related with
5530+ * the specific context, it is unnecessary to export it.
5531+ * So it is not supported when the buffer is allocated from wrapped
5532+ * backend dirver.
5533+ */
5534+ if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5535+ return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5536+ }
5537+
54515538 if (!buf_info)
54525539 return VA_STATUS_ERROR_INVALID_PARAMETER;
54535540
@@ -5477,6 +5564,10 @@ i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
54775564 if (!obj_buffer)
54785565 return VA_STATUS_ERROR_INVALID_BUFFER;
54795566
5567+ if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5568+ return VA_STATUS_ERROR_INVALID_BUFFER;
5569+ }
5570+
54805571 return i965_release_buffer_handle(obj_buffer);
54815572 }
54825573