Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / stream_texture_manager_in_process_android.cc
blob174edaa6ee9915391fe87dd12bc64a8b69fcdf65
1 // Copyright 2013 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 "gpu/command_buffer/service/stream_texture_manager_in_process_android.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "gpu/command_buffer/service/texture_manager.h"
10 #include "ui/gfx/geometry/size.h"
11 #include "ui/gl/android/surface_texture.h"
12 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_image.h"
15 namespace gpu {
17 namespace {
19 // Simply wraps a SurfaceTexture reference as a GLImage.
20 class GLImageImpl : public gfx::GLImage {
21 public:
22 GLImageImpl(const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
23 const base::Closure& release_callback);
25 // implement gfx::GLImage
26 void Destroy(bool have_context) override;
27 gfx::Size GetSize() override;
28 bool BindTexImage(unsigned target) override;
29 void ReleaseTexImage(unsigned target) override;
30 bool CopyTexImage(unsigned target) override;
31 void WillUseTexImage() override;
32 void DidUseTexImage() override {}
33 void WillModifyTexImage() override {}
34 void DidModifyTexImage() override {}
35 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
36 int z_order,
37 gfx::OverlayTransform transform,
38 const gfx::Rect& bounds_rect,
39 const gfx::RectF& crop_rect) override;
41 private:
42 ~GLImageImpl() override;
44 scoped_refptr<gfx::SurfaceTexture> surface_texture_;
45 base::Closure release_callback_;
47 DISALLOW_COPY_AND_ASSIGN(GLImageImpl);
50 GLImageImpl::GLImageImpl(
51 const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
52 const base::Closure& release_callback)
53 : surface_texture_(surface_texture), release_callback_(release_callback) {}
55 GLImageImpl::~GLImageImpl() {
56 release_callback_.Run();
59 void GLImageImpl::Destroy(bool have_context) {
60 NOTREACHED();
63 gfx::Size GLImageImpl::GetSize() {
64 return gfx::Size();
67 bool GLImageImpl::BindTexImage(unsigned target) {
68 NOTREACHED();
69 return false;
72 void GLImageImpl::ReleaseTexImage(unsigned target) {
73 NOTREACHED();
76 bool GLImageImpl::CopyTexImage(unsigned target) {
77 return false;
80 void GLImageImpl::WillUseTexImage() {
81 surface_texture_->UpdateTexImage();
84 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
85 int z_order,
86 gfx::OverlayTransform transform,
87 const gfx::Rect& bounds_rect,
88 const gfx::RectF& crop_rect) {
89 NOTREACHED();
90 return false;
93 } // anonymous namespace
95 StreamTextureManagerInProcess::StreamTextureManagerInProcess()
96 : next_id_(1), weak_factory_(this) {}
98 StreamTextureManagerInProcess::~StreamTextureManagerInProcess() {
99 if (!textures_.empty()) {
100 LOG(WARNING) << "Undestroyed surface textures while tearing down "
101 "StreamTextureManager.";
105 GLuint StreamTextureManagerInProcess::CreateStreamTexture(
106 uint32 client_texture_id,
107 gles2::TextureManager* texture_manager) {
108 CalledOnValidThread();
110 gles2::TextureRef* texture = texture_manager->GetTexture(client_texture_id);
112 if (!texture || (texture->texture()->target() &&
113 texture->texture()->target() != GL_TEXTURE_EXTERNAL_OES)) {
114 return 0;
117 scoped_refptr<gfx::SurfaceTexture> surface_texture(
118 gfx::SurfaceTexture::Create(texture->service_id()));
120 uint32 stream_id = next_id_++;
121 base::Closure release_callback =
122 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture,
123 weak_factory_.GetWeakPtr(), stream_id);
124 scoped_refptr<gfx::GLImage> gl_image(new GLImageImpl(surface_texture,
125 release_callback));
127 gfx::Size size = gl_image->GetSize();
128 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
129 texture_manager->SetLevelInfo(texture,
130 GL_TEXTURE_EXTERNAL_OES,
132 GL_RGBA,
133 size.width(),
134 size.height(),
137 GL_RGBA,
138 GL_UNSIGNED_BYTE,
139 true);
140 texture_manager->SetLevelImage(
141 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get());
144 base::AutoLock lock(map_lock_);
145 textures_[stream_id] = surface_texture;
148 if (next_id_ == 0)
149 next_id_++;
151 return stream_id;
154 void StreamTextureManagerInProcess::OnReleaseStreamTexture(uint32 stream_id) {
155 CalledOnValidThread();
156 base::AutoLock lock(map_lock_);
157 textures_.erase(stream_id);
160 // This can get called from any thread.
161 scoped_refptr<gfx::SurfaceTexture>
162 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) {
163 base::AutoLock lock(map_lock_);
164 TextureMap::const_iterator it = textures_.find(stream_id);
165 if (it != textures_.end())
166 return it->second;
168 return NULL;
171 } // namespace gpu