OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 5 #ifndef CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
7 | 7 |
8 #include <map> | |
jonathan.backer
2012/12/04 19:15:13
nit: necessary?
no sievers
2012/12/05 22:02:34
Done.
no sievers
2012/12/05 22:02:34
Done.
| |
9 | |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/memory/weak_ptr.h" | |
10 #include "content/common/gpu/gpu_command_buffer_stub.h" | 11 #include "content/common/gpu/gpu_command_buffer_stub.h" |
11 #include "content/common/gpu/image_transport_surface.h" | 12 #include "content/common/gpu/image_transport_surface.h" |
13 #include "gpu/command_buffer/service/mailbox_manager.h" | |
12 #include "gpu/command_buffer/service/texture_manager.h" | 14 #include "gpu/command_buffer/service/texture_manager.h" |
15 #include "ui/gl/gl_context.h" | |
13 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 class GpuChannelManager; | 19 class GpuChannelManager; |
17 | 20 |
18 class TextureImageTransportSurface : | 21 class TextureImageTransportSurface : |
19 public ImageTransportSurface, | 22 public ImageTransportSurface, |
20 public GpuCommandBufferStub::DestructionObserver, | 23 public GpuCommandBufferStub::DestructionObserver, |
21 public gfx::GLSurface, | 24 public gfx::GLSurface { |
22 public base::SupportsWeakPtr<TextureImageTransportSurface> { | |
23 public: | 25 public: |
24 TextureImageTransportSurface(GpuChannelManager* manager, | 26 TextureImageTransportSurface(GpuChannelManager* manager, |
25 GpuCommandBufferStub* stub, | 27 GpuCommandBufferStub* stub, |
26 const gfx::GLSurfaceHandle& handle); | 28 const gfx::GLSurfaceHandle& handle); |
27 | 29 |
28 // gfx::GLSurface implementation. | 30 // gfx::GLSurface implementation. |
29 virtual bool Initialize() OVERRIDE; | 31 virtual bool Initialize() OVERRIDE; |
30 virtual void Destroy() OVERRIDE; | 32 virtual void Destroy() OVERRIDE; |
31 virtual bool DeferDraws() OVERRIDE; | 33 virtual bool DeferDraws() OVERRIDE; |
32 virtual bool Resize(const gfx::Size& size) OVERRIDE; | 34 virtual bool Resize(const gfx::Size& size) OVERRIDE; |
33 virtual bool IsOffscreen() OVERRIDE; | 35 virtual bool IsOffscreen() OVERRIDE; |
34 virtual bool SwapBuffers() OVERRIDE; | 36 virtual bool SwapBuffers() OVERRIDE; |
35 virtual gfx::Size GetSize() OVERRIDE; | 37 virtual gfx::Size GetSize() OVERRIDE; |
36 virtual void* GetHandle() OVERRIDE; | 38 virtual void* GetHandle() OVERRIDE; |
37 virtual unsigned GetFormat() OVERRIDE; | 39 virtual unsigned GetFormat() OVERRIDE; |
38 virtual std::string GetExtensions() OVERRIDE; | 40 virtual std::string GetExtensions() OVERRIDE; |
39 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 41 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
40 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 42 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
41 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 43 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
42 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; | 44 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
43 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | 45 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
44 virtual void* GetShareHandle() OVERRIDE; | 46 virtual void* GetShareHandle() OVERRIDE; |
45 virtual void* GetDisplay() OVERRIDE; | 47 virtual void* GetDisplay() OVERRIDE; |
46 virtual void* GetConfig() OVERRIDE; | 48 virtual void* GetConfig() OVERRIDE; |
47 | 49 |
48 protected: | 50 protected: |
49 // ImageTransportSurface implementation. | 51 // ImageTransportSurface implementation. |
50 virtual void OnBufferPresented( | 52 virtual void OnBufferPresented( |
51 bool presented, | 53 uint64 surface_handle, |
52 uint32 sync_point) OVERRIDE; | 54 uint32 sync_point) OVERRIDE; |
53 virtual void OnResizeViewACK() OVERRIDE; | 55 virtual void OnResizeViewACK() OVERRIDE; |
54 virtual void OnSetFrontSurfaceIsProtected( | |
55 bool is_protected, | |
56 uint32 protection_state_id) OVERRIDE; | |
57 virtual void OnResize(gfx::Size size) OVERRIDE; | 56 virtual void OnResize(gfx::Size size) OVERRIDE; |
58 | 57 |
59 // GpuCommandBufferStub::DestructionObserver implementation. | 58 // GpuCommandBufferStub::DestructionObserver implementation. |
60 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; | 59 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; |
61 | 60 |
62 private: | 61 private: |
63 // A texture backing the front/back buffer in the parent stub. | 62 // A texture backing the front/back buffer. |
64 struct Texture { | 63 struct Texture { |
65 Texture(); | 64 Texture(); |
66 ~Texture(); | 65 ~Texture(); |
67 | 66 |
68 // The client-side id in the parent stub. | |
69 uint32 client_id; | |
70 | |
71 // The currently allocated size. | 67 // The currently allocated size. |
72 gfx::Size size; | 68 gfx::Size size; |
73 | 69 |
74 // Whether or not that texture has been sent to the client yet. | 70 // The actual GL texture id. |
75 bool sent_to_client; | 71 uint32 service_id; |
76 | 72 |
77 // The texture info in the parent stub. | 73 // The surface identifier for this texture. |
78 gpu::gles2::TextureManager::TextureInfo::Ref info; | 74 uint64 identifier; |
jonathan.backer
2012/12/04 19:15:13
nit: s/identifier/surface_handle?
This would disa
no sievers
2012/12/05 22:02:34
Done.
| |
79 }; | 75 }; |
80 | 76 |
81 virtual ~TextureImageTransportSurface(); | 77 virtual ~TextureImageTransportSurface(); |
82 void CreateBackTexture(const gfx::Size& size); | 78 void CreateBackTexture(); |
83 void AttachBackTextureToFBO(); | 79 void AttachBackTextureToFBO(); |
84 void ReleaseTexture(int id); | 80 void ReleaseBackTexture(); |
85 void ReleaseParentStub(); | |
86 void AdjustFrontBufferAllocation(); | 81 void AdjustFrontBufferAllocation(); |
87 void BufferPresentedImpl(bool presented); | 82 void BufferPresentedImpl(uint64 surface_handle); |
88 int front() const { return front_; } | 83 void ProduceTexture(Texture& texture); |
89 int back() const { return 1 - front_; } | 84 void ConsumeTexture(Texture& texture); |
85 | |
86 gpu::gles2::MailboxName& mailbox_name(uint64 id) { | |
87 DCHECK(id == 1 || id == 2); | |
88 return mailbox_names_[id-1]; | |
89 } | |
90 | 90 |
91 // The framebuffer that represents this surface (service id). Allocated lazily | 91 // The framebuffer that represents this surface (service id). Allocated lazily |
92 // in OnMakeCurrent. | 92 // in OnMakeCurrent. |
93 uint32 fbo_id_; | 93 uint32 fbo_id_; |
94 | 94 |
95 // The front and back buffers. | 95 // The current backbuffer. |
96 Texture textures_[2]; | 96 Texture backbuffer_; |
97 | 97 |
98 gfx::Rect previous_damage_rect_; | 98 gfx::Size current_size_; |
jonathan.backer
2012/12/04 19:15:13
Maybe a comment on why this differs from |backbuff
no sievers
2012/12/05 22:02:34
Done.
| |
99 | |
100 // Indicates which of the 2 above is the front buffer. | |
101 int front_; | |
102 | 99 |
103 // Whether or not the command buffer stub has been destroyed. | 100 // Whether or not the command buffer stub has been destroyed. |
104 bool stub_destroyed_; | 101 bool stub_destroyed_; |
105 | 102 |
106 bool backbuffer_suggested_allocation_; | 103 bool backbuffer_suggested_allocation_; |
107 bool frontbuffer_suggested_allocation_; | 104 bool frontbuffer_suggested_allocation_; |
108 | 105 |
109 bool frontbuffer_is_protected_; | |
110 uint32 protection_state_id_; | |
111 | |
112 scoped_ptr<ImageTransportHelper> helper_; | 106 scoped_ptr<ImageTransportHelper> helper_; |
113 gfx::GLSurfaceHandle handle_; | 107 gfx::GLSurfaceHandle handle_; |
114 GpuCommandBufferStub* parent_stub_; | |
115 | 108 |
116 // The offscreen surface used to make the context current. However note that | 109 // The offscreen surface used to make the context current. However note that |
117 // the actual rendering is always redirected to an FBO. | 110 // the actual rendering is always redirected to an FBO. |
118 scoped_refptr<GLSurface> surface_; | 111 scoped_refptr<gfx::GLSurface> surface_; |
112 | |
113 // Holds a reference to the underlying context for cleanup. | |
114 scoped_refptr<gfx::GLContext> context_; | |
119 | 115 |
120 // Whether a SwapBuffers is pending. | 116 // Whether a SwapBuffers is pending. |
121 bool is_swap_buffers_pending_; | 117 bool is_swap_buffers_pending_; |
122 | 118 |
123 // Whether we unscheduled command buffer because of pending SwapBuffers. | 119 // Whether we unscheduled command buffer because of pending SwapBuffers. |
124 bool did_unschedule_; | 120 bool did_unschedule_; |
125 | 121 |
126 // Whether or not the buffer flip went through browser side on the last | 122 // The mailbox names used for texture exchange. Uses the texture |
127 // swap or post sub buffer. | 123 // identifier as the key. |
jonathan.backer
2012/12/04 19:15:13
nit: s/texture identifier/surface_handle?
no sievers
2012/12/05 22:02:34
Done.
| |
128 bool did_flip_; | 124 gpu::gles2::MailboxName mailbox_names_[2]; |
125 | |
126 // Holds a reference to the mailbox manager for cleanup. | |
127 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | |
129 | 128 |
130 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); | 129 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); |
131 }; | 130 }; |
132 | 131 |
133 } // namespace content | 132 } // namespace content |
134 | 133 |
135 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 134 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
OLD | NEW |