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

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

Powered by Google App Engine
This is Rietveld 408576698