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