1 // Copyright (c) 2012 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_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_
6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_
8 #include "base/basictypes.h"
9 #include "content/common/gpu/gpu_command_buffer_stub.h"
10 #include "content/common/gpu/image_transport_surface.h"
11 #include "gpu/command_buffer/service/mailbox_manager.h"
12 #include "gpu/command_buffer/service/texture_manager.h"
13 #include "ui/gl/gl_context.h"
14 #include "ui/gl/gl_surface.h"
17 class GpuChannelManager
;
19 class TextureImageTransportSurface
:
20 public ImageTransportSurface
,
21 public GpuCommandBufferStub::DestructionObserver
,
22 public gfx::GLSurface
{
24 TextureImageTransportSurface(GpuChannelManager
* manager
,
25 GpuCommandBufferStub
* stub
,
26 const gfx::GLSurfaceHandle
& handle
);
28 // gfx::GLSurface implementation.
29 virtual bool Initialize() OVERRIDE
;
30 virtual void Destroy() OVERRIDE
;
31 virtual bool DeferDraws() OVERRIDE
;
32 virtual bool Resize(const gfx::Size
& size
) OVERRIDE
;
33 virtual bool IsOffscreen() OVERRIDE
;
34 virtual bool SwapBuffers() OVERRIDE
;
35 virtual gfx::Size
GetSize() OVERRIDE
;
36 virtual void* GetHandle() OVERRIDE
;
37 virtual unsigned GetFormat() OVERRIDE
;
38 virtual std::string
GetExtensions() OVERRIDE
;
39 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE
;
40 virtual bool PostSubBuffer(int x
, int y
, int width
, int height
) OVERRIDE
;
41 virtual bool OnMakeCurrent(gfx::GLContext
* context
) OVERRIDE
;
42 virtual void SetBackbufferAllocation(bool allocated
) OVERRIDE
;
43 virtual void SetFrontbufferAllocation(bool allocated
) OVERRIDE
;
44 virtual void* GetShareHandle() OVERRIDE
;
45 virtual void* GetDisplay() OVERRIDE
;
46 virtual void* GetConfig() OVERRIDE
;
49 // ImageTransportSurface implementation.
50 virtual void OnBufferPresented(
51 const AcceleratedSurfaceMsg_BufferPresented_Params
& params
) OVERRIDE
;
52 virtual void OnResizeViewACK() OVERRIDE
;
53 virtual void OnResize(gfx::Size size
) OVERRIDE
;
55 // GpuCommandBufferStub::DestructionObserver implementation.
56 virtual void OnWillDestroyStub(GpuCommandBufferStub
* stub
) OVERRIDE
;
59 // A texture backing the front/back buffer.
64 // The currently allocated size.
67 // The actual GL texture id.
70 // The surface handle for this texture (only 1 and 2 are valid).
71 uint64 surface_handle
;
74 virtual ~TextureImageTransportSurface();
75 void CreateBackTexture();
76 void AttachBackTextureToFBO();
77 void ReleaseBackTexture();
78 void BufferPresentedImpl(uint64 surface_handle
);
79 void ProduceTexture(Texture
& texture
);
80 void ConsumeTexture(Texture
& texture
);
82 gpu::gles2::MailboxName
& mailbox_name(uint64 surface_handle
) {
83 DCHECK(surface_handle
== 1 || surface_handle
== 2);
84 return mailbox_names_
[surface_handle
- 1];
87 // The framebuffer that represents this surface (service id). Allocated lazily
91 // The current backbuffer.
94 // The current size of the GLSurface. Used to disambiguate from the current
95 // texture size which might be outdated (since we use two buffers).
96 gfx::Size current_size_
;
98 // Whether or not the command buffer stub has been destroyed.
101 bool backbuffer_suggested_allocation_
;
102 bool frontbuffer_suggested_allocation_
;
104 scoped_ptr
<ImageTransportHelper
> helper_
;
105 gfx::GLSurfaceHandle handle_
;
107 // The offscreen surface used to make the context current. However note that
108 // the actual rendering is always redirected to an FBO.
109 scoped_refptr
<gfx::GLSurface
> surface_
;
111 // Holds a reference to the underlying context for cleanup.
112 scoped_refptr
<gfx::GLContext
> context_
;
114 // Whether a SwapBuffers is pending.
115 bool is_swap_buffers_pending_
;
117 // Whether we unscheduled command buffer because of pending SwapBuffers.
118 bool did_unschedule_
;
120 // The mailbox names used for texture exchange. Uses surface_handle as key.
121 gpu::gles2::MailboxName mailbox_names_
[2];
123 // Holds a reference to the mailbox manager for cleanup.
124 scoped_refptr
<gpu::gles2::MailboxManager
> mailbox_manager_
;
126 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface
);
129 } // namespace content
131 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_