Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/gpu/stream_texture_android.h" | 5 #include "content/common/gpu/stream_texture_android.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/stringize_macros.h" | 10 #include "base/strings/stringize_macros.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 61 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
| 62 int32_t route_id, | 62 int32_t route_id, |
| 63 uint32_t texture_id) | 63 uint32_t texture_id) |
| 64 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), | 64 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), |
| 65 size_(0, 0), | 65 size_(0, 0), |
| 66 has_valid_frame_(false), | |
| 67 has_pending_frame_(false), | |
| 68 owner_stub_(owner_stub), | 66 owner_stub_(owner_stub), |
| 69 route_id_(route_id), | 67 route_id_(route_id), |
| 70 has_listener_(false), | 68 has_listener_(false), |
| 71 texture_id_(texture_id), | 69 texture_id_(texture_id), |
| 72 framebuffer_(0), | 70 framebuffer_(0), |
| 73 vertex_shader_(0), | 71 vertex_shader_(0), |
| 74 fragment_shader_(0), | 72 fragment_shader_(0), |
| 75 program_(0), | 73 program_(0), |
| 76 vertex_buffer_(0), | 74 vertex_buffer_(0), |
| 77 u_xform_location_(-1), | 75 u_xform_location_(-1), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 ->feature_info() | 131 ->feature_info() |
| 134 ->workarounds() | 132 ->workarounds() |
| 135 .use_virtualized_gl_contexts); | 133 .use_virtualized_gl_contexts); |
| 136 if (needs_make_current) { | 134 if (needs_make_current) { |
| 137 scoped_make_current.reset(new ui::ScopedMakeCurrent( | 135 scoped_make_current.reset(new ui::ScopedMakeCurrent( |
| 138 owner_stub_->decoder()->GetGLContext(), owner_stub_->surface())); | 136 owner_stub_->decoder()->GetGLContext(), owner_stub_->surface())); |
| 139 } | 137 } |
| 140 return scoped_make_current; | 138 return scoped_make_current; |
| 141 } | 139 } |
| 142 | 140 |
| 143 void StreamTexture::UpdateTexImage() { | |
| 144 DCHECK(surface_texture_.get()); | |
| 145 DCHECK(owner_stub_); | |
| 146 | |
| 147 if (!has_pending_frame_) return; | |
| 148 | |
| 149 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current(MakeStubCurrent()); | |
| 150 | |
| 151 surface_texture_->UpdateTexImage(); | |
| 152 | |
| 153 has_valid_frame_ = true; | |
| 154 has_pending_frame_ = false; | |
| 155 | |
| 156 float mtx[16]; | |
| 157 surface_texture_->GetTransformMatrix(mtx); | |
| 158 | |
| 159 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { | |
| 160 memcpy(current_matrix_, mtx, sizeof(mtx)); | |
| 161 | |
| 162 if (has_listener_) { | |
| 163 GpuStreamTextureMsg_MatrixChanged_Params params; | |
| 164 memcpy(¶ms.m00, mtx, sizeof(mtx)); | |
| 165 owner_stub_->channel()->Send( | |
| 166 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 if (scoped_make_current.get()) { | |
| 171 // UpdateTexImage() implies glBindTexture(). | |
| 172 // The cmd decoder takes care of restoring the binding for this GLImage as | |
| 173 // far as the current context is concerned, but if we temporarily change | |
| 174 // it, we have to keep the state intact in *that* context also. | |
| 175 const gpu::gles2::ContextState* state = | |
| 176 owner_stub_->decoder()->GetContextState(); | |
| 177 const gpu::gles2::TextureUnit& active_unit = | |
| 178 state->texture_units[state->active_texture_unit]; | |
| 179 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | |
| 180 active_unit.bound_texture_external_oes.get() | |
| 181 ? active_unit.bound_texture_external_oes->service_id() | |
| 182 : 0); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 bool StreamTexture::CopyTexImage(unsigned target) { | 141 bool StreamTexture::CopyTexImage(unsigned target) { |
| 187 if (target == GL_TEXTURE_2D) { | 142 if (target == GL_TEXTURE_2D) { |
| 188 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, | 143 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size_.width(), size_.height(), 0, |
| 189 GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | 144 GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 190 return CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(), gfx::Rect(size_)); | 145 return CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(), gfx::Rect(size_)); |
| 191 } | 146 } |
| 192 | 147 |
| 193 if (target != GL_TEXTURE_EXTERNAL_OES) | 148 if (target != GL_TEXTURE_EXTERNAL_OES) |
| 194 return false; | 149 return false; |
| 195 | 150 |
| 196 if (!owner_stub_ || !surface_texture_.get()) | 151 if (!owner_stub_ || !surface_texture_.get()) |
| 197 return true; | 152 return true; |
| 198 | 153 |
| 199 GLint texture_id; | 154 GLint texture_id; |
| 200 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); | 155 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id); |
| 201 DCHECK(texture_id); | 156 DCHECK(texture_id); |
| 202 | 157 |
| 203 // The following code only works if we're being asked to copy into | 158 // The following code only works if we're being asked to copy into |
| 204 // |texture_id_|. Copying into a different texture is not supported. | 159 // |texture_id_|. Copying into a different texture is not supported. |
| 205 if (static_cast<unsigned>(texture_id) != texture_id_) | 160 if (static_cast<unsigned>(texture_id) != texture_id_) |
| 206 return false; | 161 return false; |
| 207 | 162 |
| 208 UpdateTexImage(); | |
| 209 | |
| 210 TextureManager* texture_manager = | 163 TextureManager* texture_manager = |
| 211 owner_stub_->decoder()->GetContextGroup()->texture_manager(); | 164 owner_stub_->decoder()->GetContextGroup()->texture_manager(); |
| 212 gpu::gles2::Texture* texture = | 165 gpu::gles2::Texture* texture = |
| 213 texture_manager->GetTextureForServiceId(texture_id_); | 166 texture_manager->GetTextureForServiceId(texture_id_); |
| 214 if (texture) { | 167 if (texture) { |
| 215 // By setting image state to UNBOUND instead of COPIED we ensure that | 168 // By setting image state to UNBOUND instead of COPIED we ensure that |
| 216 // CopyTexImage() is called each time the surface texture is used for | 169 // CopyTexImage() is called each time the surface texture is used for |
| 217 // drawing. | 170 // drawing. |
| 218 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, | 171 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this, |
| 219 gpu::gles2::Texture::UNBOUND); | 172 gpu::gles2::Texture::UNBOUND); |
| 220 } | 173 } |
| 221 | 174 |
| 222 return true; | 175 return true; |
| 223 } | 176 } |
| 224 | 177 |
| 225 void StreamTexture::OnFrameAvailable() { | 178 void StreamTexture::OnFrameAvailable() { |
| 226 has_pending_frame_ = true; | 179 if (!owner_stub_) |
| 227 if (has_listener_ && owner_stub_) { | 180 return; |
| 181 | |
| 182 if (has_listener_) { | |
| 228 owner_stub_->channel()->Send( | 183 owner_stub_->channel()->Send( |
| 229 new GpuStreamTextureMsg_FrameAvailable(route_id_)); | 184 new GpuStreamTextureMsg_FrameAvailable(route_id_)); |
|
liberato (no reviews please)
2016/02/02 15:49:44
if one moves this later (after matrixchanged), doe
| |
| 230 } | 185 } |
| 186 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current(MakeStubCurrent()); | |
| 187 | |
| 188 surface_texture_->UpdateTexImage(); | |
| 189 | |
| 190 float mtx[16]; | |
| 191 surface_texture_->GetTransformMatrix(mtx); | |
| 192 | |
| 193 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { | |
| 194 memcpy(current_matrix_, mtx, sizeof(mtx)); | |
| 195 | |
| 196 if (has_listener_) { | |
| 197 GpuStreamTextureMsg_MatrixChanged_Params params; | |
| 198 memcpy(¶ms.m00, mtx, sizeof(mtx)); | |
| 199 owner_stub_->channel()->Send( | |
|
no sievers
2016/02/01 18:30:47
I meant: Send this message before GpuStreamTexture
jchen10
2016/02/02 03:19:24
So nice! :)
Done.
| |
| 200 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); | |
| 201 } | |
| 202 } | |
| 203 if (scoped_make_current.get()) { | |
| 204 // UpdateTexImage() implies glBindTexture(). | |
| 205 // The cmd decoder takes care of restoring the binding for this GLImage as | |
| 206 // far as the current context is concerned, but if we temporarily change | |
| 207 // it, we have to keep the state intact in *that* context also. | |
| 208 const gpu::gles2::ContextState* state = | |
| 209 owner_stub_->decoder()->GetContextState(); | |
| 210 const gpu::gles2::TextureUnit& active_unit = | |
| 211 state->texture_units[state->active_texture_unit]; | |
| 212 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | |
| 213 active_unit.bound_texture_external_oes.get() | |
| 214 ? active_unit.bound_texture_external_oes->service_id() | |
| 215 : 0); | |
| 216 } | |
| 231 } | 217 } |
| 232 | 218 |
| 233 gfx::Size StreamTexture::GetSize() { | 219 gfx::Size StreamTexture::GetSize() { |
| 234 return size_; | 220 return size_; |
| 235 } | 221 } |
| 236 | 222 |
| 237 unsigned StreamTexture::GetInternalFormat() { | 223 unsigned StreamTexture::GetInternalFormat() { |
| 238 return GL_RGBA; | 224 return GL_RGBA; |
| 239 } | 225 } |
| 240 | 226 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 277 |
| 292 if (rect != gfx::Rect(size_)) { | 278 if (rect != gfx::Rect(size_)) { |
| 293 LOG(ERROR) << "Sub-rectangle is not supported"; | 279 LOG(ERROR) << "Sub-rectangle is not supported"; |
| 294 return false; | 280 return false; |
| 295 } | 281 } |
| 296 | 282 |
| 297 GLint target_texture = 0; | 283 GLint target_texture = 0; |
| 298 glGetIntegerv(GL_TEXTURE_BINDING_2D, &target_texture); | 284 glGetIntegerv(GL_TEXTURE_BINDING_2D, &target_texture); |
| 299 DCHECK(target_texture); | 285 DCHECK(target_texture); |
| 300 | 286 |
| 301 UpdateTexImage(); | |
| 302 | |
| 303 if (!framebuffer_) { | 287 if (!framebuffer_) { |
| 304 glGenFramebuffersEXT(1, &framebuffer_); | 288 glGenFramebuffersEXT(1, &framebuffer_); |
| 305 | 289 |
| 306 // This vertex shader introduces a y flip before applying the stream | 290 // This vertex shader introduces a y flip before applying the stream |
| 307 // texture matrix. This is required because the stream texture matrix | 291 // texture matrix. This is required because the stream texture matrix |
| 308 // Android provides is intended to be used in a y-up coordinate system, | 292 // Android provides is intended to be used in a y-up coordinate system, |
| 309 // whereas Chromium expects y-down. | 293 // whereas Chromium expects y-down. |
| 310 | 294 |
| 311 // clang-format off | 295 // clang-format off |
| 312 const char kVertexShader[] = STRINGIZE( | 296 const char kVertexShader[] = STRINGIZE( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 return false; | 361 return false; |
| 378 } | 362 } |
| 379 | 363 |
| 380 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 364 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
| 381 uint64_t process_tracing_id, | 365 uint64_t process_tracing_id, |
| 382 const std::string& dump_name) { | 366 const std::string& dump_name) { |
| 383 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 367 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
| 384 } | 368 } |
| 385 | 369 |
| 386 } // namespace content | 370 } // namespace content |
| OLD | NEW |