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 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ | 5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ |
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ | 6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_ |
7 | 7 |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "content/common/gpu/image_transport_surface_fbo_mac.h" | 9 #include "content/common/gpu/image_transport_surface_fbo_mac.h" |
10 #include "ui/base/cocoa/remote_layer_api.h" | 10 #include "ui/base/cocoa/remote_layer_api.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/scoped_cgl.h" | 12 #include "ui/gl/scoped_cgl.h" |
13 | 13 |
14 @interface ImageTransportLayer : CAOpenGLLayer { | 14 @class ImageTransportLayer; |
15 base::ScopedTypeRef<CGLContextObj> shareContext_; | |
16 GLuint texture_; | |
17 gfx::Size pixelSize_; | |
18 } | |
19 @end | |
20 | 15 |
21 namespace content { | 16 namespace content { |
22 | 17 |
23 // Allocate CAOpenGLLayer-backed storage for an FBO image transport surface. | 18 // Allocate CAOpenGLLayer-backed storage for an FBO image transport surface. |
24 class CALayerStorageProvider | 19 class CALayerStorageProvider |
25 : public ImageTransportSurfaceFBO::StorageProvider { | 20 : public ImageTransportSurfaceFBO::StorageProvider { |
26 public: | 21 public: |
27 CALayerStorageProvider(); | 22 CALayerStorageProvider(ImageTransportSurfaceFBO* transport_surface); |
28 virtual ~CALayerStorageProvider(); | 23 virtual ~CALayerStorageProvider(); |
29 | 24 |
30 // ImageTransportSurfaceFBO::StorageProvider implementation: | 25 // ImageTransportSurfaceFBO::StorageProvider implementation: |
31 virtual gfx::Size GetRoundedSize(gfx::Size size) OVERRIDE; | 26 virtual gfx::Size GetRoundedSize(gfx::Size size) OVERRIDE; |
32 virtual bool AllocateColorBufferStorage( | 27 virtual bool AllocateColorBufferStorage( |
33 CGLContextObj context, GLuint texture, | 28 CGLContextObj context, GLuint texture, |
34 gfx::Size pixel_size, float scale_factor) OVERRIDE; | 29 gfx::Size pixel_size, float scale_factor) OVERRIDE; |
35 virtual void FreeColorBufferStorage() OVERRIDE; | 30 virtual void FreeColorBufferStorage() OVERRIDE; |
36 virtual uint64 GetSurfaceHandle() const OVERRIDE; | 31 virtual uint64 GetSurfaceHandle() const OVERRIDE; |
37 virtual void WillSwapBuffers() OVERRIDE; | 32 virtual void WillSwapBuffers() OVERRIDE; |
| 33 virtual void CanFreeSwappedBuffer() OVERRIDE; |
| 34 |
| 35 // Interface to ImageTransportLayer: |
| 36 CGLContextObj LayerShareGroupContext(); |
| 37 bool LayerCanDraw(); |
| 38 void LayerDoDraw(); |
38 | 39 |
39 private: | 40 private: |
| 41 ImageTransportSurfaceFBO* transport_surface_; |
| 42 |
| 43 // Set when a new swap occurs, and un-set when |layer_| draws that frame. |
| 44 bool has_pending_draw_; |
| 45 |
| 46 // A counter that is incremented whenever LayerCanDraw returns false. If this |
| 47 // reaches a threshold, then |layer_| is switched to synchronous drawing to |
| 48 // save CPU work. |
| 49 uint32 can_draw_returned_false_count_; |
| 50 |
| 51 // The texture with the pixels to draw, and the share group it is allocated |
| 52 // in. |
| 53 base::ScopedTypeRef<CGLContextObj> share_group_context_; |
| 54 GLuint fbo_texture_; |
| 55 gfx::Size fbo_pixel_size_; |
| 56 |
| 57 // The CALayer that the current frame is being drawn into. |
40 base::scoped_nsobject<CAContext> context_; | 58 base::scoped_nsobject<CAContext> context_; |
41 base::scoped_nsobject<ImageTransportLayer> layer_; | 59 base::scoped_nsobject<ImageTransportLayer> layer_; |
42 | 60 |
43 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider); | 61 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider); |
44 }; | 62 }; |
45 | 63 |
46 } // namespace content | 64 } // namespace content |
47 | 65 |
48 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_CALAYER_MAC_H_ | 66 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_CALAYER_MAC_H_ |
OLD | NEW |