Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / gl / gl_image_surface_texture.cc
blob833e78bdc98809ebb34ca3b686c86416298da27c
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.
5 #include "ui/gl/gl_image_surface_texture.h"
7 #include "base/debug/trace_event.h"
8 #include "ui/gl/android/surface_texture.h"
9 #include "ui/gl/android/surface_texture_tracker.h"
11 namespace gfx {
13 GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
14 : size_(size), texture_id_(0) {
17 GLImageSurfaceTexture::~GLImageSurfaceTexture() {
18 DCHECK(!surface_texture_);
19 DCHECK_EQ(0, texture_id_);
22 bool GLImageSurfaceTexture::Initialize(
23 const gfx::GpuMemoryBufferHandle& handle) {
24 DCHECK(!surface_texture_);
25 surface_texture_ =
26 SurfaceTextureTracker::GetInstance()->AcquireSurfaceTexture(
27 handle.surface_texture_id.primary_id,
28 handle.surface_texture_id.secondary_id);
29 return !!surface_texture_;
32 void GLImageSurfaceTexture::Destroy(bool have_context) {
33 surface_texture_ = NULL;
34 texture_id_ = 0;
37 gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
39 bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
40 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
42 if (target != GL_TEXTURE_EXTERNAL_OES) {
43 LOG(ERROR)
44 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
45 return false;
48 GLint texture_id;
49 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
50 DCHECK(texture_id);
52 if (texture_id_ && texture_id_ != texture_id) {
53 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
54 return false;
57 DCHECK(surface_texture_);
58 if (texture_id != texture_id_) {
59 // Note: Surface textures used as gpu memory buffers are created with an
60 // initial dummy texture id of 0. We need to call DetachFromGLContext() here
61 // to detach from the dummy texture before we can attach to a real texture
62 // id. DetachFromGLContext() will delete the texture for the current
63 // attachment point so it's important that this is never called when
64 // attached to a real texture id. Detaching from the dummy texture id should
65 // not cause any problems as the GL should silently ignore 0 when passed to
66 // glDeleteTextures.
67 DCHECK_EQ(0, texture_id_);
68 surface_texture_->DetachFromGLContext();
70 // This will attach the surface texture to the texture currently bound to
71 // GL_TEXTURE_EXTERNAL_OES target.
72 surface_texture_->AttachToGLContext();
73 texture_id_ = texture_id;
76 surface_texture_->UpdateTexImage();
77 return true;
80 bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
81 int z_order,
82 OverlayTransform transform,
83 const Rect& bounds_rect,
84 const RectF& crop_rect) {
85 return false;
88 } // namespace gfx