OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_path.h" | |
8 #include "base/file_util.h" | |
9 #include "base/path_service.h" | |
10 #include "base/string_util.h" | |
7 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
jonathan.backer
2011/11/14 14:06:58
nit: alphabetize
| |
8 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/gfx/canvas_skia.h" | 13 #include "ui/gfx/canvas_skia.h" |
14 #include "ui/gfx/codec/png_codec.h" | |
10 #include "ui/gfx/compositor/compositor_observer.h" | 15 #include "ui/gfx/compositor/compositor_observer.h" |
11 #include "ui/gfx/compositor/layer.h" | 16 #include "ui/gfx/compositor/layer.h" |
12 #include "ui/gfx/compositor/layer_animation_sequence.h" | 17 #include "ui/gfx/compositor/layer_animation_sequence.h" |
13 #include "ui/gfx/compositor/test_compositor.h" | 18 #include "ui/gfx/compositor/test_compositor.h" |
14 #include "ui/gfx/compositor/test_compositor_host.h" | 19 #include "ui/gfx/compositor/test_compositor_host.h" |
15 | 20 |
16 namespace ui { | 21 namespace ui { |
17 | 22 |
18 namespace { | 23 namespace { |
19 | 24 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 virtual ~NullLayerDelegate() {} | 171 virtual ~NullLayerDelegate() {} |
167 | 172 |
168 private: | 173 private: |
169 // Overridden from LayerDelegate: | 174 // Overridden from LayerDelegate: |
170 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { | 175 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE { |
171 } | 176 } |
172 | 177 |
173 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); | 178 DISALLOW_COPY_AND_ASSIGN(NullLayerDelegate); |
174 }; | 179 }; |
175 | 180 |
181 // Encodes a bitmap into a PNG and write to disk. Returns true on success. The | |
182 // parent directory does not have to exist. | |
jonathan.backer
2011/11/14 14:06:58
This is great. Just don't see where it's called. (
| |
183 bool WritePNGFile(const SkBitmap& bitmap, const FilePath& file_path) { | |
184 std::vector<unsigned char> png_data; | |
185 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data) && | |
186 file_util::CreateDirectory(file_path.DirName())) { | |
187 int bytes_written = file_util::WriteFile( | |
188 file_path, reinterpret_cast<char*>(&png_data[0]), png_data.size()); | |
189 if (bytes_written == static_cast<int>(png_data.size())) | |
190 return true; | |
191 } | |
192 return false; | |
193 } | |
194 | |
176 } | 195 } |
177 | 196 |
178 #if defined(OS_WIN) | 197 #if defined(OS_WIN) |
179 // These are disabled on windows as they don't run correctly on the buildbot. | 198 // These are disabled on windows as they don't run correctly on the buildbot. |
180 // Reenable once we move to the real compositor. | 199 // Reenable once we move to the real compositor. |
181 #define MAYBE_Delegate DISABLED_Delegate | 200 #define MAYBE_Delegate DISABLED_Delegate |
182 #define MAYBE_Draw DISABLED_Draw | 201 #define MAYBE_Draw DISABLED_Draw |
183 #define MAYBE_DrawTree DISABLED_DrawTree | 202 #define MAYBE_DrawTree DISABLED_DrawTree |
184 #define MAYBE_Hierarchy DISABLED_Hierarchy | 203 #define MAYBE_Hierarchy DISABLED_Hierarchy |
185 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture | 204 #define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 EXPECT_TRUE(schedule_draw_invoked_); | 804 EXPECT_TRUE(schedule_draw_invoked_); |
786 } | 805 } |
787 | 806 |
788 // Checks that pixels are actually drawn to the screen with a read back. | 807 // Checks that pixels are actually drawn to the screen with a read back. |
789 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { | 808 TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { |
790 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, | 809 scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, |
791 gfx::Rect(0, 0, 500, 500))); | 810 gfx::Rect(0, 0, 500, 500))); |
792 DrawTree(layer.get()); | 811 DrawTree(layer.get()); |
793 | 812 |
794 SkBitmap bitmap; | 813 SkBitmap bitmap; |
795 GetCompositor()->ReadPixels(&bitmap); | 814 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap)); |
796 ASSERT_FALSE(bitmap.empty()); | 815 ASSERT_FALSE(bitmap.empty()); |
797 | 816 |
798 SkAutoLockPixels lock(bitmap); | 817 SkAutoLockPixels lock(bitmap); |
799 bool is_all_red = true; | 818 bool is_all_red = true; |
800 for (int x = 0; is_all_red && x < 500; x++) | 819 for (int x = 0; is_all_red && x < 500; x++) |
801 for (int y = 0; is_all_red && y < 500; y++) | 820 for (int y = 0; is_all_red && y < 500; y++) |
802 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); | 821 is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); |
803 | 822 |
804 EXPECT_TRUE(is_all_red); | 823 EXPECT_TRUE(is_all_red); |
805 } | 824 } |
806 | 825 |
807 } // namespace ui | 826 } // namespace ui |
OLD | NEW |