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

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

Issue 1418603002: Revert of 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: 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 (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"
(...skipping 27 matching lines...) Expand all
38 38
39 // TODO: Ideally a valid image id was returned to the client so that 39 // TODO: Ideally a valid image id was returned to the client so that
40 // it could then call glBindTexImage2D() for doing the following. 40 // it could then call glBindTexImage2D() for doing the following.
41 scoped_refptr<gfx::GLImage> gl_image( 41 scoped_refptr<gfx::GLImage> gl_image(
42 new StreamTexture(owner_stub, stream_id, texture->service_id())); 42 new StreamTexture(owner_stub, stream_id, texture->service_id()));
43 gfx::Size size = gl_image->GetSize(); 43 gfx::Size size = gl_image->GetSize();
44 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES); 44 texture_manager->SetTarget(texture, GL_TEXTURE_EXTERNAL_OES);
45 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA, 45 texture_manager->SetLevelInfo(texture, GL_TEXTURE_EXTERNAL_OES, 0, GL_RGBA,
46 size.width(), size.height(), 1, 0, GL_RGBA, 46 size.width(), size.height(), 1, 0, GL_RGBA,
47 GL_UNSIGNED_BYTE, gfx::Rect(size)); 47 GL_UNSIGNED_BYTE, gfx::Rect(size));
48 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, 48 texture_manager->SetLevelImage(
49 gl_image.get(), 49 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get());
50 gpu::gles2::Texture::UNBOUND);
51 return true; 50 return true;
52 } 51 }
53 52
54 return false; 53 return false;
55 } 54 }
56 55
57 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, 56 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub,
58 int32 route_id, 57 int32 route_id,
59 uint32 texture_id) 58 uint32 texture_id)
60 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), 59 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)),
61 size_(0, 0), 60 size_(0, 0),
62 has_valid_frame_(false), 61 has_valid_frame_(false),
63 has_pending_frame_(false), 62 has_pending_frame_(false),
64 owner_stub_(owner_stub), 63 owner_stub_(owner_stub),
65 route_id_(route_id), 64 route_id_(route_id),
66 has_listener_(false), 65 has_listener_(false),
67 texture_id_(texture_id),
68 weak_factory_(this) { 66 weak_factory_(this) {
69 owner_stub->AddDestructionObserver(this); 67 owner_stub->AddDestructionObserver(this);
70 memset(current_matrix_, 0, sizeof(current_matrix_)); 68 memset(current_matrix_, 0, sizeof(current_matrix_));
71 owner_stub->channel()->AddRoute(route_id, this); 69 owner_stub->channel()->AddRoute(route_id, this);
72 surface_texture_->SetFrameAvailableCallback(base::Bind( 70 surface_texture_->SetFrameAvailableCallback(base::Bind(
73 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); 71 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr()));
74 } 72 }
75 73
76 StreamTexture::~StreamTexture() { 74 StreamTexture::~StreamTexture() {
77 if (owner_stub_) { 75 if (owner_stub_) {
78 owner_stub_->RemoveDestructionObserver(this); 76 owner_stub_->RemoveDestructionObserver(this);
79 owner_stub_->channel()->RemoveRoute(route_id_); 77 owner_stub_->channel()->RemoveRoute(route_id_);
80 } 78 }
81 } 79 }
82 80
83 void StreamTexture::OnWillDestroyStub() { 81 void StreamTexture::OnWillDestroyStub() {
84 owner_stub_->RemoveDestructionObserver(this); 82 owner_stub_->RemoveDestructionObserver(this);
85 owner_stub_->channel()->RemoveRoute(route_id_); 83 owner_stub_->channel()->RemoveRoute(route_id_);
86 owner_stub_ = NULL; 84 owner_stub_ = NULL;
87 85
88 // If the owner goes away, there is no need to keep the SurfaceTexture around. 86 // If the owner goes away, there is no need to keep the SurfaceTexture around.
89 // The GL texture will keep working regardless with the currently bound frame. 87 // The GL texture will keep working regardless with the currently bound frame.
90 surface_texture_ = NULL; 88 surface_texture_ = NULL;
91 } 89 }
92 90
93 void StreamTexture::Destroy(bool have_context) { 91 void StreamTexture::Destroy(bool have_context) {
94 NOTREACHED(); 92 NOTREACHED();
95 } 93 }
96 94
97 bool StreamTexture::CopyTexImage(unsigned target) { 95 void StreamTexture::WillUseTexImage() {
98 DCHECK_EQ(target, static_cast<unsigned>(GL_TEXTURE_EXTERNAL_OES));
99
100 if (!owner_stub_ || !surface_texture_.get()) 96 if (!owner_stub_ || !surface_texture_.get())
101 return true; 97 return;
102 98
103 if (has_pending_frame_) { 99 if (has_pending_frame_) {
104 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; 100 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
105 bool needs_make_current = 101 bool needs_make_current =
106 !owner_stub_->decoder()->GetGLContext()->IsCurrent(NULL); 102 !owner_stub_->decoder()->GetGLContext()->IsCurrent(NULL);
107 // On Android we should not have to perform a real context switch here when 103 // On Android we should not have to perform a real context switch here when
108 // using virtual contexts. 104 // using virtual contexts.
109 DCHECK(!needs_make_current || !owner_stub_->decoder() 105 DCHECK(!needs_make_current || !owner_stub_->decoder()
110 ->GetContextGroup() 106 ->GetContextGroup()
111 ->feature_info() 107 ->feature_info()
(...skipping 13 matching lines...) Expand all
125 // it, we have to keep the state intact in *that* context also. 121 // it, we have to keep the state intact in *that* context also.
126 const gpu::gles2::ContextState* state = 122 const gpu::gles2::ContextState* state =
127 owner_stub_->decoder()->GetContextState(); 123 owner_stub_->decoder()->GetContextState();
128 const gpu::gles2::TextureUnit& active_unit = 124 const gpu::gles2::TextureUnit& active_unit =
129 state->texture_units[state->active_texture_unit]; 125 state->texture_units[state->active_texture_unit];
130 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 126 glBindTexture(GL_TEXTURE_EXTERNAL_OES,
131 active_unit.bound_texture_external_oes.get() 127 active_unit.bound_texture_external_oes.get()
132 ? active_unit.bound_texture_external_oes->service_id() 128 ? active_unit.bound_texture_external_oes->service_id()
133 : 0); 129 : 0);
134 } 130 }
135
136 TextureManager* texture_manager =
137 owner_stub_->decoder()->GetContextGroup()->texture_manager();
138 gpu::gles2::Texture* texture =
139 texture_manager->GetTextureForServiceId(texture_id_);
140 if (texture) {
141 // By setting image state to UNBOUND instead of COPIED we ensure that
142 // CopyTexImage() is called each time the surface texture is used for
143 // drawing.
144 texture->SetLevelImage(GL_TEXTURE_EXTERNAL_OES, 0, this,
145 gpu::gles2::Texture::UNBOUND);
146 }
147 } 131 }
148 132
149 if (has_listener_ && has_valid_frame_) { 133 if (has_listener_ && has_valid_frame_) {
150 float mtx[16]; 134 float mtx[16];
151 surface_texture_->GetTransformMatrix(mtx); 135 surface_texture_->GetTransformMatrix(mtx);
152 136
153 // Only query the matrix once we have bound a valid frame. 137 // Only query the matrix once we have bound a valid frame.
154 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { 138 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) {
155 memcpy(current_matrix_, mtx, sizeof(mtx)); 139 memcpy(current_matrix_, mtx, sizeof(mtx));
156 140
157 GpuStreamTextureMsg_MatrixChanged_Params params; 141 GpuStreamTextureMsg_MatrixChanged_Params params;
158 memcpy(&params.m00, mtx, sizeof(mtx)); 142 memcpy(&params.m00, mtx, sizeof(mtx));
159 owner_stub_->channel()->Send( 143 owner_stub_->channel()->Send(
160 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); 144 new GpuStreamTextureMsg_MatrixChanged(route_id_, params));
161 } 145 }
162 } 146 }
163
164 return true;
165 } 147 }
166 148
167 void StreamTexture::OnFrameAvailable() { 149 void StreamTexture::OnFrameAvailable() {
168 has_pending_frame_ = true; 150 has_pending_frame_ = true;
169 if (has_listener_ && owner_stub_) { 151 if (has_listener_ && owner_stub_) {
170 owner_stub_->channel()->Send( 152 owner_stub_->channel()->Send(
171 new GpuStreamTextureMsg_FrameAvailable(route_id_)); 153 new GpuStreamTextureMsg_FrameAvailable(route_id_));
172 } 154 }
173 } 155 }
174 156
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return false; 214 return false;
233 } 215 }
234 216
235 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 217 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
236 uint64_t process_tracing_id, 218 uint64_t process_tracing_id,
237 const std::string& dump_name) { 219 const std::string& dump_name) {
238 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 220 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914
239 } 221 }
240 222
241 } // namespace content 223 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/stream_texture_android.h ('k') | gpu/command_buffer/service/framebuffer_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698