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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "cc/output/compositor_frame_metadata.h" | 12 #include "cc/output/compositor_frame_metadata.h" |
13 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
14 #include "cc/output/copy_output_result.h" | 14 #include "cc/output/copy_output_result.h" |
15 #include "cc/output/software_output_device.h" | 15 #include "cc/output/software_output_device.h" |
16 #include "cc/quads/render_pass.h" | 16 #include "cc/quads/render_pass.h" |
17 #include "cc/quads/render_pass_draw_quad.h" | 17 #include "cc/quads/render_pass_draw_quad.h" |
18 #include "cc/quads/solid_color_draw_quad.h" | 18 #include "cc/quads/solid_color_draw_quad.h" |
19 #include "cc/quads/tile_draw_quad.h" | 19 #include "cc/quads/tile_draw_quad.h" |
20 #include "cc/test/animation_test_common.h" | 20 #include "cc/test/animation_test_common.h" |
21 #include "cc/test/fake_output_surface.h" | 21 #include "cc/test/fake_output_surface.h" |
22 #include "cc/test/fake_output_surface_client.h" | 22 #include "cc/test/fake_output_surface_client.h" |
23 #include "cc/test/fake_resource_provider.h" | 23 #include "cc/test/fake_resource_provider.h" |
24 #include "cc/test/geometry_test_utils.h" | 24 #include "cc/test/geometry_test_utils.h" |
25 #include "cc/test/render_pass_test_utils.h" | 25 #include "cc/test/render_pass_test_utils.h" |
26 #include "cc/test/test_shared_bitmap_manager.h" | 26 #include "cc/test/test_shared_bitmap_manager.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "third_party/skia/include/core/SkCanvas.h" | 29 #include "third_party/skia/include/core/SkCanvas.h" |
| 30 #include "third_party/skia/include/utils/SkNWayCanvas.h" |
30 #include "ui/gfx/skia_util.h" | 31 #include "ui/gfx/skia_util.h" |
31 | 32 |
32 namespace cc { | 33 namespace cc { |
33 namespace { | 34 namespace { |
34 | 35 |
35 class SoftwareRendererTest : public testing::Test { | 36 class SoftwareRendererTest : public testing::Test { |
36 public: | 37 public: |
37 void InitializeRenderer( | 38 void InitializeRenderer( |
38 std::unique_ptr<SoftwareOutputDevice> software_output_device) { | 39 std::unique_ptr<SoftwareOutputDevice> software_output_device) { |
39 output_surface_ = | 40 output_surface_ = |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); | 372 output->getColor(smaller_rect.right() - 1, smaller_rect.bottom() - 1)); |
372 | 373 |
373 EXPECT_EQ( | 374 EXPECT_EQ( |
374 SK_ColorMAGENTA, | 375 SK_ColorMAGENTA, |
375 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); | 376 output->getColor(interior_visible_rect.x(), interior_visible_rect.y())); |
376 EXPECT_EQ(SK_ColorMAGENTA, | 377 EXPECT_EQ(SK_ColorMAGENTA, |
377 output->getColor(interior_visible_rect.right() - 1, | 378 output->getColor(interior_visible_rect.right() - 1, |
378 interior_visible_rect.bottom() - 1)); | 379 interior_visible_rect.bottom() - 1)); |
379 } | 380 } |
380 | 381 |
| 382 class ClipTrackingCanvas : public SkNWayCanvas { |
| 383 public: |
| 384 ClipTrackingCanvas(int width, int height) : SkNWayCanvas(width, height) {} |
| 385 void onClipRect(const SkRect& rect, |
| 386 SkClipOp op, |
| 387 ClipEdgeStyle style) override { |
| 388 last_clip_rect_ = rect; |
| 389 SkNWayCanvas::onClipRect(rect, op, style); |
| 390 } |
| 391 |
| 392 SkRect last_clip_rect() const { return last_clip_rect_; } |
| 393 |
| 394 private: |
| 395 SkRect last_clip_rect_; |
| 396 }; |
| 397 |
381 class PartialSwapSoftwareOutputDevice : public SoftwareOutputDevice { | 398 class PartialSwapSoftwareOutputDevice : public SoftwareOutputDevice { |
382 public: | 399 public: |
383 // SoftwareOutputDevice overrides. | 400 // SoftwareOutputDevice overrides. |
384 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { | 401 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
385 damage_rect_at_start_ = damage_rect; | 402 damage_rect_at_start_ = damage_rect; |
386 canvas_ = SoftwareOutputDevice::BeginPaint(damage_rect); | 403 canvas_.reset(new ClipTrackingCanvas(viewport_pixel_size_.width(), |
387 return canvas_; | 404 viewport_pixel_size_.height())); |
| 405 canvas_->addCanvas(SoftwareOutputDevice::BeginPaint(damage_rect)); |
| 406 return canvas_.get(); |
388 } | 407 } |
| 408 |
389 void EndPaint() override { | 409 void EndPaint() override { |
390 clip_rect_at_end_ = gfx::SkIRectToRect(canvas_->getDeviceClipBounds()); | 410 clip_rect_at_end_ = gfx::SkRectToRectF(canvas_->last_clip_rect()); |
391 SoftwareOutputDevice::EndPaint(); | 411 SoftwareOutputDevice::EndPaint(); |
392 } | 412 } |
393 | 413 |
394 gfx::Rect damage_rect_at_start() const { return damage_rect_at_start_; } | 414 gfx::Rect damage_rect_at_start() const { return damage_rect_at_start_; } |
395 gfx::Rect clip_rect_at_end() const { return clip_rect_at_end_; } | 415 gfx::RectF clip_rect_at_end() const { return clip_rect_at_end_; } |
396 | 416 |
397 private: | 417 private: |
398 SkCanvas* canvas_ = nullptr; | 418 std::unique_ptr<ClipTrackingCanvas> canvas_; |
399 gfx::Rect damage_rect_at_start_; | 419 gfx::Rect damage_rect_at_start_; |
400 gfx::Rect clip_rect_at_end_; | 420 gfx::RectF clip_rect_at_end_; |
401 }; | 421 }; |
402 | 422 |
403 TEST_F(SoftwareRendererTest, PartialSwap) { | 423 TEST_F(SoftwareRendererTest, PartialSwap) { |
404 float device_scale_factor = 1.f; | 424 float device_scale_factor = 1.f; |
405 gfx::Size viewport_size(100, 100); | 425 gfx::Size viewport_size(100, 100); |
406 | 426 |
407 settings_.partial_swap_enabled = true; | 427 settings_.partial_swap_enabled = true; |
408 | 428 |
409 auto device_owned = base::MakeUnique<PartialSwapSoftwareOutputDevice>(); | 429 auto device_owned = base::MakeUnique<PartialSwapSoftwareOutputDevice>(); |
410 auto* device = device_owned.get(); | 430 auto* device = device_owned.get(); |
(...skipping 10 matching lines...) Expand all Loading... |
421 // Partial frame, we should pass this rect to the SoftwareOutputDevice. | 441 // Partial frame, we should pass this rect to the SoftwareOutputDevice. |
422 // partial swap is enabled. | 442 // partial swap is enabled. |
423 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); | 443 root_pass->damage_rect = gfx::Rect(2, 2, 3, 3); |
424 | 444 |
425 renderer()->DecideRenderPassAllocationsForFrame(list); | 445 renderer()->DecideRenderPassAllocationsForFrame(list); |
426 renderer()->DrawFrame(&list, device_scale_factor, viewport_size); | 446 renderer()->DrawFrame(&list, device_scale_factor, viewport_size); |
427 | 447 |
428 // The damage rect should be reported to the SoftwareOutputDevice. | 448 // The damage rect should be reported to the SoftwareOutputDevice. |
429 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->damage_rect_at_start()); | 449 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->damage_rect_at_start()); |
430 // The SkCanvas should be clipped to the damage rect. | 450 // The SkCanvas should be clipped to the damage rect. |
431 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), device->clip_rect_at_end()); | 451 EXPECT_EQ(gfx::RectF(2, 2, 3, 3), device->clip_rect_at_end()); |
432 } | 452 } |
433 | 453 |
434 } // namespace | 454 } // namespace |
435 } // namespace cc | 455 } // namespace cc |
OLD | NEW |