| 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 <GLES3/gl3.h> | 5 #include <GLES3/gl3.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 cc::PaintCanvas* target_canvas() { return &target_canvas_; } | 117 cc::PaintCanvas* target_canvas() { return &target_canvas_; } |
| 118 | 118 |
| 119 protected: | 119 protected: |
| 120 SkCanvasVideoRenderer renderer_; | 120 SkCanvasVideoRenderer renderer_; |
| 121 | 121 |
| 122 scoped_refptr<VideoFrame> natural_frame_; | 122 scoped_refptr<VideoFrame> natural_frame_; |
| 123 scoped_refptr<VideoFrame> larger_frame_; | 123 scoped_refptr<VideoFrame> larger_frame_; |
| 124 scoped_refptr<VideoFrame> smaller_frame_; | 124 scoped_refptr<VideoFrame> smaller_frame_; |
| 125 scoped_refptr<VideoFrame> cropped_frame_; | 125 scoped_refptr<VideoFrame> cropped_frame_; |
| 126 | 126 |
| 127 cc::PaintCanvas target_canvas_; | 127 cc::SkiaPaintCanvas target_canvas_; |
| 128 base::MessageLoop message_loop_; | 128 base::MessageLoop message_loop_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRendererTest); | 130 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRendererTest); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 static SkBitmap AllocBitmap(int width, int height) { | 133 static SkBitmap AllocBitmap(int width, int height) { |
| 134 SkBitmap bitmap; | 134 SkBitmap bitmap; |
| 135 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); | 135 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); |
| 136 bitmap.eraseColor(0); | 136 bitmap.eraseColor(0); |
| 137 return bitmap; | 137 return bitmap; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 kHeight * 1 / 6 - 1)); | 361 kHeight * 1 / 6 - 1)); |
| 362 EXPECT_EQ(SK_ColorRED, | 362 EXPECT_EQ(SK_ColorRED, |
| 363 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1)); | 363 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1)); |
| 364 EXPECT_EQ(SK_ColorGREEN, | 364 EXPECT_EQ(SK_ColorGREEN, |
| 365 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6)); | 365 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6)); |
| 366 EXPECT_EQ(SK_ColorBLUE, | 366 EXPECT_EQ(SK_ColorBLUE, |
| 367 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); | 367 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(SkCanvasVideoRendererTest, CroppedFrame_NoScaling) { | 370 TEST_F(SkCanvasVideoRendererTest, CroppedFrame_NoScaling) { |
| 371 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 371 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 372 const gfx::Rect crop_rect = cropped_frame()->visible_rect(); | 372 const gfx::Rect crop_rect = cropped_frame()->visible_rect(); |
| 373 | 373 |
| 374 // Force painting to a non-zero position on the destination bitmap, to check | 374 // Force painting to a non-zero position on the destination bitmap, to check |
| 375 // if the coordinates are calculated properly. | 375 // if the coordinates are calculated properly. |
| 376 const int offset_x = 10; | 376 const int offset_x = 10; |
| 377 const int offset_y = 15; | 377 const int offset_y = 15; |
| 378 canvas.translate(offset_x, offset_y); | 378 canvas.translate(offset_x, offset_y); |
| 379 | 379 |
| 380 // Create a destination canvas with dimensions and scale which would not | 380 // Create a destination canvas with dimensions and scale which would not |
| 381 // cause scaling. | 381 // cause scaling. |
| 382 canvas.scale(static_cast<SkScalar>(crop_rect.width()) / kWidth, | 382 canvas.scale(static_cast<SkScalar>(crop_rect.width()) / kWidth, |
| 383 static_cast<SkScalar>(crop_rect.height()) / kHeight); | 383 static_cast<SkScalar>(crop_rect.height()) / kHeight); |
| 384 | 384 |
| 385 Paint(cropped_frame(), &canvas, kNone); | 385 Paint(cropped_frame(), &canvas, kNone); |
| 386 | 386 |
| 387 // Check the corners. | 387 // Check the corners. |
| 388 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, offset_x, offset_y)); | 388 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, offset_x, offset_y)); |
| 389 EXPECT_EQ(SK_ColorRED, | 389 EXPECT_EQ(SK_ColorRED, |
| 390 GetColorAt(&canvas, offset_x + crop_rect.width() - 1, offset_y)); | 390 GetColorAt(&canvas, offset_x + crop_rect.width() - 1, offset_y)); |
| 391 EXPECT_EQ(SK_ColorGREEN, | 391 EXPECT_EQ(SK_ColorGREEN, |
| 392 GetColorAt(&canvas, offset_x, offset_y + crop_rect.height() - 1)); | 392 GetColorAt(&canvas, offset_x, offset_y + crop_rect.height() - 1)); |
| 393 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, offset_x + crop_rect.width() - 1, | 393 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, offset_x + crop_rect.width() - 1, |
| 394 offset_y + crop_rect.height() - 1)); | 394 offset_y + crop_rect.height() - 1)); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_90) { | 397 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_90) { |
| 398 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 398 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 399 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, | 399 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, |
| 400 SkBlendMode::kSrcOver, VIDEO_ROTATION_90); | 400 SkBlendMode::kSrcOver, VIDEO_ROTATION_90); |
| 401 // Check the corners. | 401 // Check the corners. |
| 402 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, 0, 0)); | 402 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, 0, 0)); |
| 403 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, 0)); | 403 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, 0)); |
| 404 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 404 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 405 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, kHeight - 1)); | 405 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, kHeight - 1)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_180) { | 408 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_180) { |
| 409 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 409 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 410 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, | 410 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, |
| 411 SkBlendMode::kSrcOver, VIDEO_ROTATION_180); | 411 SkBlendMode::kSrcOver, VIDEO_ROTATION_180); |
| 412 // Check the corners. | 412 // Check the corners. |
| 413 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, 0)); | 413 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, 0)); |
| 414 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, 0)); | 414 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, 0)); |
| 415 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 415 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 416 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, kHeight - 1)); | 416 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, kHeight - 1)); |
| 417 } | 417 } |
| 418 | 418 |
| 419 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_270) { | 419 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_270) { |
| 420 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 420 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 421 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, | 421 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, |
| 422 SkBlendMode::kSrcOver, VIDEO_ROTATION_270); | 422 SkBlendMode::kSrcOver, VIDEO_ROTATION_270); |
| 423 // Check the corners. | 423 // Check the corners. |
| 424 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, 0)); | 424 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, 0)); |
| 425 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, 0)); | 425 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, 0)); |
| 426 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 426 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 427 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, 0, kHeight - 1)); | 427 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, 0, kHeight - 1)); |
| 428 } | 428 } |
| 429 | 429 |
| 430 TEST_F(SkCanvasVideoRendererTest, Video_Translate) { | 430 TEST_F(SkCanvasVideoRendererTest, Video_Translate) { |
| 431 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 431 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 432 FillCanvas(&canvas, SK_ColorMAGENTA); | 432 FillCanvas(&canvas, SK_ColorMAGENTA); |
| 433 | 433 |
| 434 PaintRotated(cropped_frame(), &canvas, | 434 PaintRotated(cropped_frame(), &canvas, |
| 435 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), | 435 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), |
| 436 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_0); | 436 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_0); |
| 437 // Check the corners of quadrant 2 and 4. | 437 // Check the corners of quadrant 2 and 4. |
| 438 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); | 438 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); |
| 439 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); | 439 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); |
| 440 EXPECT_EQ(SK_ColorMAGENTA, | 440 EXPECT_EQ(SK_ColorMAGENTA, |
| 441 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); | 441 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); |
| 442 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); | 442 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); |
| 443 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); | 443 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); |
| 444 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); | 444 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); |
| 445 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 445 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 446 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); | 446 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_90) { | 449 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_90) { |
| 450 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 450 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 451 FillCanvas(&canvas, SK_ColorMAGENTA); | 451 FillCanvas(&canvas, SK_ColorMAGENTA); |
| 452 | 452 |
| 453 PaintRotated(cropped_frame(), &canvas, | 453 PaintRotated(cropped_frame(), &canvas, |
| 454 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), | 454 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), |
| 455 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_90); | 455 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_90); |
| 456 // Check the corners of quadrant 2 and 4. | 456 // Check the corners of quadrant 2 and 4. |
| 457 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); | 457 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); |
| 458 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); | 458 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); |
| 459 EXPECT_EQ(SK_ColorMAGENTA, | 459 EXPECT_EQ(SK_ColorMAGENTA, |
| 460 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); | 460 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); |
| 461 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); | 461 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); |
| 462 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); | 462 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); |
| 463 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); | 463 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); |
| 464 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 464 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 465 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); | 465 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); |
| 466 } | 466 } |
| 467 | 467 |
| 468 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_180) { | 468 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_180) { |
| 469 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 469 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 470 FillCanvas(&canvas, SK_ColorMAGENTA); | 470 FillCanvas(&canvas, SK_ColorMAGENTA); |
| 471 | 471 |
| 472 PaintRotated(cropped_frame(), &canvas, | 472 PaintRotated(cropped_frame(), &canvas, |
| 473 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), | 473 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), |
| 474 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_180); | 474 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_180); |
| 475 // Check the corners of quadrant 2 and 4. | 475 // Check the corners of quadrant 2 and 4. |
| 476 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); | 476 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); |
| 477 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); | 477 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); |
| 478 EXPECT_EQ(SK_ColorMAGENTA, | 478 EXPECT_EQ(SK_ColorMAGENTA, |
| 479 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); | 479 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); |
| 480 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); | 480 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); |
| 481 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); | 481 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); |
| 482 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); | 482 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); |
| 483 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); | 483 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); |
| 484 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); | 484 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); |
| 485 } | 485 } |
| 486 | 486 |
| 487 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_270) { | 487 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_270) { |
| 488 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 488 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 489 FillCanvas(&canvas, SK_ColorMAGENTA); | 489 FillCanvas(&canvas, SK_ColorMAGENTA); |
| 490 | 490 |
| 491 PaintRotated(cropped_frame(), &canvas, | 491 PaintRotated(cropped_frame(), &canvas, |
| 492 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), | 492 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), |
| 493 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_270); | 493 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_270); |
| 494 // Check the corners of quadrant 2 and 4. | 494 // Check the corners of quadrant 2 and 4. |
| 495 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); | 495 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); |
| 496 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); | 496 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); |
| 497 EXPECT_EQ(SK_ColorMAGENTA, | 497 EXPECT_EQ(SK_ColorMAGENTA, |
| 498 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); | 498 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 const int stride = bitmap.width() + offset_x; | 551 const int stride = bitmap.width() + offset_x; |
| 552 const size_t byte_size = stride * (bitmap.height() + offset_y) * 2; | 552 const size_t byte_size = stride * (bitmap.height() + offset_y) * 2; |
| 553 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( | 553 std::unique_ptr<unsigned char, base::AlignedFreeDeleter> memory( |
| 554 static_cast<unsigned char*>(base::AlignedAlloc( | 554 static_cast<unsigned char*>(base::AlignedAlloc( |
| 555 byte_size, media::VideoFrame::kFrameAddressAlignment))); | 555 byte_size, media::VideoFrame::kFrameAddressAlignment))); |
| 556 const gfx::Rect rect(offset_x, offset_y, bitmap.width(), bitmap.height()); | 556 const gfx::Rect rect(offset_x, offset_y, bitmap.width(), bitmap.height()); |
| 557 scoped_refptr<media::VideoFrame> video_frame = | 557 scoped_refptr<media::VideoFrame> video_frame = |
| 558 CreateTestY16Frame(gfx::Size(stride, offset_y + bitmap.height()), rect, | 558 CreateTestY16Frame(gfx::Size(stride, offset_y + bitmap.height()), rect, |
| 559 memory.get(), cropped_frame()->timestamp()); | 559 memory.get(), cropped_frame()->timestamp()); |
| 560 | 560 |
| 561 cc::PaintCanvas canvas(bitmap); | 561 cc::SkiaPaintCanvas canvas(bitmap); |
| 562 cc::PaintFlags flags; | 562 cc::PaintFlags flags; |
| 563 flags.setFilterQuality(kNone_SkFilterQuality); | 563 flags.setFilterQuality(kNone_SkFilterQuality); |
| 564 renderer_.Paint(video_frame, &canvas, | 564 renderer_.Paint(video_frame, &canvas, |
| 565 gfx::RectF(bitmap.width(), bitmap.height()), flags, | 565 gfx::RectF(bitmap.width(), bitmap.height()), flags, |
| 566 VIDEO_ROTATION_0, Context3D()); | 566 VIDEO_ROTATION_0, Context3D()); |
| 567 SkAutoLockPixels lock(bitmap); | 567 SkAutoLockPixels lock(bitmap); |
| 568 for (int j = 0; j < bitmap.height(); j++) { | 568 for (int j = 0; j < bitmap.height(); j++) { |
| 569 for (int i = 0; i < bitmap.width(); i++) { | 569 for (int i = 0; i < bitmap.width(); i++) { |
| 570 const int value = i + j * bitmap.width(); | 570 const int value = i + j * bitmap.width(); |
| 571 EXPECT_EQ(SkColorSetRGB(value, value, value), bitmap.getColor(i, j)); | 571 EXPECT_EQ(SkColorSetRGB(value, value, value), bitmap.getColor(i, j)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 638 |
| 639 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is | 639 // Test that SkCanvasVideoRendererTest::Paint doesn't crash when GrContext is |
| 640 // abandoned. | 640 // abandoned. |
| 641 TEST_F(SkCanvasVideoRendererTest, ContextLost) { | 641 TEST_F(SkCanvasVideoRendererTest, ContextLost) { |
| 642 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); | 642 sk_sp<const GrGLInterface> null_interface(GrGLCreateNullInterface()); |
| 643 sk_sp<GrContext> gr_context(GrContext::Create( | 643 sk_sp<GrContext> gr_context(GrContext::Create( |
| 644 kOpenGL_GrBackend, | 644 kOpenGL_GrBackend, |
| 645 reinterpret_cast<GrBackendContext>(null_interface.get()))); | 645 reinterpret_cast<GrBackendContext>(null_interface.get()))); |
| 646 gr_context->abandonContext(); | 646 gr_context->abandonContext(); |
| 647 | 647 |
| 648 cc::PaintCanvas canvas(AllocBitmap(kWidth, kHeight)); | 648 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); |
| 649 | 649 |
| 650 TestGLES2Interface gles2; | 650 TestGLES2Interface gles2; |
| 651 Context3D context_3d(&gles2, gr_context.get()); | 651 Context3D context_3d(&gles2, gr_context.get()); |
| 652 gfx::Size size(kWidth, kHeight); | 652 gfx::Size size(kWidth, kHeight); |
| 653 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( | 653 gpu::MailboxHolder holders[VideoFrame::kMaxPlanes] = {gpu::MailboxHolder( |
| 654 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)}; | 654 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB)}; |
| 655 auto video_frame = VideoFrame::WrapNativeTextures( | 655 auto video_frame = VideoFrame::WrapNativeTextures( |
| 656 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size, | 656 PIXEL_FORMAT_UYVY, holders, base::Bind(MailboxHoldersReleased), size, |
| 657 gfx::Rect(size), size, kNoTimestamp); | 657 gfx::Rect(size), size, kNoTimestamp); |
| 658 | 658 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 669 SkImageInfo imInfo = | 669 SkImageInfo imInfo = |
| 670 SkImageInfo::MakeN32(fWidth, fHeight, kOpaque_SkAlphaType); | 670 SkImageInfo::MakeN32(fWidth, fHeight, kOpaque_SkAlphaType); |
| 671 | 671 |
| 672 sk_sp<const GrGLInterface> glInterface(GrGLCreateNullInterface()); | 672 sk_sp<const GrGLInterface> glInterface(GrGLCreateNullInterface()); |
| 673 sk_sp<GrContext> grContext( | 673 sk_sp<GrContext> grContext( |
| 674 GrContext::Create(kOpenGL_GrBackend, | 674 GrContext::Create(kOpenGL_GrBackend, |
| 675 reinterpret_cast<GrBackendContext>(glInterface.get()))); | 675 reinterpret_cast<GrBackendContext>(glInterface.get()))); |
| 676 | 676 |
| 677 sk_sp<SkSurface> surface = | 677 sk_sp<SkSurface> surface = |
| 678 SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kYes, imInfo); | 678 SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kYes, imInfo); |
| 679 cc::PaintCanvas canvas(surface->getCanvas()); | 679 cc::SkiaPaintCanvas canvas(surface->getCanvas()); |
| 680 | 680 |
| 681 TestGLES2Interface gles2; | 681 TestGLES2Interface gles2; |
| 682 Context3D context_3d(&gles2, grContext.get()); | 682 Context3D context_3d(&gles2, grContext.get()); |
| 683 gfx::Size coded_size(fWidth, fHeight); | 683 gfx::Size coded_size(fWidth, fHeight); |
| 684 gfx::Size visible_size(fWidth / 2, fHeight / 2); | 684 gfx::Size visible_size(fWidth / 2, fHeight / 2); |
| 685 | 685 |
| 686 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; | 686 gpu::MailboxHolder mailbox_holders[VideoFrame::kMaxPlanes]; |
| 687 for (size_t i = 0; i < VideoFrame::kMaxPlanes; i++) { | 687 for (size_t i = 0; i < VideoFrame::kMaxPlanes; i++) { |
| 688 mailbox_holders[i] = gpu::MailboxHolder( | 688 mailbox_holders[i] = gpu::MailboxHolder( |
| 689 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB); | 689 gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_RECTANGLE_ARB); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 EXPECT_EQ(expected_value, data[(i + j * width)]); | 803 EXPECT_EQ(expected_value, data[(i + j * width)]); |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 }); | 806 }); |
| 807 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), | 807 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), |
| 808 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, | 808 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, |
| 809 1 /*yoffset*/, false /*flip_y*/, true); | 809 1 /*yoffset*/, false /*flip_y*/, true); |
| 810 } | 810 } |
| 811 | 811 |
| 812 } // namespace media | 812 } // namespace media |
| OLD | NEW |