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/common/gpu/client/gl_helper.h" | 5 #include "content/common/gpu/client/gl_helper.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 uint32 sync_point) { | 120 uint32 sync_point) { |
121 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); | 121 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); |
122 } | 122 } |
123 | 123 |
124 void CropScaleReadbackAndCleanTexture( | 124 void CropScaleReadbackAndCleanTexture( |
125 GLuint src_texture, | 125 GLuint src_texture, |
126 const gfx::Size& src_size, | 126 const gfx::Size& src_size, |
127 const gfx::Rect& src_subrect, | 127 const gfx::Rect& src_subrect, |
128 const gfx::Size& dst_size, | 128 const gfx::Size& dst_size, |
129 unsigned char* out, | 129 unsigned char* out, |
130 bool readback_config_rgb565, | |
130 const base::Callback<void(bool)>& callback, | 131 const base::Callback<void(bool)>& callback, |
131 GLHelper::ScalerQuality quality); | 132 GLHelper::ScalerQuality quality); |
132 | 133 |
133 void ReadbackTextureSync(GLuint texture, | 134 void ReadbackTextureSync(GLuint texture, |
134 const gfx::Rect& src_rect, | 135 const gfx::Rect& src_rect, |
135 unsigned char* out); | 136 unsigned char* out); |
136 | 137 |
137 // Reads back bytes from the currently bound frame buffer. | 138 // Reads back bytes from the currently bound frame buffer. |
138 // Note that dst_size is specified in bytes, not pixels. | 139 // Note that dst_size is specified in bytes, not pixels. |
139 void ReadbackAsync(const gfx::Size& dst_size, | 140 void ReadbackAsync(const gfx::Size& dst_size, |
140 int32 bytes_per_row, // generally dst_size.width() * 4 | 141 int32 bytes_per_row, // generally dst_size.width() * 4 |
141 int32 row_stride_bytes, // generally dst_size.width() * 4 | 142 int32 row_stride_bytes, // generally dst_size.width() * 4 |
142 unsigned char* out, | 143 unsigned char* out, |
144 bool readback_config_rgb565, | |
143 const base::Callback<void(bool)>& callback); | 145 const base::Callback<void(bool)>& callback); |
144 | 146 |
145 void ReadbackPlane(TextureFrameBufferPair* source, | 147 void ReadbackPlane(TextureFrameBufferPair* source, |
146 const scoped_refptr<media::VideoFrame>& target, | 148 const scoped_refptr<media::VideoFrame>& target, |
147 int plane, | 149 int plane, |
148 int size_shift, | 150 int size_shift, |
149 const gfx::Rect& dst_subrect, | 151 const gfx::Rect& dst_subrect, |
150 const base::Callback<void(bool)>& callback); | 152 const base::Callback<void(bool)>& callback); |
151 | 153 |
152 GLuint CopyAndScaleTexture(GLuint texture, | 154 GLuint CopyAndScaleTexture(GLuint texture, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 | 280 |
279 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 281 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
280 // scales it to |dst_size|, writes it into a texture, and returns its ID. | 282 // scales it to |dst_size|, writes it into a texture, and returns its ID. |
281 // |src_size| is the size of |src_texture|. | 283 // |src_size| is the size of |src_texture|. |
282 GLuint ScaleTexture(GLuint src_texture, | 284 GLuint ScaleTexture(GLuint src_texture, |
283 const gfx::Size& src_size, | 285 const gfx::Size& src_size, |
284 const gfx::Rect& src_subrect, | 286 const gfx::Rect& src_subrect, |
285 const gfx::Size& dst_size, | 287 const gfx::Size& dst_size, |
286 bool vertically_flip_texture, | 288 bool vertically_flip_texture, |
287 bool swizzle, | 289 bool swizzle, |
290 bool readback_config_rgb565, | |
288 GLHelper::ScalerQuality quality); | 291 GLHelper::ScalerQuality quality); |
289 | 292 |
290 static void nullcallback(bool success) {} | 293 static void nullcallback(bool success) {} |
291 void ReadbackDone(Request* request); | 294 void ReadbackDone(Request *request, int bytes_per_pixel); |
292 void FinishRequest(Request* request, bool result); | 295 void FinishRequest(Request* request, bool result); |
293 void CancelRequests(); | 296 void CancelRequests(); |
294 | 297 |
295 static const float kRGBtoYColorWeights[]; | 298 static const float kRGBtoYColorWeights[]; |
296 static const float kRGBtoUColorWeights[]; | 299 static const float kRGBtoUColorWeights[]; |
297 static const float kRGBtoVColorWeights[]; | 300 static const float kRGBtoVColorWeights[]; |
298 | 301 |
299 GLES2Interface* gl_; | 302 GLES2Interface* gl_; |
300 gpu::ContextSupport* context_support_; | 303 gpu::ContextSupport* context_support_; |
301 GLHelper* helper_; | 304 GLHelper* helper_; |
(...skipping 21 matching lines...) Expand all Loading... | |
323 swizzle); | 326 swizzle); |
324 } | 327 } |
325 | 328 |
326 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( | 329 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( |
327 GLuint src_texture, | 330 GLuint src_texture, |
328 const gfx::Size& src_size, | 331 const gfx::Size& src_size, |
329 const gfx::Rect& src_subrect, | 332 const gfx::Rect& src_subrect, |
330 const gfx::Size& dst_size, | 333 const gfx::Size& dst_size, |
331 bool vertically_flip_texture, | 334 bool vertically_flip_texture, |
332 bool swizzle, | 335 bool swizzle, |
336 bool readback_config_rgb565, | |
333 GLHelper::ScalerQuality quality) { | 337 GLHelper::ScalerQuality quality) { |
334 scoped_ptr<ScalerInterface> scaler( | 338 scoped_ptr<ScalerInterface> scaler( |
335 helper_->CreateScaler(quality, | 339 helper_->CreateScaler(quality, |
336 src_size, | 340 src_size, |
337 src_subrect, | 341 src_subrect, |
338 dst_size, | 342 dst_size, |
339 vertically_flip_texture, | 343 vertically_flip_texture, |
340 swizzle)); | 344 swizzle)); |
341 | 345 |
342 GLuint dst_texture = 0u; | 346 GLuint dst_texture = 0u; |
343 gl_->GenTextures(1, &dst_texture); | 347 gl_->GenTextures(1, &dst_texture); |
344 { | 348 { |
345 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 349 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
350 GLenum format = readback_config_rgb565 ? GL_RGB : GL_RGBA; | |
351 GLenum type = readback_config_rgb565 ? | |
352 GL_UNSIGNED_SHORT_5_6_5 : | |
353 GL_UNSIGNED_BYTE; | |
346 gl_->TexImage2D(GL_TEXTURE_2D, | 354 gl_->TexImage2D(GL_TEXTURE_2D, |
347 0, | 355 0, |
348 GL_RGBA, | 356 format, |
349 dst_size.width(), | 357 dst_size.width(), |
350 dst_size.height(), | 358 dst_size.height(), |
351 0, | 359 0, |
352 GL_RGBA, | 360 format, |
353 GL_UNSIGNED_BYTE, | 361 type, |
354 NULL); | 362 NULL); |
355 } | 363 } |
356 scaler->Scale(src_texture, dst_texture); | 364 scaler->Scale(src_texture, dst_texture); |
357 return dst_texture; | 365 return dst_texture; |
358 } | 366 } |
359 | 367 |
360 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 368 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
361 const gfx::Size& dst_size, | 369 const gfx::Size& dst_size, |
362 int32 bytes_per_row, | 370 int32 bytes_per_row, |
363 int32 row_stride_bytes, | 371 int32 row_stride_bytes, |
364 unsigned char* out, | 372 unsigned char* out, |
373 bool readback_config_rgb565, | |
365 const base::Callback<void(bool)>& callback) { | 374 const base::Callback<void(bool)>& callback) { |
366 Request* request = | 375 Request* request = |
367 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 376 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
368 request_queue_.push(request); | 377 request_queue_.push(request); |
369 request->buffer = 0u; | 378 request->buffer = 0u; |
379 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
370 gl_->GenBuffers(1, &request->buffer); | 380 gl_->GenBuffers(1, &request->buffer); |
371 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); | 381 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); |
372 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 382 gl_->BufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
373 4 * dst_size.GetArea(), | 383 bytes_per_pixel * dst_size.GetArea(), |
374 NULL, | 384 NULL, |
375 GL_STREAM_READ); | 385 GL_STREAM_READ); |
376 | 386 |
377 request->query = 0u; | 387 request->query = 0u; |
378 gl_->GenQueriesEXT(1, &request->query); | 388 gl_->GenQueriesEXT(1, &request->query); |
379 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); | 389 gl_->BeginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, request->query); |
390 GLenum format = readback_config_rgb565 ? GL_RGB : GL_RGBA; | |
391 GLenum type = readback_config_rgb565 ? | |
392 GL_UNSIGNED_SHORT_5_6_5 : | |
393 GL_UNSIGNED_BYTE; | |
380 gl_->ReadPixels(0, | 394 gl_->ReadPixels(0, |
381 0, | 395 0, |
382 dst_size.width(), | 396 dst_size.width(), |
383 dst_size.height(), | 397 dst_size.height(), |
384 GL_RGBA, | 398 format, |
385 GL_UNSIGNED_BYTE, | 399 type, |
386 NULL); | 400 NULL); |
387 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); | 401 gl_->EndQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); |
388 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 402 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
389 context_support_->SignalQuery( | 403 context_support_->SignalQuery( |
390 request->query, | 404 request->query, |
391 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), request)); | 405 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), |
406 request, bytes_per_pixel)); | |
392 } | 407 } |
393 | |
394 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 408 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
395 GLuint src_texture, | 409 GLuint src_texture, |
396 const gfx::Size& src_size, | 410 const gfx::Size& src_size, |
397 const gfx::Rect& src_subrect, | 411 const gfx::Rect& src_subrect, |
398 const gfx::Size& dst_size, | 412 const gfx::Size& dst_size, |
399 unsigned char* out, | 413 unsigned char* out, |
414 bool readback_config_rgb565, | |
400 const base::Callback<void(bool)>& callback, | 415 const base::Callback<void(bool)>& callback, |
401 GLHelper::ScalerQuality quality) { | 416 GLHelper::ScalerQuality quality) { |
402 GLuint texture = ScaleTexture(src_texture, | 417 GLuint texture = ScaleTexture(src_texture, |
403 src_size, | 418 src_size, |
404 src_subrect, | 419 src_subrect, |
405 dst_size, | 420 dst_size, |
406 true, | 421 true, |
407 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 422 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
408 true, | 423 true, |
409 #else | 424 #else |
410 false, | 425 false, |
411 #endif | 426 #endif |
427 readback_config_rgb565, | |
412 quality); | 428 quality); |
413 ScopedFramebuffer dst_framebuffer(gl_); | 429 ScopedFramebuffer dst_framebuffer(gl_); |
414 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 430 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
415 dst_framebuffer); | 431 dst_framebuffer); |
416 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 432 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
417 gl_->FramebufferTexture2D( | 433 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
418 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | 434 GL_COLOR_ATTACHMENT0, |
419 ReadbackAsync( | 435 GL_TEXTURE_2D, |
420 dst_size, dst_size.width() * 4, dst_size.width() * 4, out, callback); | 436 texture, |
437 0); | |
438 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
439 ReadbackAsync(dst_size, | |
440 dst_size.width() * bytes_per_pixel, | |
441 dst_size.width() * bytes_per_pixel, | |
442 out, | |
443 readback_config_rgb565, | |
444 callback); | |
421 gl_->DeleteTextures(1, &texture); | 445 gl_->DeleteTextures(1, &texture); |
422 } | 446 } |
423 | 447 |
424 void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture, | 448 void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture, |
425 const gfx::Rect& src_rect, | 449 const gfx::Rect& src_rect, |
426 unsigned char* out) { | 450 unsigned char* out) { |
427 ScopedFramebuffer dst_framebuffer(gl_); | 451 ScopedFramebuffer dst_framebuffer(gl_); |
428 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 452 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
429 dst_framebuffer); | 453 dst_framebuffer); |
430 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 454 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
(...skipping 13 matching lines...) Expand all Loading... | |
444 const gfx::Size& src_size, | 468 const gfx::Size& src_size, |
445 const gfx::Size& dst_size, | 469 const gfx::Size& dst_size, |
446 bool vertically_flip_texture, | 470 bool vertically_flip_texture, |
447 GLHelper::ScalerQuality quality) { | 471 GLHelper::ScalerQuality quality) { |
448 return ScaleTexture(src_texture, | 472 return ScaleTexture(src_texture, |
449 src_size, | 473 src_size, |
450 gfx::Rect(src_size), | 474 gfx::Rect(src_size), |
451 dst_size, | 475 dst_size, |
452 vertically_flip_texture, | 476 vertically_flip_texture, |
453 false, | 477 false, |
478 false, | |
454 quality); | 479 quality); |
455 } | 480 } |
456 | 481 |
457 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request) { | 482 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
483 int bytes_per_pixel) { | |
458 TRACE_EVENT0("mirror", | 484 TRACE_EVENT0("mirror", |
459 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 485 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
460 finished_request->done = true; | 486 finished_request->done = true; |
461 | 487 |
462 // We process transfer requests in the order they were received, regardless | 488 // We process transfer requests in the order they were received, regardless |
463 // of the order we get the callbacks in. | 489 // of the order we get the callbacks in. |
464 while (!request_queue_.empty()) { | 490 while (!request_queue_.empty()) { |
465 Request* request = request_queue_.front(); | 491 Request* request = request_queue_.front(); |
466 if (!request->done) { | 492 if (!request->done) { |
467 break; | 493 break; |
468 } | 494 } |
469 | 495 |
470 bool result = false; | 496 bool result = false; |
471 if (request->buffer != 0) { | 497 if (request->buffer != 0) { |
472 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); | 498 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); |
473 unsigned char* data = static_cast<unsigned char*>(gl_->MapBufferCHROMIUM( | 499 unsigned char* data = static_cast<unsigned char*>(gl_->MapBufferCHROMIUM( |
474 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); | 500 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); |
475 if (data) { | 501 if (data) { |
476 result = true; | 502 result = true; |
477 if (request->bytes_per_row == request->size.width() * 4 && | 503 if (request->bytes_per_row == request->size.width() * bytes_per_pixel && |
478 request->bytes_per_row == request->row_stride_bytes) { | 504 request->bytes_per_row == request->row_stride_bytes) { |
479 memcpy(request->pixels, data, request->size.GetArea() * 4); | 505 memcpy(request->pixels, data, |
506 request->size.GetArea() * bytes_per_pixel); | |
480 } else { | 507 } else { |
481 unsigned char* out = request->pixels; | 508 unsigned char* out = request->pixels; |
482 for (int y = 0; y < request->size.height(); y++) { | 509 for (int y = 0; y < request->size.height(); y++) { |
483 memcpy(out, data, request->bytes_per_row); | 510 memcpy(out, data, request->bytes_per_row); |
484 out += request->row_stride_bytes; | 511 out += request->row_stride_bytes; |
485 data += request->size.width() * 4; | 512 data += request->size.width() * bytes_per_pixel; |
486 } | 513 } |
487 } | 514 } |
488 gl_->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | 515 gl_->UnmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); |
489 } | 516 } |
490 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 517 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
491 } | 518 } |
492 | 519 |
493 FinishRequest(request, result); | 520 FinishRequest(request, result); |
494 } | 521 } |
495 } | 522 } |
(...skipping 16 matching lines...) Expand all Loading... | |
512 } | 539 } |
513 | 540 |
514 void GLHelper::CopyTextureToImpl::CancelRequests() { | 541 void GLHelper::CopyTextureToImpl::CancelRequests() { |
515 while (!request_queue_.empty()) { | 542 while (!request_queue_.empty()) { |
516 Request* request = request_queue_.front(); | 543 Request* request = request_queue_.front(); |
517 FinishRequest(request, false); | 544 FinishRequest(request, false); |
518 } | 545 } |
519 } | 546 } |
520 | 547 |
521 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) | 548 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) |
522 : gl_(gl), context_support_(context_support) {} | 549 : gl_(gl), |
550 context_support_(context_support), | |
551 initialized_565_format_check_(false), | |
552 support_565_format_(false) {} | |
523 | 553 |
524 GLHelper::~GLHelper() {} | 554 GLHelper::~GLHelper() {} |
525 | 555 |
526 void GLHelper::CropScaleReadbackAndCleanTexture( | 556 void GLHelper::CropScaleReadbackAndCleanTexture( |
527 GLuint src_texture, | 557 GLuint src_texture, |
528 const gfx::Size& src_size, | 558 const gfx::Size& src_size, |
529 const gfx::Rect& src_subrect, | 559 const gfx::Rect& src_subrect, |
530 const gfx::Size& dst_size, | 560 const gfx::Size& dst_size, |
531 unsigned char* out, | 561 unsigned char* out, |
562 bool readback_config_rgb565, | |
532 const base::Callback<void(bool)>& callback) { | 563 const base::Callback<void(bool)>& callback) { |
533 InitCopyTextToImpl(); | 564 InitCopyTextToImpl(); |
534 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( | 565 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( |
535 src_texture, | 566 src_texture, |
536 src_size, | 567 src_size, |
537 src_subrect, | 568 src_subrect, |
538 dst_size, | 569 dst_size, |
539 out, | 570 out, |
571 readback_config_rgb565, | |
540 callback, | 572 callback, |
541 GLHelper::SCALER_QUALITY_FAST); | 573 GLHelper::SCALER_QUALITY_FAST); |
542 } | 574 } |
543 | 575 |
544 void GLHelper::CropScaleReadbackAndCleanMailbox( | 576 void GLHelper::CropScaleReadbackAndCleanMailbox( |
545 const gpu::Mailbox& src_mailbox, | 577 const gpu::Mailbox& src_mailbox, |
546 uint32 sync_point, | 578 uint32 sync_point, |
547 const gfx::Size& src_size, | 579 const gfx::Size& src_size, |
548 const gfx::Rect& src_subrect, | 580 const gfx::Rect& src_subrect, |
549 const gfx::Size& dst_size, | 581 const gfx::Size& dst_size, |
550 unsigned char* out, | 582 unsigned char* out, |
583 bool readback_config_rgb565, | |
551 const base::Callback<void(bool)>& callback) { | 584 const base::Callback<void(bool)>& callback) { |
552 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); | 585 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); |
553 CropScaleReadbackAndCleanTexture( | 586 CropScaleReadbackAndCleanTexture( |
554 mailbox_texture, src_size, src_subrect, dst_size, out, callback); | 587 mailbox_texture, src_size, src_subrect, dst_size, out, |
588 readback_config_rgb565, | |
589 callback); | |
555 gl_->DeleteTextures(1, &mailbox_texture); | 590 gl_->DeleteTextures(1, &mailbox_texture); |
556 } | 591 } |
557 | 592 |
558 void GLHelper::ReadbackTextureSync(GLuint texture, | 593 void GLHelper::ReadbackTextureSync(GLuint texture, |
559 const gfx::Rect& src_rect, | 594 const gfx::Rect& src_rect, |
560 unsigned char* out) { | 595 unsigned char* out) { |
561 InitCopyTextToImpl(); | 596 InitCopyTextToImpl(); |
562 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out); | 597 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out); |
563 } | 598 } |
564 | 599 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 rect.width(), | 755 rect.width(), |
721 rect.height()); | 756 rect.height()); |
722 } | 757 } |
723 | 758 |
724 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { | 759 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { |
725 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 760 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
726 gl_->CopyTexImage2D( | 761 gl_->CopyTexImage2D( |
727 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); | 762 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); |
728 } | 763 } |
729 | 764 |
765 bool GLHelper::CanUseRgb565Readback() { | |
766 if(initialized_565_format_check_){ | |
767 return support_565_format_; | |
768 } | |
769 const int kTestSize = 64; | |
770 GLuint dst_texture = 0u; | |
771 gl_->GenTextures(1, &dst_texture); | |
772 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | |
773 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
774 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
775 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
776 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
777 gl_->TexImage2D(GL_TEXTURE_2D, | |
778 0, | |
779 GL_RGB, | |
780 kTestSize, | |
781 kTestSize, | |
782 0, | |
783 GL_RGB, | |
784 GL_UNSIGNED_SHORT_5_6_5, | |
785 NULL); | |
786 ScopedFramebuffer dst_framebuffer(gl_); | |
787 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | |
788 dst_framebuffer); | |
789 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | |
790 GL_COLOR_ATTACHMENT0, | |
791 GL_TEXTURE_2D, | |
792 dst_texture, | |
793 0); | |
794 int ext_format, ext_type; | |
795 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); | |
796 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); | |
797 gl_->DeleteTextures(1, &dst_texture); | |
798 if((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5)){ | |
piman
2014/01/10 22:38:33
nit: space before ( and after )
sivag
2014/01/15 15:24:13
Done.
| |
799 support_565_format_ = true; | |
800 } | |
801 initialized_565_format_check_ = true; | |
802 return support_565_format_; | |
803 } | |
804 | |
730 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 805 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
731 TextureFrameBufferPair* source, | 806 TextureFrameBufferPair* source, |
732 const scoped_refptr<media::VideoFrame>& target, | 807 const scoped_refptr<media::VideoFrame>& target, |
733 int plane, | 808 int plane, |
734 int size_shift, | 809 int size_shift, |
735 const gfx::Rect& dst_subrect, | 810 const gfx::Rect& dst_subrect, |
736 const base::Callback<void(bool)>& callback) { | 811 const base::Callback<void(bool)>& callback) { |
737 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 812 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
738 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + | 813 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + |
739 (dst_subrect.x() >> size_shift); | 814 (dst_subrect.x() >> size_shift); |
740 ReadbackAsync(source->size(), | 815 ReadbackAsync(source->size(), |
741 dst_subrect.width() >> size_shift, | 816 dst_subrect.width() >> size_shift, |
742 target->stride(plane), | 817 target->stride(plane), |
743 target->data(plane) + offset, | 818 target->data(plane) + offset, |
819 false, | |
744 callback); | 820 callback); |
745 } | 821 } |
746 | 822 |
747 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { | 823 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { |
748 0.257f, 0.504f, 0.098f, 0.0625f}; | 824 0.257f, 0.504f, 0.098f, 0.0625f}; |
749 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { | 825 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { |
750 -0.148f, -0.291f, 0.439f, 0.5f}; | 826 -0.148f, -0.291f, 0.439f, 0.5f}; |
751 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { | 827 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { |
752 0.439f, -0.368f, -0.071f, 0.5f}; | 828 0.439f, -0.368f, -0.071f, 0.5f}; |
753 | 829 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1120 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
1045 src_size, | 1121 src_size, |
1046 src_subrect, | 1122 src_subrect, |
1047 dst_size, | 1123 dst_size, |
1048 dst_subrect, | 1124 dst_subrect, |
1049 flip_vertically, | 1125 flip_vertically, |
1050 use_mrt); | 1126 use_mrt); |
1051 } | 1127 } |
1052 | 1128 |
1053 } // namespace content | 1129 } // namespace content |
OLD | NEW |