[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_fbo_mac.h
blob3587e21b0b3a86f84d7d6f26843a479609bf6915
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, GLuint texture,
38 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 // Retrieve the handle for the surface to send to the browser process to
45 // display.
46 virtual uint64 GetSurfaceHandle() const = 0;
48 // Called when a frame is about to be sent to the browser process.
49 virtual void WillSwapBuffers() = 0;
52 ImageTransportSurfaceFBO(StorageProvider* storage_provider,
53 GpuChannelManager* manager,
54 GpuCommandBufferStub* stub,
55 gfx::PluginWindowHandle handle);
57 // GLSurface implementation
58 virtual bool Initialize() OVERRIDE;
59 virtual void Destroy() OVERRIDE;
60 virtual bool DeferDraws() OVERRIDE;
61 virtual bool IsOffscreen() OVERRIDE;
62 virtual bool SwapBuffers() OVERRIDE;
63 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
64 virtual bool SupportsPostSubBuffer() OVERRIDE;
65 virtual gfx::Size GetSize() OVERRIDE;
66 virtual void* GetHandle() OVERRIDE;
67 virtual void* GetDisplay() OVERRIDE;
68 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE;
69 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE;
70 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE;
71 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE;
73 protected:
74 // ImageTransportSurface implementation
75 virtual void OnBufferPresented(
76 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE;
77 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE;
78 virtual void SetLatencyInfo(
79 const std::vector<ui::LatencyInfo>&) OVERRIDE;
80 virtual void WakeUpGpu() OVERRIDE;
82 // GpuCommandBufferStub::DestructionObserver implementation.
83 virtual void OnWillDestroyStub() OVERRIDE;
85 private:
86 virtual ~ImageTransportSurfaceFBO() OVERRIDE;
88 void AdjustBufferAllocation();
89 void DestroyFramebuffer();
90 void CreateFramebuffer();
92 scoped_ptr<StorageProvider> storage_provider_;
94 // Tracks the current buffer allocation state.
95 bool backbuffer_suggested_allocation_;
96 bool frontbuffer_suggested_allocation_;
98 uint32 fbo_id_;
99 GLuint texture_id_;
100 GLuint depth_stencil_renderbuffer_id_;
101 bool has_complete_framebuffer_;
103 // Weak pointer to the context that this was last made current to.
104 gfx::GLContext* context_;
106 gfx::Size size_;
107 gfx::Size rounded_size_;
108 float scale_factor_;
110 // Whether or not we've successfully made the surface current once.
111 bool made_current_;
113 // Whether a SwapBuffers is pending.
114 bool is_swap_buffers_pending_;
116 // Whether we unscheduled command buffer because of pending SwapBuffers.
117 bool did_unschedule_;
119 std::vector<ui::LatencyInfo> latency_info_;
121 scoped_ptr<ImageTransportHelper> helper_;
123 DISALLOW_COPY_AND_ASSIGN(ImageTransportSurfaceFBO);
126 } // namespace content
128 #endif // CONTENT_COMMON_GPU_IMAGE_TRANSPORT_SURFACE_MAC_H_