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

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

Issue 148513004: Android: Always update SurfaceTexture when used for draw (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "content/common/android/surface_texture_peer.h" 8 #include "content/common/android/surface_texture_peer.h"
9 #include "content/common/gpu/gpu_channel.h" 9 #include "content/common/gpu/gpu_channel.h"
10 #include "content/common/gpu/gpu_messages.h" 10 #include "content/common/gpu/gpu_messages.h"
11 #include "gpu/command_buffer/service/context_group.h" 11 #include "gpu/command_buffer/service/context_group.h"
12 #include "gpu/command_buffer/service/context_state.h"
12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 13 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
13 #include "gpu/command_buffer/service/texture_manager.h" 14 #include "gpu/command_buffer/service/texture_manager.h"
14 #include "ui/gfx/size.h" 15 #include "ui/gfx/size.h"
16 #include "ui/gl/scoped_make_current.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 using gpu::gles2::ContextGroup; 20 using gpu::gles2::ContextGroup;
19 using gpu::gles2::GLES2Decoder; 21 using gpu::gles2::GLES2Decoder;
20 using gpu::gles2::TextureManager; 22 using gpu::gles2::TextureManager;
21 using gpu::gles2::TextureRef; 23 using gpu::gles2::TextureRef;
22 24
23 // static 25 // static
24 int32 StreamTexture::Create( 26 int32 StreamTexture::Create(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 60 }
59 61
60 return 0; 62 return 0;
61 } 63 }
62 64
63 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, 65 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
64 int32 route_id, 66 int32 route_id,
65 uint32 texture_id) 67 uint32 texture_id)
66 : surface_texture_(new gfx::SurfaceTexture(texture_id)), 68 : surface_texture_(new gfx::SurfaceTexture(texture_id)),
67 size_(0, 0), 69 size_(0, 0),
68 has_updated_(false), 70 has_valid_frame_(false),
71 has_pending_frame_(false),
69 owner_stub_(owner_stub), 72 owner_stub_(owner_stub),
70 route_id_(route_id), 73 route_id_(route_id),
71 has_listener_(false), 74 has_listener_(false),
72 weak_factory_(this) { 75 weak_factory_(this) {
73 owner_stub->AddDestructionObserver(this); 76 owner_stub->AddDestructionObserver(this);
74 memset(current_matrix_, 0, sizeof(current_matrix_)); 77 memset(current_matrix_, 0, sizeof(current_matrix_));
75 owner_stub->channel()->AddRoute(route_id, this); 78 owner_stub->channel()->AddRoute(route_id, this);
76 } 79 }
77 80
78 StreamTexture::~StreamTexture() { 81 StreamTexture::~StreamTexture() {
(...skipping 14 matching lines...) Expand all
93 } 96 }
94 97
95 void StreamTexture::Destroy() { 98 void StreamTexture::Destroy() {
96 NOTREACHED(); 99 NOTREACHED();
97 } 100 }
98 101
99 void StreamTexture::WillUseTexImage() { 102 void StreamTexture::WillUseTexImage() {
100 if (!owner_stub_) 103 if (!owner_stub_)
101 return; 104 return;
102 105
103 // TODO(sievers): Update also when used in a different context. 106 if (surface_texture_.get() && has_pending_frame_) {
104 // Also see crbug.com/309162. 107 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
105 if (surface_texture_.get()) { 108 bool needs_make_current =
109 !owner_stub_->decoder()->GetGLContext()->IsCurrent(NULL);
110 // On Android we should not have to perform a real context switch here when
111 // using virtual contexts.
112 DCHECK(!needs_make_current || !owner_stub_->decoder()
113 ->GetContextGroup()
114 ->feature_info()
115 ->workarounds()
116 .use_virtualized_gl_contexts);
117 if (needs_make_current) {
118 scoped_make_current.reset(new ui::ScopedMakeCurrent(
119 owner_stub_->decoder()->GetGLContext(), owner_stub_->surface()));
120 }
106 surface_texture_->UpdateTexImage(); 121 surface_texture_->UpdateTexImage();
122 has_valid_frame_ = true;
123 has_pending_frame_ = false;
124 if (scoped_make_current.get()) {
125 // UpdateTexImage() implies glBindTexture().
126 // The cmd decoder takes care of restoring the binding for this GLImage as
127 // far as the current context is concerned, but if we temporarily change
128 // it, we have to keep the state intact in *that* context also.
129 const gpu::gles2::ContextState* state =
130 owner_stub_->decoder()->GetContextState();
131 const gpu::gles2::TextureUnit& active_unit =
132 state->texture_units[state->active_texture_unit];
133 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
134 active_unit.bound_texture_external_oes->service_id());
135 }
107 } 136 }
108 137
109 if (has_listener_) { 138 if (has_listener_ && has_valid_frame_) {
110 float mtx[16]; 139 float mtx[16];
111 surface_texture_->GetTransformMatrix(mtx); 140 surface_texture_->GetTransformMatrix(mtx);
112 141
113 // Only query the matrix once we have bound a valid frame. 142 // Only query the matrix once we have bound a valid frame.
114 if (has_updated_ && memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { 143 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) {
115 memcpy(current_matrix_, mtx, sizeof(mtx)); 144 memcpy(current_matrix_, mtx, sizeof(mtx));
116 145
117 GpuStreamTextureMsg_MatrixChanged_Params params; 146 GpuStreamTextureMsg_MatrixChanged_Params params;
118 memcpy(&params.m00, mtx, sizeof(mtx)); 147 memcpy(&params.m00, mtx, sizeof(mtx));
119 owner_stub_->channel()->Send( 148 owner_stub_->channel()->Send(
120 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); 149 new GpuStreamTextureMsg_MatrixChanged(route_id_, params));
121 } 150 }
122 } 151 }
123 } 152 }
124 153
125 void StreamTexture::OnFrameAvailable() { 154 void StreamTexture::OnFrameAvailable() {
126 has_updated_ = true; 155 has_pending_frame_ = true;
127 DCHECK(has_listener_); 156 DCHECK(has_listener_);
128 if (owner_stub_) { 157 if (owner_stub_) {
129 owner_stub_->channel()->Send( 158 owner_stub_->channel()->Send(
130 new GpuStreamTextureMsg_FrameAvailable(route_id_)); 159 new GpuStreamTextureMsg_FrameAvailable(route_id_));
131 } 160 }
132 } 161 }
133 162
134 gfx::Size StreamTexture::GetSize() { 163 gfx::Size StreamTexture::GetSize() {
135 return size_; 164 return size_;
136 } 165 }
(...skipping 22 matching lines...) Expand all
159 if (!owner_stub_) 188 if (!owner_stub_)
160 return; 189 return;
161 190
162 base::ProcessHandle process = owner_stub_->channel()->renderer_pid(); 191 base::ProcessHandle process = owner_stub_->channel()->renderer_pid();
163 192
164 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer( 193 SurfaceTexturePeer::GetInstance()->EstablishSurfaceTexturePeer(
165 process, surface_texture_, primary_id, secondary_id); 194 process, surface_texture_, primary_id, secondary_id);
166 } 195 }
167 196
168 } // namespace content 197 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/stream_texture_android.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698