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 "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 20 matching lines...) Expand all Loading... | |
31 GLES2Decoder* decoder = owner_stub->decoder(); | 31 GLES2Decoder* decoder = owner_stub->decoder(); |
32 TextureManager* texture_manager = | 32 TextureManager* texture_manager = |
33 decoder->GetContextGroup()->texture_manager(); | 33 decoder->GetContextGroup()->texture_manager(); |
34 TextureRef* texture = texture_manager->GetTexture(client_texture_id); | 34 TextureRef* texture = texture_manager->GetTexture(client_texture_id); |
35 | 35 |
36 if (texture && (!texture->texture()->target() || | 36 if (texture && (!texture->texture()->target() || |
37 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { | 37 texture->texture()->target() == GL_TEXTURE_EXTERNAL_OES)) { |
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(new StreamTexture( |
42 new StreamTexture(owner_stub, stream_id, texture->service_id())); | 42 owner_stub, stream_id, client_texture_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( | 48 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, |
49 texture, GL_TEXTURE_EXTERNAL_OES, 0, gl_image.get()); | 49 gl_image.get(), |
50 gpu::gles2::Texture::UNBOUND); | |
50 return true; | 51 return true; |
51 } | 52 } |
52 | 53 |
53 return false; | 54 return false; |
54 } | 55 } |
55 | 56 |
56 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, | 57 StreamTexture::StreamTexture(GpuCommandBufferStub* owner_stub, |
57 int32 route_id, | 58 int32 route_id, |
59 uint32 client_texture_id, | |
58 uint32 texture_id) | 60 uint32 texture_id) |
59 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), | 61 : surface_texture_(gfx::SurfaceTexture::Create(texture_id)), |
60 size_(0, 0), | 62 size_(0, 0), |
61 has_valid_frame_(false), | 63 has_valid_frame_(false), |
62 has_pending_frame_(false), | 64 has_pending_frame_(false), |
63 owner_stub_(owner_stub), | 65 owner_stub_(owner_stub), |
64 route_id_(route_id), | 66 route_id_(route_id), |
65 has_listener_(false), | 67 has_listener_(false), |
68 client_texture_id_(client_texture_id), | |
66 weak_factory_(this) { | 69 weak_factory_(this) { |
67 owner_stub->AddDestructionObserver(this); | 70 owner_stub->AddDestructionObserver(this); |
68 memset(current_matrix_, 0, sizeof(current_matrix_)); | 71 memset(current_matrix_, 0, sizeof(current_matrix_)); |
69 owner_stub->channel()->AddRoute(route_id, this); | 72 owner_stub->channel()->AddRoute(route_id, this); |
70 surface_texture_->SetFrameAvailableCallback(base::Bind( | 73 surface_texture_->SetFrameAvailableCallback(base::Bind( |
71 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); | 74 &StreamTexture::OnFrameAvailable, weak_factory_.GetWeakPtr())); |
72 } | 75 } |
73 | 76 |
74 StreamTexture::~StreamTexture() { | 77 StreamTexture::~StreamTexture() { |
75 if (owner_stub_) { | 78 if (owner_stub_) { |
76 owner_stub_->RemoveDestructionObserver(this); | 79 owner_stub_->RemoveDestructionObserver(this); |
77 owner_stub_->channel()->RemoveRoute(route_id_); | 80 owner_stub_->channel()->RemoveRoute(route_id_); |
78 } | 81 } |
79 } | 82 } |
80 | 83 |
81 void StreamTexture::OnWillDestroyStub() { | 84 void StreamTexture::OnWillDestroyStub() { |
82 owner_stub_->RemoveDestructionObserver(this); | 85 owner_stub_->RemoveDestructionObserver(this); |
83 owner_stub_->channel()->RemoveRoute(route_id_); | 86 owner_stub_->channel()->RemoveRoute(route_id_); |
84 owner_stub_ = NULL; | 87 owner_stub_ = NULL; |
85 | 88 |
86 // If the owner goes away, there is no need to keep the SurfaceTexture around. | 89 // If the owner goes away, there is no need to keep the SurfaceTexture around. |
87 // The GL texture will keep working regardless with the currently bound frame. | 90 // The GL texture will keep working regardless with the currently bound frame. |
88 surface_texture_ = NULL; | 91 surface_texture_ = NULL; |
89 } | 92 } |
90 | 93 |
91 void StreamTexture::Destroy(bool have_context) { | 94 void StreamTexture::Destroy(bool have_context) { |
92 NOTREACHED(); | 95 NOTREACHED(); |
93 } | 96 } |
94 | 97 |
95 void StreamTexture::WillUseTexImage() { | 98 bool StreamTexture::CopyTexImage(unsigned target) { |
99 DCHECK_EQ(target, static_cast<unsigned>(GL_TEXTURE_EXTERNAL_OES)); | |
100 | |
96 if (!owner_stub_ || !surface_texture_.get()) | 101 if (!owner_stub_ || !surface_texture_.get()) |
97 return; | 102 return true; |
98 | 103 |
99 if (has_pending_frame_) { | 104 if (has_pending_frame_) { |
100 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 105 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
101 bool needs_make_current = | 106 bool needs_make_current = |
102 !owner_stub_->decoder()->GetGLContext()->IsCurrent(NULL); | 107 !owner_stub_->decoder()->GetGLContext()->IsCurrent(NULL); |
103 // On Android we should not have to perform a real context switch here when | 108 // On Android we should not have to perform a real context switch here when |
104 // using virtual contexts. | 109 // using virtual contexts. |
105 DCHECK(!needs_make_current || !owner_stub_->decoder() | 110 DCHECK(!needs_make_current || !owner_stub_->decoder() |
106 ->GetContextGroup() | 111 ->GetContextGroup() |
107 ->feature_info() | 112 ->feature_info() |
(...skipping 13 matching lines...) Expand all Loading... | |
121 // it, we have to keep the state intact in *that* context also. | 126 // it, we have to keep the state intact in *that* context also. |
122 const gpu::gles2::ContextState* state = | 127 const gpu::gles2::ContextState* state = |
123 owner_stub_->decoder()->GetContextState(); | 128 owner_stub_->decoder()->GetContextState(); |
124 const gpu::gles2::TextureUnit& active_unit = | 129 const gpu::gles2::TextureUnit& active_unit = |
125 state->texture_units[state->active_texture_unit]; | 130 state->texture_units[state->active_texture_unit]; |
126 glBindTexture(GL_TEXTURE_EXTERNAL_OES, | 131 glBindTexture(GL_TEXTURE_EXTERNAL_OES, |
127 active_unit.bound_texture_external_oes.get() | 132 active_unit.bound_texture_external_oes.get() |
128 ? active_unit.bound_texture_external_oes->service_id() | 133 ? active_unit.bound_texture_external_oes->service_id() |
129 : 0); | 134 : 0); |
130 } | 135 } |
136 | |
137 TextureManager* texture_manager = | |
138 owner_stub_->decoder()->GetContextGroup()->texture_manager(); | |
139 TextureRef* texture = texture_manager->GetTexture(client_texture_id_); | |
no sievers
2015/10/15 21:52:44
What if the original client texture was deleted, b
reveman
2015/10/15 22:56:16
hm, does that make it invalid to refer to the text
| |
140 // By setting image state to UNBOUND instead of COPIED we ensure that | |
141 // CopyTexImage() is called each time the surface texture is used for | |
142 // drawing. | |
143 texture_manager->SetLevelImage(texture, GL_TEXTURE_EXTERNAL_OES, 0, this, | |
144 gpu::gles2::Texture::UNBOUND); | |
131 } | 145 } |
132 | 146 |
133 if (has_listener_ && has_valid_frame_) { | 147 if (has_listener_ && has_valid_frame_) { |
134 float mtx[16]; | 148 float mtx[16]; |
135 surface_texture_->GetTransformMatrix(mtx); | 149 surface_texture_->GetTransformMatrix(mtx); |
136 | 150 |
137 // Only query the matrix once we have bound a valid frame. | 151 // Only query the matrix once we have bound a valid frame. |
138 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { | 152 if (memcmp(current_matrix_, mtx, sizeof(mtx)) != 0) { |
139 memcpy(current_matrix_, mtx, sizeof(mtx)); | 153 memcpy(current_matrix_, mtx, sizeof(mtx)); |
140 | 154 |
141 GpuStreamTextureMsg_MatrixChanged_Params params; | 155 GpuStreamTextureMsg_MatrixChanged_Params params; |
142 memcpy(¶ms.m00, mtx, sizeof(mtx)); | 156 memcpy(¶ms.m00, mtx, sizeof(mtx)); |
143 owner_stub_->channel()->Send( | 157 owner_stub_->channel()->Send( |
144 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); | 158 new GpuStreamTextureMsg_MatrixChanged(route_id_, params)); |
145 } | 159 } |
146 } | 160 } |
161 | |
162 return true; | |
147 } | 163 } |
148 | 164 |
149 void StreamTexture::OnFrameAvailable() { | 165 void StreamTexture::OnFrameAvailable() { |
150 has_pending_frame_ = true; | 166 has_pending_frame_ = true; |
151 if (has_listener_ && owner_stub_) { | 167 if (has_listener_ && owner_stub_) { |
152 owner_stub_->channel()->Send( | 168 owner_stub_->channel()->Send( |
153 new GpuStreamTextureMsg_FrameAvailable(route_id_)); | 169 new GpuStreamTextureMsg_FrameAvailable(route_id_)); |
154 } | 170 } |
155 } | 171 } |
156 | 172 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 return false; | 230 return false; |
215 } | 231 } |
216 | 232 |
217 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 233 void StreamTexture::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
218 uint64_t process_tracing_id, | 234 uint64_t process_tracing_id, |
219 const std::string& dump_name) { | 235 const std::string& dump_name) { |
220 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 | 236 // TODO(ericrk): Add OnMemoryDump for GLImages. crbug.com/514914 |
221 } | 237 } |
222 | 238 |
223 } // namespace content | 239 } // namespace content |
OLD | NEW |