David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "starboard/blitter.h" |
| 16 | #include "starboard/nplb/blitter_helpers.h" |
| 17 | #include "starboard/window.h" |
| 18 | #include "testing/gtest/include/gtest/gtest.h" |
| 19 | |
| 20 | #if SB_HAS(BLITTER) |
| 21 | |
| 22 | namespace starboard { |
| 23 | namespace nplb { |
| 24 | namespace { |
| 25 | |
| 26 | TEST(SbBlitterCreateSurfaceFromPixelDataTest, SunnyDay) { |
| 27 | SbBlitterDevice device = SbBlitterCreateDefaultDevice(); |
| 28 | ASSERT_TRUE(SbBlitterIsDeviceValid(device)); |
| 29 | |
| 30 | const int kWidth = 128; |
| 31 | const int kHeight = 128; |
| 32 | |
| 33 | // Test that we can get pitch on all supported image formats. |
| 34 | std::vector<SbBlitterPixelDataFormat> supported_formats = |
| 35 | GetAllSupportedPixelFormatsForPixelData(device); |
| 36 | for (std::vector<SbBlitterPixelDataFormat>::const_iterator iter = |
| 37 | supported_formats.begin(); |
| 38 | iter != supported_formats.end(); ++iter) { |
| 39 | SbBlitterPixelData pixel_data = |
| 40 | SbBlitterCreatePixelData(device, kWidth, kHeight, *iter); |
| 41 | ASSERT_TRUE(SbBlitterIsPixelDataValid(pixel_data)); |
| 42 | |
| 43 | SbBlitterSurface surface = |
| 44 | SbBlitterCreateSurfaceFromPixelData(device, pixel_data); |
| 45 | EXPECT_TRUE(SbBlitterIsSurfaceValid(surface)); |
| 46 | |
| 47 | EXPECT_TRUE(SbBlitterDestroySurface(surface)); |
| 48 | } |
| 49 | |
| 50 | EXPECT_TRUE(SbBlitterDestroyDevice(device)); |
| 51 | } |
| 52 | |
| 53 | TEST(SbBlitterCreateSurfaceFromPixelDataTest, RainyDayInvalidPixelData) { |
| 54 | SbBlitterDevice device = SbBlitterCreateDefaultDevice(); |
| 55 | ASSERT_TRUE(SbBlitterIsDeviceValid(device)); |
| 56 | |
| 57 | SbBlitterSurface surface = |
| 58 | SbBlitterCreateSurfaceFromPixelData(device, kSbBlitterInvalidPixelData); |
| 59 | EXPECT_FALSE(SbBlitterIsSurfaceValid(surface)); |
| 60 | |
| 61 | EXPECT_TRUE(SbBlitterDestroyDevice(device)); |
| 62 | } |
| 63 | |
| 64 | TEST(SbBlitterCreateSurfaceFromPixelDataTest, RainyDayInvalidDevice) { |
| 65 | // We still need a valid device to create the pixel data, we just won't pass |
| 66 | // it into SbBlitterCreateSurfaceFromPixelData(). |
| 67 | SbBlitterDevice device = SbBlitterCreateDefaultDevice(); |
| 68 | ASSERT_TRUE(SbBlitterIsDeviceValid(device)); |
| 69 | |
| 70 | const int kWidth = 128; |
| 71 | const int kHeight = 128; |
| 72 | |
| 73 | std::vector<SbBlitterPixelDataFormat> supported_formats = |
| 74 | GetAllSupportedPixelFormatsForPixelData(device); |
| 75 | for (std::vector<SbBlitterPixelDataFormat>::const_iterator iter = |
| 76 | supported_formats.begin(); |
| 77 | iter != supported_formats.end(); ++iter) { |
| 78 | SbBlitterPixelData pixel_data = |
| 79 | SbBlitterCreatePixelData(device, kWidth, kHeight, *iter); |
| 80 | ASSERT_TRUE(SbBlitterIsPixelDataValid(pixel_data)); |
| 81 | |
| 82 | SbBlitterSurface surface = SbBlitterCreateSurfaceFromPixelData( |
| 83 | kSbBlitterInvalidDevice, pixel_data); |
| 84 | EXPECT_FALSE(SbBlitterIsSurfaceValid(surface)); |
| 85 | |
| 86 | EXPECT_TRUE(SbBlitterDestroyPixelData(pixel_data)); |
| 87 | } |
| 88 | |
| 89 | EXPECT_TRUE(SbBlitterDestroyDevice(device)); |
| 90 | } |
| 91 | |
| 92 | } // namespace |
| 93 | } // namespace nplb |
| 94 | } // namespace starboard |
| 95 | |
| 96 | #endif // SB_HAS(BLITTER) |