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 "ui/gfx/mac/io_surface_manager.h" | 5 #include "ui/gfx/mac/io_surface.h" |
6 | 6 |
7 #include <IOSurface/IOSurface.h> | |
8 #include <stddef.h> | 7 #include <stddef.h> |
9 #include <stdint.h> | 8 #include <stdint.h> |
10 | 9 |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/mach_logging.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "ui/gfx/buffer_format_util.h" | 13 #include "ui/gfx/buffer_format_util.h" |
15 | 14 |
16 namespace gfx { | 15 namespace gfx { |
| 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 IOSurfaceManager* g_instance = NULL; | |
20 | |
21 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 19 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
22 const CFStringRef key, | 20 const CFStringRef key, |
23 int32_t value) { | 21 int32_t value) { |
24 base::ScopedCFTypeRef<CFNumberRef> number( | 22 base::ScopedCFTypeRef<CFNumberRef> number( |
25 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 23 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
26 CFDictionaryAddValue(dictionary, key, number.get()); | 24 CFDictionaryAddValue(dictionary, key, number.get()); |
27 } | 25 } |
28 | 26 |
29 int32_t BytesPerElement(gfx::BufferFormat format, int plane) { | 27 int32_t BytesPerElement(gfx::BufferFormat format, int plane) { |
30 switch (format) { | 28 switch (format) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 NOTREACHED(); | 80 NOTREACHED(); |
83 return 0; | 81 return 0; |
84 } | 82 } |
85 | 83 |
86 NOTREACHED(); | 84 NOTREACHED(); |
87 return 0; | 85 return 0; |
88 } | 86 } |
89 | 87 |
90 } // namespace | 88 } // namespace |
91 | 89 |
| 90 namespace internal { |
| 91 |
92 // static | 92 // static |
93 IOSurfaceManager* IOSurfaceManager::GetInstance() { | 93 mach_port_t IOSurfaceMachPortTraits::Retain(mach_port_t port) { |
94 DCHECK(g_instance); | 94 kern_return_t kr = |
95 return g_instance; | 95 mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1); |
| 96 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 97 << "IOSurfaceMachPortTraits::Retain mach_port_mod_refs"; |
| 98 return port; |
96 } | 99 } |
97 | 100 |
98 // static | 101 // static |
99 void IOSurfaceManager::SetInstance(IOSurfaceManager* instance) { | 102 void IOSurfaceMachPortTraits::Release(mach_port_t port) { |
100 DCHECK(!g_instance || !instance); | 103 kern_return_t kr = |
101 g_instance = instance; | 104 mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, -1); |
| 105 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) |
| 106 << "IOSurfaceMachPortTraits::Release mach_port_mod_refs"; |
102 } | 107 } |
103 | 108 |
104 // static | 109 } // namespace internal |
105 IOSurfaceRef IOSurfaceManager::CreateIOSurface(const gfx::Size& size, | 110 |
106 gfx::BufferFormat format) { | 111 IOSurfaceRef CreateIOSurface(const gfx::Size& size, gfx::BufferFormat format) { |
107 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); | 112 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
108 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( | 113 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
109 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); | 114 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
110 | 115 |
111 // Don't specify plane information unless there are indeed multiple planes | 116 // Don't specify plane information unless there are indeed multiple planes |
112 // because DisplayLink drivers do not support this. | 117 // because DisplayLink drivers do not support this. |
113 // http://crbug.com/527556 | 118 // http://crbug.com/527556 |
114 if (num_planes > 1) { | 119 if (num_planes > 1) { |
115 for (size_t plane = 0; plane < num_planes; ++plane) { | 120 for (size_t plane = 0; plane < num_planes; ++plane) { |
116 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); | 121 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); |
(...skipping 22 matching lines...) Expand all Loading... |
139 if (num_planes > 1) { | 144 if (num_planes > 1) { |
140 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); | 145 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
141 } else { | 146 } else { |
142 AddIntegerValue(properties, kIOSurfaceBytesPerElement, | 147 AddIntegerValue(properties, kIOSurfaceBytesPerElement, |
143 BytesPerElement(format, 0)); | 148 BytesPerElement(format, 0)); |
144 } | 149 } |
145 | 150 |
146 return IOSurfaceCreate(properties); | 151 return IOSurfaceCreate(properties); |
147 } | 152 } |
148 | 153 |
149 } // namespace content | 154 } // namespace gfx |
OLD | NEW |