[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 5 | #ifndef PPAPI_TESTS_TEST_GRAPHICS_2D_H_ |
| 6 | #define PPAPI_TESTS_TEST_GRAPHICS_2D_H_ |
| 7 | |
| 8 | #include <string> |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 9 | |
| 10 | #include "ppapi/c/pp_stdint.h" |
[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 11 | #include "ppapi/c/ppb_graphics_2d.h" |
| 12 | #include "ppapi/c/ppb_image_data.h" |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 13 | #include "ppapi/tests/test_case.h" |
| 14 | |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 15 | namespace pp { |
| 16 | class Graphics2D; |
| 17 | class ImageData; |
| 18 | class Point; |
| 19 | class Rect; |
| 20 | } |
| 21 | |
| 22 | class TestGraphics2D : public TestCase { |
| 23 | public: |
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 24 | explicit TestGraphics2D(TestingInstance* instance) : TestCase(instance) {} |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 25 | |
| 26 | // TestCase implementation. |
| 27 | virtual bool Init(); |
[email protected] | 2622d6b | 2011-11-16 04:28:02 | [diff] [blame] | 28 | virtual void RunTests(const std::string& filter); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 29 | |
| 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] | c4283577 | 2012-08-22 18:22:13 | [diff] [blame] | 72 | // 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] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 81 | 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] | 0cd5b9df | 2012-06-28 19:33:33 | [diff] [blame] | 90 | std::string TestDev(); |
[email protected] | c4283577 | 2012-08-22 18:22:13 | [diff] [blame] | 91 | std::string TestReplaceContentsCaching(); |
[email protected] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 92 | |
| 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] | 1758e88 | 2010-11-01 16:16:50 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 98 | #endif // PPAPI_TESTS_TEST_GRAPHICS_2D_H_ |