Esempio n. 1
0
/**
 * Deletes textures and EGL surfaces and context.
 * @param   raspitex_state  Pointer to the Raspi
 */
void raspitexutil_gl_term(RASPITEX_STATE *raspitex_state)
{
   vcos_log_trace("%s", VCOS_FUNCTION);

   /* Delete OES textures */
   glDeleteTextures(1, &raspitex_state->texture);
   eglDestroyImageKHR(raspitex_state->display, raspitex_state->egl_image);
   raspitex_state->egl_image = EGL_NO_IMAGE_KHR;

   glDeleteTextures(1, &raspitex_state->y_texture);
   eglDestroyImageKHR(raspitex_state->display, raspitex_state->y_egl_image);
   raspitex_state->y_egl_image = EGL_NO_IMAGE_KHR;

   glDeleteTextures(1, &raspitex_state->u_texture);
   eglDestroyImageKHR(raspitex_state->display, raspitex_state->u_egl_image);
   raspitex_state->u_egl_image = EGL_NO_IMAGE_KHR;

   glDeleteTextures(1, &raspitex_state->v_texture);
   eglDestroyImageKHR(raspitex_state->display, raspitex_state->v_egl_image);
   raspitex_state->u_egl_image = EGL_NO_IMAGE_KHR;

   /* Terminate EGL */
   eglMakeCurrent(raspitex_state->display, EGL_NO_SURFACE,
         EGL_NO_SURFACE, EGL_NO_CONTEXT);
   eglDestroyContext(raspitex_state->display, raspitex_state->context);
   eglDestroySurface(raspitex_state->display, raspitex_state->surface);
   eglTerminate(raspitex_state->display);
}
Esempio n. 2
0
static Bool
glamor_egl_close_screen(ScreenPtr screen)
{
    ScrnInfoPtr scrn;
    struct glamor_egl_screen_private *glamor_egl;
    PixmapPtr screen_pixmap;
    EGLImageKHR back_image;

    scrn = xf86ScreenToScrn(screen);
    glamor_egl = glamor_egl_get_screen_private(scrn);
    screen_pixmap = screen->GetScreenPixmap(screen);

    eglDestroyImageKHR(glamor_egl->display,glamor_egl->front_image);
    dixSetPrivate(&screen_pixmap->devPrivates, glamor_egl_pixmap_private_key,
                  NULL);
    glamor_egl->front_image = NULL;
    if (glamor_egl->back_pixmap && *glamor_egl->back_pixmap) {
        back_image = dixLookupPrivate(&(*glamor_egl->back_pixmap)->devPrivates,
                                      glamor_egl_pixmap_private_key);
        if (back_image != NULL && back_image != EGL_NO_IMAGE_KHR) {
            eglDestroyImageKHR(glamor_egl->display, back_image);
            dixSetPrivate(&(*glamor_egl->back_pixmap)->devPrivates,
                          glamor_egl_pixmap_private_key, NULL);
        }
    }

    screen->CloseScreen = glamor_egl->saved_close_screen;

    return screen->CloseScreen(screen);
}
static GrBackendTexture make_gl_backend_texture(
        GrContext* context, AHardwareBuffer* hardwareBuffer,
        int width, int height, GrPixelConfig config,
        GrAHardwareBufferImageGenerator::DeleteImageProc* deleteProc,
        GrAHardwareBufferImageGenerator::DeleteImageCtx* deleteCtx,
        bool isProtectedContent,
        const GrBackendFormat& backendFormat) {
    while (GL_NO_ERROR != glGetError()) {} //clear GL errors

    EGLClientBuffer clientBuffer = eglGetNativeClientBufferANDROID(hardwareBuffer);
    EGLint attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
                         isProtectedContent ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE,
                         isProtectedContent ? EGL_TRUE : EGL_NONE,
                         EGL_NONE };
    EGLDisplay display = eglGetCurrentDisplay();
    // eglCreateImageKHR will add a ref to the AHardwareBuffer
    EGLImageKHR image = eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
                                          clientBuffer, attribs);
    if (EGL_NO_IMAGE_KHR == image) {
        SkDebugf("Could not create EGL image, err = (%#x)", (int) eglGetError() );
        return GrBackendTexture();
    }

    GrGLuint texID;
    glGenTextures(1, &texID);
    if (!texID) {
        eglDestroyImageKHR(display, image);
        return GrBackendTexture();
    }
    glBindTexture(GL_TEXTURE_EXTERNAL_OES, texID);
    GLenum status = GL_NO_ERROR;
    if ((status = glGetError()) != GL_NO_ERROR) {
        SkDebugf("glBindTexture failed (%#x)", (int) status);
        glDeleteTextures(1, &texID);
        eglDestroyImageKHR(display, image);
        return GrBackendTexture();
    }
    glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);
    if ((status = glGetError()) != GL_NO_ERROR) {
        SkDebugf("glEGLImageTargetTexture2DOES failed (%#x)", (int) status);
        glDeleteTextures(1, &texID);
        eglDestroyImageKHR(display, image);
        return GrBackendTexture();
    }
    context->resetContext(kTextureBinding_GrGLBackendState);

    GrGLTextureInfo textureInfo;
    textureInfo.fID = texID;
    SkASSERT(backendFormat.isValid());
    textureInfo.fTarget = *backendFormat.getGLTarget();
    textureInfo.fFormat = *backendFormat.getGLFormat();

    *deleteProc = GrAHardwareBufferImageGenerator::DeleteGLTexture;
    *deleteCtx = new GLCleanupHelper(texID, image, display);

    return GrBackendTexture(width, height, GrMipMapped::kNo, textureInfo);
}
WindowGrabber::~WindowGrabber()
{
    QCoreApplication::eventDispatcher()->removeNativeEventFilter(this);
    if (eglImagesInitialized()) {
        glDeleteTextures(2, imgTextures);
        eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), img[0]);
        eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), img[1]);
    }
}
Esempio n. 5
0
static bool
test_buffer_not_null(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset)
{
	EGLImageKHR img;
	EGLint attr[] = {
		EGL_WIDTH, w,
		EGL_HEIGHT, h,
		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
		EGL_NONE
	};

	/**
	 * The spec says:
	 *
	 *     "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
	 *      display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
	 *      NULL, cast into the type EGLClientBuffer."
	 */
	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)1, attr);

	if (!piglit_check_egl_error(EGL_BAD_PARAMETER)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
Esempio n. 6
0
PIGLIT_GL_TEST_CONFIG_END

#define DRM_FORMAT_INVALID fourcc_code('F', 'O', 'O', '0')

static bool
test_excess_attributes(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset, EGLint attr_id, EGLint attr_val)
{
	const EGLint excess_attr[2 * 7 + 1] = {
			EGL_HEIGHT, w,
		 	EGL_WIDTH, h,
			EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
			EGL_DMA_BUF_PLANE0_FD_EXT, fd,
			EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
			EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
			attr_id, attr_val,
			EGL_NONE };
	EGLImageKHR img = eglCreateImageKHR(eglGetCurrentDisplay(),
				EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT,
				(EGLClientBuffer)NULL, excess_attr);

	if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
Esempio n. 7
0
/*------------------------------------------------------------------------------
|    OMX_TextureData::freeData
+-----------------------------------------------------------------------------*/
void OMX_TextureData::freeData()
{
   if (!m_textureData || !m_textureId || !m_eglImage)
      log_warn("Double free of OMX texture data requested.");

   EGLDisplay eglDisplay = get_egl_display();

   // Destroy texture, EGL image and free the buffer.
   log_debug("Freeing KHR image...");
   if (m_eglImage && eglDestroyImageKHR(eglDisplay, m_eglImage) == EGL_SUCCESS) {
      EGLint err = eglGetError();
      LOG_ERROR(LOG_TAG, "Failed to destroy EGLImageKHR: %d.", err);
   }
   m_eglImage = NULL;

   if (m_textureId) {
      log_debug("Freeing texture...");
      glDeleteTextures(1, &m_textureId);
      m_textureId = 0;
   }

   if (m_textureData) {
      log_debug("Freeing texture data...");
      delete m_textureData;
      m_textureData = NULL;
   }
}
enum piglit_result
piglit_display(void)
{
	const unsigned w = 2;
	const unsigned h = 2;
	const unsigned cpp = 4;
	const unsigned fourcc = DRM_FORMAT_ARGB8888;
	const unsigned char *pixels = alloca(w * h * cpp);
	struct piglit_dma_buf *buf;
	EGLImageKHR img;
	enum piglit_result res;
	bool pass = true;

	res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
	if (res != PIGLIT_PASS)
		return res;

	img = create_image(w, h, buf->fd, buf->stride[0], buf->offset[0]);

	if (!img) {
		piglit_destroy_dma_buf(buf);

		/* unsupported format (BAD_MATCH) is not an error. */
		return piglit_check_egl_error(EGL_BAD_MATCH) ?
					PIGLIT_SKIP : PIGLIT_FAIL;
	}

	pass = try_as_texture_2d(img) && pass;
	pass = try_as_render_buffer(img) && pass;

	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
	piglit_destroy_dma_buf(buf);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 9
0
static bool
test_pitch_zero(unsigned w, unsigned h, int fd, unsigned stride,
		unsigned offset)
{
	EGLImageKHR img;
	EGLint attr[] = {
		EGL_WIDTH, w,
		EGL_HEIGHT, h,
		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
		EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
		EGL_NONE
	};

	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);

	if (!piglit_check_egl_error(EGL_BAD_ACCESS)) {
		if (img)
			eglDestroyImageKHR(eglGetCurrentDisplay(), img);
		return false;
	}

	return true;
}
static DFBResult
mesaDeallocateBuffer( CoreSurfacePool       *pool,
                      void                  *pool_data,
                      void                  *pool_local,
                      CoreSurfaceBuffer     *buffer,
                      CoreSurfaceAllocation *allocation,
                      void                  *alloc_data )
{
     MesaPoolData       *data  = pool_data;
     MesaAllocationData *alloc = alloc_data;
     MesaPoolLocalData  *local = pool_local;

     (void)data;

     D_DEBUG_AT( Mesa_Surfaces, "%s( %p )\n", __FUNCTION__, buffer );

     D_MAGIC_ASSERT( pool, CoreSurfacePool );
     D_MAGIC_ASSERT( data, MesaPoolData );
     D_MAGIC_ASSERT( alloc, MesaAllocationData );

     drmModeRmFB( local->mesa->fd,  alloc->fb_id );
     eglDestroyImageKHR( local->mesa->dpy, alloc->image );
     gbm_bo_destroy( alloc->bo );

     D_MAGIC_CLEAR( alloc );

     return DFB_OK;
}
Esempio n. 11
0
LayerBuffer::BufferSource::~BufferSource()
{    
    class MessageDestroyTexture : public MessageBase {
        SurfaceFlinger* flinger;
        GLuint name;
    public:
        MessageDestroyTexture(
                SurfaceFlinger* flinger, GLuint name)
            : flinger(flinger), name(name) { }
        virtual bool handler() {
            glDeleteTextures(1, &name);
            return true;
        }
    };

    if (mTexture.name != -1U) {
        // GL textures can only be destroyed from the GL thread
        getFlinger()->mEventQueue.postMessage(
                new MessageDestroyTexture(getFlinger(), mTexture.name) );
    }
    if (mTexture.image != EGL_NO_IMAGE_KHR) {
        EGLDisplay dpy(getFlinger()->graphicPlane(0).getEGLDisplay());
        eglDestroyImageKHR(dpy, mTexture.image);
    }
}
status_t SurfaceTexture::acquireBufferLocked(BufferQueue::BufferItem *item) {
    status_t err = ConsumerBase::acquireBufferLocked(item);
    if (err != NO_ERROR) {
        return err;
    }

    int slot = item->mBuf;
    if (item->mGraphicBuffer != NULL) {
        if (mEglSlots[slot].mEglImage != EGL_NO_IMAGE_KHR) {
            eglDestroyImageKHR(mEglDisplay, mEglSlots[slot].mEglImage);
            mEglSlots[slot].mEglImage = EGL_NO_IMAGE_KHR;
        }
    }

#ifndef STE_HARDWARE
    // Update the GL texture object. We may have to do this even when
    // item.mGraphicBuffer == NULL, if we destroyed the EGLImage when
    // detaching from a context but the buffer has not been re-allocated.
    if (mEglSlots[slot].mEglImage == EGL_NO_IMAGE_KHR) {
        EGLImageKHR image = createImage(mEglDisplay, mSlots[slot].mGraphicBuffer);
        if (image == EGL_NO_IMAGE_KHR) {
            return UNKNOWN_ERROR;
        }
        mEglSlots[slot].mEglImage = image;
    }
#endif

    return NO_ERROR;
}
Esempio n. 13
0
void QKmsBufferManager::clearBuffers()
{
    //Make sure that the FBO is binded
    glBindFramebuffer(GL_FRAMEBUFFER, m_frameBufferObject);
    //Detach the Color/Depth/Stencil Attachments.
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER,
                              0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER,
                              0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_STENCIL_ATTACHMENT,
                              GL_RENDERBUFFER,
                              0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    //Delete the shared Depth/Stencil buffer
    glDeleteRenderbuffers(1, &m_depthAndStencilBufferObject);

    //Delete each renderbuffer object
    //Delete each EGLImage
    //Remove each drm Framebuffer
    foreach (QKmsFramebuffer *buffer, m_framebuffers) {
        glDeleteRenderbuffers(1, &buffer->renderBuffer);
        eglDestroyImageKHR(m_screen->device()->eglDisplay(), buffer->eglImage);
        drmModeRmFB(m_screen->device()->fd(), buffer->framebufferId);
        delete buffer;
    }
Esempio n. 14
0
status_t GLConsumer::bindUnslottedBufferLocked(EGLDisplay dpy) {
    ST_LOGV("bindUnslottedBuffer ct=%d ctb=%p",
            mCurrentTexture, mCurrentTextureBuf.get());

    // Create a temporary EGLImageKHR.
    Rect crop;
    EGLImageKHR image = createImage(dpy, mCurrentTextureBuf, mCurrentCrop);
    if (image == EGL_NO_IMAGE_KHR) {
        return UNKNOWN_ERROR;
    }

    // Attach the current buffer to the GL texture.
    glEGLImageTargetTexture2DOES(mTexTarget, (GLeglImageOES)image);

    GLint error;
    status_t err = OK;
    while ((error = glGetError()) != GL_NO_ERROR) {
        ST_LOGE("bindUnslottedBuffer: error binding external texture image %p "
                "(slot %d): %#04x", image, mCurrentTexture, error);
        err = UNKNOWN_ERROR;
    }

    // We destroy the EGLImageKHR here because the current buffer may no
    // longer be associated with one of the buffer slots, so we have
    // nowhere to to store it.  If the buffer is still associated with a
    // slot then another EGLImageKHR will be created next time that buffer
    // gets acquired in updateTexImage.
    eglDestroyImageKHR(dpy, image);

    return err;
}
Esempio n. 15
0
status_t GLConsumer::detachFromContext() {
    ATRACE_CALL();
#ifndef MTK_DEFAULT_AOSP
    ST_LOGI("detachFromContext");
#else
    ST_LOGV("detachFromContext");
#endif
    Mutex::Autolock lock(mMutex);

    if (mAbandoned) {
        ST_LOGE("detachFromContext: abandoned GLConsumer");
        return NO_INIT;
    }

    if (!mAttached) {
        ST_LOGE("detachFromContext: GLConsumer is not attached to a "
                "context");
        return INVALID_OPERATION;
    }

    EGLDisplay dpy = eglGetCurrentDisplay();
    EGLContext ctx = eglGetCurrentContext();

    if (mEglDisplay != dpy && mEglDisplay != EGL_NO_DISPLAY) {
        ST_LOGE("detachFromContext: invalid current EGLDisplay");
        return INVALID_OPERATION;
    }

    if (mEglContext != ctx && mEglContext != EGL_NO_CONTEXT) {
        ST_LOGE("detachFromContext: invalid current EGLContext");
        return INVALID_OPERATION;
    }

    if (dpy != EGL_NO_DISPLAY && ctx != EGL_NO_CONTEXT) {
        status_t err = syncForReleaseLocked(dpy);
        if (err != OK) {
            return err;
        }

        glDeleteTextures(1, &mTexName);
    }

    // Because we're giving up the EGLDisplay we need to free all the EGLImages
    // that are associated with it.  They'll be recreated when the
    // GLConsumer gets attached to a new OpenGL ES context (and thus gets a
    // new EGLDisplay).
    for (int i =0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) {
        EGLImageKHR img = mEglSlots[i].mEglImage;
        if (img != EGL_NO_IMAGE_KHR) {
            eglDestroyImageKHR(mEglDisplay, img);
            mEglSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
        }
    }

    mEglDisplay = EGL_NO_DISPLAY;
    mEglContext = EGL_NO_CONTEXT;
    mAttached = false;

    return OK;
}
Esempio n. 16
0
status_t GLConsumer::acquireBufferLocked(BufferQueue::BufferItem *item,
        nsecs_t presentWhen) {
    status_t err = ConsumerBase::acquireBufferLocked(item, presentWhen);
    if (err != NO_ERROR) {
        return err;
    }

    int slot = item->mBuf;
    bool destroyEglImage = false;

    if (mEglSlots[slot].mEglImage != EGL_NO_IMAGE_KHR) {
        if (item->mGraphicBuffer != NULL) {
            // This buffer has not been acquired before, so we must assume
            // that any EGLImage in mEglSlots is stale.
            destroyEglImage = true;
        } else if (mEglSlots[slot].mCropRect != item->mCrop) {
            // We've already seen this buffer before, but it now has a
            // different crop rect, so we'll need to recreate the EGLImage if
            // we're using the EGL_ANDROID_image_crop extension.
            destroyEglImage = hasEglAndroidImageCrop();
        }
    }

    if (destroyEglImage) {
        if (!eglDestroyImageKHR(mEglDisplay, mEglSlots[slot].mEglImage)) {
            ST_LOGW("acquireBufferLocked: eglDestroyImageKHR failed for slot=%d",
                  slot);
            // keep going
        }
        mEglSlots[slot].mEglImage = EGL_NO_IMAGE_KHR;
    }

    return NO_ERROR;
}
enum piglit_result
piglit_display(void)
{
	GLuint tex;
	enum piglit_result result = PIGLIT_FAIL;
	const unsigned char src[] = { 0x00, 0x00, 0x00, 0x00 };
	EGLImageKHR img = create_tex_based_egl_image(1, 1, src);

	if (img == EGL_NO_IMAGE_KHR)
	       return PIGLIT_FAIL;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);

	glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
			       (GLeglImageOES)img);

	if (piglit_check_gl_error(GL_INVALID_OPERATION))
	       result = PIGLIT_PASS;

	glDeleteTextures(1, &tex);
	eglDestroyImageKHR(eglGetCurrentDisplay(), img);

	return result;
}
GLConsumer::EglImage::~EglImage() {
    if (mEglImage != EGL_NO_IMAGE_KHR) {
        if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) {
           ALOGE("~EglImage: eglDestroyImageKHR failed");
        }
        eglTerminate(mEglDisplay);
    }
}
Esempio n. 19
0
Image::~Image() {
    if (mImage != EGL_NO_IMAGE_KHR) {
        eglDestroyImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), mImage);
        mImage = EGL_NO_IMAGE_KHR;

        Caches::getInstance().deleteTexture(mTexture);
        mTexture = 0;
    }
}
Esempio n. 20
0
void SurfaceTexture::freeBufferLocked(int i) {
    mSlots[i].mGraphicBuffer = 0;
    mSlots[i].mBufferState = BufferSlot::FREE;
    mSlots[i].mFrameNumber = 0;
    if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
        eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
        mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
        mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
    }
}
Esempio n. 21
0
void LayerBuffer::BufferSource::clearTempBufferImage() const
{
    // delete the image
    EGLDisplay dpy(getFlinger()->graphicPlane(0).getEGLDisplay());
    eglDestroyImageKHR(dpy, mTexture.image);

    // and the associated texture (recreate a name)
    glDeleteTextures(1, &mTexture.name);
    Texture defaultTexture;
    mTexture = defaultTexture;
}
Esempio n. 22
0
void
platform_free_eglimage (EGLDisplay display, EGLContext context, GLuint tex_id,
    EGLImageKHR * image, gpointer * image_platform_data)
{
  fbdev_pixmap *pixmap = *image_platform_data;

  eglDestroyImageKHR (display, *image);
  ump_reference_release ((ump_handle) pixmap->data);
  ump_close ();
  g_slice_free (fbdev_pixmap, *image_platform_data);
}
status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
{
    if (tex->name != -1U) {
        glDeleteTextures(1, &tex->name);
        tex->name = -1U;
    }
    if (tex->image != EGL_NO_IMAGE_KHR) {
        eglDestroyImageKHR(dpy, tex->image);
        tex->image = EGL_NO_IMAGE_KHR;
    }
    return NO_ERROR;
}
Esempio n. 24
0
static enum piglit_result
sample_and_destroy_img(unsigned w, unsigned h, EGLImageKHR img)
{
	GLuint prog, tex;
	GLenum error;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);

	/* Set the image as level zero */
	glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
			(GLeglImageOES)img);
	error = glGetError();

	/**
	 * EGL may not support binding of external textures, this is not an
	 * error.
	 */
	if (error == GL_INVALID_OPERATION)
		return PIGLIT_SKIP;

	if (error != GL_NO_ERROR) {
		printf("glEGLImageTargetTexture2DOES() failed: %s 0x%x\n",
			piglit_get_gl_error_name(error), error);
		return PIGLIT_FAIL;
	}

	glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER,
			GL_NEAREST);
	glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER,
			GL_NEAREST);

	prog = piglit_build_simple_program(vs_src, fs_src);
	
	glUseProgram(prog);

	glUniform1i(glGetUniformLocation(prog, "sampler"), 0);
	set_vertices(prog);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glViewport(0, 0, w, h);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

	glDeleteProgram(prog);
	glUseProgram(0);

	glDeleteTextures(1, &tex);
	eglDestroyImageKHR(eglGetCurrentDisplay(), img);

	return PIGLIT_PASS;
}
Esempio n. 25
0
static void
drm_surface_data_destroy(void *p)
{
	struct drm_surface_data *data = p;
	struct display *d = data->display;

	cairo_device_acquire(d->device);
	glDeleteTextures(1, &data->texture);
	cairo_device_release(d->device);

	eglDestroyImageKHR(d->dpy, data->image);
	wl_buffer_destroy(data->data.buffer);
}
void SurfaceTexture::freeBufferLocked(int slotIndex) {
    ST_LOGV("freeBufferLocked: slotIndex=%d", slotIndex);
    if (slotIndex == mCurrentTexture) {
        mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT;
    }
    EGLImageKHR img = mEglSlots[slotIndex].mEglImage;
    if (img != EGL_NO_IMAGE_KHR) {
        ST_LOGV("destroying EGLImage dpy=%p img=%p", mEglDisplay, img);
        eglDestroyImageKHR(mEglDisplay, img);
    }
    mEglSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR;
    ConsumerBase::freeBufferLocked(slotIndex);
}
Esempio n. 27
0
NativeImageGL2D::~NativeImageGL2D()
{
    if (m_fbo)
        glDeleteFramebuffers(1, &m_fbo);
    if (m_renderBuffer)
        glDeleteRenderbuffers(1, &m_renderBuffer);
#if USE(EGL) && PLATFORM(X11)
    if (m_privateImageHandle)
        eglDestroyImageKHR(PlatformContextGL2D::offScreenSurface()->sharedDisplay(), reinterpret_cast<EGLImageKHR>(m_privateImageHandle));
    if (m_sharedImageHandle)
        X11Helper::destroyPixmap(m_sharedImageHandle);
#endif
    if (m_texture)
        glDeleteTextures(1, &m_texture);
}
Esempio n. 28
0
int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc)
{
    EGLImageKHR image;
    EGLint num_planes, fd;

    image = eglCreateImageKHR(qemu_egl_display, eglGetCurrentContext(),
                              EGL_GL_TEXTURE_2D_KHR,
                              (EGLClientBuffer)(unsigned long)tex_id,
                              NULL);
    if (!image) {
        return -1;
    }

    eglExportDMABUFImageQueryMESA(qemu_egl_display, image, fourcc,
                                  &num_planes, NULL);
    if (num_planes != 1) {
        eglDestroyImageKHR(qemu_egl_display, image);
        return -1;
    }
    eglExportDMABUFImageMESA(qemu_egl_display, image, &fd, stride, NULL);
    eglDestroyImageKHR(qemu_egl_display, image);

    return fd;
}
Esempio n. 29
0
status_t TextureManager::initEglImage(Image* pImage,
        EGLDisplay dpy, const sp<GraphicBuffer>& buffer, EGLContext ctx)
{
    status_t err = NO_ERROR;
    if (!pImage->dirty) return err;

    // free the previous image
    if (pImage->image != EGL_NO_IMAGE_KHR) {
        eglDestroyImageKHR(dpy, pImage->image);
        pImage->image = EGL_NO_IMAGE_KHR;
    }

    // construct an EGL_NATIVE_BUFFER_ANDROID
    android_native_buffer_t* clientBuf = buffer->getNativeBuffer();

    // create the new EGLImageKHR
    const EGLint attrs[] = {
            EGL_IMAGE_PRESERVED_KHR,    EGL_TRUE,
            EGL_NONE,                   EGL_NONE
    };
    pImage->image = eglCreateImageKHR(
            dpy, ctx, EGL_NATIVE_BUFFER_ANDROID,
            (EGLClientBuffer)clientBuf, attrs);

    if (pImage->image != EGL_NO_IMAGE_KHR) {
        if (pImage->name == -1UL) {
            initTexture(pImage, buffer->format);
        }
        const GLenum target = getTextureTarget(pImage);
        glBindTexture(target, pImage->name);
        glEGLImageTargetTexture2DOES(target, (GLeglImageOES)pImage->image);
        GLint error = glGetError();
        if (error != GL_NO_ERROR) {
            LOGE("glEGLImageTargetTexture2DOES(%p) failed err=0x%04x",
                    pImage->image, error);
            err = INVALID_OPERATION;
        } else {
            // Everything went okay!
            pImage->dirty  = false;
            pImage->width  = clientBuf->width;
            pImage->height = clientBuf->height;
        }
    } else {
        LOGE("eglCreateImageKHR() failed. err=0x%4x", eglGetError());
        err = INVALID_OPERATION;
    }
    return err;
}
Esempio n. 30
0
/** Destroy all EGL images */
static void vidtex_destroy_images(VIDTEX_T *vt)
{
   VIDTEX_IMAGE_SLOT_T *slot;

   for (slot = vt->slots; slot < vt->slots + vcos_countof(vt->slots); slot++)
   {
      slot->video_frame = NULL;

      if (slot->image)
      {
         vcos_log_trace("Destroying EGL image %p", slot->image);
         eglDestroyImageKHR(vt->display, slot->image);
         slot->image = NULL;
      }
   }
}