blob: 27c9f64184d676d960712ff2e228b511aae6c45d [file] [log] [blame]
[email protected]82efc0d2014-03-31 06:45:021// 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"
[email protected]82efc0d2014-03-31 06:45:029
10namespace gfx {
11
[email protected]b63f1d62014-07-18 15:40:5912GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
13 : size_(size), texture_id_(0) {
14}
[email protected]82efc0d2014-03-31 06:45:0215
[email protected]d2eaf52f2014-07-31 15:01:2416GLImageSurfaceTexture::~GLImageSurfaceTexture() {
dchengbbbea182014-10-07 03:13:2017 DCHECK(!surface_texture_.get());
[email protected]d2eaf52f2014-07-31 15:01:2418 DCHECK_EQ(0, texture_id_);
19}
[email protected]82efc0d2014-03-31 06:45:0220
reveman6f3e3652014-10-10 03:32:0021bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) {
dchengbbbea182014-10-07 03:13:2022 DCHECK(!surface_texture_.get());
reveman6f3e3652014-10-10 03:32:0023 surface_texture_ = surface_texture;
24 return true;
[email protected]82efc0d2014-03-31 06:45:0225}
26
[email protected]d2eaf52f2014-07-31 15:01:2427void GLImageSurfaceTexture::Destroy(bool have_context) {
[email protected]82efc0d2014-03-31 06:45:0228 surface_texture_ = NULL;
29 texture_id_ = 0;
30}
31
32gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
33
34bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
35 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
36
37 if (target != GL_TEXTURE_EXTERNAL_OES) {
38 LOG(ERROR)
39 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
40 return false;
41 }
42
43 GLint texture_id;
44 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
45 DCHECK(texture_id);
46
47 if (texture_id_ && texture_id_ != texture_id) {
48 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
49 return false;
50 }
51
dchengbbbea182014-10-07 03:13:2052 DCHECK(surface_texture_.get());
[email protected]82efc0d2014-03-31 06:45:0253 if (texture_id != texture_id_) {
54 // Note: Surface textures used as gpu memory buffers are created with an
55 // initial dummy texture id of 0. We need to call DetachFromGLContext() here
56 // to detach from the dummy texture before we can attach to a real texture
57 // id. DetachFromGLContext() will delete the texture for the current
58 // attachment point so it's important that this is never called when
59 // attached to a real texture id. Detaching from the dummy texture id should
60 // not cause any problems as the GL should silently ignore 0 when passed to
61 // glDeleteTextures.
62 DCHECK_EQ(0, texture_id_);
63 surface_texture_->DetachFromGLContext();
64
65 // This will attach the surface texture to the texture currently bound to
66 // GL_TEXTURE_EXTERNAL_OES target.
67 surface_texture_->AttachToGLContext();
68 texture_id_ = texture_id;
69 }
70
71 surface_texture_->UpdateTexImage();
72 return true;
73}
74
revemance8fbe82014-09-05 02:19:5275bool GLImageSurfaceTexture::CopyTexImage(unsigned target) {
76 return false;
77}
78
[email protected]5e57db72014-08-01 21:50:1779bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
80 int z_order,
81 OverlayTransform transform,
82 const Rect& bounds_rect,
83 const RectF& crop_rect) {
84 return false;
85}
86
[email protected]82efc0d2014-03-31 06:45:0287} // namespace gfx