File: io_surface.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 4,010 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_MAC_IO_SURFACE_H_
#define UI_GFX_MAC_IO_SURFACE_H_

#include <IOSurface/IOSurfaceRef.h>
#include <mach/mach.h>

#include "base/apple/scoped_cftyperef.h"
#include "base/component_export.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/generic_shared_memory_id.h"
#include "ui/gfx/geometry/size.h"

namespace gfx {

namespace internal {

struct IOSurfaceMachPortTraits {
  COMPONENT_EXPORT(GFX) static mach_port_t InvalidValue() {
    return MACH_PORT_NULL;
  }
  COMPONENT_EXPORT(GFX) static mach_port_t Retain(mach_port_t);
  COMPONENT_EXPORT(GFX) static void Release(mach_port_t);
};

struct ScopedInUseIOSurfaceTraits {
  static IOSurfaceRef InvalidValue() { return nullptr; }
  static IOSurfaceRef Retain(IOSurfaceRef io_surface) {
    CFRetain(io_surface);
    IOSurfaceIncrementUseCount(io_surface);
    return io_surface;
  }
  static void Release(IOSurfaceRef io_surface) {
    IOSurfaceDecrementUseCount(io_surface);
    CFRelease(io_surface);
  }
};

}  // namespace internal

using IOSurfaceId = GenericSharedMemoryId;

// Helper function to create an IOSurface with a specified size and format.
// The surface is zero-initialized if |should_clear| is true. This is not
// necessary for anonymous surfaces that are not exported to renderers and used
// as render targets only. If |override_rgba_to_bgra| is true (default) a BGRA
// IOSurface is created for RGBA/X_8888 BufferFormat. This is needed for GL
// usage since neither ANGLE Metal nor CGL support importing RGBA IOSurfaces,
// whereas for non-GL backends (Dawn and Metal) we want the formats to match.
// TODO(sunnyps): Revisit this when we switch to ANGLE Metal completely since
// wrapping RGBA_8888 can be implemented with Metal quite easily.
COMPONENT_EXPORT(GFX)
base::apple::ScopedCFTypeRef<IOSurfaceRef> CreateIOSurface(
    const Size& size,
    BufferFormat format,
    bool should_clear = true,
#if BUILDFLAG(IS_IOS)
    bool override_rgba_to_bgra = false
#else
    bool override_rgba_to_bgra = true
#endif
);

// A scoper for handling Mach port names that are send rights for IOSurfaces.
// This scoper is both copyable and assignable, which will increase the kernel
// reference count of the right. On destruction, the reference count is
// decremented.
using ScopedRefCountedIOSurfaceMachPort =
    base::apple::ScopedTypeRef<mach_port_t, internal::IOSurfaceMachPortTraits>;

// A scoper for holding a reference to an IOSurface and also incrementing its
// in-use counter while the scoper exists.
using ScopedInUseIOSurface =
    base::apple::ScopedTypeRef<IOSurfaceRef,
                               internal::ScopedInUseIOSurfaceTraits>;

// A scoper for holding a reference to an IOSurface.
using ScopedIOSurface = base::apple::ScopedCFTypeRef<IOSurfaceRef>;

// Return true if there exists a value for IOSurfaceColorSpace or
// IOSurfaceICCProfile that will make CoreAnimation render using |color_space|.
COMPONENT_EXPORT(GFX)
bool IOSurfaceCanSetColorSpace(const gfx::ColorSpace& color_space);

// Set color space for given IOSurface. IOSurfaceCanSetColorSpace must return
// true for |color_space| otherwise this does nothing.
COMPONENT_EXPORT(GFX)
void IOSurfaceSetColorSpace(IOSurfaceRef io_surface,
                            const gfx::ColorSpace& color_space);

// Return the expected four character code pixel format for an IOSurface with
// the specified gfx::BufferFormat.
COMPONENT_EXPORT(GFX)
uint32_t BufferFormatToIOSurfacePixelFormat(gfx::BufferFormat format,
                                            bool override_rgba_to_bgra = true);

// Return an IOSurface consuming |io_surface_mach_port|.
COMPONENT_EXPORT(GFX)
base::apple::ScopedCFTypeRef<IOSurfaceRef> IOSurfaceMachPortToIOSurface(
    ScopedRefCountedIOSurfaceMachPort io_surface_mach_port);

}  // namespace gfx

#endif  // UI_GFX_MAC_IO_SURFACE_H_