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

Side by Side Diff: content/renderer/media/renderer_gpu_video_accelerator_factories.cc

Issue 316553002: Convert format of pixels read from GL to BGRA on CPU if necessary (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/renderer/media/renderer_gpu_video_accelerator_factories.h" 5 #include "content/renderer/media/renderer_gpu_video_accelerator_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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 193 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
194 context->copyTextureCHROMIUM( 194 context->copyTextureCHROMIUM(
195 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE); 195 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE);
196 196
197 GLuint fb; 197 GLuint fb;
198 gles2->GenFramebuffers(1, &fb); 198 gles2->GenFramebuffers(1, &fb);
199 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); 199 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb);
200 gles2->FramebufferTexture2D( 200 gles2->FramebufferTexture2D(
201 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0); 201 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0);
202 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); 202 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4);
203
203 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ 204 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \
204 SK_A32_SHIFT == 24 205 SK_A32_SHIFT == 24
205 GLenum skia_format = GL_BGRA_EXT; 206 GLenum skia_format = GL_BGRA_EXT;
207 GLenum read_format = GL_BGRA_EXT;
208 GLint supported_format = 0;
209 GLint supported_type = 0;
210 gles2->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &supported_format);
211 gles2->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &supported_type);
212 if (supported_format != GL_BGRA_EXT || supported_type != GL_UNSIGNED_BYTE) {
213 read_format = GL_RGBA;
214 }
206 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ 215 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \
207 SK_A32_SHIFT == 24 216 SK_A32_SHIFT == 24
208 GLenum skia_format = GL_RGBA; 217 GLenum skia_format = GL_RGBA;
218 GLenum read_format = GL_RGBA;
209 #else 219 #else
210 #error Unexpected Skia ARGB_8888 layout! 220 #error Unexpected Skia ARGB_8888 layout!
211 #endif 221 #endif
212 gles2->ReadPixels(visible_rect.x(), 222 gles2->ReadPixels(visible_rect.x(),
213 visible_rect.y(), 223 visible_rect.y(),
214 visible_rect.width(), 224 visible_rect.width(),
215 visible_rect.height(), 225 visible_rect.height(),
216 skia_format, 226 read_format,
217 GL_UNSIGNED_BYTE, 227 GL_UNSIGNED_BYTE,
218 pixels.pixelRef()->pixels()); 228 pixels.pixelRef()->pixels());
219 gles2->DeleteFramebuffers(1, &fb); 229 gles2->DeleteFramebuffers(1, &fb);
220 gles2->DeleteTextures(1, &tmp_texture); 230 gles2->DeleteTextures(1, &tmp_texture);
231
232 if (skia_format != read_format) {
233 DCHECK(read_format == GL_RGBA);
234 int pixel_count = visible_rect.width() * visible_rect.height();
235 uint32_t* pixels_ptr = static_cast<uint32_t*>(pixels.pixelRef()->pixels());
236 for (int i = 0; i < pixel_count; ++i) {
237 uint32_t r = pixels_ptr[i] & 0xFF;
238 uint32_t g = (pixels_ptr[i] >> 8) & 0xFF;
239 uint32_t b = (pixels_ptr[i] >> 16) & 0xFF;
240 uint32_t a = (pixels_ptr[i] >> 24) & 0xFF;
241 pixels_ptr[i] = (r << SK_R32_SHIFT) |
242 (g << SK_G32_SHIFT) |
243 (b << SK_B32_SHIFT) |
244 (a << SK_A32_SHIFT);
245 }
246 }
247
221 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); 248 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
222 } 249 }
223 250
224 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( 251 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory(
225 size_t size) { 252 size_t size) {
226 DCHECK(task_runner_->BelongsToCurrentThread()); 253 DCHECK(task_runner_->BelongsToCurrentThread());
227 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get()); 254 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get());
228 } 255 }
229 256
230 scoped_refptr<base::SingleThreadTaskRunner> 257 scoped_refptr<base::SingleThreadTaskRunner>
231 RendererGpuVideoAcceleratorFactories::GetTaskRunner() { 258 RendererGpuVideoAcceleratorFactories::GetTaskRunner() {
232 return task_runner_; 259 return task_runner_;
233 } 260 }
234 261
235 } // namespace content 262 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698