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

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: moved texture code to ReflectorTexture 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/reflector_impl.h" 14 #include "content/browser/compositor/reflector_impl.h"
15 #include "content/browser/compositor/reflector_texture.h"
15 #include "content/common/gpu/client/context_provider_command_buffer.h" 16 #include "content/common/gpu/client/context_provider_command_buffer.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "gpu/command_buffer/client/context_support.h" 18 #include "gpu/command_buffer/client/context_support.h"
18 #include "gpu/command_buffer/client/gles2_interface.h" 19 #include "gpu/command_buffer/client/gles2_interface.h"
19 #include "third_party/khronos/GLES2/gl2.h" 20 #include "third_party/khronos/GLES2/gl2.h"
20 #include "third_party/khronos/GLES2/gl2ext.h" 21 #include "third_party/khronos/GLES2/gl2ext.h"
21 22
22 using cc::CompositorFrame; 23 using cc::CompositorFrame;
23 using cc::GLFrameData; 24 using cc::GLFrameData;
24 using cc::ResourceProvider; 25 using cc::ResourceProvider;
25 using gpu::gles2::GLES2Interface; 26 using gpu::gles2::GLES2Interface;
26 27
27 namespace content { 28 namespace content {
28 29
29 OffscreenBrowserCompositorOutputSurface:: 30 OffscreenBrowserCompositorOutputSurface::
30 OffscreenBrowserCompositorOutputSurface( 31 OffscreenBrowserCompositorOutputSurface(
31 const scoped_refptr<ContextProviderCommandBuffer>& context, 32 const scoped_refptr<ContextProviderCommandBuffer>& context,
32 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager, 33 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
33 scoped_ptr<BrowserCompositorOverlayCandidateValidator> 34 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
34 overlay_candidate_validator) 35 overlay_candidate_validator)
35 : BrowserCompositorOutputSurface(context, 36 : BrowserCompositorOutputSurface(context,
36 vsync_manager, 37 vsync_manager,
37 overlay_candidate_validator.Pass()), 38 overlay_candidate_validator.Pass()),
38 fbo_(0), 39 fbo_(0),
39 is_backbuffer_discarded_(false), 40 is_backbuffer_discarded_(false),
40 backing_texture_id_(0),
41 weak_ptr_factory_(this) { 41 weak_ptr_factory_(this) {
42 capabilities_.max_frames_pending = 1; 42 capabilities_.max_frames_pending = 1;
43 capabilities_.uses_default_gl_framebuffer = false; 43 capabilities_.uses_default_gl_framebuffer = false;
44 } 44 }
45 45
46 OffscreenBrowserCompositorOutputSurface:: 46 OffscreenBrowserCompositorOutputSurface::
47 ~OffscreenBrowserCompositorOutputSurface() { 47 ~OffscreenBrowserCompositorOutputSurface() {
48 DiscardBackbuffer(); 48 DiscardBackbuffer();
49 } 49 }
50 50
51 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() { 51 void OffscreenBrowserCompositorOutputSurface::EnsureBackbuffer() {
52 is_backbuffer_discarded_ = false; 52 is_backbuffer_discarded_ = false;
53 53
54 if (!backing_texture_id_) { 54 if (!reflector_texture_.get()) {
55 reflector_texture_.reset(new ReflectorTexture(context_provider()));
56
55 GLES2Interface* gl = context_provider_->ContextGL(); 57 GLES2Interface* gl = context_provider_->ContextGL();
56 cc::ResourceFormat format = cc::RGBA_8888; 58 cc::ResourceFormat format = cc::RGBA_8888;
57 59 gl->BindTexture(GL_TEXTURE_2D, reflector_texture_->texture_id());
58 gl->GenTextures(1, &backing_texture_id_);
59 gl->BindTexture(GL_TEXTURE_2D, backing_texture_id_);
60 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 60 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
61 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 61 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); 62 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); 63 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
64 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), 64 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format),
65 surface_size_.width(), surface_size_.height(), 0, 65 surface_size_.width(), surface_size_.height(), 0,
66 GLDataFormat(format), GLDataType(format), nullptr); 66 GLDataFormat(format), GLDataType(format), nullptr);
67 if (!fbo_)
68 gl->GenFramebuffers(1, &fbo_);
69
70 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
71 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
72 GL_TEXTURE_2D, reflector_texture_->texture_id(),
73 0);
74 reflector_->OnSourceTextureMailboxUpdated(
75 reflector_texture_->mailbox());
67 } 76 }
68 } 77 }
69 78
70 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() { 79 void OffscreenBrowserCompositorOutputSurface::DiscardBackbuffer() {
71 is_backbuffer_discarded_ = true; 80 is_backbuffer_discarded_ = true;
72 81
73 GLES2Interface* gl = context_provider_->ContextGL(); 82 GLES2Interface* gl = context_provider_->ContextGL();
74 83
75 if (backing_texture_id_) { 84 if (reflector_texture_) {
76 gl->DeleteTextures(1, &backing_texture_id_); 85 reflector_texture_.reset();
77 backing_texture_id_ = 0; 86 if (reflector_)
87 reflector_->OnSourceTextureMailboxUpdated(nullptr);
78 } 88 }
79 89
80 if (fbo_) { 90 if (fbo_) {
81 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_); 91 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
82 gl->DeleteFramebuffers(1, &fbo_); 92 gl->DeleteFramebuffers(1, &fbo_);
83 fbo_ = 0; 93 fbo_ = 0;
84 } 94 }
85 } 95 }
86 96
87 void OffscreenBrowserCompositorOutputSurface::Reshape(const gfx::Size& size, 97 void OffscreenBrowserCompositorOutputSurface::Reshape(const gfx::Size& size,
88 float scale_factor) { 98 float scale_factor) {
89 if (size == surface_size_) 99 if (size == surface_size_)
90 return; 100 return;
91 101
92 surface_size_ = size; 102 surface_size_ = size;
93 device_scale_factor_ = scale_factor; 103 device_scale_factor_ = scale_factor;
94 DiscardBackbuffer(); 104 DiscardBackbuffer();
95 EnsureBackbuffer(); 105 EnsureBackbuffer();
96 } 106 }
97 107
98 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() { 108 void OffscreenBrowserCompositorOutputSurface::BindFramebuffer() {
109 bool need_to_bind = !!reflector_texture_.get();
99 EnsureBackbuffer(); 110 EnsureBackbuffer();
100 DCHECK(backing_texture_id_); 111 DCHECK(reflector_texture_.get());
101 112
102 GLES2Interface* gl = context_provider_->ContextGL(); 113 if (need_to_bind) {
103 114 GLES2Interface* gl = context_provider_->ContextGL();
104 if (!fbo_) 115 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
105 gl->GenFramebuffers(1, &fbo_); 116 }
106 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo_);
107 gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
108 backing_texture_id_, 0);
109 } 117 }
110 118
111 void OffscreenBrowserCompositorOutputSurface::SwapBuffers( 119 void OffscreenBrowserCompositorOutputSurface::SwapBuffers(
112 cc::CompositorFrame* frame) { 120 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_) { 121 if (reflector_) {
117 if (frame->gl_frame_data->sub_buffer_rect == 122 if (frame->gl_frame_data->sub_buffer_rect ==
118 gfx::Rect(frame->gl_frame_data->size)) 123 gfx::Rect(frame->gl_frame_data->size))
119 reflector_->OnSourceSwapBuffers(); 124 reflector_->OnSourceSwapBuffers();
120 else 125 else
121 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect); 126 reflector_->OnSourcePostSubBuffer(frame->gl_frame_data->sub_buffer_rect);
122 } 127 }
123 128
124 client_->DidSwapBuffers(); 129 client_->DidSwapBuffers();
130 }
125 131
126 // TODO(oshima): sync with the reflector's SwapBuffersComplete. 132 void OffscreenBrowserCompositorOutputSurface::OnReflectorChanged() {
127 uint32_t sync_point = 133 if (reflector_)
128 context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); 134 EnsureBackbuffer();
129 context_provider_->ContextSupport()->SignalSyncPoint( 135 }
130 sync_point, base::Bind(&OutputSurface::OnSwapBuffersComplete, 136
131 weak_ptr_factory_.GetWeakPtr())); 137 base::Closure
138 OffscreenBrowserCompositorOutputSurface::CreateCompositionStartedCallback() {
139 return base::Bind(&OutputSurface::OnSwapBuffersComplete,
140 weak_ptr_factory_.GetWeakPtr());
132 } 141 }
133 142
134 #if defined(OS_MACOSX) 143 #if defined(OS_MACOSX)
135 144
136 bool OffscreenBrowserCompositorOutputSurface:: 145 bool OffscreenBrowserCompositorOutputSurface::
137 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const { 146 SurfaceShouldNotShowFramesAfterSuspendForRecycle() const {
138 return true; 147 return true;
139 } 148 }
140 149
141 #endif 150 #endif
142 151
143 } // namespace content 152 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/compositor/offscreen_browser_compositor_output_surface.h ('k') | content/browser/compositor/reflector_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698