Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: ui/gl/gl_image_io_surface_unittest.cc

Issue 1419733005: gpu: Add YCbCr 420v extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on master. Add gl/gfx namespace qualifiers. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gl/gl_image_io_surface_unittest.cc
diff --git a/ui/gl/gl_image_io_surface_unittest.cc b/ui/gl/gl_image_io_surface_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e8f73ed5aa42dc69302039528620ce9ba6b15f83
--- /dev/null
+++ b/ui/gl/gl_image_io_surface_unittest.cc
@@ -0,0 +1,93 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gl/gl_image_io_surface.h"
+#include "ui/gl/test/gl_image_test_template.h"
+
+namespace gfx {
+namespace {
+void AddIntegerValue(CFMutableDictionaryRef dictionary,
+ const CFStringRef key,
+ int32 value) {
+ base::ScopedCFTypeRef<CFNumberRef> number(
+ CFNumberCreate(NULL, kCFNumberSInt32Type, &value));
+ CFDictionaryAddValue(dictionary, key, number.get());
+}
+
+IOSurfaceRef CreateIOSurface(const Size& size) {
+ size_t num_planes = 2;
+ base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable(
+ kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks));
+
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_y(
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ AddIntegerValue(plane_y, kIOSurfacePlaneWidth, size.width());
+ AddIntegerValue(plane_y, kIOSurfacePlaneHeight, size.height());
+ AddIntegerValue(plane_y, kIOSurfacePlaneBytesPerElement, 1);
+ CFArrayAppendValue(planes, plane_y);
+
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_uv(
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ AddIntegerValue(plane_uv, kIOSurfacePlaneWidth, size.width() / 2);
+ AddIntegerValue(plane_uv, kIOSurfacePlaneHeight, size.height() / 2);
+ AddIntegerValue(plane_uv, kIOSurfacePlaneBytesPerElement, 2);
+ CFArrayAppendValue(planes, plane_uv);
+
+ base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ AddIntegerValue(properties, kIOSurfaceWidth, size.width());
+ AddIntegerValue(properties, kIOSurfaceHeight, size.height());
+ AddIntegerValue(properties, kIOSurfacePixelFormat, '420v');
+ CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes);
+
+ return IOSurfaceCreate(properties);
+}
+
+class GLImageIOSurface420vTestDelegate {
+ public:
+ scoped_refptr<gl::GLImage> CreateSolidColorImage(
+ const Size& size,
+ const uint8_t color[4]) const {
+ scoped_refptr<gl::GLImageIOSurface> image(
+ new gl::GLImageIOSurface(size, GL_RGB_YCBCR_420V_CHROMIUM));
+ IOSurfaceRef surface_ref = CreateIOSurface(size);
+ IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr);
+ EXPECT_NE(status, kIOReturnCannotLock);
+ void* y_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 0);
+ void* uv_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 1);
+ uint8_t* data[] = {static_cast<uint8_t*>(y_data),
+ static_cast<uint8_t*>(uv_data)};
+ int strides[] = {IOSurfaceGetBytesPerRowOfPlane(surface_ref, 0),
+ IOSurfaceGetBytesPerRowOfPlane(surface_ref, 1)};
+
+ GLImageTestSupport::SetBufferDataToColor(
+ size.width(), size.height(), strides, BufferFormat::YUV_420_BIPLANAR,
+ color, data);
+ IOSurfaceUnlock(surface_ref, 0, nullptr);
+
+ bool rv = image->Initialize(surface_ref, GenericSharedMemoryId(1),
+ BufferFormat::YUV_420_BIPLANAR);
+ EXPECT_TRUE(rv);
+
+ return image;
+ }
+};
+
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface,
+ GLImageTest,
+ GLImageIOSurface420vTestDelegate);
+
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface,
+ GLImageCopyTest,
+ GLImageIOSurface420vTestDelegate);
+
+} // namespace
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698