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

Side by Side Diff: media/renderers/skcanvas_video_renderer_unittest.cc

Issue 2792133002: Paint: remove readPixels. (Closed)
Patch Set: update Created 3 years, 8 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 | « cc/paint/skia_paint_canvas.cc ('k') | ui/gfx/canvas.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 <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 15 matching lines...) Expand all
26 #include "ui/gfx/geometry/rect_f.h" 26 #include "ui/gfx/geometry/rect_f.h"
27 27
28 using media::VideoFrame; 28 using media::VideoFrame;
29 29
30 namespace media { 30 namespace media {
31 31
32 static const int kWidth = 320; 32 static const int kWidth = 320;
33 static const int kHeight = 240; 33 static const int kHeight = 240;
34 static const gfx::RectF kNaturalRect(kWidth, kHeight); 34 static const gfx::RectF kNaturalRect(kWidth, kHeight);
35 35
36 // Helper for filling a |canvas| with a solid |color|.
37 void FillCanvas(cc::PaintCanvas* canvas, SkColor color) {
38 canvas->clear(color);
39 }
40
41 // Helper for returning the color of a solid |canvas|.
42 SkColor GetColorAt(cc::PaintCanvas* canvas, int x, int y) {
43 SkBitmap bitmap;
44 if (!bitmap.tryAllocN32Pixels(1, 1))
45 return 0;
46 if (!canvas->readPixels(&bitmap, x, y))
47 return 0;
48 return bitmap.getColor(0, 0);
49 }
50
51 SkColor GetColor(cc::PaintCanvas* canvas) {
52 return GetColorAt(canvas, 0, 0);
53 }
54
55 // Generate frame pixels to provided |external_memory| and wrap it as frame. 36 // Generate frame pixels to provided |external_memory| and wrap it as frame.
56 scoped_refptr<VideoFrame> CreateTestY16Frame(const gfx::Size& coded_size, 37 scoped_refptr<VideoFrame> CreateTestY16Frame(const gfx::Size& coded_size,
57 const gfx::Rect& visible_rect, 38 const gfx::Rect& visible_rect,
58 void* external_memory, 39 void* external_memory,
59 base::TimeDelta timestamp) { 40 base::TimeDelta timestamp) {
60 const int offset_x = visible_rect.x(); 41 const int offset_x = visible_rect.x();
61 const int offset_y = visible_rect.y(); 42 const int offset_y = visible_rect.y();
62 const int stride = coded_size.width(); 43 const int stride = coded_size.width();
63 const size_t byte_size = stride * coded_size.height() * 2; 44 const size_t byte_size = stride * coded_size.height() * 2;
64 45
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 cc::PaintCanvas* canvas); 89 cc::PaintCanvas* canvas);
109 90
110 // Getters for various frame sizes. 91 // Getters for various frame sizes.
111 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; } 92 scoped_refptr<VideoFrame> natural_frame() { return natural_frame_; }
112 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; } 93 scoped_refptr<VideoFrame> larger_frame() { return larger_frame_; }
113 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; } 94 scoped_refptr<VideoFrame> smaller_frame() { return smaller_frame_; }
114 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; } 95 scoped_refptr<VideoFrame> cropped_frame() { return cropped_frame_; }
115 96
116 // Standard canvas. 97 // Standard canvas.
117 cc::PaintCanvas* target_canvas() { return &target_canvas_; } 98 cc::PaintCanvas* target_canvas() { return &target_canvas_; }
99 SkBitmap* bitmap() { return &bitmap_; }
118 100
119 protected: 101 protected:
120 SkCanvasVideoRenderer renderer_; 102 SkCanvasVideoRenderer renderer_;
121 103
122 scoped_refptr<VideoFrame> natural_frame_; 104 scoped_refptr<VideoFrame> natural_frame_;
123 scoped_refptr<VideoFrame> larger_frame_; 105 scoped_refptr<VideoFrame> larger_frame_;
124 scoped_refptr<VideoFrame> smaller_frame_; 106 scoped_refptr<VideoFrame> smaller_frame_;
125 scoped_refptr<VideoFrame> cropped_frame_; 107 scoped_refptr<VideoFrame> cropped_frame_;
126 108
109 SkBitmap bitmap_;
127 cc::SkiaPaintCanvas target_canvas_; 110 cc::SkiaPaintCanvas target_canvas_;
128 base::MessageLoop message_loop_; 111 base::MessageLoop message_loop_;
129 112
130 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRendererTest); 113 DISALLOW_COPY_AND_ASSIGN(SkCanvasVideoRendererTest);
131 }; 114 };
132 115
133 static SkBitmap AllocBitmap(int width, int height) { 116 static SkBitmap AllocBitmap(int width, int height) {
134 SkBitmap bitmap; 117 SkBitmap bitmap;
135 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); 118 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
136 bitmap.eraseColor(0); 119 bitmap.eraseColor(0);
137 return bitmap; 120 return bitmap;
138 } 121 }
139 122
140 SkCanvasVideoRendererTest::SkCanvasVideoRendererTest() 123 SkCanvasVideoRendererTest::SkCanvasVideoRendererTest()
141 : natural_frame_(VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight))), 124 : natural_frame_(VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight))),
142 larger_frame_( 125 larger_frame_(
143 VideoFrame::CreateBlackFrame(gfx::Size(kWidth * 2, kHeight * 2))), 126 VideoFrame::CreateBlackFrame(gfx::Size(kWidth * 2, kHeight * 2))),
144 smaller_frame_( 127 smaller_frame_(
145 VideoFrame::CreateBlackFrame(gfx::Size(kWidth / 2, kHeight / 2))), 128 VideoFrame::CreateBlackFrame(gfx::Size(kWidth / 2, kHeight / 2))),
146 cropped_frame_( 129 cropped_frame_(
147 VideoFrame::CreateFrame(PIXEL_FORMAT_YV12, 130 VideoFrame::CreateFrame(PIXEL_FORMAT_YV12,
148 gfx::Size(16, 16), 131 gfx::Size(16, 16),
149 gfx::Rect(6, 6, 8, 6), 132 gfx::Rect(6, 6, 8, 6),
150 gfx::Size(8, 6), 133 gfx::Size(8, 6),
151 base::TimeDelta::FromMilliseconds(4))), 134 base::TimeDelta::FromMilliseconds(4))),
152 target_canvas_(AllocBitmap(kWidth, kHeight)) { 135 bitmap_(AllocBitmap(kWidth, kHeight)),
136 target_canvas_(bitmap_) {
153 // Give each frame a unique timestamp. 137 // Give each frame a unique timestamp.
154 natural_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(1)); 138 natural_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(1));
155 larger_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(2)); 139 larger_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(2));
156 smaller_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(3)); 140 smaller_frame_->set_timestamp(base::TimeDelta::FromMilliseconds(3));
157 141
158 // Make sure the cropped video frame's aspect ratio matches the output device. 142 // Make sure the cropped video frame's aspect ratio matches the output device.
159 // Update cropped_frame_'s crop dimensions if this is not the case. 143 // Update cropped_frame_'s crop dimensions if this is not the case.
160 EXPECT_EQ(cropped_frame()->visible_rect().width() * kHeight, 144 EXPECT_EQ(cropped_frame()->visible_rect().width() * kHeight,
161 cropped_frame()->visible_rect().height() * kWidth); 145 cropped_frame()->visible_rect().height() * kWidth);
162 146
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 263 }
280 264
281 void SkCanvasVideoRendererTest::Copy( 265 void SkCanvasVideoRendererTest::Copy(
282 const scoped_refptr<VideoFrame>& video_frame, 266 const scoped_refptr<VideoFrame>& video_frame,
283 cc::PaintCanvas* canvas) { 267 cc::PaintCanvas* canvas) {
284 renderer_.Copy(video_frame, canvas, Context3D()); 268 renderer_.Copy(video_frame, canvas, Context3D());
285 } 269 }
286 270
287 TEST_F(SkCanvasVideoRendererTest, NoFrame) { 271 TEST_F(SkCanvasVideoRendererTest, NoFrame) {
288 // Test that black gets painted over canvas. 272 // Test that black gets painted over canvas.
289 FillCanvas(target_canvas(), SK_ColorRED); 273 target_canvas()->clear(SK_ColorRED);
290 PaintWithoutFrame(target_canvas()); 274 PaintWithoutFrame(target_canvas());
291 EXPECT_EQ(SK_ColorBLACK, GetColor(target_canvas())); 275 EXPECT_EQ(SK_ColorBLACK, bitmap()->getColor(0, 0));
292 } 276 }
293 277
294 TEST_F(SkCanvasVideoRendererTest, TransparentFrame) { 278 TEST_F(SkCanvasVideoRendererTest, TransparentFrame) {
295 FillCanvas(target_canvas(), SK_ColorRED); 279 target_canvas()->clear(SK_ColorRED);
296 PaintRotated( 280 PaintRotated(
297 VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(), 281 VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(),
298 target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrcOver, 282 target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrcOver,
299 VIDEO_ROTATION_0); 283 VIDEO_ROTATION_0);
300 EXPECT_EQ(static_cast<SkColor>(SK_ColorRED), GetColor(target_canvas())); 284 EXPECT_EQ(static_cast<SkColor>(SK_ColorRED), bitmap()->getColor(0, 0));
301 } 285 }
302 286
303 TEST_F(SkCanvasVideoRendererTest, TransparentFrameSrcMode) { 287 TEST_F(SkCanvasVideoRendererTest, TransparentFrameSrcMode) {
304 FillCanvas(target_canvas(), SK_ColorRED); 288 target_canvas()->clear(SK_ColorRED);
305 // SRC mode completely overwrites the buffer. 289 // SRC mode completely overwrites the buffer.
306 PaintRotated( 290 PaintRotated(
307 VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(), 291 VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(),
308 target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrc, 292 target_canvas(), kNaturalRect, kNone, SkBlendMode::kSrc,
309 VIDEO_ROTATION_0); 293 VIDEO_ROTATION_0);
310 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), 294 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT),
311 GetColor(target_canvas())); 295 bitmap()->getColor(0, 0));
312 } 296 }
313 297
314 TEST_F(SkCanvasVideoRendererTest, CopyTransparentFrame) { 298 TEST_F(SkCanvasVideoRendererTest, CopyTransparentFrame) {
315 FillCanvas(target_canvas(), SK_ColorRED); 299 target_canvas()->clear(SK_ColorRED);
316 Copy(VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(), 300 Copy(VideoFrame::CreateTransparentFrame(gfx::Size(kWidth, kHeight)).get(),
317 target_canvas()); 301 target_canvas());
318 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), 302 EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT),
319 GetColor(target_canvas())); 303 bitmap()->getColor(0, 0));
320 } 304 }
321 305
322 TEST_F(SkCanvasVideoRendererTest, Natural) { 306 TEST_F(SkCanvasVideoRendererTest, Natural) {
323 Paint(natural_frame(), target_canvas(), kRed); 307 Paint(natural_frame(), target_canvas(), kRed);
324 EXPECT_EQ(SK_ColorRED, GetColor(target_canvas())); 308 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(0, 0));
325 } 309 }
326 310
327 TEST_F(SkCanvasVideoRendererTest, Larger) { 311 TEST_F(SkCanvasVideoRendererTest, Larger) {
328 Paint(natural_frame(), target_canvas(), kRed); 312 Paint(natural_frame(), target_canvas(), kRed);
329 EXPECT_EQ(SK_ColorRED, GetColor(target_canvas())); 313 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(0, 0));
330 314
331 Paint(larger_frame(), target_canvas(), kBlue); 315 Paint(larger_frame(), target_canvas(), kBlue);
332 EXPECT_EQ(SK_ColorBLUE, GetColor(target_canvas())); 316 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(0, 0));
333 } 317 }
334 318
335 TEST_F(SkCanvasVideoRendererTest, Smaller) { 319 TEST_F(SkCanvasVideoRendererTest, Smaller) {
336 Paint(natural_frame(), target_canvas(), kRed); 320 Paint(natural_frame(), target_canvas(), kRed);
337 EXPECT_EQ(SK_ColorRED, GetColor(target_canvas())); 321 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(0, 0));
338 322
339 Paint(smaller_frame(), target_canvas(), kBlue); 323 Paint(smaller_frame(), target_canvas(), kBlue);
340 EXPECT_EQ(SK_ColorBLUE, GetColor(target_canvas())); 324 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(0, 0));
341 } 325 }
342 326
343 TEST_F(SkCanvasVideoRendererTest, NoTimestamp) { 327 TEST_F(SkCanvasVideoRendererTest, NoTimestamp) {
344 VideoFrame* video_frame = natural_frame().get(); 328 VideoFrame* video_frame = natural_frame().get();
345 video_frame->set_timestamp(media::kNoTimestamp); 329 video_frame->set_timestamp(media::kNoTimestamp);
346 Paint(video_frame, target_canvas(), kRed); 330 Paint(video_frame, target_canvas(), kRed);
347 EXPECT_EQ(SK_ColorRED, GetColor(target_canvas())); 331 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(0, 0));
348 } 332 }
349 333
350 TEST_F(SkCanvasVideoRendererTest, CroppedFrame) { 334 TEST_F(SkCanvasVideoRendererTest, CroppedFrame) {
351 Paint(cropped_frame(), target_canvas(), kNone); 335 Paint(cropped_frame(), target_canvas(), kNone);
352 // Check the corners. 336 // Check the corners.
353 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), 0, 0)); 337 EXPECT_EQ(SK_ColorBLACK, bitmap()->getColor(0, 0));
354 EXPECT_EQ(SK_ColorRED, GetColorAt(target_canvas(), kWidth - 1, 0)); 338 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(kWidth - 1, 0));
355 EXPECT_EQ(SK_ColorGREEN, GetColorAt(target_canvas(), 0, kHeight - 1)); 339 EXPECT_EQ(SK_ColorGREEN, bitmap()->getColor(0, kHeight - 1));
356 EXPECT_EQ(SK_ColorBLUE, GetColorAt(target_canvas(), kWidth - 1, kHeight - 1)); 340 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(kWidth - 1, kHeight - 1));
357 // Check the interior along the border between color regions. Note that we're 341 // Check the interior along the border between color regions. Note that we're
358 // bilinearly upscaling, so we'll need to take care to pick sample points that 342 // bilinearly upscaling, so we'll need to take care to pick sample points that
359 // are just outside the "zone of resampling". 343 // are just outside the "zone of resampling".
360 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, 344 EXPECT_EQ(SK_ColorBLACK,
361 kHeight * 1 / 6 - 1)); 345 bitmap()->getColor(kWidth * 1 / 8 - 1, kHeight * 1 / 6 - 1));
362 EXPECT_EQ(SK_ColorRED, 346 EXPECT_EQ(SK_ColorRED,
363 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1)); 347 bitmap()->getColor(kWidth * 3 / 8, kHeight * 1 / 6 - 1));
364 EXPECT_EQ(SK_ColorGREEN, 348 EXPECT_EQ(SK_ColorGREEN,
365 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6)); 349 bitmap()->getColor(kWidth * 1 / 8 - 1, kHeight * 3 / 6));
366 EXPECT_EQ(SK_ColorBLUE, 350 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(kWidth * 3 / 8, kHeight * 3 / 6));
367 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6));
368 } 351 }
369 352
370 TEST_F(SkCanvasVideoRendererTest, CroppedFrame_NoScaling) { 353 TEST_F(SkCanvasVideoRendererTest, CroppedFrame_NoScaling) {
371 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 354 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
355 cc::SkiaPaintCanvas canvas(bitmap);
372 const gfx::Rect crop_rect = cropped_frame()->visible_rect(); 356 const gfx::Rect crop_rect = cropped_frame()->visible_rect();
373 357
374 // Force painting to a non-zero position on the destination bitmap, to check 358 // Force painting to a non-zero position on the destination bitmap, to check
375 // if the coordinates are calculated properly. 359 // if the coordinates are calculated properly.
376 const int offset_x = 10; 360 const int offset_x = 10;
377 const int offset_y = 15; 361 const int offset_y = 15;
378 canvas.translate(offset_x, offset_y); 362 canvas.translate(offset_x, offset_y);
379 363
380 // Create a destination canvas with dimensions and scale which would not 364 // Create a destination canvas with dimensions and scale which would not
381 // cause scaling. 365 // cause scaling.
382 canvas.scale(static_cast<SkScalar>(crop_rect.width()) / kWidth, 366 canvas.scale(static_cast<SkScalar>(crop_rect.width()) / kWidth,
383 static_cast<SkScalar>(crop_rect.height()) / kHeight); 367 static_cast<SkScalar>(crop_rect.height()) / kHeight);
384 368
385 Paint(cropped_frame(), &canvas, kNone); 369 Paint(cropped_frame(), &canvas, kNone);
386 370
387 // Check the corners. 371 // Check the corners.
388 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, offset_x, offset_y)); 372 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(offset_x, offset_y));
389 EXPECT_EQ(SK_ColorRED, 373 EXPECT_EQ(SK_ColorRED,
390 GetColorAt(&canvas, offset_x + crop_rect.width() - 1, offset_y)); 374 bitmap.getColor(offset_x + crop_rect.width() - 1, offset_y));
391 EXPECT_EQ(SK_ColorGREEN, 375 EXPECT_EQ(SK_ColorGREEN,
392 GetColorAt(&canvas, offset_x, offset_y + crop_rect.height() - 1)); 376 bitmap.getColor(offset_x, offset_y + crop_rect.height() - 1));
393 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, offset_x + crop_rect.width() - 1, 377 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(offset_x + crop_rect.width() - 1,
394 offset_y + crop_rect.height() - 1)); 378 offset_y + crop_rect.height() - 1));
395 } 379 }
396 380
397 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_90) { 381 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_90) {
398 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 382 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
383 cc::SkiaPaintCanvas canvas(bitmap);
399 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, 384 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
400 SkBlendMode::kSrcOver, VIDEO_ROTATION_90); 385 SkBlendMode::kSrcOver, VIDEO_ROTATION_90);
401 // Check the corners. 386 // Check the corners.
402 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, 0, 0)); 387 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0));
403 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, 0)); 388 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth - 1, 0));
404 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 389 EXPECT_EQ(SK_ColorRED, bitmap.getColor(kWidth - 1, kHeight - 1));
405 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, kHeight - 1)); 390 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(0, kHeight - 1));
406 } 391 }
407 392
408 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_180) { 393 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_180) {
409 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 394 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
395 cc::SkiaPaintCanvas canvas(bitmap);
410 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, 396 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
411 SkBlendMode::kSrcOver, VIDEO_ROTATION_180); 397 SkBlendMode::kSrcOver, VIDEO_ROTATION_180);
412 // Check the corners. 398 // Check the corners.
413 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, 0, 0)); 399 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(0, 0));
414 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, 0)); 400 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth - 1, 0));
415 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 401 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth - 1, kHeight - 1));
416 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, kHeight - 1)); 402 EXPECT_EQ(SK_ColorRED, bitmap.getColor(0, kHeight - 1));
417 } 403 }
418 404
419 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_270) { 405 TEST_F(SkCanvasVideoRendererTest, Video_Rotation_270) {
420 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 406 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
407 cc::SkiaPaintCanvas canvas(bitmap);
421 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone, 408 PaintRotated(cropped_frame(), &canvas, kNaturalRect, kNone,
422 SkBlendMode::kSrcOver, VIDEO_ROTATION_270); 409 SkBlendMode::kSrcOver, VIDEO_ROTATION_270);
423 // Check the corners. 410 // Check the corners.
424 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, 0, 0)); 411 EXPECT_EQ(SK_ColorRED, bitmap.getColor(0, 0));
425 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, 0)); 412 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth - 1, 0));
426 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 413 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth - 1, kHeight - 1));
427 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, 0, kHeight - 1)); 414 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(0, kHeight - 1));
428 } 415 }
429 416
430 TEST_F(SkCanvasVideoRendererTest, Video_Translate) { 417 TEST_F(SkCanvasVideoRendererTest, Video_Translate) {
431 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 418 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
432 FillCanvas(&canvas, SK_ColorMAGENTA); 419 cc::SkiaPaintCanvas canvas(bitmap);
420 canvas.clear(SK_ColorMAGENTA);
433 421
434 PaintRotated(cropped_frame(), &canvas, 422 PaintRotated(cropped_frame(), &canvas,
435 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), 423 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
436 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_0); 424 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_0);
437 // Check the corners of quadrant 2 and 4. 425 // Check the corners of quadrant 2 and 4.
438 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); 426 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
439 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 427 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
440 EXPECT_EQ(SK_ColorMAGENTA, 428 EXPECT_EQ(SK_ColorMAGENTA,
441 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 429 bitmap.getColor((kWidth / 2) - 1, (kHeight / 2) - 1));
442 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 430 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, (kHeight / 2) - 1));
443 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 431 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth / 2, kHeight / 2));
444 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 432 EXPECT_EQ(SK_ColorRED, bitmap.getColor(kWidth - 1, kHeight / 2));
445 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 433 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth - 1, kHeight - 1));
446 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 434 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth / 2, kHeight - 1));
447 } 435 }
448 436
449 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_90) { 437 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_90) {
450 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 438 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
451 FillCanvas(&canvas, SK_ColorMAGENTA); 439 cc::SkiaPaintCanvas canvas(bitmap);
440 canvas.clear(SK_ColorMAGENTA);
452 441
453 PaintRotated(cropped_frame(), &canvas, 442 PaintRotated(cropped_frame(), &canvas,
454 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), 443 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
455 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_90); 444 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_90);
456 // Check the corners of quadrant 2 and 4. 445 // Check the corners of quadrant 2 and 4.
457 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); 446 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
458 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 447 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
459 EXPECT_EQ(SK_ColorMAGENTA, 448 EXPECT_EQ(SK_ColorMAGENTA,
460 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 449 bitmap.getColor((kWidth / 2) - 1, (kHeight / 2) - 1));
461 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 450 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, (kHeight / 2) - 1));
462 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 451 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth / 2, kHeight / 2));
463 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 452 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth - 1, kHeight / 2));
464 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 453 EXPECT_EQ(SK_ColorRED, bitmap.getColor(kWidth - 1, kHeight - 1));
465 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 454 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth / 2, kHeight - 1));
466 } 455 }
467 456
468 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_180) { 457 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_180) {
469 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 458 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
470 FillCanvas(&canvas, SK_ColorMAGENTA); 459 cc::SkiaPaintCanvas canvas(bitmap);
460 canvas.clear(SK_ColorMAGENTA);
471 461
472 PaintRotated(cropped_frame(), &canvas, 462 PaintRotated(cropped_frame(), &canvas,
473 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), 463 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
474 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_180); 464 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_180);
475 // Check the corners of quadrant 2 and 4. 465 // Check the corners of quadrant 2 and 4.
476 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); 466 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
477 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 467 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
478 EXPECT_EQ(SK_ColorMAGENTA, 468 EXPECT_EQ(SK_ColorMAGENTA,
479 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 469 bitmap.getColor((kWidth / 2) - 1, (kHeight / 2) - 1));
480 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 470 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, (kHeight / 2) - 1));
481 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 471 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth / 2, kHeight / 2));
482 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 472 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth - 1, kHeight / 2));
483 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 473 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth - 1, kHeight - 1));
484 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 474 EXPECT_EQ(SK_ColorRED, bitmap.getColor(kWidth / 2, kHeight - 1));
485 } 475 }
486 476
487 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_270) { 477 TEST_F(SkCanvasVideoRendererTest, Video_Translate_Rotation_270) {
488 cc::SkiaPaintCanvas canvas(AllocBitmap(kWidth, kHeight)); 478 SkBitmap bitmap = AllocBitmap(kWidth, kHeight);
489 FillCanvas(&canvas, SK_ColorMAGENTA); 479 cc::SkiaPaintCanvas canvas(bitmap);
480 canvas.clear(SK_ColorMAGENTA);
490 481
491 PaintRotated(cropped_frame(), &canvas, 482 PaintRotated(cropped_frame(), &canvas,
492 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), 483 gfx::RectF(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
493 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_270); 484 kNone, SkBlendMode::kSrcOver, VIDEO_ROTATION_270);
494 // Check the corners of quadrant 2 and 4. 485 // Check the corners of quadrant 2 and 4.
495 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, 0)); 486 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, 0));
496 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, (kWidth / 2) - 1, 0)); 487 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor((kWidth / 2) - 1, 0));
497 EXPECT_EQ(SK_ColorMAGENTA, 488 EXPECT_EQ(SK_ColorMAGENTA,
498 GetColorAt(&canvas, (kWidth / 2) - 1, (kHeight / 2) - 1)); 489 bitmap.getColor((kWidth / 2) - 1, (kHeight / 2) - 1));
499 EXPECT_EQ(SK_ColorMAGENTA, GetColorAt(&canvas, 0, (kHeight / 2) - 1)); 490 EXPECT_EQ(SK_ColorMAGENTA, bitmap.getColor(0, (kHeight / 2) - 1));
500 EXPECT_EQ(SK_ColorRED, GetColorAt(&canvas, kWidth / 2, kHeight / 2)); 491 EXPECT_EQ(SK_ColorRED, bitmap.getColor(kWidth / 2, kHeight / 2));
501 EXPECT_EQ(SK_ColorBLUE, GetColorAt(&canvas, kWidth - 1, kHeight / 2)); 492 EXPECT_EQ(SK_ColorBLUE, bitmap.getColor(kWidth - 1, kHeight / 2));
502 EXPECT_EQ(SK_ColorGREEN, GetColorAt(&canvas, kWidth - 1, kHeight - 1)); 493 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(kWidth - 1, kHeight - 1));
503 EXPECT_EQ(SK_ColorBLACK, GetColorAt(&canvas, kWidth / 2, kHeight - 1)); 494 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(kWidth / 2, kHeight - 1));
504 } 495 }
505 496
506 TEST_F(SkCanvasVideoRendererTest, HighBits) { 497 TEST_F(SkCanvasVideoRendererTest, HighBits) {
507 // Copy cropped_frame into a highbit frame. 498 // Copy cropped_frame into a highbit frame.
508 scoped_refptr<VideoFrame> frame(VideoFrame::CreateFrame( 499 scoped_refptr<VideoFrame> frame(VideoFrame::CreateFrame(
509 PIXEL_FORMAT_YUV420P10, cropped_frame()->coded_size(), 500 PIXEL_FORMAT_YUV420P10, cropped_frame()->coded_size(),
510 cropped_frame()->visible_rect(), cropped_frame()->natural_size(), 501 cropped_frame()->visible_rect(), cropped_frame()->natural_size(),
511 cropped_frame()->timestamp())); 502 cropped_frame()->timestamp()));
512 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; ++plane) { 503 for (int plane = VideoFrame::kYPlane; plane <= VideoFrame::kVPlane; ++plane) {
513 int width = cropped_frame()->row_bytes(plane); 504 int width = cropped_frame()->row_bytes(plane);
514 uint16_t* dst = reinterpret_cast<uint16_t*>(frame->data(plane)); 505 uint16_t* dst = reinterpret_cast<uint16_t*>(frame->data(plane));
515 uint8_t* src = cropped_frame()->data(plane); 506 uint8_t* src = cropped_frame()->data(plane);
516 for (int row = 0; row < cropped_frame()->rows(plane); row++) { 507 for (int row = 0; row < cropped_frame()->rows(plane); row++) {
517 for (int col = 0; col < width; col++) { 508 for (int col = 0; col < width; col++) {
518 dst[col] = src[col] << 2; 509 dst[col] = src[col] << 2;
519 } 510 }
520 src += cropped_frame()->stride(plane); 511 src += cropped_frame()->stride(plane);
521 dst += frame->stride(plane) / 2; 512 dst += frame->stride(plane) / 2;
522 } 513 }
523 } 514 }
524 515
525 Paint(frame, target_canvas(), kNone); 516 Paint(frame, target_canvas(), kNone);
526 // Check the corners. 517 // Check the corners.
527 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), 0, 0)); 518 EXPECT_EQ(SK_ColorBLACK, bitmap()->getColor(0, 0));
528 EXPECT_EQ(SK_ColorRED, GetColorAt(target_canvas(), kWidth - 1, 0)); 519 EXPECT_EQ(SK_ColorRED, bitmap()->getColor(kWidth - 1, 0));
529 EXPECT_EQ(SK_ColorGREEN, GetColorAt(target_canvas(), 0, kHeight - 1)); 520 EXPECT_EQ(SK_ColorGREEN, bitmap()->getColor(0, kHeight - 1));
530 EXPECT_EQ(SK_ColorBLUE, GetColorAt(target_canvas(), kWidth - 1, kHeight - 1)); 521 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(kWidth - 1, kHeight - 1));
531 // Check the interior along the border between color regions. Note that we're 522 // Check the interior along the border between color regions. Note that we're
532 // bilinearly upscaling, so we'll need to take care to pick sample points that 523 // bilinearly upscaling, so we'll need to take care to pick sample points that
533 // are just outside the "zone of resampling". 524 // are just outside the "zone of resampling".
534 EXPECT_EQ(SK_ColorBLACK, GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, 525 EXPECT_EQ(SK_ColorBLACK,
535 kHeight * 1 / 6 - 1)); 526 bitmap()->getColor(kWidth * 1 / 8 - 1, kHeight * 1 / 6 - 1));
536 EXPECT_EQ(SK_ColorRED, 527 EXPECT_EQ(SK_ColorRED,
537 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 1 / 6 - 1)); 528 bitmap()->getColor(kWidth * 3 / 8, kHeight * 1 / 6 - 1));
538 EXPECT_EQ(SK_ColorGREEN, 529 EXPECT_EQ(SK_ColorGREEN,
539 GetColorAt(target_canvas(), kWidth * 1 / 8 - 1, kHeight * 3 / 6)); 530 bitmap()->getColor(kWidth * 1 / 8 - 1, kHeight * 3 / 6));
540 EXPECT_EQ(SK_ColorBLUE, 531 EXPECT_EQ(SK_ColorBLUE, bitmap()->getColor(kWidth * 3 / 8, kHeight * 3 / 6));
541 GetColorAt(target_canvas(), kWidth * 3 / 8, kHeight * 3 / 6));
542 } 532 }
543 533
544 TEST_F(SkCanvasVideoRendererTest, Y16) { 534 TEST_F(SkCanvasVideoRendererTest, Y16) {
545 SkBitmap bitmap; 535 SkBitmap bitmap;
546 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType)); 536 bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType));
547 537
548 // |offset_x| and |offset_y| define visible rect's offset to coded rect. 538 // |offset_x| and |offset_y| define visible rect's offset to coded rect.
549 const int offset_x = 3; 539 const int offset_x = 3;
550 const int offset_y = 5; 540 const int offset_y = 5;
551 const int stride = bitmap.width() + offset_x; 541 const int stride = bitmap.width() + offset_x;
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 EXPECT_EQ(expected_value, data[(i + j * width)]); 793 EXPECT_EQ(expected_value, data[(i + j * width)]);
804 } 794 }
805 } 795 }
806 }); 796 });
807 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(), 797 SkCanvasVideoRenderer::TexSubImage2D(GL_TEXTURE_2D, &gles2, video_frame.get(),
808 0, GL_RED, GL_FLOAT, 2 /*xoffset*/, 798 0, GL_RED, GL_FLOAT, 2 /*xoffset*/,
809 1 /*yoffset*/, false /*flip_y*/, true); 799 1 /*yoffset*/, false /*flip_y*/, true);
810 } 800 }
811 801
812 } // namespace media 802 } // namespace media
OLDNEW
« no previous file with comments | « cc/paint/skia_paint_canvas.cc ('k') | ui/gfx/canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698