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 #ifndef CC_SURFACES_SURFACE_AGGREGATOR_TEST_HELPERS_H_ 6 #define CC_SURFACES_SURFACE_AGGREGATOR_TEST_HELPERS_H_ 7 8 #include "cc/base/scoped_ptr_vector.h" 9 #include "cc/quads/draw_quad.h" 10 #include "cc/quads/render_pass_id.h" 11 #include "cc/surfaces/surface_id.h" 12 #include "third_party/skia/include/core/SkColor.h" 13 #include "ui/gfx/size.h" 14 15 namespace cc { 16 17 class RenderPass; 18 class Surface; 19 class TestRenderPass; 20 21 typedef ScopedPtrVector<RenderPass> RenderPassList; 22 23 namespace test { 24 25 struct Quad { SolidColorQuadQuad26 static Quad SolidColorQuad(SkColor color) { 27 Quad quad; 28 quad.material = DrawQuad::SOLID_COLOR; 29 quad.color = color; 30 return quad; 31 } 32 SurfaceQuadQuad33 static Quad SurfaceQuad(SurfaceId surface_id) { 34 Quad quad; 35 quad.material = DrawQuad::SURFACE_CONTENT; 36 quad.surface_id = surface_id; 37 return quad; 38 } 39 RenderPassQuadQuad40 static Quad RenderPassQuad(RenderPassId id) { 41 Quad quad; 42 quad.material = DrawQuad::RENDER_PASS; 43 quad.render_pass_id = id; 44 return quad; 45 } 46 47 DrawQuad::Material material; 48 // Set when material==DrawQuad::SURFACE_CONTENT. 49 SurfaceId surface_id; 50 // Set when material==DrawQuad::SOLID_COLOR. 51 SkColor color; 52 // Set when material==DrawQuad::RENDER_PASS. 53 RenderPassId render_pass_id; 54 55 private: QuadQuad56 Quad() 57 : material(DrawQuad::INVALID), 58 color(SK_ColorWHITE), 59 render_pass_id(-1, -1) {} 60 }; 61 62 struct Pass { PassPass63 Pass(Quad* quads, size_t quad_count, RenderPassId id) 64 : quads(quads), quad_count(quad_count), id(id) {} PassPass65 Pass(Quad* quads, size_t quad_count) 66 : quads(quads), quad_count(quad_count), id(1, 1) {} 67 68 Quad* quads; 69 size_t quad_count; 70 RenderPassId id; 71 }; 72 73 void AddSurfaceQuad(TestRenderPass* pass, 74 const gfx::Size& surface_size, 75 int surface_id); 76 77 void AddQuadInPass(TestRenderPass* pass, Quad desc); 78 79 void AddPasses(RenderPassList* pass_list, 80 const gfx::Rect& output_rect, 81 Pass* passes, 82 size_t pass_count); 83 84 void TestQuadMatchesExpectations(Quad expected_quad, const DrawQuad* quad); 85 86 void TestPassMatchesExpectations(Pass expected_pass, const RenderPass* pass); 87 88 void TestPassesMatchExpectations(Pass* expected_passes, 89 size_t expected_pass_count, 90 const RenderPassList* passes); 91 92 } // namespace test 93 } // namespace cc 94 95 #endif // CC_SURFACES_SURFACE_AGGREGATOR_TEST_HELPERS_H_ 96