rsesek | 5c7c3e9 | 2016-01-05 03:37:11 | [diff] [blame] | 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 | |
| 5 | #ifndef UI_GFX_MAC_IO_SURFACE_H_ |
| 6 | #define UI_GFX_MAC_IO_SURFACE_H_ |
| 7 | |
| 8 | #include <IOSurface/IOSurface.h> |
| 9 | #include <mach/mach.h> |
| 10 | |
| 11 | #include "base/mac/scoped_cftyperef.h" |
| 12 | #include "ui/gfx/buffer_types.h" |
Sunny Sachanandani | 88353d2 | 2017-10-26 01:52:24 | [diff] [blame^] | 13 | #include "ui/gfx/color_space.h" |
rsesek | 5c7c3e9 | 2016-01-05 03:37:11 | [diff] [blame] | 14 | #include "ui/gfx/generic_shared_memory_id.h" |
| 15 | #include "ui/gfx/geometry/size.h" |
| 16 | #include "ui/gfx/gfx_export.h" |
| 17 | |
| 18 | namespace gfx { |
| 19 | |
| 20 | namespace internal { |
| 21 | |
| 22 | struct IOSurfaceMachPortTraits { |
| 23 | GFX_EXPORT static mach_port_t InvalidValue() { return MACH_PORT_NULL; } |
| 24 | GFX_EXPORT static mach_port_t Retain(mach_port_t); |
| 25 | GFX_EXPORT static void Release(mach_port_t); |
| 26 | }; |
| 27 | |
ccameron | 69a2dae | 2016-03-28 03:23:45 | [diff] [blame] | 28 | struct ScopedInUseIOSurfaceTraits { |
| 29 | static IOSurfaceRef InvalidValue() { return nullptr; } |
| 30 | static IOSurfaceRef Retain(IOSurfaceRef io_surface) { |
| 31 | CFRetain(io_surface); |
| 32 | IOSurfaceIncrementUseCount(io_surface); |
| 33 | return io_surface; |
| 34 | } |
| 35 | static void Release(IOSurfaceRef io_surface) { |
| 36 | IOSurfaceDecrementUseCount(io_surface); |
| 37 | CFRelease(io_surface); |
| 38 | } |
| 39 | }; |
| 40 | |
rsesek | 5c7c3e9 | 2016-01-05 03:37:11 | [diff] [blame] | 41 | } // namespace internal |
| 42 | |
| 43 | using IOSurfaceId = GenericSharedMemoryId; |
| 44 | |
| 45 | // Helper function to create an IOSurface with a specified size and format. |
| 46 | GFX_EXPORT IOSurfaceRef CreateIOSurface(const Size& size, BufferFormat format); |
| 47 | |
| 48 | // A scoper for handling Mach port names that are send rights for IOSurfaces. |
| 49 | // This scoper is both copyable and assignable, which will increase the kernel |
| 50 | // reference count of the right. On destruction, the reference count is |
| 51 | // decremented. |
| 52 | using ScopedRefCountedIOSurfaceMachPort = |
| 53 | base::ScopedTypeRef<mach_port_t, internal::IOSurfaceMachPortTraits>; |
| 54 | |
ccameron | 69a2dae | 2016-03-28 03:23:45 | [diff] [blame] | 55 | // A scoper for holding a reference to an IOSurface and also incrementing its |
| 56 | // in-use counter while the scoper exists. |
| 57 | using ScopedInUseIOSurface = |
| 58 | base::ScopedTypeRef<IOSurfaceRef, internal::ScopedInUseIOSurfaceTraits>; |
| 59 | |
Sunny Sachanandani | 88353d2 | 2017-10-26 01:52:24 | [diff] [blame^] | 60 | // Set color space for given IOSurface. Color space must have an associated ICC |
| 61 | // color profile otherwise this function does nothing. |
| 62 | GFX_EXPORT void IOSurfaceSetColorSpace(IOSurfaceRef io_surface, |
| 63 | const gfx::ColorSpace& color_space); |
| 64 | |
rsesek | 5c7c3e9 | 2016-01-05 03:37:11 | [diff] [blame] | 65 | } // namespace gfx |
| 66 | |
| 67 | #endif // UI_GFX_MAC_IO_SURFACE_H_ |