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