OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ | 5 #ifndef UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ |
6 #define UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ | 6 #define UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <CoreFoundation/CoreFoundation.h> | 9 #include <CoreFoundation/CoreFoundation.h> |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // |target| is the target type for the color buffer. | 117 // |target| is the target type for the color buffer. |
118 void AllocateRenderBuffers(GLenum target, const gfx::Size& size); | 118 void AllocateRenderBuffers(GLenum target, const gfx::Size& size); |
119 | 119 |
120 // Helper function to attach the buffers previously allocated by a call to | 120 // Helper function to attach the buffers previously allocated by a call to |
121 // AllocateRenderBuffers(). On return, |fbo_| can be used for | 121 // AllocateRenderBuffers(). On return, |fbo_| can be used for |
122 // rendering. |target| must be the same value as used in the call to | 122 // rendering. |target| must be the same value as used in the call to |
123 // AllocateRenderBuffers(). Returns |true| if the resulting framebuffer | 123 // AllocateRenderBuffers(). Returns |true| if the resulting framebuffer |
124 // object is valid. | 124 // object is valid. |
125 bool SetupFrameBufferObject(GLenum target); | 125 bool SetupFrameBufferObject(GLenum target); |
126 | 126 |
| 127 gfx::Size ClampToValidDimensions(const gfx::Size& size); |
| 128 |
127 // The OpenGL context, and pbuffer drawable, used to transfer data | 129 // The OpenGL context, and pbuffer drawable, used to transfer data |
128 // to the shared region (IOSurface or TransportDIB). Strictly | 130 // to the shared region (IOSurface or TransportDIB). Strictly |
129 // speaking, we do not need to allocate a GL context all of the | 131 // speaking, we do not need to allocate a GL context all of the |
130 // time. We only need one if (a) we are using the IOSurface code | 132 // time. We only need one if (a) we are using the IOSurface code |
131 // path, or (b) if we are allocating an FBO internally. | 133 // path, or (b) if we are allocating an FBO internally. |
132 scoped_refptr<gfx::GLSurface> gl_surface_; | 134 scoped_refptr<gfx::GLSurface> gl_surface_; |
133 scoped_refptr<gfx::GLContext> gl_context_; | 135 scoped_refptr<gfx::GLContext> gl_context_; |
134 // Either |io_surface_| or |transport_dib_| is a valid pointer, but not both. | 136 // Either |io_surface_| or |transport_dib_| is a valid pointer, but not both. |
135 // |io_surface_| is non-NULL if the IOSurface APIs are supported (Mac OS X | 137 // |io_surface_| is non-NULL if the IOSurface APIs are supported (Mac OS X |
136 // 10.6 and later). | 138 // 10.6 and later). |
137 // TODO(dspringer,kbr): Should the GPU backing store be encapsulated in its | 139 // TODO(dspringer,kbr): Should the GPU backing store be encapsulated in its |
138 // own class so all this implementation detail is hidden? | 140 // own class so all this implementation detail is hidden? |
139 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; | 141 base::mac::ScopedCFTypeRef<CFTypeRef> io_surface_; |
140 | 142 |
141 // The id of |io_surface_| or 0 if that's NULL. | 143 // The id of |io_surface_| or 0 if that's NULL. |
142 uint64 io_surface_id_; | 144 uint64 io_surface_id_; |
143 | 145 |
144 // TODO(dspringer): If we end up keeping this TransportDIB mechanism, this | 146 // TODO(dspringer): If we end up keeping this TransportDIB mechanism, this |
145 // should really be a scoped_ptr_malloc<>, with a deallocate functor that | 147 // should really be a scoped_ptr_malloc<>, with a deallocate functor that |
146 // runs |dib_free_callback_|. I was not able to figure out how to | 148 // runs |dib_free_callback_|. I was not able to figure out how to |
147 // make this work (or even compile). | 149 // make this work (or even compile). |
148 scoped_ptr<TransportDIB> transport_dib_; | 150 scoped_ptr<TransportDIB> transport_dib_; |
149 gfx::Size surface_size_; | 151 gfx::Size surface_size_; |
| 152 // It's important to avoid allocating zero-width or zero-height |
| 153 // IOSurfaces and textures on the Mac, so we clamp each to a minimum |
| 154 // of 1. This is the real size of the surface; surface_size_ is what |
| 155 // the user requested. |
| 156 gfx::Size real_surface_size_; |
150 // TODO(kbr): the FBO management should not be in this class at all. | 157 // TODO(kbr): the FBO management should not be in this class at all. |
151 // However, if it is factored out, care needs to be taken to not | 158 // However, if it is factored out, care needs to be taken to not |
152 // introduce another copy of the color data on the GPU; the direct | 159 // introduce another copy of the color data on the GPU; the direct |
153 // binding of the internal texture to the IOSurface saves a copy. | 160 // binding of the internal texture to the IOSurface saves a copy. |
154 bool allocate_fbo_; | 161 bool allocate_fbo_; |
155 // If the IOSurface code path is being used, then this texture | 162 // If the IOSurface code path is being used, then this texture |
156 // object is always allocated. Otherwise, it is only allocated if | 163 // object is always allocated. Otherwise, it is only allocated if |
157 // the user requests an FBO be allocated. | 164 // the user requests an FBO be allocated. |
158 GLuint texture_; | 165 GLuint texture_; |
159 // The FBO and renderbuffer are only allocated if allocate_fbo_ is | 166 // The FBO and renderbuffer are only allocated if allocate_fbo_ is |
160 // true. | 167 // true. |
161 GLuint fbo_; | 168 GLuint fbo_; |
162 GLuint depth_stencil_renderbuffer_; | 169 GLuint depth_stencil_renderbuffer_; |
163 // Allocate a TransportDIB in the renderer. | 170 // Allocate a TransportDIB in the renderer. |
164 scoped_ptr<Callback2<size_t, TransportDIB::Handle*>::Type> | 171 scoped_ptr<Callback2<size_t, TransportDIB::Handle*>::Type> |
165 dib_alloc_callback_; | 172 dib_alloc_callback_; |
166 scoped_ptr<Callback1<TransportDIB::Id>::Type> dib_free_callback_; | 173 scoped_ptr<Callback1<TransportDIB::Id>::Type> dib_free_callback_; |
167 }; | 174 }; |
168 | 175 |
169 #endif // UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ | 176 #endif // UI_GFX_SURFACE_ACCELERATED_SURFACE_MAC_H_ |
OLD | NEW |