[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 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 | |
ssid | 334fb87a | 2015-01-27 20:12:07 | [diff] [blame] | 7 | #include "base/trace_event/trace_event.h" |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 8 | #include "ui/gl/android/surface_texture.h" |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 9 | |
| 10 | namespace gfx { |
| 11 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 12 | GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size) |
| 13 | : size_(size), texture_id_(0) { |
| 14 | } |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 15 | |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 16 | GLImageSurfaceTexture::~GLImageSurfaceTexture() { |
dongseong.hwang | d041a28 | 2015-04-09 05:34:35 | [diff] [blame] | 17 | DCHECK(thread_checker_.CalledOnValidThread()); |
dcheng | bbbea18 | 2014-10-07 03:13:20 | [diff] [blame] | 18 | DCHECK(!surface_texture_.get()); |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 19 | DCHECK_EQ(0, texture_id_); |
| 20 | } |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 21 | |
reveman | 6f3e365 | 2014-10-10 03:32:00 | [diff] [blame] | 22 | bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) { |
dongseong.hwang | d041a28 | 2015-04-09 05:34:35 | [diff] [blame] | 23 | DCHECK(thread_checker_.CalledOnValidThread()); |
dcheng | bbbea18 | 2014-10-07 03:13:20 | [diff] [blame] | 24 | DCHECK(!surface_texture_.get()); |
reveman | 6f3e365 | 2014-10-10 03:32:00 | [diff] [blame] | 25 | surface_texture_ = surface_texture; |
| 26 | return true; |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 27 | } |
| 28 | |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 29 | void GLImageSurfaceTexture::Destroy(bool have_context) { |
dongseong.hwang | d041a28 | 2015-04-09 05:34:35 | [diff] [blame] | 30 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 31 | surface_texture_ = NULL; |
| 32 | texture_id_ = 0; |
| 33 | } |
| 34 | |
| 35 | gfx::Size GLImageSurfaceTexture::GetSize() { return size_; } |
| 36 | |
christiank | 55ddebb | 2015-05-18 08:56:32 | [diff] [blame] | 37 | unsigned GLImageSurfaceTexture::GetInternalFormat() { return GL_RGBA; } |
| 38 | |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 39 | bool GLImageSurfaceTexture::BindTexImage(unsigned target) { |
| 40 | TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage"); |
dongseong.hwang | d041a28 | 2015-04-09 05:34:35 | [diff] [blame] | 41 | DCHECK(thread_checker_.CalledOnValidThread()); |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 42 | |
| 43 | if (target != GL_TEXTURE_EXTERNAL_OES) { |
| 44 | LOG(ERROR) |
| 45 | << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target"; |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | GLint texture_id; |
| 50 | glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
| 51 | DCHECK(texture_id); |
| 52 | |
| 53 | if (texture_id_ && texture_id_ != texture_id) { |
| 54 | LOG(ERROR) << "Surface texture can only be bound to one texture ID"; |
| 55 | return false; |
| 56 | } |
| 57 | |
dcheng | bbbea18 | 2014-10-07 03:13:20 | [diff] [blame] | 58 | DCHECK(surface_texture_.get()); |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 59 | if (texture_id != texture_id_) { |
| 60 | // Note: Surface textures used as gpu memory buffers are created with an |
| 61 | // initial dummy texture id of 0. We need to call DetachFromGLContext() here |
| 62 | // to detach from the dummy texture before we can attach to a real texture |
| 63 | // id. DetachFromGLContext() will delete the texture for the current |
| 64 | // attachment point so it's important that this is never called when |
| 65 | // attached to a real texture id. Detaching from the dummy texture id should |
| 66 | // not cause any problems as the GL should silently ignore 0 when passed to |
| 67 | // glDeleteTextures. |
| 68 | DCHECK_EQ(0, texture_id_); |
| 69 | surface_texture_->DetachFromGLContext(); |
| 70 | |
| 71 | // This will attach the surface texture to the texture currently bound to |
| 72 | // GL_TEXTURE_EXTERNAL_OES target. |
| 73 | surface_texture_->AttachToGLContext(); |
| 74 | texture_id_ = texture_id; |
| 75 | } |
| 76 | |
| 77 | surface_texture_->UpdateTexImage(); |
| 78 | return true; |
| 79 | } |
| 80 | |
reveman | 6b683f2 | 2015-05-22 02:38:32 | [diff] [blame] | 81 | bool GLImageSurfaceTexture::CopyTexSubImage(unsigned target, |
| 82 | const Point& offset, |
| 83 | const Rect& rect) { |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | |
[email protected] | 5e57db7 | 2014-08-01 21:50:17 | [diff] [blame] | 87 | bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 88 | int z_order, |
| 89 | OverlayTransform transform, |
| 90 | const Rect& bounds_rect, |
| 91 | const RectF& crop_rect) { |
| 92 | return false; |
| 93 | } |
| 94 | |
[email protected] | 82efc0d | 2014-03-31 06:45:02 | [diff] [blame] | 95 | } // namespace gfx |