Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/base/scoped_ptr_vector.h" | |
| 6 #include "cc/output/output_surface.h" | |
| 7 #include "cc/output/output_surface_client.h" | |
| 8 #include "cc/output/overlay_candidates.h" | |
| 9 #include "cc/output/overlay_renderer.h" | |
| 10 #include "cc/quads/checkerboard_draw_quad.h" | |
| 11 #include "cc/quads/render_pass.h" | |
| 12 #include "cc/quads/texture_draw_quad.h" | |
| 13 #include "cc/resources/resource_provider.h" | |
| 14 #include "cc/resources/texture_mailbox.h" | |
| 15 #include "cc/test/fake_output_surface_client.h" | |
| 16 #include "cc/test/test_context_provider.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace cc { | |
| 20 namespace { | |
| 21 | |
| 22 static const gfx::Rect overlay_rect(0, 0, 128, 128); | |
| 23 static const gfx::PointF uv_top_left(0.1f, 0.2f); | |
| 24 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.
| |
| 25 | |
| 26 void MailboxReleased(unsigned sync_point, bool lost_resource) {} | |
| 27 | |
| 28 class SingleOverlayCandidate : public OverlayCandidates { | |
|
enne (OOO)
2014/03/14 18:13:41
This naming is a bit awkward. Singular "FooOverla
| |
| 29 public: | |
| 30 virtual void CheckOverlaySupport( | |
| 31 OverlayCandidates::OverlaySurfaceCandidateList* surfaces) OVERRIDE; | |
| 32 }; | |
| 33 | |
| 34 void SingleOverlayCandidate::CheckOverlaySupport( | |
| 35 OverlayCandidates::OverlaySurfaceCandidateList* surfaces) { | |
| 36 size_t expected_candidates = 2; | |
| 37 EXPECT_EQ(expected_candidates, surfaces->size()); | |
| 38 | |
| 39 OverlayCandidates::OverlaySurfaceCandidate& candidate = surfaces->back(); | |
| 40 EXPECT_EQ(overlay_rect.ToString(), candidate.display_rect.ToString()); | |
| 41 EXPECT_EQ(BoundingRect(uv_top_left, uv_bottom_right).ToString(), | |
| 42 candidate.crop_rect.ToString()); | |
| 43 candidate.overlay_handled = true; | |
| 44 } | |
| 45 | |
| 46 class OverlayOutputSurface : public OutputSurface { | |
| 47 public: | |
| 48 explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider) | |
| 49 : OutputSurface(context_provider) {} | |
| 50 | |
| 51 void InitOverlayCandidates() { | |
| 52 overlay_candidates_.reset(new SingleOverlayCandidate); | |
| 53 } | |
| 54 }; | |
| 55 | |
| 56 gpu::Mailbox MailboxFromChar(char value) { | |
| 57 gpu::Mailbox mailbox; | |
| 58 memset(mailbox.name, value, sizeof(mailbox.name)); | |
| 59 return mailbox; | |
| 60 } | |
|
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.
| |
| 61 | |
| 62 TEST(OverlayCandidatesTest, NoOverlaysByDefault) { | |
| 63 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); | |
| 64 OverlayOutputSurface output_surface(provider); | |
| 65 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.
| |
| 66 | |
| 67 output_surface.InitOverlayCandidates(); | |
| 68 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.
| |
| 69 } | |
| 70 | |
| 71 TEST(OverlayCandidatesTest, ResourceTest) { | |
|
piman
2014/03/14 03:42:34
This is really an OverlayRenderer test
| |
| 72 scoped_refptr<TestContextProvider> provider = TestContextProvider::Create(); | |
| 73 OverlayOutputSurface output_surface(provider); | |
| 74 FakeOutputSurfaceClient client; | |
| 75 EXPECT_TRUE(output_surface.BindToClient(&client)); | |
| 76 output_surface.InitOverlayCandidates(); | |
| 77 EXPECT_NE(nullptr, output_surface.overlay_candidates()); | |
| 78 | |
| 79 scoped_ptr<ResourceProvider> resource_provider( | |
| 80 ResourceProvider::Create(&output_surface, NULL, 0, false, 1)); | |
| 81 | |
| 82 scoped_ptr<OverlayRenderer> overlay_renderer( | |
| 83 new OverlayRenderer(&output_surface, resource_provider.get())); | |
| 84 | |
| 85 RenderPass::Id id(1, 0); | |
| 86 gfx::Rect output_rect(0, 0, 256, 256); | |
| 87 bool has_transparent_background = true; | |
| 88 | |
| 89 scoped_ptr<RenderPass> pass = RenderPass::Create(); | |
| 90 pass->SetAll(id, | |
| 91 output_rect, | |
| 92 output_rect, | |
| 93 gfx::Transform(), | |
| 94 has_transparent_background); | |
| 95 | |
| 96 // Stick a quad in the pass, this should not get copied. | |
| 97 scoped_ptr<SharedQuadState> shared_state = SharedQuadState::Create(); | |
| 98 pass->shared_quad_state_list.push_back(shared_state.Pass()); | |
| 99 | |
| 100 // Add an overlay candidate to the pass. | |
| 101 unsigned sync_point = 0; | |
| 102 TextureMailbox mailbox = | |
| 103 TextureMailbox(MailboxFromChar('a'), GL_TEXTURE_2D, sync_point); | |
| 104 mailbox.set_hw_backed(true); | |
| 105 scoped_ptr<SingleReleaseCallback> release_callback = | |
| 106 SingleReleaseCallback::Create(base::Bind(&MailboxReleased)); | |
| 107 | |
| 108 ResourceProvider::ResourceId resource_id = | |
| 109 resource_provider->CreateResourceFromTextureMailbox( | |
| 110 mailbox, release_callback.Pass()); | |
| 111 bool premultiplied_alpha = false; | |
| 112 bool flipped = false; | |
| 113 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | |
| 114 | |
| 115 scoped_ptr<TextureDrawQuad> overlay_quad = TextureDrawQuad::Create(); | |
| 116 overlay_quad->SetNew(pass->shared_quad_state_list.back(), | |
| 117 overlay_rect, | |
| 118 overlay_rect, | |
| 119 overlay_rect, | |
| 120 resource_id, | |
| 121 premultiplied_alpha, | |
| 122 uv_top_left, | |
| 123 uv_bottom_right, | |
| 124 SK_ColorBLACK, | |
| 125 vertex_opacity, | |
| 126 flipped); | |
| 127 | |
| 128 pass->quad_list.push_back(overlay_quad.PassAs<DrawQuad>()); | |
| 129 | |
| 130 // Add something behind it. | |
| 131 scoped_ptr<CheckerboardDrawQuad> checkerboard_quad = | |
| 132 CheckerboardDrawQuad::Create(); | |
| 133 checkerboard_quad->SetNew( | |
| 134 pass->shared_quad_state_list.back(), gfx::Rect(), gfx::Rect(), SkColor()); | |
| 135 pass->quad_list.push_back(checkerboard_quad.PassAs<DrawQuad>()); | |
| 136 | |
| 137 RenderPassList pass_list; | |
| 138 pass_list.push_back(pass.Pass()); | |
| 139 | |
| 140 // Check for potential candidates. | |
| 141 overlay_renderer->ProcessForOverlays(&pass_list); | |
| 142 | |
| 143 // This should have one more pass with an overlay. | |
| 144 size_t expected_pass_count = 2; | |
| 145 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.
| |
| 146 | |
| 147 RenderPass* overlay_pass = pass_list.front(); | |
| 148 EXPECT_EQ(RenderPass::SIMPLE_OVERLAY, overlay_pass->overlay_state); | |
| 149 RenderPass* main_pass = pass_list.back(); | |
| 150 EXPECT_EQ(RenderPass::NO_OVERLAY, main_pass->overlay_state); | |
| 151 } | |
| 152 | |
| 153 } // namespace | |
| 154 } // namespace cc | |
| OLD | NEW |