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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/common/gpu/gpu_command_buffer_stub.h" | 12 #include "content/common/gpu/gpu_command_buffer_stub.h" |
13 #include "content/common/gpu/image_transport_surface.h" | 13 #include "content/common/gpu/image_transport_surface.h" |
14 #include "gpu/command_buffer/service/mailbox_manager.h" | 14 #include "gpu/command_buffer/service/mailbox_manager.h" |
15 #include "gpu/command_buffer/service/texture_definition.h" | |
16 #include "gpu/command_buffer/service/texture_manager.h" | 15 #include "gpu/command_buffer/service/texture_manager.h" |
17 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
18 #include "ui/gl/gl_surface.h" | 17 #include "ui/gl/gl_surface.h" |
19 | 18 |
20 namespace content { | 19 namespace content { |
21 class GpuChannelManager; | 20 class GpuChannelManager; |
22 | 21 |
23 class TextureImageTransportSurface | 22 class TextureImageTransportSurface |
24 : public ImageTransportSurface, | 23 : public ImageTransportSurface, |
25 public GpuCommandBufferStub::DestructionObserver, | 24 public GpuCommandBufferStub::DestructionObserver, |
26 public gfx::GLSurface { | 25 public gfx::GLSurface { |
27 public: | 26 public: |
28 TextureImageTransportSurface(GpuChannelManager* manager, | 27 TextureImageTransportSurface(GpuChannelManager* manager, |
29 GpuCommandBufferStub* stub, | 28 GpuCommandBufferStub* stub, |
30 const gfx::GLSurfaceHandle& handle); | 29 const gfx::GLSurfaceHandle& handle); |
31 | 30 |
32 // gfx::GLSurface implementation. | 31 // gfx::GLSurface implementation. |
33 virtual bool Initialize() OVERRIDE; | 32 virtual bool Initialize() OVERRIDE; |
34 virtual void Destroy() OVERRIDE; | 33 virtual void Destroy() OVERRIDE; |
35 virtual bool DeferDraws() OVERRIDE; | 34 virtual bool DeferDraws() OVERRIDE; |
36 virtual bool Resize(const gfx::Size& size) OVERRIDE; | |
37 virtual bool IsOffscreen() OVERRIDE; | 35 virtual bool IsOffscreen() OVERRIDE; |
38 virtual bool SwapBuffers() OVERRIDE; | 36 virtual bool SwapBuffers() OVERRIDE; |
39 virtual gfx::Size GetSize() OVERRIDE; | 37 virtual gfx::Size GetSize() OVERRIDE; |
40 virtual void* GetHandle() OVERRIDE; | 38 virtual void* GetHandle() OVERRIDE; |
41 virtual unsigned GetFormat() OVERRIDE; | 39 virtual unsigned GetFormat() OVERRIDE; |
42 virtual std::string GetExtensions() OVERRIDE; | 40 virtual std::string GetExtensions() OVERRIDE; |
43 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 41 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
44 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; |
45 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | |
46 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; | 43 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; |
47 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | 44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
48 virtual void* GetShareHandle() OVERRIDE; | 45 virtual void* GetShareHandle() OVERRIDE; |
49 virtual void* GetDisplay() OVERRIDE; | 46 virtual void* GetDisplay() OVERRIDE; |
50 virtual void* GetConfig() OVERRIDE; | 47 virtual void* GetConfig() OVERRIDE; |
51 | 48 |
52 protected: | 49 protected: |
53 // ImageTransportSurface implementation. | 50 // ImageTransportSurface implementation. |
54 virtual void OnBufferPresented( | 51 virtual void OnBufferPresented( |
55 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; | 52 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; |
56 virtual void OnResizeViewACK() OVERRIDE; | 53 virtual void OnResizeViewACK() OVERRIDE; |
57 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE; | 54 virtual void OnResize(gfx::Size size, float scale_factor) OVERRIDE; |
58 virtual void SetLatencyInfo( | 55 virtual void SetLatencyInfo( |
59 const ui::LatencyInfo& latency_info) OVERRIDE; | 56 const ui::LatencyInfo& latency_info) OVERRIDE; |
60 | 57 |
61 // GpuCommandBufferStub::DestructionObserver implementation. | 58 // GpuCommandBufferStub::DestructionObserver implementation. |
62 virtual void OnWillDestroyStub() OVERRIDE; | 59 virtual void OnWillDestroyStub() OVERRIDE; |
63 | 60 |
64 private: | 61 private: |
65 | 62 |
66 gfx::Size backbuffer_size() const { | 63 gfx::Size backbuffer_size() const { |
67 return gfx::Size(backbuffer_->level_infos()[0][0].width, | 64 DCHECK(backbuffer_); |
68 backbuffer_->level_infos()[0][0].height); | 65 GLsizei width = 0; |
| 66 GLsizei height = 0; |
| 67 backbuffer_->texture()->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 68 return gfx::Size(width, height); |
69 } | 69 } |
70 | 70 |
71 virtual ~TextureImageTransportSurface(); | 71 virtual ~TextureImageTransportSurface(); |
72 void CreateBackTexture(); | 72 void CreateBackTexture(); |
73 void AttachBackTextureToFBO(); | 73 void AttachBackTextureToFBO(); |
74 void ReleaseBackTexture(); | 74 void ReleaseBackTexture(); |
| 75 void ReleaseFrontTexture(); |
75 void BufferPresentedImpl(const std::string& mailbox_name); | 76 void BufferPresentedImpl(const std::string& mailbox_name); |
76 void ProduceTexture(); | |
77 void ConsumeTexture(); | |
78 | |
79 static gpu::gles2::TextureDefinition* CreateTextureDefinition(gfx::Size size, | |
80 int service_id); | |
81 | 77 |
82 // The framebuffer that represents this surface (service id). Allocated lazily | 78 // The framebuffer that represents this surface (service id). Allocated lazily |
83 // in OnMakeCurrent. | 79 // in OnMakeCurrent. |
84 uint32 fbo_id_; | 80 uint32 fbo_id_; |
85 | 81 |
86 // The current backbuffer. | 82 // The current backbuffer. |
87 scoped_ptr<gpu::gles2::TextureDefinition> backbuffer_; | 83 scoped_refptr<gpu::gles2::TextureRef> backbuffer_; |
| 84 scoped_refptr<gpu::gles2::TextureRef> frontbuffer_; |
88 | 85 |
89 // The mailbox name for the current backbuffer texture. Needs to be unique per | 86 // The mailbox name for the current backbuffer texture. Needs to be unique per |
90 // GL texture and is invalid while service_id is zero. | 87 // GL texture and is invalid while service_id is zero. |
91 gpu::gles2::MailboxName mailbox_name_; | 88 gpu::gles2::MailboxName back_mailbox_name_; |
| 89 gpu::gles2::MailboxName front_mailbox_name_; |
92 | 90 |
93 // The current size of the GLSurface. Used to disambiguate from the current | 91 // The current size of the GLSurface. Used to disambiguate from the current |
94 // texture size which might be outdated (since we use two buffers). | 92 // texture size which might be outdated (since we use two buffers). |
95 gfx::Size current_size_; | 93 gfx::Size current_size_; |
96 float scale_factor_; | 94 float scale_factor_; |
97 | 95 |
98 // Whether or not the command buffer stub has been destroyed. | 96 // Whether or not the command buffer stub has been destroyed. |
99 bool stub_destroyed_; | 97 bool stub_destroyed_; |
100 | 98 |
101 bool backbuffer_suggested_allocation_; | 99 bool backbuffer_suggested_allocation_; |
102 bool frontbuffer_suggested_allocation_; | 100 bool frontbuffer_suggested_allocation_; |
103 | 101 |
104 scoped_ptr<ImageTransportHelper> helper_; | 102 scoped_ptr<ImageTransportHelper> helper_; |
105 gfx::GLSurfaceHandle handle_; | 103 gfx::GLSurfaceHandle handle_; |
106 | 104 |
107 // The offscreen surface used to make the context current. However note that | 105 // The offscreen surface used to make the context current. However note that |
108 // the actual rendering is always redirected to an FBO. | 106 // the actual rendering is always redirected to an FBO. |
109 scoped_refptr<gfx::GLSurface> surface_; | 107 scoped_refptr<gfx::GLSurface> surface_; |
110 | 108 |
111 // Holds a reference to the underlying context for cleanup. | |
112 scoped_refptr<gfx::GLContext> context_; | |
113 | |
114 // Whether a SwapBuffers is pending. | 109 // Whether a SwapBuffers is pending. |
115 bool is_swap_buffers_pending_; | 110 bool is_swap_buffers_pending_; |
116 | 111 |
117 // Whether we unscheduled command buffer because of pending SwapBuffers. | 112 // Whether we unscheduled command buffer because of pending SwapBuffers. |
118 bool did_unschedule_; | 113 bool did_unschedule_; |
119 | 114 |
120 // Holds a reference to the mailbox manager for cleanup. | 115 // Holds a reference to the mailbox manager for cleanup. |
121 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 116 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
122 | 117 |
123 ui::LatencyInfo latency_info_; | 118 ui::LatencyInfo latency_info_; |
124 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); | 119 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); |
125 }; | 120 }; |
126 | 121 |
127 } // namespace content | 122 } // namespace content |
128 | 123 |
129 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 124 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
OLD | NEW |