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

Side by Side Diff: content/common/gpu/client/gl_helper.cc

Issue 88033002: Add RGB565 Texture readback support in gl_helper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected indentation. Created 6 years, 11 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
OLDNEW
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
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
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
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
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 26 matching lines...) Expand all
522 : gl_(gl), context_support_(context_support) {} 549 : gl_(gl), context_support_(context_support) {}
523 550
524 GLHelper::~GLHelper() {} 551 GLHelper::~GLHelper() {}
525 552
526 void GLHelper::CropScaleReadbackAndCleanTexture( 553 void GLHelper::CropScaleReadbackAndCleanTexture(
527 GLuint src_texture, 554 GLuint src_texture,
528 const gfx::Size& src_size, 555 const gfx::Size& src_size,
529 const gfx::Rect& src_subrect, 556 const gfx::Rect& src_subrect,
530 const gfx::Size& dst_size, 557 const gfx::Size& dst_size,
531 unsigned char* out, 558 unsigned char* out,
559 bool readback_config_rgb565,
532 const base::Callback<void(bool)>& callback) { 560 const base::Callback<void(bool)>& callback) {
533 InitCopyTextToImpl(); 561 InitCopyTextToImpl();
534 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( 562 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture(
535 src_texture, 563 src_texture,
536 src_size, 564 src_size,
537 src_subrect, 565 src_subrect,
538 dst_size, 566 dst_size,
539 out, 567 out,
568 readback_config_rgb565,
540 callback, 569 callback,
541 GLHelper::SCALER_QUALITY_FAST); 570 GLHelper::SCALER_QUALITY_FAST);
542 } 571 }
543 572
544 void GLHelper::CropScaleReadbackAndCleanMailbox( 573 void GLHelper::CropScaleReadbackAndCleanMailbox(
545 const gpu::Mailbox& src_mailbox, 574 const gpu::Mailbox& src_mailbox,
546 uint32 sync_point, 575 uint32 sync_point,
547 const gfx::Size& src_size, 576 const gfx::Size& src_size,
548 const gfx::Rect& src_subrect, 577 const gfx::Rect& src_subrect,
549 const gfx::Size& dst_size, 578 const gfx::Size& dst_size,
550 unsigned char* out, 579 unsigned char* out,
580 bool readback_config_rgb565,
551 const base::Callback<void(bool)>& callback) { 581 const base::Callback<void(bool)>& callback) {
552 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); 582 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point);
553 CropScaleReadbackAndCleanTexture( 583 CropScaleReadbackAndCleanTexture(
554 mailbox_texture, src_size, src_subrect, dst_size, out, callback); 584 mailbox_texture, src_size, src_subrect, dst_size, out,
585 readback_config_rgb565,
586 callback);
555 gl_->DeleteTextures(1, &mailbox_texture); 587 gl_->DeleteTextures(1, &mailbox_texture);
556 } 588 }
557 589
558 void GLHelper::ReadbackTextureSync(GLuint texture, 590 void GLHelper::ReadbackTextureSync(GLuint texture,
559 const gfx::Rect& src_rect, 591 const gfx::Rect& src_rect,
560 unsigned char* out) { 592 unsigned char* out) {
561 InitCopyTextToImpl(); 593 InitCopyTextToImpl();
562 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out); 594 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out);
563 } 595 }
564 596
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 rect.x(), 750 rect.x(),
719 rect.y(), 751 rect.y(),
720 rect.width(), 752 rect.width(),
721 rect.height()); 753 rect.height());
722 } 754 }
723 755
724 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { 756 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) {
725 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); 757 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture);
726 gl_->CopyTexImage2D( 758 gl_->CopyTexImage2D(
727 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); 759 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0);
728 } 760 }
piman 2014/01/09 18:12:15 nit: add empty line
sivag 2014/01/10 12:20:01 Done.
729 761 bool GLHelper::CanUseRgb565Readback() {
762 const int test_size = 64;
piman 2014/01/09 18:12:15 nit: kTestSize
sivag 2014/01/10 12:20:01 Done.
763 GLuint dst_texture = 0u;
764 gl_->GenTextures(1, &dst_texture);
765 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture);
766 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
767 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
768 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
769 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
770 gl_->TexImage2D(GL_TEXTURE_2D,
771 0,
772 GL_RGB,
773 test_size,
774 test_size,
775 0,
776 GL_RGB,
777 GL_UNSIGNED_SHORT_5_6_5,
778 NULL);
779 ScopedFramebuffer dst_framebuffer(gl_);
780 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_,
781 dst_framebuffer);
782 gl_->FramebufferTexture2D(GL_FRAMEBUFFER,
783 GL_COLOR_ATTACHMENT0,
784 GL_TEXTURE_2D,
785 dst_texture,
786 0);
787 int ext_format, ext_type;
788 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format);
789 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type);
790 gl_->DeleteTextures(1, &dst_texture);
791 return ((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5));
piman 2014/01/09 18:12:15 nit: no need for outer ()
sivag 2014/01/10 12:20:01 Done.
792 }
piman 2014/01/09 18:12:15 nit: add empty line
730 void GLHelper::CopyTextureToImpl::ReadbackPlane( 793 void GLHelper::CopyTextureToImpl::ReadbackPlane(
731 TextureFrameBufferPair* source, 794 TextureFrameBufferPair* source,
732 const scoped_refptr<media::VideoFrame>& target, 795 const scoped_refptr<media::VideoFrame>& target,
733 int plane, 796 int plane,
734 int size_shift, 797 int size_shift,
735 const gfx::Rect& dst_subrect, 798 const gfx::Rect& dst_subrect,
736 const base::Callback<void(bool)>& callback) { 799 const base::Callback<void(bool)>& callback) {
737 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); 800 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer());
738 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + 801 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) +
739 (dst_subrect.x() >> size_shift); 802 (dst_subrect.x() >> size_shift);
740 ReadbackAsync(source->size(), 803 ReadbackAsync(source->size(),
741 dst_subrect.width() >> size_shift, 804 dst_subrect.width() >> size_shift,
742 target->stride(plane), 805 target->stride(plane),
743 target->data(plane) + offset, 806 target->data(plane) + offset,
807 false,
744 callback); 808 callback);
745 } 809 }
746 810
747 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { 811 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = {
748 0.257f, 0.504f, 0.098f, 0.0625f}; 812 0.257f, 0.504f, 0.098f, 0.0625f};
749 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { 813 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = {
750 -0.148f, -0.291f, 0.439f, 0.5f}; 814 -0.148f, -0.291f, 0.439f, 0.5f};
751 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { 815 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = {
752 0.439f, -0.368f, -0.071f, 0.5f}; 816 0.439f, -0.368f, -0.071f, 0.5f};
753 817
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, 1108 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality,
1045 src_size, 1109 src_size,
1046 src_subrect, 1110 src_subrect,
1047 dst_size, 1111 dst_size,
1048 dst_subrect, 1112 dst_subrect,
1049 flip_vertically, 1113 flip_vertically,
1050 use_mrt); 1114 use_mrt);
1051 } 1115 }
1052 1116
1053 } // namespace content 1117 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698