Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / gl / gl_image_surface_texture.cc
blob20e7b15634642e9d46d37e0178fe76d4f27cbee3
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/trace_event/trace_event.h"
8 #include "ui/gl/android/surface_texture.h"
10 namespace gfx {
12 GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
13 : size_(size), texture_id_(0) {
16 GLImageSurfaceTexture::~GLImageSurfaceTexture() {
17 DCHECK(thread_checker_.CalledOnValidThread());
18 DCHECK(!surface_texture_.get());
19 DCHECK_EQ(0, texture_id_);
22 bool GLImageSurfaceTexture::Initialize(SurfaceTexture* surface_texture) {
23 DCHECK(thread_checker_.CalledOnValidThread());
24 DCHECK(!surface_texture_.get());
25 surface_texture_ = surface_texture;
26 return true;
29 void GLImageSurfaceTexture::Destroy(bool have_context) {
30 DCHECK(thread_checker_.CalledOnValidThread());
31 surface_texture_ = NULL;
32 texture_id_ = 0;
35 gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
37 bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
38 TRACE_EVENT0("gpu", "GLImageSurfaceTexture::BindTexImage");
39 DCHECK(thread_checker_.CalledOnValidThread());
41 if (target != GL_TEXTURE_EXTERNAL_OES) {
42 LOG(ERROR)
43 << "Surface texture can only be bound to TEXTURE_EXTERNAL_OES target";
44 return false;
47 GLint texture_id;
48 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
49 DCHECK(texture_id);
51 if (texture_id_ && texture_id_ != texture_id) {
52 LOG(ERROR) << "Surface texture can only be bound to one texture ID";
53 return false;
56 DCHECK(surface_texture_.get());
57 if (texture_id != texture_id_) {
58 // Note: Surface textures used as gpu memory buffers are created with an
59 // initial dummy texture id of 0. We need to call DetachFromGLContext() here
60 // to detach from the dummy texture before we can attach to a real texture
61 // id. DetachFromGLContext() will delete the texture for the current
62 // attachment point so it's important that this is never called when
63 // attached to a real texture id. Detaching from the dummy texture id should
64 // not cause any problems as the GL should silently ignore 0 when passed to
65 // glDeleteTextures.
66 DCHECK_EQ(0, texture_id_);
67 surface_texture_->DetachFromGLContext();
69 // This will attach the surface texture to the texture currently bound to
70 // GL_TEXTURE_EXTERNAL_OES target.
71 surface_texture_->AttachToGLContext();
72 texture_id_ = texture_id;
75 surface_texture_->UpdateTexImage();
76 return true;
79 bool GLImageSurfaceTexture::CopyTexImage(unsigned target) {
80 return false;
83 bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
84 int z_order,
85 OverlayTransform transform,
86 const Rect& bounds_rect,
87 const RectF& crop_rect) {
88 return false;
91 } // namespace gfx