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

Side by Side Diff: cc/draw_quad_unittest.cc

Issue 11783094: cc: Add point-based UV coordinate on TextureLayer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | cc/gl_renderer.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/draw_quad.h" 5 #include "cc/draw_quad.h"
6 6
7 #include "cc/checkerboard_draw_quad.h" 7 #include "cc/checkerboard_draw_quad.h"
8 #include "cc/debug_border_draw_quad.h" 8 #include "cc/debug_border_draw_quad.h"
9 #include "cc/io_surface_draw_quad.h" 9 #include "cc/io_surface_draw_quad.h"
10 #include "cc/math_util.h" 10 #include "cc/math_util.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copyQuad->material); 355 EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copyQuad->material);
356 EXPECT_EQ(textureId, copyQuad->texture_id); 356 EXPECT_EQ(textureId, copyQuad->texture_id);
357 EXPECT_EQ(matrix, copyQuad->matrix); 357 EXPECT_EQ(matrix, copyQuad->matrix);
358 } 358 }
359 359
360 TEST(DrawQuadTest, copyTextureDrawQuad) 360 TEST(DrawQuadTest, copyTextureDrawQuad)
361 { 361 {
362 gfx::Rect opaqueRect(3, 7, 10, 12); 362 gfx::Rect opaqueRect(3, 7, 10, 12);
363 unsigned resourceId = 82; 363 unsigned resourceId = 82;
364 bool premultipliedAlpha = true; 364 bool premultipliedAlpha = true;
365 gfx::RectF uvRect(0.5f, 224.f, 51.f, 36.f); 365 gfx::PointF uvTopLeft(0.5f, 224.f);
366 gfx::PointF uvBottomRight(51.5f, 260.f);
366 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; 367 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
367 bool flipped = true; 368 bool flipped = true;
368 CREATE_SHARED_STATE(); 369 CREATE_SHARED_STATE();
369 370
370 CREATE_QUAD_6_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlph a, uvRect, vertex_opacity, flipped); 371 CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlph a, uvTopLeft, uvBottomRight, vertex_opacity, flipped);
371 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material); 372 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material);
372 EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect); 373 EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect);
373 EXPECT_EQ(resourceId, copyQuad->resource_id); 374 EXPECT_EQ(resourceId, copyQuad->resource_id);
374 EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha); 375 EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha);
375 EXPECT_FLOAT_RECT_EQ(uvRect, copyQuad->uv_rect); 376 EXPECT_EQ(uvTopLeft, copyQuad->uv_top_left);
377 EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right);
376 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); 378 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4);
377 EXPECT_EQ(flipped, copyQuad->flipped); 379 EXPECT_EQ(flipped, copyQuad->flipped);
378 380
379 CREATE_QUAD_5_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvRect, v ertex_opacity, flipped); 381 CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft , uvBottomRight, vertex_opacity, flipped);
380 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material); 382 EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material);
381 EXPECT_EQ(resourceId, copyQuad->resource_id); 383 EXPECT_EQ(resourceId, copyQuad->resource_id);
382 EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha); 384 EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha);
383 EXPECT_FLOAT_RECT_EQ(uvRect, copyQuad->uv_rect); 385 EXPECT_EQ(uvTopLeft, copyQuad->uv_top_left);
386 EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right);
384 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); 387 EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4);
385 EXPECT_EQ(flipped, copyQuad->flipped); 388 EXPECT_EQ(flipped, copyQuad->flipped);
386 } 389 }
387 390
391 TEST(DrawQuadTest, clipTextureDrawQuad)
392 {
393 gfx::Rect opaqueRect(3, 7, 10, 12);
394 unsigned resourceId = 82;
395 bool premultipliedAlpha = true;
396 bool flipped = true;
397 CREATE_SHARED_STATE();
398 // The original quad position is (30, 40) its size is 50*60.
399 sharedState->content_to_target_transform = gfx::Transform(1.f, 0.f, 0.f, 1.f , 10.f, 20.f);
400 // After transformation, the quad position is (40, 60) its size is 50*60.
401 sharedState->clip_rect = gfx::Rect(50, 70, 30, 20);
402
403 // The original quad is 'ABCD', the clipped quad is 'abcd':
404 //40 50 90
405 // B--:-------C 60
406 // | b----c -|-70
407 // | | | |
408 // | a----d -|-90
409 // | |
410 // A----------D 120
411 // UV and vertex opacity are stored per vertex on the parent rectangle 'ABCD '.
412
413 // This is the UV value for vertex 'B'.
414 gfx::PointF uvTopLeft(0.1f, 0.2f);
415 // This is the UV value for vertex 'D'.
416 gfx::PointF uvBottomRight(0.9f, 0.8f);
417 // This the vertex opacity for the vertices 'ABCD'.
418 const float vertexOpacity[] = {0.3f, 0.4f, 0.7f, 0.8f};
419
420 {
421 CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAl pha, uvTopLeft, uvBottomRight, vertexOpacity, flipped);
422 CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLe ft, uvBottomRight, vertexOpacity, flipped);
423 EXPECT_TRUE(quadAll->PerformClipping());
424
425 // This is the expected UV value for vertex 'b'.
426 // uv(b) = uv(B) + (Bb / BD) * (uv(D) - uv(B))
427 // 0.3 = 0.2 + (10 / 60) * (0.8 - 0.2)
428 gfx::PointF uvTopLeftClipped(0.26f, 0.3f);
429 // This is the expected UV value for vertex 'd'.
430 // uv(d) = uv(B) + (Bd / BD) * (uv(D) - uv(B))
431 gfx::PointF uvBottomRightClipped(0.74f, 0.5f);
432 // This the expected vertex opacity for the vertices 'abcd'.
433 // They are computed with a bilinear interpolation of the corner values.
434 const float vertexOpacityClipped[] = {0.43f, 0.45f, 0.65f, 0.67f};
435
436 EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left);
437 EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right);
438 EXPECT_FLOAT_ARRAY_EQ(vertexOpacityClipped, quadAll->vertex_opacity, 4);
439 }
440
441 uvTopLeft = gfx::PointF(0.8f, 0.7f);
442 uvBottomRight = gfx::PointF(0.2f, 0.1f);
443
444 {
445 CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAl pha, uvTopLeft, uvBottomRight, vertexOpacity, flipped);
446 CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLe ft, uvBottomRight, vertexOpacity, flipped);
447 EXPECT_TRUE(quadAll->PerformClipping());
448
449 // This is the expected UV value for vertex 'b'.
450 gfx::PointF uvTopLeftClipped(0.68f, 0.6f);
451 // This is the expected UV value for vertex 'd'.
452 gfx::PointF uvBottomRightClipped(0.32f, 0.4f);
453
454 EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left);
455 EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right);
456 }
457 }
458
388 TEST(DrawQuadTest, copyTileDrawQuad) 459 TEST(DrawQuadTest, copyTileDrawQuad)
389 { 460 {
390 gfx::Rect opaqueRect(33, 44, 22, 33); 461 gfx::Rect opaqueRect(33, 44, 22, 33);
391 unsigned resourceId = 104; 462 unsigned resourceId = 104;
392 gfx::RectF texCoordRect(31, 12, 54, 20); 463 gfx::RectF texCoordRect(31, 12, 54, 20);
393 gfx::Size textureSize(85, 32); 464 gfx::Size textureSize(85, 32);
394 bool swizzleContents = true; 465 bool swizzleContents = true;
395 bool leftEdgeAA = true; 466 bool leftEdgeAA = true;
396 bool topEdgeAA = true; 467 bool topEdgeAA = true;
397 bool rightEdgeAA = false; 468 bool rightEdgeAA = false;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 EXPECT_EQ(uPlane.resourceId, copyQuad->u_plane.resourceId); 534 EXPECT_EQ(uPlane.resourceId, copyQuad->u_plane.resourceId);
464 EXPECT_EQ(uPlane.size, copyQuad->u_plane.size); 535 EXPECT_EQ(uPlane.size, copyQuad->u_plane.size);
465 EXPECT_EQ(uPlane.format, copyQuad->u_plane.format); 536 EXPECT_EQ(uPlane.format, copyQuad->u_plane.format);
466 EXPECT_EQ(vPlane.resourceId, copyQuad->v_plane.resourceId); 537 EXPECT_EQ(vPlane.resourceId, copyQuad->v_plane.resourceId);
467 EXPECT_EQ(vPlane.size, copyQuad->v_plane.size); 538 EXPECT_EQ(vPlane.size, copyQuad->v_plane.size);
468 EXPECT_EQ(vPlane.format, copyQuad->v_plane.format); 539 EXPECT_EQ(vPlane.format, copyQuad->v_plane.format);
469 } 540 }
470 541
471 } // namespace 542 } // namespace
472 } // namespace cc 543 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/gl_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698