OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/gl/gl_image_ref_counted_memory.h" | 11 #include "ui/gl/gl_image_ref_counted_memory.h" |
| 12 #include "ui/gl/gl_utils.h" |
12 #include "ui/gl/test/gl_image_test_template.h" | 13 #include "ui/gl/test/gl_image_test_template.h" |
13 | 14 |
14 namespace gl { | 15 namespace gl { |
15 namespace { | 16 namespace { |
16 | 17 |
17 template <gfx::BufferFormat format> | |
18 class GLImageRefCountedMemoryTestDelegate { | 18 class GLImageRefCountedMemoryTestDelegate { |
19 public: | 19 public: |
20 scoped_refptr<gl::GLImage> CreateSolidColorImage( | 20 scoped_refptr<gl::GLImage> CreateSolidColorImage( |
21 const gfx::Size& size, | 21 const gfx::Size& size, |
| 22 gfx::BufferFormat format, |
22 const uint8_t color[4]) const { | 23 const uint8_t color[4]) const { |
23 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); | 24 DCHECK_EQ(NumberOfPlanesForBufferFormat(format), 1u); |
24 std::vector<uint8_t> data(gfx::BufferSizeForBufferFormat(size, format)); | 25 std::vector<uint8_t> data(gfx::BufferSizeForBufferFormat(size, format)); |
25 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); | 26 scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data)); |
26 GLImageTestSupport::SetBufferDataToColor( | 27 GLImageTestSupport::SetBufferDataToColor( |
27 size.width(), size.height(), | 28 size.width(), size.height(), |
28 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0, | 29 static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0, |
29 format, color, &bytes->data().front()); | 30 format, color, &bytes->data().front()); |
30 scoped_refptr<GLImageRefCountedMemory> image(new GLImageRefCountedMemory( | 31 scoped_refptr<GLImageRefCountedMemory> image( |
31 size, gl::GLImageMemory::GetInternalFormatForTesting(format))); | 32 new GLImageRefCountedMemory(size, gl::GetTextureFormatFrom(format))); |
32 bool rv = image->Initialize(bytes.get(), format); | 33 bool rv = image->Initialize(bytes.get(), format); |
33 EXPECT_TRUE(rv); | 34 EXPECT_TRUE(rv); |
34 return image; | 35 return image; |
35 } | 36 } |
| 37 |
| 38 static bool IsSupported(gfx::BufferFormat format) { |
| 39 switch (format) { |
| 40 case gfx::BufferFormat::RGBX_8888: |
| 41 case gfx::BufferFormat::RGBA_8888: |
| 42 case gfx::BufferFormat::BGRX_8888: |
| 43 case gfx::BufferFormat::BGRA_8888: |
| 44 return true; |
| 45 default: |
| 46 return false; |
| 47 } |
| 48 NOTREACHED(); |
| 49 return false; |
| 50 } |
36 }; | 51 }; |
37 | 52 |
38 using GLImageTestTypes = testing::Types< | |
39 GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>, | |
40 GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>, | |
41 GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>, | |
42 GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>; | |
43 | |
44 INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory, | 53 INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory, |
45 GLImageTest, | 54 GLImageTest, |
46 GLImageTestTypes); | 55 GLImageRefCountedMemoryTestDelegate); |
47 | 56 |
48 INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory, | 57 INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory, |
49 GLImageCopyTest, | 58 GLImageCopyTest, |
50 GLImageTestTypes); | 59 GLImageRefCountedMemoryTestDelegate); |
51 | 60 |
52 } // namespace | 61 } // namespace |
53 } // namespace gl | 62 } // namespace gl |
OLD | NEW |