Chromium Code Reviews| Index: cc/output/overlay_candidates_unittest.cc |
| diff --git a/cc/output/overlay_candidates_unittest.cc b/cc/output/overlay_candidates_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0d2a1c557e131c05598a83cfa631698bb78906b2 |
| --- /dev/null |
| +++ b/cc/output/overlay_candidates_unittest.cc |
| @@ -0,0 +1,154 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/base/scoped_ptr_vector.h" |
| +#include "cc/output/output_surface.h" |
| +#include "cc/output/output_surface_client.h" |
| +#include "cc/output/overlay_candidates.h" |
| +#include "cc/output/overlay_renderer.h" |
| +#include "cc/quads/checkerboard_draw_quad.h" |
| +#include "cc/quads/render_pass.h" |
| +#include "cc/quads/texture_draw_quad.h" |
| +#include "cc/resources/resource_provider.h" |
| +#include "cc/resources/texture_mailbox.h" |
| +#include "cc/test/fake_output_surface_client.h" |
| +#include "cc/test/test_context_provider.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +static const gfx::Rect overlay_rect(0, 0, 128, 128); |
| +static const gfx::PointF uv_top_left(0.1f, 0.2f); |
| +static const gfx::PointF uv_bottom_right(1.0f, 1.0f); |
|
piman
2014/03/14 03:42:34
nit: naming kOverlayRect, etc.
Also, you don't nee
alexst (slow to review)
2014/03/14 19:54:22
Done.
|
| + |
| +void MailboxReleased(unsigned sync_point, bool lost_resource) {} |
| + |
| +class SingleOverlayCandidate : public OverlayCandidates { |
|
enne (OOO)
2014/03/14 18:13:41
This naming is a bit awkward. Singular "FooOverla
|
| + public: |
| + virtual void CheckOverlaySupport( |
| + OverlayCandidates::OverlaySurfaceCandidateList* surfaces) OVERRIDE; |
| +}; |
| + |
| +void SingleOverlayCandidate::CheckOverlaySupport( |
| + OverlayCandidates::OverlaySurfaceCandidateList* surfaces) { |
| + size_t expected_candidates = 2; |
| + EXPECT_EQ(expected_candidates, surfaces->size()); |
| + |
| + OverlayCandidates::OverlaySurfaceCandidate& candidate = surfaces->back(); |
| + EXPECT_EQ(overlay_rect.ToString(), candidate.display_rect.ToString()); |
| + EXPECT_EQ(BoundingRect(uv_top_left, uv_bottom_right).ToString(), |
| + candidate.crop_rect.ToString()); |
| + candidate.overlay_handled = true; |
| +} |
| + |
| +class OverlayOutputSurface : public OutputSurface { |
| + public: |
| + explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider) |
| + : OutputSurface(context_provider) {} |
| + |
| + void InitOverlayCandidates() { |
| + overlay_candidates_.reset(new SingleOverlayCandidate); |
| + } |
| +}; |
| + |
| +gpu::Mailbox MailboxFromChar(char value) { |
| + gpu::Mailbox mailbox; |
| + memset(mailbox.name, value, sizeof(mailbox.name)); |
| + return mailbox; |
| +} |
|
piman
2014/03/14 03:42:34
note: you can use gpu::Mailbox::Generate() now. It
alexst (slow to review)
2014/03/14 19:54:22
Done.
|
| + |
| +TEST(OverlayCandidatesTest, NoOverlaysByDefault) { |
| + scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| + OverlayOutputSurface output_surface(provider); |
| + EXPECT_EQ(nullptr, output_surface.overlay_candidates()); |
|
piman
2014/03/14 03:42:34
nit: we don't (yet) allow nullptr because we still
alexst (slow to review)
2014/03/14 19:54:22
Done.
|
| + |
| + output_surface.InitOverlayCandidates(); |
| + EXPECT_NE(nullptr, output_surface.overlay_candidates()); |
|
piman
2014/03/14 03:42:34
nit: nullptr
alexst (slow to review)
2014/03/14 19:54:22
Done.
|
| +} |
| + |
| +TEST(OverlayCandidatesTest, ResourceTest) { |
|
piman
2014/03/14 03:42:34
This is really an OverlayRenderer test
|
| + scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); |
| + OverlayOutputSurface output_surface(provider); |
| + FakeOutputSurfaceClient client; |
| + EXPECT_TRUE(output_surface.BindToClient(&client)); |
| + output_surface.InitOverlayCandidates(); |
| + EXPECT_NE(nullptr, output_surface.overlay_candidates()); |
| + |
| + scoped_ptr<ResourceProvider> resource_provider( |
| + ResourceProvider::Create(&output_surface, NULL, 0, false, 1)); |
| + |
| + scoped_ptr<OverlayRenderer> overlay_renderer( |
| + new OverlayRenderer(&output_surface, resource_provider.get())); |
| + |
| + RenderPass::Id id(1, 0); |
| + gfx::Rect output_rect(0, 0, 256, 256); |
| + bool has_transparent_background = true; |
| + |
| + scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| + pass->SetAll(id, |
| + output_rect, |
| + output_rect, |
| + gfx::Transform(), |
| + has_transparent_background); |
| + |
| + // Stick a quad in the pass, this should not get copied. |
| + scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); |
| + pass->shared_quad_state_list.push_back(shared_state.Pass()); |
| + |
| + // Add an overlay candidate to the pass. |
| + unsigned sync_point = 0; |
| + TextureMailbox mailbox = |
| + TextureMailbox(MailboxFromChar('a'), GL_TEXTURE_2D, sync_point); |
| + mailbox.set_hw_backed(true); |
| + scoped_ptr<SingleReleaseCallback> release_callback = |
| + SingleReleaseCallback::Create(base::Bind(&MailboxReleased)); |
| + |
| + ResourceProvider::ResourceId resource_id = |
| + resource_provider->CreateResourceFromTextureMailbox( |
| + mailbox, release_callback.Pass()); |
| + bool premultiplied_alpha = false; |
| + bool flipped = false; |
| + float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| + |
| + scoped_ptr<TextureDrawQuad> overlay_quad = TextureDrawQuad::Create(); |
| + overlay_quad->SetNew(pass->shared_quad_state_list.back(), |
| + overlay_rect, |
| + overlay_rect, |
| + overlay_rect, |
| + resource_id, |
| + premultiplied_alpha, |
| + uv_top_left, |
| + uv_bottom_right, |
| + SK_ColorBLACK, |
| + vertex_opacity, |
| + flipped); |
| + |
| + pass->quad_list.push_back(overlay_quad.PassAs<DrawQuad>()); |
| + |
| + // Add something behind it. |
| + scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = |
| + CheckerboardDrawQuad::Create(); |
| + checkerboard_quad->SetNew( |
| + pass->shared_quad_state_list.back(), gfx::Rect(), gfx::Rect(), SkColor()); |
| + pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>()); |
| + |
| + RenderPassList pass_list; |
| + pass_list.push_back(pass.Pass()); |
| + |
| + // Check for potential candidates. |
| + overlay_renderer->ProcessForOverlays(&pass_list); |
| + |
| + // This should have one more pass with an overlay. |
| + size_t expected_pass_count = 2; |
| + EXPECT_EQ(expected_pass_count, pass_list.size()); |
|
piman
2014/03/14 03:42:34
nit: ASSERT_EQ since you will dereference the elem
alexst (slow to review)
2014/03/14 19:54:22
Done.
|
| + |
| + RenderPass* overlay_pass = pass_list.front(); |
| + EXPECT_EQ(RenderPass::SIMPLE_OVERLAY, overlay_pass->overlay_state); |
| + RenderPass* main_pass = pass_list.back(); |
| + EXPECT_EQ(RenderPass::NO_OVERLAY, main_pass->overlay_state); |
| +} |
| + |
| +} // namespace |
| +} // namespace cc |