OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/gpu/image_transport_surface_iosurface_mac.h" | 5 #include "content/common/gpu/image_transport_surface_iosurface_mac.h" |
6 | 6 |
7 #include "content/common/gpu/gpu_messages.h" | 7 #include "content/common/gpu/gpu_messages.h" |
| 8 #include "content/common/gpu/surface_handle_types_mac.h" |
8 | 9 |
9 namespace content { | 10 namespace content { |
10 namespace { | 11 namespace { |
11 | 12 |
12 // IOSurface dimensions will be rounded up to a multiple of this value in order | 13 // IOSurface dimensions will be rounded up to a multiple of this value in order |
13 // to reduce memory thrashing during resize. This must be a power of 2. | 14 // to reduce memory thrashing during resize. This must be a power of 2. |
14 const uint32 kIOSurfaceDimensionRoundup = 64; | 15 const uint32 kIOSurfaceDimensionRoundup = 64; |
15 | 16 |
16 int RoundUpSurfaceDimension(int number) { | 17 int RoundUpSurfaceDimension(int number) { |
17 DCHECK(number >= 0); | 18 DCHECK(number >= 0); |
(...skipping 26 matching lines...) Expand all Loading... |
44 IOSurfaceStorageProvider::~IOSurfaceStorageProvider() { | 45 IOSurfaceStorageProvider::~IOSurfaceStorageProvider() { |
45 DCHECK(!io_surface_); | 46 DCHECK(!io_surface_); |
46 } | 47 } |
47 | 48 |
48 gfx::Size IOSurfaceStorageProvider::GetRoundedSize(gfx::Size size) { | 49 gfx::Size IOSurfaceStorageProvider::GetRoundedSize(gfx::Size size) { |
49 return gfx::Size(RoundUpSurfaceDimension(size.width()), | 50 return gfx::Size(RoundUpSurfaceDimension(size.width()), |
50 RoundUpSurfaceDimension(size.height())); | 51 RoundUpSurfaceDimension(size.height())); |
51 } | 52 } |
52 | 53 |
53 bool IOSurfaceStorageProvider::AllocateColorBufferStorage( | 54 bool IOSurfaceStorageProvider::AllocateColorBufferStorage( |
54 CGLContextObj context, | 55 CGLContextObj context, gfx::Size pixel_size, float scale_factor) { |
55 gfx::Size size) { | |
56 // Allocate a new IOSurface, which is the GPU resource that can be | 56 // Allocate a new IOSurface, which is the GPU resource that can be |
57 // shared across processes. | 57 // shared across processes. |
58 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 58 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
59 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 59 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
60 0, | 60 0, |
61 &kCFTypeDictionaryKeyCallBacks, | 61 &kCFTypeDictionaryKeyCallBacks, |
62 &kCFTypeDictionaryValueCallBacks)); | 62 &kCFTypeDictionaryValueCallBacks)); |
63 AddIntegerValue(properties, | 63 AddIntegerValue(properties, |
64 kIOSurfaceWidth, | 64 kIOSurfaceWidth, |
65 size.width()); | 65 pixel_size.width()); |
66 AddIntegerValue(properties, | 66 AddIntegerValue(properties, |
67 kIOSurfaceHeight, | 67 kIOSurfaceHeight, |
68 size.height()); | 68 pixel_size.height()); |
69 AddIntegerValue(properties, | 69 AddIntegerValue(properties, |
70 kIOSurfaceBytesPerElement, 4); | 70 kIOSurfaceBytesPerElement, 4); |
71 AddBooleanValue(properties, | 71 AddBooleanValue(properties, |
72 kIOSurfaceIsGlobal, true); | 72 kIOSurfaceIsGlobal, true); |
73 // I believe we should be able to unreference the IOSurfaces without | 73 // I believe we should be able to unreference the IOSurfaces without |
74 // synchronizing with the browser process because they are | 74 // synchronizing with the browser process because they are |
75 // ultimately reference counted by the operating system. | 75 // ultimately reference counted by the operating system. |
76 io_surface_.reset(IOSurfaceCreate(properties)); | 76 io_surface_.reset(IOSurfaceCreate(properties)); |
77 io_surface_handle_ = IOSurfaceGetID(io_surface_); | 77 io_surface_id_ = IOSurfaceGetID(io_surface_); |
78 | 78 |
79 // Don't think we need to identify a plane. | 79 // Don't think we need to identify a plane. |
80 GLuint plane = 0; | 80 GLuint plane = 0; |
81 CGLError cglerror = CGLTexImageIOSurface2D( | 81 CGLError cglerror = CGLTexImageIOSurface2D( |
82 context, | 82 context, |
83 GL_TEXTURE_RECTANGLE_ARB, | 83 GL_TEXTURE_RECTANGLE_ARB, |
84 GL_RGBA, | 84 GL_RGBA, |
85 size.width(), | 85 pixel_size.width(), |
86 size.height(), | 86 pixel_size.height(), |
87 GL_BGRA, | 87 GL_BGRA, |
88 GL_UNSIGNED_INT_8_8_8_8_REV, | 88 GL_UNSIGNED_INT_8_8_8_8_REV, |
89 io_surface_.get(), | 89 io_surface_.get(), |
90 plane); | 90 plane); |
91 if (cglerror != kCGLNoError) { | 91 if (cglerror != kCGLNoError) { |
92 DLOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cglerror; | 92 DLOG(ERROR) << "CGLTexImageIOSurface2D failed with CGL error: " << cglerror; |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 glFlush(); | 96 glFlush(); |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 void IOSurfaceStorageProvider::FreeColorBufferStorage() { | 100 void IOSurfaceStorageProvider::FreeColorBufferStorage() { |
101 io_surface_.reset(); | 101 io_surface_.reset(); |
102 io_surface_handle_ = 0; | 102 io_surface_id_ = 0; |
103 } | 103 } |
104 | 104 |
105 uint64 IOSurfaceStorageProvider::GetSurfaceHandle() const { | 105 uint64 IOSurfaceStorageProvider::GetSurfaceHandle() const { |
106 return io_surface_handle_; | 106 return SurfaceHandleFromIOSurfaceID(io_surface_id_); |
| 107 } |
| 108 |
| 109 void IOSurfaceStorageProvider::WillSwapBuffers() { |
107 } | 110 } |
108 | 111 |
109 } // namespace content | 112 } // namespace content |
OLD | NEW |