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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 uint32 sync_point) { | 132 uint32 sync_point) { |
133 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); | 133 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); |
134 } | 134 } |
135 | 135 |
136 void CropScaleReadbackAndCleanTexture( | 136 void CropScaleReadbackAndCleanTexture( |
137 WebGLId src_texture, | 137 WebGLId src_texture, |
138 const gfx::Size& src_size, | 138 const gfx::Size& src_size, |
139 const gfx::Rect& src_subrect, | 139 const gfx::Rect& src_subrect, |
140 const gfx::Size& dst_size, | 140 const gfx::Size& dst_size, |
141 unsigned char* out, | 141 unsigned char* out, |
142 bool readback_config_rgb565, | |
142 const base::Callback<void(bool)>& callback, | 143 const base::Callback<void(bool)>& callback, |
143 GLHelper::ScalerQuality quality); | 144 GLHelper::ScalerQuality quality); |
144 | 145 |
145 void ReadbackTextureSync(WebGLId texture, | 146 void ReadbackTextureSync(WebGLId texture, |
146 const gfx::Rect& src_rect, | 147 const gfx::Rect& src_rect, |
147 unsigned char* out); | 148 unsigned char* out); |
148 | 149 |
149 // Reads back bytes from the currently bound frame buffer. | 150 // Reads back bytes from the currently bound frame buffer. |
150 // Note that dst_size is specified in bytes, not pixels. | 151 // Note that dst_size is specified in bytes, not pixels. |
151 void ReadbackAsync( | 152 void ReadbackAsync( |
152 const gfx::Size& dst_size, | 153 const gfx::Size& dst_size, |
153 int32 bytes_per_row, // generally dst_size.width() * 4 | 154 int32 bytes_per_row, // generally dst_size.width() * 4 |
154 int32 row_stride_bytes, // generally dst_size.width() * 4 | 155 int32 row_stride_bytes, // generally dst_size.width() * 4 |
155 unsigned char* out, | 156 unsigned char* out, |
157 bool readback_config_rgb565, | |
156 const base::Callback<void(bool)>& callback); | 158 const base::Callback<void(bool)>& callback); |
157 | 159 |
158 void ReadbackPlane(TextureFrameBufferPair* source, | 160 void ReadbackPlane(TextureFrameBufferPair* source, |
159 const scoped_refptr<media::VideoFrame>& target, | 161 const scoped_refptr<media::VideoFrame>& target, |
160 int plane, | 162 int plane, |
161 int size_shift, | 163 int size_shift, |
162 const gfx::Rect& dst_subrect, | 164 const gfx::Rect& dst_subrect, |
163 const base::Callback<void(bool)>& callback); | 165 const base::Callback<void(bool)>& callback); |
164 | 166 |
165 blink::WebGLId CopyAndScaleTexture(WebGLId texture, | 167 blink::WebGLId CopyAndScaleTexture(WebGLId texture, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 300 |
299 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 301 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
300 // scales it to |dst_size|, writes it into a texture, and returns its ID. | 302 // scales it to |dst_size|, writes it into a texture, and returns its ID. |
301 // |src_size| is the size of |src_texture|. | 303 // |src_size| is the size of |src_texture|. |
302 WebGLId ScaleTexture(WebGLId src_texture, | 304 WebGLId ScaleTexture(WebGLId src_texture, |
303 const gfx::Size& src_size, | 305 const gfx::Size& src_size, |
304 const gfx::Rect& src_subrect, | 306 const gfx::Rect& src_subrect, |
305 const gfx::Size& dst_size, | 307 const gfx::Size& dst_size, |
306 bool vertically_flip_texture, | 308 bool vertically_flip_texture, |
307 bool swizzle, | 309 bool swizzle, |
310 bool readback_config_rgb565, | |
no sievers
2014/01/07 16:26:02
nit: two spaces
sivag
2014/01/09 14:51:50
DOne.
| |
308 GLHelper::ScalerQuality quality); | 311 GLHelper::ScalerQuality quality); |
309 | 312 |
310 static void nullcallback(bool success) {} | 313 static void nullcallback(bool success) {} |
311 void ReadbackDone(Request *request); | 314 void ReadbackDone(Request *request,int bytes_per_pixel); |
no sievers
2014/01/07 16:26:02
nit: space after comma missing
sivag
2014/01/09 14:51:50
Done.
| |
312 void FinishRequest(Request* request, bool result); | 315 void FinishRequest(Request* request, bool result); |
313 void CancelRequests(); | 316 void CancelRequests(); |
314 | 317 |
315 static const float kRGBtoYColorWeights[]; | 318 static const float kRGBtoYColorWeights[]; |
316 static const float kRGBtoUColorWeights[]; | 319 static const float kRGBtoUColorWeights[]; |
317 static const float kRGBtoVColorWeights[]; | 320 static const float kRGBtoVColorWeights[]; |
318 | 321 |
319 WebGraphicsContext3D* context_; | 322 WebGraphicsContext3D* context_; |
320 gpu::ContextSupport* context_support_; | 323 gpu::ContextSupport* context_support_; |
321 GLHelper* helper_; | 324 GLHelper* helper_; |
(...skipping 22 matching lines...) Expand all Loading... | |
344 swizzle); | 347 swizzle); |
345 } | 348 } |
346 | 349 |
347 WebGLId GLHelper::CopyTextureToImpl::ScaleTexture( | 350 WebGLId GLHelper::CopyTextureToImpl::ScaleTexture( |
348 WebGLId src_texture, | 351 WebGLId src_texture, |
349 const gfx::Size& src_size, | 352 const gfx::Size& src_size, |
350 const gfx::Rect& src_subrect, | 353 const gfx::Rect& src_subrect, |
351 const gfx::Size& dst_size, | 354 const gfx::Size& dst_size, |
352 bool vertically_flip_texture, | 355 bool vertically_flip_texture, |
353 bool swizzle, | 356 bool swizzle, |
357 bool readback_config_rgb565, | |
no sievers
2014/01/07 16:26:02
nit: two spaces
sivag
2014/01/09 14:51:50
Done
| |
354 GLHelper::ScalerQuality quality) { | 358 GLHelper::ScalerQuality quality) { |
355 scoped_ptr<ScalerInterface> scaler( | 359 scoped_ptr<ScalerInterface> scaler( |
356 helper_->CreateScaler(quality, | 360 helper_->CreateScaler(quality, |
357 src_size, | 361 src_size, |
358 src_subrect, | 362 src_subrect, |
359 dst_size, | 363 dst_size, |
360 vertically_flip_texture, | 364 vertically_flip_texture, |
361 swizzle)); | 365 swizzle)); |
362 | 366 |
363 WebGLId dst_texture = context_->createTexture(); | 367 WebGLId dst_texture = context_->createTexture(); |
364 { | 368 { |
365 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, dst_texture); | 369 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, dst_texture); |
366 context_->texImage2D(GL_TEXTURE_2D, | 370 if(readback_config_rgb565){ |
no sievers
2014/01/07 16:26:02
nit: space missing
sivag
2014/01/09 14:51:50
Done.
| |
367 0, | 371 context_->texImage2D(GL_TEXTURE_2D, |
368 GL_RGBA, | 372 0, |
369 dst_size.width(), | 373 GL_RGB, |
370 dst_size.height(), | 374 dst_size.width(), |
371 0, | 375 dst_size.height(), |
372 GL_RGBA, | 376 0, |
373 GL_UNSIGNED_BYTE, | 377 GL_RGB, |
374 NULL); | 378 GL_UNSIGNED_SHORT_5_6_5, |
375 } | 379 NULL); |
380 }else{ | |
no sievers
2014/01/07 16:26:02
nit: spaces missing
sivag
2014/01/09 14:51:50
Done.
| |
381 context_->texImage2D(GL_TEXTURE_2D, | |
382 0, | |
383 GL_RGBA, | |
384 dst_size.width(), | |
385 dst_size.height(), | |
386 0, | |
387 GL_RGBA, | |
388 GL_UNSIGNED_BYTE, | |
389 NULL); | |
390 } | |
391 } | |
376 scaler->Scale(src_texture, dst_texture); | 392 scaler->Scale(src_texture, dst_texture); |
377 return dst_texture; | 393 return dst_texture; |
378 } | 394 } |
379 | 395 |
380 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 396 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
381 const gfx::Size& dst_size, | 397 const gfx::Size& dst_size, |
382 int32 bytes_per_row, | 398 int32 bytes_per_row, |
383 int32 row_stride_bytes, | 399 int32 row_stride_bytes, |
384 unsigned char* out, | 400 unsigned char* out, |
401 bool readback_config_rgb565, | |
385 const base::Callback<void(bool)>& callback) { | 402 const base::Callback<void(bool)>& callback) { |
no sievers
2014/01/07 16:26:02
Can you add a check for GL_IMPLEMENTATION_COLOR_RE
sivag
2014/01/09 14:51:50
Is this needed as we are already doing the check a
| |
386 Request* request = new Request(dst_size, | 403 Request* request = new Request(dst_size, |
387 bytes_per_row, | 404 bytes_per_row, |
388 row_stride_bytes, | 405 row_stride_bytes, |
389 out, | 406 out, |
390 callback); | 407 callback); |
391 request_queue_.push(request); | 408 request_queue_.push(request); |
392 request->buffer = context_->createBuffer(); | 409 request->buffer = context_->createBuffer(); |
410 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
393 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 411 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
394 request->buffer); | 412 request->buffer); |
395 context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 413 context_->bufferData(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
396 4 * dst_size.GetArea(), | 414 bytes_per_pixel * dst_size.GetArea(), |
397 NULL, | 415 NULL, |
398 GL_STREAM_READ); | 416 GL_STREAM_READ); |
399 | |
400 request->query = context_->createQueryEXT(); | 417 request->query = context_->createQueryEXT(); |
401 context_->beginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, | 418 context_->beginQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, |
402 request->query); | 419 request->query); |
403 context_->readPixels(0, 0, dst_size.width(), dst_size.height(), | 420 if(readback_config_rgb565){ |
no sievers
2014/01/07 16:26:02
nit: space missing in between ')' and '{'
sivag
2014/01/09 14:51:50
Done.
| |
421 context_->readPixels(0, 0, dst_size.width(), dst_size.height(), | |
422 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL); | |
no sievers
2014/01/07 16:26:02
nit: indent here and in 425.
sivag
2014/01/09 14:51:50
Done.
| |
423 }else{ | |
424 context_->readPixels(0, 0, dst_size.width(), dst_size.height(), | |
404 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 425 GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
426 } | |
405 context_->endQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); | 427 context_->endQueryEXT(GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM); |
406 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 428 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
407 context_support_->SignalQuery( | 429 context_support_->SignalQuery( |
408 request->query, | 430 request->query, |
409 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), request)); | 431 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), |
432 request, bytes_per_pixel)); | |
410 } | 433 } |
411 | |
412 | |
413 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 434 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
414 WebGLId src_texture, | 435 WebGLId src_texture, |
415 const gfx::Size& src_size, | 436 const gfx::Size& src_size, |
416 const gfx::Rect& src_subrect, | 437 const gfx::Rect& src_subrect, |
417 const gfx::Size& dst_size, | 438 const gfx::Size& dst_size, |
418 unsigned char* out, | 439 unsigned char* out, |
440 bool readback_config_rgb565, | |
419 const base::Callback<void(bool)>& callback, | 441 const base::Callback<void(bool)>& callback, |
420 GLHelper::ScalerQuality quality) { | 442 GLHelper::ScalerQuality quality) { |
421 WebGLId texture = ScaleTexture(src_texture, | 443 WebGLId texture = ScaleTexture(src_texture, |
422 src_size, | 444 src_size, |
423 src_subrect, | 445 src_subrect, |
424 dst_size, | 446 dst_size, |
425 true, | 447 true, |
426 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 448 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
427 true, | 449 true, |
428 #else | 450 #else |
429 false, | 451 false, |
430 #endif | 452 #endif |
453 readback_config_rgb565, | |
431 quality); | 454 quality); |
432 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); | 455 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); |
433 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, | 456 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, |
434 dst_framebuffer); | 457 dst_framebuffer); |
435 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 458 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
436 context_->framebufferTexture2D(GL_FRAMEBUFFER, | 459 context_->framebufferTexture2D(GL_FRAMEBUFFER, |
437 GL_COLOR_ATTACHMENT0, | 460 GL_COLOR_ATTACHMENT0, |
438 GL_TEXTURE_2D, | 461 GL_TEXTURE_2D, |
439 texture, | 462 texture, |
440 0); | 463 0); |
464 int bytes_per_pixel = readback_config_rgb565 ? 2 : 4; | |
441 ReadbackAsync(dst_size, | 465 ReadbackAsync(dst_size, |
442 dst_size.width() * 4, | 466 dst_size.width() * bytes_per_pixel, |
443 dst_size.width() * 4, | 467 dst_size.width() * bytes_per_pixel, |
444 out, | 468 out, |
469 readback_config_rgb565, | |
445 callback); | 470 callback); |
446 context_->deleteTexture(texture); | 471 context_->deleteTexture(texture); |
447 } | 472 } |
448 | 473 |
449 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( | 474 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( |
450 WebGLId texture, | 475 WebGLId texture, |
451 const gfx::Rect& src_rect, | 476 const gfx::Rect& src_rect, |
452 unsigned char* out) { | 477 unsigned char* out) { |
453 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); | 478 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); |
454 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, | 479 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, |
(...skipping 18 matching lines...) Expand all Loading... | |
473 const gfx::Size& src_size, | 498 const gfx::Size& src_size, |
474 const gfx::Size& dst_size, | 499 const gfx::Size& dst_size, |
475 bool vertically_flip_texture, | 500 bool vertically_flip_texture, |
476 GLHelper::ScalerQuality quality) { | 501 GLHelper::ScalerQuality quality) { |
477 return ScaleTexture(src_texture, | 502 return ScaleTexture(src_texture, |
478 src_size, | 503 src_size, |
479 gfx::Rect(src_size), | 504 gfx::Rect(src_size), |
480 dst_size, | 505 dst_size, |
481 vertically_flip_texture, | 506 vertically_flip_texture, |
482 false, | 507 false, |
508 false, | |
483 quality); | 509 quality); |
484 } | 510 } |
485 | 511 |
486 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request) { | 512 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
513 int bytes_per_pixel) { | |
487 TRACE_EVENT0("mirror", | 514 TRACE_EVENT0("mirror", |
488 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 515 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
489 finished_request->done = true; | 516 finished_request->done = true; |
490 | 517 |
491 // We process transfer requests in the order they were received, regardless | 518 // We process transfer requests in the order they were received, regardless |
492 // of the order we get the callbacks in. | 519 // of the order we get the callbacks in. |
493 while (!request_queue_.empty()) { | 520 while (!request_queue_.empty()) { |
494 Request* request = request_queue_.front(); | 521 Request* request = request_queue_.front(); |
495 if (!request->done) { | 522 if (!request->done) { |
496 break; | 523 break; |
497 } | 524 } |
498 | 525 |
499 bool result = false; | 526 bool result = false; |
500 if (request->buffer != 0) { | 527 if (request->buffer != 0) { |
501 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, | 528 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, |
502 request->buffer); | 529 request->buffer); |
503 unsigned char* data = static_cast<unsigned char *>( | 530 unsigned char* data = static_cast<unsigned char *>( |
504 context_->mapBufferCHROMIUM( | 531 context_->mapBufferCHROMIUM( |
505 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); | 532 GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, GL_READ_ONLY)); |
506 if (data) { | 533 if (data) { |
507 result = true; | 534 result = true; |
508 if (request->bytes_per_row == request->size.width() * 4 && | 535 if (request->bytes_per_row == request->size.width() * bytes_per_pixel && |
509 request->bytes_per_row == request->row_stride_bytes) { | 536 request->bytes_per_row == request->row_stride_bytes) { |
510 memcpy(request->pixels, data, request->size.GetArea() * 4); | 537 memcpy(request->pixels, data, |
538 request->size.GetArea() * bytes_per_pixel); | |
511 } else { | 539 } else { |
512 unsigned char* out = request->pixels; | 540 unsigned char* out = request->pixels; |
513 for (int y = 0; y < request->size.height(); y++) { | 541 for (int y = 0; y < request->size.height(); y++) { |
514 memcpy(out, data, request->bytes_per_row); | 542 memcpy(out, data, request->bytes_per_row); |
515 out += request->row_stride_bytes; | 543 out += request->row_stride_bytes; |
516 data += request->size.width() * 4; | 544 data += request->size.width() * bytes_per_pixel; |
517 } | 545 } |
518 } | 546 } |
519 context_->unmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); | 547 context_->unmapBufferCHROMIUM(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM); |
520 } | 548 } |
521 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); | 549 context_->bindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, 0); |
522 } | 550 } |
523 | 551 |
524 FinishRequest(request, result); | 552 FinishRequest(request, result); |
525 } | 553 } |
526 } | 554 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 586 |
559 GLHelper::~GLHelper() { | 587 GLHelper::~GLHelper() { |
560 } | 588 } |
561 | 589 |
562 void GLHelper::CropScaleReadbackAndCleanTexture( | 590 void GLHelper::CropScaleReadbackAndCleanTexture( |
563 WebGLId src_texture, | 591 WebGLId src_texture, |
564 const gfx::Size& src_size, | 592 const gfx::Size& src_size, |
565 const gfx::Rect& src_subrect, | 593 const gfx::Rect& src_subrect, |
566 const gfx::Size& dst_size, | 594 const gfx::Size& dst_size, |
567 unsigned char* out, | 595 unsigned char* out, |
596 bool readback_config_rgb565, | |
568 const base::Callback<void(bool)>& callback) { | 597 const base::Callback<void(bool)>& callback) { |
569 InitCopyTextToImpl(); | 598 InitCopyTextToImpl(); |
570 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( | 599 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( |
571 src_texture, | 600 src_texture, |
572 src_size, | 601 src_size, |
573 src_subrect, | 602 src_subrect, |
574 dst_size, | 603 dst_size, |
575 out, | 604 out, |
605 readback_config_rgb565, | |
576 callback, | 606 callback, |
577 GLHelper::SCALER_QUALITY_FAST); | 607 GLHelper::SCALER_QUALITY_FAST); |
578 } | 608 } |
579 | 609 |
580 void GLHelper::CropScaleReadbackAndCleanMailbox( | 610 void GLHelper::CropScaleReadbackAndCleanMailbox( |
581 const gpu::Mailbox& src_mailbox, | 611 const gpu::Mailbox& src_mailbox, |
582 uint32 sync_point, | 612 uint32 sync_point, |
583 const gfx::Size& src_size, | 613 const gfx::Size& src_size, |
584 const gfx::Rect& src_subrect, | 614 const gfx::Rect& src_subrect, |
585 const gfx::Size& dst_size, | 615 const gfx::Size& dst_size, |
586 unsigned char* out, | 616 unsigned char* out, |
617 bool readback_config_rgb565, | |
587 const base::Callback<void(bool)>& callback) { | 618 const base::Callback<void(bool)>& callback) { |
588 WebGLId mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); | 619 WebGLId mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); |
589 CropScaleReadbackAndCleanTexture( | 620 CropScaleReadbackAndCleanTexture( |
590 mailbox_texture, src_size, src_subrect, dst_size, out, callback); | 621 mailbox_texture, src_size, src_subrect, dst_size, out, |
622 readback_config_rgb565, | |
623 callback); | |
591 context_->deleteTexture(mailbox_texture); | 624 context_->deleteTexture(mailbox_texture); |
592 } | 625 } |
593 | 626 |
594 void GLHelper::ReadbackTextureSync(blink::WebGLId texture, | 627 void GLHelper::ReadbackTextureSync(blink::WebGLId texture, |
595 const gfx::Rect& src_rect, | 628 const gfx::Rect& src_rect, |
596 unsigned char* out) { | 629 unsigned char* out) { |
597 InitCopyTextToImpl(); | 630 InitCopyTextToImpl(); |
598 copy_texture_to_impl_->ReadbackTextureSync(texture, | 631 copy_texture_to_impl_->ReadbackTextureSync(texture, |
599 src_rect, | 632 src_rect, |
600 out); | 633 out); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 } | 783 } |
751 | 784 |
752 void GLHelper::CopyTextureFullImage(blink::WebGLId texture, | 785 void GLHelper::CopyTextureFullImage(blink::WebGLId texture, |
753 const gfx::Size& size) { | 786 const gfx::Size& size) { |
754 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); | 787 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, texture); |
755 context_->copyTexImage2D(GL_TEXTURE_2D, 0, | 788 context_->copyTexImage2D(GL_TEXTURE_2D, 0, |
756 GL_RGB, | 789 GL_RGB, |
757 0, 0, | 790 0, 0, |
758 size.width(), size.height(), 0); | 791 size.width(), size.height(), 0); |
759 } | 792 } |
760 | 793 bool GLHelper::CanUseRgb565Readback() { |
794 const int test_size = 100; | |
no sievers
2014/01/07 16:26:02
Can you use something power of two?
sivag
2014/01/09 14:51:50
Done.
| |
795 WebGLId dst_texture = context_->createTexture(); | |
796 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(context_, dst_texture); | |
797 context_->texImage2D(GL_TEXTURE_2D, | |
no sievers
2014/01/07 16:26:02
nit: indent
sivag
2014/01/09 14:51:50
Done.
| |
798 0, | |
799 GL_RGB, | |
800 test_size, | |
801 test_size, | |
802 0, | |
803 GL_RGB, | |
804 GL_UNSIGNED_SHORT_5_6_5, | |
805 NULL); | |
no sievers
2014/01/07 16:26:02
The texture is incomplete because the default min_
sivag
2014/01/09 14:51:50
Done.
| |
806 ScopedFramebuffer dst_framebuffer(context_, context_->createFramebuffer()); | |
807 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(context_, | |
808 dst_framebuffer); | |
809 context_->framebufferTexture2D(GL_FRAMEBUFFER, | |
810 GL_COLOR_ATTACHMENT0, | |
811 GL_TEXTURE_2D, | |
812 dst_texture, | |
813 0); | |
814 int ext_format, ext_type; | |
815 context_->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); | |
816 context_->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); | |
817 context_->deleteTexture(dst_texture); | |
818 return ((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5)); | |
819 } | |
761 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 820 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
762 TextureFrameBufferPair* source, | 821 TextureFrameBufferPair* source, |
763 const scoped_refptr<media::VideoFrame>& target, | 822 const scoped_refptr<media::VideoFrame>& target, |
764 int plane, | 823 int plane, |
765 int size_shift, | 824 int size_shift, |
766 const gfx::Rect& dst_subrect, | 825 const gfx::Rect& dst_subrect, |
767 const base::Callback<void(bool)>& callback) { | 826 const base::Callback<void(bool)>& callback) { |
768 context_->bindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 827 context_->bindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
769 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + | 828 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + |
770 (dst_subrect.x() >> size_shift); | 829 (dst_subrect.x() >> size_shift); |
771 ReadbackAsync( | 830 ReadbackAsync( |
772 source->size(), | 831 source->size(), |
773 dst_subrect.width() >> size_shift, | 832 dst_subrect.width() >> size_shift, |
774 target->stride(plane), | 833 target->stride(plane), |
775 target->data(plane) + offset, | 834 target->data(plane) + offset, |
835 false, | |
776 callback); | 836 callback); |
777 } | 837 } |
778 | 838 |
779 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { | 839 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { |
780 0.257f, 0.504f, 0.098f, 0.0625f | 840 0.257f, 0.504f, 0.098f, 0.0625f |
781 }; | 841 }; |
782 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { | 842 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { |
783 -0.148f, -0.291f, 0.439f, 0.5f | 843 -0.148f, -0.291f, 0.439f, 0.5f |
784 }; | 844 }; |
785 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { | 845 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1084 quality, | 1144 quality, |
1085 src_size, | 1145 src_size, |
1086 src_subrect, | 1146 src_subrect, |
1087 dst_size, | 1147 dst_size, |
1088 dst_subrect, | 1148 dst_subrect, |
1089 flip_vertically, | 1149 flip_vertically, |
1090 use_mrt); | 1150 use_mrt); |
1091 } | 1151 } |
1092 | 1152 |
1093 } // namespace content | 1153 } // namespace content |
OLD | NEW |