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