Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_fbo_mac.h
blobd5a0c2011f86140c01459f0d57a8f40d1e075855
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_FBO_MAC_H_
6 #define CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_FBO_MAC_H_
8 #include "base/mac/scoped_cftyperef.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/gpu/gpu_command_buffer_stub.h"
11 #include "content/common/gpu/image_transport_surface.h"
12 #include "ui/gl/gl_bindings.h"
14 namespace content {
16 // We are backed by an offscreen surface for the purposes of creating
17 // a context, but use FBOs to render to texture. The texture may be backed by
18 // an IOSurface, or it may be presented to the screen via a CALayer, depending
19 // on the StorageProvider class specified.
20 class ImageTransportSurfaceFBO
21 : public gfx::GLSurface,
22 public ImageTransportSurface,
23 public GpuCommandBufferStub::DestructionObserver {
24 public:
25 // The interface through which storage for the color buffer of the FBO is
26 // allocated.
27 class StorageProvider {
28 public:
29 virtual ~StorageProvider() {}
30 // IOSurfaces cause too much address space fragmentation if they are
31 // allocated on every resize. This gets a rounded size for allocation.
32 virtual gfx::Size GetRoundedSize(gfx::Size size) = 0;
34 // Allocate the storage for the color buffer. The specified context is
35 // current, and there is a texture bound to GL_TEXTURE_RECTANGLE_ARB.
36 virtual bool AllocateColorBufferStorage(
37 CGLContextObj context, const base::Closure& context_dirtied_callback,
38 GLuint texture, gfx::Size size, float scale_factor) = 0;
40 // Free the storage allocated in the AllocateColorBufferStorage call. The
41 // GL texture that was bound has already been deleted by the caller.
42 virtual void FreeColorBufferStorage() = 0;
44 // Called when the frame size has changed (the buffer may not have been
45 // reallocated, since its size may be rounded).
46 virtual void FrameSizeChanged(
47 const gfx::Size& pixel_size, float scale_factor) = 0;
49 // Swap buffers, or post sub-buffer.
50 virtual void SwapBuffers() = 0;
52 // Indicate that the backbuffer will be written to.
53 virtual void WillWriteToBackbuffer() = 0;
55 // Indicate that the backbuffer has been discarded and should not be seen
56 // again.
57 virtual void DiscardBackbuffer() = 0;
59 // Called once for every SwapBuffers call when the IPC for the present has
60 // been processed by the browser. |disable_throttling| is set if the
61 // browser suspects that GPU back-pressure should be disabled.
62 virtual void SwapBuffersAckedByBrowser(bool disable_throttling) = 0;
65 ImageTransportSurfaceFBO(GpuChannelManager* manager,
66 GpuCommandBufferStub* stub,
67 gfx::PluginWindowHandle handle);
69 // GLSurface implementation
70 bool Initialize() override;
71 void Destroy() override;
72 bool DeferDraws() override;
73 bool IsOffscreen() override;
74 bool SwapBuffers() override;
75 bool PostSubBuffer(int x, int y, int width, int height) override;
76 bool SupportsPostSubBuffer() override;
77 gfx::Size GetSize() override;
78 void* GetHandle() override;
79 void* GetDisplay() override;
80 bool OnMakeCurrent(gfx::GLContext* context) override;
81 void NotifyWasBound() override;
82 unsigned int GetBackingFrameBufferObject() override;
83 bool SetBackbufferAllocation(bool allocated) override;
84 void SetFrontbufferAllocation(bool allocated) override;
86 // Called when the context may continue to make forward progress after a swap.
87 void SendSwapBuffers(uint64 surface_handle,
88 const gfx::Size pixel_size,
89 float scale_factor);
90 void SetRendererID(int renderer_id);
92 protected:
93 // ImageTransportSurface implementation
94 void OnBufferPresented(
95 const AcceleratedSurfaceMsg_BufferPresented_Params& params) override;
96 void OnResize(gfx::Size pixel_size, float scale_factor) override;
97 void SetLatencyInfo(const std::vector<ui::LatencyInfo>&) override;
98 void WakeUpGpu() override;
100 // GpuCommandBufferStub::DestructionObserver implementation.
101 void OnWillDestroyStub() override;
103 private:
104 ~ImageTransportSurfaceFBO() override;
106 void AdjustBufferAllocation();
107 void DestroyFramebuffer();
108 void AllocateOrResizeFramebuffer(
109 const gfx::Size& pixel_size, float scale_factor);
110 bool SwapBuffersInternal();
112 scoped_ptr<StorageProvider> storage_provider_;
114 // Tracks the current buffer allocation state.
115 bool backbuffer_suggested_allocation_;
116 bool frontbuffer_suggested_allocation_;
118 uint32 fbo_id_;
119 GLuint texture_id_;
120 GLuint depth_stencil_renderbuffer_id_;
121 bool has_complete_framebuffer_;
123 // Weak pointer to the context that this was last made current to.
124 gfx::GLContext* context_;
126 gfx::Size pixel_size_;
127 gfx::Size rounded_pixel_size_;
128 float scale_factor_;
130 // Whether or not we've successfully made the surface current once.
131 bool made_current_;
133 // Whether a SwapBuffers IPC needs to be sent to the browser.
134 bool is_swap_buffers_send_pending_;
135 std::vector<ui::LatencyInfo> latency_info_;
137 scoped_ptr<ImageTransportHelper> helper_;
139 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurfaceFBO);
142 } // namespace content
144 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_FBO_MAC_H_