예제 #1
0
bool
CLVaBuffer::init_va_buffer (SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo)
{
    cl_mem mem_id = NULL;
    uint32_t bo_name = 0;
    cl_import_buffer_info_intel import_buffer_info;

    xcam_mem_clear (import_buffer_info);
    import_buffer_info.fd = bo->get_fd ();
    import_buffer_info.size = bo->get_size ();
    if (import_buffer_info.fd != -1) {
        mem_id = context->import_dma_buffer (import_buffer_info);
    }

    if (mem_id == NULL) {
        drm_intel_bo_flink (bo->get_bo (), &bo_name);
        mem_id = context->create_va_buffer (bo_name);
        if (mem_id == NULL) {
            XCAM_LOG_WARNING ("CLVaBuffer create va buffer failed");
            return false;
        }
    }

    set_mem_id (mem_id);
    return true;
}
/*
 * Function: XvMCPutSurface
 *
 * Description:
 * Arguments:
 *  display: Connection to X server
 *  surface: Surface to be displayed
 *  draw: X Drawable on which to display the surface
 *  srcx: X coordinate of the top left corner of the region to be
 *          displayed within the surface.
 *  srcy: Y coordinate of the top left corner of the region to be
 *          displayed within the surface.
 *  srcw: Width of the region to be displayed.
 *  srch: Height of the region to be displayed.
 *  destx: X cordinate of the top left corner of the destination region
 *         in the drawable coordinates.
 *  desty: Y cordinate of the top left corner of the destination region
 *         in the drawable coordinates.
 *  destw: Width of the destination region.
 *  desth: Height of the destination region.
 *  flags: One or more of the following.
 *	XVMC_TOP_FIELD - Display only the Top field of the surface.
 *	XVMC_BOTTOM_FIELD - Display only the Bottom Field of the surface.
 *	XVMC_FRAME_PICTURE - Display both fields or frame.
 */
