OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
6 | 6 |
7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" |
8 #include "cc/content_layer.h" | 8 #include "cc/content_layer.h" |
9 #include "cc/content_layer_client.h" | 9 #include "cc/content_layer_client.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
11 #include "cc/layer_tree_host_impl.h" | 11 #include "cc/layer_tree_host_impl.h" |
12 #include "cc/layer_tree_impl.h" | 12 #include "cc/layer_tree_impl.h" |
13 #include "cc/output_surface.h" | 13 #include "cc/output_surface.h" |
| 14 #include "cc/picture_layer.h" |
14 #include "cc/prioritized_resource.h" | 15 #include "cc/prioritized_resource.h" |
15 #include "cc/single_thread_proxy.h" | 16 #include "cc/single_thread_proxy.h" |
16 #include "cc/test/fake_content_layer.h" | 17 #include "cc/test/fake_content_layer.h" |
17 #include "cc/test/fake_content_layer_client.h" | 18 #include "cc/test/fake_content_layer_client.h" |
18 #include "cc/test/fake_layer_tree_host_client.h" | 19 #include "cc/test/fake_layer_tree_host_client.h" |
19 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
20 #include "cc/test/fake_proxy.h" | 21 #include "cc/test/fake_proxy.h" |
21 #include "cc/test/fake_scrollbar_layer.h" | 22 #include "cc/test/fake_scrollbar_layer.h" |
22 #include "cc/test/geometry_test_utils.h" | 23 #include "cc/test/geometry_test_utils.h" |
23 #include "cc/test/layer_tree_test_common.h" | 24 #include "cc/test/layer_tree_test_common.h" |
24 #include "cc/resource_update_queue.h" | 25 #include "cc/resource_update_queue.h" |
25 #include "cc/test/occlusion_tracker_test_common.h" | 26 #include "cc/test/occlusion_tracker_test_common.h" |
26 #include "cc/timing_function.h" | 27 #include "cc/timing_function.h" |
| 28 #include "skia/ext/refptr.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
29 #include "third_party/khronos/GLES2/gl2.h" | 31 #include "third_party/khronos/GLES2/gl2.h" |
30 #include "third_party/khronos/GLES2/gl2ext.h" | 32 #include "third_party/khronos/GLES2/gl2ext.h" |
| 33 #include "third_party/skia/include/core/SkPicture.h" |
31 #include "ui/gfx/point_conversions.h" | 34 #include "ui/gfx/point_conversions.h" |
32 #include "ui/gfx/size_conversions.h" | 35 #include "ui/gfx/size_conversions.h" |
33 #include "ui/gfx/vector2d_conversions.h" | 36 #include "ui/gfx/vector2d_conversions.h" |
34 | 37 |
35 namespace cc { | 38 namespace cc { |
36 namespace { | 39 namespace { |
37 | 40 |
38 class LayerTreeHostTest : public ThreadedTest { }; | 41 class LayerTreeHostTest : public ThreadedTest { }; |
39 | 42 |
40 // Shortlived layerTreeHosts shouldn't die. | 43 // Shortlived layerTreeHosts shouldn't die. |
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 FakeLayerImplTreeHostClient client(useSoftwareRendering, useDelegatingRender
er); | 2015 FakeLayerImplTreeHostClient client(useSoftwareRendering, useDelegatingRender
er); |
2013 | 2016 |
2014 LayerTreeSettings settings; | 2017 LayerTreeSettings settings; |
2015 settings.maxPartialTextureUpdates = 4; | 2018 settings.maxPartialTextureUpdates = 4; |
2016 | 2019 |
2017 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); | 2020 scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
oped_ptr<Thread>()); |
2018 EXPECT_TRUE(host->initializeRendererIfNeeded()); | 2021 EXPECT_TRUE(host->initializeRendererIfNeeded()); |
2019 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); | 2022 EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); |
2020 } | 2023 } |
2021 | 2024 |
| 2025 class LayerTreeHostTestCapturePicture : public LayerTreeHostTest { |
| 2026 public: |
| 2027 LayerTreeHostTestCapturePicture() |
| 2028 : m_bounds(gfx::Size(100, 100)) |
| 2029 , m_layer(PictureLayer::create(&m_contentClient)) |
| 2030 { |
| 2031 m_settings.implSidePainting = true; |
| 2032 } |
| 2033 |
| 2034 class FillRectContentLayerClient : public ContentLayerClient { |
| 2035 public: |
| 2036 virtual void paintContents(SkCanvas* canvas, const gfx::Rect& clip, gfx:
:RectF& opaque) OVERRIDE |
| 2037 { |
| 2038 SkPaint paint; |
| 2039 paint.setColor(SK_ColorGREEN); |
| 2040 |
| 2041 SkRect rect = SkRect::MakeWH(canvas->getDeviceSize().width(), canvas
->getDeviceSize().height()); |
| 2042 opaque = gfx::RectF(rect.width(), rect.height()); |
| 2043 canvas->drawRect(rect, paint); |
| 2044 } |
| 2045 }; |
| 2046 |
| 2047 virtual void beginTest() OVERRIDE |
| 2048 { |
| 2049 m_layer->setIsDrawable(true); |
| 2050 m_layer->setBounds(m_bounds); |
| 2051 m_layerTreeHost->setViewportSize(m_bounds, m_bounds); |
| 2052 m_layerTreeHost->setRootLayer(m_layer); |
| 2053 |
| 2054 EXPECT_TRUE(m_layerTreeHost->initializeRendererIfNeeded()); |
| 2055 postSetNeedsCommitToMainThread(); |
| 2056 } |
| 2057 |
| 2058 virtual void didCommitAndDrawFrame() OVERRIDE |
| 2059 { |
| 2060 m_picture = m_layerTreeHost->capturePicture(); |
| 2061 endTest(); |
| 2062 } |
| 2063 |
| 2064 virtual void afterTest() OVERRIDE |
| 2065 { |
| 2066 EXPECT_EQ(m_bounds, gfx::Size(m_picture->width(), m_picture->height())); |
| 2067 |
| 2068 SkBitmap bitmap; |
| 2069 bitmap.setConfig(SkBitmap::kARGB_8888_Config, m_bounds.width(), m_bounds
.height()); |
| 2070 bitmap.allocPixels(); |
| 2071 bitmap.eraseARGB(0, 0, 0, 0); |
| 2072 SkCanvas canvas(bitmap); |
| 2073 |
| 2074 m_picture->draw(&canvas); |
| 2075 |
| 2076 bitmap.lockPixels(); |
| 2077 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
| 2078 EXPECT_EQ(SK_ColorGREEN, pixels[0]); |
| 2079 bitmap.unlockPixels(); |
| 2080 } |
| 2081 |
| 2082 private: |
| 2083 gfx::Size m_bounds; |
| 2084 FillRectContentLayerClient m_contentClient; |
| 2085 scoped_refptr<PictureLayer> m_layer; |
| 2086 skia::RefPtr<SkPicture> m_picture; |
| 2087 }; |
| 2088 |
| 2089 MULTI_THREAD_TEST_F(LayerTreeHostTestCapturePicture); |
| 2090 |
2022 } // namespace | 2091 } // namespace |
2023 } // namespace cc | 2092 } // namespace cc |
OLD | NEW |