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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 uint32 sync_point) { | 134 uint32 sync_point) { |
135 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); | 135 return helper_->ConsumeMailboxToTexture(mailbox, sync_point); |
136 } | 136 } |
137 | 137 |
138 void CropScaleReadbackAndCleanTexture( | 138 void CropScaleReadbackAndCleanTexture( |
139 GLuint src_texture, | 139 GLuint src_texture, |
140 const gfx::Size& src_size, | 140 const gfx::Size& src_size, |
141 const gfx::Rect& src_subrect, | 141 const gfx::Rect& src_subrect, |
142 const gfx::Size& dst_size, | 142 const gfx::Size& dst_size, |
143 unsigned char* out, | 143 unsigned char* out, |
144 const SkBitmap::Config config, | 144 const SkColorType color_type, |
145 const base::Callback<void(bool)>& callback, | 145 const base::Callback<void(bool)>& callback, |
146 GLHelper::ScalerQuality quality); | 146 GLHelper::ScalerQuality quality); |
147 | 147 |
148 void ReadbackTextureSync(GLuint texture, | 148 void ReadbackTextureSync(GLuint texture, |
149 const gfx::Rect& src_rect, | 149 const gfx::Rect& src_rect, |
150 unsigned char* out, | 150 unsigned char* out, |
151 SkBitmap::Config format); | 151 SkColorType format); |
152 | 152 |
153 void ReadbackTextureAsync(GLuint texture, | 153 void ReadbackTextureAsync(GLuint texture, |
154 const gfx::Size& dst_size, | 154 const gfx::Size& dst_size, |
155 unsigned char* out, | 155 unsigned char* out, |
156 SkBitmap::Config config, | 156 SkColorType color_type, |
157 const base::Callback<void(bool)>& callback); | 157 const base::Callback<void(bool)>& callback); |
158 | 158 |
159 // Reads back bytes from the currently bound frame buffer. | 159 // Reads back bytes from the currently bound frame buffer. |
160 // Note that dst_size is specified in bytes, not pixels. | 160 // Note that dst_size is specified in bytes, not pixels. |
161 void ReadbackAsync(const gfx::Size& dst_size, | 161 void ReadbackAsync(const gfx::Size& dst_size, |
162 int32 bytes_per_row, // generally dst_size.width() * 4 | 162 int32 bytes_per_row, // generally dst_size.width() * 4 |
163 int32 row_stride_bytes, // generally dst_size.width() * 4 | 163 int32 row_stride_bytes, // generally dst_size.width() * 4 |
164 unsigned char* out, | 164 unsigned char* out, |
165 const SkBitmap::Config config, | 165 const SkColorType color_type, |
166 ReadbackSwizzle swizzle, | 166 ReadbackSwizzle swizzle, |
167 const base::Callback<void(bool)>& callback); | 167 const base::Callback<void(bool)>& callback); |
168 | 168 |
169 void ReadbackPlane(TextureFrameBufferPair* source, | 169 void ReadbackPlane(TextureFrameBufferPair* source, |
170 const scoped_refptr<media::VideoFrame>& target, | 170 const scoped_refptr<media::VideoFrame>& target, |
171 int plane, | 171 int plane, |
172 int size_shift, | 172 int size_shift, |
173 const gfx::Rect& dst_subrect, | 173 const gfx::Rect& dst_subrect, |
174 ReadbackSwizzle swizzle, | 174 ReadbackSwizzle swizzle, |
175 const base::Callback<void(bool)>& callback); | 175 const base::Callback<void(bool)>& callback); |
(...skipping 10 matching lines...) Expand all Loading... |
186 const gfx::Rect& src_subrect, | 186 const gfx::Rect& src_subrect, |
187 const gfx::Size& dst_size, | 187 const gfx::Size& dst_size, |
188 const gfx::Rect& dst_subrect, | 188 const gfx::Rect& dst_subrect, |
189 bool flip_vertically, | 189 bool flip_vertically, |
190 bool use_mrt); | 190 bool use_mrt); |
191 | 191 |
192 // Returns the maximum number of draw buffers available, | 192 // Returns the maximum number of draw buffers available, |
193 // 0 if GL_EXT_draw_buffers is not available. | 193 // 0 if GL_EXT_draw_buffers is not available. |
194 GLint MaxDrawBuffers() const { return max_draw_buffers_; } | 194 GLint MaxDrawBuffers() const { return max_draw_buffers_; } |
195 | 195 |
196 bool IsReadbackConfigSupported(SkBitmap::Config bitmap_config); | 196 bool IsReadbackConfigSupported(SkColorType color_type); |
197 | 197 |
198 private: | 198 private: |
199 // A single request to CropScaleReadbackAndCleanTexture. | 199 // A single request to CropScaleReadbackAndCleanTexture. |
200 // The main thread can cancel the request, before it's handled by the helper | 200 // The main thread can cancel the request, before it's handled by the helper |
201 // thread, by resetting the texture and pixels fields. Alternatively, the | 201 // thread, by resetting the texture and pixels fields. Alternatively, the |
202 // thread marks that it handles the request by resetting the pixels field | 202 // thread marks that it handles the request by resetting the pixels field |
203 // (meaning it guarantees that the callback with be called). | 203 // (meaning it guarantees that the callback with be called). |
204 // In either case, the callback must be called exactly once, and the texture | 204 // In either case, the callback must be called exactly once, and the texture |
205 // must be deleted by the main thread gl. | 205 // must be deleted by the main thread gl. |
206 struct Request { | 206 struct Request { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 309 |
310 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 310 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
311 // scales it to |dst_size|, writes it into a texture, and returns its ID. | 311 // scales it to |dst_size|, writes it into a texture, and returns its ID. |
312 // |src_size| is the size of |src_texture|. | 312 // |src_size| is the size of |src_texture|. |
313 GLuint ScaleTexture(GLuint src_texture, | 313 GLuint ScaleTexture(GLuint src_texture, |
314 const gfx::Size& src_size, | 314 const gfx::Size& src_size, |
315 const gfx::Rect& src_subrect, | 315 const gfx::Rect& src_subrect, |
316 const gfx::Size& dst_size, | 316 const gfx::Size& dst_size, |
317 bool vertically_flip_texture, | 317 bool vertically_flip_texture, |
318 bool swizzle, | 318 bool swizzle, |
319 SkBitmap::Config config, | 319 SkColorType color_type, |
320 GLHelper::ScalerQuality quality); | 320 GLHelper::ScalerQuality quality); |
321 | 321 |
322 static void nullcallback(bool success) {} | 322 static void nullcallback(bool success) {} |
323 void ReadbackDone(Request *request, int bytes_per_pixel); | 323 void ReadbackDone(Request *request, int bytes_per_pixel); |
324 void FinishRequest(Request* request, bool result); | 324 void FinishRequest(Request* request, bool result); |
325 void CancelRequests(); | 325 void CancelRequests(); |
326 | 326 |
327 static const float kRGBtoYColorWeights[]; | 327 static const float kRGBtoYColorWeights[]; |
328 static const float kRGBtoUColorWeights[]; | 328 static const float kRGBtoUColorWeights[]; |
329 static const float kRGBtoVColorWeights[]; | 329 static const float kRGBtoVColorWeights[]; |
(...skipping 25 matching lines...) Expand all Loading... |
355 swizzle); | 355 swizzle); |
356 } | 356 } |
357 | 357 |
358 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( | 358 GLuint GLHelper::CopyTextureToImpl::ScaleTexture( |
359 GLuint src_texture, | 359 GLuint src_texture, |
360 const gfx::Size& src_size, | 360 const gfx::Size& src_size, |
361 const gfx::Rect& src_subrect, | 361 const gfx::Rect& src_subrect, |
362 const gfx::Size& dst_size, | 362 const gfx::Size& dst_size, |
363 bool vertically_flip_texture, | 363 bool vertically_flip_texture, |
364 bool swizzle, | 364 bool swizzle, |
365 SkBitmap::Config bitmap_config, | 365 SkColorType color_type, |
366 GLHelper::ScalerQuality quality) { | 366 GLHelper::ScalerQuality quality) { |
367 if (!IsReadbackConfigSupported(bitmap_config)) | 367 if (!IsReadbackConfigSupported(color_type)) |
368 return 0; | 368 return 0; |
369 | 369 |
370 scoped_ptr<ScalerInterface> scaler( | 370 scoped_ptr<ScalerInterface> scaler( |
371 helper_->CreateScaler(quality, | 371 helper_->CreateScaler(quality, |
372 src_size, | 372 src_size, |
373 src_subrect, | 373 src_subrect, |
374 dst_size, | 374 dst_size, |
375 vertically_flip_texture, | 375 vertically_flip_texture, |
376 swizzle)); | 376 swizzle)); |
377 GLuint dst_texture = 0u; | 377 GLuint dst_texture = 0u; |
378 // Start with ARGB8888 params as any other format which is not | 378 // Start with ARGB8888 params as any other format which is not |
379 // supported is already asserted above. | 379 // supported is already asserted above. |
380 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; | 380 GLenum format = GL_RGBA , type = GL_UNSIGNED_BYTE; |
381 gl_->GenTextures(1, &dst_texture); | 381 gl_->GenTextures(1, &dst_texture); |
382 { | 382 { |
383 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); | 383 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dst_texture); |
384 switch (bitmap_config) { | 384 switch (color_type) { |
385 case SkBitmap::kARGB_8888_Config: | 385 case kN32_SkColorType: |
386 // Do nothing params already set. | 386 // Do nothing params already set. |
387 break; | 387 break; |
388 case SkBitmap::kRGB_565_Config: | 388 case kRGB_565_SkColorType: |
389 format = GL_RGB; | 389 format = GL_RGB; |
390 type = GL_UNSIGNED_SHORT_5_6_5; | 390 type = GL_UNSIGNED_SHORT_5_6_5; |
391 break; | 391 break; |
392 default: | 392 default: |
393 NOTREACHED(); | 393 NOTREACHED(); |
394 break; | 394 break; |
395 } | 395 } |
396 gl_->TexImage2D(GL_TEXTURE_2D, | 396 gl_->TexImage2D(GL_TEXTURE_2D, |
397 0, | 397 0, |
398 format, | 398 format, |
399 dst_size.width(), | 399 dst_size.width(), |
400 dst_size.height(), | 400 dst_size.height(), |
401 0, | 401 0, |
402 format, | 402 format, |
403 type, | 403 type, |
404 NULL); | 404 NULL); |
405 } | 405 } |
406 scaler->Scale(src_texture, dst_texture); | 406 scaler->Scale(src_texture, dst_texture); |
407 return dst_texture; | 407 return dst_texture; |
408 } | 408 } |
409 | 409 |
410 void GLHelper::CopyTextureToImpl::ReadbackAsync( | 410 void GLHelper::CopyTextureToImpl::ReadbackAsync( |
411 const gfx::Size& dst_size, | 411 const gfx::Size& dst_size, |
412 int32 bytes_per_row, | 412 int32 bytes_per_row, |
413 int32 row_stride_bytes, | 413 int32 row_stride_bytes, |
414 unsigned char* out, | 414 unsigned char* out, |
415 const SkBitmap::Config bitmap_config, | 415 const SkColorType color_type, |
416 ReadbackSwizzle swizzle, | 416 ReadbackSwizzle swizzle, |
417 const base::Callback<void(bool)>& callback) { | 417 const base::Callback<void(bool)>& callback) { |
418 if (!IsReadbackConfigSupported(bitmap_config)) { | 418 if (!IsReadbackConfigSupported(color_type)) { |
419 callback.Run(false); | 419 callback.Run(false); |
420 return; | 420 return; |
421 } | 421 } |
422 Request* request = | 422 Request* request = |
423 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); | 423 new Request(dst_size, bytes_per_row, row_stride_bytes, out, callback); |
424 request_queue_.push(request); | 424 request_queue_.push(request); |
425 request->buffer = 0u; | 425 request->buffer = 0u; |
426 // Start with ARGB8888 params as any other format which is not | 426 // Start with ARGB8888 params as any other format which is not |
427 // supported is already asserted above. | 427 // supported is already asserted above. |
428 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; | 428 GLenum format = GL_RGBA, type = GL_UNSIGNED_BYTE; |
429 int bytes_per_pixel = 4; | 429 int bytes_per_pixel = 4; |
430 | 430 |
431 switch (bitmap_config) { | 431 switch (color_type) { |
432 case SkBitmap::kARGB_8888_Config: | 432 case kN32_SkColorType: |
433 if (swizzle == kSwizzleBGRA) | 433 if (swizzle == kSwizzleBGRA) |
434 format = GL_BGRA_EXT; | 434 format = GL_BGRA_EXT; |
435 break; | 435 break; |
436 case SkBitmap::kRGB_565_Config: | 436 case kRGB_565_SkColorType: |
437 format = GL_RGB; | 437 format = GL_RGB; |
438 type = GL_UNSIGNED_SHORT_5_6_5; | 438 type = GL_UNSIGNED_SHORT_5_6_5; |
439 bytes_per_pixel = 2; | 439 bytes_per_pixel = 2; |
440 break; | 440 break; |
441 default: | 441 default: |
442 NOTREACHED(); | 442 NOTREACHED(); |
443 break; | 443 break; |
444 } | 444 } |
445 gl_->GenBuffers(1, &request->buffer); | 445 gl_->GenBuffers(1, &request->buffer); |
446 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); | 446 gl_->BindBuffer(GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM, request->buffer); |
(...skipping 18 matching lines...) Expand all Loading... |
465 request->query, | 465 request->query, |
466 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), | 466 base::Bind(&CopyTextureToImpl::ReadbackDone, AsWeakPtr(), |
467 request, bytes_per_pixel)); | 467 request, bytes_per_pixel)); |
468 } | 468 } |
469 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( | 469 void GLHelper::CopyTextureToImpl::CropScaleReadbackAndCleanTexture( |
470 GLuint src_texture, | 470 GLuint src_texture, |
471 const gfx::Size& src_size, | 471 const gfx::Size& src_size, |
472 const gfx::Rect& src_subrect, | 472 const gfx::Rect& src_subrect, |
473 const gfx::Size& dst_size, | 473 const gfx::Size& dst_size, |
474 unsigned char* out, | 474 unsigned char* out, |
475 const SkBitmap::Config bitmap_config, | 475 const SkColorType color_type, |
476 const base::Callback<void(bool)>& callback, | 476 const base::Callback<void(bool)>& callback, |
477 GLHelper::ScalerQuality quality) { | 477 GLHelper::ScalerQuality quality) { |
478 if (!IsReadbackConfigSupported(bitmap_config)) { | 478 if (!IsReadbackConfigSupported(color_type)) { |
479 callback.Run(false); | 479 callback.Run(false); |
480 return; | 480 return; |
481 } | 481 } |
482 GLuint texture = ScaleTexture(src_texture, | 482 GLuint texture = ScaleTexture(src_texture, |
483 src_size, | 483 src_size, |
484 src_subrect, | 484 src_subrect, |
485 dst_size, | 485 dst_size, |
486 true, | 486 true, |
487 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT | 487 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT |
488 true, | 488 true, |
489 #else | 489 #else |
490 false, | 490 false, |
491 #endif | 491 #endif |
492 bitmap_config, | 492 color_type, |
493 quality); | 493 quality); |
494 DCHECK(texture); | 494 DCHECK(texture); |
495 ScopedFramebuffer dst_framebuffer(gl_); | 495 ScopedFramebuffer dst_framebuffer(gl_); |
496 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 496 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
497 dst_framebuffer); | 497 dst_framebuffer); |
498 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 498 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
499 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 499 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
500 GL_COLOR_ATTACHMENT0, | 500 GL_COLOR_ATTACHMENT0, |
501 GL_TEXTURE_2D, | 501 GL_TEXTURE_2D, |
502 texture, | 502 texture, |
503 0); | 503 0); |
504 int bytes_per_pixel = 4; | 504 int bytes_per_pixel = 4; |
505 switch (bitmap_config) { | 505 switch (color_type) { |
506 case SkBitmap::kARGB_8888_Config: | 506 case kN32_SkColorType: |
507 // Do nothing params already set. | 507 // Do nothing params already set. |
508 break; | 508 break; |
509 case SkBitmap::kRGB_565_Config: | 509 case kRGB_565_SkColorType: |
510 bytes_per_pixel = 2; | 510 bytes_per_pixel = 2; |
511 break; | 511 break; |
512 default: | 512 default: |
513 NOTREACHED(); | 513 NOTREACHED(); |
514 break; | 514 break; |
515 } | 515 } |
516 ReadbackAsync(dst_size, | 516 ReadbackAsync(dst_size, |
517 dst_size.width() * bytes_per_pixel, | 517 dst_size.width() * bytes_per_pixel, |
518 dst_size.width() * bytes_per_pixel, | 518 dst_size.width() * bytes_per_pixel, |
519 out, | 519 out, |
520 bitmap_config, | 520 color_type, |
521 kSwizzleNone, | 521 kSwizzleNone, |
522 callback); | 522 callback); |
523 gl_->DeleteTextures(1, &texture); | 523 gl_->DeleteTextures(1, &texture); |
524 } | 524 } |
525 | 525 |
526 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( | 526 void GLHelper::CopyTextureToImpl::ReadbackTextureSync( |
527 GLuint texture, | 527 GLuint texture, |
528 const gfx::Rect& src_rect, | 528 const gfx::Rect& src_rect, |
529 unsigned char* out, | 529 unsigned char* out, |
530 SkBitmap::Config bitmap_config) { | 530 SkColorType color_type) { |
531 if (!IsReadbackConfigSupported(bitmap_config)) | 531 if (!IsReadbackConfigSupported(color_type)) |
532 return; | 532 return; |
533 | 533 |
534 ScopedFramebuffer dst_framebuffer(gl_); | 534 ScopedFramebuffer dst_framebuffer(gl_); |
535 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 535 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
536 dst_framebuffer); | 536 dst_framebuffer); |
537 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 537 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
538 gl_->FramebufferTexture2D( | 538 gl_->FramebufferTexture2D( |
539 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); | 539 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
540 GLenum format = | 540 GLenum format = |
541 (bitmap_config == SkBitmap::kRGB_565_Config) ? GL_RGB : GL_RGBA; | 541 (color_type == kRGB_565_SkColorType) ? GL_RGB : GL_RGBA; |
542 GLenum type = (bitmap_config == SkBitmap::kRGB_565_Config) | 542 GLenum type = (color_type == kRGB_565_SkColorType) |
543 ? GL_UNSIGNED_SHORT_5_6_5 | 543 ? GL_UNSIGNED_SHORT_5_6_5 |
544 : GL_UNSIGNED_BYTE; | 544 : GL_UNSIGNED_BYTE; |
545 gl_->ReadPixels(src_rect.x(), | 545 gl_->ReadPixels(src_rect.x(), |
546 src_rect.y(), | 546 src_rect.y(), |
547 src_rect.width(), | 547 src_rect.width(), |
548 src_rect.height(), | 548 src_rect.height(), |
549 format, | 549 format, |
550 type, | 550 type, |
551 out); | 551 out); |
552 } | 552 } |
553 | 553 |
554 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( | 554 void GLHelper::CopyTextureToImpl::ReadbackTextureAsync( |
555 GLuint texture, | 555 GLuint texture, |
556 const gfx::Size& dst_size, | 556 const gfx::Size& dst_size, |
557 unsigned char* out, | 557 unsigned char* out, |
558 SkBitmap::Config bitmap_config, | 558 SkColorType color_type, |
559 const base::Callback<void(bool)>& callback) { | 559 const base::Callback<void(bool)>& callback) { |
560 if (!IsReadbackConfigSupported(bitmap_config)) | 560 if (!IsReadbackConfigSupported(color_type)) |
561 return; | 561 return; |
562 | 562 |
563 ScopedFramebuffer dst_framebuffer(gl_); | 563 ScopedFramebuffer dst_framebuffer(gl_); |
564 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, | 564 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl_, |
565 dst_framebuffer); | 565 dst_framebuffer); |
566 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); | 566 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, texture); |
567 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 567 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, |
568 GL_COLOR_ATTACHMENT0, | 568 GL_COLOR_ATTACHMENT0, |
569 GL_TEXTURE_2D, | 569 GL_TEXTURE_2D, |
570 texture, | 570 texture, |
571 0); | 571 0); |
572 int bytes_per_pixel = (bitmap_config == SkBitmap::kRGB_565_Config) ? 2 : 4; | 572 int bytes_per_pixel = (color_type == kRGB_565_SkColorType) ? 2 : 4; |
573 ReadbackAsync(dst_size, | 573 ReadbackAsync(dst_size, |
574 dst_size.width() * bytes_per_pixel, | 574 dst_size.width() * bytes_per_pixel, |
575 dst_size.width() * bytes_per_pixel, | 575 dst_size.width() * bytes_per_pixel, |
576 out, | 576 out, |
577 bitmap_config, | 577 color_type, |
578 kSwizzleNone, | 578 kSwizzleNone, |
579 callback); | 579 callback); |
580 } | 580 } |
581 | 581 |
582 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( | 582 GLuint GLHelper::CopyTextureToImpl::CopyAndScaleTexture( |
583 GLuint src_texture, | 583 GLuint src_texture, |
584 const gfx::Size& src_size, | 584 const gfx::Size& src_size, |
585 const gfx::Size& dst_size, | 585 const gfx::Size& dst_size, |
586 bool vertically_flip_texture, | 586 bool vertically_flip_texture, |
587 GLHelper::ScalerQuality quality) { | 587 GLHelper::ScalerQuality quality) { |
588 return ScaleTexture(src_texture, | 588 return ScaleTexture(src_texture, |
589 src_size, | 589 src_size, |
590 gfx::Rect(src_size), | 590 gfx::Rect(src_size), |
591 dst_size, | 591 dst_size, |
592 vertically_flip_texture, | 592 vertically_flip_texture, |
593 false, | 593 false, |
594 SkBitmap::kARGB_8888_Config, | 594 kN32_SkColorType, |
595 quality); | 595 quality); |
596 } | 596 } |
597 | 597 |
598 bool GLHelper::CopyTextureToImpl::IsReadbackConfigSupported( | 598 bool GLHelper::CopyTextureToImpl::IsReadbackConfigSupported( |
599 SkBitmap::Config bitmap_config) { | 599 SkColorType color_type) { |
600 if (!helper_) { | 600 if (!helper_) { |
601 DCHECK(helper_); | 601 DCHECK(helper_); |
602 return false; | 602 return false; |
603 } | 603 } |
604 return helper_->IsReadbackConfigSupported(bitmap_config); | 604 return helper_->IsReadbackConfigSupported(color_type); |
605 } | 605 } |
606 | 606 |
607 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, | 607 void GLHelper::CopyTextureToImpl::ReadbackDone(Request* finished_request, |
608 int bytes_per_pixel) { | 608 int bytes_per_pixel) { |
609 TRACE_EVENT0("mirror", | 609 TRACE_EVENT0("mirror", |
610 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); | 610 "GLHelper::CopyTextureToImpl::CheckReadbackFramebufferComplete"); |
611 finished_request->done = true; | 611 finished_request->done = true; |
612 | 612 |
613 // We process transfer requests in the order they were received, regardless | 613 // We process transfer requests in the order they were received, regardless |
614 // of the order we get the callbacks in. | 614 // of the order we get the callbacks in. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 readback_support_(new GLHelperReadbackSupport(gl)) {} | 675 readback_support_(new GLHelperReadbackSupport(gl)) {} |
676 | 676 |
677 GLHelper::~GLHelper() {} | 677 GLHelper::~GLHelper() {} |
678 | 678 |
679 void GLHelper::CropScaleReadbackAndCleanTexture( | 679 void GLHelper::CropScaleReadbackAndCleanTexture( |
680 GLuint src_texture, | 680 GLuint src_texture, |
681 const gfx::Size& src_size, | 681 const gfx::Size& src_size, |
682 const gfx::Rect& src_subrect, | 682 const gfx::Rect& src_subrect, |
683 const gfx::Size& dst_size, | 683 const gfx::Size& dst_size, |
684 unsigned char* out, | 684 unsigned char* out, |
685 const SkBitmap::Config config, | 685 const SkColorType color_type, |
686 const base::Callback<void(bool)>& callback, | 686 const base::Callback<void(bool)>& callback, |
687 GLHelper::ScalerQuality quality) { | 687 GLHelper::ScalerQuality quality) { |
688 InitCopyTextToImpl(); | 688 InitCopyTextToImpl(); |
689 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( | 689 copy_texture_to_impl_->CropScaleReadbackAndCleanTexture( |
690 src_texture, | 690 src_texture, |
691 src_size, | 691 src_size, |
692 src_subrect, | 692 src_subrect, |
693 dst_size, | 693 dst_size, |
694 out, | 694 out, |
695 config, | 695 color_type, |
696 callback, | 696 callback, |
697 quality); | 697 quality); |
698 } | 698 } |
699 | 699 |
700 void GLHelper::CropScaleReadbackAndCleanMailbox( | 700 void GLHelper::CropScaleReadbackAndCleanMailbox( |
701 const gpu::Mailbox& src_mailbox, | 701 const gpu::Mailbox& src_mailbox, |
702 uint32 sync_point, | 702 uint32 sync_point, |
703 const gfx::Size& src_size, | 703 const gfx::Size& src_size, |
704 const gfx::Rect& src_subrect, | 704 const gfx::Rect& src_subrect, |
705 const gfx::Size& dst_size, | 705 const gfx::Size& dst_size, |
706 unsigned char* out, | 706 unsigned char* out, |
707 const SkBitmap::Config bitmap_config, | 707 const SkColorType color_type, |
708 const base::Callback<void(bool)>& callback, | 708 const base::Callback<void(bool)>& callback, |
709 GLHelper::ScalerQuality quality) { | 709 GLHelper::ScalerQuality quality) { |
710 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); | 710 GLuint mailbox_texture = ConsumeMailboxToTexture(src_mailbox, sync_point); |
711 CropScaleReadbackAndCleanTexture( | 711 CropScaleReadbackAndCleanTexture( |
712 mailbox_texture, src_size, src_subrect, dst_size, out, | 712 mailbox_texture, src_size, src_subrect, dst_size, out, |
713 bitmap_config, | 713 color_type, |
714 callback, | 714 callback, |
715 quality); | 715 quality); |
716 gl_->DeleteTextures(1, &mailbox_texture); | 716 gl_->DeleteTextures(1, &mailbox_texture); |
717 } | 717 } |
718 | 718 |
719 void GLHelper::ReadbackTextureSync(GLuint texture, | 719 void GLHelper::ReadbackTextureSync(GLuint texture, |
720 const gfx::Rect& src_rect, | 720 const gfx::Rect& src_rect, |
721 unsigned char* out, | 721 unsigned char* out, |
722 SkBitmap::Config format) { | 722 SkColorType format) { |
723 InitCopyTextToImpl(); | 723 InitCopyTextToImpl(); |
724 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); | 724 copy_texture_to_impl_->ReadbackTextureSync(texture, src_rect, out, format); |
725 } | 725 } |
726 | 726 |
727 void GLHelper::ReadbackTextureAsync( | 727 void GLHelper::ReadbackTextureAsync( |
728 GLuint texture, | 728 GLuint texture, |
729 const gfx::Size& dst_size, | 729 const gfx::Size& dst_size, |
730 unsigned char* out, | 730 unsigned char* out, |
731 SkBitmap::Config config, | 731 SkColorType color_type, |
732 const base::Callback<void(bool)>& callback) { | 732 const base::Callback<void(bool)>& callback) { |
733 InitCopyTextToImpl(); | 733 InitCopyTextToImpl(); |
734 copy_texture_to_impl_->ReadbackTextureAsync(texture, | 734 copy_texture_to_impl_->ReadbackTextureAsync(texture, |
735 dst_size, | 735 dst_size, |
736 out, | 736 out, |
737 config, | 737 color_type, |
738 callback); | 738 callback); |
739 } | 739 } |
740 | 740 |
741 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { | 741 GLuint GLHelper::CopyTexture(GLuint texture, const gfx::Size& size) { |
742 InitCopyTextToImpl(); | 742 InitCopyTextToImpl(); |
743 return copy_texture_to_impl_->CopyAndScaleTexture( | 743 return copy_texture_to_impl_->CopyAndScaleTexture( |
744 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); | 744 texture, size, size, false, GLHelper::SCALER_QUALITY_FAST); |
745 } | 745 } |
746 | 746 |
747 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, | 747 GLuint GLHelper::CopyAndScaleTexture(GLuint texture, |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 const gfx::Rect& dst_subrect, | 910 const gfx::Rect& dst_subrect, |
911 ReadbackSwizzle swizzle, | 911 ReadbackSwizzle swizzle, |
912 const base::Callback<void(bool)>& callback) { | 912 const base::Callback<void(bool)>& callback) { |
913 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); | 913 gl_->BindFramebuffer(GL_FRAMEBUFFER, source->framebuffer()); |
914 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + | 914 size_t offset = target->stride(plane) * (dst_subrect.y() >> size_shift) + |
915 (dst_subrect.x() >> size_shift); | 915 (dst_subrect.x() >> size_shift); |
916 ReadbackAsync(source->size(), | 916 ReadbackAsync(source->size(), |
917 dst_subrect.width() >> size_shift, | 917 dst_subrect.width() >> size_shift, |
918 target->stride(plane), | 918 target->stride(plane), |
919 target->data(plane) + offset, | 919 target->data(plane) + offset, |
920 SkBitmap::kARGB_8888_Config, | 920 kN32_SkColorType, |
921 swizzle, | 921 swizzle, |
922 callback); | 922 callback); |
923 } | 923 } |
924 | 924 |
925 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { | 925 const float GLHelper::CopyTextureToImpl::kRGBtoYColorWeights[] = { |
926 0.257f, 0.504f, 0.098f, 0.0625f}; | 926 0.257f, 0.504f, 0.098f, 0.0625f}; |
927 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { | 927 const float GLHelper::CopyTextureToImpl::kRGBtoUColorWeights[] = { |
928 -0.148f, -0.291f, 0.439f, 0.5f}; | 928 -0.148f, -0.291f, 0.439f, 0.5f}; |
929 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { | 929 const float GLHelper::CopyTextureToImpl::kRGBtoVColorWeights[] = { |
930 0.439f, -0.368f, -0.071f, 0.5f}; | 930 0.439f, -0.368f, -0.071f, 0.5f}; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 target, | 1187 target, |
1188 media::VideoFrame::kVPlane, | 1188 media::VideoFrame::kVPlane, |
1189 1, | 1189 1, |
1190 dst_subrect_, | 1190 dst_subrect_, |
1191 swizzle_, | 1191 swizzle_, |
1192 base::Bind(&CallbackKeepingVideoFrameAlive, target, callback)); | 1192 base::Bind(&CallbackKeepingVideoFrameAlive, target, callback)); |
1193 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); | 1193 gl_->BindFramebuffer(GL_FRAMEBUFFER, 0); |
1194 media::LetterboxYUV(target, dst_subrect_); | 1194 media::LetterboxYUV(target, dst_subrect_); |
1195 } | 1195 } |
1196 | 1196 |
1197 bool GLHelper::IsReadbackConfigSupported(SkBitmap::Config texture_format) { | 1197 bool GLHelper::IsReadbackConfigSupported(SkColorType texture_format) { |
1198 DCHECK(readback_support_.get()); | 1198 DCHECK(readback_support_.get()); |
1199 return readback_support_.get()->IsReadbackConfigSupported(texture_format); | 1199 return readback_support_.get()->IsReadbackConfigSupported(texture_format); |
1200 } | 1200 } |
1201 | 1201 |
1202 ReadbackYUVInterface* GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( | 1202 ReadbackYUVInterface* GLHelper::CopyTextureToImpl::CreateReadbackPipelineYUV( |
1203 GLHelper::ScalerQuality quality, | 1203 GLHelper::ScalerQuality quality, |
1204 const gfx::Size& src_size, | 1204 const gfx::Size& src_size, |
1205 const gfx::Rect& src_subrect, | 1205 const gfx::Rect& src_subrect, |
1206 const gfx::Size& dst_size, | 1206 const gfx::Size& dst_size, |
1207 const gfx::Rect& dst_subrect, | 1207 const gfx::Rect& dst_subrect, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, | 1253 return copy_texture_to_impl_->CreateReadbackPipelineYUV(quality, |
1254 src_size, | 1254 src_size, |
1255 src_subrect, | 1255 src_subrect, |
1256 dst_size, | 1256 dst_size, |
1257 dst_subrect, | 1257 dst_subrect, |
1258 flip_vertically, | 1258 flip_vertically, |
1259 use_mrt); | 1259 use_mrt); |
1260 } | 1260 } |
1261 | 1261 |
1262 } // namespace content | 1262 } // namespace content |
OLD | NEW |