gl_image_ref_counted_memory_unittest.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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
  3. // found in the LICENSE file.
  4. #include <stdint.h>
  5. #include <vector>
  6. #include "base/memory/ref_counted_memory.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "ui/gl/gl_image_ref_counted_memory.h"
  9. #include "ui/gl/test/gl_image_test_template.h"
  10. namespace gl {
  11. namespace {
  12. const uint8_t kGreen[] = {0x0, 0xFF, 0x0, 0xFF};
  13. template <gfx::BufferFormat format>
  14. class GLImageRefCountedMemoryTestDelegate : public GLImageTestDelegateBase {
  15. public:
  16. scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size,
  17. const uint8_t color[4]) const {
  18. DCHECK_EQ(NumberOfPlanesForLinearBufferFormat(format), 1u);
  19. std::vector<uint8_t> data(gfx::BufferSizeForBufferFormat(size, format));
  20. scoped_refptr<base::RefCountedBytes> bytes(new base::RefCountedBytes(data));
  21. GLImageTestSupport::SetBufferDataToColor(
  22. size.width(), size.height(),
  23. static_cast<int>(RowSizeForBufferFormat(size.width(), format, 0)), 0,
  24. format, color, &bytes->data().front());
  25. auto image = base::MakeRefCounted<GLImageRefCountedMemory>(size);
  26. bool rv = image->Initialize(bytes.get(), format);
  27. EXPECT_TRUE(rv);
  28. return image;
  29. }
  30. unsigned GetTextureTarget() const { return GL_TEXTURE_2D; }
  31. const uint8_t* GetImageColor() { return kGreen; }
  32. int GetAdmissibleError() const { return 0; }
  33. };
  34. using GLImageTestTypes = testing::Types<
  35. GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>,
  36. GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>,
  37. GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>,
  38. GLImageRefCountedMemoryTestDelegate<gfx::BufferFormat::BGRA_8888>>;
  39. INSTANTIATE_TYPED_TEST_SUITE_P(GLImageRefCountedMemory,
  40. GLImageTest,
  41. GLImageTestTypes);
  42. INSTANTIATE_TYPED_TEST_SUITE_P(GLImageRefCountedMemory,
  43. GLImageCopyTest,
  44. GLImageTestTypes);
  45. } // namespace
  46. } // namespace gl