Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: cc/tiles/tile_manager_unittest.cc

Issue 1854723002: cc: Simplify task and its derived classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corrected scope of dependencies. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "cc/playback/raster_source.h" 10 #include "cc/playback/raster_source.h"
11 #include "cc/playback/recording_source.h" 11 #include "cc/playback/recording_source.h"
12 #include "cc/raster/raster_buffer.h"
13 #include "cc/resources/resource_pool.h" 12 #include "cc/resources/resource_pool.h"
14 #include "cc/test/begin_frame_args_test.h" 13 #include "cc/test/begin_frame_args_test.h"
15 #include "cc/test/fake_impl_task_runner_provider.h" 14 #include "cc/test/fake_impl_task_runner_provider.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 15 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_output_surface.h" 16 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_output_surface_client.h" 17 #include "cc/test/fake_output_surface_client.h"
19 #include "cc/test/fake_picture_layer_impl.h" 18 #include "cc/test/fake_picture_layer_impl.h"
20 #include "cc/test/fake_picture_layer_tiling_client.h" 19 #include "cc/test/fake_picture_layer_tiling_client.h"
21 #include "cc/test/fake_raster_source.h" 20 #include "cc/test/fake_raster_source.h"
22 #include "cc/test/fake_recording_source.h" 21 #include "cc/test/fake_recording_source.h"
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 // Since it's high res, the bitmap (blue) was drawn, and the 1812 // Since it's high res, the bitmap (blue) was drawn, and the
1814 // background is not visible. 1813 // background is not visible.
1815 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y)); 1814 ASSERT_EQ(SK_ColorBLUE, bitmap->getColor(x, y));
1816 } 1815 }
1817 } 1816 }
1818 } 1817 }
1819 } 1818 }
1820 } 1819 }
1821 1820
1822 // Fake TileTaskRunner that just no-ops all calls. 1821 // Fake TileTaskRunner that just no-ops all calls.
1823 class FakeTileTaskRunner : public TileTaskRunner, public TileTaskClient { 1822 class FakeTileTaskRunner : public TileTaskRunner {
1824 public: 1823 public:
1825 FakeTileTaskRunner() {} 1824 FakeTileTaskRunner() {}
1826 ~FakeTileTaskRunner() override {} 1825 ~FakeTileTaskRunner() override {}
1827 1826
1827 // RasterBufferProvider methods.
1828 scoped_ptr<RasterBuffer> AcquireBufferForRaster(
1829 const Resource* resource,
1830 uint64_t resource_content_id,
1831 uint64_t previous_content_id) override {
1832 NOTREACHED();
1833 return nullptr;
1834 }
1835 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {}
1836
1828 // TileTaskRunner methods. 1837 // TileTaskRunner methods.
1829 void Shutdown() override {} 1838 void Shutdown() override {}
1830 void CheckForCompletedTasks() override {} 1839 void CheckForCompletedTasks() override {}
1831 ResourceFormat GetResourceFormat(bool must_support_alpha) const override { 1840 ResourceFormat GetResourceFormat(bool must_support_alpha) const override {
1832 return ResourceFormat::RGBA_8888; 1841 return ResourceFormat::RGBA_8888;
1833 } 1842 }
1834 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override { 1843 bool GetResourceRequiresSwizzle(bool must_support_alpha) const override {
1835 return false; 1844 return false;
1836 } 1845 }
1837 1846
1838 void ScheduleTasks(TaskGraph* graph) override {} 1847 void ScheduleTasks(TaskGraph* graph) override {}
1839
1840 // TileTaskClient methods.
1841 scoped_ptr<RasterBuffer> AcquireBufferForRaster(
1842 const Resource* resource,
1843 uint64_t resource_content_id,
1844 uint64_t previous_content_id) override {
1845 NOTREACHED();
1846 return nullptr;
1847 }
1848 void ReleaseBufferForRaster(scoped_ptr<RasterBuffer> buffer) override {}
1849 }; 1848 };
1850 1849
1851 // Fake TileTaskRunner that just cancels all scheduled tasks immediately. 1850 // Fake TileTaskRunner that just cancels all scheduled tasks immediately.
1852 class CancellingTileTaskRunner : public FakeTileTaskRunner { 1851 class CancellingTileTaskRunner : public FakeTileTaskRunner {
1853 public: 1852 public:
1854 CancellingTileTaskRunner() {} 1853 CancellingTileTaskRunner() {}
1855 ~CancellingTileTaskRunner() override {} 1854 ~CancellingTileTaskRunner() override {}
1856 1855
1857 void ScheduleTasks(TaskGraph* graph) override { 1856 void ScheduleTasks(TaskGraph* graph) override {
1858 // Just call CompleteOnOriginThread on each item in the queue. As none of 1857 // Just call CompleteOnOriginThread on each item in the queue. As none of
1859 // these items have run yet, they will be treated as cancelled tasks. 1858 // these items have run yet, they will be treated as cancelled tasks.
1860 for (const auto& node : graph->nodes) { 1859 for (const auto& node : graph->nodes) {
1861 static_cast<TileTask*>(node.task)->CompleteOnOriginThread(this); 1860 node.task->CompleteOnOriginThread();
1862 } 1861 }
1863 } 1862 }
1864 }; 1863 };
1865 1864
1866 class PartialRasterTileManagerTest : public TileManagerTest { 1865 class PartialRasterTileManagerTest : public TileManagerTest {
1867 public: 1866 public:
1868 void CustomizeSettings(LayerTreeSettings* settings) override { 1867 void CustomizeSettings(LayerTreeSettings* settings) override {
1869 settings->use_partial_raster = true; 1868 settings->use_partial_raster = true;
1870 } 1869 }
1871 }; 1870 };
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 host_impl_ = nullptr; 1923 host_impl_ = nullptr;
1925 } 1924 }
1926 1925
1927 // Fake TileTaskRunner that verifies the resource content ID of raster tasks. 1926 // Fake TileTaskRunner that verifies the resource content ID of raster tasks.
1928 class VerifyResourceContentIdTileTaskRunner : public FakeTileTaskRunner { 1927 class VerifyResourceContentIdTileTaskRunner : public FakeTileTaskRunner {
1929 public: 1928 public:
1930 explicit VerifyResourceContentIdTileTaskRunner(uint64_t expected_resource_id) 1929 explicit VerifyResourceContentIdTileTaskRunner(uint64_t expected_resource_id)
1931 : expected_resource_id_(expected_resource_id) {} 1930 : expected_resource_id_(expected_resource_id) {}
1932 ~VerifyResourceContentIdTileTaskRunner() override {} 1931 ~VerifyResourceContentIdTileTaskRunner() override {}
1933 1932
1934 void ScheduleTasks(TaskGraph* graph) override { 1933 // RasterBufferProvider methods.
1935 for (const auto& node : graph->nodes) {
1936 TileTask* task = static_cast<TileTask*>(node.task);
1937 // Triggers a call to AcquireBufferForRaster.
1938 task->ScheduleOnOriginThread(this);
1939 // Calls TileManager as though task was cancelled.
1940 task->CompleteOnOriginThread(this);
1941 }
1942 }
1943
1944 // TileTaskClient methods.
1945 scoped_ptr<RasterBuffer> AcquireBufferForRaster( 1934 scoped_ptr<RasterBuffer> AcquireBufferForRaster(
1946 const Resource* resource, 1935 const Resource* resource,
1947 uint64_t resource_content_id, 1936 uint64_t resource_content_id,
1948 uint64_t previous_content_id) override { 1937 uint64_t previous_content_id) override {
1949 EXPECT_EQ(expected_resource_id_, resource_content_id); 1938 EXPECT_EQ(expected_resource_id_, resource_content_id);
1950 return nullptr; 1939 return nullptr;
1951 } 1940 }
1952 1941
1942 void ScheduleTasks(TaskGraph* graph) override {
1943 for (const auto& node : graph->nodes) {
1944 Task* task = node.task;
1945 // Triggers a call to AcquireBufferForRaster.
1946 task->ScheduleOnOriginThread();
1947 // Calls TileManager as though task was cancelled.
1948 task->CompleteOnOriginThread();
1949 }
1950 }
1951
1953 private: 1952 private:
1954 uint64_t expected_resource_id_; 1953 uint64_t expected_resource_id_;
1955 }; 1954 };
1956 1955
1957 // Runs a test to ensure that partial raster is either enabled or disabled, 1956 // Runs a test to ensure that partial raster is either enabled or disabled,
1958 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl 1957 // depending on |partial_raster_enabled|'s value. Takes ownership of host_impl
1959 // so that cleanup order can be controlled. 1958 // so that cleanup order can be controlled.
1960 void RunPartialRasterCheck(scoped_ptr<LayerTreeHostImpl> host_impl, 1959 void RunPartialRasterCheck(scoped_ptr<LayerTreeHostImpl> host_impl,
1961 bool partial_raster_enabled) { 1960 bool partial_raster_enabled) {
1962 // Pick arbitrary IDs - they don't really matter as long as they're constant. 1961 // Pick arbitrary IDs - they don't really matter as long as they're constant.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 2020
2022 // Ensures that the tile manager does not attempt to reuse tiles when partial 2021 // Ensures that the tile manager does not attempt to reuse tiles when partial
2023 // raster is disabled. 2022 // raster is disabled.
2024 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) { 2023 TEST_F(TileManagerTest, PartialRasterSuccessfullyDisabled) {
2025 RunPartialRasterCheck(std::move(host_impl_), 2024 RunPartialRasterCheck(std::move(host_impl_),
2026 false /* partial_raster_enabled */); 2025 false /* partial_raster_enabled */);
2027 } 2026 }
2028 2027
2029 } // namespace 2028 } // namespace
2030 } // namespace cc 2029 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698