_X_EXPORT Status XvMCPutSurface(Display * display, XvMCSurface * surface,
				Drawable draw, short srcx, short srcy,
				unsigned short srcw, unsigned short srch,
				short destx, short desty,
				unsigned short destw, unsigned short desth,
				int flags)
{
	Status ret = Success;
	XvMCContext *context;
	intel_xvmc_surface_ptr intel_surf;

	if (!display || !surface)
		return XvMCBadSurface;

	intel_surf = surface->privData;
	context = intel_surf->context;
	if (!context || !intel_surf)
		return XvMCBadSurface;

	if (intel_surf->gc_init == FALSE) {
		intel_surf->gc = XCreateGC(display, draw, 0, NULL);
		intel_surf->gc_init = TRUE;
	} else if (draw != intel_surf->last_draw) {
		XFreeGC(display, intel_surf->gc);
		intel_surf->gc = XCreateGC(display, draw, 0, NULL);
	}
	intel_surf->last_draw = draw;

	drm_intel_bo_flink(intel_surf->bo, &intel_surf->gem_handle);

	ret = XvPutImage(display, context->port, draw, intel_surf->gc,
			 intel_surf->image, srcx, srcy, srcw, srch, destx,
			 desty, destw, desth);
	return ret;
}
예제 #3
0
static GLboolean
intel_query_image(__DRIimage *image, int attrib, int *value)
{
   switch (attrib) {
   case __DRI_IMAGE_ATTRIB_STRIDE:
      *value = image->pitch;
      return true;
   case __DRI_IMAGE_ATTRIB_HANDLE:
      *value = image->bo->handle;
      return true;
   case __DRI_IMAGE_ATTRIB_NAME:
      return !drm_intel_bo_flink(image->bo, (uint32_t *) value);
   case __DRI_IMAGE_ATTRIB_FORMAT:
      *value = image->dri_format;
      return true;
   case __DRI_IMAGE_ATTRIB_WIDTH:
      *value = image->width;
      return true;
   case __DRI_IMAGE_ATTRIB_HEIGHT:
      *value = image->height;
      return true;
   case __DRI_IMAGE_ATTRIB_COMPONENTS:
      if (image->planar_format == NULL)
         return false;
      *value = image->planar_format->components;
      return true;
   case __DRI_IMAGE_ATTRIB_FD:
      if (drm_intel_bo_gem_export_to_prime(image->bo, value) == 0)
         return true;
      return false;
  default:
      return false;
   }
}
예제 #4
0
static boolean
i915_drm_buffer_get_handle(struct i915_winsys *iws,
                            struct i915_winsys_buffer *buffer,
                            struct winsys_handle *whandle,
                            unsigned stride)
{
   struct i915_drm_buffer *buf = i915_drm_buffer(buffer);

   if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
      if (!buf->flinked) {
         if (drm_intel_bo_flink(buf->bo, &buf->flink))
            return FALSE;
         buf->flinked = TRUE;
      }

      whandle->handle = buf->flink;
   } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
      whandle->handle = buf->bo->handle;
   } else {
      assert(!"unknown usage");
      return FALSE;
   }

   whandle->stride = stride;
   return TRUE;
}
예제 #5
0
bool
CLVaImage::init_va_image (
    SmartPtr<CLContext> &context, SmartPtr<DrmBoBuffer> &bo,
    const CLImageDesc &cl_desc, uint32_t offset)
{

    uint32_t bo_name = 0;
    cl_mem mem_id = 0;
    bool need_create = true;
    cl_libva_image va_image_info;
    cl_import_image_info_intel import_image_info;

    xcam_mem_clear (va_image_info);
    xcam_mem_clear (import_image_info);
    import_image_info.offset = va_image_info.offset = offset;
    import_image_info.width = va_image_info.width = cl_desc.width;
    import_image_info.height = va_image_info.height = cl_desc.height;
    import_image_info.fmt = va_image_info.fmt = cl_desc.format;
    import_image_info.row_pitch = va_image_info.row_pitch = cl_desc.row_pitch;
    import_image_info.size = cl_desc.size;
    import_image_info.type = CL_MEM_OBJECT_IMAGE2D;

    XCAM_ASSERT (bo.ptr ());

    SmartPtr<CLImageBoBuffer> cl_image_buffer = bo.dynamic_cast_ptr<CLImageBoBuffer> ();
    if (cl_image_buffer.ptr ()) {
        SmartPtr<CLImage> cl_image_data = cl_image_buffer->get_cl_image ();
        XCAM_ASSERT (cl_image_data.ptr ());
        CLImageDesc old_desc = cl_image_data->get_image_desc ();
        if (cl_desc == old_desc) {
            need_create = false;
            mem_id = cl_image_data->get_mem_id ();
        }
    }

    if (need_create) {
        import_image_info.fd = bo->get_fd();
        if (import_image_info.fd != -1)
            mem_id = context->import_dma_image (import_image_info);

        if (mem_id == NULL) {
            if (drm_intel_bo_flink (bo->get_bo (), &bo_name) == 0) {
                va_image_info.bo_name = bo_name;
                mem_id = context->create_va_image (va_image_info);
            }
            if (mem_id == NULL) {
                XCAM_LOG_WARNING ("create va image failed");
                return false;
            }
        }
    } else {
        va_image_info.bo_name = uint32_t(-1);
    }

    set_mem_id (mem_id, need_create);
    init_desc_by_image ();
    _va_image_info = va_image_info;
    return true;
}
예제 #6
0
bool
intel_region_flink(struct intel_region *region, uint32_t *name)
{
   if (region->name == 0) {
      if (drm_intel_bo_flink(region->bo, &region->name))
	 return false;
   }

   *name = region->name;

   return true;
}
예제 #7
0
int
intel_winsys_export_handle(struct intel_winsys *winsys,
                           struct intel_bo *bo,
                           enum intel_tiling_mode tiling,
                           unsigned long pitch,
                           unsigned long height,
                           struct winsys_handle *handle)
{
   int err = 0;

   switch (handle->type) {
   case DRM_API_HANDLE_TYPE_SHARED:
      {
         uint32_t name;

         err = drm_intel_bo_flink(gem_bo(bo), &name);
         if (!err)
            handle->handle = name;
      }
      break;
   case DRM_API_HANDLE_TYPE_KMS:
      handle->handle = gem_bo(bo)->handle;
      break;
   case DRM_API_HANDLE_TYPE_FD:
      {
         int fd;

         err = drm_intel_bo_gem_export_to_prime(gem_bo(bo), &fd);
         if (!err)
            handle->handle = fd;
      }
      break;
   default:
      err = -EINVAL;
      break;
   }

   if (err)
      return err;

   handle->stride = pitch;

