Chromium Code Reviews| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 const gfx::Rect& src_subrect, | 171 const gfx::Rect& src_subrect, |
| 172 const gfx::Size& dst_size, | 172 const gfx::Size& dst_size, |
| 173 const gfx::Rect& dst_subrect, | 173 const gfx::Rect& dst_subrect, |
| 174 bool flip_vertically, | 174 bool flip_vertically, |
| 175 bool use_mrt); | 175 bool use_mrt); |
| 176 | 176 |
| 177 // Returns the maximum number of draw buffers available, | 177 // Returns the maximum number of draw buffers available, |
| 178 // 0 if GL_EXT_draw_buffers is not available. | 178 // 0 if GL_EXT_draw_buffers is not available. |
| 179 GLint MaxDrawBuffers() const { return max_draw_buffers_; } | 179 GLint MaxDrawBuffers() const { return max_draw_buffers_; } |
| 180 | 180 |
| 181 bool IsReadbackConfigSupported(SkBitmap::Config bitmap_config); | |
| 182 | |
| 181 private: | 183 private: |
| 182 // A single request to CropScaleReadbackAndCleanTexture. | 184 // A single request to CropScaleReadbackAndCleanTexture. |
| 183 // The main thread can cancel the request, before it's handled by the helper | 185 // The main thread can cancel the request, before it's handled by the helper |
| 184 // thread, by resetting the texture and pixels fields. Alternatively, the | 186 // thread, by resetting the texture and pixels fields. Alternatively, the |
| 185 // thread marks that it handles the request by resetting the pixels field | 187 // thread marks that it handles the request by resetting the pixels field |
| 186 // (meaning it guarantees that the callback with be called). | 188 // (meaning it guarantees that the callback with be called). |
| 187 // In either case, the callback must be called exactly once, and the texture | 189 // In either case, the callback must be called exactly once, and the texture |
| 188 // must be deleted by the main thread gl. | 190 // must be deleted by the main thread gl. |
| 189 struct Request { | 191 struct Request { |
| 190 Request(const gfx::Size& size_, | 192 Request(const gfx::Size& size_, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 swizzle); | 336 swizzle); |
| 335 } | 337 } |
| 336 | 338 |
| 337 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( | 339 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( |
| 338 GLuint src_texture, | 340 GLuint src_texture, |
| 339 const gfx::Size& src_size, | 341 const gfx::Size& src_size, |
| 340 const gfx::Rect& src_subrect, | 342 const gfx::Rect& src_subrect, |
| 341 const gfx::Size& dst_size, | 343 const gfx::Size& dst_size, |
| 342 bool vertically_flip_texture, | 344 bool vertically_flip_texture, |
| 343 bool swizzle, | 345 bool swizzle, |
| 344 SkBitmap::Config config, | 346 SkBitmap::Config bitmap_config, |
| 345 GLHelper::ScalerQuality quality) { | 347 GLHelper::ScalerQuality quality) { |
| 348 if (!IsReadbackConfigSupported(bitmap_config)) | |
| 349 return 0; | |
| 346 | 350 |
| 347 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | |
| 348 (config == SkBitmap::kARGB_8888_Config)); | |
| 349 if (!format_support) { | |
| 350 DCHECK(format_support); | |
| 351 return 0; | |
| 352 } | |
| 353 scoped_ptr<ScalerInterface> scaler( | 351 scoped_ptr<ScalerInterface> scaler( |
| 354 helper_->CreateScaler(quality, | 352 helper_->CreateScaler(quality, |
| 355 src_size, | 353 src_size, |
| 356 src_subrect, | 354 src_subrect, |
| 357 dst_size, | 355 dst_size, |
| 358 vertically_flip_texture, | 356 vertically_flip_texture, |
| 359 swizzle)); | 357 swizzle)); |
| 360 GLuint dst_texture = 0u; | 358 GLuint dst_texture = 0u; |
| 361 // Start with ARGB8888 params as any other format which is not | 359 // Start with ARGB8888 params as any other format which is not |
| 362 // supported is already asserted above. | 360 // supported is already asserted above. |
| 363 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; | 361 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; |
| 364 gl_->GenTextures(1, &dst_texture); | 362 gl_->GenTextures(1, &dst_texture); |
| 365 { | 363 { |
| 366 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 364 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
| 367 switch (config) { | 365 switch (bitmap_config) { |
| 368 case SkBitmap::kARGB_8888_Config: | 366 case SkBitmap::kARGB_8888_Config: |
| 369 // Do nothing params already set. | 367 // Do nothing params already set. |
| 370 break; | 368 break; |
| 371 case SkBitmap::kRGB_565_Config: | 369 case SkBitmap::kRGB_565_Config: |
| 372 format = GL_RGB; | 370 format = GL_RGB; |
| 373 type = GL_UNSIGNED_SHORT_5_6_5; | 371 type = GL_UNSIGNED_SHORT_5_6_5; |
| 374 break; | 372 break; |
| 375 default: | 373 default: |
| 376 NOTREACHED(); | 374 NOTREACHED(); |
| 377 break; | 375 break; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 388 } | 386 } |
| 389 scaler->Scale(src_texture, dst_texture); | 387 scaler->Scale(src_texture, dst_texture); |
| 390 return dst_texture; | 388 return dst_texture; |
| 391 } | 389 } |
| 392 | 390 |
| 393 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 391 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
| 394 const gfx::Size& dst_size, | 392 const gfx::Size& dst_size, |
| 395 int32 bytes_per_row, | 393 int32 bytes_per_row, |
| 396 int32 row_stride_bytes, | 394 int32 row_stride_bytes, |
| 397 unsigned char* out, | 395 unsigned char* out, |
| 398 const SkBitmap::Config config, | 396 const SkBitmap::Config bitmap_config, |
| 399 const base::Callback<void(bool)>& callback) { | 397 const base::Callback<void(bool)>& callback) { |
| 400 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | 398 if (!IsReadbackConfigSupported(bitmap_config)) { |
| 401 (config == SkBitmap::kARGB_8888_Config)); | |
| 402 if (!format_support) { | |
| 403 DCHECK(format_support); | |
| 404 callback.Run(false); | 399 callback.Run(false); |
| 405 return; | 400 return; |
| 406 } | 401 } |
| 407 Request* request = | 402 Request* request = |
| 408 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 403 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
| 409 request_queue_.push(request); | 404 request_queue_.push(request); |
| 410 request->buffer = 0u; | 405 request->buffer = 0u; |
| 411 // Start with ARGB8888 params as any other format which is not | 406 // Start with ARGB8888 params as any other format which is not |
| 412 // supported is already asserted above. | 407 // supported is already asserted above. |
| 413 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; | 408 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; |
| 414 int bytes_per_pixel = 4; | 409 int bytes_per_pixel = 4; |
| 415 | 410 |
| 416 switch (config) { | 411 switch (bitmap_config) { |
| 417 case SkBitmap::kARGB_8888_Config: | 412 case SkBitmap::kARGB_8888_Config: |
| 418 // Do nothing params already set. | 413 // Do nothing params already set. |
| 419 break; | 414 break; |
| 420 case SkBitmap::kRGB_565_Config: | 415 case SkBitmap::kRGB_565_Config: |
| 421 format = GL_RGB; | 416 format = GL_RGB; |
| 422 type = GL_UNSIGNED_SHORT_5_6_5; | 417 type = GL_UNSIGNED_SHORT_5_6_5; |
| 423 bytes_per_pixel = 2; | 418 bytes_per_pixel = 2; |
| 424 break; | 419 break; |
| 425 default: | 420 default: |
| 426 NOTREACHED(); | 421 NOTREACHED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 452 } | 447 } |
| 453 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 448 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
| 454 GLuint src_texture, | 449 GLuint src_texture, |
| 455 const gfx::Size& src_size, | 450 const gfx::Size& src_size, |
| 456 const gfx::Rect& src_subrect, | 451 const gfx::Rect& src_subrect, |
| 457 const gfx::Size& dst_size, | 452 const gfx::Size& dst_size, |
| 458 unsigned char* out, | 453 unsigned char* out, |
| 459 const SkBitmap::Config bitmap_config, | 454 const SkBitmap::Config bitmap_config, |
| 460 const base::Callback<void(bool)>& callback, | 455 const base::Callback<void(bool)>& callback, |
| 461 GLHelper::ScalerQuality quality) { | 456 GLHelper::ScalerQuality quality) { |
| 462 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | 457 if (!IsReadbackConfigSupported(bitmap_config)) { |
| 463 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
| 464 if (!format_support) { | |
| 465 DCHECK(format_support); | |
| 466 callback.Run(false); | 458 callback.Run(false); |
| 467 return; | 459 return; |
| 468 } | 460 } |
| 469 GLuint texture = ScaleTexture(src_texture, | 461 GLuint texture = ScaleTexture(src_texture, |
| 470 src_size, | 462 src_size, |
| 471 src_subrect, | 463 src_subrect, |
| 472 dst_size, | 464 dst_size, |
| 473 true, | 465 true, |
| 474 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 466 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
| 475 true, | 467 true, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 502 } | 494 } |
| 503 ReadbackAsync(dst_size, | 495 ReadbackAsync(dst_size, |
| 504 dst_size.width() * bytes_per_pixel, | 496 dst_size.width() * bytes_per_pixel, |
| 505 dst_size.width() * bytes_per_pixel, | 497 dst_size.width() * bytes_per_pixel, |
| 506 out, | 498 out, |
| 507 bitmap_config, | 499 bitmap_config, |
| 508 callback); | 500 callback); |
| 509 gl_->DeleteTextures(1, &texture); | 501 gl_->DeleteTextures(1, &texture); |
| 510 } | 502 } |
| 511 | 503 |
| 512 void GLHelper::CopyTextureToImpl::ReadbackTextureSync(GLuint texture, | 504 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( |
| 513 const gfx::Rect& src_rect, | 505 GLuint texture, |
| 514 unsigned char* out, | 506 const gfx::Rect& src_rect, |
| 515 SkBitmap::Config config) { | 507 unsigned char* out, |
| 516 DCHECK((config == SkBitmap::kRGB_565_Config) || | 508 SkBitmap::Config bitmap_config) { |
| 517 (config == SkBitmap::kARGB_8888_Config)); | 509 if (!IsReadbackConfigSupported(bitmap_config)) |
| 510 return; | |
| 511 | |
| 518 ScopedFramebuffer dst_framebuffer(gl_); | 512 ScopedFramebuffer dst_framebuffer(gl_); |
| 519 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 513 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 520 dst_framebuffer); | 514 dst_framebuffer); |
| 521 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 515 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 522 gl_->FramebufferTexture2D( | 516 gl_->FramebufferTexture2D( |
| 523 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | 517 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 524 GLenum format = (config == SkBitmap::kRGB_565_Config) ? | 518 GLenum format = |
| 525 GL_RGB : | 519 (bitmap_config == SkBitmap::kRGB_565_Config) ? GL_RGB : GL_RGBA; |
| 526 GL_RGBA; | 520 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) |
| 527 GLenum type = (config == SkBitmap::kRGB_565_Config) ? | 521 ? GL_UNSIGNED_SHORT_5_6_5 |
| 528 GL_UNSIGNED_SHORT_5_6_5 : | 522 : GL_UNSIGNED_BYTE; |
| 529 GL_UNSIGNED_BYTE; | |
| 530 gl_->ReadPixels(src_rect.x(), | 523 gl_->ReadPixels(src_rect.x(), |
| 531 src_rect.y(), | 524 src_rect.y(), |
| 532 src_rect.width(), | 525 src_rect.width(), |
| 533 src_rect.height(), | 526 src_rect.height(), |
| 534 format, | 527 format, |
| 535 type, | 528 type, |
| 536 out); | 529 out); |
| 537 } | 530 } |
| 538 | 531 |
| 539 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( | 532 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( |
| 540 GLuint texture, | 533 GLuint texture, |
| 541 const gfx::Size& dst_size, | 534 const gfx::Size& dst_size, |
| 542 unsigned char* out, | 535 unsigned char* out, |
| 543 SkBitmap::Config config, | 536 SkBitmap::Config bitmap_config, |
| 544 const base::Callback<void(bool)>& callback) { | 537 const base::Callback<void(bool)>& callback) { |
| 545 // Only ARGB888 and RGB565 supported as of now. | 538 if (!IsReadbackConfigSupported(bitmap_config)) |
| 546 bool format_support = ((config == SkBitmap::kRGB_565_Config) || | |
| 547 (config == SkBitmap::kARGB_8888_Config)); | |
| 548 if (!format_support) { | |
| 549 DCHECK(format_support); | |
| 550 return; | 539 return; |
| 551 } | 540 |
| 552 ScopedFramebuffer dst_framebuffer(gl_); | 541 ScopedFramebuffer dst_framebuffer(gl_); |
| 553 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 542 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 554 dst_framebuffer); | 543 dst_framebuffer); |
| 555 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 544 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 556 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 545 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 557 GL_COLOR_ATTACHMENT0, | 546 GL_COLOR_ATTACHMENT0, |
| 558 GL_TEXTURE_2D, | 547 GL_TEXTURE_2D, |
| 559 texture, | 548 texture, |
| 560 0); | 549 0); |
| 561 int bytes_per_pixel = (config == SkBitmap::kRGB_565_Config) ? 2 : 4; | 550 int bytes_per_pixel = (bitmap_config == SkBitmap::kRGB_565_Config) ? 2 : 4; |
| 562 ReadbackAsync(dst_size, | 551 ReadbackAsync(dst_size, |
| 563 dst_size.width() * bytes_per_pixel, | 552 dst_size.width() * bytes_per_pixel, |
| 564 dst_size.width() * bytes_per_pixel, | 553 dst_size.width() * bytes_per_pixel, |
| 565 out, | 554 out, |
| 566 config, | 555 bitmap_config, |
| 567 callback); | 556 callback); |
| 568 } | 557 } |
| 569 | 558 |
| 570 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 559 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
| 571 GLuint src_texture, | 560 GLuint src_texture, |
| 572 const gfx::Size& src_size, | 561 const gfx::Size& src_size, |
| 573 const gfx::Size& dst_size, | 562 const gfx::Size& dst_size, |
| 574 bool vertically_flip_texture, | 563 bool vertically_flip_texture, |
| 575 GLHelper::ScalerQuality quality) { | 564 GLHelper::ScalerQuality quality) { |
| 576 return ScaleTexture(src_texture, | 565 return ScaleTexture(src_texture, |
| 577 src_size, | 566 src_size, |
| 578 gfx::Rect(src_size), | 567 gfx::Rect(src_size), |
| 579 dst_size, | 568 dst_size, |
| 580 vertically_flip_texture, | 569 vertically_flip_texture, |
| 581 false, | 570 false, |
| 582 SkBitmap::kARGB_8888_Config, | 571 SkBitmap::kARGB_8888_Config, |
| 583 quality); | 572 quality); |
| 584 } | 573 } |
| 585 | 574 |
| 575 bool GLHelper::CopyTextureToImpl::IsReadbackConfigSupported( | |
| 576 SkBitmap::Config bitmap_config) { | |
| 577 if (!helper_) { | |
| 578 DCHECK(helper_); | |
| 579 return false; | |
| 580 } | |
| 581 return helper_->IsReadbackConfigSupported(bitmap_config); | |
| 582 } | |
| 583 | |
| 586 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, | 584 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
| 587 int bytes_per_pixel) { | 585 int bytes_per_pixel) { |
| 588 TRACE_EVENT0("mirror", | 586 TRACE_EVENT0("mirror", |
| 589 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 587 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
| 590 finished_request->done = true; | 588 finished_request->done = true; |
| 591 | 589 |
| 592 // We process transfer requests in the order they were received, regardless | 590 // We process transfer requests in the order they were received, regardless |
| 593 // of the order we get the callbacks in. | 591 // of the order we get the callbacks in. |
| 594 while (!request_queue_.empty()) { | 592 while (!request_queue_.empty()) { |
| 595 Request* request = request_queue_.front(); | 593 Request* request = request_queue_.front(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 } | 640 } |
| 643 | 641 |
| 644 void GLHelper::CopyTextureToImpl::CancelRequests() { | 642 void GLHelper::CopyTextureToImpl::CancelRequests() { |
| 645 while (!request_queue_.empty()) { | 643 while (!request_queue_.empty()) { |
| 646 Request* request = request_queue_.front(); | 644 Request* request = request_queue_.front(); |
| 647 FinishRequest(request, false); | 645 FinishRequest(request, false); |
| 648 } | 646 } |
| 649 } | 647 } |
| 650 | 648 |
| 651 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) | 649 GLHelper::GLHelper(GLES2Interface* gl, gpu::ContextSupport* context_support) |
| 652 : gl_(gl), | 650 : gl_(gl), context_support_(context_support) { |
| 653 context_support_(context_support), | 651 InitializeReadbackSupport(); |
| 654 initialized_565_format_check_(false), | 652 } |
| 655 support_565_format_(false) {} | |
| 656 | 653 |
| 657 GLHelper::~GLHelper() {} | 654 GLHelper::~GLHelper() {} |
| 658 | 655 |
| 659 void GLHelper::CropScaleReadbackAndCleanTexture( | 656 void GLHelper::CropScaleReadbackAndCleanTexture( |
| 660 GLuint src_texture, | 657 GLuint src_texture, |
| 661 const gfx::Size& src_size, | 658 const gfx::Size& src_size, |
| 662 const gfx::Rect& src_subrect, | 659 const gfx::Rect& src_subrect, |
| 663 const gfx::Size& dst_size, | 660 const gfx::Size& dst_size, |
| 664 unsigned char* out, | 661 unsigned char* out, |
| 665 const SkBitmap::Config config, | 662 const SkBitmap::Config config, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 rect.width(), | 865 rect.width(), |
| 869 rect.height()); | 866 rect.height()); |
| 870 } | 867 } |
| 871 | 868 |
| 872 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { | 869 void GLHelper::CopyTextureFullImage(GLuint texture, const gfx::Size& size) { |
| 873 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 870 content::ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
| 874 gl_->CopyTexImage2D( | 871 gl_->CopyTexImage2D( |
| 875 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); | 872 GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size.width(), size.height(), 0); |
| 876 } | 873 } |
| 877 | 874 |
| 878 bool GLHelper::CanUseRgb565Readback() { | 875 void GLHelper::InitializeReadbackSupport() { |
| 879 if(initialized_565_format_check_){ | 876 // We are concerned about 16, 32-bit formats only. |
| 880 return support_565_format_; | 877 // The below are the most used 16, 32-bit formats. |
| 878 // In future if any new format support is needed that should be added here. | |
| 879 // IsReadbackConfigSupported should be just initialized once and it should | |
| 880 // never trigger SupportsFormat, between texture operations. | |
| 881 for (int i = 0; i < SkBitmap::kConfigCount; ++i) { | |
| 882 format_support_table_[i] = FORMAT_SUPPORT_UNKNOWN; | |
| 881 } | 883 } |
| 884 IsReadbackConfigSupported(SkBitmap::kRGB_565_Config); | |
| 885 IsReadbackConfigSupported(SkBitmap::kARGB_4444_Config); | |
| 886 IsReadbackConfigSupported(SkBitmap::kARGB_8888_Config); | |
| 887 | |
| 888 for (int i = 0; i < SkBitmap::kConfigCount; ++i) { | |
| 889 if (format_support_table_[i] == FORMAT_SUPPORT_UNKNOWN) | |
| 890 format_support_table_[i] = FORMAT_NOT_SUPPORTED; | |
| 891 } | |
| 892 } | |
| 893 | |
| 894 bool GLHelper::SupportsFormat(GLint format, GLint type) { | |
| 882 const int kTestSize = 64; | 895 const int kTestSize = 64; |
| 883 GLuint dst_texture = 0u; | 896 GLuint dst_texture = 0u; |
| 897 bool supports_format = false; | |
| 884 gl_->GenTextures(1, &dst_texture); | 898 gl_->GenTextures(1, &dst_texture); |
| 885 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 899 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
| 886 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 900 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 887 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 901 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 888 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 902 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 889 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 903 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 890 gl_->TexImage2D(GL_TEXTURE_2D, | 904 gl_->TexImage2D( |
| 891 0, | 905 GL_TEXTURE_2D, 0, format, kTestSize, kTestSize, 0, format, type, NULL); |
| 892 GL_RGB, | |
| 893 kTestSize, | |
| 894 kTestSize, | |
| 895 0, | |
| 896 GL_RGB, | |
| 897 GL_UNSIGNED_SHORT_5_6_5, | |
| 898 NULL); | |
| 899 ScopedFramebuffer dst_framebuffer(gl_); | 906 ScopedFramebuffer dst_framebuffer(gl_); |
| 900 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 907 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
| 901 dst_framebuffer); | 908 dst_framebuffer); |
| 902 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 909 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
| 903 GL_COLOR_ATTACHMENT0, | 910 GL_COLOR_ATTACHMENT0, |
| 904 GL_TEXTURE_2D, | 911 GL_TEXTURE_2D, |
| 905 dst_texture, | 912 dst_texture, |
| 906 0); | 913 0); |
| 907 GLint ext_format = 0, ext_type = 0; | 914 GLint ext_format = 0, ext_type = 0; |
| 908 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); | 915 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &ext_format); |
| 909 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); | 916 gl_->GetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &ext_type); |
| 910 gl_->DeleteTextures(1, &dst_texture); | 917 gl_->DeleteTextures(1, &dst_texture); |
| 911 if ((ext_format == GL_RGB) && (ext_type == GL_UNSIGNED_SHORT_5_6_5)) { | 918 if ((ext_format == format) && (ext_type == type)) { |
| 912 support_565_format_ = true; | 919 supports_format = true; |
| 913 } | 920 } |
| 914 initialized_565_format_check_ = true; | 921 return supports_format; |
| 915 return support_565_format_; | 922 } |
| 923 | |
| 924 bool GLHelper::IsReadbackConfigSupported(SkBitmap::Config bitmap_format) { | |
| 925 switch (format_support_table_[bitmap_format]) { | |
| 926 case FORMAT_SUPPORT_UNKNOWN: | |
|
no sievers
2014/02/26 20:05:43
If you change things this way, I'd remove the lazy
sivag
2014/02/27 15:33:17
Done.
| |
| 927 break; | |
| 928 case FORMAT_SUPPORTED: | |
| 929 return true; | |
| 930 case FORMAT_NOT_SUPPORTED: | |
| 931 return false; | |
| 932 default: | |
| 933 NOTREACHED(); | |
| 934 break; | |
| 935 } | |
| 936 | |
| 937 bool supports_format = false; | |
| 938 switch (bitmap_format) { | |
| 939 case SkBitmap::kRGB_565_Config: | |
| 940 supports_format = SupportsFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5); | |
| 941 break; | |
| 942 case SkBitmap::kARGB_8888_Config: | |
| 943 supports_format = SupportsFormat(GL_RGBA, GL_UNSIGNED_BYTE); | |
| 944 break; | |
| 945 case SkBitmap::kARGB_4444_Config: | |
| 946 supports_format = false; | |
| 947 break; | |
| 948 default: | |
| 949 NOTREACHED(); | |
| 950 supports_format = false; | |
| 951 break; | |
| 952 } | |
| 953 format_support_table_[bitmap_format] = | |
| 954 supports_format ? FORMAT_SUPPORTED : FORMAT_NOT_SUPPORTED; | |
| 955 | |
| 956 return supports_format; | |
| 916 } | 957 } |
| 917 | 958 |
| 918 void GLHelper::CopyTextureToImpl::ReadbackPlane( | 959 void GLHelper::CopyTextureToImpl::ReadbackPlane( |
| 919 TextureFrameBufferPair* source, | 960 TextureFrameBufferPair* source, |
| 920 const scoped_refptr<media::VideoFrame>& target, | 961 const scoped_refptr<media::VideoFrame>& target, |
| 921 int plane, | 962 int plane, |
| 922 int size_shift, | 963 int size_shift, |
| 923 const gfx::Rect& dst_subrect, | 964 const gfx::Rect& dst_subrect, |
| 924 const base::Callback<void(bool)>& callback) { | 965 const base::Callback<void(bool)>& callback) { |
| 925 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 966 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1233 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1274 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
| 1234 src_size, | 1275 src_size, |
| 1235 src_subrect, | 1276 src_subrect, |
| 1236 dst_size, | 1277 dst_size, |
| 1237 dst_subrect, | 1278 dst_subrect, |
| 1238 flip_vertically, | 1279 flip_vertically, |
| 1239 use_mrt); | 1280 use_mrt); |
| 1240 } | 1281 } |
| 1241 | 1282 |
| 1242 } // namespace content | 1283 } // namespace content |
| OLD | NEW |