Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: content/browser/compositor/offscreen_browser_compositor_output_surface.cc

Issue 1123763003: Draw the offscreen texture to reflector's surface without extra copy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
(...skipping 19 matching lines...) Expand all
45 47
46 OffscreenBrowserCompositorOutputSurface:: 48 OffscreenBrowserCompositorOutputSurface::
47 ~OffscreenBrowserCompositorOutputSurface() { 49 ~OffscreenBrowserCompositorOutputSurface() {
48 DiscardBackbuffer(); 50 DiscardBackbuffer();
49 } 51 }
50 52
51 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { 53 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() {
52 is_backbuffer_discarded_ = false; 54 is_backbuffer_discarded_ = false;
53 55
54 if (!backing_texture_id_) { 56 if (!backing_texture_id_) {
57 GLHelper* shared_helper =
58 ImageTransportFactory::GetInstance()->GetGLHelper();
59 mailbox_ = new OwnedMailbox(shared_helper);
55 GLES2Interface* gl = context_provider_->ContextGL(); 60 GLES2Interface* gl = context_provider_->ContextGL();
61
62 offline_compositor_gl_helper_.reset(
63 new GLHelper(gl, context_provider()->ContextSupport()));
64
65 backing_texture_id_ =
66 offline_compositor_gl_helper_->ConsumeMailboxToTexture(
67 mailbox_->mailbox(), mailbox_->sync_point());
68
56 cc::ResourceFormat format = cc::RGBA_8888; 69 cc::ResourceFormat format = cc::RGBA_8888;
57
58 gl->GenTextures(1, &backing_texture_id_);
59 gl->BindTexture(GL_TEXTURE_2D, backing_texture_id_); 70 gl->BindTexture(GL_TEXTURE_2D, backing_texture_id_);
60 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 71 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
61 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 72 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); 73 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); 74 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), 75 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format),
65 surface_size_.width(), surface_size_.height(), 0, 76 surface_size_.width(), surface_size_.height(), 0,
66 GLDataFormat(format), GLDataType(format), nullptr); 77 GLDataFormat(format), GLDataType(format), nullptr);
78 if (!fbo_)
79 gl->GenFramebuffers(1, &fbo_);
80
81 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
82 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
83 GL_TEXTURE_2D, backing_texture_id_, 0);
84 reflector_->OnSourceTextureMailboxUpdated(mailbox_);
67 } 85 }
68 } 86 }
69 87
70 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() { 88 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() {
71 is_backbuffer_discarded_ = true; 89 is_backbuffer_discarded_ = true;
72 90
73 GLES2Interface* gl = context_provider_->ContextGL(); 91 GLES2Interface* gl = context_provider_->ContextGL();
74 92
75 if (backing_texture_id_) { 93 if (backing_texture_id_) {
76 gl->DeleteTextures(1, &backing_texture_id_); 94 mailbox_ = nullptr;
77 backing_texture_id_ = 0; 95 backing_texture_id_ = 0;
96 if (reflector_)
97 reflector_->OnSourceTextureMailboxUpdated(mailbox_);
78 } 98 }
79 99
80 if (fbo_) { 100 if (fbo_) {
81 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 101 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
82 gl->DeleteFramebuffers(1, &fbo_); 102 gl->DeleteFramebuffers(1, &fbo_);
83 fbo_ = 0; 103 fbo_ = 0;
84 } 104 }
85 } 105 }
86 106
87 void OffscreenBrowserCompositorOutputSurface::Reshape(const gfx::Size& size, 107 void OffscreenBrowserCompositorOutputSurface::Reshape(const gfx::Size& size,
88 float scale_factor) { 108 float scale_factor) {
89 if (size == surface_size_) 109 if (size == surface_size_)
90 return; 110 return;
91 111
92 surface_size_ = size; 112 surface_size_ = size;
93 device_scale_factor_ = scale_factor; 113 device_scale_factor_ = scale_factor;
94 DiscardBackbuffer(); 114 DiscardBackbuffer();
95 EnsureBackbuffer(); 115 EnsureBackbuffer();
96 } 116 }
97 117
98 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() { 118 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() {
119 bool need_to_bind = !!backing_texture_id_;
99 EnsureBackbuffer(); 120 EnsureBackbuffer();
100 DCHECK(backing_texture_id_); 121 DCHECK(backing_texture_id_);
101 122
102 GLES2Interface* gl = context_provider_->ContextGL(); 123 if (need_to_bind) {
103 124 GLES2Interface* gl = context_provider_->ContextGL();
104 if (!fbo_) 125 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
105 gl->GenFramebuffers(1, &fbo_); 126 }
106 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
107 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
108 backing_texture_id_, 0);
109 } 127 }
110 128
111 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( 129 void OffscreenBrowserCompositorOutputSurface::SwapBuffers(
112 cc::CompositorFrame* frame) { 130 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_) { 131 if (reflector_) {
117 if (frame->gl_frame_data->sub_buffer_rect == 132 if (frame->gl_frame_data->sub_buffer_rect ==
118 gfx::Rect(frame->gl_frame_data->size)) 133 gfx::Rect(frame->gl_frame_data->size))
119 reflector_->OnSourceSwapBuffers(); 134 reflector_->OnSourceSwapBuffers();
120 else 135 else
121 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); 136 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect);
122 } 137 }
123 138
124 client_->DidSwapBuffers(); 139 client_->DidSwapBuffers();
140 }
125 141
126 // TODO(oshima): sync with the reflector's SwapBuffersComplete. 142 void OffscreenBrowserCompositorOutputSurface::OnReflectorChanged() {
127 uint32_t sync_point = 143 if (reflector_)
128 context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); 144 EnsureBackbuffer();
129 context_provider_->ContextSupport()->SignalSyncPoint( 145 }
130 sync_point, base::Bind(&OutputSurface::OnSwapBuffersComplete, 146
131 weak_ptr_factory_.GetWeakPtr())); 147 base::Closure
148 OffscreenBrowserCompositorOutputSurface::CreateCompositionStartedCallback() {
149 return base::Bind(&OutputSurface::OnSwapBuffersComplete,
150 weak_ptr_factory_.GetWeakPtr());
132 } 151 }
133 152
134 #if defined(OS_MACOSX) 153 #if defined(OS_MACOSX)
135 154
136 bool OffscreenBrowserCompositorOutputSurface:: 155 bool OffscreenBrowserCompositorOutputSurface::
137 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { 156 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const {
138 return true; 157 return true;
139 } 158 }
140 159
141 #endif 160 #endif
142 161
143 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698