Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gl/gl_image_surface_texture.h" | |
| 6 | |
| 7 #include "base/debug/trace_event.h" | |
| 8 #include "ui/gl/android/surface_texture.h" | |
| 9 #include "ui/gl/android/surface_texture_tracker.h" | |
| 10 #include "ui/gl/gl_bindings.h" | |
| 11 | |
| 12 namespace gfx { | |
| 13 namespace { | |
| 14 | |
| 15 // This is admittedly a bit ugly. SurfaceTexture API takes ownership of texture | |
| 16 // ids when AttachToGLContext() is called and will delete the texture unless | |
| 17 // DetachFromGLContext() is called with no context current. This helper class | |
| 18 // can be used to temporarily make no context current for the purpose of | |
| 19 // stealing the texture id of a given surface texture. | |
| 20 class ScopedNoContextCurrent { | |
| 21 public: | |
| 22 ScopedNoContextCurrent() | |
| 23 : display_(eglGetCurrentDisplay()), | |
| 24 context_(eglGetCurrentContext()), | |
| 25 draw_surface_(eglGetCurrentSurface(EGL_DRAW)), | |
| 26 read_surface_(eglGetCurrentSurface(EGL_READ)) { | |
| 27 eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); | |
| 28 } | |
| 29 | |
| 30 ~ScopedNoContextCurrent() { | |
| 31 eglMakeCurrent(display_, draw_surface_, read_surface_, context_); | |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 EGLDisplay display_; | |
| 36 EGLContext context_; | |
| 37 EGLSurface draw_surface_; | |
| 38 EGLSurface read_surface_; | |
| 39 }; | |
| 40 | |
| 41 void DetachFromGLContext(SurfaceTexture* surface_texture) { | |
|
epennerAtGoogle
2014/03/12 00:45:06
I'm not sure this works 100% the way we want, at l
reveman
2014/03/12 16:07:06
Seems to be working OK but there might be some fen
epennerAtGoogle
2014/03/12 19:46:28
What I meant here was, 'if we don't need the fenci
epennerAtGoogle
2014/03/12 20:52:33
Oh, one thought here would be: should we redefine
reveman
2014/03/12 21:19:11
Yes, we might want to do that in GLImage::ReleaseT
| |
| 42 // Detach with no context current to prevent SurfaceTexture from deleting | |
| 43 // currently attached texture id. | |
| 44 ScopedNoContextCurrent no_context_current; | |
| 45 surface_texture->DetachFromGLContext(); | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 GLImageSurfaceTexture::GLImageSurfaceTexture(gfx::Size size) : size_(size) {} | |
| 51 | |
| 52 GLImageSurfaceTexture::~GLImageSurfaceTexture() { Destroy(); } | |
| 53 | |
| 54 bool GLImageSurfaceTexture::Initialize(gfx::GpuMemoryBufferHandle buffer) { | |
| 55 DCHECK(!surface_texture_); | |
| 56 surface_texture_ = | |
| 57 SurfaceTextureTracker::GetInstance()->AcquireSurfaceTexture( | |
| 58 buffer.surface_texture_id); | |
| 59 return !!surface_texture_; | |
| 60 } | |
| 61 | |
| 62 void GLImageSurfaceTexture::Destroy() { | |
| 63 if (surface_texture_) | |
| 64 DetachFromGLContext(surface_texture_.get()); | |
| 65 } | |
| 66 | |
| 67 gfx::Size GLImageSurfaceTexture::GetSize() { return size_; } | |
| 68 | |
| 69 bool GLImageSurfaceTexture::BindTexImage(unsigned target) { | |
| 70 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage"); | |
| 71 | |
| 72 DCHECK(surface_texture_); | |
| 73 DetachFromGLContext(surface_texture_.get()); | |
| 74 DCHECK_EQ(static_cast<unsigned>(GL_TEXTURE_EXTERNAL_OES), target); | |
| 75 surface_texture_->AttachToGLContext(); | |
| 76 surface_texture_->UpdateTexImage(); | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 void GLImageSurfaceTexture::ReleaseTexImage(unsigned target) {} | |
| 81 | |
| 82 void GLImageSurfaceTexture::WillUseTexImage() {} | |
| 83 | |
| 84 void GLImageSurfaceTexture::DidUseTexImage() {} | |
| 85 | |
| 86 } // namespace gfx | |
| OLD | NEW |