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/software_renderer.h" | 5 #include "cc/output/software_renderer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "cc/output/compositor_frame_metadata.h" | 11 #include "cc/output/compositor_frame_metadata.h" |
12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
13 #include "cc/output/copy_output_result.h" | 13 #include "cc/output/copy_output_result.h" |
14 #include "cc/output/software_output_device.h" | 14 #include "cc/output/software_output_device.h" |
15 #include "cc/quads/render_pass.h" | 15 #include "cc/quads/render_pass.h" |
16 #include "cc/quads/render_pass_draw_quad.h" | 16 #include "cc/quads/render_pass_draw_quad.h" |
17 #include "cc/quads/solid_color_draw_quad.h" | 17 #include "cc/quads/solid_color_draw_quad.h" |
18 #include "cc/quads/tile_draw_quad.h" | 18 #include "cc/quads/tile_draw_quad.h" |
19 #include "cc/test/animation_test_common.h" | 19 #include "cc/test/animation_test_common.h" |
20 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
21 #include "cc/test/fake_output_surface_client.h" | 21 #include "cc/test/fake_output_surface_client.h" |
22 #include "cc/test/fake_resource_provider.h" | 22 #include "cc/test/fake_resource_provider.h" |
23 #include "cc/test/geometry_test_utils.h" | 23 #include "cc/test/geometry_test_utils.h" |
24 #include "cc/test/render_pass_test_utils.h" | 24 #include "cc/test/render_pass_test_utils.h" |
25 #include "cc/test/test_shared_bitmap_manager.h" | 25 #include "cc/test/test_shared_bitmap_manager.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "third_party/skia/include/core/SkCanvas.h" | 28 #include "third_party/skia/include/core/SkCanvas.h" |
| 29 #include "ui/gfx/skia_util.h" |
29 | 30 |
30 namespace cc { | 31 namespace cc { |
31 namespace { | 32 namespace { |
32 | 33 |
33 class SoftwareRendererTest : public testing::Test, public RendererClient { | 34 class SoftwareRendererTest : public testing::Test, public RendererClient { |
34 public: | 35 public: |
35 void InitializeRenderer( | 36 void InitializeRenderer( |
36 std::unique_ptr<SoftwareOutputDevice> software_output_device) { | 37 std::unique_ptr<SoftwareOutputDevice> software_output_device) { |
37 output_surface_ = | 38 output_surface_ = |
38 FakeOutputSurface::CreateSoftware(std::move(software_output_device)); | 39 FakeOutputSurface::CreateSoftware(std::move(software_output_device)); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); | 389 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); |
389 | 390 |
390 EXPECT_EQ( | 391 EXPECT_EQ( |
391 SK_ColorMAGENTA, | 392 SK_ColorMAGENTA, |
392 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); | 393 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); |
393 EXPECT_EQ(SK_ColorMAGENTA, | 394 EXPECT_EQ(SK_ColorMAGENTA, |
394 output->getColor(interior_visible_rect.right() - 1, | 395 output->getColor(interior_visible_rect.right() - 1, |
395 interior_visible_rect.bottom() - 1)); | 396 interior_visible_rect.bottom() - 1)); |
396 } | 397 } |
397 | 398 |
| 399 class PartialSwapSoftwareOutputDevice : public SoftwareOutputDevice { |
| 400 public: |
| 401 // SoftwareOutputDevice overrides. |
| 402 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
| 403 damage_rect_at_start_ = damage_rect; |
| 404 canvas_ = SoftwareOutputDevice::BeginPaint(damage_rect); |
| 405 return canvas_; |
| 406 } |
| 407 void EndPaint() override { |
| 408 SkIRect clip_device_bounds; |
| 409 canvas_->getClipDeviceBounds(&clip_device_bounds); |
| 410 clip_rect_at_end_ = gfx::SkIRectToRect(clip_device_bounds); |
| 411 SoftwareOutputDevice::EndPaint(); |
| 412 } |
| 413 |
| 414 gfx::Rect damage_rect_at_start() const { return damage_rect_at_start_; } |
| 415 gfx::Rect clip_rect_at_end() const { return clip_rect_at_end_; } |
| 416 |
| 417 private: |
| 418 SkCanvas* canvas_ = nullptr; |
| 419 gfx::Rect damage_rect_at_start_; |
| 420 gfx::Rect clip_rect_at_end_; |
| 421 }; |
| 422 |
| 423 TEST_F(SoftwareRendererTest, PartialSwap) { |
| 424 float device_scale_factor = 1.f; |
| 425 gfx::Rect device_viewport_rect(0, 0, 100, 100); |
| 426 |
| 427 auto device_owned = base::MakeUnique<PartialSwapSoftwareOutputDevice>(); |
| 428 auto* device = device_owned.get(); |
| 429 InitializeRenderer(std::move(device_owned)); |
| 430 |
| 431 gfx::Rect viewport_rect(100, 100); |
| 432 gfx::Rect clip_rect(100, 100); |
| 433 |
| 434 RenderPassList list; |
| 435 |
| 436 RenderPassId root_pass_id(1, 0); |
| 437 RenderPass* root_pass = |
| 438 AddRenderPass(&list, root_pass_id, viewport_rect, gfx::Transform()); |
| 439 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); |
| 440 |
| 441 // Partial frame, we should pass this rect to the SoftwareOutputDevice. |
| 442 // partial swap is enabled. |
| 443 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
| 444 |
| 445 renderer()->DecideRenderPassAllocationsForFrame(list); |
| 446 renderer()->DrawFrame(&list, device_scale_factor, gfx::ColorSpace(), |
| 447 viewport_rect, clip_rect); |
| 448 |
| 449 // The damage rect should be reported to the SoftwareOutputDevice. |
| 450 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->damage_rect_at_start()); |
| 451 // The SkCanvas should be clipped to the damage rect. |
| 452 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->clip_rect_at_end()); |
| 453 } |
| 454 |
398 } // namespace | 455 } // namespace |
399 } // namespace cc | 456 } // namespace cc |
OLD | NEW |