| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "content/browser/compositor/software_output_device_mac.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gfx/skia_util.h" |
| 9 |
| 10 namespace content { |
| 11 |
| 12 namespace { |
| 13 |
| 14 TEST(SoftwareOutputDeviceMacTest, Basics) { |
| 15 std::unique_ptr<SoftwareOutputDeviceMac> device( |
| 16 new SoftwareOutputDeviceMac(nullptr)); |
| 17 gfx::Size pixel_size(512, 512); |
| 18 float scale_factor = 1; |
| 19 |
| 20 EXPECT_EQ(device->BufferQueueSizeForTesting(), 0u); |
| 21 device->Resize(pixel_size, scale_factor); |
| 22 |
| 23 // Frame 0. |
| 24 gfx::Rect damage0(pixel_size); |
| 25 device->BeginPaint(damage0); |
| 26 IOSurfaceRef io_surface0 = device->CurrentPaintIOSurfaceForTesting(); |
| 27 device->EndPaint(); |
| 28 |
| 29 // Frame 1. |
| 30 // We didn't set the IOSurface in use, so it should be re-used, and we should |
| 31 // have no copy. |
| 32 gfx::Rect damage1(10, 10, 10, 10); |
| 33 device->BeginPaint(damage1); |
| 34 IOSurfaceRef io_surface1 = device->CurrentPaintIOSurfaceForTesting(); |
| 35 device->EndPaint(); |
| 36 EXPECT_EQ(io_surface0, io_surface1); |
| 37 EXPECT_EQ(device->BufferQueueSizeForTesting(), 1u); |
| 38 EXPECT_TRUE(device->LastCopyRegionForTesting().isEmpty()); |
| 39 |
| 40 // Frame 2. |
| 41 // The IOSurface is in use, so we should allocate a new one. We'll do a full |
| 42 // copy because it's a new buffer. |
| 43 IOSurfaceIncrementUseCount(io_surface1); |
| 44 gfx::Rect damage2(20, 20, 10, 10); |
| 45 device->BeginPaint(damage2); |
| 46 IOSurfaceRef io_surface2 = device->CurrentPaintIOSurfaceForTesting(); |
| 47 device->EndPaint(); |
| 48 EXPECT_NE(io_surface1, io_surface2); |
| 49 EXPECT_EQ(device->BufferQueueSizeForTesting(), 2u); |
| 50 SkRegion copy_region2(gfx::RectToSkIRect(gfx::Rect(pixel_size))); |
| 51 copy_region2.op(gfx::RectToSkIRect(damage2), SkRegion::kDifference_Op); |
| 52 EXPECT_EQ(device->LastCopyRegionForTesting(), copy_region2); |
| 53 |
| 54 // Frame 3. |
| 55 // Both IOSurfaces are in use, so we'll allocate yet a new one and do another |
| 56 // full copy. |
| 57 IOSurfaceIncrementUseCount(io_surface2); |
| 58 gfx::Rect damage3(30, 30, 10, 10); |
| 59 device->BeginPaint(damage3); |
| 60 IOSurfaceRef io_surface3 = device->CurrentPaintIOSurfaceForTesting(); |
| 61 device->EndPaint(); |
| 62 EXPECT_NE(io_surface1, io_surface3); |
| 63 EXPECT_NE(io_surface2, io_surface3); |
| 64 EXPECT_EQ(device->BufferQueueSizeForTesting(), 3u); |
| 65 SkRegion copy_region3(gfx::RectToSkIRect(gfx::Rect(pixel_size))); |
| 66 copy_region3.op(gfx::RectToSkIRect(damage3), SkRegion::kDifference_Op); |
| 67 EXPECT_EQ(device->LastCopyRegionForTesting(), copy_region3); |
| 68 |
| 69 // Frame 4. |
| 70 // The IOSurface from frame1 is free, so we should re-use it. We should be |
| 71 // copying the damage from frame2 and frame3. |
| 72 IOSurfaceIncrementUseCount(io_surface3); |
| 73 IOSurfaceDecrementUseCount(io_surface1); |
| 74 gfx::Rect damage4(35, 35, 15, 15); |
| 75 device->BeginPaint(damage4); |
| 76 IOSurfaceRef io_surface4 = device->CurrentPaintIOSurfaceForTesting(); |
| 77 device->EndPaint(); |
| 78 EXPECT_EQ(io_surface1, io_surface4); |
| 79 EXPECT_EQ(device->BufferQueueSizeForTesting(), 3u); |
| 80 SkRegion copy_region4; |
| 81 copy_region4.op(gfx::RectToSkIRect(damage2), SkRegion::kUnion_Op); |
| 82 copy_region4.op(gfx::RectToSkIRect(damage3), SkRegion::kUnion_Op); |
| 83 copy_region4.op(gfx::RectToSkIRect(damage4), SkRegion::kDifference_Op); |
| 84 EXPECT_EQ(device->LastCopyRegionForTesting(), copy_region4); |
| 85 |
| 86 // Frame 5. |
| 87 // All IOSurfaces are allocated, allocate another. |
| 88 IOSurfaceIncrementUseCount(io_surface4); |
| 89 gfx::Rect damage5(50, 50, 10, 10); |
| 90 device->BeginPaint(damage5); |
| 91 IOSurfaceRef io_surface5 = device->CurrentPaintIOSurfaceForTesting(); |
| 92 EXPECT_NE(io_surface5, io_surface2); |
| 93 EXPECT_NE(io_surface5, io_surface3); |
| 94 EXPECT_NE(io_surface5, io_surface4); |
| 95 device->EndPaint(); |
| 96 EXPECT_EQ(device->BufferQueueSizeForTesting(), 4u); |
| 97 |
| 98 // Frame 6. |
| 99 // All IOSurfaces are in use, allocate another, but free the one from frame2 |
| 100 // (add an extra retain and check to retain count to verify that it steps |
| 101 // down). |
| 102 IOSurfaceIncrementUseCount(io_surface5); |
| 103 CFRetain(io_surface2); |
| 104 EXPECT_EQ(CFGetRetainCount(io_surface2), 2u); |
| 105 gfx::Rect damage6(60, 60, 10, 10); |
| 106 device->BeginPaint(damage6); |
| 107 IOSurfaceRef io_surface6 = device->CurrentPaintIOSurfaceForTesting(); |
| 108 device->EndPaint(); |
| 109 EXPECT_EQ(device->BufferQueueSizeForTesting(), 4u); |
| 110 EXPECT_NE(io_surface6, io_surface2); |
| 111 EXPECT_NE(io_surface6, io_surface3); |
| 112 EXPECT_NE(io_surface6, io_surface4); |
| 113 EXPECT_NE(io_surface6, io_surface5); |
| 114 EXPECT_EQ(CFGetRetainCount(io_surface2), 1u); |
| 115 CFRelease(io_surface2); |
| 116 } |
| 117 |
| 118 } // namespace |
| 119 |
| 120 } // namespace content |
| OLD | NEW |