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 3 // found in the LICENSE file. 4 5 #include <vector> 6 7 #include "base/files/file_path.h" 8 #include "base/memory/ref_counted.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "cc/test/layer_tree_test.h" 11 12 #ifndef CC_TEST_LAYER_TREE_PIXEL_TEST_H_ 13 #define CC_TEST_LAYER_TREE_PIXEL_TEST_H_ 14 15 class SkBitmap; 16 17 namespace cc { 18 class CopyOutputRequest; 19 class CopyOutputResult; 20 class LayerTreeHost; 21 class PixelComparator; 22 class SolidColorLayer; 23 class TextureLayer; 24 class TextureMailbox; 25 26 class LayerTreePixelTest : public LayerTreeTest { 27 protected: 28 LayerTreePixelTest(); 29 virtual ~LayerTreePixelTest(); 30 31 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) OVERRIDE; 32 virtual scoped_refptr<cc::ContextProvider> 33 OffscreenContextProviderForMainThread() OVERRIDE; 34 virtual scoped_refptr<cc::ContextProvider> 35 OffscreenContextProviderForCompositorThread() OVERRIDE; 36 37 virtual scoped_ptr<CopyOutputRequest> CreateCopyOutputRequest(); 38 39 void ReadbackResult(scoped_ptr<CopyOutputResult> result); 40 41 virtual void BeginTest() OVERRIDE; 42 virtual void SetupTree() OVERRIDE; 43 virtual void AfterTest() OVERRIDE; 44 virtual void EndTest() OVERRIDE; 45 46 void TryEndTest(); 47 48 scoped_refptr<SolidColorLayer> CreateSolidColorLayer(gfx::Rect rect, 49 SkColor color); 50 scoped_refptr<SolidColorLayer> CreateSolidColorLayerWithBorder( 51 gfx::Rect rect, 52 SkColor color, 53 int border_width, 54 SkColor border_color); 55 scoped_refptr<TextureLayer> CreateTextureLayer(gfx::Rect rect, 56 const SkBitmap& bitmap); 57 58 enum PixelTestType { 59 GL_WITH_DEFAULT, 60 GL_WITH_BITMAP, 61 SOFTWARE_WITH_DEFAULT, 62 SOFTWARE_WITH_BITMAP 63 }; 64 65 void RunPixelTest(PixelTestType type, 66 scoped_refptr<Layer> content_root, 67 base::FilePath file_name); 68 69 void RunPixelTestWithReadbackTarget(PixelTestType type, 70 scoped_refptr<Layer> content_root, 71 Layer* target, 72 base::FilePath file_name); 73 74 scoped_ptr<SkBitmap> CopyTextureMailboxToBitmap( 75 gfx::Size size, 76 const TextureMailbox& texture_mailbox); 77 78 TextureMailbox CopyBitmapToTextureMailboxAsTexture(const SkBitmap& bitmap); 79 80 void ReleaseTextureMailbox( 81 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 82 uint32 texture, 83 uint32 sync_point, 84 bool lost_resource); 85 86 // Common CSS colors defined for tests to use. 87 enum Colors { 88 kCSSOrange = 0xffffa500, 89 kCSSBrown = 0xffa52a2a, 90 kCSSGreen = 0xff008000, 91 }; 92 93 scoped_ptr<PixelComparator> pixel_comparator_; 94 PixelTestType test_type_; 95 scoped_refptr<Layer> content_root_; 96 Layer* readback_target_; 97 base::FilePath ref_file_; 98 scoped_ptr<SkBitmap> result_bitmap_; 99 std::vector<scoped_refptr<TextureLayer> > texture_layers_; 100 int pending_texture_mailbox_callbacks_; 101 }; 102 103 } // namespace cc 104 105 #endif // CC_TEST_LAYER_TREE_PIXEL_TEST_H_ 106