OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/media/renderer_gpu_video_decoder_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 media::VideoDecodeAccelerator::Client* client) { | 89 media::VideoDecodeAccelerator::Client* client) { |
90 DCHECK(message_loop_->BelongsToCurrentThread()); | 90 DCHECK(message_loop_->BelongsToCurrentThread()); |
91 | 91 |
92 if (context_.get() && context_->GetCommandBufferProxy()) { | 92 if (context_.get() && context_->GetCommandBufferProxy()) { |
93 vda_ = gpu_channel_host_->CreateVideoDecoder( | 93 vda_ = gpu_channel_host_->CreateVideoDecoder( |
94 context_->GetCommandBufferProxy()->GetRouteID(), profile, client); | 94 context_->GetCommandBufferProxy()->GetRouteID(), profile, client); |
95 } | 95 } |
96 compositor_loop_async_waiter_.Signal(); | 96 compositor_loop_async_waiter_.Signal(); |
97 } | 97 } |
98 | 98 |
99 bool RendererGpuVideoDecoderFactories::CreateTextures( | 99 uint32 RendererGpuVideoDecoderFactories::CreateTextures( |
100 int32 count, const gfx::Size& size, | 100 int32 count, const gfx::Size& size, |
101 std::vector<uint32>* texture_ids, | 101 std::vector<uint32>* texture_ids, |
| 102 std::vector<gpu::Mailbox>* texture_mailboxes, |
102 uint32 texture_target) { | 103 uint32 texture_target) { |
| 104 uint32 sync_point = 0; |
| 105 |
103 DCHECK(!message_loop_->BelongsToCurrentThread()); | 106 DCHECK(!message_loop_->BelongsToCurrentThread()); |
104 message_loop_->PostTask(FROM_HERE, base::Bind( | 107 message_loop_->PostTask(FROM_HERE, base::Bind( |
105 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 108 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
106 count, size, texture_target)); | 109 count, size, texture_target, &sync_point)); |
107 | 110 |
108 base::WaitableEvent* objects[] = {&aborted_waiter_, | 111 base::WaitableEvent* objects[] = {&aborted_waiter_, |
109 &compositor_loop_async_waiter_}; | 112 &compositor_loop_async_waiter_}; |
110 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) | 113 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) |
111 return false; | 114 return 0; |
112 texture_ids->swap(created_textures_); | 115 texture_ids->swap(created_textures_); |
113 return true; | 116 texture_mailboxes->swap(created_texture_mailboxes_); |
| 117 return sync_point; |
114 } | 118 } |
115 | 119 |
116 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( | 120 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( |
117 int32 count, const gfx::Size& size, uint32 texture_target) { | 121 int32 count, const gfx::Size& size, uint32 texture_target, |
| 122 uint32* sync_point) { |
118 DCHECK(message_loop_->BelongsToCurrentThread()); | 123 DCHECK(message_loop_->BelongsToCurrentThread()); |
119 DCHECK(texture_target); | 124 DCHECK(texture_target); |
120 | 125 |
121 if (!context_.get()) { | 126 if (!context_.get()) { |
122 compositor_loop_async_waiter_.Signal(); | 127 compositor_loop_async_waiter_.Signal(); |
123 return; | 128 return; |
124 } | 129 } |
125 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 130 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
126 created_textures_.resize(count); | 131 created_textures_.resize(count); |
| 132 created_texture_mailboxes_.resize(count); |
127 gles2->GenTextures(count, &created_textures_[0]); | 133 gles2->GenTextures(count, &created_textures_[0]); |
128 for (int i = 0; i < count; ++i) { | 134 for (int i = 0; i < count; ++i) { |
129 gles2->ActiveTexture(GL_TEXTURE0); | 135 gles2->ActiveTexture(GL_TEXTURE0); |
130 uint32 texture_id = created_textures_[i]; | 136 uint32 texture_id = created_textures_[i]; |
131 gles2->BindTexture(texture_target, texture_id); | 137 gles2->BindTexture(texture_target, texture_id); |
132 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 138 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
133 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 139 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
134 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 140 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
135 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 141 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
136 if (texture_target == GL_TEXTURE_2D) { | 142 if (texture_target == GL_TEXTURE_2D) { |
137 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), | 143 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), |
138 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 144 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
139 } | 145 } |
| 146 gles2->GenMailboxCHROMIUM(created_texture_mailboxes_[i].name); |
| 147 gles2->ProduceTextureCHROMIUM(texture_target, |
| 148 created_texture_mailboxes_[i].name); |
140 } | 149 } |
| 150 |
141 // We need a glFlush here to guarantee the decoder (in the GPU process) can | 151 // We need a glFlush here to guarantee the decoder (in the GPU process) can |
142 // use the texture ids we return here. Since textures are expected to be | 152 // use the texture ids we return here. Since textures are expected to be |
143 // reused, this should not be unacceptably expensive. | 153 // reused, this should not be unacceptably expensive. |
144 gles2->Flush(); | 154 gles2->Flush(); |
145 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 155 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 156 |
| 157 *sync_point = gles2->InsertSyncPointCHROMIUM(); |
146 compositor_loop_async_waiter_.Signal(); | 158 compositor_loop_async_waiter_.Signal(); |
147 } | 159 } |
148 | 160 |
149 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 161 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
150 DCHECK(!message_loop_->BelongsToCurrentThread()); | 162 DCHECK(!message_loop_->BelongsToCurrentThread()); |
151 message_loop_->PostTask(FROM_HERE, base::Bind( | 163 message_loop_->PostTask(FROM_HERE, base::Bind( |
152 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 164 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
153 } | 165 } |
154 | 166 |
155 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 167 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
156 DCHECK(message_loop_->BelongsToCurrentThread()); | 168 DCHECK(message_loop_->BelongsToCurrentThread()); |
157 if (!context_.get()) | 169 if (!context_.get()) |
158 return; | 170 return; |
159 | 171 |
160 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 172 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
161 gles2->DeleteTextures(1, &texture_id); | 173 gles2->DeleteTextures(1, &texture_id); |
162 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 174 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
163 } | 175 } |
164 | 176 |
| 177 void RendererGpuVideoDecoderFactories::WaitSyncPoint(uint32 sync_point) { |
| 178 if (message_loop_->BelongsToCurrentThread()) { |
| 179 AsyncWaitSyncPoint(sync_point); |
| 180 return; |
| 181 } |
| 182 |
| 183 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 184 &RendererGpuVideoDecoderFactories::AsyncWaitSyncPoint, |
| 185 this, |
| 186 sync_point)); |
| 187 base::WaitableEvent* objects[] = {&aborted_waiter_, |
| 188 &compositor_loop_async_waiter_}; |
| 189 base::WaitableEvent::WaitMany(objects, arraysize(objects)); |
| 190 } |
| 191 |
| 192 void RendererGpuVideoDecoderFactories::AsyncWaitSyncPoint(uint32 sync_point) { |
| 193 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 194 if (!context_) { |
| 195 compositor_loop_async_waiter_.Signal(); |
| 196 return; |
| 197 } |
| 198 |
| 199 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
| 200 gles2->WaitSyncPointCHROMIUM(sync_point); |
| 201 compositor_loop_async_waiter_.Signal(); |
| 202 } |
| 203 |
165 void RendererGpuVideoDecoderFactories::ReadPixels( | 204 void RendererGpuVideoDecoderFactories::ReadPixels( |
166 uint32 texture_id, uint32 texture_target, const gfx::Size& size, | 205 uint32 texture_id, uint32 texture_target, const gfx::Size& size, |
167 const SkBitmap& pixels) { | 206 const SkBitmap& pixels) { |
168 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. | 207 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. |
169 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to | 208 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to |
170 // ensure that the underlying pixels in the SkBitmap passed in remain valid | 209 // ensure that the underlying pixels in the SkBitmap passed in remain valid |
171 // until the AsyncReadPixels() call completes. | 210 // until the AsyncReadPixels() call completes. |
172 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); | 211 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); |
173 | 212 |
174 if (!message_loop_->BelongsToCurrentThread()) { | 213 if (!message_loop_->BelongsToCurrentThread()) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return aborted_waiter_.IsSignaled(); | 295 return aborted_waiter_.IsSignaled(); |
257 } | 296 } |
258 | 297 |
259 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { | 298 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { |
260 // OK to release because Destroy() will delete the VDA instance. | 299 // OK to release because Destroy() will delete the VDA instance. |
261 if (vda_) | 300 if (vda_) |
262 vda_.release()->Destroy(); | 301 vda_.release()->Destroy(); |
263 } | 302 } |
264 | 303 |
265 } // namespace content | 304 } // namespace content |
OLD | NEW |