[NaCl SDK]: use standard __BEGIN_DECLS macros in sys/select.h
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_calayer_mac.h
blob96a01e484c83bc053ad74dc5bd8b5331bf1b58ea
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_CALAYER_MAC_H_
8 #include "base/mac/scoped_nsobject.h"
9 #include "content/common/gpu/image_transport_surface_fbo_mac.h"
10 #include "ui/base/cocoa/remote_layer_api.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/scoped_cgl.h"
14 @class ImageTransportLayer;
16 namespace content {
18 // Allocate CAOpenGLLayer-backed storage for an FBO image transport surface.
19 class CALayerStorageProvider
20 : public ImageTransportSurfaceFBO::StorageProvider {
21 public:
22 CALayerStorageProvider(ImageTransportSurfaceFBO* transport_surface);
23 virtual ~CALayerStorageProvider();
25 // ImageTransportSurfaceFBO::StorageProvider implementation:
26 virtual gfx::Size GetRoundedSize(gfx::Size size) OVERRIDE;
27 virtual bool AllocateColorBufferStorage(
28 CGLContextObj context, GLuint texture,
29 gfx::Size pixel_size, float scale_factor) OVERRIDE;
30 virtual void FreeColorBufferStorage() OVERRIDE;
31 virtual void SwapBuffers(const gfx::Size& size, float scale_factor) OVERRIDE;
32 virtual void WillWriteToBackbuffer() OVERRIDE;
33 virtual void DiscardBackbuffer() OVERRIDE;
34 virtual void SwapBuffersAckedByBrowser() OVERRIDE;
36 // Interface to ImageTransportLayer:
37 CGLContextObj LayerShareGroupContext();
38 bool LayerCanDraw();
39 void LayerDoDraw();
40 void LayerResetStorageProvider();
42 private:
43 void DrawWithVsyncDisabled();
44 void SendPendingSwapToBrowserAfterFrameDrawn();
46 ImageTransportSurfaceFBO* transport_surface_;
48 // Used to determine if we should use setNeedsDisplay or setAsynchronous to
49 // animate.
50 const bool gpu_vsync_disabled_;
52 // Set when a new swap occurs, and un-set when |layer_| draws that frame.
53 bool has_pending_draw_;
55 // A counter that is incremented whenever LayerCanDraw returns false. If this
56 // reaches a threshold, then |layer_| is switched to synchronous drawing to
57 // save CPU work.
58 uint32 can_draw_returned_false_count_;
60 // The texture with the pixels to draw, and the share group it is allocated
61 // in.
62 base::ScopedTypeRef<CGLContextObj> share_group_context_;
63 GLuint fbo_texture_;
64 gfx::Size fbo_pixel_size_;
65 float fbo_scale_factor_;
67 // The CALayer that the current frame is being drawn into.
68 base::scoped_nsobject<CAContext> context_;
69 base::scoped_nsobject<ImageTransportLayer> layer_;
71 base::WeakPtrFactory<CALayerStorageProvider> weak_factory_;
72 DISALLOW_COPY_AND_ASSIGN(CALayerStorageProvider);
75 } // namespace content
77 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_CALAYER_MAC_H_