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