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> | 7 #include <IOSurface/IOSurface.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "ui/gfx/buffer_format_util.h" | 11 #include "ui/gfx/buffer_format_util.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 namespace { | 14 namespace { |
15 | 15 |
16 IOSurfaceManager* g_instance = NULL; | |
17 | |
18 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 16 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
19 const CFStringRef key, | 17 const CFStringRef key, |
20 int32 value) { | 18 int32 value) { |
21 base::ScopedCFTypeRef<CFNumberRef> number( | 19 base::ScopedCFTypeRef<CFNumberRef> number( |
22 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 20 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
23 CFDictionaryAddValue(dictionary, key, number.get()); | 21 CFDictionaryAddValue(dictionary, key, number.get()); |
24 } | 22 } |
25 | 23 |
26 int32 BytesPerElement(gfx::BufferFormat format, int plane) { | 24 int32 BytesPerElement(gfx::BufferFormat format, int plane) { |
27 switch (format) { | 25 switch (format) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 NOTREACHED(); | 77 NOTREACHED(); |
80 return 0; | 78 return 0; |
81 } | 79 } |
82 | 80 |
83 NOTREACHED(); | 81 NOTREACHED(); |
84 return 0; | 82 return 0; |
85 } | 83 } |
86 | 84 |
87 } // namespace | 85 } // namespace |
88 | 86 |
89 // static | 87 IOSurfaceRef CreateIOSurface(const gfx::Size& size, gfx::BufferFormat format) { |
90 IOSurfaceManager* IOSurfaceManager::GetInstance() { | |
91 DCHECK(g_instance); | |
92 return g_instance; | |
93 } | |
94 | |
95 // static | |
96 void IOSurfaceManager::SetInstance(IOSurfaceManager* instance) { | |
97 DCHECK(!g_instance || !instance); | |
98 g_instance = instance; | |
99 } | |
100 | |
101 // static | |
102 IOSurfaceRef IOSurfaceManager::CreateIOSurface(const gfx::Size& size, | |
103 gfx::BufferFormat format) { | |
104 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); | 88 size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
105 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( | 89 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
106 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); | 90 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
107 | 91 |
108 // Don't specify plane information unless there are indeed multiple planes | 92 // Don't specify plane information unless there are indeed multiple planes |
109 // because DisplayLink drivers do not support this. | 93 // because DisplayLink drivers do not support this. |
110 // http://crbug.com/527556 | 94 // http://crbug.com/527556 |
111 if (num_planes > 1) { | 95 if (num_planes > 1) { |
112 for (size_t plane = 0; plane < num_planes; ++plane) { | 96 for (size_t plane = 0; plane < num_planes; ++plane) { |
113 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); | 97 size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane); |
(...skipping 23 matching lines...) Expand all Loading... |
137 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); | 121 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
138 } else { | 122 } else { |
139 AddIntegerValue(properties, kIOSurfaceBytesPerElement, | 123 AddIntegerValue(properties, kIOSurfaceBytesPerElement, |
140 BytesPerElement(format, 0)); | 124 BytesPerElement(format, 0)); |
141 } | 125 } |
142 | 126 |
143 return IOSurfaceCreate(properties); | 127 return IOSurfaceCreate(properties); |
144 } | 128 } |
145 | 129 |
146 } // namespace content | 130 } // namespace content |
OLD | NEW |