blob: bec06be8f242d8e227cdc50cd8082e0b64af6890 [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
ssid334fb87a2015-01-27 20:12:077#include "base/trace_event/trace_event.h"
[email protected]82efc0d2014-03-31 06:45:028#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() {
dongseong.hwangd041a282015-04-09 05:34:3517 DCHECK(thread_checker_.CalledOnValidThread());
dchengbbbea182014-10-07 03:13:2018 DCHECK(!surface_texture_.get());
[email protected]d2eaf52f2014-07-31 15:01:2419 DCHECK_EQ(0, texture_id_);
20}
[email protected]82efc0d2014-03-31 06:45:0221
reveman6f3e3652014-10-10 03:32:0022bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) {
dongseong.hwangd041a282015-04-09 05:34:3523 DCHECK(thread_checker_.CalledOnValidThread());
dchengbbbea182014-10-07 03:13:2024 DCHECK(!surface_texture_.get());
reveman6f3e3652014-10-10 03:32:0025 surface_texture_ = surface_texture;
26 return true;
[email protected]82efc0d2014-03-31 06:45:0227}
28
[email protected]d2eaf52f2014-07-31 15:01:2429void GLImageSurfaceTexture::Destroy(bool have_context) {
dongseong.hwangd041a282015-04-09 05:34:3530 DCHECK(thread_checker_.CalledOnValidThread());
[email protected]82efc0d2014-03-31 06:45:0231 surface_texture_ = NULL;
32 texture_id_ = 0;
33}
34
35gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
36
christiank55ddebb2015-05-18 08:56:3237unsigned GLImageSurfaceTexture::GetInternalFormat() { return GL_RGBA; }
38
[email protected]82efc0d2014-03-31 06:45:0239bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
40 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
dongseong.hwangd041a282015-04-09 05:34:3541 DCHECK(thread_checker_.CalledOnValidThread());
[email protected]82efc0d2014-03-31 06:45:0242
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
dchengbbbea182014-10-07 03:13:2058 DCHECK(surface_texture_.get());
[email protected]82efc0d2014-03-31 06:45:0259 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
reveman6b683f22015-05-22 02:38:3281bool GLImageSurfaceTexture::CopyTexSubImage(unsigned target,
82 const Point& offset,
83 const Rect& rect) {
revemance8fbe82014-09-05 02:19:5284 return false;
85}
86
[email protected]5e57db72014-08-01 21:50:1787bool 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]82efc0d2014-03-31 06:45:0295} // namespace gfx