   return 0;
}
예제 #8
0
static __DRIbuffer *
intelAllocateBuffer(__DRIscreen *screen,
		    unsigned attachment, unsigned format,
		    int width, int height)
{
   struct intel_buffer *intelBuffer;
   struct intel_screen *intelScreen = screen->driverPrivate;

   assert(attachment == __DRI_BUFFER_FRONT_LEFT ||
          attachment == __DRI_BUFFER_BACK_LEFT);

   intelBuffer = calloc(1, sizeof *intelBuffer);
   if (intelBuffer == NULL)
      return NULL;

   /* The front and back buffers are color buffers, which are X tiled. */
   uint32_t tiling = I915_TILING_X;
   unsigned long pitch;
   int cpp = format / 8;
   intelBuffer->bo = drm_intel_bo_alloc_tiled(intelScreen->bufmgr,
                                              "intelAllocateBuffer",
                                              width,
                                              height,
                                              cpp,
                                              &tiling, &pitch,
                                              BO_ALLOC_FOR_RENDER);

   if (intelBuffer->bo == NULL) {
	   free(intelBuffer);
	   return NULL;
   }

   drm_intel_bo_flink(intelBuffer->bo, &intelBuffer->base.name);

   intelBuffer->base.attachment = attachment;
   intelBuffer->base.cpp = cpp;
   intelBuffer->base.pitch = pitch;

   return &intelBuffer->base;
}
예제 #9
0
static boolean
intel_drm_shared_handle_from_texture(struct drm_api *api,
                                     struct pipe_screen *screen,
                                     struct pipe_texture *texture,
                                     unsigned *pitch,
                                     unsigned *handle)
{
   struct intel_drm_buffer *buf = NULL;
   struct intel_buffer *buffer = NULL;
   if (!i915_get_texture_buffer_intel(texture, &buffer, pitch))
      return FALSE;

   buf = intel_drm_buffer(buffer);
   if (!buf->flinked) {
      if (drm_intel_bo_flink(buf->bo, &buf->flink))
         return FALSE;
      buf->flinked = TRUE;
   }

   *handle = buf->flink;

   return TRUE;
}
예제 #10
0
/**
 * \brief Assign a DRI buffer's DRM region to a renderbuffer.
 *
 * This is called from intel_update_renderbuffers().
 *
 * \par Note:
 *    DRI buffers whose attachment point is DRI2BufferStencil or
 *    DRI2BufferDepthStencil are handled as special cases.
 *
 * \param buffer_name is a human readable name, such as "dri2 front buffer",
 *        that is passed to drm_intel_bo_gem_create_from_name().
 *
 * \see intel_update_renderbuffers()
 */
static void
intel_process_dri2_buffer(struct brw_context *brw,
                          __DRIdrawable *drawable,
                          __DRIbuffer *buffer,
                          struct intel_renderbuffer *rb,
                          const char *buffer_name)
{
   struct gl_framebuffer *fb = drawable->driverPrivate;
   drm_intel_bo *bo;

   if (!rb)
      return;

   unsigned num_samples = rb->Base.Base.NumSamples;

   /* We try to avoid closing and reopening the same BO name, because the first
    * use of a mapping of the buffer involves a bunch of page faulting which is
    * moderately expensive.
    */
   struct intel_mipmap_tree *last_mt;
   if (num_samples == 0)
      last_mt = rb->mt;
   else
      last_mt = rb->singlesample_mt;

   uint32_t old_name = 0;
   if (last_mt) {
       /* The bo already has a name because the miptree was created by a
	* previous call to intel_process_dri2_buffer(). If a bo already has a
	* name, then drm_intel_bo_flink() is a low-cost getter.  It does not
	* create a new name.
	*/
      drm_intel_bo_flink(last_mt->bo, &old_name);
   }

   if (old_name == buffer->name)
      return;

   if (unlikely(INTEL_DEBUG & DEBUG_DRI)) {
      fprintf(stderr,
              "attaching buffer %d, at %d, cpp %d, pitch %d\n",
              buffer->name, buffer->attachment,
              buffer->cpp, buffer->pitch);
   }

   intel_miptree_release(&rb->mt);
   bo = drm_intel_bo_gem_create_from_name(brw->bufmgr, buffer_name,
                                          buffer->name);
   if (!bo) {
      fprintf(stderr,
              "Failed to open BO for returned DRI2 buffer "
              "(%dx%d, %s, named %d).\n"
              "This is likely a bug in the X Server that will lead to a "
              "crash soon.\n",
              drawable->w, drawable->h, buffer_name, buffer->name);
      return;
   }

   intel_update_winsys_renderbuffer_miptree(brw, rb, bo,
                                            drawable->w, drawable->h,
                                            buffer->pitch);

   if (brw_is_front_buffer_drawing(fb) &&
       (buffer->attachment == __DRI_BUFFER_FRONT_LEFT ||
        buffer->attachment == __DRI_BUFFER_FAKE_FRONT_LEFT) &&
       rb->Base.Base.NumSamples > 1) {
      intel_renderbuffer_upsample(brw, rb);
   }

   assert(rb->mt);

   drm_intel_bo_unreference(bo);
}