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

Side by Side Diff: content/common/gpu/stream_texture_android.cc

Issue 1639183002: Report the SurfaceTexture tranform matrix to CC timely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge UpdateTexImage to OnFrameAvailable Created 4 years, 11 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
« no previous file with comments | « content/common/gpu/stream_texture_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(&params.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;
227 if (has_listener_ && owner_stub_) { 179 if (has_listener_ && owner_stub_) {
228 owner_stub_->channel()->Send( 180 owner_stub_->channel()->Send(
229 new GpuStreamTextureMsg_FrameAvailable(route_id_)); 181 new GpuStreamTextureMsg_FrameAvailable(route_id_));
230 } 182 }
183 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current(MakeStubCurrent());
no sievers 2016/01/27 19:05:20 This is not safe here (unlike the previous call si
jchen10 2016/01/28 01:31:39 Done.
184
185 surface_texture_->UpdateTexImage();
no sievers 2016/01/27 19:05:20 It's not really clear how this fixes it. It just r
jchen10 2016/01/28 01:31:39 The current problematic work flow is like: 1. Stre
186
187 float mtx[16];
188 surface_texture_->GetTransformMatrix(mtx);
189
190 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) {
191 memcpy(current_matrix_, mtx, sizeof(mtx));
192
193 if (has_listener_) {
194 GpuStreamTextureMsg_MatrixChanged_Params params;
195 memcpy(&params.m00, mtx, sizeof(mtx));
196 owner_stub_->channel()->Send(
197 new GpuStreamTextureMsg_MatrixChanged(route_id_, params));
198 }
199 }
200 if (scoped_make_current.get()) {
201 // UpdateTexImage() implies glBindTexture().
202 // The cmd decoder takes care of restoring the binding for this GLImage as
203 // far as the current context is concerned, but if we temporarily change
204 // it, we have to keep the state intact in *that* context also.
205 const gpu::gles2::ContextState* state =
206 owner_stub_->decoder()->GetContextState();
207 const gpu::gles2::TextureUnit& active_unit =
208 state->texture_units[state->active_texture_unit];
209 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
210 active_unit.bound_texture_external_oes.get()
211 ? active_unit.bound_texture_external_oes->service_id()
212 : 0);
213 }
231 } 214 }
232 215
233 gfx::Size StreamTexture::GetSize() { 216 gfx::Size StreamTexture::GetSize() {
234 return size_; 217 return size_;
235 } 218 }
236 219
237 unsigned StreamTexture::GetInternalFormat() { 220 unsigned StreamTexture::GetInternalFormat() {
238 return GL_RGBA; 221 return GL_RGBA;
239 } 222 }
240 223
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 274
292 if (rect != gfx::Rect(size_)) { 275 if (rect != gfx::Rect(size_)) {
293 LOG(ERROR) << "Sub-rectangle is not supported"; 276 LOG(ERROR) << "Sub-rectangle is not supported";
294 return false; 277 return false;
295 } 278 }
296 279
297 GLint target_texture = 0; 280 GLint target_texture = 0;
298 glGetIntegerv(GL_TEXTURE_BINDING_2D, &target_texture); 281 glGetIntegerv(GL_TEXTURE_BINDING_2D, &target_texture);
299 DCHECK(target_texture); 282 DCHECK(target_texture);
300 283
301 UpdateTexImage();
302
303 if (!framebuffer_) { 284 if (!framebuffer_) {
304 glGenFramebuffersEXT(1, &framebuffer_); 285 glGenFramebuffersEXT(1, &framebuffer_);
305 286
306 // This vertex shader introduces a y flip before applying the stream 287 // This vertex shader introduces a y flip before applying the stream
307 // texture matrix. This is required because the stream texture matrix 288 // texture matrix. This is required because the stream texture matrix
308 // Android provides is intended to be used in a y-up coordinate system, 289 // Android provides is intended to be used in a y-up coordinate system,
309 // whereas Chromium expects y-down. 290 // whereas Chromium expects y-down.
310 291
311 // clang-format off 292 // clang-format off
312 const char kVertexShader[] = STRINGIZE( 293 const char kVertexShader[] = STRINGIZE(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return false; 358 return false;
378 } 359 }
379 360
380 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 361 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
381 uint64_t process_tracing_id, 362 uint64_t process_tracing_id,
382 const std::string& dump_name) { 363 const std::string& dump_name) {
383 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 364 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914
384 } 365 }
385 366
386 } // namespace content 367 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/stream_texture_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698