blob: 3c1fe3288993ed394cb6aa6b3a1b3a8033b83fa9 [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]1758e882010-11-01 16:16:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]0a6d5f62011-11-11 08:04:075#ifndef PPAPI_TESTS_TEST_GRAPHICS_2D_H_
6#define PPAPI_TESTS_TEST_GRAPHICS_2D_H_
7
8#include <string>
[email protected]1758e882010-11-01 16:16:509
10#include "ppapi/c/pp_stdint.h"
[email protected]256513872012-01-05 15:41:5211#include "ppapi/c/ppb_graphics_2d.h"
12#include "ppapi/c/ppb_image_data.h"
[email protected]1758e882010-11-01 16:16:5013#include "ppapi/tests/test_case.h"
14
[email protected]1758e882010-11-01 16:16:5015namespace pp {
16class Graphics2D;
17class ImageData;
18class Point;
19class Rect;
20}
21
22class TestGraphics2D : public TestCase {
23 public:
[email protected]0a6d5f62011-11-11 08:04:0724 explicit TestGraphics2D(TestingInstance* instance) : TestCase(instance) {}
[email protected]1758e882010-11-01 16:16:5025
26 // TestCase implementation.
27 virtual bool Init();
[email protected]2622d6b2011-11-16 04:28:0228 virtual void RunTests(const std::string& filter);
[email protected]1758e882010-11-01 16:16:5029
30 void QuitMessageLoop();
31
32 private:
33 bool ReadImageData(const pp::Graphics2D& dc,
34 pp::ImageData* image,
35 const pp::Point& top_left) const;
36
37 void FillRectInImage(pp::ImageData* image,
38 const pp::Rect& rect,
39 uint32_t color) const;
40
41 // Fill image with gradient colors.
42 void FillImageWithGradient(pp::ImageData* image) const;
43
44 // Return true if images are the same.
45 bool CompareImages(const pp::ImageData& image1,
46 const pp::ImageData& image2);
47
48 // Return true if images within specified rectangles are the same.
49 bool CompareImageRect(const pp::ImageData& image1,
50 const pp::Rect& rc1,
51 const pp::ImageData& image2,
52 const pp::Rect& rc2) const;
53
54 // Validates that the given image is a single color with a square of another
55 // color inside it.
56 bool IsSquareInImage(const pp::ImageData& image_data,
57 uint32_t background_color,
58 const pp::Rect& square, uint32_t square_color) const;
59
60 // Validates that the given device context is a single color with a square of
61 // another color inside it.
62 bool IsSquareInDC(const pp::Graphics2D& dc, uint32_t background_color,
63 const pp::Rect& square, uint32_t square_color) const;
64
65 // Validates that the given device context is filled with the given color.
66 bool IsDCUniformColor(const pp::Graphics2D& dc, uint32_t color) const;
67
68 // Issues a flush on the given device context and blocks until the flush
69 // has issued its callback. Returns true on success.
70 bool FlushAndWaitForDone(pp::Graphics2D* context);
71
[email protected]c42835772012-08-22 18:22:1372 // Creates an image and replaces the contents of the Graphics2D with the
73 // image, waiting for completion. This returns the resource ID of the image
74 // data we created. This image data will be released by the time the call
75 // completes, but it can be used for comparisons later.
76 //
77 // Returns 0 on failure.
78 PP_Resource ReplaceContentsAndReturnID(pp::Graphics2D* dc,
79 const pp::Size& size);
80
[email protected]1758e882010-11-01 16:16:5081 std::string TestInvalidResource();
82 std::string TestInvalidSize();
83 std::string TestHumongous();
84 std::string TestInitToZero();
85 std::string TestDescribe();
86 std::string TestPaint();
87 std::string TestScroll();
88 std::string TestReplace();
89 std::string TestFlush();
[email protected]0cd5b9df2012-06-28 19:33:3390 std::string TestDev();
[email protected]c42835772012-08-22 18:22:1391 std::string TestReplaceContentsCaching();
[email protected]1758e882010-11-01 16:16:5092
93 // Used by the tests that access the C API directly.
94 const PPB_Graphics2D* graphics_2d_interface_;
95 const PPB_ImageData* image_data_interface_;
[email protected]1758e882010-11-01 16:16:5096};
97
[email protected]0a6d5f62011-11-11 08:04:0798#endif // PPAPI_TESTS_TEST_GRAPHICS_2D_H_