OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/compositor/offscreen_browser_compositor_output_surface .h" | 5 #include "content/browser/compositor/offscreen_browser_compositor_output_surface .h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/compositor_frame_ack.h" | 9 #include "cc/output/compositor_frame_ack.h" |
10 #include "cc/output/gl_frame_data.h" | 10 #include "cc/output/gl_frame_data.h" |
11 #include "cc/output/output_surface_client.h" | 11 #include "cc/output/output_surface_client.h" |
12 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
13 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor.h" | 13 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida tor.h" |
14 #include "content/browser/compositor/owned_mailbox.h" | |
14 #include "content/browser/compositor/reflector_impl.h" | 15 #include "content/browser/compositor/reflector_impl.h" |
15 #include "content/common/gpu/client/context_provider_command_buffer.h" | 16 #include "content/common/gpu/client/context_provider_command_buffer.h" |
17 #include "content/common/gpu/client/gl_helper.h" | |
16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
17 #include "gpu/command_buffer/client/context_support.h" | 19 #include "gpu/command_buffer/client/context_support.h" |
18 #include "gpu/command_buffer/client/gles2_interface.h" | 20 #include "gpu/command_buffer/client/gles2_interface.h" |
19 #include "third_party/khronos/GLES2/gl2.h" | 21 #include "third_party/khronos/GLES2/gl2.h" |
20 #include "third_party/khronos/GLES2/gl2ext.h" | 22 #include "third_party/khronos/GLES2/gl2ext.h" |
21 | 23 |
22 using cc::CompositorFrame; | 24 using cc::CompositorFrame; |
23 using cc::GLFrameData; | 25 using cc::GLFrameData; |
24 using cc::ResourceProvider; | 26 using cc::ResourceProvider; |
25 using gpu::gles2::GLES2Interface; | 27 using gpu::gles2::GLES2Interface; |
26 | 28 |
27 namespace content { | 29 namespace content { |
28 | 30 |
29 OffscreenBrowserCompositorOutputSurface:: | 31 OffscreenBrowserCompositorOutputSurface:: |
30 OffscreenBrowserCompositorOutputSurface( | 32 OffscreenBrowserCompositorOutputSurface( |
31 const scoped_refptr<ContextProviderCommandBuffer>& context, | 33 const scoped_refptr<ContextProviderCommandBuffer>& context, |
32 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, | 34 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, |
33 scoped_ptr<BrowserCompositorOverlayCandidateValidator> | 35 scoped_ptr<BrowserCompositorOverlayCandidateValidator> |
34 overlay_candidate_validator) | 36 overlay_candidate_validator) |
35 : BrowserCompositorOutputSurface(context, | 37 : BrowserCompositorOutputSurface(context, |
36 vsync_manager, | 38 vsync_manager, |
37 overlay_candidate_validator.Pass()), | 39 overlay_candidate_validator.Pass()), |
38 fbo_(0), | 40 fbo_(0), |
39 is_backbuffer_discarded_(false), | 41 is_backbuffer_discarded_(false), |
40 backing_texture_id_(0), | 42 backing_texture_id_(0), |
43 needs_update_reflector_(false), | |
41 weak_ptr_factory_(this) { | 44 weak_ptr_factory_(this) { |
42 capabilities_.max_frames_pending = 1; | 45 capabilities_.max_frames_pending = 1; |
43 capabilities_.uses_default_gl_framebuffer = false; | 46 capabilities_.uses_default_gl_framebuffer = false; |
44 } | 47 } |
45 | 48 |
46 OffscreenBrowserCompositorOutputSurface:: | 49 OffscreenBrowserCompositorOutputSurface:: |
47 ~OffscreenBrowserCompositorOutputSurface() { | 50 ~OffscreenBrowserCompositorOutputSurface() { |
48 DiscardBackbuffer(); | 51 DiscardBackbuffer(); |
49 } | 52 } |
50 | 53 |
51 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { | 54 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { |
52 is_backbuffer_discarded_ = false; | 55 is_backbuffer_discarded_ = false; |
53 | 56 |
54 if (!backing_texture_id_) { | 57 if (!backing_texture_id_) { |
58 GLHelper* shared_helper = | |
59 ImageTransportFactory::GetInstance()->GetGLHelper(); | |
60 mailbox_ = new OwnedMailbox(shared_helper); | |
55 GLES2Interface* gl = context_provider_->ContextGL(); | 61 GLES2Interface* gl = context_provider_->ContextGL(); |
62 | |
63 offline_compositor_gl_helper_.reset( | |
64 new GLHelper(gl, context_provider()->ContextSupport())); | |
65 | |
66 backing_texture_id_ = | |
67 offline_compositor_gl_helper_->ConsumeMailboxToTexture( | |
68 mailbox_->mailbox(), mailbox_->sync_point()); | |
69 | |
56 cc::ResourceFormat format = cc::RGBA_8888; | 70 cc::ResourceFormat format = cc::RGBA_8888; |
57 | |
58 gl->GenTextures(1, &backing_texture_id_); | |
59 gl->BindTexture(GL_TEXTURE_2D, backing_texture_id_); | 71 gl->BindTexture(GL_TEXTURE_2D, backing_texture_id_); |
60 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 72 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
61 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 73 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
62 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 74 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
63 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 75 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
64 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), | 76 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), |
65 surface_size_.width(), surface_size_.height(), 0, | 77 surface_size_.width(), surface_size_.height(), 0, |
66 GLDataFormat(format), GLDataType(format), nullptr); | 78 GLDataFormat(format), GLDataType(format), nullptr); |
79 needs_update_reflector_ = true; | |
67 } | 80 } |
68 } | 81 } |
69 | 82 |
70 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() { | 83 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() { |
71 is_backbuffer_discarded_ = true; | 84 is_backbuffer_discarded_ = true; |
72 | 85 |
73 GLES2Interface* gl = context_provider_->ContextGL(); | 86 GLES2Interface* gl = context_provider_->ContextGL(); |
74 | 87 |
75 if (backing_texture_id_) { | 88 if (backing_texture_id_) { |
76 gl->DeleteTextures(1, &backing_texture_id_); | 89 gl->DeleteTextures(1, &backing_texture_id_); |
(...skipping 26 matching lines...) Expand all Loading... | |
103 | 116 |
104 if (!fbo_) | 117 if (!fbo_) |
105 gl->GenFramebuffers(1, &fbo_); | 118 gl->GenFramebuffers(1, &fbo_); |
106 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); | 119 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); |
107 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 120 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
108 backing_texture_id_, 0); | 121 backing_texture_id_, 0); |
109 } | 122 } |
110 | 123 |
111 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( | 124 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( |
112 cc::CompositorFrame* frame) { | 125 cc::CompositorFrame* frame) { |
113 // TODO(oshima): Pass the texture to the reflector so that the | |
114 // reflector can simply use and draw it on their surface instead of | |
115 // copying the texture. | |
116 if (reflector_) { | 126 if (reflector_) { |
127 if (needs_update_reflector_) { | |
128 needs_update_reflector_ = false; | |
129 reflector_->OnSourceTextureMailboxUpdated(); | |
130 } | |
131 offline_compositor_gl_helper_->InsertOrderingBarrier(); | |
oshima
2015/05/06 01:03:35
I'm not sure if this is necessary. It seems to be
| |
132 | |
117 if (frame->gl_frame_data->sub_buffer_rect == | 133 if (frame->gl_frame_data->sub_buffer_rect == |
118 gfx::Rect(frame->gl_frame_data->size)) | 134 gfx::Rect(frame->gl_frame_data->size)) |
119 reflector_->OnSourceSwapBuffers(); | 135 reflector_->OnSourceSwapBuffers(); |
120 else | 136 else |
121 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | 137 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); |
122 } | 138 } |
123 | 139 |
124 client_->DidSwapBuffers(); | 140 client_->DidSwapBuffers(); |
141 } | |
125 | 142 |
126 // TODO(oshima): sync with the reflector's SwapBuffersComplete. | 143 scoped_refptr<OwnedMailbox> |
127 uint32_t sync_point = | 144 OffscreenBrowserCompositorOutputSurface::GetTextureMailbox() { |
128 context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); | 145 EnsureBackbuffer(); |
129 context_provider_->ContextSupport()->SignalSyncPoint( | 146 // This is called from the reflector, so no need to update |
130 sync_point, base::Bind(&OutputSurface::OnSwapBuffersComplete, | 147 // the refletor. |
131 weak_ptr_factory_.GetWeakPtr())); | 148 needs_update_reflector_ = false; |
149 return mailbox_; | |
150 } | |
151 | |
152 base::Closure | |
153 OffscreenBrowserCompositorOutputSurface::CreateCompositionStartedCallback() { | |
154 return base::Bind(&OutputSurface::OnSwapBuffersComplete, | |
155 weak_ptr_factory_.GetWeakPtr()); | |
132 } | 156 } |
133 | 157 |
134 #if defined(OS_MACOSX) | 158 #if defined(OS_MACOSX) |
135 | 159 |
136 bool OffscreenBrowserCompositorOutputSurface:: | 160 bool OffscreenBrowserCompositorOutputSurface:: |
137 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { | 161 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { |
138 return true; | 162 return true; |
139 } | 163 } |
140 | 164 |
141 #endif | 165 #endif |
142 | 166 |
143 } // namespace content | 167 } // namespace content |
OLD | NEW |