Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: gpu/command_buffer/service/stream_texture_manager_in_process_android.cc

Issue 1401423003: Re-land: ui: Move GLImage::BindTexImage fallback from GLImage implementations to GLES2CmdDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix stream texture issue Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h " 5 #include "gpu/command_buffer/service/stream_texture_manager_in_process_android.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "gpu/command_buffer/service/texture_manager.h" 9 #include "gpu/command_buffer/service/texture_manager.h"
10 #include "ui/gfx/geometry/size.h" 10 #include "ui/gfx/geometry/size.h"
11 #include "ui/gl/android/surface_texture.h" 11 #include "ui/gl/android/surface_texture.h"
12 #include "ui/gl/gl_bindings.h" 12 #include "ui/gl/gl_bindings.h"
13 #include "ui/gl/gl_image.h" 13 #include "ui/gl/gl_image.h"
14 14
15 namespace gpu { 15 namespace gpu {
16 16
17 namespace { 17 namespace {
18 18
19 // Simply wraps a SurfaceTexture reference as a GLImage. 19 // Simply wraps a SurfaceTexture reference as a GLImage.
20 class GLImageImpl : public gfx::GLImage { 20 class GLImageImpl : public gfx::GLImage {
21 public: 21 public:
22 GLImageImpl(const scoped_refptr<gfx::SurfaceTexture>& surface_texture, 22 GLImageImpl(uint32 texture_id,
23 gles2::TextureManager* texture_manager,
24 const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
23 const base::Closure& release_callback); 25 const base::Closure& release_callback);
24 26
25 // implement gfx::GLImage 27 // implement gfx::GLImage
26 void Destroy(bool have_context) override; 28 void Destroy(bool have_context) override;
27 gfx::Size GetSize() override; 29 gfx::Size GetSize() override;
28 unsigned GetInternalFormat() override; 30 unsigned GetInternalFormat() override;
29 bool BindTexImage(unsigned target) override; 31 bool BindTexImage(unsigned target) override;
30 void ReleaseTexImage(unsigned target) override; 32 void ReleaseTexImage(unsigned target) override;
33 bool CopyTexImage(unsigned target) override;
31 bool CopyTexSubImage(unsigned target, 34 bool CopyTexSubImage(unsigned target,
32 const gfx::Point& offset, 35 const gfx::Point& offset,
33 const gfx::Rect& rect) override; 36 const gfx::Rect& rect) override;
34 void WillUseTexImage() override;
35 void DidUseTexImage() override {}
36 void WillModifyTexImage() override {}
37 void DidModifyTexImage() override {}
38 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 37 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
39 int z_order, 38 int z_order,
40 gfx::OverlayTransform transform, 39 gfx::OverlayTransform transform,
41 const gfx::Rect& bounds_rect, 40 const gfx::Rect& bounds_rect,
42 const gfx::RectF& crop_rect) override; 41 const gfx::RectF& crop_rect) override;
43 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 42 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
44 uint64_t process_tracing_id, 43 uint64_t process_tracing_id,
45 const std::string& dump_name) override; 44 const std::string& dump_name) override;
46 45
47 private: 46 private:
48 ~GLImageImpl() override; 47 ~GLImageImpl() override;
49 48
49 uint32 texture_id_;
50 gles2::TextureManager* texture_manager_;
50 scoped_refptr<gfx::SurfaceTexture> surface_texture_; 51 scoped_refptr<gfx::SurfaceTexture> surface_texture_;
51 base::Closure release_callback_; 52 base::Closure release_callback_;
52 53
53 DISALLOW_COPY_AND_ASSIGN(GLImageImpl); 54 DISALLOW_COPY_AND_ASSIGN(GLImageImpl);
54 }; 55 };
55 56
56 GLImageImpl::GLImageImpl( 57 GLImageImpl::GLImageImpl(
58 uint32 texture_id,
59 gles2::TextureManager* texture_manager,
57 const scoped_refptr<gfx::SurfaceTexture>& surface_texture, 60 const scoped_refptr<gfx::SurfaceTexture>& surface_texture,
58 const base::Closure& release_callback) 61 const base::Closure& release_callback)
59 : surface_texture_(surface_texture), release_callback_(release_callback) {} 62 : texture_id_(texture_id),
63 texture_manager_(texture_manager),
64 surface_texture_(surface_texture),
65 release_callback_(release_callback) {}
60 66
61 GLImageImpl::~GLImageImpl() { 67 GLImageImpl::~GLImageImpl() {
62 release_callback_.Run(); 68 release_callback_.Run();
63 } 69 }
64 70
65 void GLImageImpl::Destroy(bool have_context) { 71 void GLImageImpl::Destroy(bool have_context) {
66 NOTREACHED(); 72 NOTREACHED();
67 } 73 }
68 74
69 gfx::Size GLImageImpl::GetSize() { 75 gfx::Size GLImageImpl::GetSize() {
70 return gfx::Size(); 76 return gfx::Size();
71 } 77 }
72 78
73 unsigned GLImageImpl::GetInternalFormat() { 79 unsigned GLImageImpl::GetInternalFormat() {
74 return GL_RGBA; 80 return GL_RGBA;
75 } 81 }
76 82
77 bool GLImageImpl::BindTexImage(unsigned target) { 83 bool GLImageImpl::BindTexImage(unsigned target) {
78 NOTREACHED(); 84 NOTREACHED();
79 return false; 85 return false;
80 } 86 }
81 87
82 void GLImageImpl::ReleaseTexImage(unsigned target) { 88 void GLImageImpl::ReleaseTexImage(unsigned target) {
83 NOTREACHED(); 89 NOTREACHED();
84 } 90 }
85 91
92 bool GLImageImpl::CopyTexImage(unsigned target) {
93 if (target != GL_TEXTURE_EXTERNAL_OES)
94 return false;
95
96 GLint texture_id;
97 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
98 DCHECK(texture_id);
99
100 // The following code only works if we're being asked to copy into
101 // |texture_id_|. Copying into a different texture is not supported.
102 if (static_cast<unsigned>(texture_id) != texture_id_)
103 return false;
104
105 surface_texture_->UpdateTexImage();
106
107 gles2::Texture* texture =
108 texture_manager_->GetTextureForServiceId(texture_id_);
109 if (texture) {
110 // By setting image state to UNBOUND instead of COPIED we ensure that
111 // CopyTexImage() is called each time the surface texture is used for
112 // drawing.
113 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this,
114 gles2::Texture::UNBOUND);
115 }
116 return true;
117 }
118
86 bool GLImageImpl::CopyTexSubImage(unsigned target, 119 bool GLImageImpl::CopyTexSubImage(unsigned target,
87 const gfx::Point& offset, 120 const gfx::Point& offset,
88 const gfx::Rect& rect) { 121 const gfx::Rect& rect) {
89 return false; 122 return false;
90 } 123 }
91 124
92 void GLImageImpl::WillUseTexImage() {
93 surface_texture_->UpdateTexImage();
94 }
95
96 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 125 bool GLImageImpl::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
97 int z_order, 126 int z_order,
98 gfx::OverlayTransform transform, 127 gfx::OverlayTransform transform,
99 const gfx::Rect& bounds_rect, 128 const gfx::Rect& bounds_rect,
100 const gfx::RectF& crop_rect) { 129 const gfx::RectF& crop_rect) {
101 NOTREACHED(); 130 NOTREACHED();
102 return false; 131 return false;
103 } 132 }
104 133
105 void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 134 void GLImageImpl::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
(...skipping 26 matching lines...) Expand all
132 return 0; 161 return 0;
133 } 162 }
134 163
135 scoped_refptr<gfx::SurfaceTexture> surface_texture( 164 scoped_refptr<gfx::SurfaceTexture> surface_texture(
136 gfx::SurfaceTexture::Create(texture->service_id())); 165 gfx::SurfaceTexture::Create(texture->service_id()));
137 166
138 uint32 stream_id = next_id_++; 167 uint32 stream_id = next_id_++;
139 base::Closure release_callback = 168 base::Closure release_callback =
140 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture, 169 base::Bind(&StreamTextureManagerInProcess::OnReleaseStreamTexture,
141 weak_factory_.GetWeakPtr(), stream_id); 170 weak_factory_.GetWeakPtr(), stream_id);
142 scoped_refptr<gfx::GLImage> gl_image(new GLImageImpl(surface_texture, 171 scoped_refptr<gfx::GLImage> gl_image(
143 release_callback)); 172 new GLImageImpl(texture->service_id(), texture_manager, surface_texture,
173 release_callback));
144 174
145 gfx::Size size = gl_image->GetSize(); 175 gfx::Size size = gl_image->GetSize();
146 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); 176 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
147 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, 177 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
148 size.width(), size.height(), 1, 0, GL_RGBA, 178 size.width(), size.height(), 1, 0, GL_RGBA,
149 GL_UNSIGNED_BYTE, gfx::Rect(size)); 179 GL_UNSIGNED_BYTE, gfx::Rect(size));
150 texture_manager->SetLevelImage( 180 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0,
151 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get()); 181 gl_image.get(), gles2::Texture::UNBOUND);
152 182
153 { 183 {
154 base::AutoLock lock(map_lock_); 184 base::AutoLock lock(map_lock_);
155 textures_[stream_id] = surface_texture; 185 textures_[stream_id] = surface_texture;
156 } 186 }
157 187
158 if (next_id_ == 0) 188 if (next_id_ == 0)
159 next_id_++; 189 next_id_++;
160 190
161 return stream_id; 191 return stream_id;
(...skipping 10 matching lines...) Expand all
172 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) { 202 StreamTextureManagerInProcess::GetSurfaceTexture(uint32 stream_id) {
173 base::AutoLock lock(map_lock_); 203 base::AutoLock lock(map_lock_);
174 TextureMap::const_iterator it = textures_.find(stream_id); 204 TextureMap::const_iterator it = textures_.find(stream_id);
175 if (it != textures_.end()) 205 if (it != textures_.end())
176 return it->second; 206 return it->second;
177 207
178 return NULL; 208 return NULL;
179 } 209 }
180 210
181 } // namespace gpu 211 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/mailbox_manager_sync.cc ('k') | gpu/command_buffer/service/texture_definition.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698