| OLD | NEW |
| 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/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 2143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2154 ContextPurgedWhenRendererBecomesInvisible) { | 2154 ContextPurgedWhenRendererBecomesInvisible) { |
| 2155 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false)); | 2155 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false)); |
| 2156 renderer_->SetVisible(true); | 2156 renderer_->SetVisible(true); |
| 2157 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2157 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 2158 | 2158 |
| 2159 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); | 2159 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); |
| 2160 renderer_->SetVisible(false); | 2160 renderer_->SetVisible(false); |
| 2161 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2161 Mock::VerifyAndClearExpectations(context_support_ptr_); |
| 2162 } | 2162 } |
| 2163 | 2163 |
| 2164 class SwapWithBoundsMockGLES2Interface : public TestGLES2Interface { |
| 2165 public: |
| 2166 void InitializeTestContext(TestWebGraphicsContext3D* context) override { |
| 2167 context->set_have_swap_buffers_with_bounds(true); |
| 2168 } |
| 2169 }; |
| 2170 |
| 2171 class ContentBoundsOverlayProcessor : public OverlayProcessor { |
| 2172 public: |
| 2173 class Strategy : public OverlayProcessor::Strategy { |
| 2174 public: |
| 2175 explicit Strategy(const std::vector<gfx::Rect>& content_bounds) |
| 2176 : content_bounds_(content_bounds) {} |
| 2177 ~Strategy() override {} |
| 2178 bool Attempt(ResourceProvider* resource_provider, |
| 2179 RenderPass* render_pass, |
| 2180 OverlayCandidateList* candidates, |
| 2181 std::vector<gfx::Rect>* content_bounds) override { |
| 2182 content_bounds->insert(content_bounds->end(), content_bounds_.begin(), |
| 2183 content_bounds_.end()); |
| 2184 return true; |
| 2185 } |
| 2186 |
| 2187 const std::vector<gfx::Rect> content_bounds_; |
| 2188 }; |
| 2189 |
| 2190 ContentBoundsOverlayProcessor(OutputSurface* surface, |
| 2191 const std::vector<gfx::Rect>& content_bounds) |
| 2192 : OverlayProcessor(surface), content_bounds_(content_bounds) {} |
| 2193 |
| 2194 void Initialize() override { |
| 2195 strategy_ = new Strategy(content_bounds_); |
| 2196 strategies_.push_back(base::WrapUnique(strategy_)); |
| 2197 } |
| 2198 |
| 2199 Strategy* strategy_; |
| 2200 const std::vector<gfx::Rect> content_bounds_; |
| 2201 }; |
| 2202 |
| 2203 class GLRendererSwapWithBoundsTest : public GLRendererTest { |
| 2204 protected: |
| 2205 void RunTest(const std::vector<gfx::Rect>& content_bounds) { |
| 2206 auto gl_owned = base::MakeUnique<SwapWithBoundsMockGLES2Interface>(); |
| 2207 |
| 2208 auto provider = TestContextProvider::Create(std::move(gl_owned)); |
| 2209 provider->BindToCurrentThread(); |
| 2210 |
| 2211 FakeOutputSurfaceClient output_surface_client; |
| 2212 std::unique_ptr<FakeOutputSurface> output_surface( |
| 2213 FakeOutputSurface::Create3d(std::move(provider))); |
| 2214 output_surface->BindToClient(&output_surface_client); |
| 2215 |
| 2216 std::unique_ptr<ResourceProvider> resource_provider = |
| 2217 FakeResourceProvider::Create(output_surface->context_provider(), |
| 2218 nullptr); |
| 2219 |
| 2220 RendererSettings settings; |
| 2221 FakeRendererGL renderer(&settings, output_surface.get(), |
| 2222 resource_provider.get()); |
| 2223 renderer.Initialize(); |
| 2224 EXPECT_EQ(true, renderer.use_swap_with_bounds()); |
| 2225 renderer.SetVisible(true); |
| 2226 |
| 2227 OverlayProcessor* processor = |
| 2228 new ContentBoundsOverlayProcessor(output_surface.get(), content_bounds); |
| 2229 processor->Initialize(); |
| 2230 renderer.SetOverlayProcessor(processor); |
| 2231 |
| 2232 gfx::Size viewport_size(100, 100); |
| 2233 |
| 2234 { |
| 2235 int root_pass_id = 1; |
| 2236 AddRenderPass(&render_passes_in_draw_order_, root_pass_id, |
| 2237 gfx::Rect(viewport_size), gfx::Transform(), |
| 2238 FilterOperations()); |
| 2239 |
| 2240 renderer.DecideRenderPassAllocationsForFrame( |
| 2241 render_passes_in_draw_order_); |
| 2242 DrawFrame(&renderer, viewport_size); |
| 2243 renderer.SwapBuffers(std::vector<ui::LatencyInfo>()); |
| 2244 |
| 2245 std::vector<gfx::Rect> expected_content_bounds; |
| 2246 EXPECT_EQ(content_bounds, |
| 2247 output_surface->last_sent_frame()->content_bounds); |
| 2248 } |
| 2249 } |
| 2250 }; |
| 2251 |
| 2252 TEST_F(GLRendererSwapWithBoundsTest, EmptyContent) { |
| 2253 std::vector<gfx::Rect> content_bounds; |
| 2254 RunTest(content_bounds); |
| 2255 } |
| 2256 |
| 2257 TEST_F(GLRendererSwapWithBoundsTest, NonEmpty) { |
| 2258 std::vector<gfx::Rect> content_bounds; |
| 2259 content_bounds.push_back(gfx::Rect(0, 0, 10, 10)); |
| 2260 content_bounds.push_back(gfx::Rect(20, 20, 30, 30)); |
| 2261 RunTest(content_bounds); |
| 2262 } |
| 2263 |
| 2164 } // namespace | 2264 } // namespace |
| 2165 } // namespace cc | 2265 } // namespace cc |
| OLD | NEW |