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